Signed-off-by: Martin Lablans <c...@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
_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to