[pve-devel] [PATCH v2 storage 3/3] zfs: list images: code cleanup

Fiona Ebner f.ebner at proxmox.com
Tue Dec 20 14:16:38 CET 2022


Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---

New in v2.

 PVE/Storage/ZFSPoolPlugin.pm | 42 ++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
index 0899894..f829b86 100644
--- a/PVE/Storage/ZFSPoolPlugin.pm
+++ b/PVE/Storage/ZFSPoolPlugin.pm
@@ -254,36 +254,30 @@ sub free_image {
 sub list_images {
     my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
 
-    my $zfs_list = $class->zfs_list_zvol($scfg);
+    my $zfs_list = $class->zfs_list_zvol($scfg) // {};
 
     my $res = [];
 
-    if (my $dat = $zfs_list) {
+    for my $info (values $zfs_list->%*) {
+	my $volname = $info->{name};
+	my $parent = $info->{parent};
+	my $owner = $info->{vmid};
 
-	foreach my $image (keys %$dat) {
-
-	    my $info = $dat->{$image};
-
-	    my $volname = $info->{name};
-	    my $parent = $info->{parent};
-	    my $owner = $info->{vmid};
-
-	    if ($parent && $parent =~ m/^(\S+)\@__base__$/) {
-		my ($basename) = ($1);
-		$info->{volid} = "$storeid:$basename/$volname";
-	    } else {
-		$info->{volid} = "$storeid:$volname";
-	    }
-
-	    if ($vollist) {
-		my $found = grep { $_ eq $info->{volid} } @$vollist;
-		next if !$found;
-	    } else {
-		next if defined ($vmid) && ($owner ne $vmid);
-	    }
+	if ($parent && $parent =~ m/^(\S+)\@__base__$/) {
+	    my ($basename) = ($1);
+	    $info->{volid} = "$storeid:$basename/$volname";
+	} else {
+	    $info->{volid} = "$storeid:$volname";
+	}
 
-	    push @$res, $info;
+	if ($vollist) {
+	    my $found = grep { $_ eq $info->{volid} } @$vollist;
+	    next if !$found;
+	} else {
+	    next if defined ($vmid) && ($owner ne $vmid);
 	}
+
+	push @$res, $info;
     }
     return $res;
 }
-- 
2.30.2






More information about the pve-devel mailing list