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(
--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(@_); });
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;
}
}
# 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) = @_;
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};