[pve-devel] [PATCH container] pct mount: add --snapshot option

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Aug 11 11:56:55 CEST 2016


Mounts an existing snapshot instead of the current state.
---
Useful for testing storage implementations ;-)

 src/PVE/CLI/pct.pm | 17 ++++++++++++++++-
 src/PVE/LXC.pm     |  6 +++---
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index cf4a014..8ea23b6 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -278,6 +278,11 @@ __PACKAGE__->register_method({
 	additionalProperties => 0,
 	properties => {
 	    vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
+	    snapshot => {
+		type => 'string',
+		optional => 1,
+		description => "The snapshot to mount.",
+	    },
 	},
     },
     returns => { type => 'null' },
@@ -290,7 +295,17 @@ __PACKAGE__->register_method({
 	my $storecfg = PVE::Storage::config();
 	PVE::LXC::Config->lock_config($vmid, sub {
 	    my $conf = PVE::LXC::Config->set_lock($vmid, 'mounted');
-	    PVE::LXC::mount_all($vmid, $storecfg, $conf);
+
+	    my $snapshot = extract_param($param, 'snapshot');
+
+	    if ($snapshot) {
+		my $snaps = $conf->{snapshots}
+		    or die "No snapshots available\n";
+		$conf = $snaps->{$snapshot}
+		    or die "No such snapshot: $snapshot\n";
+	    }
+
+	    PVE::LXC::mount_all($vmid, $storecfg, $conf, 0, $snapshot);
 	});
 	return undef;
     }});
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 35ce796..b07c198 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -923,13 +923,13 @@ sub umount_all {
 }
 
 sub mount_all {
-    my ($vmid, $storage_cfg, $conf, $ignore_ro) = @_;
+    my ($vmid, $storage_cfg, $conf, $ignore_ro, $snapshot) = @_;
 
     my $rootdir = "/var/lib/lxc/$vmid/rootfs";
     File::Path::make_path($rootdir);
 
     my $volid_list = PVE::LXC::Config->get_vm_volumes($conf);
-    PVE::Storage::activate_volumes($storage_cfg, $volid_list);
+    PVE::Storage::activate_volumes($storage_cfg, $volid_list, $snapshot);
 
     eval {
 	PVE::LXC::Config->foreach_mountpoint($conf, sub {
@@ -937,7 +937,7 @@ sub mount_all {
 
 	    $mountpoint->{ro} = 0 if $ignore_ro;
 
-	    mountpoint_mount($mountpoint, $rootdir, $storage_cfg);
+	    mountpoint_mount($mountpoint, $rootdir, $storage_cfg, $snapshot);
         });
     };
     if (my $err = $@) {
-- 
2.1.4





More information about the pve-devel mailing list