mirror of
				https://git.proxmox.com/git/qemu-server
				synced 2025-11-04 11:28:38 +00:00 
			
		
		
		
	cfg2cmd: factor out ovmf drives printing
No functional change is intended. Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
		
							parent
							
								
									ad9e347c46
								
							
						
					
					
						commit
						b7d80c7905
					
				@ -3514,6 +3514,68 @@ my sub should_disable_smm {
 | 
			
		||||
	$vga->{type} && $vga->{type} =~ m/^(serial\d+|none)$/;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
my sub print_ovmf_drive_commandlines {
 | 
			
		||||
    my ($conf, $storecfg, $vmid, $arch, $q35, $version_guard) = @_;
 | 
			
		||||
 | 
			
		||||
    my $d;
 | 
			
		||||
    if (my $efidisk = $conf->{efidisk0}) {
 | 
			
		||||
	$d = parse_drive('efidisk0', $efidisk);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    my ($ovmf_code, $ovmf_vars) = get_ovmf_files($arch, $d, $q35);
 | 
			
		||||
    die "uefi base image '$ovmf_code' not found\n" if ! -f $ovmf_code;
 | 
			
		||||
 | 
			
		||||
    my ($path, $format);
 | 
			
		||||
    my $read_only_str = '';
 | 
			
		||||
    if ($d) {
 | 
			
		||||
	my ($storeid, $volname) = PVE::Storage::parse_volume_id($d->{file}, 1);
 | 
			
		||||
	$format = $d->{format};
 | 
			
		||||
	if ($storeid) {
 | 
			
		||||
	    $path = PVE::Storage::path($storecfg, $d->{file});
 | 
			
		||||
	    if (!defined($format)) {
 | 
			
		||||
		my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
 | 
			
		||||
		$format = qemu_img_format($scfg, $volname);
 | 
			
		||||
	    }
 | 
			
		||||
	} else {
 | 
			
		||||
	    $path = $d->{file};
 | 
			
		||||
	    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
 | 
			
		||||
    my $cache = "";
 | 
			
		||||
    if ($path =~ m/^rbd:/) {
 | 
			
		||||
	$cache = ',cache=writeback';
 | 
			
		||||
	$path .= ':rbd_cache_policy=writeback'; # avoid write-around, we *need* to cache writes too
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    my $code_drive_str = "if=pflash,unit=0,format=raw,readonly=on,file=$ovmf_code";
 | 
			
		||||
    my $var_drive_str = "if=pflash"
 | 
			
		||||
	. ",unit=1"
 | 
			
		||||
	. "$cache"
 | 
			
		||||
	. ",format=$format"
 | 
			
		||||
	. ",id=drive-efidisk0"
 | 
			
		||||
	. "$size_str"
 | 
			
		||||
	. ",file=$path"
 | 
			
		||||
	. "$read_only_str";
 | 
			
		||||
 | 
			
		||||
    return ($code_drive_str, $var_drive_str);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub config_to_command {
 | 
			
		||||
    my ($storecfg, $vmid, $conf, $defaults, $forcemachine, $forcecpu,
 | 
			
		||||
        $pbs_backing) = @_;
 | 
			
		||||
@ -3633,54 +3695,10 @@ sub config_to_command {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ($conf->{bios} && $conf->{bios} eq 'ovmf') {
 | 
			
		||||
	my $d;
 | 
			
		||||
	if (my $efidisk = $conf->{efidisk0}) {
 | 
			
		||||
	    $d = parse_drive('efidisk0', $efidisk);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	my ($ovmf_code, $ovmf_vars) = get_ovmf_files($arch, $d, $q35);
 | 
			
		||||
	die "uefi base image '$ovmf_code' not found\n" if ! -f $ovmf_code;
 | 
			
		||||
 | 
			
		||||
	my ($path, $format);
 | 
			
		||||
	my $read_only_str = '';
 | 
			
		||||
	if ($d) {
 | 
			
		||||
	    my ($storeid, $volname) = PVE::Storage::parse_volume_id($d->{file}, 1);
 | 
			
		||||
	    $format = $d->{format};
 | 
			
		||||
	    if ($storeid) {
 | 
			
		||||
		$path = PVE::Storage::path($storecfg, $d->{file});
 | 
			
		||||
		if (!defined($format)) {
 | 
			
		||||
		    my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
 | 
			
		||||
		    $format = qemu_img_format($scfg, $volname);
 | 
			
		||||
		}
 | 
			
		||||
	    } else {
 | 
			
		||||
		$path = $d->{file};
 | 
			
		||||
		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
 | 
			
		||||
	my $cache = "";
 | 
			
		||||
	if ($path =~ m/^rbd:/) {
 | 
			
		||||
		$cache = ',cache=writeback';
 | 
			
		||||
		$path .= ':rbd_cache_policy=writeback'; # avoid write-around, we *need* to cache writes too
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	push @$cmd, '-drive', "if=pflash,unit=0,format=raw,readonly=on,file=$ovmf_code";
 | 
			
		||||
	push @$cmd, '-drive', "if=pflash,unit=1$cache,format=$format,id=drive-efidisk0$size_str,file=${path}${read_only_str}";
 | 
			
		||||
	my ($code_drive_str, $var_drive_str) =
 | 
			
		||||
	    print_ovmf_drive_commandlines($conf, $storecfg, $vmid, $arch, $q35, $version_guard);
 | 
			
		||||
	push $cmd->@*, '-drive', $code_drive_str;
 | 
			
		||||
	push $cmd->@*, '-drive', $var_drive_str;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ($q35) { # tell QEMU to load q35 config early
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user