From 3e1f112286dc554bdf245e950b512842e66b70b7 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 11 Sep 2017 08:40:28 +0200 Subject: [PATCH] create_disks: refactor out and improve efidisk creation factor out code in a new create_efidisk submethod, as else this code is hardly readable as the efidisk0 case is a special case. Refer from putting all this specialised handling directly to the much shorter code for all other cases. Also the disk was created with a specific format and then a format detection on the newly created disk was done, which is pretty useless, clear that up. Signed-off-by: Thomas Lamprecht --- PVE/API2/Qemu.pm | 19 +------------------ PVE/QemuServer.pm | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 84340189..1002c875 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -144,24 +144,7 @@ my $create_disks = sub { 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; - $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); - my $path = PVE::Storage::path($storecfg, $volid); - my $efidiskcmd = ['/usr/bin/qemu-img', 'convert', '-n', '-f', 'raw', '-O', $qemufmt]; - push @$efidiskcmd, $ovmfvars; - push @$efidiskcmd, $path; - - PVE::Storage::activate_volumes($storecfg, [$volid]); - - eval { PVE::Tools::run_command($efidiskcmd); }; - my $err = $@; - die "Copying of EFI Vars image failed: $err" if $err; + ($volid, $size) = PVE::QemuServer::create_efidisk($storecfg, $storeid, $vmid, $fmt); } else { $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $size); } diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index b52c93d6..e0c0c509 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -6309,6 +6309,24 @@ sub qemu_use_old_bios_files { return ($use_old_bios_files, $machine_type); } +sub create_efidisk { + my ($storecfg, $storeid, $vmid, $fmt) = @_; + + die "EFI vars default image not found\n" if ! -f $OVMF_VARS; + + my $vars_size = PVE::Tools::convert_size(-s $OVMF_VARS, 'b' => 'kb'); + my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $vars_size); + PVE::Storage::activate_volumes($storecfg, [$volid]); + + my $path = PVE::Storage::path($storecfg, $volid); + eval { + run_command(['/usr/bin/qemu-img', 'convert', '-n', '-f', 'raw', '-O', $fmt, $OVMF_VARS, $path]); + }; + die "Copying EFI vars image failed: $@" if $@; + + return ($volid, $vars_size); +} + sub lspci { my $devices = {}; -- 2.39.5