]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/NFSPlugin.pm
c2d41762c76e3a9b4b12423a2825462dc5d17562
1 package PVE
::Storage
::NFSPlugin
;
10 use PVE
::Tools
qw(run_command);
12 use PVE
::Storage
::Plugin
;
13 use PVE
::JSONSchema
qw(get_standard_option);
15 use base
qw(PVE::Storage::Plugin);
17 # NFS helper functions
20 my ($server, $export, $mountpoint, $mountdata) = @_;
22 $server = "[$server]" if Net
::IP
::ip_is_ipv6
($server);
23 my $source = "$server:$export";
25 $mountdata = PVE
::ProcFSTools
::parse_proc_mounts
() if !$mountdata;
26 return $mountpoint if grep {
28 $_->[0] =~ m
|^\Q
$source\E/?$| &&
29 $_->[1] eq $mountpoint
35 my ($server, $export, $mountpoint, $options) = @_;
37 $server = "[$server]" if Net
::IP
::ip_is_ipv6
($server);
38 my $source = "$server:$export";
40 my $cmd = ['/bin/mount', '-t', 'nfs', $source, $mountpoint];
42 push @$cmd, '-o', $options;
45 run_command
($cmd, errmsg
=> "mount error");
56 content
=> [ { images
=> 1, rootdir
=> 1, vztmpl
=> 1, iso
=> 1, backup
=> 1, snippets
=> 1 },
58 format
=> [ { raw
=> 1, qcow2
=> 1, vmdk
=> 1 } , 'raw' ],
65 description
=> "NFS export path.",
66 type
=> 'string', format
=> 'pve-storage-path',
69 description
=> "Server IP or DNS name.",
70 type
=> 'string', format
=> 'pve-storage-server',
73 description
=> "NFS mount options (see 'man nfs')",
74 type
=> 'string', format
=> 'pve-storage-options',
81 path
=> { fixed
=> 1 },
82 'content-dirs' => { optional
=> 1 },
83 server
=> { fixed
=> 1 },
84 export
=> { fixed
=> 1 },
85 nodes
=> { optional
=> 1 },
86 disable
=> { optional
=> 1 },
87 maxfiles
=> { optional
=> 1 },
88 'prune-backups' => { optional
=> 1 },
89 'max-protected-backups' => { optional
=> 1 },
90 options
=> { optional
=> 1 },
91 content
=> { optional
=> 1 },
92 format
=> { optional
=> 1 },
93 mkdir => { optional
=> 1 },
94 bwlimit
=> { optional
=> 1 },
95 preallocation
=> { optional
=> 1 },
101 my ($class, $sectionId, $config, $create, $skipSchemaCheck) = @_;
103 $config->{path
} = "/mnt/pve/$sectionId" if $create && !$config->{path
};
105 return $class->SUPER::check_config
($sectionId, $config, $create, $skipSchemaCheck);
108 # Storage implementation
111 my ($class, $storeid, $scfg, $cache) = @_;
113 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
114 if !$cache->{mountdata
};
116 my $path = $scfg->{path
};
117 my $server = $scfg->{server
};
118 my $export = $scfg->{export
};
120 return undef if !nfs_is_mounted
($server, $export, $path, $cache->{mountdata
});
122 return $class->SUPER::status
($storeid, $scfg, $cache);
125 sub activate_storage
{
126 my ($class, $storeid, $scfg, $cache) = @_;
128 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
129 if !$cache->{mountdata
};
131 my $path = $scfg->{path
};
132 my $server = $scfg->{server
};
133 my $export = $scfg->{export
};
135 if (!nfs_is_mounted
($server, $export, $path, $cache->{mountdata
})) {
136 # NOTE: only call mkpath when not mounted (avoid hang when NFS server is offline
137 mkpath
$path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir});
139 die "unable to activate storage '$storeid' - " .
140 "directory '$path' does not exist\n" if ! -d
$path;
142 nfs_mount
($server, $export, $path, $scfg->{options
});
145 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
148 sub deactivate_storage
{
149 my ($class, $storeid, $scfg, $cache) = @_;
151 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
152 if !$cache->{mountdata
};
154 my $path = $scfg->{path
};
155 my $server = $scfg->{server
};
156 my $export = $scfg->{export
};
158 if (nfs_is_mounted
($server, $export, $path, $cache->{mountdata
})) {
159 my $cmd = ['/bin/umount', $path];
160 run_command
($cmd, errmsg
=> 'umount error');
164 sub check_connection
{
165 my ($class, $storeid, $scfg) = @_;
167 my $server = $scfg->{server
};
168 my $opts = $scfg->{options
};
172 my $is_v4 = defined($opts) && $opts =~ /vers=4.*/;
174 my $ip = PVE
::JSONSchema
::pve_verify_ip
($server, 1);
176 $ip = PVE
::Network
::get_ip_from_hostname
($server);
179 my $transport = PVE
::JSONSchema
::pve_verify_ipv4
($ip, 1) ?
'tcp' : 'tcp6';
181 # nfsv4 uses a pseudo-filesystem always beginning with /
182 # no exports are listed
183 $cmd = ['/usr/sbin/rpcinfo', '-T', $transport, $ip, 'nfs', '4'];
185 $cmd = ['/sbin/showmount', '--no-headers', '--exports', $server];
188 eval { run_command
($cmd, timeout
=> 10, outfunc
=> sub {}, errfunc
=> sub {}) };
192 $port = $1 if defined($opts) && $opts =~ /port=(\d+)/;
194 # rpcinfo is expected to work when the port is 0 (see 'man 5 nfs') and tcp_ping()
195 # defaults to port 7 when passing in 0.
196 return 0 if $port == 0;
198 return PVE
::Network
::tcp_ping
($server, $port, 2);
206 # FIXME remove on the next APIAGE reset.
207 # Deprecated, use get_volume_attribute instead.
208 sub get_volume_notes
{
210 PVE
::Storage
::DirPlugin
::get_volume_notes
($class, @_);
213 # FIXME remove on the next APIAGE reset.
214 # Deprecated, use update_volume_attribute instead.
215 sub update_volume_notes
{
217 PVE
::Storage
::DirPlugin
::update_volume_notes
($class, @_);
220 sub get_volume_attribute
{
221 return PVE
::Storage
::DirPlugin
::get_volume_attribute
(@_);
224 sub update_volume_attribute
{
225 return PVE
::Storage
::DirPlugin
::update_volume_attribute
(@_);