From 3ea55f0532944b82b01ba1aae3c77431a9a0cb82 Mon Sep 17 00:00:00 2001 From: Tim Marx Date: Fri, 6 Dec 2019 14:04:45 +0100 Subject: [PATCH] calculate reasonable metadatasize for lvm thin pools on creation Letting LVM set the meta-data size internally was not a good idea, as it produces really small metadata LVs. Adapts the same logic as the installer. Signed-off-by: Tim Marx Reviewed-By: Dominik Csapak Tested-By: Dominik Csapak --- PVE/API2/Disks/LVMThin.pm | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/PVE/API2/Disks/LVMThin.pm b/PVE/API2/Disks/LVMThin.pm index 23c0279..4d303f8 100644 --- a/PVE/API2/Disks/LVMThin.pm +++ b/PVE/API2/Disks/LVMThin.pm @@ -109,9 +109,26 @@ __PACKAGE__->register_method ({ my $worker = sub { PVE::Diskmanage::locked_disk_action(sub { PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name); + my $pv = PVE::Storage::LVMPlugin::lvm_pv_info($dev); + # keep some free space just in case + my $datasize = $pv->{size} - 128*1024; + # default to 1% for metadata + my $metadatasize = $datasize/100; + # but at least 1G, as recommended in lvmthin man + $metadatasize = 1024*1024 if $metadatasize < 1024*1024; + # but at most 16G, which is the current lvm max + $metadatasize = 16*1024*1024 if $metadatasize > 16*1024*1024; + # shrink data by needed amount for metadata + $datasize -= 2*$metadatasize; - # create thinpool with size 100%, let lvm handle the metadata size - run_command(['/sbin/lvcreate', '--type', 'thin-pool', '-l100%FREE', '-n', $name, $name]); + run_command([ + '/sbin/lvcreate', + '--type', 'thin-pool', + "-L${datasize}K", + '--poolmetadatasize', "${metadatasize}K", + '-n', $name, + $name + ]); if ($param->{add_storage}) { my $storage_params = { -- 2.39.2