All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhao Lei <zhaolei@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Zhao Lei <zhaolei@cn.fujitsu.com>
Subject: [PATCH 07/11] btrfs-progs: qgroup: use btrfs_open_dir for btrfs qgroup command
Date: Mon, 12 Oct 2015 21:23:00 +0800	[thread overview]
Message-ID: <2b77db10ce6818718b4877df8f8ca04ba11760bc.1444655800.git.zhaolei@cn.fujitsu.com> (raw)
In-Reply-To: <cover.1444655800.git.zhaolei@cn.fujitsu.com>

We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.

Before patch:
  # ./btrfs qgroup create 1/5  /mnt/tmp1
  ERROR: unable to create quota group: Inappropriate ioctl for device
  #
  # ./btrfs qgroup assign 1/5 2/5 /mnt/tmp1
  ERROR: unable to assign quota group: Inappropriate ioctl for device
  #
  # ./btrfs qgroup show /mnt/tmp1
  ERROR: can't perform the search - Inappropriate ioctl for device
  ERROR: can't list qgroups: Inappropriate ioctl for device
  #
  # ./btrfs qgroup limit 1G 1/5  /mnt/tmp1
  ERROR: unable to limit requested quota group: Inappropriate ioctl for device

After patch:
  # ./btrfs qgroup create 1/5 /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs qgroup assign 1/5 2/5 /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs qgroup show /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs qgroup limit 1G 1/5 /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
 cmds-qgroup.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 48c1733..0ad99f4 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -79,11 +79,9 @@ static int qgroup_assign(int assign, int argc, char **argv)
 		fprintf(stderr, "ERROR: bad relation requested '%s'\n", path);
 		return 1;
 	}
-	fd = open_file_or_dir(path, &dirstream);
-	if (fd < 0) {
-		fprintf(stderr, "ERROR: can't access '%s'\n", path);
+	fd = btrfs_open_dir(path, &dirstream, 1);
+	if (fd < 0)
 		return 1;
-	}
 
 	ret = ioctl(fd, BTRFS_IOC_QGROUP_ASSIGN, &args);
 	e = errno;
@@ -137,11 +135,9 @@ static int qgroup_create(int create, int argc, char **argv)
 	args.create = create;
 	args.qgroupid = parse_qgroupid(argv[1]);
 
-	fd = open_file_or_dir(path, &dirstream);
-	if (fd < 0) {
-		fprintf(stderr, "ERROR: can't access '%s'\n", path);
+	fd = btrfs_open_dir(path, &dirstream, 1);
+	if (fd < 0)
 		return 1;
-	}
 
 	ret = ioctl(fd, BTRFS_IOC_QGROUP_CREATE, &args);
 	e = errno;
@@ -351,11 +347,9 @@ static int cmd_qgroup_show(int argc, char **argv)
 		usage(cmd_qgroup_show_usage);
 
 	path = argv[optind];
-	fd = open_file_or_dir(path, &dirstream);
-	if (fd < 0) {
-		fprintf(stderr, "ERROR: can't access '%s'\n", path);
+	fd = btrfs_open_dir(path, &dirstream, 1);
+	if (fd < 0)
 		return 1;
-	}
 
 	if (filter_flag) {
 		qgroupid = btrfs_get_path_rootid(fd);
@@ -460,11 +454,9 @@ static int cmd_qgroup_limit(int argc, char **argv)
 	} else
 		usage(cmd_qgroup_limit_usage);
 
-	fd = open_file_or_dir(path, &dirstream);
-	if (fd < 0) {
-		fprintf(stderr, "ERROR: can't access '%s'\n", path);
+	fd = btrfs_open_dir(path, &dirstream, 1);
+	if (fd < 0)
 		return 1;
-	}
 
 	ret = ioctl(fd, BTRFS_IOC_QGROUP_LIMIT, &args);
 	e = errno;
-- 
1.8.5.1


  parent reply	other threads:[~2015-10-12 13:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-12 13:22 [PATCH 00/11] btrfs-progs: Use btrfs_open_dir to avoid show error of ioctl or tree search Zhao Lei
2015-10-12 13:22 ` [PATCH 01/11] btrfs-progs: subvolume: use btrfs_open_dir for btrfs subvolume command Zhao Lei
2015-10-12 13:22 ` [PATCH 02/11] btrfs-progs: filesystem: use btrfs_open_dir for btrfs filesystem command Zhao Lei
2015-10-12 13:22 ` [PATCH 03/11] btrfs-progs: balance: use btrfs_open_dir for btrfs balance command Zhao Lei
2015-10-12 13:22 ` [PATCH 04/11] btrfs-progs: inspect: Bypass unnecessary clean function in open_error Zhao Lei
2015-10-12 13:22 ` [PATCH 05/11] btrfs-progs: inspect: set return value of error case Zhao Lei
2015-10-12 13:22 ` [PATCH 06/11] btrfs-progs: inspect: use btrfs_open_dir for btrfs inspect command Zhao Lei
2015-10-12 13:23 ` Zhao Lei [this message]
2015-10-12 13:23 ` [PATCH 08/11] btrfs-progs: quota: use btrfs_open_dir for btrfs quota command Zhao Lei
2015-10-12 13:23 ` [PATCH 09/11] btrfs-progs: use btrfs_open_dir in open_path_or_dev_mnt Zhao Lei
2015-10-12 13:23 ` [PATCH 10/11] btrfs-progs: replace: use btrfs_open_dir for btrfs replace command Zhao Lei
2015-10-12 13:23 ` [PATCH 11/11] btrfs-progs: fragments: use btrfs_open_dir for btrfs-fragments command Zhao Lei
2015-10-13 15:58 ` [PATCH 00/11] btrfs-progs: Use btrfs_open_dir to avoid show error of ioctl or tree search David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b77db10ce6818718b4877df8f8ca04ba11760bc.1444655800.git.zhaolei@cn.fujitsu.com \
    --to=zhaolei@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.