]> git.proxmox.com Git - qemu-server.git/commitdiff
create_disks: refactor out and improve efidisk creation
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 11 Sep 2017 06:40:28 +0000 (08:40 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 11 Sep 2017 08:04:46 +0000 (10:04 +0200)
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 <t.lamprecht@proxmox.com>
PVE/API2/Qemu.pm
PVE/QemuServer.pm

index 8434018992a7c4fa563c9e7db9969faebaa053e1..1002c8755bf555a7d0a44bccd216b07b8d91b505 100644 (file)
@@ -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);
            }
index b52c93d67f2d09957fdf9d618e7fc1c29c5b2215..e0c0c50982b85d16e79a4787bfcf93e11a9c859a 100644 (file)
@@ -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 = {};