From 32075a2cb828ef3d728875f65a061687e013e213 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 28 Jun 2019 17:23:44 +0200 Subject: [PATCH] check_local_storage_availability: only count each unavailable storage once and some general cleanup Signed-off-by: Thomas Lamprecht --- PVE/API2/Qemu.pm | 5 ++--- PVE/QemuServer.pm | 10 ++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 1c4e07ba..e2a63be1 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -3211,12 +3211,11 @@ __PACKAGE__->register_method({ if (!$res->{running}) { $res->{allowed_nodes} = []; my $checked_nodes = PVE::QemuServer::check_local_storage_availability($vmconf, $storecfg); + delete $checked_nodes->{$localnode}; - delete $checked_nodes->{$localnode} if $checked_nodes->{$localnode}; foreach my $node (keys %$checked_nodes) { - if (!defined $checked_nodes->{$node}->{not_available_storages}){ + if (!defined $checked_nodes->{$node}->{unavailable_storages}) { push @{$res->{allowed_nodes}}, $node; - delete $checked_nodes->{$node}; } } diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 35e26331..b4b15801 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -2942,18 +2942,24 @@ sub check_local_storage_availability { if ($scfg->{disable}) { foreach my $node (keys %$nodehash) { - push @{$nodehash->{$node}->{not_available_storages}}, $storeid; + $nodehash->{$node}->{unavailable_storages}->{$storeid} = 1; } } elsif (my $avail = $scfg->{nodes}) { foreach my $node (keys %$nodehash) { if (!$avail->{$node}) { - push @{$nodehash->{$node}->{not_available_storages}}, $storeid; + $nodehash->{$node}->{unavailable_storages}->{$storeid} = 1; } } } } }); + foreach my $node (values %$nodehash) { + if (my $unavail = $node->{unavailable_storages}) { + $node->{unavailable_storages} = [ sort keys %$unavail ]; + } + } + return $nodehash }