]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/DirPlugin.pm
1 package PVE
::Storage
::DirPlugin
;
11 use PVE
::Storage
::Plugin
;
12 use PVE
::JSONSchema
qw(get_standard_option);
14 use base
qw(PVE::Storage::Plugin);
24 content
=> [ { images
=> 1, rootdir
=> 1, vztmpl
=> 1, iso
=> 1, backup
=> 1, snippets
=> 1, none
=> 1 },
25 { images
=> 1, rootdir
=> 1 }],
26 format
=> [ { raw
=> 1, qcow2
=> 1, vmdk
=> 1, subvol
=> 1 } , 'raw' ],
33 description
=> "File system path.",
34 type
=> 'string', format
=> 'pve-storage-path',
37 description
=> "Create the directory if it doesn't exist.",
43 "Assume the given path is an externally managed mountpoint " .
44 "and consider the storage offline if it is not mounted. ".
45 "Using a boolean (yes/no) value serves as a shortcut to using the target path in this field.",
49 bwlimit
=> get_standard_option
('bwlimit'),
55 path
=> { fixed
=> 1 },
56 nodes
=> { optional
=> 1 },
57 shared
=> { optional
=> 1 },
58 disable
=> { optional
=> 1 },
59 maxfiles
=> { optional
=> 1 },
60 'prune-backups' => { optional
=> 1 },
61 content
=> { optional
=> 1 },
62 format
=> { optional
=> 1 },
63 mkdir => { optional
=> 1 },
64 is_mountpoint
=> { optional
=> 1 },
65 bwlimit
=> { optional
=> 1 },
66 preallocation
=> { optional
=> 1 },
70 # Storage implementation
73 # NOTE: should ProcFSTools::is_mounted accept an optional cache like this?
75 my ($mountpoint, $mountdata) = @_;
77 $mountpoint = Cwd
::realpath
($mountpoint); # symlinks
78 return 0 if !defined($mountpoint); # path does not exist
80 $mountdata = PVE
::ProcFSTools
::parse_proc_mounts
() if !$mountdata;
81 return 1 if grep { $_->[1] eq $mountpoint } @$mountdata;
85 sub parse_is_mountpoint
{
87 my $is_mp = $scfg->{is_mountpoint
};
88 return undef if !defined $is_mp;
89 if (defined(my $bool = PVE
::JSONSchema
::parse_boolean
($is_mp))) {
90 return $bool ?
$scfg->{path
} : undef;
92 return $is_mp; # contains a path
95 # FIXME remove on the next APIAGE reset.
96 # Deprecated, use get_volume_attribute instead.
97 sub get_volume_notes
{
98 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
100 my ($vtype) = $class->parse_volname($volname);
101 return if $vtype ne 'backup';
103 my $path = $class->filesystem_path($scfg, $volname);
104 $path .= $class->SUPER::NOTES_EXT
;
106 return PVE
::Tools
::file_get_contents
($path) if -f
$path;
111 # FIXME remove on the next APIAGE reset.
112 # Deprecated, use update_volume_attribute instead.
113 sub update_volume_notes
{
114 my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
116 my ($vtype) = $class->parse_volname($volname);
117 die "only backups can have notes\n" if $vtype ne 'backup';
119 my $path = $class->filesystem_path($scfg, $volname);
120 $path .= $class->SUPER::NOTES_EXT
;
122 if (defined($notes) && $notes ne '') {
123 PVE
::Tools
::file_set_contents
($path, $notes);
125 unlink $path or $! == ENOENT
or die "could not delete notes - $!\n";
130 sub get_volume_attribute
{
131 my ($class, $scfg, $storeid, $volname, $attribute) = @_;
133 if ($attribute eq 'notes') {
134 return $class->get_volume_notes($scfg, $storeid, $volname);
137 my ($vtype) = $class->parse_volname($volname);
138 return if $vtype ne 'backup';
140 if ($attribute eq 'protected') {
141 my $path = $class->filesystem_path($scfg, $volname);
142 return -e PVE
::Storage
::protection_file_path
($path) ?
1 : 0;
148 sub update_volume_attribute
{
149 my ($class, $scfg, $storeid, $volname, $attribute, $value) = @_;
151 if ($attribute eq 'notes') {
152 return $class->update_volume_notes($scfg, $storeid, $volname, $value);
155 my ($vtype) = $class->parse_volname($volname);
156 die "only backups support attribute '$attribute'\n" if $vtype ne 'backup';
158 if ($attribute eq 'protected') {
159 my $path = $class->filesystem_path($scfg, $volname);
160 my $protection_path = PVE
::Storage
::protection_file_path
($path);
162 return if !((-e
$protection_path) xor $value); # protection status already correct
165 my $fh = IO
::File-
>new($protection_path, O_CREAT
, 0644)
166 or die "unable to create protection file '$protection_path' - $!\n";
169 unlink $protection_path or $! == ENOENT
170 or die "could not delete protection file '$protection_path' - $!\n";
176 die "attribute '$attribute' is not supported for storage type '$scfg->{type}'\n";
180 my ($class, $storeid, $scfg, $cache) = @_;
182 if (defined(my $mp = parse_is_mountpoint
($scfg))) {
183 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
184 if !$cache->{mountdata
};
186 return undef if !path_is_mounted
($mp, $cache->{mountdata
});
189 return $class->SUPER::status
($storeid, $scfg, $cache);
193 sub activate_storage
{
194 my ($class, $storeid, $scfg, $cache) = @_;
196 my $path = $scfg->{path
};
197 if (!defined($scfg->{mkdir}) || $scfg->{mkdir}) {
201 my $mp = parse_is_mountpoint
($scfg);
202 if (defined($mp) && !path_is_mounted
($mp, $cache->{mountdata
})) {
203 die "unable to activate storage '$storeid' - " .
204 "directory is expected to be a mount point but is not mounted: '$mp'\n";
207 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
211 my ($self, $sectionId, $config, $create, $skipSchemaCheck) = @_;
212 my $opts = PVE
::SectionConfig
::check_config
($self, $sectionId, $config, $create, $skipSchemaCheck);
213 return $opts if !$create;
214 if ($opts->{path
} !~ m
@^/[-/a-zA-Z0-9_
.]+$@) {
215 die "illegal path for directory storage: $opts->{path}\n";