[pve-devel] [PATCH storage] calculate reasonable metadatasize for lvm thin pools on creation

Tim Marx t.marx at proxmox.com
Fri Dec 6 14:04:45 CET 2019


Signed-off-by: Tim Marx <t.marx at proxmox.com>
---
 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.20.1



More information about the pve-devel mailing list