public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v13 qemu-server 1/8] clone disk: assert that drive name is the same for drive-mirror on single VM
Date: Thu, 17 Mar 2022 12:30:59 +0100	[thread overview]
Message-ID: <20220317113107.60466-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20220317113107.60466-1-f.ebner@proxmox.com>

because when the VM ID of target and source are the same,
qemu_drive_mirror_monitor() switches the QEMU device node over to the
new backing image. The planned import-from functionality makes it
possible to run into this, although for an a bit unusual use case.

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

New in v13.

 PVE/QemuServer.pm | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 6a9f6b31..dd6f48f3 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -7585,11 +7585,17 @@ sub clone_disk {
     my ($newvmid, $dst_drivename, $efisize) = $dest->@{qw(vmid drivename efisize)};
     my ($storage, $format) = $dest->@{qw(storage format)};
 
+    my $use_drive_mirror = $full && $running && $src_drivename && !$snapname;
+
     if ($src_drivename && $dst_drivename && $src_drivename ne $dst_drivename) {
 	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';
+
+	# This would lead to two device nodes in QEMU pointing to the same backing image!
+	die "cannot change drive name when cloning disk from/to the same VM\n"
+	    if $use_drive_mirror && $vmid == $newvmid;
     }
 
     my $newvolid;
@@ -7644,7 +7650,12 @@ sub clone_disk {
 	}
 
 	my $sparseinit = PVE::Storage::volume_has_feature($storecfg, 'sparseinit', $newvolid);
-	if (!$running || !$src_drivename || $snapname) {
+	if ($use_drive_mirror) {
+	    die "cannot move TPM state while VM is running\n" if $src_drivename eq 'tpmstate0';
+
+	    qemu_drive_mirror($vmid, $src_drivename, $newvolid, $newvmid, $sparseinit, $jobs,
+	        $completion, $qga, $bwlimit);
+	} else {
 	    # TODO: handle bwlimits
 	    if ($dst_drivename eq 'efidisk0') {
 		# the relevant data on the efidisk may be smaller than the source
@@ -7661,11 +7672,6 @@ sub clone_disk {
 	    } else {
 		qemu_img_convert($drive->{file}, $newvolid, $size, $snapname, $sparseinit);
 	    }
-	} else {
-	    die "cannot move TPM state while VM is running\n" if $src_drivename eq 'tpmstate0';
-
-	    qemu_drive_mirror($vmid, $src_drivename, $newvolid, $newvmid, $sparseinit, $jobs,
-	        $completion, $qga, $bwlimit);
 	}
     }
 
-- 
2.30.2





  reply	other threads:[~2022-03-17 11:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17 11:30 [pve-devel] [PATCH-SERIES v13 qemu-server/manager] API for disk import and OVF Fabian Ebner
2022-03-17 11:30 ` Fabian Ebner [this message]
2022-03-17 11:31 ` [pve-devel] [PATCH v13 qemu-server 2/8] clone disk: move check against cloning TPM state of running VM to beginning Fabian Ebner
2022-03-17 11:31 ` [pve-devel] [PATCH v13 qemu-server 3/8] api: clone vm: check against cloning running TPM state early Fabian Ebner
2022-03-17 11:31 ` [pve-devel] [PATCH v13 qemu-server 4/8] clone disk: also clone EFI disk from snapshot Fabian Ebner
     [not found]   ` <<20220317113107.60466-5-f.ebner@proxmox.com>
2022-04-04 14:58     ` Fabian Grünbichler
2022-03-17 11:31 ` [pve-devel] [PATCH v13 qemu-server 5/8] api: add endpoint for parsing .ovf files Fabian Ebner
2022-03-17 11:31 ` [pve-devel] [PATCH v13 qemu-server 6/8] schema: drive: use separate schema when disk allocation is possible Fabian Ebner
2022-03-17 11:31 ` [pve-devel] [PATCH v13 qemu-server 7/8] api: support VM disk import Fabian Ebner
     [not found]   ` <CAOKSTBvWfnXW9RUo2ddKACTgZV9Be-7d=9g8zPoduaDH=XP1Zw@mail.gmail.com>
2022-03-17 12:35     ` Thomas Lamprecht
2022-03-17 11:31 ` [pve-devel] [PATCH v13 qemu-server 8/8] api: update vm: print drive string for newly allocated/imported drives Fabian Ebner
2022-03-17 11:31 ` [pve-devel] [PATCH v13 manager 1/1] api: nodes: add readovf endpoint Fabian Ebner
2022-04-04 14:59 ` [pve-devel] applied: [PATCH-SERIES v13 qemu-server/manager] API for disk import and OVF Fabian Grünbichler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220317113107.60466-2-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal