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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 6948D69D35 for ; Mon, 14 Mar 2022 16:55:29 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5F53D6240 for ; Mon, 14 Mar 2022 16:55:29 +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 6BBDF6235 for ; Mon, 14 Mar 2022 16:55:27 +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 43B8B46357 for ; Mon, 14 Mar 2022 16:55:27 +0100 (CET) Date: Mon, 14 Mar 2022 16:55:20 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20220309100919.31512-1-f.ebner@proxmox.com> <20220309100919.31512-8-f.ebner@proxmox.com> In-Reply-To: <<20220309100919.31512-8-f.ebner@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1647262537.el5ineow9k.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.187 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: Re: [pve-devel] [PATCH v12 qemu-server 07/16] clone disk: allow cloning from an unused or unreferenced disk 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: Mon, 14 Mar 2022 15:55:29 -0000 On March 9, 2022 11:09 am, Fabian Ebner wrote: > and also when source and target drivename are different. In those > cases, it is done via qemu-img convert/dd. >=20 > In preparation to allow import from existing PVE-managed disks. >=20 > Signed-off-by: Fabian Ebner > --- > PVE/API2/Qemu.pm | 2 ++ > PVE/QemuServer.pm | 29 +++++++++++++++++++---------- > 2 files changed, 21 insertions(+), 10 deletions(-) >=20 > diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm > index 9b8eb88..3b86034 100644 > --- a/PVE/API2/Qemu.pm > +++ b/PVE/API2/Qemu.pm > @@ -3228,6 +3228,7 @@ __PACKAGE__->register_method({ > =20 > my $dest_info =3D { > vmid =3D> $newid, > + drivename =3D> $opt, > storage =3D> $storage, > format =3D> $format, > }; > @@ -3489,6 +3490,7 @@ __PACKAGE__->register_method({ > =20 > my $dest_info =3D { > vmid =3D> $vmid, > + drivename =3D> $disk, > storage =3D> $storeid, > format =3D> $format, > }; > diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm > index ed06239..b98ed3d 100644 > --- a/PVE/QemuServer.pm > +++ b/PVE/QemuServer.pm > @@ -7574,15 +7574,25 @@ sub clone_disk { > my ($storecfg, $source, $dest, $full, $newvollist, $jobs, $completio= n, $qga, $bwlimit) =3D @_; > =20 > my ($vmid, $running) =3D $source->@{qw(vmid running)}; > - my ($drivename, $drive, $snapname) =3D $source->@{qw(drivename drive= snapname)}; > + my ($src_drivename, $drive, $snapname) =3D $source->@{qw(drivename d= rive snapname)}; > =20 > - my ($newvmid, $efisize) =3D $dest->@{qw(vmid efisize)}; > + my ($newvmid, $dst_drivename, $efisize) =3D $dest->@{qw(vmid drivena= me efisize)}; > my ($storage, $format) =3D $dest->@{qw(storage format)}; > =20 > + if ($src_drivename && $dst_drivename && $src_drivename ne $dst_drive= name) { > + die "cloning from/to EFI disk requires EFI disk\n" > + if $src_drivename eq 'efidisk0' || $dst_drivename eq 'efidisk0'; > + die "cloning from/to TPM state requires TPM state\n" > + if $src_drivename eq 'tpmstate0' || $dst_drivename eq 'tpmstate0'; potential follow-up: should we check `$running && !$snapname` here (continu= ed below) > + } > + > my $newvolid; > =20 > + print "create " . ($full ? 'full' : 'linked') . " clone of drive "; > + print "$src_drivename " if $src_drivename; > + print "($drive->{file})\n"; > + > if (!$full) { > - print "create linked clone of drive $drivename ($drive->{file})\n"; > $newvolid =3D PVE::Storage::vdisk_clone($storecfg, $drive->{file}, $ne= wvmid, $snapname); > push @$newvollist, $newvolid; > } else { > @@ -7592,7 +7602,6 @@ sub clone_disk { > =20 > my $dst_format =3D resolve_dst_disk_format($storecfg, $storeid, $volnam= e, $format); > =20 > - print "create full clone of drive $drivename ($drive->{file})\n"; > my $name =3D undef; > my $size =3D undef; > if (drive_is_cloudinit($drive)) { > @@ -7603,9 +7612,9 @@ sub clone_disk { > } > $snapname =3D undef; > $size =3D PVE::QemuServer::Cloudinit::CLOUDINIT_DISK_SIZE; > - } elsif ($drivename eq 'efidisk0') { > + } elsif ($dst_drivename eq 'efidisk0') { > $size =3D $efisize or die "internal error - need to specify EFI dis= k size\n"; > - } elsif ($drivename eq 'tpmstate0') { > + } elsif ($dst_drivename eq 'tpmstate0') { > $dst_format =3D 'raw'; > $size =3D PVE::QemuServer::Drive::TPMSTATE_DISK_SIZE; > } else { > @@ -7629,9 +7638,9 @@ sub clone_disk { > } > =20 > my $sparseinit =3D PVE::Storage::volume_has_feature($storecfg, 'sparsei= nit', $newvolid); > - if (!$running || $snapname) { > + if (!$running || !$src_drivename || $snapname) { > # TODO: handle bwlimits > - if ($drivename eq 'efidisk0') { > + if ($dst_drivename eq 'efidisk0') { > # the relevant data on the efidisk may be smaller than the source > # e.g. on RBD/ZFS, so we use dd to copy only the amount > # that is given by the OVMF_VARS.fd > @@ -7647,9 +7656,9 @@ sub clone_disk { > qemu_img_convert($drive->{file}, $newvolid, $size, $snapname, $sparsei= nit); > } > } else { corresponding to this else branch here - mirroring but changing=20 drivename is not something we currently ever want to do, so we might=20 want to guard against it? > - die "cannot move TPM state while VM is running\n" if $drivename eq = 'tpmstate0'; > + die "cannot move TPM state while VM is running\n" if $src_drivename= eq 'tpmstate0'; > =20 > - qemu_drive_mirror($vmid, $drivename, $newvolid, $newvmid, $sparsein= it, $jobs, > + qemu_drive_mirror($vmid, $src_drivename, $newvolid, $newvmid, $spar= seinit, $jobs, > $completion, $qga, $bwlimit); > } > } > --=20 > 2.30.2 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20