From b276e4bc50b6ca99056a45315ea859c68d58fc1b Mon Sep 17 00:00:00 2001 From: Jeff Mahoney Date: Wed, 4 Jun 2014 16:43:11 -0400 Subject: btrfs-progs: canonicalize pathnames for device commands mount(8) will canonicalize pathnames before passing them to the kernel. Links to e.g. /dev/sda will be resolved to /dev/sda. Links to /dev/dm-# will be resolved using the name of the device mapper table to /dev/mapper/. Btrfs will use whatever name the user passes to it, regardless of whether it is canonical or not. That means that if a 'btrfs device ready' is issued on any device node pointing to the original device, it will adopt the new name instead of the name that was used during mount. Mounting using /dev/sdb2 will result in df: /dev/sdb2 209715200 39328 207577088 1% /mnt lrwxrwxrwx 1 root root 4 Jun 4 13:36 /dev/whatever-i-like -> sdb2 /dev/whatever-i-like 209715200 39328 207577088 1% /mnt Likewise, mounting with /dev/mapper/whatever and using /dev/dm-0 with a btrfs device command results in df showing /dev/dm-0. This can happen with multipath devices with friendly names enabled and doing something like 'partprobe' which (at least with our version) ends up issuing a 'change' uevent on the sysfs node. That *always* uses the dm-# name, and we get confused users. This patch does the same canonicalization of the paths that mount does so that we don't end up having inconsistent names reported by ->show_devices later. Signed-off-by: Jeff Mahoney [use PATH_MAX in canonicalize_dm_name] Signed-off-by: David Sterba --- cmds-replace.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'cmds-replace.c') diff --git a/cmds-replace.c b/cmds-replace.c index 9eb981b..186a127 100644 --- a/cmds-replace.c +++ b/cmds-replace.c @@ -134,7 +134,7 @@ static int cmd_start_replace(int argc, char **argv) int fddstdev = -1; char *path; char *srcdev; - char *dstdev; + char *dstdev = NULL; int avoid_reading_from_srcdev = 0; int force_using_targetdev = 0; struct stat st; @@ -209,7 +209,12 @@ static int cmd_start_replace(int argc, char **argv) } srcdev = argv[optind]; - dstdev = argv[optind + 1]; + dstdev = canonicalize_path(argv[optind + 1]); + if (!dstdev) { + fprintf(stderr, + "ERROR: Could not canonicalize path '%s': %s\n", + argv[optind + 1], strerror(errno)); + } if (is_numerical(srcdev)) { struct btrfs_ioctl_fs_info_args fi_args; @@ -283,6 +288,8 @@ static int cmd_start_replace(int argc, char **argv) close(fddstdev); fddstdev = -1; + free(dstdev); + dstdev = NULL; dev_replace_handle_sigint(fdmnt); if (!do_not_background) { @@ -317,6 +324,8 @@ static int cmd_start_replace(int argc, char **argv) return 0; leave_with_error: + if (dstdev) + free(dstdev); if (fdmnt != -1) close(fdmnt); if (fdsrcdev != -1) -- cgit v1.2.1