From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C2806E0B9 for ; Tue, 6 Dec 2022 18:12:28 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A137A30D93 for ; Tue, 6 Dec 2022 18:11:58 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 6 Dec 2022 18:11:57 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 5F4EB44CD9 for ; Tue, 6 Dec 2022 18:11:57 +0100 (CET) Message-ID: Date: Tue, 6 Dec 2022 18:11:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Thunderbird/108.0 Content-Language: en-GB To: Proxmox VE development discussion , Fiona Ebner References: <20221202125931.57214-1-f.ebner@proxmox.com> From: Thomas Lamprecht In-Reply-To: <20221202125931.57214-1-f.ebner@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.106 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.27 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, qemuserver.pm] Subject: Re: [pve-devel] [PATCH qemu-server] cfg2cmd: factor out ovmf drives printing X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Dec 2022 17:12:28 -0000 Am 02/12/2022 um 13:59 schrieb Fiona Ebner: > No functional change is intended. > > Signed-off-by: Fiona Ebner > --- > > Popped out while trying the other approach mentioned in: > https://lists.proxmox.com/pipermail/pve-devel/2022-December/055091.html looks ok, having it in a separate method opens up a few more "line reduction without making it harder to understand" possibilities, e.g., the following diff would drop 21 lines, but reorder the var string a bit too - what do you think? ----8<---- diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 619908d..dd6ea3e 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -3517,63 +3517,42 @@ my sub should_disable_smm { 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 $d = $conf->{efidisk0} ? parse_drive('efidisk0', $conf->{efidisk0}) : undef; 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 = ''; + my $var_drive_str = "if=pflash,unit=1,id=drive-efidisk0"; if ($d) { my ($storeid, $volname) = PVE::Storage::parse_volume_id($d->{file}, 1); - $format = $d->{format}; + my ($path, $format) = $d->@{'file', '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); + } elsif (!defined($format)) { + die "efidisk format must be specified\n"; } + # SPI flash does lots of read-modify-write OPs, without writeback this gets really slow #3329 + if ($path =~ m/^rbd:/) { + $var_drive_str .= ',cache=writeback'; + $path .= ':rbd_cache_policy=writeback'; # avoid write-around, we *need* to cache writes too + } + $var_drive_str .= ",format=$format,file=$path"; - $read_only_str = ',readonly=on' if drive_is_read_only($conf, $d); + $var_drive_str .= ",size=" . (-s $ovmf_vars) if $format eq 'raw' && $version_guard->(4, 1, 2); + $var_drive_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"; + my $path = "/tmp/$vmid-ovmf.fd"; PVE::Tools::file_copy($ovmf_vars, $path, -s $ovmf_vars); - $format = 'raw'; + $var_drive_str .= ",format=raw,file=$path"; + $var_drive_str .= ",size=" . (-s $ovmf_vars) if $version_guard->(4, 1, 2); } - 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); + return ("if=pflash,unit=0,format=raw,readonly=on,file=$ovmf_code", $var_drive_str); } sub config_to_command {