aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2024-01-31 10:58:17 +0100
committerDavid Sterba <dsterba@suse.com>2024-01-31 11:07:39 +0100
commitcb740b3dfb97f09e458c4e0bcfd87a6f5d1e7a33 (patch)
tree43fcc9d8c783f7b84a4119eecd858bdc92aa9456
parent74e57d25dcb913eacb4a83247e136c7348d2e395 (diff)
downloadbtrfs-progs-cb740b3dfb97f09e458c4e0bcfd87a6f5d1e7a33.tar.gz
btrfs-progs: fi show: canonicalize path when using blkid and -d
There's a report that passing raw device mapper path and -d don't work together: yyy@xxx ~ $ sudo btrfs filesystem show /dev/dm-0 Label: none uuid: a7fbb8d6-ec5d-4e88-bd8b-c686553e0dc7 Total devices 1 FS bytes used 144.00KiB devid 1 size 256.00MiB used 88.00MiB path /dev/mapper/da0972636816-LogVol00 With --all-devices yyy@xxx ~ $ sudo btrfs filesystem show --all-devices /dev/dm-0 ERROR: not a valid btrfs filesystem: /dev/dm-0 Where dm-0 corresponds to the LogVol00 device from above. Passing the option -d skips some steps but still uses the real path of the device that is required for scanning and identification, while blkid uses the canonicalized path. The combination of raw device name and -d was not handled as the raw path is not in cache and thus not recognized. Canonicalization fixes that although this changes the device name in the output. Issue: #732 Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--cmds/filesystem.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index e0e74fbe..b7ca4c9a 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -709,6 +709,7 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
struct btrfs_fs_devices *fs_devices;
struct btrfs_root *root = NULL;
char *search = NULL;
+ char *canon_path = NULL;
int ret;
/* default, search both kernel and udev */
int where = -1;
@@ -790,8 +791,15 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
}
}
- if (where == BTRFS_SCAN_LBLKID)
+ if (where == BTRFS_SCAN_LBLKID) {
+ /*
+ * Blkid needs canonicalized paths, eg. when the /dev/dm-0 is
+ * passed on command line.
+ */
+ canon_path = path_canonicalize(search);
+ search = canon_path;
goto devs_only;
+ }
/* show mounted btrfs */
ret = btrfs_scan_kernel(search, unit_mode);
@@ -850,6 +858,7 @@ devs_only:
free_fs_devices(fs_devices);
}
out:
+ free(canon_path);
if (root)
close_ctree(root);
free_seen_fsid(seen_fsid_hash);