]> git.proxmox.com Git - pve-storage.git/commitdiff
rbd: list images: early return to avoid indentation
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 9 Apr 2021 11:51:15 +0000 (13:51 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 9 Apr 2021 11:51:15 +0000 (13:51 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/Storage/RBDPlugin.pm

index 8c4ce4527bea9af505ced6adfe2bcc0fa9a68c29..5c9c073dac3d2c92834fdb015e8f891fd6231e1c 100644 (file)
@@ -539,39 +539,36 @@ sub list_images {
     my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
 
     $cache->{rbd} = rbd_ls($scfg, $storeid) if !$cache->{rbd};
+
     my $pool =  $scfg->{pool} ? $scfg->{pool} : 'rbd';
     $pool .= "/$scfg->{namespace}" if defined($scfg->{namespace});
 
-    my $res = [];
-
-    if (my $dat = $cache->{rbd}->{$pool}) {
-       for my $image (sort keys %$dat) {
-
-           my $info = $dat->{$image};
+    my $dat = $cache->{rbd}->{$pool};
+    return [] if !$dat; # nothing found
 
-           my $volname = $info->{name};
-           my $parent = $info->{parent};
-           my $owner = $info->{vmid};
-
-           if ($parent && $parent =~ m/^(base-\d+-\S+)\@__base__$/) {
-               $info->{volid} = "$storeid:$1/$volname";
-           } else {
-               $info->{volid} = "$storeid:$volname";
-           }
+    my $res = [];
+    for my $image (sort keys %$dat) {
+       my $info = $dat->{$image};
+       my ($volname, $parent, $owner) = $info->@{'name', 'parent', 'vmid'};
+
+       if ($parent && $parent =~ m/^(base-\d+-\S+)\@__base__$/) {
+           $info->{volid} = "$storeid:$1/$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 ($vollist) {
+           my $found = grep { $_ eq $info->{volid} } @$vollist;
+           next if !$found;
+       } else {
+           next if defined ($vmid) && ($owner ne $vmid);
+       }
 
-           $info->{format} = 'raw';
+       $info->{format} = 'raw';
 
-           push @$res, $info;
-       }
+       push @$res, $info;
     }
-    
+
     return $res;
 }