]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/DirPlugin.pm
1fcb8ce0b6167c806eba38adca2a7fe4a68c0d61
1 package PVE
::Storage
::DirPlugin
;
10 use PVE
::Storage
::Plugin
;
11 use PVE
::JSONSchema
qw(get_standard_option);
13 use base
qw(PVE::Storage::Plugin);
23 content
=> [ { images
=> 1, rootdir
=> 1, vztmpl
=> 1, iso
=> 1, backup
=> 1, snippets
=> 1, none
=> 1 },
24 { images
=> 1, rootdir
=> 1 }],
25 format
=> [ { raw
=> 1, qcow2
=> 1, vmdk
=> 1, subvol
=> 1 } , 'raw' ],
32 description
=> "File system path.",
33 type
=> 'string', format
=> 'pve-storage-path',
36 description
=> "Create the directory if it doesn't exist.",
42 "Assume the given path is an externally managed mountpoint " .
43 "and consider the storage offline if it is not mounted. ".
44 "Using a boolean (yes/no) value serves as a shortcut to using the target path in this field.",
48 bwlimit
=> get_standard_option
('bwlimit'),
54 path
=> { fixed
=> 1 },
55 nodes
=> { optional
=> 1 },
56 shared
=> { optional
=> 1 },
57 disable
=> { optional
=> 1 },
58 maxfiles
=> { optional
=> 1 },
59 'prune-backups' => { optional
=> 1 },
60 content
=> { optional
=> 1 },
61 format
=> { optional
=> 1 },
62 mkdir => { optional
=> 1 },
63 is_mountpoint
=> { optional
=> 1 },
64 bwlimit
=> { optional
=> 1 },
65 preallocation
=> { optional
=> 1 },
69 # Storage implementation
72 # NOTE: should ProcFSTools::is_mounted accept an optional cache like this?
74 my ($mountpoint, $mountdata) = @_;
76 $mountpoint = Cwd
::realpath
($mountpoint); # symlinks
77 return 0 if !defined($mountpoint); # path does not exist
79 $mountdata = PVE
::ProcFSTools
::parse_proc_mounts
() if !$mountdata;
80 return 1 if grep { $_->[1] eq $mountpoint } @$mountdata;
84 sub parse_is_mountpoint
{
86 my $is_mp = $scfg->{is_mountpoint
};
87 return undef if !defined $is_mp;
88 if (defined(my $bool = PVE
::JSONSchema
::parse_boolean
($is_mp))) {
89 return $bool ?
$scfg->{path
} : undef;
91 return $is_mp; # contains a path
94 sub get_volume_notes
{
95 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
97 my $path = $class->filesystem_path($scfg, $volname);
98 $path .= $class->SUPER::NOTES_EXT
;
100 return PVE
::Tools
::file_get_contents
($path) if -f
$path;
105 sub update_volume_notes
{
106 my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
108 my ($vtype) = $class->parse_volname($volname);
109 die "only backups can have notes\n" if $vtype ne 'backup';
111 my $path = $class->filesystem_path($scfg, $volname);
112 $path .= $class->SUPER::NOTES_EXT
;
114 if (defined($notes) && $notes ne '') {
115 PVE
::Tools
::file_set_contents
($path, $notes);
117 unlink $path or $! == ENOENT
or die "could not delete notes - $!\n";
123 my ($class, $storeid, $scfg, $cache) = @_;
125 if (defined(my $mp = parse_is_mountpoint
($scfg))) {
126 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
127 if !$cache->{mountdata
};
129 return undef if !path_is_mounted
($mp, $cache->{mountdata
});
132 return $class->SUPER::status
($storeid, $scfg, $cache);
136 sub activate_storage
{
137 my ($class, $storeid, $scfg, $cache) = @_;
139 my $path = $scfg->{path
};
140 if (!defined($scfg->{mkdir}) || $scfg->{mkdir}) {
144 my $mp = parse_is_mountpoint
($scfg);
145 if (defined($mp) && !path_is_mounted
($mp, $cache->{mountdata
})) {
146 die "unable to activate storage '$storeid' - " .
147 "directory is expected to be a mount point but is not mounted: '$mp'\n";
150 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
154 my ($self, $sectionId, $config, $create, $skipSchemaCheck) = @_;
155 my $opts = PVE
::SectionConfig
::check_config
($self, $sectionId, $config, $create, $skipSchemaCheck);
156 return $opts if !$create;
157 if ($opts->{path
} !~ m
@^/[-/a-zA-Z0-9_
.]+$@) {
158 die "illegal path for directory storage: $opts->{path}\n";