[pve-devel] [PATCH v3 qemu-server 21/22] update_disk_config: use config volume iterators instead of loops
Fabian Ebner
f.ebner at proxmox.com
Thu Mar 12 13:08:31 CET 2020
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
PVE/QemuServer.pm | 50 ++++++++++++++++++++++++-----------------------
1 file changed, 26 insertions(+), 24 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index ee99b26..b38b8dd 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5571,35 +5571,37 @@ sub update_disk_config {
my $referencedpath = {};
# update size info
- foreach my $opt (keys %$conf) {
- if (is_valid_drivename($opt)) {
- my $drive = parse_drive($opt, $conf->{$opt});
- my $volid = $drive->{file};
- next if !$volid;
+ PVE::QemuConfig->foreach_volume($conf, undef, sub {
+ my ($opt, $drive) = @_;
- # mark volid as "in-use" for next step
- $referenced->{$volid} = 1;
- if ($volid_hash->{$volid} &&
- (my $path = $volid_hash->{$volid}->{path})) {
- $referencedpath->{$path} = 1;
- }
+ my $volid = $drive->{file};
+ return if !$volid;
- next if drive_is_cdrom($drive);
- next if !$volid_hash->{$volid};
+ # mark volid as "in-use" for next step
+ $referenced->{$volid} = 1;
+ if ($volid_hash->{$volid} &&
+ (my $path = $volid_hash->{$volid}->{path})) {
+ $referencedpath->{$path} = 1;
+ }
- my ($updated, $old_size, $new_size) = PVE::QemuServer::Drive::update_disksize($drive, $volid_hash);
- if (defined($updated)) {
- $changes = 1;
- $conf->{$opt} = print_drive($updated);
- print "$prefix size of disk '$volid' ($opt) updated from $old_size to $new_size\n";
- }
+ return if drive_is_cdrom($drive);
+ return if !$volid_hash->{$volid};
+
+ my ($updated, $old_size, $new_size) = PVE::QemuServer::Drive::update_disksize($drive, $volid_hash);
+ if (defined($updated)) {
+ $changes = 1;
+ $conf->{$opt} = print_drive($updated);
+ print "$prefix size of disk '$volid' ($opt) updated from $old_size to $new_size\n";
}
- }
+ });
# remove 'unusedX' entry if volume is used
- foreach my $opt (keys %$conf) {
- next if $opt !~ m/^unused\d+$/;
- my $volid = $conf->{$opt};
+ PVE::QemuConfig->foreach_unused_volume($conf, sub {
+ my ($opt, $drive) = @_;
+
+ my $volid = $drive->{file};
+ return if !$volid;
+
my $path = $volid_hash->{$volid}->{path} if $volid_hash->{$volid};
if ($referenced->{$volid} || ($path && $referencedpath->{$path})) {
print "$prefix remove entry '$opt', its volume '$volid' is in use\n";
@@ -5609,7 +5611,7 @@ sub update_disk_config {
$referenced->{$volid} = 1;
$referencedpath->{$path} = 1 if $path;
- }
+ });
foreach my $volid (sort keys %$volid_hash) {
next if $volid =~ m/vm-$vmid-state-/;
--
2.20.1
More information about the pve-devel
mailing list