5
0
mirror of git://git.proxmox.com/git/qemu-server.git synced 2025-01-08 21:18:03 +03:00

Include vmstate and unused volumes in foreach_volid

and refactor the test_volid closure. Like this get_replicatable_volumes doesn't
need a separate loop for unused volumes anymore. For get_vm_volumes, which is used
for activation/deactivation of volumes at migration and deactivation in vm_stop_cleanup,
includes those volumes now. For migration it's an improvement, because those volumes
might need to be migrated and for vm_stop_cleanup it shouldn't hurt. The last user
of foreach_volid is check_vm_disks_local used by migrate_vm_precondition,
where information about the additional volumes doesn't hurt either.

Note that replicate is (still) set by default, so the behavior for
get_replicatable_volumes for unused volumes should not change.

Hibernation vmstate files are now also included and recognized as 'is_vmstate'.
The 'size' attribute will not be overwritten by subsequent iterations for the
same volid anymore (a volid may appear both in the config and in snapshots),
so the size from the current config is now preferred.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fabian Ebner 2020-04-16 14:54:43 +02:00 committed by Thomas Lamprecht
parent b24f07d406
commit ae180b8f08
3 changed files with 24 additions and 17 deletions

View File

@ -162,13 +162,6 @@ sub get_replicatable_volumes {
PVE::QemuServer::foreach_volid($conf, $test_volid);
# add 'unusedX' volumes to volhash
foreach my $key (keys %$conf) {
if ($key =~ m/^unused/) {
$test_volid->($conf->{$key}, { replicate => 1 });
}
}
return $volhash;
}

View File

@ -388,6 +388,7 @@ sub sync_disks {
return if $scfg->{shared};
$local_volumes->{$volid}->{ref} = $attr->{referenced_in_config} ? 'config' : 'snapshot';
$local_volumes->{$volid}->{ref} = 'storage' if $attr->{is_unused};
$local_volumes->{$volid}->{is_vmstate} = $attr->{is_vmstate} ? 1 : 0;

View File

@ -4303,39 +4303,52 @@ sub foreach_volid {
my $volhash = {};
my $test_volid = sub {
my ($volid, $is_cdrom, $replicate, $shared, $snapname, $size) = @_;
my ($key, $drive, $snapname) = @_;
my $volid = $drive->{file};
return if !$volid;
$volhash->{$volid}->{cdrom} //= 1;
$volhash->{$volid}->{cdrom} = 0 if !$is_cdrom;
$volhash->{$volid}->{cdrom} = 0 if !drive_is_cdrom($drive);
my $replicate = $drive->{replicate} // 1;
$volhash->{$volid}->{replicate} //= 0;
$volhash->{$volid}->{replicate} = 1 if $replicate;
$volhash->{$volid}->{shared} //= 0;
$volhash->{$volid}->{shared} = 1 if $shared;
$volhash->{$volid}->{shared} = 1 if $drive->{shared};
$volhash->{$volid}->{referenced_in_config} //= 0;
$volhash->{$volid}->{referenced_in_config} = 1 if !defined($snapname);
$volhash->{$volid}->{referenced_in_snapshot}->{$snapname} = 1
if defined($snapname);
$volhash->{$volid}->{size} = $size if $size;
my $size = $drive->{size};
$volhash->{$volid}->{size} //= $size if $size;
$volhash->{$volid}->{is_vmstate} //= 0;
$volhash->{$volid}->{is_vmstate} = 1 if $key eq 'vmstate';
$volhash->{$volid}->{is_unused} //= 0;
$volhash->{$volid}->{is_unused} = 1 if $key =~ /^unused\d+$/;
};
PVE::QemuConfig->foreach_volume($conf, sub {
my $include_opts = {
extra_keys => ['vmstate'],
include_unused => 1,
};
PVE::QemuConfig->foreach_volume_full($conf, $include_opts, sub {
my ($ds, $drive) = @_;
$test_volid->($drive->{file}, drive_is_cdrom($drive), $drive->{replicate} // 1, $drive->{shared}, undef, $drive->{size});
$test_volid->($ds, $drive);
});
foreach my $snapname (keys %{$conf->{snapshots}}) {
my $snap = $conf->{snapshots}->{$snapname};
$test_volid->($snap->{vmstate}, 0, 1, 0, $snapname);
$volhash->{$snap->{vmstate}}->{is_vmstate} = 1 if $snap->{vmstate};
PVE::QemuConfig->foreach_volume($snap, sub {
PVE::QemuConfig->foreach_volume_full($snap, $include_opts, sub {
my ($ds, $drive) = @_;
$test_volid->($drive->{file}, drive_is_cdrom($drive), $drive->{replicate} // 1, $drive->{shared}, $snapname);
$test_volid->($ds, $drive, $snapname);
});
}