This refactoring allows us to use the code that decides which disks will be included in a backup from multiple places and provide a reason for the decision.
Signed-off-by: Aaron Lauterer <a.laute...@proxmox.com> --- PVE/QemuConfig.pm | 30 ++++++++++++++++++++++++++++++ PVE/VZDump/QemuServer.pm | 28 ++++++++++++++-------------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm index 1ba728a..bcf4180 100644 --- a/PVE/QemuConfig.pm +++ b/PVE/QemuConfig.pm @@ -130,6 +130,36 @@ sub get_replicatable_volumes { return $volhash; } +sub get_volumes_backup_status { + my ($class, $conf) = @_; + + my $volhash = {}; + + my $test = sub { + my ($volid, $attr) = @_; + + return if !$volid; + return if PVE::QemuServer::drive_is_cdrom($attr); + + my $status = 1; + my $reason = 'default include'; + + if (exists($attr->{backup}) && !$attr->{backup}) { + $status = 0; + $reason = 'manual'; + } + + $volhash->{$volid}->{included} = $status; + $volhash->{$volid}->{reason} = $reason; + $volhash->{$volid}->{volume} = $attr->{file}; + $volhash->{$volid}->{data} = $attr; + }; + + PVE::QemuServer::foreach_drive($conf, $test); + + return $volhash; +} + sub __snapshot_save_vmstate { my ($class, $vmid, $conf, $snapname, $storecfg, $statestorage, $suspend) = @_; diff --git a/PVE/VZDump/QemuServer.pm b/PVE/VZDump/QemuServer.pm index 3d9c61a..0336ade 100644 --- a/PVE/VZDump/QemuServer.pm +++ b/PVE/VZDump/QemuServer.pm @@ -69,34 +69,34 @@ sub prepare { my $vollist = []; my $drivehash = {}; - PVE::QemuServer::foreach_drive($conf, sub { - my ($ds, $drive) = @_; + my $backup_status = PVE::QemuConfig->get_volumes_backup_status($conf); - return if PVE::QemuServer::drive_is_cdrom($drive); + foreach my $name (sort keys %{$backup_status}) { + my $disk = $backup_status->{$name}; - my $volid = $drive->{file}; + my $volid = $disk->{data}->{file}; - if (defined($drive->{backup}) && !$drive->{backup}) { - $self->loginfo("exclude disk '$ds' '$volid' (backup=no)"); + if (exists $disk->{included} && !$disk->{included}) { + $self->loginfo("exclude disk '$name' '$volid' (backup=no)"); return; - } elsif ($self->{vm_was_running} && $drive->{iothread}) { + } elsif ($self->{vm_was_running} && $disk->{data}->{iothread}) { if (!PVE::QemuServer::Machine::runs_at_least_qemu_version($vmid, 4, 0, 1)) { - die "disk '$ds' '$volid' (iothread=on) can't use backup feature with running QEMU " . + die "disk '$name' '$volid' (iothread=on) can't use backup feature with running QEMU " . "version < 4.0.1! Either set backup=no for this drive or upgrade QEMU and restart VM\n"; } } else { - my $log = "include disk '$ds' '$volid'"; - if (defined $drive->{size}) { - my $readable_size = PVE::JSONSchema::format_size($drive->{size}); + my $log = "include disk '$name' '$volid'"; + if (defined $disk->{data}->{size}) { + my $readable_size = PVE::JSONSchema::format_size($disk->{data}->{size}); $log .= " $readable_size"; - } + } $self->loginfo($log); } my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1); push @$vollist, $volid if $storeid; - $drivehash->{$ds} = $drive; - }); + $drivehash->{$name} = $disk->{data}; + } PVE::Storage::activate_volumes($self->{storecfg}, $vollist); -- 2.20.1 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel