Pass new size directly, so the function doesn't need to know about
how some hash is organized. And return a message directly, instead
of both size-strings. Also dropped the wantarray, because both
existing callers use the message anyways.

Signed-off-by: Fabian Ebner <f.eb...@proxmox.com>
---
 PVE/QemuMigrate.pm      |  5 +++--
 PVE/QemuServer.pm       |  6 +++---
 PVE/QemuServer/Drive.pm | 11 +++++------
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index f6baeda..96de0db 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -522,11 +522,12 @@ sub sync_disks {
 
            my $volid = $drive->{file};
            return if !defined($local_volumes->{$volid}); # only update sizes 
for local volumes
+           return if !defined($volid_hash->{$volid});
 
-           my ($updated, $old_size, $new_size) = 
PVE::QemuServer::Drive::update_disksize($drive, $volid_hash);
+           my ($updated, $msg) = 
PVE::QemuServer::Drive::update_disksize($drive, $volid_hash->{$volid}->{size});
            if (defined($updated)) {
                $conf->{$key} = PVE::QemuServer::print_drive($updated);
-               $self->log('info', "size of disk '$updated->{file}' ($key) 
updated from $old_size to $new_size\n");
+               $self->log('info', "drive '$key': $msg");
            }
        });
 
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index dcf05df..506f6fb 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5932,7 +5932,7 @@ sub update_disk_config {
     my ($vmid, $conf, $volid_hash) = @_;
 
     my $changes;
-    my $prefix = "VM $vmid:";
+    my $prefix = "VM $vmid";
 
     # used and unused disks
     my $referenced = {};
@@ -5960,11 +5960,11 @@ sub update_disk_config {
        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);
+       my ($updated, $msg) = PVE::QemuServer::Drive::update_disksize($drive, 
$volid_hash->{$volid}->{size});
        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";
+           print "$prefix ($opt): $msg\n";
        }
     });
 
diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm
index f84333f..91c33f8 100644
--- a/PVE/QemuServer/Drive.pm
+++ b/PVE/QemuServer/Drive.pm
@@ -522,14 +522,11 @@ sub bootdisk_size {
 }
 
 sub update_disksize {
-    my ($drive, $volid_hash) = @_;
+    my ($drive, $newsize) = @_;
 
-    my $volid = $drive->{file};
-    return undef if !defined($volid);
-    return undef if !defined($volid_hash->{$volid}) || 
!defined($volid_hash->{$volid}->{size});
+    return undef if !defined($newsize);
 
     my $oldsize = $drive->{size} // 0;
-    my $newsize = $volid_hash->{$volid}->{size};
 
     if ($newsize != $oldsize) {
        $drive->{size} = $newsize;
@@ -537,7 +534,9 @@ sub update_disksize {
        my $old_fmt = PVE::JSONSchema::format_size($oldsize);
        my $new_fmt = PVE::JSONSchema::format_size($newsize);
 
-       return wantarray ? ($drive, $old_fmt, $new_fmt) : $drive;
+       my $msg = "size of disk '$drive->{file}' updated from $old_fmt to 
$new_fmt";
+
+       return ($drive, $msg);
     }
 
     return undef;
-- 
2.20.1


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to