ovmf cmd assembly: rework now that it's in a separate method

We can now do a few things that would be not really possible, or at
least mess with readability when this was still mostly inline
config2command, shaves of quite a few lines of code.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-12-12 11:35:19 +01:00
parent 2ceb59d4b1
commit 3d07669cf1

View File

@ -3517,63 +3517,42 @@ my sub should_disable_smm {
my sub print_ovmf_drive_commandlines { my sub print_ovmf_drive_commandlines {
my ($conf, $storecfg, $vmid, $arch, $q35, $version_guard) = @_; my ($conf, $storecfg, $vmid, $arch, $q35, $version_guard) = @_;
my $d; my $d = $conf->{efidisk0} ? parse_drive('efidisk0', $conf->{efidisk0}) : undef;
if (my $efidisk = $conf->{efidisk0}) {
$d = parse_drive('efidisk0', $efidisk);
}
my ($ovmf_code, $ovmf_vars) = get_ovmf_files($arch, $d, $q35); my ($ovmf_code, $ovmf_vars) = get_ovmf_files($arch, $d, $q35);
die "uefi base image '$ovmf_code' not found\n" if ! -f $ovmf_code; die "uefi base image '$ovmf_code' not found\n" if ! -f $ovmf_code;
my ($path, $format); my $var_drive_str = "if=pflash,unit=1,id=drive-efidisk0";
my $read_only_str = '';
if ($d) { if ($d) {
my ($storeid, $volname) = PVE::Storage::parse_volume_id($d->{file}, 1); my ($storeid, $volname) = PVE::Storage::parse_volume_id($d->{file}, 1);
$format = $d->{format}; my ($path, $format) = $d->@{'file', 'format'};
if ($storeid) { if ($storeid) {
$path = PVE::Storage::path($storecfg, $d->{file}); $path = PVE::Storage::path($storecfg, $d->{file});
if (!defined($format)) { if (!defined($format)) {
my $scfg = PVE::Storage::storage_config($storecfg, $storeid); my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
$format = qemu_img_format($scfg, $volname); $format = qemu_img_format($scfg, $volname);
} }
} else { } elsif (!defined($format)) {
$path = $d->{file}; die "efidisk format must be specified\n";
die "efidisk format must be specified\n"
if !defined($format);
} }
$read_only_str = ',readonly=on' if drive_is_read_only($conf, $d);
} else {
log_warn("no efidisk configured! Using temporary efivars disk.");
$path = "/tmp/$vmid-ovmf.fd";
PVE::Tools::file_copy($ovmf_vars, $path, -s $ovmf_vars);
$format = 'raw';
}
my $size_str = "";
if ($format eq 'raw' && $version_guard->(4, 1, 2)) {
$size_str = ",size=" . (-s $ovmf_vars);
}
# SPI flash does lots of read-modify-write OPs, without writeback this gets really slow #3329 # SPI flash does lots of read-modify-write OPs, without writeback this gets really slow #3329
my $cache = "";
if ($path =~ m/^rbd:/) { if ($path =~ m/^rbd:/) {
$cache = ',cache=writeback'; $var_drive_str .= ',cache=writeback';
$path .= ':rbd_cache_policy=writeback'; # avoid write-around, we *need* to cache writes too $path .= ':rbd_cache_policy=writeback'; # avoid write-around, we *need* to cache writes too
} }
$var_drive_str .= ",format=$format,file=$path";
my $code_drive_str = "if=pflash,unit=0,format=raw,readonly=on,file=$ovmf_code"; $var_drive_str .= ",size=" . (-s $ovmf_vars) if $format eq 'raw' && $version_guard->(4, 1, 2);
my $var_drive_str = "if=pflash" $var_drive_str .= ',readonly=on' if drive_is_read_only($conf, $d);
. ",unit=1" } else {
. ",id=drive-efidisk0" log_warn("no efidisk configured! Using temporary efivars disk.");
. "$cache" my $path = "/tmp/$vmid-ovmf.fd";
. ",format=$format" PVE::Tools::file_copy($ovmf_vars, $path, -s $ovmf_vars);
. ",file=$path" $var_drive_str .= ",format=raw,file=$path";
. "$size_str" $var_drive_str .= ",size=" . (-s $ovmf_vars) if $version_guard->(4, 1, 2);
. "$read_only_str"; }
return ($code_drive_str, $var_drive_str); return ("if=pflash,unit=0,format=raw,readonly=on,file=$ovmf_code", $var_drive_str);
} }
sub config_to_command { sub config_to_command {