btrfs-progs: quota: use btrfs_open_dir for btrfs quota 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 quota enable /mnt/tmp1
  ERROR: quota command failed: Inappropriate ioctl for device
  # ./btrfs quota disable /mnt/tmp1
  ERROR: quota command failed: Inappropriate ioctl for device
  # ./btrfs quota rescan /mnt/tmp1
  ERROR: quota rescan failed: Inappropriate ioctl for device
  #

After patch:
  # ./btrfs quota enable /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs quota disable /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs quota rescan /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>
This commit is contained in:
Zhao Lei 2015-10-12 21:23:01 +08:00 committed by David Sterba
parent bbbe7fd7d0
commit 5e1a77c45c
1 changed files with 4 additions and 8 deletions

View File

@ -45,11 +45,9 @@ static int quota_ctl(int cmd, int argc, char **argv)
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
args.cmd = cmd; args.cmd = cmd;
fd = open_file_or_dir(path, &dirstream); fd = btrfs_open_dir(path, &dirstream, 1);
if (fd < 0) { if (fd < 0)
fprintf(stderr, "ERROR: can't access '%s'\n", path);
return 1; return 1;
}
ret = ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args); ret = ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args);
e = errno; e = errno;
@ -141,11 +139,9 @@ static int cmd_quota_rescan(int argc, char **argv)
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
path = argv[optind]; path = argv[optind];
fd = open_file_or_dir(path, &dirstream); fd = btrfs_open_dir(path, &dirstream, 1);
if (fd < 0) { if (fd < 0)
fprintf(stderr, "ERROR: can't access '%s'\n", path);
return 1; return 1;
}
ret = ioctl(fd, ioctlnum, &args); ret = ioctl(fd, ioctlnum, &args);
e = errno; e = errno;