From f9602323c6665677f14a82ecb942fb2da3b2b35a Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 2 Jul 2018 15:54:47 +0200 Subject: [PATCH] lvm: use add hook Signed-off-by: Thomas Lamprecht --- 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.39.2