]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/NFSPlugin.pm
c94fb910d5b5cb306fbff746f5685cb386e9a2ee
1 package PVE
::Storage
::NFSPlugin
;
8 use PVE
::Tools
qw(run_command);
10 use PVE
::Storage
::Plugin
;
11 use PVE
::JSONSchema
qw(get_standard_option);
13 use base
qw(PVE::Storage::Plugin);
15 # NFS helper functions
18 my ($server, $export, $mountpoint, $mountdata) = @_;
20 $server = "[$server]" if Net
::IP
::ip_is_ipv6
($server);
21 my $source = "$server:$export";
23 $mountdata = PVE
::ProcFSTools
::parse_proc_mounts
() if !$mountdata;
24 return $mountpoint if grep {
26 $_->[0] =~ m
|^\Q
$source\E/?$| &&
27 $_->[1] eq $mountpoint
33 my ($server, $export, $mountpoint, $options) = @_;
35 $server = "[$server]" if Net
::IP
::ip_is_ipv6
($server);
36 my $source = "$server:$export";
38 my $cmd = ['/bin/mount', '-t', 'nfs', $source, $mountpoint];
40 push @$cmd, '-o', $options;
43 run_command
($cmd, errmsg
=> "mount error");
54 content
=> [ { images
=> 1, rootdir
=> 1, vztmpl
=> 1, iso
=> 1, backup
=> 1, snippets
=> 1 },
56 format
=> [ { raw
=> 1, qcow2
=> 1, vmdk
=> 1 } , 'raw' ],
63 description
=> "NFS export path.",
64 type
=> 'string', format
=> 'pve-storage-path',
67 description
=> "Server IP or DNS name.",
68 type
=> 'string', format
=> 'pve-storage-server',
71 description
=> "NFS mount options (see 'man nfs')",
72 type
=> 'string', format
=> 'pve-storage-options',
79 path
=> { fixed
=> 1 },
80 server
=> { fixed
=> 1 },
81 export
=> { fixed
=> 1 },
82 nodes
=> { optional
=> 1 },
83 disable
=> { optional
=> 1 },
84 maxfiles
=> { optional
=> 1 },
85 'prune-backups' => { optional
=> 1 },
86 options
=> { optional
=> 1 },
87 content
=> { optional
=> 1 },
88 format
=> { optional
=> 1 },
89 mkdir => { optional
=> 1 },
90 bwlimit
=> { optional
=> 1 },
96 my ($class, $sectionId, $config, $create, $skipSchemaCheck) = @_;
98 $config->{path
} = "/mnt/pve/$sectionId" if $create && !$config->{path
};
100 return $class->SUPER::check_config
($sectionId, $config, $create, $skipSchemaCheck);
103 # Storage implementation
106 my ($class, $storeid, $scfg, $cache) = @_;
108 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
109 if !$cache->{mountdata
};
111 my $path = $scfg->{path
};
112 my $server = $scfg->{server
};
113 my $export = $scfg->{export
};
115 return undef if !nfs_is_mounted
($server, $export, $path, $cache->{mountdata
});
117 return $class->SUPER::status
($storeid, $scfg, $cache);
120 sub activate_storage
{
121 my ($class, $storeid, $scfg, $cache) = @_;
123 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
124 if !$cache->{mountdata
};
126 my $path = $scfg->{path
};
127 my $server = $scfg->{server
};
128 my $export = $scfg->{export
};
130 if (!nfs_is_mounted
($server, $export, $path, $cache->{mountdata
})) {
132 # NOTE: only call mkpath when not mounted (avoid hang
133 # when NFS server is offline
135 mkpath
$path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir});
137 die "unable to activate storage '$storeid' - " .
138 "directory '$path' does not exist\n" if ! -d
$path;
140 nfs_mount
($server, $export, $path, $scfg->{options
});
143 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
146 sub deactivate_storage
{
147 my ($class, $storeid, $scfg, $cache) = @_;
149 $cache->{mountdata
} = PVE
::ProcFSTools
::parse_proc_mounts
()
150 if !$cache->{mountdata
};
152 my $path = $scfg->{path
};
153 my $server = $scfg->{server
};
154 my $export = $scfg->{export
};
156 if (nfs_is_mounted
($server, $export, $path, $cache->{mountdata
})) {
157 my $cmd = ['/bin/umount', $path];
158 run_command
($cmd, errmsg
=> 'umount error');
162 sub check_connection
{
163 my ($class, $storeid, $scfg) = @_;
165 my $server = $scfg->{server
};
167 my $cmd = ['/sbin/showmount', '--no-headers', '--exports', $server];
169 eval { run_command
($cmd, timeout
=> 10, outfunc
=> sub {}, errfunc
=> sub {}) };