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 9EF911FF2C5 for ; Mon, 8 Jul 2024 17:14:08 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B754C99C7; Mon, 8 Jul 2024 17:14:27 +0200 (CEST) Date: Mon, 8 Jul 2024 17:13:54 +0200 From: Christoph Heiss To: Aaron Lauterer Message-ID: References: <20240516102837.422278-1-c.heiss@proxmox.com> <20240516102837.422278-2-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-SPAM-LEVEL: Spam detection results: 0 AWL 0.009 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: Re: [pve-devel] [PATCH installer 1/3] low-level: add zfs module for retrieving importable zpool info 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 Cc: 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" Thanks for the review! On Mon, Jul 08, 2024 at 04:24:16PM GMT, Aaron Lauterer wrote: > On 2024-05-16 12:28, Christoph Heiss wrote: > > [..] > > diff --git a/Proxmox/Sys/ZFS.pm b/Proxmox/Sys/ZFS.pm > > new file mode 100644 > > index 0000000..4c732ca > > --- /dev/null > > +++ b/Proxmox/Sys/ZFS.pm > > @@ -0,0 +1,43 @@ > > +package Proxmox::Sys::ZFS; > > + > > +use strict; > > +use warnings; > > + > > +use Proxmox::Sys::Command qw(run_command); > > + > > +use base qw(Exporter); > > +our @EXPORT_OK = qw(get_exported_pools); > > + > > Some of the flow in this function is difficult to understand without having > a sample of the text it is parsing. Could we have a small example, maybe > added as comment? > That could help people to see what is it trying to parse, even if they are > not too familiar with the expected output Makes sense, will do that! I'll also add some tests using verbatim outputs of `zfs import`, such that these can always be run. Probably easier than creating test pools and calling `zfs import` at test run time. > > > +my sub parse_pool_list { > > + my ($fh) = @_; > > + > > + my @pools; > > + my $pool = {}; # last found pool in output > > + > > + while (my $line = <$fh>) { > > + if ($line =~ /^\s+pool: (.+)$/) { > > + push @pools, $pool if %$pool; > > + $pool = { name => $1 }; > > + next; > > + } > > + > > + next if !%$pool; > > + > > + if ($line =~ /^\s*(id|state|status|action): (.+)$/) { > > + chomp($pool->{$1} = $2); > > + next; > > + } > > + } > > + > > + push @pools, $pool if %$pool; > > + return \@pools; > > not too sure, but we usually tend to use anonymous arrays, $pools = []; > then we could just return $pools > The downside is of course that we need to dereference it in all the other > places, AFAICT all the `push` lines: > push @$pools ... > > But IME this is more in line with how usually handle such code. Sure, I'll rewrite it in that style for v2. _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel