From ada088e6279ddb5471d27afcd760d99743f16aaa Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 18 Mar 2016 10:11:10 +0100 Subject: [PATCH] Fix #918: add /dev/mapper symlinks for dm-* devices Mount canonicalizes paths unless the -c option is used. This is mostly fine but for device-mapper nodes (/dev/dm-*) it'll fetch the /dev/mapper/* path and pass that to the mount system call resulting in /proc/mounts showing the /dev/mapper path. This is neither the one we provided (since we use /dev/$vg/$lv), nor the one userspace tools will find in /dev currently. Since the dm-* paths are rather inconvenient to look at we decided to keep mount's behavior and compensate by providing the /dev/mapper symlinks for devices via the autodev hook. --- src/PVE/LXC.pm | 5 +++++ src/lxc-pve-autodev-hook | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 3ed5d92..3a92f3d 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -1073,6 +1073,11 @@ sub mountpoint_mount { } return wantarray ? ($path, 0, undef) : $path; } elsif ($format eq 'raw' || $format eq 'iso') { + # NOTE: 'mount' performs canonicalization without the '-c' switch, which for + # device-mapper devices is special-cased to use the /dev/mapper symlinks. + # Our autodev hook expects the /dev/dm-* device currently + # and will create the /dev/mapper symlink accordingly + ($path) = (Cwd::realpath($path) =~ /^(.*)$/s); # realpath() taints my $domount = sub { my ($path) = @_; if ($mount_path) { diff --git a/src/lxc-pve-autodev-hook b/src/lxc-pve-autodev-hook index efc82a2..2e2f998 100755 --- a/src/lxc-pve-autodev-hook +++ b/src/lxc-pve-autodev-hook @@ -53,6 +53,13 @@ while (defined(my $line = <$fd>)) { PVE::Tools::run_command(['mknod', '-m', '666', "$root/dev/$dev", $type, $major, $minor]); + + if ($dev =~ /^dm-\d+$/) { + File::Path::mkpath("$root/dev/mapper"); + my $mapped_name = PVE::Tools::file_get_contents("/sys/block/$dev/dm/name"); + chomp $mapped_name; + symlink("/dev/$dev", "$root/dev/mapper/$mapped_name"); + } } close $fd; -- 2.39.2