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 396701FF164 for <inbox@lore.proxmox.com>; Fri, 23 May 2025 15:33:17 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1D6FA1BDC9; Fri, 23 May 2025 15:32:38 +0200 (CEST) From: Fiona Ebner <f.ebner@proxmox.com> To: pve-devel@lists.proxmox.com Date: Fri, 23 May 2025 15:31:55 +0200 Message-Id: <20250523133156.617227-10-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250523133156.617227-1-f.ebner@proxmox.com> References: <20250523133156.617227-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.033 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [RFC v2 storage 09/10] plugin: qemu block device: add support for snapshot option X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> 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/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> This is mostly in preparation for external qcow2 snapshot support. For internal qcow2 snapshots, which currently are the only supported variant, it is not possible to attach the snapshot only. If access to that is required it will need to be handled differently, e.g. via a FUSE/NBD export. Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> --- New in v2. src/PVE/Storage/ISCSIDirectPlugin.pm | 3 +++ src/PVE/Storage/Plugin.pm | 13 ++++++++++++- src/PVE/Storage/RBDPlugin.pm | 2 ++ src/PVE/Storage/ZFSPlugin.pm | 3 +++ src/PVE/Storage/ZFSPoolPlugin.pm | 2 ++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/PVE/Storage/ISCSIDirectPlugin.pm b/src/PVE/Storage/ISCSIDirectPlugin.pm index 8f25577..23e8a24 100644 --- a/src/PVE/Storage/ISCSIDirectPlugin.pm +++ b/src/PVE/Storage/ISCSIDirectPlugin.pm @@ -108,6 +108,9 @@ sub path { sub qemu_blockdev_options { my ($class, $scfg, $storeid, $volname, $options) = @_; + die "volume snapshot is not possible on iscsi device\n" + if $options->{'snapshot-name'}; + my $lun = ($class->parse_volname($volname))[1]; return { diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 7fe1b17..54e39a9 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -1921,6 +1921,11 @@ A hash reference with additional options. =over +=item C<< $options->{'snapshot-name'} >> + +(optional) The snapshot name. Set when the associated snapshot should be opened rather than the +volume itself. + =item C<< $options->{hints} >> A hash reference with hints indicating what the volume will be used for. This can be safely ignored @@ -1946,9 +1951,15 @@ sub qemu_blockdev_options { my $blockdev = {}; - my ($path) = $class->filesystem_path($scfg, $volname); + my ($path) = $class->filesystem_path($scfg, $volname, $options->{'snapshot-name'}); if ($path =~ m|^/|) { + # For qcow2 and qed the path of a snapshot will be the same, but it's not possible to attach + # the snapshot alone. + my $format = ($class->parse_volname($volname))[6]; + die "cannot attach only the snapshot of a '$format' image\n" + if $options->{'snapshot-name'} && ($format eq 'qcow2' || $format eq 'qed'); + # The 'file' driver only works for regular files. The check below is taken from # block/file-posix.c:hdev_probe_device() in QEMU. Do not bother with detecting 'host_cdrom' # devices here, those are not managed by the storage layer. diff --git a/src/PVE/Storage/RBDPlugin.pm b/src/PVE/Storage/RBDPlugin.pm index 6fa0689..72bd7c8 100644 --- a/src/PVE/Storage/RBDPlugin.pm +++ b/src/PVE/Storage/RBDPlugin.pm @@ -500,6 +500,7 @@ sub qemu_blockdev_options { my ($name) = ($class->parse_volname($volname))[1]; if ($scfg->{krbd}) { + $name .= '@'.$options->{'snapshot-name'} if $options->{'snapshot-name'}; my $rbd_dev_path = get_rbd_dev_path($scfg, $storeid, $name); return { driver => 'host_device', filename => $rbd_dev_path }; } @@ -510,6 +511,7 @@ sub qemu_blockdev_options { image => "$name", }; $blockdev->{namespace} = "$scfg->{namespace}" if defined($scfg->{namespace}); + $blockdev->{snapshot} = $options->{'snapshot-name'} if $options->{'snapshot-name'}; $blockdev->{conf} = $cmd_option->{ceph_conf} if $cmd_option->{ceph_conf}; diff --git a/src/PVE/Storage/ZFSPlugin.pm b/src/PVE/Storage/ZFSPlugin.pm index 1392781..963e860 100644 --- a/src/PVE/Storage/ZFSPlugin.pm +++ b/src/PVE/Storage/ZFSPlugin.pm @@ -250,6 +250,9 @@ sub path { sub qemu_blockdev_options { my ($class, $scfg, $storeid, $volname, $options) = @_; + die "direct access to snapshots not implemented\n" + if $options->{'snapshot-name'}; + my $name = ($class->parse_volname($volname))[1]; my $guid = $class->zfs_get_lu_name($scfg, $name); my $lun = $class->zfs_get_lun_number($scfg, $guid); diff --git a/src/PVE/Storage/ZFSPoolPlugin.pm b/src/PVE/Storage/ZFSPoolPlugin.pm index 302c965..cd01414 100644 --- a/src/PVE/Storage/ZFSPoolPlugin.pm +++ b/src/PVE/Storage/ZFSPoolPlugin.pm @@ -164,6 +164,8 @@ sub path { sub qemu_blockdev_options { my ($class, $scfg, $storeid, $volname, $options) = @_; + die "cannot attach only the snapshot of a zvol\n" if $options->{'snapshot-name'}; + my ($path) = $class->path($scfg, $volname, $storeid); my $blockdev = { driver => 'host_device', filename => $path }; -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel