plugin: qemu block device: add support for snapshot option

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.

Such accesses are currently not done for running VMs via '-drive'
either, so there still is feature parity.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fiona Ebner
2025-07-02 18:27:45 +02:00
committed by Fabian Grünbichler
parent 590fb76238
commit 2d874037f3
5 changed files with 20 additions and 1 deletions

View File

@ -113,6 +113,9 @@ sub path {
sub qemu_blockdev_options { sub qemu_blockdev_options {
my ($class, $scfg, $storeid, $volname, $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]; my $lun = ($class->parse_volname($volname))[1];
return { return {

View File

@ -2009,6 +2009,9 @@ disk of a VM, containing its OMVF variables.
=back =back
=item C<< $options->{'snapshot-name'} >>: (optional) The snapshot name. Set when the associated snapshot should be opened rather than the
volume itself.
=back =back
=back =back
@ -2020,9 +2023,15 @@ sub qemu_blockdev_options {
my $blockdev = {}; my $blockdev = {};
my ($path) = $class->filesystem_path($scfg, $volname); my ($path) = $class->filesystem_path($scfg, $volname, $options->{'snapshot-name'});
if ($path =~ m|^/|) { 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 # 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' # 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. # devices here, those are not managed by the storage layer.

View File

@ -530,6 +530,7 @@ sub qemu_blockdev_options {
my ($name) = ($class->parse_volname($volname))[1]; my ($name) = ($class->parse_volname($volname))[1];
if ($scfg->{krbd}) { if ($scfg->{krbd}) {
$name .= '@' . $options->{'snapshot-name'} if $options->{'snapshot-name'};
my $rbd_dev_path = get_rbd_dev_path($scfg, $storeid, $name); my $rbd_dev_path = get_rbd_dev_path($scfg, $storeid, $name);
return { driver => 'host_device', filename => $rbd_dev_path }; return { driver => 'host_device', filename => $rbd_dev_path };
} }
@ -540,6 +541,7 @@ sub qemu_blockdev_options {
image => "$name", image => "$name",
}; };
$blockdev->{namespace} = "$scfg->{namespace}" if defined($scfg->{namespace}); $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}; $blockdev->{conf} = $cmd_option->{ceph_conf} if $cmd_option->{ceph_conf};

View File

@ -250,6 +250,9 @@ sub path {
sub qemu_blockdev_options { sub qemu_blockdev_options {
my ($class, $scfg, $storeid, $volname, $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 $name = ($class->parse_volname($volname))[1];
my $guid = $class->zfs_get_lu_name($scfg, $name); my $guid = $class->zfs_get_lu_name($scfg, $name);
my $lun = $class->zfs_get_lun_number($scfg, $guid); my $lun = $class->zfs_get_lun_number($scfg, $guid);

View File

@ -169,6 +169,8 @@ sub qemu_blockdev_options {
die "volume '$volname' not usable as VM image\n" if $format ne 'raw'; die "volume '$volname' not usable as VM image\n" if $format ne 'raw';
die "cannot attach only the snapshot of a zvol\n" if $options->{'snapshot-name'};
my ($path) = $class->path($scfg, $volname, $storeid); my ($path) = $class->path($scfg, $volname, $storeid);
my $blockdev = { driver => 'host_device', filename => $path }; my $blockdev = { driver => 'host_device', filename => $path };