mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-10-04 08:42:38 +00:00
refactor finding of vmstate storage
we need that on another place, so refactor in its own sub Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
c3ddb94dc0
commit
66cebc4671
@ -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();
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user