]> git.proxmox.com Git - qemu-server.git/commitdiff
efidisk: do not hard code efivar base image size
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 11 Sep 2017 06:40:27 +0000 (08:40 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 11 Sep 2017 08:04:46 +0000 (10:04 +0200)
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 <t.lamprecht@proxmox.com>
PVE/API2/Qemu.pm

index 747172e21adbb73e23f3d45d7ac4316119755ccc..8434018992a7c4fa563c9e7db9969faebaa053e1 100644 (file)
@@ -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 {