[pve-devel] [PATCH qemu-server v2 1/3] refactor finding of vmstate storage

Dominik Csapak d.csapak at proxmox.com
Mon Dec 9 15:26:58 CET 2019


we need that on another place, so refactor in its own sub

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* improved comments

 PVE/QemuConfig.pm | 18 +++---------------
 PVE/QemuServer.pm | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index f13c7b0..1ba728a 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -133,23 +133,11 @@ sub get_replicatable_volumes {
 sub __snapshot_save_vmstate {
     my ($class, $vmid, $conf, $snapname, $storecfg, $statestorage, $suspend) = @_;
 
-    # first, use explicitly configured storage
-    # either directly via API, or via conf
-    my $target = $statestorage // $conf->{vmstatestorage};
+    # use given storage or search for one from the config
+    my $target = $statestorage;
 
     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';
+	$target = PVE::QemuServer::find_vmstate_storage($conf, $storecfg);
     }
 
     my $defaults = PVE::QemuServer::load_defaults();
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index e10461f..38287c2 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -7201,6 +7201,30 @@ sub resolve_first_disk {
     return $firstdisk;
 }
 
+# NOTE: if this logic changes, please update docs & possibly gui logic
+sub find_vmstate_storage {
+    my ($conf, $storecfg) = @_;
+
+    # first, return storage from conf if set
+    return $conf->{vmstatestorage} if $conf->{vmstatestorage};
+
+    my ($target, $shared, $local);
+
+    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';
+
+    return $target;
+}
+
 sub generate_uuid {
     my ($uuid, $uuid_str);
     UUID::generate($uuid);
-- 
2.20.1





More information about the pve-devel mailing list