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

Dominik Csapak d.csapak at proxmox.com
Thu Dec 5 15:38:17 CET 2019


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

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/QemuConfig.pm | 15 ++-------------
 PVE/QemuServer.pm | 23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index f13c7b0..f69b5d8 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -135,21 +135,10 @@ sub __snapshot_save_vmstate {
 
     # first, use explicitly configured storage
     # either directly via API, or via conf
-    my $target = $statestorage // $conf->{vmstatestorage};
+    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 0d0e610..33b1d50 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -7205,6 +7205,29 @@ sub resolve_first_disk {
     return $firstdisk;
 }
 
+sub find_vmstate_storage {
+    my ($conf, $storecfg) = @_;
+
+    # 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