[PATCH v4 pve-storage 5/5] lvm: add lvremove helper

Alexandre Derumier alexandre.derumier at groupe-cyllene.com
Tue Mar 11 11:28:59 CET 2025


Signed-off-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
---
 src/PVE/Storage/LVMPlugin.pm | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index 2431fcd..ab3563b 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -373,6 +373,14 @@ sub lvrename {
     );
 }
 
+sub lvremove {
+   my ($name, $vg) = @_;
+
+   my $path = $vg ? "$vg/$name" : $name;
+   my $cmd = ['/sbin/lvremove', '-f', $path];
+   run_command($cmd, errmsg => "lvremove '$path' error");
+}
+
 sub alloc_image {
     my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size, $backing) = @_;
 
@@ -453,8 +461,7 @@ sub free_image {
 	warn $@ if $@;
 
 	$class->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
-	    my $cmd = ['/sbin/lvremove', '-f', "$vg/del-$volname"];
-	    run_command($cmd, errmsg => "lvremove '$vg/del-$volname' error");
+	    lvremove("del-$volname", $vg);
 	});
 	print "successfully removed volume $volname ($vg/del-$volname)\n";
     };
@@ -470,9 +477,7 @@ sub free_image {
 	run_command($cmd, errmsg => "lvrename '$vg/$volname' error");
 	return $zero_out_worker;
     } else {
-	my $tmpvg = $scfg->{vgname};
-	$cmd = ['/sbin/lvremove', '-f', "$tmpvg/$volname"];
-	run_command($cmd, errmsg => "lvremove '$tmpvg/$volname' error");
+	lvremove($volname, $scfg->{vgname});
     }
 
     return undef;
-- 
2.39.5




More information about the pve-devel mailing list