From: Max Carrara <m.carrara@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC v1 pve-storage 5/6] introduce check for `type` method and duplicate types
Date: Thu, 30 Jan 2025 15:51:23 +0100 [thread overview]
Message-ID: <20250130145124.317745-6-m.carrara@proxmox.com> (raw)
In-Reply-To: <20250130145124.317745-1-m.carrara@proxmox.com>
Check whether a plugin defines a `type` method (as required by
PVE::SectionConfig). Throw and exception if it doesn't.
Also check for the same type being declared more than once.
All this is added to make implementing a plugin a little more
developer-friendly through more expressive error messages. Both cases
are otherwise also handled by the `register` method of
PVE::SectionConfig.
Signed-off-by: Max Carrara <m.carrara@proxmox.com>
---
src/PVE/Storage.pm | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index a9568b1..4cf591f 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -312,6 +312,7 @@ my sub do_pre_register_check_plugin : prototype(%) {
my (%params) = @_;
my $plugin_name = $params{name};
+ my $plugin_types = $params{plugin_types};
my $plugin_index = $plugin_register_state->{index};
@@ -345,6 +346,26 @@ my sub do_pre_register_check_plugin : prototype(%) {
if $version < $min_version;
};
+ my $check_plugin_type = sub {
+ # so that we may call methods on $plugin_name
+ no strict 'refs'; ## no critic
+
+ # Method is inherited, no need to check for its existence.
+ # However, if not overridden, it will `die`
+ my $type = eval {
+ $plugin_name->type()
+ };
+
+ die "plugin does not override \"type()\" method\n"
+ if $@;
+
+ my $source_plugin = $plugin_types->{$type};
+ die "plugin with type \"$type\" already exists: $source_plugin\n"
+ if defined($source_plugin);
+
+ $plugin_types->{$type} = $plugin_name;
+ };
+
my $check_symbols = sub {
my $prohibited_symbols = PVE::Storage::Plugin::get_prohibited_symbols();
@@ -364,6 +385,7 @@ my sub do_pre_register_check_plugin : prototype(%) {
eval {
$check_derives_base->();
$check_plugin_api->() if $is_custom;
+ $check_plugin_type->();
$check_symbols->();
};
@@ -389,10 +411,13 @@ C<L<< do_pre_register_check_plugin()|/"do_pre_register_check_plugin(%params)" >>
my sub pre_register_check_plugins : prototype() {
my @errs = ();
+ # { type() => plugin_name }
+ my $plugin_types = {};
+
my @standard_plugins = get_indexed_plugins(is_custom => 0);
for my $plugin (@standard_plugins) {
eval {
- do_pre_register_check_plugin(name => $plugin);
+ do_pre_register_check_plugin(name => $plugin, plugin_types => $plugin_types);
};
push(@errs, $@) if $@;
@@ -408,7 +433,7 @@ 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);
+ do_pre_register_check_plugin(name => $plugin, plugin_types => $plugin_types);
};
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:51 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 ` Max Carrara [this message]
2025-01-30 14:51 ` [pve-devel] [RFC v1 pve-storage 6/6] introduce check for duplicate plugin properties Max Carrara
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-6-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