5
0
mirror of git://git.proxmox.com/git/qemu-server.git synced 2025-01-24 02:04:10 +03:00

update_disksize: make interface leaner

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>
This commit is contained in:
Fabian Ebner 2020-05-20 10:20:37 +02:00 committed by Thomas Lamprecht
parent 1c2174833b
commit 9b29cbd0ed
3 changed files with 11 additions and 11 deletions

View 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");
}
});

View 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";
}
});

View 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;