]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/RBDPlugin.pm
btrfs: add 'btrfs' import/export format
[pve-storage.git] / PVE / Storage / RBDPlugin.pm
index 8c4ce4527bea9af505ced6adfe2bcc0fa9a68c29..a8d1243c50e1a950fbbe6aa88ac4953d6005b34e 100644 (file)
@@ -24,11 +24,10 @@ my $get_parent_image_name = sub {
 
 my sub get_rbd_path {
     my ($scfg, $volume) = @_;
-    my $pool =  $scfg->{pool} ? $scfg->{pool} : 'rbd';
-    my $namespace = $scfg->{namespace};
-
-    return "${pool}/${namespace}/${volume}" if defined($namespace);
-    return "${pool}/${volume}";
+    my $path = $scfg->{pool} ? $scfg->{pool} : 'rbd';
+    $path .= "/$scfg->{namespace}" if defined($scfg->{namespace});
+    $path .= "/$volume" if defined($volume);
+    return $path;
 };
 
 my $build_cmd = sub {
@@ -504,7 +503,7 @@ sub alloc_image {
     $name = $class->find_free_diskname($storeid, $scfg, $vmid) if !$name;
 
     my $cmd = $rbd_cmd->($scfg, $storeid, 'create', '--image-format' , 2, '--size', int(($size+1023)/1024), $name);
-    run_rbd_command($cmd, errmsg => "rbd create $name' error");
+    run_rbd_command($cmd, errmsg => "rbd create '$name' error");
 
     return $name;
 }
@@ -539,39 +538,33 @@ 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 = [];
+    my $dat = $cache->{rbd}->{get_rbd_path($scfg)};
+    return [] if !$dat; # nothing found
 
-    if (my $dat = $cache->{rbd}->{$pool}) {
-       for my $image (sort keys %$dat) {
-
-           my $info = $dat->{$image};
-
-           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;
 }