From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 76226822B for ; Mon, 21 Aug 2023 15:45:25 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4A46D1712 for ; Mon, 21 Aug 2023 15:44:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 21 Aug 2023 15:44:54 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 802CD42DBE for ; Mon, 21 Aug 2023 15:44:54 +0200 (CEST) From: Lukas Wagner To: pve-devel@lists.proxmox.com Date: Mon, 21 Aug 2023 15:44:44 +0200 Message-Id: <20230821134444.620021-8-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230821134444.620021-1-l.wagner@proxmox.com> References: <20230821134444.620021-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.088 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [RFC pve-storage 7/7] stats: api: cache storage plugin status X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Aug 2023 13:45:25 -0000 Cache storage plugin status so that pvestatd and API calls can use the cached results, without having to query all storage plugins again. Signed-off-by: Lukas Wagner --- src/PVE/API2/Storage/Config.pm | 10 +++++++++ src/PVE/Storage.pm | 40 ++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/PVE/API2/Storage/Config.pm b/src/PVE/API2/Storage/Config.pm index e04b6ab..8c3df99 100755 --- a/src/PVE/API2/Storage/Config.pm +++ b/src/PVE/API2/Storage/Config.pm @@ -16,6 +16,7 @@ use PVE::JSONSchema qw(get_standard_option); use PVE::RPCEnvironment; use PVE::RESTHandler; +use PVE::RS::Cache; use base qw(PVE::RESTHandler); @@ -274,6 +275,9 @@ __PACKAGE__->register_method ({ die $err; } + # Remove cached plugin status on configuration changes. + PVE::RS::Cache->pvestatd_cache()->delete("storage_plugin_status"); + PVE::Storage::write_config($cfg); }, "create storage failed"); @@ -373,6 +377,9 @@ __PACKAGE__->register_method ({ ." in Proxmox VE 9. Use 'create-base-path' or 'create-subdirs' instead.\n" } + # Remove cached plugin status on configuration changes. + PVE::RS::Cache->pvestatd_cache()->delete("storage_plugin_status"); + PVE::Storage::write_config($cfg); }, "update storage failed"); @@ -422,6 +429,9 @@ __PACKAGE__->register_method ({ delete $cfg->{ids}->{$storeid}; + # Remove cached plugin status on configuration changes. + PVE::RS::Cache->pvestatd_cache()->delete("storage_plugin_status"); + PVE::Storage::write_config($cfg); }, "delete storage failed"); diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm index a4d85e1..7aa3b2e 100755 --- a/src/PVE/Storage.pm +++ b/src/PVE/Storage.pm @@ -23,6 +23,7 @@ use PVE::INotify; use PVE::RPCEnvironment; use PVE::SSHInfo; use PVE::RESTEnvironment qw(log_warn); +use PVE::RS::Cache; use PVE::Storage::Plugin; use PVE::Storage::DirPlugin; @@ -1276,6 +1277,10 @@ sub storage_info { my $cache = {}; + my $status_cache = PVE::RS::Cache->pvestatd_cache(); + my $cached_status = $status_cache->get("storage_plugin_status"); + my $refresh_status = !$cached_status; + foreach my $storeid (keys %$ids) { my $scfg = $ids->{$storeid}; @@ -1291,21 +1296,34 @@ sub storage_info { if $pd->{select_existing}; } - eval { activate_storage($cfg, $storeid, $cache); }; - if (my $err = $@) { - warn $err; - next; + if ($refresh_status) { + eval { activate_storage($cfg, $storeid, $cache); }; + if (my $err = $@) { + warn $err; + next; + } + $cached_status->{$storeid} = eval { $plugin->status($storeid, $scfg, $cache); }; + + my ($total, $avail, $used, $active) = eval { $plugin->status($storeid, $scfg, $cache); }; + warn $@ if $@; + $cached_status->{$storeid} = {}; + + $cached_status->{$storeid}->{total} = int($total); + $cached_status->{$storeid}->{avail} = int($avail); + $cached_status->{$storeid}->{used} = int($used); + $cached_status->{$storeid}->{active} = $active; + next if !$active; } - my ($total, $avail, $used, $active) = eval { $plugin->status($storeid, $scfg, $cache); }; - warn $@ if $@; - next if !$active; - $info->{$storeid}->{total} = int($total); - $info->{$storeid}->{avail} = int($avail); - $info->{$storeid}->{used} = int($used); - $info->{$storeid}->{active} = $active; + $info->{$storeid}->{total} = $cached_status->{$storeid}->{total}; + $info->{$storeid}->{avail} = $cached_status->{$storeid}->{avail}; + $info->{$storeid}->{used} = $cached_status->{$storeid}->{used}; + $info->{$storeid}->{active} = $cached_status->{$storeid}->{active}; } + # TODO: How long should status results be valid? + $status_cache->set('storage_plugin_status', $cached_status, 30) if $refresh_status; + return $info; } -- 2.39.2