From 2cd10f58be623764bf367d326085673f376f4948 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Tue, 1 Dec 2020 19:18:05 +0100 Subject: [PATCH] pbs: activate storage: fully validate if storage config works improves UX of on_update and on_add hooks *a lot*. This is a bit more expensive than the TCP ping, or even just an unauthenticated ping, but not as bad as a full datastore status - as this only reads the datastore config file (which is normally in page cache anyway). Signed-off-by: Thomas Lamprecht --- PVE/Storage/PBSPlugin.pm | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/PVE/Storage/PBSPlugin.pm b/PVE/Storage/PBSPlugin.pm index f04f9f7..43bd72f 100644 --- a/PVE/Storage/PBSPlugin.pm +++ b/PVE/Storage/PBSPlugin.pm @@ -666,13 +666,20 @@ sub scan_datastores { sub activate_storage { my ($class, $storeid, $scfg, $cache) = @_; - # a 'status' client command is to expensive here - # TODO: use a dummy ping API call to ensure the PBS API daemon is available for real - my $server = $scfg->{server}; - my $port = $scfg->{port} // 8007; - PVE::Network::tcp_ping($server, $port, 2); + my $password = pbs_get_password($scfg, $storeid); - return 1; + my $datastores = eval { scan_datastores($scfg, $password) }; + die "$storeid: $@" if $@; + + my $datastore = $scfg->{datastore}; + + for my $ds (@$datastores) { + if ($ds->{store} eq $datastore) { + return 1; + } + } + + die "$storeid: Cannot find datastore '$datastore', check permissions and existance!\n"; } sub deactivate_storage {