mirror of
git://git.proxmox.com/git/qemu-server.git
synced 2025-01-10 01:18:01 +03:00
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 <t.lamprecht@proxmox.com>
This commit is contained in:
parent
a1d8c038c5
commit
3e1f112286
@ -144,24 +144,7 @@ my $create_disks = sub {
|
|||||||
|
|
||||||
my $volid;
|
my $volid;
|
||||||
if ($ds eq 'efidisk0') {
|
if ($ds eq 'efidisk0') {
|
||||||
# handle efidisk
|
($volid, $size) = PVE::QemuServer::create_efidisk($storecfg, $storeid, $vmid, $fmt);
|
||||||
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;
|
|
||||||
} else {
|
} else {
|
||||||
$volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $size);
|
$volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $size);
|
||||||
}
|
}
|
||||||
|
@ -6309,6 +6309,24 @@ sub qemu_use_old_bios_files {
|
|||||||
return ($use_old_bios_files, $machine_type);
|
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 {
|
sub lspci {
|
||||||
|
|
||||||
my $devices = {};
|
my $devices = {};
|
||||||
|
Loading…
Reference in New Issue
Block a user