[pve-devel] [PATCH v4 qemu-server 07/27] update_disk_config: use config volume iterators instead of loops
Fabian Ebner
f.ebner at proxmox.com
Thu Mar 26 09:09:37 CET 2020
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
PVE/QemuServer.pm | 52 ++++++++++++++++++++++++-----------------------
1 file changed, 27 insertions(+), 25 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index a3e3269..3a8f52d 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5753,35 +5753,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;
-
- # mark volid as "in-use" for next step
- $referenced->{$volid} = 1;
- if ($volid_hash->{$volid} &&
- (my $path = $volid_hash->{$volid}->{path})) {
- $referencedpath->{$path} = 1;
- }
+ PVE::QemuConfig->foreach_volume($conf, undef, sub {
+ my ($opt, $drive) = @_;
- next if drive_is_cdrom($drive);
- next if !$volid_hash->{$volid};
+ my $volid = $drive->{file};
+ return if !$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";
- }
+ # mark volid as "in-use" for next step
+ $referenced->{$volid} = 1;
+ if ($volid_hash->{$volid} &&
+ (my $path = $volid_hash->{$volid}->{path})) {
+ $referencedpath->{$path} = 1;
}
- }
+
+ 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";
@@ -5791,7 +5793,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