From a1d8c038c58137050c29b697d6d80de902a59892 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 11 Sep 2017 08:40:27 +0200 Subject: [PATCH] efidisk: do not hard code efivar base image size The size of this image is not fixed, it increased to 528k in more recent build of OVMF and could increase further (not likely, but possible). Instead of changing the hardcoded value move to a more generic approach and read the size from the base image at creation time. Use the new convert_size method and generalise the assignment of size and volid between the efidisk and the normal case, as a part of this change. Signed-off-by: Thomas Lamprecht --- PVE/API2/Qemu.pm | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 747172e2..84340189 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -140,15 +140,15 @@ my $create_disks = sub { my $defformat = PVE::Storage::storage_default_format($storecfg, $storeid); my $fmt = $disk->{format} || $defformat; + $size = PVE::Tools::convert_size($size, 'gb' => 'kb'); # vdisk_alloc uses kb + my $volid; if ($ds eq 'efidisk0') { # handle efidisk my $ovmfvars = '/usr/share/kvm/OVMF_VARS-pure-efi.fd'; die "uefi vars image not found\n" if ! -f $ovmfvars; - $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, - $fmt, undef, 128); - $disk->{file} = $volid; - $disk->{size} = 128*1024; + $size = PVE::Tools::convert_size(-s $ovmfvars, 'b' => 'kb'); + $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $size); my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid); my $scfg = PVE::Storage::storage_config($storecfg, $storeid); my $qemufmt = PVE::QemuServer::qemu_img_format($scfg, $volname); @@ -163,12 +163,11 @@ my $create_disks = sub { my $err = $@; die "Copying of EFI Vars image failed: $err" if $err; } else { - $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, - $fmt, undef, $size*1024*1024); - $disk->{file} = $volid; - $disk->{size} = $size*1024*1024*1024; + $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $size); } push @$vollist, $volid; + $disk->{file} = $volid; + $disk->{size} = PVE::Tools::convert_size($size, 'kb' => 'b'); delete $disk->{format}; # no longer needed $res->{$ds} = PVE::QemuServer::print_drive($vmid, $disk); } else { -- 2.39.5