]> git.proxmox.com Git - qemu-server.git/commitdiff
update_disksize: make interface leaner
authorFabian Ebner <f.ebner@proxmox.com>
Wed, 20 May 2020 08:20:37 +0000 (10:20 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 1 Jul 2020 07:18:13 +0000 (09:18 +0200)
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.ebner@proxmox.com>
PVE/QemuMigrate.pm
PVE/QemuServer.pm
PVE/QemuServer/Drive.pm

index f6baedaf696c4ee4e5816f4a97d0777aacf247e7..96de0dbf1b53d8dad5f69831aaf72e83a1fac4b7 100644 (file)
@@ -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");
            }
        });
 
index 1abe64b9440e9acf85703b402a08b3f2793709ec..6872e061ab1cc90a65328412905d99e0d2415454 100644 (file)
@@ -5804,7 +5804,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 = {};
@@ -5832,11 +5832,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";
        }
     });
 
index f84333f5b2ea5ccd0802f0001ecc9d9269f9906c..91c33f86e0e505f17a09b19aa33650283cd87bee 100644 (file)
@@ -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;