]> git.proxmox.com Git - qemu-server.git/commitdiff
refactor finding of vmstate storage
authorDominik Csapak <d.csapak@proxmox.com>
Mon, 9 Dec 2019 14:26:58 +0000 (15:26 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 11 Dec 2019 08:02:55 +0000 (09:02 +0100)
we need that on another place, so refactor in its own sub

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/QemuConfig.pm
PVE/QemuServer.pm

index f13c7b05982940351a5e6029ba9b477113ed6765..1ba728ad774676b810b201d64652c413bd0f507d 100644 (file)
@@ -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();
index 0b4c597368ff0c0fc5554b9c5ba888ef1a9b507f..7bcdb61a23459caf537dde55904a3011a23b724b 100644 (file)
@@ -7210,6 +7210,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);