From 5dae1a319b32ea3ebbb0b48a9f0b5e3abd1833c9 Mon Sep 17 00:00:00 2001 From: Tim Marx Date: Thu, 21 Nov 2019 11:43:20 +0100 Subject: [PATCH] fix #2467: avoid duplicate volumes & tag with correct content type The bugfix for #2317 introduced a kind of odd API behavior, where each volume was returned twice from our API if a storage has both 'rootdir' & 'images' content types enabled. To give the content type of the volume an actual meaning, it is now inferred from the associated guest, if there's no guest or we don't have an owner for that volume we default to 'images'. At the volume level, there is no option to list volumes based on content types, since the volumes do not know what type they are actually used for. Signed-off-by: Tim Marx --- PVE/Storage/Plugin.pm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm index 88da231..2573cb7 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -937,7 +937,7 @@ sub list_volumes { my ($class, $storeid, $scfg, $vmid, $content_types) = @_; my $res = []; - + my $vmlist = PVE::Cluster::get_vmlist(); foreach my $ct (@$content_types) { my $data; @@ -960,7 +960,22 @@ sub list_volumes { next if !$data; foreach my $item (@$data) { - $item->{content} = $ct; + if ($ct eq 'images' || $ct eq 'rootdir') { + + my $vmtype = $vmlist->{ids}->{$item->{vmid}}->{type}; + if (defined($vmtype) && $vmtype eq 'lxc') { + $item->{content} = 'rootdir'; + } else { + $item->{content} = 'images'; + } + if (!($ct eq $item->{content})) { + next; + } + + } else { + $item->{content} = $ct; + } + push @$res, $item; } }