dir: allow a path as is_mountpoint value
This turns is_mountpoint more into export(5)'s `mountpoint`
property.
Given the directory storage with the properties:
path /a/b/c
is_mountpoint $value
$value = yes
Same as before, /a/b/c must be mounted.
$value = no (or not set)
Same as before, no effect.
$value = /a/b
New: /a/b must be mounted (as opposed to /a/b/c)
This commit is contained in:
committed by
Fabian Grünbichler
parent
5a2eba91dc
commit
de8eff4d31
@ -36,9 +36,10 @@ sub properties {
|
||||
},
|
||||
is_mountpoint => {
|
||||
description =>
|
||||
"Assume the directory is an externally managed mountpoint. " .
|
||||
"If nothing is mounted the storage will be considered offline.",
|
||||
type => 'boolean',
|
||||
"Assume the given path is an externally managed mountpoint " .
|
||||
"and consider the storage offline if it is not mounted. ".
|
||||
"Using a boolean (yes/no) value serves as a shortcut to using the target path in this field.",
|
||||
type => 'string',
|
||||
default => 'no',
|
||||
},
|
||||
};
|
||||
@ -73,16 +74,24 @@ sub path_is_mounted {
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub parse_is_mountpoint {
|
||||
my ($scfg) = @_;
|
||||
my $is_mp = $scfg->{is_mountpoint};
|
||||
return undef if !defined $is_mp;
|
||||
if (defined(my $bool = PVE::JSONSchema::parse_boolean($is_mp))) {
|
||||
return $bool ? $scfg->{path} : undef;
|
||||
}
|
||||
return $is_mp; # contains a path
|
||||
}
|
||||
|
||||
sub status {
|
||||
my ($class, $storeid, $scfg, $cache) = @_;
|
||||
|
||||
if ($scfg->{is_mountpoint}) {
|
||||
if (defined(my $mp = parse_is_mountpoint($scfg))) {
|
||||
$cache->{mountdata} = PVE::ProcFSTools::parse_proc_mounts()
|
||||
if !$cache->{mountdata};
|
||||
|
||||
my $path = $scfg->{path};
|
||||
|
||||
return undef if !path_is_mounted($path, $cache->{mountdata});
|
||||
return undef if !path_is_mounted($mp, $cache->{mountdata});
|
||||
}
|
||||
|
||||
return $class->SUPER::status($storeid, $scfg, $cache);
|
||||
@ -97,9 +106,10 @@ sub activate_storage {
|
||||
mkpath $path;
|
||||
}
|
||||
|
||||
if ($scfg->{is_mountpoint} && !path_is_mounted($path, $cache->{mountdata})) {
|
||||
my $mp = parse_is_mountpoint($scfg);
|
||||
if (defined($mp) && !path_is_mounted($mp, $cache->{mountdata})) {
|
||||
die "unable to activate storage '$storeid' - " .
|
||||
"directory is expected to be a mount point but is not mounted: '$path'\n";
|
||||
"directory is expected to be a mount point but is not mounted: '$mp'\n";
|
||||
}
|
||||
|
||||
$class->SUPER::activate_storage($storeid, $scfg, $cache);
|
||||
|
||||
Reference in New Issue
Block a user