[pve-devel] [PATCH qemu-server v2 1/6] move code of save_vmstate preparation

Dominik Csapak d.csapak at proxmox.com
Wed Mar 13 09:54:59 CET 2019


we will reuse this later

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/QemuConfig.pm | 30 +-----------------------------
 PVE/QemuServer.pm | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index 6ba0cc3..6d7012b 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -118,35 +118,7 @@ sub get_replicatable_volumes {
 sub __snapshot_save_vmstate {
     my ($class, $vmid, $conf, $snapname, $storecfg) = @_;
 
-    my $snap = $conf->{snapshots}->{$snapname};
-
-    # first, use explicitly configured storage
-    my $target = $conf->{vmstatestorage};
-
-    if (!$target) {
-	my ($shared, $local);
-	PVE::QemuServer::foreach_storage_used_by_vm($conf, sub {
-	    my ($sid) = @_;
-	    my $scfg = PVE::Storage::storage_config($storecfg, $sid);
-	    my $dst = $scfg->{shared} ? \$shared : \$local;
-	    $$dst = $sid if !$$dst || $scfg->{path}; # prefer file based storage
-	});
-
-	# second, use shared storage where VM has at least one disk
-	# third, use local storage where VM has at least one disk
-	# fall back to local storage
-	$target = $shared // $local // 'local';
-    }
-
-    my $driver_state_size = 500; # assume 32MB is enough to safe all driver state;
-    # we abort live save after $conf->{memory}, so we need at max twice that space
-    my $size = $conf->{memory}*2 + $driver_state_size;
-
-    my $name = "vm-$vmid-state-$snapname";
-    my $scfg = PVE::Storage::storage_config($storecfg, $target);
-    $name .= ".raw" if $scfg->{path}; # add filename extension for file base storage
-    $snap->{vmstate} = PVE::Storage::vdisk_alloc($storecfg, $target, $vmid, 'raw', $name, $size*1024);
-    $snap->{runningmachine} = PVE::QemuServer::get_current_qemu_machine($vmid);
+    PVE::QemuServer::prepare_save_vmstate($vmid, $conf, $snapname, $storecfg);
 }
 
 sub __snapshot_check_running {
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 546b22e..1d1b687 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -7100,6 +7100,40 @@ sub nbd_stop {
     vm_mon_cmd($vmid, 'nbd-server-stop');
 }
 
+sub prepare_save_vmstate {
+    my ($vmid, $conf, $snapname, $storecfg) = @_;
+
+    my $snap = $conf->{snapshots}->{$snapname};
+
+    # first, use explicitly configured storage
+    my $target = $conf->{vmstatestorage};
+
+    if (!$target) {
+	my ($shared, $local);
+	PVE::QemuServer::foreach_storage_used_by_vm($conf, sub {
+	    my ($sid) = @_;
+	    my $scfg = PVE::Storage::storage_config($storecfg, $sid);
+	    my $dst = $scfg->{shared} ? \$shared : \$local;
+	    $$dst = $sid if !$$dst || $scfg->{path}; # prefer file based storage
+	});
+
+	# second, use shared storage where VM has at least one disk
+	# third, use local storage where VM has at least one disk
+	# fall back to local storage
+	$target = $shared // $local // 'local';
+    }
+
+    my $driver_state_size = 500; # assume 32MB is enough to safe all driver state;
+    # we abort live save after $conf->{memory}, so we need at max twice that space
+    my $size = $conf->{memory}*2 + $driver_state_size;
+
+    my $name = "vm-$vmid-state-$snapname";
+    my $scfg = PVE::Storage::storage_config($storecfg, $target);
+    $name .= ".raw" if $scfg->{path}; # add filename extension for file base storage
+    $snap->{vmstate} = PVE::Storage::vdisk_alloc($storecfg, $target, $vmid, 'raw', $name, $size*1024);
+    $snap->{runningmachine} = PVE::QemuServer::get_current_qemu_machine($vmid);
+}
+
 # bash completion helper
 
 sub complete_backup_archives {
-- 
2.11.0




More information about the pve-devel mailing list