[PATCH qemu-server v3 17/18] snapshot: support live snapshot (remove) of qcow2 TPM drive on storage with snapshot-as-volume-chain

Fiona Ebner
2026-04-23T09:40:14Z

Adds a new drive_qmp_peer() helper to determine whether the drive is
managed by the QEMU instance or QSD instance for the VM.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
src/PVE/QemuServer.pm | 30 +++++++++++++-----------------
src/PVE/QemuServer/Drive.pm | 8 ++++++++
2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 53c40eef..9dac4024 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -82,7 +82,7 @@ use PVE::QemuServer::DriveDevice qw(print_drivedevice_full scsihw_infos);
use PVE::QemuServer::Machine;
use PVE::QemuServer::Memory qw(get_current_memory);
use PVE::QemuServer::MetaInfo;
-use PVE::QemuServer::Monitor qw(mon_cmd vm_qmp_peer);
+use PVE::QemuServer::Monitor qw(mon_cmd qmp_cmd vm_qmp_peer);
use PVE::QemuServer::Network;
use PVE::QemuServer::OVMF;
use PVE::QemuServer::PCI qw(print_pci_addr print_pcie_addr print_pcie_root_port parse_hostpci);
@@ -4355,7 +4355,8 @@ sub qemu_volume_snapshot {

if ($do_snapshots_type eq 'internal') {
print "internal qemu snapshot\n";
- mon_cmd($vmid, 'blockdev-snapshot-internal-sync', device => $deviceid, name => $snap);
+ my $qmp_peer = PVE::QemuServer::Drive::drive_qmp_peer($storecfg, $vmid, $drive);
+ qmp_cmd($qmp_peer, 'blockdev-snapshot-internal-sync', device => $deviceid, name => $snap);
} elsif ($do_snapshots_type eq 'external') {
my $machine_version = PVE::QemuServer::Machine::get_current_qemu_machine($vmid);
if (!PVE::QemuServer::Machine::is_machine_version_at_least($machine_version, 10, 0)) {
@@ -4368,14 +4369,9 @@ sub qemu_volume_snapshot {
print "external qemu snapshot\n";
my $snapshots = PVE::Storage::volume_snapshot_info($storecfg, $volid);
my $parent_snap = $snapshots->{'current'}->{parent};
+ my $qmp_peer = PVE::QemuServer::Drive::drive_qmp_peer($storecfg, $vmid, $drive);
PVE::QemuServer::VolumeChain::blockdev_external_snapshot(
- $storecfg,
- vm_qmp_peer($vmid),
- $machine_version,
- $deviceid,
- $drive,
- $snap,
- $parent_snap,
+ $storecfg, $qmp_peer, $machine_version, $deviceid, $drive, $snap, $parent_snap,
);
} elsif ($do_snapshots_type eq 'storage') {
PVE::Storage::volume_snapshot($storecfg, $volid, $snap);
@@ -4403,8 +4399,9 @@ sub qemu_volume_snapshot_delete {
my $do_snapshots_type = do_snapshots_type($storecfg, $volid, $attached_deviceid, $running);

if ($do_snapshots_type eq 'internal') {
- mon_cmd(
- $vmid,
+ my $qmp_peer = PVE::QemuServer::Drive::drive_qmp_peer($storecfg, $vmid, $drive);
+ qmp_cmd(
+ $qmp_peer,
'blockdev-snapshot-delete-internal-sync',
device => $attached_deviceid,
name => $snap,
@@ -4428,13 +4425,15 @@ sub qemu_volume_snapshot_delete {
my $parentsnap = $snapshots->{$snap}->{parent};
my $childsnap = $snapshots->{$snap}->{child};

+ my $qmp_peer = PVE::QemuServer::Drive::drive_qmp_peer($storecfg, $vmid, $drive);
+
# if we delete the first snasphot, we commit because the first snapshot original base image, it should be big.
# improve-me: if firstsnap > child : commit, if firstsnap < child do a stream.
if (!$parentsnap) {
print "delete first snapshot $snap\n";
PVE::QemuServer::VolumeChain::blockdev_commit(
$storecfg,
- vm_qmp_peer($vmid),
+ $qmp_peer,
$machine_version,
$attached_deviceid,
$drive,
@@ -4446,7 +4445,7 @@ sub qemu_volume_snapshot_delete {

PVE::QemuServer::VolumeChain::blockdev_replace(
$storecfg,
- vm_qmp_peer($vmid),
+ $qmp_peer,
$machine_version,
$attached_deviceid,
$drive,
@@ -4459,7 +4458,7 @@ sub qemu_volume_snapshot_delete {
print "stream intermediate snapshot $snap to $childsnap\n";
PVE::QemuServer::VolumeChain::blockdev_stream(
$storecfg,
- vm_qmp_peer($vmid),
+ $qmp_peer,
$machine_version,
$attached_deviceid,
$drive,
@@ -7793,9 +7792,6 @@ sub restore_tar_archive {
sub do_snapshots_type {
my ($storecfg, $volid, $deviceid, $running) = @_;

- #always use storage snapshot for tpmstate
- return 'storage' if $deviceid && $deviceid =~ m/tpmstate0/;
-
#we use storage snapshot if vm is not running or if disk is unused;
return 'storage' if !$running || !$deviceid;

diff --git a/src/PVE/QemuServer/Drive.pm b/src/PVE/QemuServer/Drive.pm
index f88504b2..79afc146 100644
--- a/src/PVE/QemuServer/Drive.pm
+++ b/src/PVE/QemuServer/Drive.pm
@@ -13,6 +13,8 @@ use PVE::Storage;
use PVE::Storage::Common;
use PVE::JSONSchema qw(get_standard_option);

+use PVE::QemuServer::Monitor qw(qsd_peer vm_qmp_peer);
+
use base qw(Exporter);

our @EXPORT_OK = qw(
@@ -1164,4 +1166,10 @@ sub drive_uses_qsd_fuse {
return;
}

+sub drive_qmp_peer {
+ my ($storecfg, $vmid, $drive) = @_;
+
+ return drive_uses_qsd_fuse($storecfg, $drive) ? qsd_peer($vmid) : vm_qmp_peer($vmid);
+}
+
1;
--
2.47.3