]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/NFSPlugin.pm
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 server
=> { fixed
=> 1 },
83 export
=> { fixed
=> 1 },
84 nodes
=> { optional
=> 1 },
85 disable
=> { optional
=> 1 },
86 maxfiles
=> { optional
=> 1 },
87 'prune-backups' => { optional
=> 1 },
88 options
=> { optional
=> 1 },
89 content
=> { optional
=> 1 },
90 format
=> { optional
=> 1 },
91 mkdir => { optional
=> 1 },
92 bwlimit
=> { optional
=> 1 },
98 my ($class, $sectionId, $config, $create, $skipSchemaCheck) = @_;
100 $config->{path
} = "/mnt/pve/$sectionId" if $create && !$config->{path
};
102 return $class->SUPER::check_config
($sectionId, $config, $create, $skipSchemaCheck);
105 # Storage implementation
108 my ($class, $storeid, $scfg, $cache) = @_;
110 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
111 if !$cache->{mountdata
};
113 my $path = $scfg->{path
};
114 my $server = $scfg->{server
};
115 my $export = $scfg->{export
};
117 return undef if !nfs_is_mounted
($server, $export, $path, $cache->{mountdata
});
119 return $class->SUPER::status
($storeid, $scfg, $cache);
122 sub activate_storage
{
123 my ($class, $storeid, $scfg, $cache) = @_;
125 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
126 if !$cache->{mountdata
};
128 my $path = $scfg->{path
};
129 my $server = $scfg->{server
};
130 my $export = $scfg->{export
};
132 if (!nfs_is_mounted
($server, $export, $path, $cache->{mountdata
})) {
133 # NOTE: only call mkpath when not mounted (avoid hang when NFS server is offline
134 mkpath
$path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir});
136 die "unable to activate storage '$storeid' - " .
137 "directory '$path' does not exist\n" if ! -d
$path;
139 nfs_mount
($server, $export, $path, $scfg->{options
});
142 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
145 sub deactivate_storage
{
146 my ($class, $storeid, $scfg, $cache) = @_;
148 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
149 if !$cache->{mountdata
};
151 my $path = $scfg->{path
};
152 my $server = $scfg->{server
};
153 my $export = $scfg->{export
};
155 if (nfs_is_mounted
($server, $export, $path, $cache->{mountdata
})) {
156 my $cmd = ['/bin/umount', $path];
157 run_command
($cmd, errmsg
=> 'umount error');
161 sub check_connection
{
162 my ($class, $storeid, $scfg) = @_;
164 my $server = $scfg->{server
};
165 my $opts = $scfg->{options
};
168 if (defined($opts) && $opts =~ /vers=4.*/) {
169 my $ip = PVE
::JSONSchema
::pve_verify_ip
($server, 1);
171 $ip = PVE
::Network
::get_ip_from_hostname
($server);
174 my $transport = PVE
::JSONSchema
::pve_verify_ipv4
($ip, 1) ?
'tcp' : 'tcp6';
176 # nfsv4 uses a pseudo-filesystem always beginning with /
177 # no exports are listed
178 $cmd = ['/usr/sbin/rpcinfo', '-T', $transport, $ip, 'nfs', '4'];
180 $cmd = ['/sbin/showmount', '--no-headers', '--exports', $server];
183 eval { run_command
($cmd, timeout
=> 10, outfunc
=> sub {}, errfunc
=> sub {}) };
191 sub get_volume_notes
{
193 PVE
::Storage
::DirPlugin
::get_volume_notes
($class, @_);
195 sub update_volume_notes
{
197 PVE
::Storage
::DirPlugin
::update_volume_notes
($class, @_);