public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Max Carrara <m.carrara@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v1 pve-storage 5/8] pluginbase: document hooks
Date: Wed, 26 Mar 2025 15:20:56 +0100	[thread overview]
Message-ID: <20250326142059.261938-6-m.carrara@proxmox.com> (raw)
In-Reply-To: <20250326142059.261938-1-m.carrara@proxmox.com>

Add docstrings for the following methods:
- on_add_hook
- on_update_hook
- on_delete_hook

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
---
 src/PVE/Storage/PluginBase.pm | 85 ++++++++++++++++++++++++++++++-----
 1 file changed, 74 insertions(+), 11 deletions(-)

diff --git a/src/PVE/Storage/PluginBase.pm b/src/PVE/Storage/PluginBase.pm
index 8a61dc3..b3ce684 100644
--- a/src/PVE/Storage/PluginBase.pm
+++ b/src/PVE/Storage/PluginBase.pm
@@ -626,29 +626,92 @@ sub find_free_diskname {
 
 =head2 HOOKS
 
+The following methods are called whenever a storage associated with the given
+plugin is added, updated, or deleted. These methods are useful for:
+
+=over
+
+=item * Setting up certain prerequisites when adding the storage (and then
+tearing them down again when the storage is deleted)
+
+=item * Handling sensitive parameters that shouldn't be written directly
+to C</etc/pve/storage.cfg> and ought to be stored elsewhere
+
+=item * Ensuring that certain conditions in the configuration are being upheld
+that cannot be done via the remaining API otherwise
+
+=back
+
+and more.
+
+=cut
+
+=head3 $plugin->on_add_hook($storeid, \%scfg, %param)
+
+=head3 $plugin->on_add_hook(...)
+
+B<OPTIONAL:> May be implemented in a storage plugin.
+
+Called during the addition of a storage, before the new storage configuration
+gets written.
+
+C<%param> contains additional key-value arguments, usually sensitive keys that
+have been extracted from C<\%scfg> in order not to write them to the storage
+configuration.
+
+C<die>s in order to abort the addition if there are (grave) problems.
+
+C</etc/pve/storage.cfg> is B<locked> when this method is called.
+
 =cut
 
-# called during addition of storage (before the new storage config got written)
-# die to abort addition if there are (grave) problems
-# NOTE: runs in a storage config *locked* context
 sub on_add_hook {
     my ($class, $storeid, $scfg, %param) = @_;
     return undef;
 }
 
-# called during storage configuration update (before the updated storage config got written)
-# die to abort the update if there are (grave) problems
-# NOTE: runs in a storage config *locked* context
+=head3 $plugin->on_update_hook($storeid, \%scfg, %param)
+
+=head3 $plugin->on_update_hook(...)
+
+B<OPTIONAL:> May be implemented in a storage plugin.
+
+Called during the update of a storage configuration, before the new
+configuration gets written.
+
+C<%param> contains additional key-value arguments, usually sensitive keys that
+have been extracted from C<\%scfg> in order not to write them to the storage
+configuration.
+
+C<die>s in order to abort the config update if there are (grave) problems.
+
+C</etc/pve/storage.cfg> is B<locked> when this method is called.
+
+=cut
+
 sub on_update_hook {
     my ($class, $storeid, $scfg, %param) = @_;
     return undef;
 }
 
-# called during deletion of storage (before the new storage config got written)
-# and if the activate check on addition fails, to cleanup all storage traces
-# which on_add_hook may have created.
-# die to abort deletion if there are (very grave) problems
-# NOTE: runs in a storage config *locked* context
+=head3 $plugin->on_delete_hook($storeid, \%scfg)
+
+=head3 $plugin->on_delete_hook(...)
+
+B<OPTIONAL:> May be implemented in a storage plugin.
+
+Called during the deletion of a storage, before the new storage configuration
+gets written. Also gets called if the activation check during storage
+addition fails in order to clean up all traces which
+C<L<< on_add_hook()|/"$plugin->on_add_hook($storeid, \%scfg, %param)" >>>
+may have created.
+
+C<die>s in order to abort the deletion of there are (very grave) problems.
+
+C</etc/pve/storage.cfg> is B<locked> when this method is called.
+
+=cut
+
 sub on_delete_hook {
     my ($class, $storeid, $scfg) = @_;
     return undef;
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-03-26 14:21 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-26 14:20 [pve-devel] [PATCH v1 pve-storage 0/8] Base Module + Documentation for PVE::Storage::Plugin API Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 1/8] pluginbase: introduce PVE::Storage::PluginBase with doc scaffold Max Carrara
2025-03-31 15:13   ` Fabian Grünbichler
2025-04-02 16:31     ` Max Carrara
2025-04-03  7:12       ` Fabian Grünbichler
2025-04-03 14:05         ` Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 2/8] pluginbase: add high-level plugin API description Max Carrara
2025-03-31 15:13   ` Fabian Grünbichler
2025-04-02 16:31     ` Max Carrara
2025-04-03  7:12       ` Fabian Grünbichler
2025-04-03 14:05         ` Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 3/8] pluginbase: document SectionConfig methods Max Carrara
2025-03-31 15:13   ` Fabian Grünbichler
2025-04-02 16:31     ` Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 4/8] pluginbase: document general plugin methods Max Carrara
2025-03-28 12:50   ` Maximiliano Sandoval
2025-03-31 15:12   ` Fabian Grünbichler
2025-04-02 16:31     ` Max Carrara
2025-03-26 14:20 ` Max Carrara [this message]
2025-03-28 13:07   ` [pve-devel] [PATCH v1 pve-storage 5/8] pluginbase: document hooks Maximiliano Sandoval
2025-03-31 15:12   ` Fabian Grünbichler
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 6/8] pluginbase: document image operation methods Max Carrara
2025-03-31 15:12   ` Fabian Grünbichler
2025-04-02 16:32     ` Max Carrara
2025-04-03  7:23       ` Fabian Grünbichler
2025-04-03 14:05         ` Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 7/8] pluginbase: document volume operations Max Carrara
2025-03-31 15:12   ` Fabian Grünbichler
2025-04-02 16:32     ` Max Carrara
2025-03-26 14:20 ` [pve-devel] [PATCH v1 pve-storage 8/8] pluginbase: document import and export methods Max Carrara
2025-04-01  8:40   ` Fabian Grünbichler
2025-04-01  9:40     ` Fiona Ebner
2025-04-02 16:32     ` Max Carrara

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=20250326142059.261938-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal