Since BTRFS_IOC_INO_PATHS requires fd of subvolume, logical-resolve
cannot find the path when mount point is not FS_TREE
(because the subvolume path cannot be opened).
In that case, print message to try -P option instead.
Signed-off-by: Misono Tomohiro <misono.tomohiro@xxxxxxxxxxxxxx>
---
cmds-inspect.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/cmds-inspect.c b/cmds-inspect.c
index ac77a5ee..21aa2903 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -137,16 +137,18 @@ static const char * const cmd_inspect_logical_resolve_usage[] = {
static int cmd_inspect_logical_resolve(int argc, char **argv)
{
int ret;
- int fd;
+ int fd = -1;
int i;
int verbose = 0;
int getpath = 1;
int bytes_left;
+ u64 rootid;
struct btrfs_ioctl_logical_ino_args loi;
struct btrfs_data_container *inodes;
u64 size = 4096;
char full_path[PATH_MAX];
char *path_ptr;
+ char *mount_path = NULL;
DIR *dirstream = NULL;
optind = 0;
@@ -178,6 +180,35 @@ static int cmd_inspect_logical_resolve(int argc, char **argv)
if (!inodes)
return 1;
+ /* Check if mount root is FS_ROOT */
+ if (getpath) {
+ ret = find_mount_root(argv[optind + 1], &mount_path);
+ if (ret) {
+ error("cannot find mount root: %m");
+ goto out;
+ }
+
+ fd = btrfs_open_file_or_dir(mount_path, &dirstream, 1);
+ if (fd < 0) {
+ ret = 1;
+ goto out;
+ }
+
+ ret = lookup_path_rootid(fd, &rootid);
+ if (ret) {
+ error("failed to lookup root id: %m");
+ goto out;
+ }
+
+ if (rootid != BTRFS_FS_TREE_OBJECTID) {
+ ret = 1;
+printf("cannot resolve path when subvolume is mounted directly. try -P option\n");
+ goto out;
+ }
+
+ close_file_or_dir(fd, dirstream);
+ }
+
memset(inodes, 0, sizeof(*inodes));
loi.logical = arg_strtou64(argv[optind]);
loi.size = size;
@@ -259,6 +290,7 @@ static int cmd_inspect_logical_resolve(int argc, char **argv)
out:
close_file_or_dir(fd, dirstream);
free(inodes);
+ free(mount_path);
return !!ret;
}
--
2.14.4
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html