]> git.proxmox.com Git - pve-container.git/commitdiff
Fix #918: add /dev/mapper symlinks for dm-* devices
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 18 Mar 2016 09:11:10 +0000 (10:11 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 18 Mar 2016 15:34:00 +0000 (16:34 +0100)
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
src/lxc-pve-autodev-hook

index 3ed5d92fd5ecaf4acc44a32c8cd2ee1905dcaf7f..3a92f3de06f07ff9a19add1d617a90da00a0b001 100644 (file)
@@ -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) {
index efc82a2dc1901d3f6a0dd10facc24aa1cc4c68f7..2e2f998398900f0d292a12cb1ca8c4023a124f44 100755 (executable)
@@ -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;