[pve-devel] [PATCH] Add support for custom storage plugins

Dmitry Petuhov mityapetuhov at gmail.com
Wed Aug 10 13:48:56 CEST 2016


PVE team cannot support specialized vendor-specific storage
plugins because of lack of hardware. But we can allow users to
add own plugins for their storages without need to rewrite any
PVE code and thus ease PVE updates to them.

Idea of this patch is to add folder /usr/share/perl5/PVE/Storage/Custom
where user can place his plugins and PVE will automatically load
them on start or warn if it could not and continue. Maybe we could
even load all plugins (except PVE::Storage::Plugin itself) this way,
because current storage plugins are not really plugins, if they
need to be explicitly loaded in PVE code :-).

This approach works (with some limitations) if plugin supports
generic PVE way: full control of volumes lifecycle. And will not
currently work for custom plugins like iSCSI, which needs to select
pre-existing volumes. Maybe someone will add more flexible way to
pve-manager to select input elements for storage plugins to target
this.

Currently tested with my NetApp plugin.

Signed-off-by: Dmitry Petuhov <mityapetuhov at gmail.com>
---
 PVE/Storage.pm | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
 mode change 100755 => 100644 PVE/Storage.pm

diff --git a/PVE/Storage.pm b/PVE/Storage.pm
old mode 100755
new mode 100644
index 25ff545..315cf65
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -12,7 +12,7 @@ use File::Path;
 use Cwd 'abs_path';
 use Socket;
 
-use PVE::Tools qw(run_command file_read_firstline $IPV6RE);
+use PVE::Tools qw(run_command file_read_firstline dir_glob_foreach $IPV6RE);
 use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
 use PVE::Exception qw(raise_param_exc);
 use PVE::JSONSchema;
@@ -33,6 +33,26 @@ use PVE::Storage::ZFSPoolPlugin;
 use PVE::Storage::ZFSPlugin;
 use PVE::Storage::DRBDPlugin;
 
+if ( -d '/usr/share/perl5/PVE/Storage/Custom' ) {
+    dir_glob_foreach('/usr/share/perl5/PVE/Storage/Custom', '.*Plugin\.pm', sub {
+	my ($file) = @_;
+	$file = 'PVE/Storage/Custom/' . $file;
+	my $modname = $file;
+	$modname =~ s!/!::!g;
+	$modname =~ s!.pm$!!;
+
+	eval {
+	    require $file;
+	};
+	if ($@) {
+	    warn $@
+	} else {
+	    import $file;
+	    $modname->register();
+	}
+    });
+}
+
 # load and initialize all plugins
 PVE::Storage::DirPlugin->register();
 PVE::Storage::LVMPlugin->register();
-- 
2.1.4




More information about the pve-devel mailing list