[pve-devel] [PATCH storage] Do not include a volume more than once in list_volumes

Fabian Ebner f.ebner at proxmox.com
Tue Nov 19 10:13:21 CET 2019


When 'content_types' included both 'images' and 'rootdir', a single volume
could appear twice in the volume list. This also fixes the same kind of
duplication in 'pvesm list'.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/Storage/Plugin.pm | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 88da231..5ce3ef8 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -937,6 +937,7 @@ sub list_volumes {
     my ($class, $storeid, $scfg, $vmid, $content_types) = @_;
 
     my $res = [];
+    my $seen = {};
 
     foreach my $ct (@$content_types) {
 	my $data;
@@ -960,8 +961,11 @@ sub list_volumes {
 	next if !$data;
 
 	foreach my $item (@$data) {
-	    $item->{content} = $ct;
-	    push @$res, $item;
+	    if (!$seen->{$item->{volid}}) {
+		$seen->{$item->{volid}} = 1;
+		$item->{content} = $ct;
+		push @$res, $item;
+	    }
 	}
     }
 
-- 
2.20.1





More information about the pve-devel mailing list