]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/DirPlugin.pm
1 package PVE
::Storage
::DirPlugin
;
7 use PVE
::Storage
::Plugin
;
8 use PVE
::JSONSchema
qw(get_standard_option);
10 use base
qw(PVE::Storage::Plugin);
20 content
=> [ { images
=> 1, rootdir
=> 1, vztmpl
=> 1, iso
=> 1, backup
=> 1, none
=> 1 },
21 { images
=> 1, rootdir
=> 1 }],
22 format
=> [ { raw
=> 1, qcow2
=> 1, vmdk
=> 1, subvol
=> 1 } , 'raw' ],
29 description
=> "File system path.",
30 type
=> 'string', format
=> 'pve-storage-path',
33 description
=> "Create the directory if it doesn't exist.",
39 "Assume the given path is an externally managed mountpoint " .
40 "and consider the storage offline if it is not mounted. ".
41 "Using a boolean (yes/no) value serves as a shortcut to using the target path in this field.",
50 path
=> { fixed
=> 1 },
51 nodes
=> { optional
=> 1 },
52 shared
=> { optional
=> 1 },
53 disable
=> { optional
=> 1 },
54 maxfiles
=> { optional
=> 1 },
55 content
=> { optional
=> 1 },
56 format
=> { optional
=> 1 },
57 mkdir => { optional
=> 1 },
58 is_mountpoint
=> { optional
=> 1 },
62 # Storage implementation
65 # NOTE: should ProcFSTools::is_mounted accept an optional cache like this?
67 my ($mountpoint, $mountdata) = @_;
69 $mountpoint = Cwd
::realpath
($mountpoint); # symlinks
70 return 0 if !defined($mountpoint); # path does not exist
72 $mountdata = PVE
::ProcFSTools
::parse_proc_mounts
() if !$mountdata;
73 return 1 if grep { $_->[1] eq $mountpoint } @$mountdata;
77 sub parse_is_mountpoint
{
79 my $is_mp = $scfg->{is_mountpoint
};
80 return undef if !defined $is_mp;
81 if (defined(my $bool = PVE
::JSONSchema
::parse_boolean
($is_mp))) {
82 return $bool ?
$scfg->{path
} : undef;
84 return $is_mp; # contains a path
88 my ($class, $storeid, $scfg, $cache) = @_;
90 if (defined(my $mp = parse_is_mountpoint
($scfg))) {
91 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
92 if !$cache->{mountdata
};
94 return undef if !path_is_mounted
($mp, $cache->{mountdata
});
97 return $class->SUPER::status
($storeid, $scfg, $cache);
101 sub activate_storage
{
102 my ($class, $storeid, $scfg, $cache) = @_;
104 my $path = $scfg->{path
};
105 if (!defined($scfg->{mkdir}) || $scfg->{mkdir}) {
109 my $mp = parse_is_mountpoint
($scfg);
110 if (defined($mp) && !path_is_mounted
($mp, $cache->{mountdata
})) {
111 die "unable to activate storage '$storeid' - " .
112 "directory is expected to be a mount point but is not mounted: '$mp'\n";
115 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
119 my ($self, $sectionId, $config, $create, $skipSchemaCheck) = @_;
120 my $opts = PVE
::SectionConfig
::check_config
($self, $sectionId, $config, $create, $skipSchemaCheck);
121 return $opts if !$create;
122 if ($opts->{path
} !~ m
@^/[-/a-zA-Z0-9_
.]+$@) {
123 die "illegal path for directory storage: $opts->{path}\n";