[pve-devel] [PATCH Storage] Newly created LVM volumes are now created with a number of stripes equal to the number of physical volumes in a volume group.

Martin Lablans code at martin.lablans.de
Wed Jul 26 20:47:03 CEST 2017


Signed-off-by: Martin Lablans <code at martin.lablans.de>
---
  PVE/Storage/LVMPlugin.pm | 19 ++++++++++++++++++-
  1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/PVE/Storage/LVMPlugin.pm b/PVE/Storage/LVMPlugin.pm
index 9633e4c..cfb18e4 100644
--- a/PVE/Storage/LVMPlugin.pm
+++ b/PVE/Storage/LVMPlugin.pm
@@ -285,13 +285,30 @@ sub alloc_image {
      $name = lvm_find_free_diskname(lvm_list_volumes($vg), $vg, 
$storeid, $vmid)
  	if !$name;

-    my $cmd = ['/sbin/lvcreate', '-aly', '--addtag', "pve-vm-$vmid", 
'--size', "${size}k", '--name', $name, $vg];
+    my $num_pvs = lvm_find_number_of_pv($vg);
+
+    my $cmd = ['/sbin/lvcreate', '-aly', '-i', $num_pvs, '--addtag', 
"pve-vm-$vmid", '--size', "${size}k", '--name', $name, $vg];

      run_command($cmd, errmsg => "lvcreate '$vg/pve-vm-$vmid' error");

      return $name;
  }

+sub lvm_find_number_of_pv {
+    my ($vg) = @_;
+
+    my $cmd = ['/sbin/vgs', $vg, '--noheadings', '--unbuffered', 
'--nosuffix', '--options', 'pv_count'];
+
+    my $ret;
+
+    run_command($cmd, errmsg => "lvm_find_number_of_pv: Cannot 
determine number of PVs for VG $vg", outfunc => sub {
+        my $line = shift;
+        $ret = trim($line);
+    });
+
+    return $ret;
+}
+
  sub free_image {
      my ($class, $storeid, $scfg, $volname, $isBase) = @_;

-- 
2.7.4



More information about the pve-devel mailing list