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 <[email protected]> --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
