From: Max Carrara <m.carrara@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC v1 pve-storage 6/6] introduce check for duplicate plugin properties
Date: Thu, 30 Jan 2025 15:51:24 +0100 [thread overview]
Message-ID: <20250130145124.317745-7-m.carrara@proxmox.com> (raw)
In-Reply-To: <20250130145124.317745-1-m.carrara@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
next prev parent reply other threads:[~2025-01-30 14:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 14:51 [pve-devel] [RFC v1 pve-storage 0/6] RFC: Tighter API Control for Storage Plugins Max Carrara
2025-01-30 14:51 ` [pve-devel] [RFC v1 pve-storage 1/6] version: introduce PVE::Storage::Version Max Carrara
2025-02-05 11:20 ` Wolfgang Bumiller
2025-01-30 14:51 ` [pve-devel] [RFC v1 pve-storage 2/6] rework plugin loading and registration mechanism Max Carrara
2025-02-05 11:33 ` Wolfgang Bumiller
2025-01-30 14:51 ` [pve-devel] [RFC v1 pve-storage 3/6] introduce compile-time checks for prohibited sub overrides Max Carrara
2025-02-05 11:41 ` Wolfgang Bumiller
2025-02-05 11:55 ` Wolfgang Bumiller
2025-01-30 14:51 ` [pve-devel] [RFC v1 pve-storage 4/6] plugin: replace fixme comments for deprecated methods with attribute Max Carrara
2025-01-30 14:51 ` [pve-devel] [RFC v1 pve-storage 5/6] introduce check for `type` method and duplicate types Max Carrara
2025-01-30 14:51 ` Max Carrara [this message]
2025-02-05 11:17 ` [pve-devel] [RFC v1 pve-storage 0/6] RFC: Tighter API Control for Storage Plugins Wolfgang Bumiller
2025-02-05 15:20 ` Max Carrara
2025-02-06 14:05 ` Fiona Ebner
2025-02-06 14:39 ` Thomas Lamprecht
2025-02-06 14:56 ` Fiona Ebner
2025-02-07 7:17 ` Thomas Lamprecht
2025-02-07 9:59 ` Fiona Ebner
2025-02-07 11:57 ` Thomas Lamprecht
2025-02-07 15:25 ` Fiona Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250130145124.317745-7-m.carrara@proxmox.com \
--to=m.carrara@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox