[pve-devel] [PATCH storage 4/5] LVMPlugin: factor out the lv creation

Dominik Csapak d.csapak at proxmox.com
Tue Jun 4 09:21:16 CEST 2019


we will want to create lvs manually for ceph nautilus db/wal devices

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/Storage/LVMPlugin.pm | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/PVE/Storage/LVMPlugin.pm b/PVE/Storage/LVMPlugin.pm
index 9ad7979..50a4f64 100644
--- a/PVE/Storage/LVMPlugin.pm
+++ b/PVE/Storage/LVMPlugin.pm
@@ -296,6 +296,22 @@ sub lvm_find_free_diskname {
     return PVE::Storage::Plugin::get_next_vm_diskname($disk_list, $storeid, $vmid, undef, $scfg);
 }
 
+sub lvcreate {
+    my ($vg, $name, $size, $tags) = @_;
+
+    if ($size =~ m/\d$/) { # no unit is given
+	$size .= "k"; # default to kilobytes
+    }
+
+    my $cmd = ['/sbin/lvcreate', '-aly', '--size', $size, '--name', $name];
+    for my $tag (@$tags) {
+	push @$cmd, '--addtag', $tag;
+    }
+    push @$cmd, $vg;
+
+    run_command($cmd, errmsg => "lvcreate '$vg/$name' error");
+}
+
 sub alloc_image {
     my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
 
@@ -317,9 +333,7 @@ sub alloc_image {
     $name = lvm_find_free_diskname(lvm_list_volumes($vg), $vg, $storeid, $vmid, $scfg)
 	if !$name;
 
-    my $cmd = ['/sbin/lvcreate', '-aly', '--addtag', "pve-vm-$vmid", '--size', "${size}k", '--name', $name, $vg];
-
-    run_command($cmd, errmsg => "lvcreate '$vg/pve-vm-$vmid' error");
+    lvcreate($vg, $name, $size, ["pve-vm-$vmid"]);
 
     return $name;
 }
-- 
2.11.0





More information about the pve-devel mailing list