[PATCH pve-storage 3/4] lvmplugin: add thin volume support for LVM external snapshots
Tiago Sousa
joao.sousa at eurotux.com
Fri Oct 17 13:25:28 CEST 2025
Signed-off-by: Tiago Sousa <joao.sousa at eurotux.com>
---
src/PVE/Storage/Common.pm | 4 ++--
src/PVE/Storage/LVMPlugin.pm | 19 +++++++++++++++----
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/PVE/Storage/Common.pm b/src/PVE/Storage/Common.pm
index 222dc76..1e5d4c6 100644
--- a/src/PVE/Storage/Common.pm
+++ b/src/PVE/Storage/Common.pm
@@ -170,7 +170,7 @@ C<$options> currently allows setting the C<preallocation> value.
=cut
sub qemu_img_create_qcow2_backed {
- my ($path, $backing_path, $backing_format, $options) = @_;
+ my ($path, $backing_path, $backing_format, $options, $thin) = @_;
my $cmd = [
'/usr/bin/qemu-img',
@@ -188,7 +188,7 @@ sub qemu_img_create_qcow2_backed {
my $opts = ['extended_l2=on', 'cluster_size=128k'];
push @$opts, "preallocation=$options->{preallocation}"
- if defined($options->{preallocation});
+ if defined($options->{preallocation}) && !$thin;
push @$cmd, '-o', join(',', @$opts) if @$opts > 0;
run_command($cmd, errmsg => "unable to create image");
diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index 0416c9e..dc5e648 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -575,7 +575,7 @@ sub lvrename {
}
my sub lvm_qcow2_format {
- my ($class, $storeid, $scfg, $name, $fmt, $backing_snap, $size) = @_;
+ my ($class, $storeid, $scfg, $name, $fmt, $backing_snap, $size, $thin) = @_;
$class->activate_volume($storeid, $scfg, $name);
my $path = $class->path($scfg, $name, $storeid);
@@ -585,7 +585,9 @@ my sub lvm_qcow2_format {
};
if ($backing_snap) {
my $backing_volname = get_snap_name($class, $name, $backing_snap);
- PVE::Storage::Common::qemu_img_create_qcow2_backed($path, $backing_volname, $fmt, $options);
+ PVE::Storage::Common::qemu_img_create_qcow2_backed(
+ $path, $backing_volname, $fmt, $options, $thin,
+ );
} else {
PVE::Storage::Common::qemu_img_create($fmt, $size, $path, $options);
}
@@ -629,7 +631,16 @@ my sub alloc_lvm_image {
die "no such volume group '$vg'\n" if !defined($vgs->{$vg});
my $free = int($vgs->{$vg}->{free});
- my $lvmsize = calculate_lvm_size($size, $fmt, $backing_snap);
+ my $lvmsize;
+
+ # FIX: make this variable a check box when taking a snapshot
+ # right now all snapshots are created thin for testing purposes
+ my $thin = $backing_snap ? 1 : 0;
+ if ($thin) {
+ $lvmsize = 2 * 1024 * 1024;
+ } else {
+ $lvmsize = calculate_lvm_size($size, $fmt, $backing_snap);
+ }
die "not enough free space ($free < $size)\n" if $free < $size;
@@ -641,7 +652,7 @@ my sub alloc_lvm_image {
return if $fmt ne 'qcow2';
#format the lvm volume with qcow2 format
- eval { lvm_qcow2_format($class, $storeid, $scfg, $name, $fmt, $backing_snap, $size) };
+ eval { lvm_qcow2_format($class, $storeid, $scfg, $name, $fmt, $backing_snap, $size, $thin) };
if ($@) {
my $err = $@;
#no need to safe cleanup as the volume is still empty
--
2.47.3
More information about the pve-devel
mailing list