From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
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))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 6327A65E86
 for <pve-devel@lists.proxmox.com>; Wed,  9 Mar 2022 11:09:34 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id C064C1B9C1
 for <pve-devel@lists.proxmox.com>; Wed,  9 Mar 2022 11:09:31 +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))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 114651B81E
 for <pve-devel@lists.proxmox.com>; Wed,  9 Mar 2022 11:09:26 +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 D649F463C9
 for <pve-devel@lists.proxmox.com>; Wed,  9 Mar 2022 11:09:25 +0100 (CET)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed,  9 Mar 2022 11:09:08 +0100
Message-Id: <20220309100919.31512-7-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20220309100919.31512-1-f.ebner@proxmox.com>
References: <20220309100919.31512-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.123 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
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
Subject: [pve-devel] [PATCH v12 qemu-server 06/16] clone disk: pass in efi
 vars size rather than config
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 09 Mar 2022 10:09:34 -0000

It's confusing that the config associated to the destination is
actually a reference to the source config for both existing callers.

Also, disk import will need to base the calculation on the passed-in
drive parameters and not just the current config, so this change is in
preparation for that too.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

New in v12.

 PVE/API2/Qemu.pm  | 8 ++++++--
 PVE/QemuServer.pm | 4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 14cac5b..9b8eb88 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -3228,11 +3228,13 @@ __PACKAGE__->register_method({
 
 		    my $dest_info = {
 			vmid => $newid,
-			conf => $oldconf, # because it's a clone
 			storage => $storage,
 			format => $format,
 		    };
 
+		    $dest_info->{efisize} = PVE::QemuServer::get_efivars_size($oldconf)
+			if $opt eq 'efidisk0';
+
 		    my $newdrive = PVE::QemuServer::clone_disk(
 			$storecfg,
 			$source_info,
@@ -3487,11 +3489,13 @@ __PACKAGE__->register_method({
 
 		my $dest_info = {
 		    vmid => $vmid,
-		    conf => $conf,
 		    storage => $storeid,
 		    format => $format,
 		};
 
+		$dest_info->{efisize} = PVE::QemuServer::get_efivars_size($conf)
+		    if $disk eq 'efidisk0';
+
 		my $newdrive = PVE::QemuServer::clone_disk(
 		    $storecfg,
 		    $source_info,
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 56437c5..ed06239 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -7576,7 +7576,7 @@ sub clone_disk {
     my ($vmid, $running) = $source->@{qw(vmid running)};
     my ($drivename, $drive, $snapname) = $source->@{qw(drivename drive snapname)};
 
-    my ($newvmid, $conf) = $dest->@{qw(vmid conf)};
+    my ($newvmid, $efisize) = $dest->@{qw(vmid efisize)};
     my ($storage, $format) = $dest->@{qw(storage format)};
 
     my $newvolid;
@@ -7604,7 +7604,7 @@ sub clone_disk {
 	    $snapname = undef;
 	    $size = PVE::QemuServer::Cloudinit::CLOUDINIT_DISK_SIZE;
 	} elsif ($drivename eq 'efidisk0') {
-	    $size = get_efivars_size($conf);
+	    $size = $efisize or die "internal error - need to specify EFI disk size\n";
 	} elsif ($drivename eq 'tpmstate0') {
 	    $dst_format = 'raw';
 	    $size = PVE::QemuServer::Drive::TPMSTATE_DISK_SIZE;
-- 
2.30.2