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

Tim Marx t.marx at proxmox.com
Wed Oct 31 14:04:28 CET 2018


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*(.*)$/) {
 		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
 		    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;
 		}
 	    }
-- 
2.11.0




More information about the pve-devel mailing list