From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 286D21FF16F for <inbox@lore.proxmox.com>; Thu, 30 Jan 2025 15:52:13 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AE7EF153AE; Thu, 30 Jan 2025 15:52:10 +0100 (CET) From: Max Carrara <m.carrara@proxmox.com> To: pve-devel@lists.proxmox.com Date: Thu, 30 Jan 2025 15:51:24 +0100 Message-Id: <20250130145124.317745-7-m.carrara@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250130145124.317745-1-m.carrara@proxmox.com> References: <20250130145124.317745-1-m.carrara@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.064 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 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 v1 pve-storage 6/6] introduce check for duplicate plugin properties X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> For each property that a plugin defines, check if the property is already defined by another plugin before registering plugins. This is mostly done for the sake of developer-friendliness. The same check is made in `PVE::SectionConfig::init()` -- the difference here is that the plugin which defined the property is preserved in the error message. Signed-off-by: Max Carrara <m.carrara@proxmox.com> --- src/PVE/Storage.pm | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm index 4cf591f..55a8668 100755 --- a/src/PVE/Storage.pm +++ b/src/PVE/Storage.pm @@ -313,6 +313,7 @@ my sub do_pre_register_check_plugin : prototype(%) { my $plugin_name = $params{name}; my $plugin_types = $params{plugin_types}; + my $plugin_properties = $params{plugin_properties}; my $plugin_index = $plugin_register_state->{index}; @@ -366,6 +367,25 @@ my sub do_pre_register_check_plugin : prototype(%) { $plugin_types->{$type} = $plugin_name; }; + my $check_plugin_properties = sub { + # so that we may call methods on $plugin_name + no strict 'refs'; ## no critic + + # method is inherited and doesn't throw + my $properties = $plugin_name->properties(); + + my @errs = (); + for my $property (keys $properties->%*) { + my $source_plugin = $plugin_properties->{$property}; + push(@errs, "property \"$property\" already exists - defined by $source_plugin") + if defined($source_plugin); + + $plugin_properties->{$property} = $plugin_name; + } + + die(join("\n", @errs), "\n") if scalar(@errs); + }; + my $check_symbols = sub { my $prohibited_symbols = PVE::Storage::Plugin::get_prohibited_symbols(); @@ -386,6 +406,7 @@ my sub do_pre_register_check_plugin : prototype(%) { $check_derives_base->(); $check_plugin_api->() if $is_custom; $check_plugin_type->(); + $check_plugin_properties->(); $check_symbols->(); }; @@ -414,10 +435,17 @@ my sub pre_register_check_plugins : prototype() { # { type() => plugin_name } my $plugin_types = {}; + # { property_name => plugin_name } + my $plugin_properties = {}; + my @standard_plugins = get_indexed_plugins(is_custom => 0); for my $plugin (@standard_plugins) { eval { - do_pre_register_check_plugin(name => $plugin, plugin_types => $plugin_types); + do_pre_register_check_plugin( + name => $plugin, + plugin_types => $plugin_types, + plugin_properties => $plugin_properties, + ); }; push(@errs, $@) if $@; @@ -433,7 +461,11 @@ my sub pre_register_check_plugins : prototype() { my @custom_plugins = get_indexed_plugins(is_custom => 1); for my $plugin (@custom_plugins) { eval { - do_pre_register_check_plugin(name => $plugin, plugin_types => $plugin_types); + do_pre_register_check_plugin( + name => $plugin, + plugin_types => $plugin_types, + plugin_properties => $plugin_properties, + ); }; if ($@) { -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel