[pve-devel] [RFC pve-storage 13/36] common: lvm: update code style

Max Carrara m.carrara at proxmox.com
Wed Jul 17 11:40:11 CEST 2024


in order to be more in line with our style guide [0]. This also
renames some parameters for clarity.

[0]: https://pve.proxmox.com/wiki/Perl_Style_Guide

Signed-off-by: Max Carrara <m.carrara at proxmox.com>
---
 src/PVE/Storage/Common/LVM.pm | 80 +++++++++++++++++++++++++----------
 1 file changed, 57 insertions(+), 23 deletions(-)

diff --git a/src/PVE/Storage/Common/LVM.pm b/src/PVE/Storage/Common/LVM.pm
index d4fa95f..2e010b6 100644
--- a/src/PVE/Storage/Common/LVM.pm
+++ b/src/PVE/Storage/Common/LVM.pm
@@ -167,7 +167,12 @@ sub lvm_create_volume_group : prototype($$$) {
     $cmd = ['/sbin/vgcreate', $vgname, $device];
     # push @$cmd, '-c', 'y' if $shared; # we do not use this yet
 
-    run_command($cmd, errmsg => "vgcreate $vgname $device error", errfunc => $ignore_no_medium_warnings, outfunc => $ignore_no_medium_warnings);
+    run_command(
+	$cmd,
+	errmsg => "vgcreate $vgname $device error",
+	errfunc => $ignore_no_medium_warnings,
+	outfunc => $ignore_no_medium_warnings
+    );
 }
 
 =pod
@@ -248,10 +253,10 @@ sub lvm_vgs : prototype(;$) {
     my $cols = [qw(vg_name vg_size vg_free lv_count)];
 
     if ($includepvs) {
-	push @$cols, qw(pv_name pv_size pv_free);
+	push $cols->@*, qw(pv_name pv_size pv_free);
     }
 
-    push @$cmd, join(',', @$cols);
+    push $cmd->@*, join(',', @$cols);
 
     my $vgs = {};
     eval {
@@ -268,7 +273,7 @@ sub lvm_vgs : prototype(;$) {
 	    };
 
 	    if (defined($pvname) && defined($pvsize) && defined($pvfree)) {
-		push @{$vgs->{$name}->{pvs}}, {
+		push $vgs->{$name}->{pvs}->@*, {
 		    name => $pvname,
 		    size => int($pvsize),
 		    free => int($pvfree),
@@ -333,7 +338,20 @@ The returned hash has the following structure:
 sub lvm_list_volumes : prototype(;$) {
     my ($vgname) = @_;
 
-    my $option_list = 'vg_name,lv_name,lv_size,lv_attr,pool_lv,data_percent,metadata_percent,snap_percent,uuid,tags,metadata_size,time';
+    my $option_list = join(',', qw(
+	vg_name
+	lv_name
+	lv_size
+	lv_attr
+	pool_lv
+	data_percent
+	metadata_percent
+	snap_percent
+	uuid
+	tags
+	metadata_size
+	time
+    ));
 
     my $cmd = [
 	'/sbin/lvs', '--separator', ':', '--noheadings', '--units', 'b',
@@ -342,7 +360,7 @@ sub lvm_list_volumes : prototype(;$) {
 	'--options', $option_list,
     ];
 
-    push @$cmd, $vgname if $vgname;
+    push $cmd->@*, $vgname if $vgname;
 
     my $lvs = {};
     run_command($cmd, outfunc => sub {
@@ -350,7 +368,21 @@ sub lvm_list_volumes : prototype(;$) {
 
 	$line = trim($line);
 
-	my ($vg_name, $lv_name, $lv_size, $lv_attr, $pool_lv, $data_percent, $meta_percent, $snap_percent, $uuid, $tags, $meta_size, $ctime) = split(':', $line);
+	my (
+	    $vg_name,
+	    $lv_name,
+	    $lv_size,
+	    $lv_attr,
+	    $pool_lv,
+	    $data_percent,
+	    $meta_percent,
+	    $snap_percent,
+	    $uuid,
+	    $tags,
+	    $meta_size,
+	    $ctime
+	) = split(':', $line);
+
 	return if !$vg_name;
 	return if !$lv_name;
 
@@ -370,8 +402,8 @@ sub lvm_list_volumes : prototype(;$) {
 	    $meta_percent ||= 0;
 	    $snap_percent ||= 0;
 	    $d->{metadata_size} = int($meta_size);
-	    $d->{metadata_used} = int(($meta_percent * $meta_size)/100);
-	    $d->{used} = int(($data_percent * $lv_size)/100);
+	    $d->{metadata_used} = int(($meta_percent * $meta_size) / 100);
+	    $d->{used} = int(($data_percent * $lv_size) / 100);
 	}
 	$lvs->{$vg_name}->{$lv_name} = $d;
     },
@@ -411,18 +443,20 @@ See also: L<C<lvm_list_volumes>|/lvm_list_volumes>
 =cut
 
 sub lvm_list_thinpools : prototype(;$) {
-    my ($vg) = @_;
+    my ($vgname) = @_;
 
-    my $lvs = lvm_list_volumes($vg);
+    my $lvs = lvm_list_volumes($vgname);
     my $thinpools = [];
 
-    foreach my $vg (keys %$lvs) {
-	foreach my $lvname (keys %{$lvs->{$vg}}) {
-	    next if $lvs->{$vg}->{$lvname}->{lv_type} ne 't';
-	    my $lv = $lvs->{$vg}->{$lvname};
+    for my $vgname (keys $lvs->%*) {
+	for my $lvname (keys $lvs->{$vgname}->%*) {
+	    next if $lvs->{$vgname}->{$lvname}->{lv_type} ne 't';
+
+	    my $lv = $lvs->{$vgname}->{$lvname};
 	    $lv->{lv} = $lvname;
-	    $lv->{vg} = $vg;
-	    push @$thinpools, $lv;
+	    $lv->{vg} = $vgname;
+
+	    push $thinpools->@*, $lv;
 	}
     }
 
@@ -443,19 +477,19 @@ C<"50g"> (50 gibibytes), C<"1T"> (1 terabyte), etc.
 =cut
 
 sub lvm_lvcreate : prototype($$$;$) {
-    my ($vg, $name, $size, $tags) = @_;
+    my ($vgname, $name, $size, $tags) = @_;
 
     if ($size =~ m/\d$/) { # no unit is given
-	$size .= "k"; # default to kilobytes
+	$size .= "k"; # default to kibibytes
     }
 
     my $cmd = ['/sbin/lvcreate', '-aly', '-Wy', '--yes', '--size', $size, '--name', $name];
-    for my $tag (@$tags) {
-	push @$cmd, '--addtag', $tag;
+    for my $tag ($tags->@*) {
+	push $cmd->@*, '--addtag', $tag;
     }
-    push @$cmd, $vg;
+    push $cmd->@*, $vgname;
 
-    run_command($cmd, errmsg => "lvcreate '$vg/$name' error");
+    run_command($cmd, errmsg => "lvcreate '$vgname/$name' error");
 }
 
 =pod
-- 
2.39.2





More information about the pve-devel mailing list