all lists on 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 1/1] implement external snapshot
Date: Thu, 19 Sep 2024 15:19:15 +0200	[thread overview]
Message-ID: <mailman.19.1726751998.332.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20240919131915.2624831-1-alexandre.derumier@groupe-cyllene.com>

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

From: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 1/1] implement external snapshot
Date: Thu, 19 Sep 2024 15:19:15 +0200
Message-ID: <20240919131915.2624831-3-alexandre.derumier@groupe-cyllene.com>

Signed-off-by: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
---
 PVE/QemuServer.pm | 74 +++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 62 insertions(+), 12 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index b26da505..646e3476 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -4713,9 +4713,14 @@ sub qemu_volume_snapshot {
     my ($vmid, $deviceid, $storecfg, $volid, $snap) = @_;
 
     my $running = check_running($vmid);
-
-    if ($running && do_snapshots_with_qemu($storecfg, $volid, $deviceid)) {
-	mon_cmd($vmid, 'blockdev-snapshot-internal-sync', device => $deviceid, name => $snap);
+    my $do_snapshots_with_qemu = do_snapshots_with_qemu($storecfg, $volid, $deviceid) if $running;
+    if ($do_snapshots_with_qemu) {
+	if($do_snapshots_with_qemu == 2) {
+	    my $snapshot_file = PVE::Storage::path($storecfg, $volid, $snap);
+	    mon_cmd($vmid, 'blockdev-snapshot-sync', device => $deviceid, 'snapshot-file' => $snapshot_file, format => 'qcow2');
+	} else {
+	    mon_cmd($vmid, 'blockdev-snapshot-internal-sync', device => $deviceid, name => $snap);
+	}
     } else {
 	PVE::Storage::volume_snapshot($storecfg, $volid, $snap);
     }
@@ -4735,13 +4740,48 @@ sub qemu_volume_snapshot_delete {
 	});
     }
 
-    if ($attached_deviceid && do_snapshots_with_qemu($storecfg, $volid, $attached_deviceid)) {
-	mon_cmd(
-	    $vmid,
-	    'blockdev-snapshot-delete-internal-sync',
-	    device => $attached_deviceid,
-	    name => $snap,
-	);
+    my $do_snapshots_with_qemu = do_snapshots_with_qemu($storecfg, $volid, $attached_deviceid) if $running;
+    if ($attached_deviceid && $do_snapshots_with_qemu) {
+
+	if ($do_snapshots_with_qemu == 2) {
+
+	    my $snapshots = PVE::Storage::volume_snapshot_info($storecfg, $volid);
+
+	    my $currentpath = $snapshots->{current}->{file};
+	    my $snappath = $snapshots->{$snap}->{file};
+	    my $parentsnap = $snapshots->{$snap}->{parent};
+	    die "error: we can't find a parent for this snapshot" if !$parentsnap;
+
+	    my $parentpath = $snapshots->{$parentsnap}->{file};
+	    my $parentformat = $snapshots->{$parentsnap}->{'format'} if $parentsnap;
+
+	    print "block-commit  top:$snappath base:$parentpath\n";
+            my $job_id = "commit-$attached_deviceid";
+	    my $jobs = {};
+	    mon_cmd(
+	        $vmid,
+		'block-commit',
+		'job-id' => $job_id,
+		device => $attached_deviceid,
+		top => $snappath,
+		base => $parentpath,
+	    );
+	    $jobs->{$job_id} = {};
+
+	    #if we delete the current, block-job-complete to finish
+	    my $completion = $currentpath eq $snappath ? 'complete' : 'auto';
+	    qemu_drive_mirror_monitor($vmid, undef, $jobs, $completion, 0, 'commit');
+
+	    my (undef, $snap_volid) = PVE::Storage::path_to_volume_id($storecfg, $snappath);
+	    PVE::Storage::vdisk_free($storecfg, $snap_volid);
+	} else {
+	    mon_cmd(
+	        $vmid,
+		'blockdev-snapshot-delete-internal-sync',
+		device => $attached_deviceid,
+		name => $snap,
+	    );
+	}
     } else {
 	PVE::Storage::volume_snapshot_delete(
 	    $storecfg, $volid, $snap, $attached_deviceid ? 1 : undef);
@@ -7776,6 +7816,8 @@ sub do_snapshots_with_qemu {
 	return 1;
     }
 
+    return 2 if $scfg->{snapext};
+
     if ($volid =~ m/\.(qcow2|qed)$/){
 	return 1;
     }
@@ -7849,8 +7891,16 @@ sub qemu_img_convert {
     if ($src_storeid) {
 	PVE::Storage::activate_volumes($storecfg, [$src_volid], $snapname);
 	my $src_scfg = PVE::Storage::storage_config($storecfg, $src_storeid);
-	$src_format = qemu_img_format($src_scfg, $src_volname);
-	$src_path = PVE::Storage::path($storecfg, $src_volid, $snapname);
+	if($src_scfg->{snapext} && $snapname) {
+	    my $snapshots = PVE::Storage::volume_snapshot_info($storecfg, $src_volid);
+	    my $parentsnap = $snapshots->{$snapname}->{parent};
+	    $src_format = $snapshots->{$parentsnap}->{format};
+	    $src_path = $snapshots->{$parentsnap}->{file};
+	    $snapname = undef;
+	} else {
+	    $src_format = qemu_img_format($src_scfg, $src_volname);
+	    $src_path = PVE::Storage::path($storecfg, $src_volid, $snapname);
+	}
 	$src_is_iscsi = ($src_path =~ m|^iscsi://|);
 	$cachemode = 'none' if $src_scfg->{type} eq 'zfspool';
     } elsif (-f $src_volid || -b $src_volid) {
-- 
2.39.2



[-- 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:[~2024-09-19 13:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240919131915.2624831-1-alexandre.derumier@groupe-cyllene.com>
2024-09-19 13:19 ` [pve-devel] [PATCH pve-storage 1/1] add external snasphot support Alexandre Derumier via pve-devel
2024-09-19 13:19 ` Alexandre Derumier via pve-devel [this message]

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.19.1726751998.332.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal