summaryrefslogtreecommitdiff
path: root/cmds-qgroup.c
diff options
context:
space:
mode:
authorZhao Lei <zhaolei@cn.fujitsu.com>2015-10-12 21:23:00 +0800
committerDavid Sterba <dsterba@suse.com>2015-11-02 09:35:01 +0100
commitbbbe7fd7d0f2f104c4c1c54e38524a6496cc9ab6 (patch)
treedb8fad0541f354f5891d8efdc8febb845fa61cef /cmds-qgroup.c
parent7c2bad665e4f4229a40a4ec234b7a1c6383ee5c3 (diff)
btrfs-progs: qgroup: use btrfs_open_dir for btrfs qgroup command
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> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-qgroup.c')
-rw-r--r--cmds-qgroup.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 48c17333..0ad99f48 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;