From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id A89FC1FF15E
	for <inbox@lore.proxmox.com>; Tue,  3 Jun 2025 09:57:09 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 6F4E310FA6;
	Tue,  3 Jun 2025 09:56:44 +0200 (CEST)
To: pve-devel@lists.proxmox.com
Date: Tue,  3 Jun 2025 09:55:57 +0200
In-Reply-To: <20250603075558.627850-1-alexandre.derumier@groupe-cyllene.com>
References: <20250603075558.627850-1-alexandre.derumier@groupe-cyllene.com>
MIME-Version: 1.0
Message-ID: <mailman.198.1748937402.395.pve-devel@lists.proxmox.com>
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Post: <mailto:pve-devel@lists.proxmox.com>
From: Alexandre Derumier via pve-devel <pve-devel@lists.proxmox.com>
Precedence: list
Cc: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
X-Mailman-Version: 2.1.29
X-BeenThere: pve-devel@lists.proxmox.com
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
Subject: [pve-devel] [PATCH qemu-server 12/13] blockdev: add backing_chain
 support
Content-Type: multipart/mixed; boundary="===============7645187548240490911=="
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

--===============7645187548240490911==
Content-Type: message/rfc822
Content-Disposition: inline

Return-Path: <root@formationkvm1.odiso.net>
X-Original-To: pve-devel@lists.proxmox.com
Delivered-To: pve-devel@lists.proxmox.com
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by lists.proxmox.com (Postfix) with ESMTPS id 48E98CB554
	for <pve-devel@lists.proxmox.com>; Tue,  3 Jun 2025 09:56:42 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id A292410D23
	for <pve-devel@lists.proxmox.com>; Tue,  3 Jun 2025 09:56:21 +0200 (CEST)
Received: from bastiontest.odiso.net (unknown [IPv6:2a0a:1580:2000:6700::14])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by firstgate.proxmox.com (Proxmox) with ESMTPS
	for <pve-devel@lists.proxmox.com>; Tue,  3 Jun 2025 09:56:16 +0200 (CEST)
Received: from formationkvm1.odiso.net (unknown [10.11.201.57])
	by bastiontest.odiso.net (Postfix) with ESMTP id 77051862E5C;
	Tue,  3 Jun 2025 09:56:02 +0200 (CEST)
Received: by formationkvm1.odiso.net (Postfix, from userid 0)
	id A5F7C110DBD4; Tue,  3 Jun 2025 09:56:01 +0200 (CEST)
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>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250603075558.627850-1-alexandre.derumier@groupe-cyllene.com>
References: <20250603075558.627850-1-alexandre.derumier@groupe-cyllene.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
X-SPAM-LEVEL: Spam detection results:  0
	AWL                     0.052 Adjusted score from AWL reputation of From: address
	BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
	DMARC_NONE                0.1 DMARC none policy
	HEADER_FROM_DIFFERENT_DOMAINS  0.001 From and EnvelopeFrom 2nd level mail domains are different
	KAM_DMARC_NONE           0.25 DKIM has Failed or SPF has failed on the message and the domain has no DMARC policy
	KAM_DMARC_STATUS         0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
	KAM_LAZY_DOMAIN_SECURITY      1 Sending domain does not have any anti-forgery methods
	PROLO_LEO1                0.1 Meta Catches all Leo drug variations so far
	RDNS_NONE               0.793 Delivered to internal network by a host with no rDNS
	SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
	SPF_NONE                0.001 SPF: sender does not publish an SPF Record

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 =3D {};
 	$blockdev_options->{hints}->{'efi-disk'} =3D 1 if $drive_id =3D~ m/^efidi=
sk(\d+)$/;
+	$blockdev_options->{'snapshot-name'} =3D $snap if $snap;
 	$blockdev =3D PVE::Storage::qemu_blockdev_options($storecfg, $volid, $blo=
ckdev_options);
 	$scfg =3D PVE::Storage::storage_config($storecfg, $storeid);
     } elsif (drive_is_cdrom($drive)) {
@@ -244,6 +245,34 @@ sub generate_format_blockdev {
     return $blockdev;
 }
=20
+my sub generate_backing_blockdev;
+sub generate_backing_blockdev {
+    my ($storecfg, $snapshots, $deviceid, $drive, $snap_id) =3D @_;
+
+    my $snapshot =3D $snapshots->{$snap_id};
+    my $parentid =3D $snapshot->{parent};
+
+    my $volid =3D $drive->{file};
+
+    my $snap_file_blockdev =3D generate_file_blockdev($storecfg, $drive, $=
snap_id);
+    $snap_file_blockdev->{filename} =3D $snapshot->{file};
+    $drive->{ro} =3D 1;
+    my $snap_fmt_blockdev =3D generate_format_blockdev($storecfg, $drive, =
$snap_file_blockdev, $snap_id);
+    $snap_fmt_blockdev->{backing} =3D generate_backing_blockdev($storecfg,=
 $snapshots, $deviceid, $drive, $parentid) if $parentid;
+    return $snap_fmt_blockdev;
+}
+
+my sub generate_backing_chain_blockdev {
+    my ($storecfg, $deviceid, $drive) =3D @_;
+
+    my $volid =3D $drive->{file};
+
+    my $snapshots =3D PVE::Storage::volume_snapshot_info($storecfg, $volid=
);
+    my $parentid =3D $snapshots->{'current'}->{parent};
+    return undef if !$parentid;
+    return generate_backing_blockdev($storecfg, $snapshots, $deviceid, $dr=
ive, $parentid);
+}
+
 sub generate_drive_blockdev {
     my ($storecfg, $drive, $live_restore_name, $size) =3D @_;
=20
@@ -262,6 +291,12 @@ sub generate_drive_blockdev {
     my $blockdev_file =3D generate_file_blockdev($storecfg, $drive);
     my $blockdev_format =3D generate_format_blockdev($storecfg, $drive, $b=
lockdev_file, undef, $size);
=20
+    my $support_qemu_snapshots =3D PVE::Storage::volume_support_qemu_snaps=
hot($storecfg, $volid);
+    if ($support_qemu_snapshots && $support_qemu_snapshots eq 'external') {
+	my $backing_chain  =3D generate_backing_chain_blockdev($storecfg, "drive-=
$drive_id", $drive);
+	$blockdev_format->{backing} =3D $backing_chain if $backing_chain;
+    }
+
     my $blockdev_live_restore =3D 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-ba=
ckingchain.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=3D1G
+
+[snap1]
+name: simple
+scsi0: localsnapext:8006/vm-8006-disk-0.qcow2,size=3D1G
+snaptime: 1748933042
+
+[snap2]
+parent: snap1
+name: simple
+scsi0: localsnapext:8006/vm-8006-disk-0.qcow2,size=3D1G
+snaptime: 1748933043
+
+[snap3]
+parent: snap2
+name: simple
+scsi0: localsnapext:8006/vm-8006-disk-0.qcow2,size=3D1G
+snaptime: 1748933044
diff --git a/test/cfg2cmd/simple-backingchain.conf.cmd b/test/cfg2cmd/simpl=
e-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=3Don' \
+  -no-shutdown \
+  -chardev 'socket,id=3Dqmp,path=3D/var/run/qemu-server/8006.qmp,server=3D=
on,wait=3Doff' \
+  -mon 'chardev=3Dqmp,mode=3Dcontrol' \
+  -chardev 'socket,id=3Dqmp-event,path=3D/var/run/qmeventd.sock,reconnect-=
ms=3D5000' \
+  -mon 'chardev=3Dqmp-event,mode=3Dcontrol' \
+  -pidfile /var/run/qemu-server/8006.pid \
+  -daemonize \
+  -smp '1,sockets=3D1,cores=3D1,maxcpus=3D1' \
+  -nodefaults \
+  -boot 'menu=3Don,strict=3Don,reboot-timeout=3D1000,splash=3D/usr/share/q=
emu-server/bootsplash.jpg' \
+  -vnc 'unix:/var/run/qemu-server/8006.vnc,password=3Don' \
+  -cpu kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep \
+  -m 512 \
+  -global 'PIIX4_PM.disable_s3=3D1' \
+  -global 'PIIX4_PM.disable_s4=3D1' \
+  -device 'pci-bridge,id=3Dpci.1,chassis_nr=3D1,bus=3Dpci.0,addr=3D0x1e' \
+  -device 'pci-bridge,id=3Dpci.2,chassis_nr=3D2,bus=3Dpci.0,addr=3D0x1f' \
+  -device 'piix3-usb-uhci,id=3Duhci,bus=3Dpci.0,addr=3D0x1.0x2' \
+  -device 'usb-tablet,id=3Dtablet,bus=3Duhci.0,port=3D1' \
+  -device 'VGA,id=3Dvga,bus=3Dpci.0,addr=3D0x2' \
+  -device 'virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3,free-pa=
ge-reporting=3Don' \
+  -iscsi 'initiator-name=3Diqn.1993-08.org.debian:01:aabbccddeeff' \
+  -device 'lsi,id=3Dscsihw0,bus=3Dpci.0,addr=3D0x5' \
+  -object '{"id":"throttle-drive-scsi0","limits":{},"qom-type":"throttle-g=
roup"}' \
+  -blockdev '{"driver":"throttle","file":{"backing":{"backing":{"cache":{"=
direct":true,"no-flush":false},"driver":"qcow2","file":{"aio":"io_uring","c=
ache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"igno=
re","driver":"file","filename":"/var/lib/vz/images/8006/snap1-vm-8006-disk-=
0.qcow2","node-name":"e-aN9FfpTi1eqQ4kUSoMKsyEYSM6k"},"node-name":"f-aN9Ffp=
Ti1eqQ4kUSoMKsyEYSM6k","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","fil=
ename":"/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-z=
eroes":"on","discard":"ignore","driver":"file","filename":"/var/lib/vz/imag=
es/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=3Dscsihw0.0,scsi-id=3D0,drive=3Ddrive-scsi0,id=3Dsc=
si0' \
+  -machine 'type=3Dpc+pve0'
diff --git a/test/run_config2command_tests.pl b/test/run_config2command_tes=
ts.pl
index d689fc5b..83b513ec 100755
--- a/test/run_config2command_tests.pl
+++ b/test/run_config2command_tests.pl
@@ -33,6 +33,15 @@ my $base_env =3D {
 		type =3D> 'dir',
 		shared =3D> 0,
 	    },
+	    localsnapext =3D> {
+		content =3D> {
+		    images =3D> 1,
+		},
+		path =3D> '/var/lib/vz',
+		type =3D> 'dir',
+		shared =3D> 0,
+		snapext =3D> 1,
+	    },
 	    noimages =3D> {
 		content =3D> {
 		    iso =3D> 1,
@@ -492,6 +501,23 @@ my $storage_module =3D Test::MockModule->new("PVE::Sto=
rage");
 $storage_module->mock(
     activate_volumes =3D> sub {
 	return;
+    },
+    volume_snapshot_info =3D> sub {
+	my $snapshots =3D {
+	    current =3D> {
+		file =3D> '/var/lib/vz/images/8006/vm-8006-disk-0.qcow2',
+		parent =3D> 'snap2'
+	    },
+	    snap2 =3D> {
+		file =3D> '/var/lib/vz/images/8006/snap2-vm-8006-disk-0.qcow2',
+		parent =3D> 'snap1'
+	    },
+	    snap1 =3D> {
+		file =3D> '/var/lib/vz/images/8006/snap1-vm-8006-disk-0.qcow2',
+
+	    },
+	};
+	return $snapshots;
     }
 );
=20
--=20
2.39.5



--===============7645187548240490911==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

--===============7645187548240490911==--