]>
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, snippets
=> 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.",
45 bwlimit
=> get_standard_option
('bwlimit'),
51 path
=> { fixed
=> 1 },
52 nodes
=> { optional
=> 1 },
53 shared
=> { optional
=> 1 },
54 disable
=> { optional
=> 1 },
55 maxfiles
=> { optional
=> 1 },
56 'prune-backups' => { optional
=> 1 },
57 content
=> { optional
=> 1 },
58 format
=> { optional
=> 1 },
59 mkdir => { optional
=> 1 },
60 is_mountpoint
=> { optional
=> 1 },
61 bwlimit
=> { optional
=> 1 },
65 # Storage implementation
68 # NOTE: should ProcFSTools::is_mounted accept an optional cache like this?
70 my ($mountpoint, $mountdata) = @_;
72 $mountpoint = Cwd
::realpath
($mountpoint); # symlinks
73 return 0 if !defined($mountpoint); # path does not exist
75 $mountdata = PVE
::ProcFSTools
::parse_proc_mounts
() if !$mountdata;
76 return 1 if grep { $_->[1] eq $mountpoint } @$mountdata;
80 sub parse_is_mountpoint
{
82 my $is_mp = $scfg->{is_mountpoint
};
83 return undef if !defined $is_mp;
84 if (defined(my $bool = PVE
::JSONSchema
::parse_boolean
($is_mp))) {
85 return $bool ?
$scfg->{path
} : undef;
87 return $is_mp; # contains a path
90 sub get_volume_notes
{
91 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
93 my $path = $class->filesystem_path($scfg, $volname);
94 $path .= $class->SUPER::NOTES_EXT
;
96 return PVE
::Tools
::file_get_contents
($path) if -f
$path;
101 sub update_volume_notes
{
102 my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
104 my ($vtype) = $class->parse_volname($volname);
105 die "only backups can have notes\n" if $vtype ne 'backup';
107 my $path = $class->filesystem_path($scfg, $volname);
108 $path .= $class->SUPER::NOTES_EXT
;
110 if (defined($notes) && $notes ne '') {
111 PVE
::Tools
::file_set_contents
($path, $notes);
113 unlink $path or die "could not delete notes - $!\n";
119 my ($class, $storeid, $scfg, $cache) = @_;
121 if (defined(my $mp = parse_is_mountpoint
($scfg))) {
122 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
123 if !$cache->{mountdata
};
125 return undef if !path_is_mounted
($mp, $cache->{mountdata
});
128 return $class->SUPER::status
($storeid, $scfg, $cache);
132 sub activate_storage
{
133 my ($class, $storeid, $scfg, $cache) = @_;
135 my $path = $scfg->{path
};
136 if (!defined($scfg->{mkdir}) || $scfg->{mkdir}) {
140 my $mp = parse_is_mountpoint
($scfg);
141 if (defined($mp) && !path_is_mounted
($mp, $cache->{mountdata
})) {
142 die "unable to activate storage '$storeid' - " .
143 "directory is expected to be a mount point but is not mounted: '$mp'\n";
146 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
150 my ($self, $sectionId, $config, $create, $skipSchemaCheck) = @_;
151 my $opts = PVE
::SectionConfig
::check_config
($self, $sectionId, $config, $create, $skipSchemaCheck);
152 return $opts if !$create;
153 if ($opts->{path
} !~ m
@^/[-/a-zA-Z0-9_
.]+$@) {
154 die "illegal path for directory storage: $opts->{path}\n";