[pve-devel] [PATCH storage 4/5] lvm: use add hook
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Jul 2 15:54:47 CEST 2018
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
PVE/API2/Storage/Config.pm | 19 -------------------
PVE/Storage/LVMPlugin.pm | 22 ++++++++++++++++++++++
2 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/PVE/API2/Storage/Config.pm b/PVE/API2/Storage/Config.pm
index bb9d0a5..434b1f3 100755
--- a/PVE/API2/Storage/Config.pm
+++ b/PVE/API2/Storage/Config.pm
@@ -165,25 +165,6 @@ __PACKAGE__->register_method ({
my $cred_file = undef;
- if ($type eq 'lvm' && $opts->{base}) {
-
- my ($baseid, $volname) = PVE::Storage::parse_volume_id($opts->{base});
-
- my $basecfg = PVE::Storage::storage_config ($cfg, $baseid, 1);
- die "base storage ID '$baseid' does not exist\n" if !$basecfg;
-
- # we only support iscsi for now
- if (!($basecfg->{type} eq 'iscsi')) {
- die "unsupported base type '$basecfg->{type}'";
- }
-
- my $path = PVE::Storage::path($cfg, $opts->{base});
-
- PVE::Storage::activate_storage($cfg, $baseid);
-
- PVE::Storage::LVMPlugin::lvm_create_volume_group($path, $opts->{vgname}, $opts->{shared});
- }
-
eval {
# try to activate if enabled on local node,
# we only do this to detect errors/problems sooner
diff --git a/PVE/Storage/LVMPlugin.pm b/PVE/Storage/LVMPlugin.pm
index 94d3a33..4e29617 100644
--- a/PVE/Storage/LVMPlugin.pm
+++ b/PVE/Storage/LVMPlugin.pm
@@ -208,6 +208,28 @@ sub options {
# Storage implementation
+sub on_add_hook {
+ my ($class, $storeid, $scfg, %param) = @_;
+
+ if (my $base = $scfg->{base}) {
+ my ($baseid, $volname) = PVE::Storage::parse_volume_id($base);
+
+ my $cfg = PVE::Storage::config();
+ my $basecfg = PVE::Storage::storage_config ($cfg, $baseid, 1);
+ die "base storage ID '$baseid' does not exist\n" if !$basecfg;
+
+ # we only support iscsi for now
+ die "unsupported base type '$basecfg->{type}'"
+ if $basecfg->{type} ne 'iscsi';
+
+ my $path = PVE::Storage::path($cfg, $base);
+
+ PVE::Storage::activate_storage($cfg, $baseid);
+
+ lvm_create_volume_group($path, $scfg->{vgname}, $scfg->{shared});
+ }
+}
+
sub parse_volname {
my ($class, $volname) = @_;
--
2.17.1
More information about the pve-devel
mailing list