The QMP command needs to be issued for the device where the disk is currently attached, not for the device where the disk was attached at the time the snapshot was taken.
Fixes the following scenario with a disk image for which do_snapshots_with_qemu() is true (i.e. qcow2 or RBD+krbd=0): 1. Take snapshot while disk image is attached to a given bus+ID. 2. Detach disk image. 3. Attach disk image to a different bus+ID. 4. Remove snapshot. Previously, this would result in an error like: > blockdev-snapshot-delete-internal-sync' failed - Cannot find > device=drive-scsi1 nor node_name=drive-scsi1 While the $running parameter for volume_snapshot_delete() is planned to be removed on the next storage plugin APIAGE reset, it currently causes an immediate return in Storage/Plugin.pm. So passing a truthy value would prevent removing a snapshot from an unused qcow2 disk that was still used at the time the snapshot was taken. Thus, and because some exotic third party plugin might be using it for whatever reason, it's necessary to keep passing the same value as before. Signed-off-by: Fiona Ebner <f.eb...@proxmox.com> Signed-off-by: Maximiliano Sandoval <m.sando...@proxmox.com> --- This is a backport for Proxmox VE 7 of https://lists.proxmox.com/pipermail/pve-devel/2022-September/054124.html which was applied at https://git.proxmox.com/?p=qemu-server.git;a=commit;h=c60586838a4bfbd4f879c509195cbfb1291db443. I tested this by creating a new Proxmox VE 7.4 VM, creating a new VM inside with storage as IDE, taking a snapshot while the VM is running, detach the storage and add it back as SCSI, then deleting the snapshot. PVE/QemuServer.pm | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index ab33aa3..be7a84e 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -4800,21 +4800,26 @@ sub qemu_volume_snapshot_delete { my ($vmid, $deviceid, $storecfg, $volid, $snap) = @_; my $running = check_running($vmid); + my $attached_deviceid; - if($running) { - - $running = undef; + if ($running) { my $conf = PVE::QemuConfig->load_config($vmid); PVE::QemuConfig->foreach_volume($conf, sub { my ($ds, $drive) = @_; - $running = 1 if $drive->{file} eq $volid; + $attached_deviceid = "drive-$ds" if $drive->{file} eq $volid; }); } - if ($running && do_snapshots_with_qemu($storecfg, $volid, $deviceid)) { - mon_cmd($vmid, 'blockdev-snapshot-delete-internal-sync', device => $deviceid, name => $snap); + if ($attached_deviceid && do_snapshots_with_qemu($storecfg, $volid, $attached_deviceid)) { + mon_cmd( + $vmid, + 'blockdev-snapshot-delete-internal-sync', + device => $attached_deviceid, + name => $snap, + ); } else { - PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snap, $running); + PVE::Storage::volume_snapshot_delete( + $storecfg, $volid, $snap, $attached_deviceid ? 1 : undef); } } -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel