]> git.proxmox.com Git - qemu-server.git/commitdiff
Refactor snapshot code
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Mon, 15 Feb 2016 08:52:57 +0000 (09:52 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 15 Feb 2016 12:26:28 +0000 (13:26 +0100)
Split vmstate saving into its own sub in preparation of
LXC/QemuServer codebase refactoring.

PVE/QemuServer.pm

index bfce953b93ff405f62b241526e782681ce037193..223c2b7dd909aa9899a19cc9e15f0ddd47b73e14 100644 (file)
@@ -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);
+};
+
 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);
     };