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 12/13] blockdev: add backing_chain support
Date: Tue,  3 Jun 2025 09:55:57 +0200	[thread overview]
Message-ID: <mailman.198.1748937402.395.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20250603075558.627850-1-alexandre.derumier@groupe-cyllene.com>

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

From: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 12/13] blockdev: add backing_chain support
Date: Tue,  3 Jun 2025 09:55:57 +0200
Message-ID: <20250603075558.627850-23-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>
---
 PVE/QemuServer/Blockdev.pm                | 35 +++++++++++++++++++++++
 test/cfg2cmd/simple-backingchain.conf     | 21 ++++++++++++++
 test/cfg2cmd/simple-backingchain.conf.cmd | 30 +++++++++++++++++++
 test/run_config2command_tests.pl          | 26 +++++++++++++++++
 4 files changed, 112 insertions(+)
 create mode 100644 test/cfg2cmd/simple-backingchain.conf
 create mode 100644 test/cfg2cmd/simple-backingchain.conf.cmd

diff --git a/PVE/QemuServer/Blockdev.pm b/PVE/QemuServer/Blockdev.pm
index 60a996f3..692336c1 100644
--- a/PVE/QemuServer/Blockdev.pm
+++ b/PVE/QemuServer/Blockdev.pm
@@ -153,6 +153,7 @@ sub generate_file_blockdev {
     } elsif($storeid) {
 	my $blockdev_options = {};
 	$blockdev_options->{hints}->{'efi-disk'} = 1 if $drive_id =~ m/^efidisk(\d+)$/;
+	$blockdev_options->{'snapshot-name'} = $snap if $snap;
 	$blockdev = PVE::Storage::qemu_blockdev_options($storecfg, $volid, $blockdev_options);
 	$scfg = PVE::Storage::storage_config($storecfg, $storeid);
     } elsif (drive_is_cdrom($drive)) {
@@ -244,6 +245,34 @@ sub generate_format_blockdev {
     return $blockdev;
 }
 
+my sub generate_backing_blockdev;
+sub generate_backing_blockdev {
+    my ($storecfg, $snapshots, $deviceid, $drive, $snap_id) = @_;
+
+    my $snapshot = $snapshots->{$snap_id};
+    my $parentid = $snapshot->{parent};
+
+    my $volid = $drive->{file};
+
+    my $snap_file_blockdev = generate_file_blockdev($storecfg, $drive, $snap_id);
+    $snap_file_blockdev->{filename} = $snapshot->{file};
+    $drive->{ro} = 1;
+    my $snap_fmt_blockdev = generate_format_blockdev($storecfg, $drive, $snap_file_blockdev, $snap_id);
+    $snap_fmt_blockdev->{backing} = generate_backing_blockdev($storecfg, $snapshots, $deviceid, $drive, $parentid) if $parentid;
+    return $snap_fmt_blockdev;
+}
+
+my sub generate_backing_chain_blockdev {
+    my ($storecfg, $deviceid, $drive) = @_;
+
+    my $volid = $drive->{file};
+
+    my $snapshots = PVE::Storage::volume_snapshot_info($storecfg, $volid);
+    my $parentid = $snapshots->{'current'}->{parent};
+    return undef if !$parentid;
+    return generate_backing_blockdev($storecfg, $snapshots, $deviceid, $drive, $parentid);
+}
+
 sub generate_drive_blockdev {
     my ($storecfg, $drive, $live_restore_name, $size) = @_;
 
@@ -262,6 +291,12 @@ sub generate_drive_blockdev {
     my $blockdev_file = generate_file_blockdev($storecfg, $drive);
     my $blockdev_format = generate_format_blockdev($storecfg, $drive, $blockdev_file, undef, $size);
 
+    my $support_qemu_snapshots = PVE::Storage::volume_support_qemu_snapshot($storecfg, $volid);
+    if ($support_qemu_snapshots && $support_qemu_snapshots eq 'external') {
+	my $backing_chain  = generate_backing_chain_blockdev($storecfg, "drive-$drive_id", $drive);
+	$blockdev_format->{backing} = $backing_chain if $backing_chain;
+    }
+
     my $blockdev_live_restore = undef;
     #pflash0 don't support throttle-filter
     return $blockdev_format if $drive_id eq 'pflash0';
diff --git a/test/cfg2cmd/simple-backingchain.conf b/test/cfg2cmd/simple-backingchain.conf
new file mode 100644
index 00000000..71664bd5
--- /dev/null
+++ b/test/cfg2cmd/simple-backingchain.conf
@@ -0,0 +1,21 @@
+# TEST: Simple test for external snapshot backing chain
+name: simple
+parent: snap3
+scsi0: localsnapext:8006/vm-8006-disk-0.qcow2,size=1G
+
+[snap1]
+name: simple
+scsi0: localsnapext:8006/vm-8006-disk-0.qcow2,size=1G
+snaptime: 1748933042
+
+[snap2]
+parent: snap1
+name: simple
+scsi0: localsnapext:8006/vm-8006-disk-0.qcow2,size=1G
+snaptime: 1748933043
+
+[snap3]
+parent: snap2
+name: simple
+scsi0: localsnapext:8006/vm-8006-disk-0.qcow2,size=1G
+snaptime: 1748933044
diff --git a/test/cfg2cmd/simple-backingchain.conf.cmd b/test/cfg2cmd/simple-backingchain.conf.cmd
new file mode 100644
index 00000000..739183ee
--- /dev/null
+++ b/test/cfg2cmd/simple-backingchain.conf.cmd
@@ -0,0 +1,30 @@
+/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 \
+  -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' \
+  -object '{"id":"throttle-drive-scsi0","limits":{},"qom-type":"throttle-group"}' \
+  -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/vz/images/8006/snap1-vm-8006-disk-0.qcow2","node-name":"e-aN9FfpTi1eqQ4kUSoMKsyEYSM6k"},"node-name":"f-aN9FfpTi1eqQ4kUSoMKsyEYSM6k","read-only":true},"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/vz/images/8006/snap2-vm-8006-disk-0.qcow2","node-name":"e-Zu2dZCd1WKQe604KQ0Cy4AMmGww"},"node-name":"f-Zu2dZCd1WKQe604KQ0Cy4AMmGww","read-only":true},"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/vz/images/8006/vm-8006-disk-0.qcow2","node-name":"e-8ps94lIsZyMk28qw4ggmas8MCki"},"node-name":"f-8ps94lIsZyMk28qw4ggmas8MCki","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' \
+  -machine 'type=pc+pve0'
diff --git a/test/run_config2command_tests.pl b/test/run_config2command_tests.pl
index d689fc5b..83b513ec 100755
--- a/test/run_config2command_tests.pl
+++ b/test/run_config2command_tests.pl
@@ -33,6 +33,15 @@ my $base_env = {
 		type => 'dir',
 		shared => 0,
 	    },
+	    localsnapext => {
+		content => {
+		    images => 1,
+		},
+		path => '/var/lib/vz',
+		type => 'dir',
+		shared => 0,
+		snapext => 1,
+	    },
 	    noimages => {
 		content => {
 		    iso => 1,
@@ -492,6 +501,23 @@ my $storage_module = Test::MockModule->new("PVE::Storage");
 $storage_module->mock(
     activate_volumes => sub {
 	return;
+    },
+    volume_snapshot_info => sub {
+	my $snapshots = {
+	    current => {
+		file => '/var/lib/vz/images/8006/vm-8006-disk-0.qcow2',
+		parent => 'snap2'
+	    },
+	    snap2 => {
+		file => '/var/lib/vz/images/8006/snap2-vm-8006-disk-0.qcow2',
+		parent => 'snap1'
+	    },
+	    snap1 => {
+		file => '/var/lib/vz/images/8006/snap1-vm-8006-disk-0.qcow2',
+
+	    },
+	};
+	return $snapshots;
     }
 );
 
-- 
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-06-03  7:57 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250603075558.627850-1-alexandre.derumier@groupe-cyllene.com>
2025-06-03  7:55 ` [pve-devel] [PATCH pve-qemu 1/1] add fake 10.0 Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 01/13] blockdev: cmdline: add blockdev syntax support Alexandre Derumier via pve-devel
2025-06-05 13:23   ` Fiona Ebner
2025-06-05 14:17     ` Fabian Grünbichler
2025-06-05 14:39     ` DERUMIER, Alexandre via pve-devel
     [not found]     ` <ee4940c99e9866910405b492dad15c68718c49ea.camel@groupe-cyllene.com>
2025-06-06  7:50       ` Fiona Ebner
2025-06-06  8:27         ` Fabian Grünbichler
2025-06-06  9:54           ` DERUMIER, Alexandre via pve-devel
2025-06-06  8:50   ` Fiona Ebner
2025-06-06  9:42     ` DERUMIER, Alexandre via pve-devel
     [not found]     ` <0605a27428cfb920ffefc51abdfec050a0a6b535.camel@groupe-cyllene.com>
2025-06-06 10:57       ` DERUMIER, Alexandre via pve-devel
2025-06-10 14:03   ` Fiona Ebner
2025-06-11  6:37     ` DERUMIER, Alexandre via pve-devel
     [not found]     ` <405662415075c0248618833b512b58258f80e0f7.camel@groupe-cyllene.com>
2025-06-11  7:24       ` Fiona Ebner
2025-06-11 14:02         ` DERUMIER, Alexandre via pve-devel
     [not found]         ` <733f5eefb25b76a0794a84d4f93ada8d70aea7be.camel@groupe-cyllene.com>
2025-06-11 14:13           ` Fiona Ebner
2025-06-12  5:20             ` DERUMIER, Alexandre via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH pve-storage 1/9] common: add qemu_img_create an preallocation_cmd_option Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 02/13] blockdev: add support for ovmf && efidisk Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH pve-storage 2/9] common: add qemu_img_create_qcow2_backed Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 03/13] blockdev: vm_devices_list : fix block-query Alexandre Derumier via pve-devel
2025-06-17 14:44   ` Fiona Ebner
2025-06-03  7:55 ` [pve-devel] [PATCH pve-storage 3/9] common: add qemu_img_info helper Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 04/13] blockdev: add support to qemu_driveadd && qemu_drivedel Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH pve-storage 4/9] common: add qemu_img_measure Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 05/13] blockdev: add support to qemu_block_set_io_throttle Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH pve-storage 5/9] rename_volume: add source && target snap Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 06/13] blockdev: add support for cdrom media eject/insert Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH pve-storage 6/9] storage: volume_snapshot: add $running param + api bump Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 07/13] blockdev: add support for block_resize Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH pve-storage 7/9] qcow2: add external snapshot support Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 08/13] blockdev: add support for nbd_export: block-export-add Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH pve-storage 8/9] lvmplugin: add qcow2 snapshot Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 09/13] blockdev: add blockdev_mirror Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH pve-storage 9/9] storage: add volume_support_qemu_snapshot Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 10/13] blockdev: change aio on target if io_uring is not default Alexandre Derumier via pve-devel
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 11/13] qemu_img convert : add external snapshot support Alexandre Derumier via pve-devel
2025-06-03  7:55 ` Alexandre Derumier via pve-devel [this message]
2025-06-03  7:55 ` [pve-devel] [PATCH qemu-server 13/13] qcow2: " Alexandre Derumier via pve-devel

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.198.1748937402.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