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.eb...@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



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to