[pve-devel] [PATCH v2 storage 1/3] close #1949: storage zfs: changed zpool command parser

Dominik Csapak d.csapak at proxmox.com
Mon Nov 5 14:15:31 CET 2018


On 10/31/18 2:04 PM, Tim Marx wrote:
> Signed-off-by: Tim Marx <t.marx at proxmox.com>
> ---
> 
> changes since v1:
> * changed regex matching groups
> * changed $lvl back to int from float
> * set vdev keys only if defined
> 
>   PVE/API2/Disks/ZFS.pm | 26 ++++++++++++--------------
>   1 file changed, 12 insertions(+), 14 deletions(-)
> 
> diff --git a/PVE/API2/Disks/ZFS.pm b/PVE/API2/Disks/ZFS.pm
> index 58a498d..4780bcd 100644
> --- a/PVE/API2/Disks/ZFS.pm
> +++ b/PVE/API2/Disks/ZFS.pm
> @@ -233,39 +233,37 @@ __PACKAGE__->register_method ({
>   		$pool->{$curfield} .= " " . $1;
>   	    } elsif (!$config && $line =~ m/^\s*config:/) {
>   		$config = 1;
> -	    } elsif ($config && $line =~ m/^(\s+)(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*(.*)$/) {
> +	    } elsif ($config && $line =~ m/^(\s+)(\S+)\s*(\S+)?\s*(\S+)?\s*(\S+)?\s*(\S+)?\s*(.*)$/) {

mhmm works, but not exactly what i had in mind, more like:

(\s+)(\S+)(?:\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+))?\s*(.*)

this makes it so that state,read,write,cksum are all there, or none

any regex experts here (regarding performance/pitfalls/etc.) ? @all

>   		my ($space, $name, $state, $read, $write, $cksum, $msg) = ($1, $2, $3, $4, $5, $6, $7);
> -		if ($space  =~ m/^\t(\s+)$/) {
> -		    my $lvl= length($1)/2; # two spaces per level
> +		if ($name ne "NAME" and $name ne $param->{name}) {
> +		    my $lvl= length($space)+2/2; # two spaces per level

mhmm, i dont think it does what it you think it does (operator order)
it now adds 1 to the length of the string

eg. "aaa" => 4

but even disegarding operator order it would mean that we get
"aaa" => 5/2 => 2.5

rest looks good

>   		    my $vdev = {
>   			name => $name,
> -			state => $state,
> -			read => $read + 0,
> -			write => $write + 0,
> -			cksum => $cksum + 0,
>   			msg => $msg,
>   			lvl => $lvl,
>   		    };
> -
> +		
> +		    $vdev->{state} = $state if defined($state);
> +		    $vdev->{read} = $read + 0 if defined($read);
> +		    $vdev->{write} = $write + 0 if defined($write);
> +		    $vdev->{cksum} = $cksum + 0 if defined($cksum);
> +		
>   		    my $cur = pop @$stack;
>   
>   		    if ($lvl > $curlvl) {
>   			$cur->{children} = [ $vdev ];
> -			push @$stack, $cur;
> -			push @$stack, $vdev;
>   		    } elsif ($lvl == $curlvl) {
>   			$cur = pop @$stack;
>   			push @{$cur->{children}}, $vdev;
> -			push @$stack, $cur;
> -			push @$stack, $vdev;
>   		    } else {
>   			while ($lvl <= $cur->{lvl}) {
>   			    $cur = pop @$stack;
>   			}
>   			push @{$cur->{children}}, $vdev;
> -			push @$stack, $cur;
> -			push @$stack, $vdev;
>   		    }
> +		
> +		    push @$stack, $cur;
> +		    push @$stack, $vdev;
>   		    $curlvl = $lvl;
>   		}
>   	    }
> 





More information about the pve-devel mailing list