[pve-devel] [PATCH container 4/4] Fix #918: add /dev/mapper symlinks for dm-* devices
Wolfgang Bumiller
w.bumiller at proxmox.com
Fri Mar 18 10:11:10 CET 2016
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.1.4
More information about the pve-devel
mailing list