btrfs-progs: inspect: use btrfs_open_dir for btrfs inspect 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 inspect-internal rootid /mnt/tmp1
  ERROR: Failed to lookup root id - Inappropriate ioctl for device
  btrfs inspect-internal rootid: rootid failed with ret=-1
  # ./btrfs inspect-internal inode-resolve 256 /mnt/tmp1
  ioctl ret=-1, error: Inappropriate ioctl for device
  # ./btrfs inspect-internal min-dev-size /mnt/tmp1
  Error invoking tree search ioctl: Inappropriate ioctl for device

After patch:
  # ./btrfs inspect-internal rootid /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs inspect-internal inode-resolve 256 /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs inspect-internal min-dev-size /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:22:59 +08:00 committed by David Sterba
parent b570afae4d
commit 7c2bad665e
1 changed files with 7 additions and 15 deletions

View File

@ -116,11 +116,9 @@ static int cmd_inspect_inode_resolve(int argc, char **argv)
if (check_argc_exact(argc - optind, 2))
usage(cmd_inspect_inode_resolve_usage);
fd = open_file_or_dir(argv[optind+1], &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n", argv[optind+1]);
fd = btrfs_open_dir(argv[optind + 1], &dirstream, 1);
if (fd < 0)
return 1;
}
ret = __ino_to_path_fd(arg_strtou64(argv[optind]), fd, verbose,
argv[optind+1]);
@ -189,9 +187,8 @@ static int cmd_inspect_logical_resolve(int argc, char **argv)
loi.size = size;
loi.inodes = ptr_to_u64(inodes);
fd = open_file_or_dir(argv[optind+1], &dirstream);
fd = btrfs_open_dir(argv[optind + 1], &dirstream, 1);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n", argv[optind+1]);
ret = 12;
goto out;
}
@ -239,10 +236,8 @@ static int cmd_inspect_logical_resolve(int argc, char **argv)
name);
BUG_ON(ret >= bytes_left);
free(name);
path_fd = open_file_or_dir(full_path, &dirs);
path_fd = btrfs_open_dir(full_path, &dirs, 1);
if (path_fd < 0) {
fprintf(stderr, "ERROR: can't access "
"'%s'\n", full_path);
ret = -ENOENT;
goto out;
}
@ -279,9 +274,8 @@ static int cmd_inspect_subvolid_resolve(int argc, char **argv)
if (check_argc_exact(argc, 3))
usage(cmd_inspect_subvolid_resolve_usage);
fd = open_file_or_dir(argv[2], &dirstream);
fd = btrfs_open_dir(argv[2], &dirstream, 1);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n", argv[2]);
ret = -ENOENT;
goto out;
}
@ -320,9 +314,8 @@ static int cmd_inspect_rootid(int argc, char **argv)
if (check_argc_exact(argc, 2))
usage(cmd_inspect_rootid_usage);
fd = open_file_or_dir(argv[1], &dirstream);
fd = btrfs_open_dir(argv[1], &dirstream, 1);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n", argv[1]);
ret = -ENOENT;
goto out;
}
@ -619,9 +612,8 @@ static int cmd_inspect_min_dev_size(int argc, char **argv)
if (check_argc_exact(argc - optind, 1))
usage(cmd_inspect_min_dev_size_usage);
fd = open_file_or_dir(argv[optind], &dirstream);
fd = btrfs_open_dir(argv[optind], &dirstream, 1);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n", argv[optind]);
ret = -ENOENT;
goto out;
}