From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 169441FF2C8 for ; Wed, 17 Jul 2024 11:42:08 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1E7DB38602; Wed, 17 Jul 2024 11:42:14 +0200 (CEST) From: Max Carrara To: pve-devel@lists.proxmox.com Date: Wed, 17 Jul 2024 11:40:11 +0200 Message-Id: <20240717094034.124857-14-m.carrara@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240717094034.124857-1-m.carrara@proxmox.com> References: <20240717094034.124857-1-m.carrara@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.029 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [RFC pve-storage 13/36] common: lvm: update code style X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" 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 --- 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|/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 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel