[pve-devel] [PATCH 2/3] distinguish between rootfs and mp at parse mp

Wolfgang Link w.link at proxmox.com
Fri Jan 15 07:25:09 CET 2016


rootfs need no mp because it is always /
---
 src/PVE/API2/LXC.pm   | 10 +++++++++-
 src/PVE/CLI/pct.pm    |  9 ++++++++-
 src/PVE/LXC.pm        | 25 ++++++++++++++++++-------
 src/PVE/LXC/Create.pm |  2 +-
 4 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 4502c59..f50c372 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1016,7 +1016,15 @@ __PACKAGE__->register_method({
 	    my $running = PVE::LXC::check_running($vmid);
 
 	    my $disk = $param->{disk};
-	    my $mp = PVE::LXC::parse_ct_mountpoint($conf->{$disk});
+
+	    my $mp;
+
+	    if ($disk eq 'rootfs') {
+		$mp = PVE::LXC::parse_ct_mountpoint($conf->{$disk}, undef, 1);
+	    } eles {
+		$mp = PVE::LXC::parse_ct_mountpoint($conf->{$disk});
+	    }
+
 	    my $volid = $mp->{volume};
 
 	    my (undef, undef, $owner, undef, undef, undef, $format) =
diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index 80205bb..123f863 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -165,7 +165,14 @@ __PACKAGE__->register_method ({
 
 	    defined($conf->{$device}) || die "cannot run command on unexisting mountpoint $device\n";
 
-	    my $mount_point = PVE::LXC::parse_ct_mountpoint($conf->{$device});
+	    my $mount_point;
+
+	    if ($device eq 'rootfs') {
+		$mount_point = PVE::LXC::parse_ct_mountpoint($conf->{$device}, undef, 1);
+	    } eles {
+		$mount_point = PVE::LXC::parse_ct_mountpoint($conf->{$device});
+	    }
+
 	    my $volid = $mount_point->{volume};
 
 	    my $path;
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index af3b9b7..33fca55 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -809,7 +809,7 @@ sub vmstatus {
 	    $d->{disk} = 0;
 	    # use 4GB by default ??
 	    if (my $rootfs = $conf->{rootfs}) {
-		my $rootinfo = parse_ct_mountpoint($rootfs);
+		my $rootinfo = parse_ct_mountpoint($rootfs, undef, 1);
 		$d->{maxdisk} = int(($rootinfo->{size} || 4)*1024*1024)*1024;
 	    } else {
 		$d->{maxdisk} = 4*1024*1024*1024;
@@ -911,12 +911,16 @@ sub classify_mountpoint {
 }
 
 sub parse_ct_mountpoint {
-    my ($data, $noerr) = @_;
+    my ($data, $noerr, $rootfs) = @_;
 
     $data //= '';
 
     my $res;
-    eval { $res = PVE::JSONSchema::parse_property_string($mp_desc, $data) };
+    if ( !$rootfs ) {
+	eval { $res = PVE::JSONSchema::parse_property_string($mp_desc, $data) };
+    } else {
+	eval { $res = PVE::JSONSchema::parse_property_string($rootfs_desc, $data) };
+    }
     if ($@) {
 	return undef if $noerr;
 	die $@;
@@ -1120,7 +1124,7 @@ sub update_lxc_config {
     my $shares = $conf->{cpuunits} || 1024;
     $raw .= "lxc.cgroup.cpu.shares = $shares\n";
 
-    my $mountpoint = parse_ct_mountpoint($conf->{rootfs});
+    my $mountpoint = parse_ct_mountpoint($conf->{rootfs}, undef, 1);
     $mountpoint->{mp} = '/';
 
     $raw .= "lxc.rootfs = $dir/rootfs\n";
@@ -1861,7 +1865,7 @@ sub snapshot_delete {
     };
 
     my $rootfs = $conf->{snapshots}->{$snapname}->{rootfs};
-    my $rootinfo = parse_ct_mountpoint($rootfs);
+    my $rootinfo = parse_ct_mountpoint($rootfs, undef, 1);
     my $volid = $rootinfo->{volume};
 
     eval {
@@ -1891,7 +1895,7 @@ sub snapshot_rollback {
     die "snapshot '$snapname' does not exist\n" if !defined($snap);
 
     my $rootfs = $snap->{rootfs};
-    my $rootinfo = parse_ct_mountpoint($rootfs);
+    my $rootinfo = parse_ct_mountpoint($rootfs, undef, 1);
     my $volid = $rootinfo->{volume};
 
     PVE::Storage::volume_rollback_is_possible($storecfg, $volid, $snapname);
@@ -1993,7 +1997,14 @@ sub foreach_mountpoint_full {
     foreach my $key (mountpoint_names($reverse)) {
 	my $value = $conf->{$key};
 	next if !defined($value);
-	my $mountpoint = parse_ct_mountpoint($value, 1);
+	my $mountpoint;
+
+	if ($key eq 'rootfs') {
+	    $mountpoint = parse_ct_mountpoint($value, 1, 1);
+	} else {
+	    $mountpoint = parse_ct_mountpoint($value, 1);
+	}
+
 	next if !defined($mountpoint);
 
 	# just to be sure: rootfs is /
diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index 53bcd2a..321e2b1 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -117,7 +117,7 @@ sub recover_config {
 	delete $conf->{template}; # restored CT is never a template
 	
 	if (defined($conf->{rootfs})) {
-	    my $rootinfo = PVE::LXC::parse_ct_mountpoint($conf->{rootfs});
+	    my $rootinfo = PVE::LXC::parse_ct_mountpoint($conf->{rootfs}, undef, 1);
 	    $disksize = $rootinfo->{size} if defined($rootinfo->{size});
 	}
 	
-- 
2.1.4





More information about the pve-devel mailing list