]> git.proxmox.com Git - pve-storage.git/commitdiff
lvm: use add hook
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 2 Jul 2018 13:54:47 +0000 (15:54 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 3 Jul 2018 10:27:34 +0000 (12:27 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Storage/Config.pm
PVE/Storage/LVMPlugin.pm

index bb9d0a548f4c6569086b89656daa068e04ca9659..434b1f3a7e5ea30f6a5fa201fd048f1de3e5e159 100755 (executable)
@@ -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
index 94d3a33c2a1b3a6e3669eb42c59a2e8c0e9984b7..4e29617d3e4a01b23423cdb4e9e30525e0e244c8 100644 (file)
@@ -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) = @_;