]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/Plugin.pm
remove unused Data::Dumper usages
[pve-storage.git] / PVE / Storage / Plugin.pm
index b640712a8eaad6dd29288995d1fa77487af66d4f..7db3a95c02ddf45ee0a5bd79be637e74965dba79 100644 (file)
@@ -2,14 +2,14 @@ package PVE::Storage::Plugin;
 
 use strict;
 use warnings;
+
 use File::chdir;
 use File::Path;
+
 use PVE::Tools qw(run_command);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::Cluster qw(cfs_register_file);
 
-use Data::Dumper;
-
 use base qw(PVE::SectionConfig);
 
 our @COMMON_TAR_FLAGS = qw(
@@ -19,6 +19,18 @@ our @COMMON_TAR_FLAGS = qw(
     --warning=no-file-ignored --warning=no-xattr-write
 );
 
+our @SHARED_STORAGE = (
+    'iscsi',
+    'nfs',
+    'cifs',
+    'rbd',
+    'cephfs',
+    'sheepdog',
+    'iscsidirect',
+    'glusterfs',
+    'zfs',
+    'drbd');
+
 cfs_register_file ('storage.cfg',
                   sub { __PACKAGE__->parse_config(@_); },
                   sub { __PACKAGE__->write_config(@_); });
@@ -331,8 +343,7 @@ sub parse_config {
        if ($def->{content}) {
            $d->{content} = $def->{content}->[1] if !$d->{content};
        }
-
-       if ($type eq 'iscsi' || $type eq 'nfs' || $type eq 'rbd' || $type eq 'sheepdog' || $type eq 'iscsidirect' || $type eq 'glusterfs' || $type eq 'zfs' || $type eq 'drbd') {
+       if (grep { $_ eq $type }  @SHARED_STORAGE) {
            $d->{shared} = 1;
        }
     }
@@ -342,6 +353,26 @@ sub parse_config {
 
 # Storage implementation
 
+# called during addition of storage (before the new storage config got written)
+# die to abort additon if there are (grave) problems
+# NOTE: runs in a storage config *locked* context
+sub on_add_hook {
+    my ($class, $storeid, $scfg, %param) = @_;
+
+    # do nothing by default
+}
+
+# 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
+sub on_delete_hook {
+    my ($class, $storeid, $scfg) = @_;
+
+    # do nothing by default
+}
+
 sub cluster_lock_storage {
     my ($class, $storeid, $shared, $timeout, $func, @param) = @_;
 
@@ -853,8 +884,13 @@ sub activate_storage {
 
     die "storage definintion has no path\n" if !$path;
 
-    die "unable to activate storage '$storeid' - " .
-       "directory '$path' does not exist\n" if ! -d $path;
+    # this path test may hang indefinitely on unresponsive mounts
+    my $timeout = 2;
+    if (! PVE::Tools::run_fork_with_timeout($timeout, sub {-d $path})) {
+       die "unable to activate storage '$storeid' - " .
+       "directory '$path' does not exist or is unreachable\n";
+    }
+
 
     return if defined($scfg->{mkdir}) && !$scfg->{mkdir};