public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Alexandre Derumier via pve-devel <pve-devel@lists.proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
Subject: [pve-devel] [PATCH qemu-server 2/3] blockdev: add backing_chain support
Date: Fri,  4 Jul 2025 08:44:57 +0200	[thread overview]
Message-ID: <mailman.960.1751611548.395.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20250704064507.511884-1-alexandre.derumier@groupe-cyllene.com>

[-- Attachment #1: Type: message/rfc822, Size: 14809 bytes --]

From: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 2/3] blockdev: add backing_chain support
Date: Fri,  4 Jul 2025 08:44:57 +0200
Message-ID: <20250704064507.511884-4-alexandre.derumier@groupe-cyllene.com>

We need to define name-nodes for all backing chain images,
to be able to live rename them with blockdev-reopen

For linked clone, we don't need to definebase image(s) chain.
They are auto added with #block nodename.

Signed-off-by: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
---
 src/PVE/QemuServer/Blockdev.pm                | 49 +++++++++++++++++++
 src/test/cfg2cmd/simple-backingchain.conf     | 25 ++++++++++
 src/test/cfg2cmd/simple-backingchain.conf.cmd | 33 +++++++++++++
 src/test/run_config2command_tests.pl          | 47 ++++++++++++++++++
 4 files changed, 154 insertions(+)
 create mode 100644 src/test/cfg2cmd/simple-backingchain.conf
 create mode 100644 src/test/cfg2cmd/simple-backingchain.conf.cmd

diff --git a/src/PVE/QemuServer/Blockdev.pm b/src/PVE/QemuServer/Blockdev.pm
index 5f1fdae3..2a0513fb 100644
--- a/src/PVE/QemuServer/Blockdev.pm
+++ b/src/PVE/QemuServer/Blockdev.pm
@@ -360,6 +360,46 @@ my sub generate_format_blockdev {
     return $blockdev;
 }
 
+my sub generate_backing_blockdev;
+
+sub generate_backing_blockdev {
+    my ($storecfg, $snapshots, $deviceid, $drive, $machine_version, $options) = @_;
+
+    my $snap_id = $options->{'snapshot-name'};
+    my $snapshot = $snapshots->{$snap_id};
+    my $parentid = $snapshot->{parent};
+
+    my $volid = $drive->{file};
+
+    my $snap_file_blockdev = generate_file_blockdev($storecfg, $drive, $machine_version, $options);
+    $snap_file_blockdev->{filename} = $snapshot->{file};
+
+    my $snap_fmt_blockdev =
+        generate_format_blockdev($storecfg, $drive, $snap_file_blockdev, $options);
+
+    if ($parentid) {
+        my $options = { 'snapshot-name' => $parentid };
+        $snap_fmt_blockdev->{backing} = generate_backing_blockdev(
+            $storecfg, $snapshots, $deviceid, $drive, $machine_version, $options,
+        );
+    }
+    return $snap_fmt_blockdev;
+}
+
+my sub generate_backing_chain_blockdev {
+    my ($storecfg, $deviceid, $drive, $machine_version) = @_;
+
+    my $volid = $drive->{file};
+
+    my $snapshots = PVE::Storage::volume_snapshot_info($storecfg, $volid);
+    my $parentid = $snapshots->{'current'}->{parent};
+    return undef if !$parentid;
+    my $options = { 'snapshot-name' => $parentid };
+    return generate_backing_blockdev(
+        $storecfg, $snapshots, $deviceid, $drive, $machine_version, $options,
+    );
+}
+
 sub generate_drive_blockdev {
     my ($storecfg, $drive, $machine_version, $options) = @_;
 
@@ -371,6 +411,15 @@ sub generate_drive_blockdev {
     my $child = generate_file_blockdev($storecfg, $drive, $machine_version, $options);
     if (!is_nbd($drive)) {
         $child = generate_format_blockdev($storecfg, $drive, $child, $options);
+
+        my $support_qemu_snapshots =
+            PVE::Storage::volume_support_qemu_snapshot($storecfg, $drive->{file});
+        if ($support_qemu_snapshots && $support_qemu_snapshots eq 'external') {
+            my $backing_chain = generate_backing_chain_blockdev(
+                $storecfg, "drive-$drive_id", $drive, $machine_version,
+            );
+            $child->{backing} = $backing_chain if $backing_chain;
+        }
     }
 
     if ($options->{'zero-initialized'}) {
diff --git a/src/test/cfg2cmd/simple-backingchain.conf b/src/test/cfg2cmd/simple-backingchain.conf
new file mode 100644
index 00000000..2c0b0f2c
--- /dev/null
+++ b/src/test/cfg2cmd/simple-backingchain.conf
@@ -0,0 +1,25 @@
+# TEST: Simple test for external snapshot backing chain
+name: simple
+parent: snap3
+scsi0: localsnapext:8006/vm-8006-disk-0.qcow2,size=1G
+scsi1: lvm-store:vm-8006-disk-0.qcow2,size=1G
+
+[snap1]
+name: simple
+scsi0: localsnapext:8006/vm-8006-disk-0.qcow2,size=1G
+scsi1: lvm-store:vm-8006-disk-0.qcow2,size=1G
+snaptime: 1748933042
+
+[snap2]
+parent: snap1
+name: simple
+scsi0: localsnapext:8006/vm-8006-disk-0.qcow2,size=1G
+scsi1: lvm-store:vm-8006-disk-0.qcow2,size=1G
+snaptime: 1748933043
+
+[snap3]
+parent: snap2
+name: simple
+scsi0: localsnapext:8006/vm-8006-disk-0.qcow2,size=1G
+scsi1: lvm-store:vm-8006-disk-0.qcow2,size=1G
+snaptime: 1748933044
diff --git a/src/test/cfg2cmd/simple-backingchain.conf.cmd b/src/test/cfg2cmd/simple-backingchain.conf.cmd
new file mode 100644
index 00000000..40c957f5
--- /dev/null
+++ b/src/test/cfg2cmd/simple-backingchain.conf.cmd
@@ -0,0 +1,33 @@
+/usr/bin/kvm \
+  -id 8006 \
+  -name 'simple,debug-threads=on' \
+  -no-shutdown \
+  -chardev 'socket,id=qmp,path=/var/run/qemu-server/8006.qmp,server=on,wait=off' \
+  -mon 'chardev=qmp,mode=control' \
+  -chardev 'socket,id=qmp-event,path=/var/run/qmeventd.sock,reconnect-ms=5000' \
+  -mon 'chardev=qmp-event,mode=control' \
+  -pidfile /var/run/qemu-server/8006.pid \
+  -daemonize \
+  -smp '1,sockets=1,cores=1,maxcpus=1' \
+  -nodefaults \
+  -boot 'menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg' \
+  -vnc 'unix:/var/run/qemu-server/8006.vnc,password=on' \
+  -cpu kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep \
+  -m 512 \
+  -object '{"id":"throttle-drive-scsi0","limits":{},"qom-type":"throttle-group"}' \
+  -object '{"id":"throttle-drive-scsi1","limits":{},"qom-type":"throttle-group"}' \
+  -global 'PIIX4_PM.disable_s3=1' \
+  -global 'PIIX4_PM.disable_s4=1' \
+  -device 'pci-bridge,id=pci.1,chassis_nr=1,bus=pci.0,addr=0x1e' \
+  -device 'pci-bridge,id=pci.2,chassis_nr=2,bus=pci.0,addr=0x1f' \
+  -device 'piix3-usb-uhci,id=uhci,bus=pci.0,addr=0x1.0x2' \
+  -device 'usb-tablet,id=tablet,bus=uhci.0,port=1' \
+  -device 'VGA,id=vga,bus=pci.0,addr=0x2' \
+  -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3,free-page-reporting=on' \
+  -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
+  -device 'lsi,id=scsihw0,bus=pci.0,addr=0x5' \
+  -blockdev '{"driver":"throttle","file":{"backing":{"backing":{"cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":{"aio":"io_uring","cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"file","filename":"/var/lib/vzsnapext/images/8006/snap1-vm-8006-disk-0.qcow2","node-name":"ea91a385a49a008a4735c0aec5c6749","read-only":false},"node-name":"fa91a385a49a008a4735c0aec5c6749","read-only":false},"cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":{"aio":"io_uring","cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"file","filename":"/var/lib/vzsnapext/images/8006/snap2-vm-8006-disk-0.qcow2","node-name":"ec0289317073959d450248d8cd7a480","read-only":false},"node-name":"fc0289317073959d450248d8cd7a480","read-only":false},"cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":{"aio":"io_uring","cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"file","filename":"/var/lib/vzsnapext/images/8006/vm-8006-disk-0.qcow2","node-name":"e74f4959037afb46eddc7313c43dfdd","read-only":false},"node-name":"f74f4959037afb46eddc7313c43dfdd","read-only":false},"node-name":"drive-scsi0","throttle-group":"throttle-drive-scsi0"}' \
+  -device 'scsi-hd,bus=scsihw0.0,scsi-id=0,drive=drive-scsi0,id=scsi0,write-cache=on' \
+  -blockdev '{"driver":"throttle","file":{"backing":{"backing":{"cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":{"aio":"native","cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"host_device","filename":"/dev/veegee/snap1-vm-8006-disk-0.qcow2","node-name":"e25f58d3e6e11f2065ad41253988915","read-only":false},"node-name":"f25f58d3e6e11f2065ad41253988915","read-only":false},"cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":{"aio":"native","cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"host_device","filename":"/dev/veegee/snap2-vm-8006-disk-0.qcow2","node-name":"e9415bb5e484c1e25d25063b01686fe","read-only":false},"node-name":"f9415bb5e484c1e25d25063b01686fe","read-only":false},"cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":{"aio":"native","cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"host_device","filename":"/dev/veegee/vm-8006-disk-0.qcow2","node-name":"e87358a470ca311f94d5cc61d1eb428","read-only":false},"node-name":"f87358a470ca311f94d5cc61d1eb428","read-only":false},"node-name":"drive-scsi1","throttle-group":"throttle-drive-scsi1"}' \
+  -device 'scsi-hd,bus=scsihw0.0,scsi-id=1,drive=drive-scsi1,id=scsi1,write-cache=on' \
+  -machine 'type=pc+pve0'
diff --git a/src/test/run_config2command_tests.pl b/src/test/run_config2command_tests.pl
index 1262a0df..61302f6b 100755
--- a/src/test/run_config2command_tests.pl
+++ b/src/test/run_config2command_tests.pl
@@ -21,6 +21,7 @@ use PVE::QemuServer::Helpers;
 use PVE::QemuServer::Monitor;
 use PVE::QemuServer::QMPHelpers;
 use PVE::QemuServer::CPUConfig;
+use PVE::Storage;
 
 my $base_env = {
     storage_config => {
@@ -34,6 +35,15 @@ my $base_env = {
                 type => 'dir',
                 shared => 0,
             },
+            localsnapext => {
+                content => {
+                    images => 1,
+                },
+                path => '/var/lib/vzsnapext',
+                type => 'dir',
+                shared => 0,
+                snapext => 1,
+            },
             noimages => {
                 content => {
                     iso => 1,
@@ -264,6 +274,43 @@ $storage_module->mock(
     deactivate_volumes => sub {
         return;
     },
+    volume_snapshot_info => sub {
+        my ($cfg, $volid) = @_;
+
+        my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid);
+
+        my $snapshots = {};
+        if ($storeid eq 'localsnapext') {
+            $snapshots = {
+                current => {
+                    file => 'var/lib/vzsnapext/images/8006/vm-8006-disk-0.qcow2',
+                    parent => 'snap2',
+                },
+                snap2 => {
+                    file => '/var/lib/vzsnapext/images/8006/snap2-vm-8006-disk-0.qcow2',
+                    parent => 'snap1',
+                },
+                snap1 => {
+                    file => '/var/lib/vzsnapext/images/8006/snap1-vm-8006-disk-0.qcow2',
+                },
+            };
+        } elsif ($storeid eq 'lvm-store') {
+            $snapshots = {
+                current => {
+                    file => '/dev/veegee/vm-8006-disk-0.qcow2',
+                    parent => 'snap2',
+                },
+                snap2 => {
+                    file => '/dev/veegee/snap2-vm-8006-disk-0.qcow2',
+                    parent => 'snap1',
+                },
+                snap1 => {
+                    file => '/dev/veegee/snap1-vm-8006-disk-0.qcow2',
+                },
+            };
+        }
+        return $snapshots;
+    },
 );
 
 my $file_stat_module = Test::MockModule->new("File::stat");
-- 
2.39.5



[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

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

  parent reply	other threads:[~2025-07-04  6:45 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250704064507.511884-1-alexandre.derumier@groupe-cyllene.com>
2025-07-04  6:44 ` [pve-devel] [PATCH qemu-server 1/3] qemu_img convert : add external snapshot support Alexandre Derumier via pve-devel
2025-07-04  6:44 ` [pve-devel] [PATCH pve-storage 01/10] tests: add lvmplugin test Alexandre Derumier via pve-devel
2025-07-04  6:44 ` Alexandre Derumier via pve-devel [this message]
2025-07-04  6:44 ` [pve-devel] [PATCH pve-storage 02/10] common: add qemu_img_create an preallocation_cmd_option Alexandre Derumier via pve-devel
2025-07-04 11:53   ` Fabian Grünbichler
2025-07-04 12:33     ` DERUMIER, Alexandre via pve-devel
     [not found]     ` <51f988f11e60f9dfaa49658c1ed9ecf72fcfcde4.camel@groupe-cyllene.com>
2025-07-07  7:55       ` Fabian Grünbichler
2025-07-04  6:44 ` [pve-devel] [PATCH pve-storage 03/10] common: qemu_img_create: add backing_file support Alexandre Derumier via pve-devel
2025-07-04 11:52   ` Fabian Grünbichler
2025-07-04 12:31     ` DERUMIER, Alexandre via pve-devel
2025-07-07  7:16     ` DERUMIER, Alexandre via pve-devel
2025-07-04  6:45 ` [pve-devel] [PATCH qemu-server 3/3] qcow2: add external snapshot support Alexandre Derumier via pve-devel
2025-07-04 11:52   ` Fabian Grünbichler
2025-07-04 12:46     ` DERUMIER, Alexandre via pve-devel
2025-07-04  6:45 ` [pve-devel] [PATCH pve-storage 04/10] rename_volume: add source && target snap Alexandre Derumier via pve-devel
2025-07-04 11:52   ` Fabian Grünbichler
2025-07-04 12:04     ` Thomas Lamprecht
2025-07-07 10:34     ` DERUMIER, Alexandre via pve-devel
2025-07-04  6:45 ` [pve-devel] [PATCH pve-storage 05/10] common: add qemu_img_info helper Alexandre Derumier via pve-devel
2025-07-04  6:45 ` [pve-devel] [PATCH pve-storage 06/10] common: add qemu-img measure Alexandre Derumier via pve-devel
2025-07-04 11:51   ` Fabian Grünbichler
2025-07-04  6:45 ` [pve-devel] [PATCH pve-storage 07/10] storage: volume_snapshot: add $running param Alexandre Derumier via pve-devel
2025-07-04 11:52   ` Fabian Grünbichler
2025-07-04  6:45 ` [pve-devel] [PATCH pve-storage 08/10] qcow2: add external snapshot support Alexandre Derumier via pve-devel
2025-07-04 11:52   ` Fabian Grünbichler
2025-07-04 13:22     ` DERUMIER, Alexandre via pve-devel
     [not found]     ` <c38598bae6477dfa6af0db96da054b156698d41c.camel@groupe-cyllene.com>
2025-07-07  8:17       ` Fabian Grünbichler
2025-07-07 10:18         ` DERUMIER, Alexandre via pve-devel
     [not found]         ` <c671fe82a7cdab90a3691115a7132d0a35ae79b7.camel@groupe-cyllene.com>
2025-07-07 10:53           ` Fabian Grünbichler
2025-07-08  8:44     ` DERUMIER, Alexandre via pve-devel
     [not found]     ` <3d1d8516e3c68de370608033647a38e99ef50f23.camel@groupe-cyllene.com>
2025-07-08  8:56       ` Fabian Grünbichler
2025-07-08 11:37         ` DERUMIER, Alexandre via pve-devel
2025-07-08 10:04     ` DERUMIER, Alexandre via pve-devel
     [not found]     ` <27854af70a4fe3a7765d2760098e2f82f3475f17.camel@groupe-cyllene.com>
2025-07-08 10:59       ` Fabian Grünbichler
2025-07-08 11:35         ` DERUMIER, Alexandre via pve-devel
     [not found]         ` <0b2ba0c34d2c8c15d7cb642442b300a3180e1592.camel@groupe-cyllene.com>
2025-07-08 12:50           ` Thomas Lamprecht
2025-07-08 13:19             ` DERUMIER, Alexandre via pve-devel
2025-07-08 13:42         ` DERUMIER, Alexandre via pve-devel
     [not found]         ` <67627e7904281520e1f7152657ed00c7ba3c138b.camel@groupe-cyllene.com>
2025-07-08 14:18           ` Fabian Grünbichler
2025-07-09 12:52     ` DERUMIER, Alexandre via pve-devel
2025-07-04  6:45 ` [pve-devel] [PATCH pve-storage 09/10] lvmplugin: add qcow2 snapshot Alexandre Derumier via pve-devel
2025-07-04 11:51   ` Fabian Grünbichler
2025-07-09  7:24     ` DERUMIER, Alexandre via pve-devel
2025-07-09  8:06     ` DERUMIER, Alexandre via pve-devel
2025-07-04  6:45 ` [pve-devel] [PATCH pve-storage 10/10] storage : add volume_support_qemu_snapshot Alexandre Derumier via pve-devel
2025-07-04 11:51   ` 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=mailman.960.1751611548.395.pve-devel@lists.proxmox.com \
    --to=pve-devel@lists.proxmox.com \
    --cc=alexandre.derumier@groupe-cyllene.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