[pve-devel] [PATCH qemu-server] Refactor snapshot code

Fabian Grünbichler f.gruenbichler at proxmox.com
Mon Feb 15 09:52:57 CET 2016


Split vmstate saving into its own sub in preparation of
LXC/QemuServer codebase refactoring.
---
 PVE/QemuServer.pm | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 1139438..fa71275 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5908,6 +5908,17 @@ my $alloc_vmstate_volid = sub {
     return $volid;
 };
 
+my $snapshot_save_vmstate = sub {
+    my ($vmid, $conf, $snapname, $storecfg) = @_;
+
+    my $snap = $conf->{snapshots}->{$snapname};
+
+    $snap->{vmstate} = &$alloc_vmstate_volid($storecfg, $vmid, $conf, $snapname);
+    # always overwrite machine if we save vmstate. This makes sure we
+    # can restore it later using correct machine type
+    $snap->{machine} = get_current_qemu_machine($vmid) if $snap->{vmstate};
+};
+
 my $snapshot_prepare = sub {
     my ($vmid, $snapname, $save_vmstate, $comment) = @_;
 
@@ -5928,12 +5939,12 @@ my $snapshot_prepare = sub {
 	    if defined($conf->{snapshots}->{$snapname});
 
 	my $storecfg = PVE::Storage::config();
-	die "snapshot feature is not available" if !has_feature('snapshot', $conf, $storecfg);
+	die "snapshot feature is not available\n" if !has_feature('snapshot', $conf, $storecfg);
 
 	$snap = $conf->{snapshots}->{$snapname} = {};
 
 	if ($save_vmstate && check_running($vmid)) {
-	    $snap->{vmstate} = &$alloc_vmstate_volid($storecfg, $vmid, $conf, $snapname);
+	    &$snapshot_save_vmstate($vmid, $conf, $snapname, $storecfg);
 	}
 
 	&$snapshot_copy_config($conf, $snap);
@@ -5942,9 +5953,6 @@ my $snapshot_prepare = sub {
 	$snap->{snaptime} = time();
 	$snap->{description} = $comment if $comment;
 
-	# always overwrite machine if we save vmstate. This makes sure we
-	# can restore it later using correct machine type
-	$snap->{machine} = get_current_qemu_machine($vmid) if $snap->{vmstate};
 	write_config($vmid, $conf);
     };
 
-- 
2.1.4





More information about the pve-devel mailing list