[pve-devel] [PATCH pve-container 1/7] introduce internal mountpont 'type' property

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Nov 25 15:25:11 CET 2015


To avoid having to use the ^/ and ^/dev/ regexes which are
easy to forget about there's now a 'type' property on
mountpoints which classify them via names, for now including
"volume", "bind" and "device".
---
 src/PVE/LXC.pm        | 33 +++++++++++++++++++++------------
 src/PVE/VZDump/LXC.pm |  3 ++-
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 6775fe3..e5eee29 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -902,6 +902,15 @@ sub vmstatus {
     return $list;
 }
 
+sub classify_mountpoint {
+    my ($vol) = @_;
+    if ($vol =~ m!^/!) {
+	return 'device' if $vol =~ m!^/dev/!;
+	return 'bind';
+    }
+    return 'volume';
+}
+
 sub parse_ct_mountpoint {
     my ($data, $noerr) = @_;
 
@@ -923,12 +932,15 @@ sub parse_ct_mountpoint {
 	$res->{size} = $size;
     }
 
+    $res->{type} = classify_mountpoint($res->{volume});
+
     return $res;
 }
 
 sub print_ct_mountpoint {
     my ($info, $nomp) = @_;
-    my $skip = $nomp ? ['mp'] : [];
+    my $skip = [ 'type' ];
+    push @$skip, 'mp' if $nomp;
     return PVE::JSONSchema::print_property_string($info, $mp_desc, $skip);
 }
 
@@ -1172,9 +1184,6 @@ sub verify_searchdomain_list {
 sub add_unused_volume {
     my ($config, $volid) = @_;
 
-    # skip bind mounts and block devices
-    return if $volid =~ m|^/|;
-
     my $key;
     for (my $ind = $MAX_UNUSED_DISKS - 1; $ind >= 0; $ind--) {
 	my $test = "unused$ind";
@@ -1244,7 +1253,9 @@ sub update_pct_config {
 		next if $hotplug_error->($opt);
 		check_protection($conf, "can't remove CT $vmid drive '$opt'");
 		my $mountpoint = parse_ct_mountpoint($conf->{$opt});
-		add_unused_volume($conf, $mountpoint->{volume});
+		if ($mountpoint->{type} eq 'volume') {
+		    add_unused_volume($conf, $mountpoint->{volume})
+		}
 		delete $conf->{$opt};
 	    } elsif ($opt eq 'unprivileged') {
 		die "unable to delete read-only option: '$opt'\n";
@@ -1411,10 +1422,7 @@ sub get_primary_ips {
 sub delete_mountpoint_volume {
     my ($storage_cfg, $vmid, $volume) = @_;
 
-    # skip bind mounts and block devices
-    if ($volume =~ m|^/|) {
-	    return;
-    }
+    return if classify_mountpoint($volume) ne 'volume';
 
     my ($vtype, $name, $owner) = PVE::Storage::parse_volname($storage_cfg, $volume);
     PVE::Storage::vdisk_free($storage_cfg, $volume) if $vmid == $owner;
@@ -2115,6 +2123,7 @@ sub mountpoint_mount {
 
     my $volid = $mountpoint->{volume};
     my $mount = $mountpoint->{mp};
+    my $type = $mountpoint->{type};
     
     return if !$volid || !$mount;
 
@@ -2176,10 +2185,10 @@ sub mountpoint_mount {
 	} else {
 	    die "unsupported image format '$format'\n";
 	}
-    } elsif ($volid =~ m|^/dev/.+|) {
+    } elsif ($type eq 'device') {
 	PVE::Tools::run_command(['mount', $volid, $mount_path]) if $mount_path;
 	return wantarray ? ($volid, 0) : $volid;
-    } elsif ($volid !~ m|^/dev/.+| && $volid =~ m|^/.+| && -d $volid) {
+    } elsif ($type eq 'bind' && -d $volid) {
 	&$check_mount_path($volid);
 	PVE::Tools::run_command(['mount', '-o', 'bind', $volid, $mount_path]) if $mount_path;
 	return wantarray ? ($volid, 0) : $volid;
@@ -2200,7 +2209,7 @@ sub get_vm_volumes {
 
 	my $volid = $mountpoint->{volume};
 
-        return if !$volid || $volid =~ m|^/|;
+        return if !$volid || $mountpoint->{type} ne 'volume';
 
         my ($sid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
         return if !$sid;
diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index 1c2e782..33b5c07 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -114,8 +114,9 @@ sub prepare {
 	my ($name, $data) = @_;
 	my $volid = $data->{volume};
 	my $mount = $data->{mp};
+	my $type = $data->{type};
 
-	return if !$volid || !$mount || $volid =~ m|^/|;
+	return if !$volid || !$mount || $type ne 'volume';
 
 	if ($name ne 'rootfs' && !$data->{backup}) {
 	    push @$exclude_dirs, $mount;
-- 
2.1.4





More information about the pve-devel mailing list