]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/NFSPlugin.pm
1 package PVE
::Storage
::NFSPlugin
;
7 use PVE
::Tools
qw(run_command);
8 use PVE
::Storage
::Plugin
;
9 use PVE
::JSONSchema
qw(get_standard_option);
11 use base
qw(PVE::Storage::Plugin);
13 # NFS helper functions
15 sub read_proc_mounts
{
17 local $/; # enable slurp mode
20 if (my $fd = IO
::File-
>new("/proc/mounts", "r")) {
29 my ($server, $export, $mountpoint, $mountdata) = @_;
31 my $source = "$server:$export";
33 $mountdata = read_proc_mounts
() if !$mountdata;
35 if ($mountdata =~ m
|^$source/?\s$mountpoint\snfs|m
) {
43 my ($server, $export, $mountpoint, $options) = @_;
45 my $source = "$server:$export";
47 my $cmd = ['/bin/mount', '-t', 'nfs', $source, $mountpoint];
49 push @$cmd, '-o', $options;
52 run_command
($cmd, errmsg
=> "mount error");
63 content
=> [ { images
=> 1, rootdir
=> 1, vztmpl
=> 1, iso
=> 1, backup
=> 1},
65 format
=> [ { raw
=> 1, qcow2
=> 1, vmdk
=> 1 } , 'raw' ],
72 description
=> "NFS export path.",
73 type
=> 'string', format
=> 'pve-storage-path',
76 description
=> "Server IP or DNS name.",
77 type
=> 'string', format
=> 'pve-storage-server',
80 description
=> "NFS mount options (see 'man nfs')",
81 type
=> 'string', format
=> 'pve-storage-options',
88 path
=> { fixed
=> 1 },
89 server
=> { fixed
=> 1 },
90 export
=> { fixed
=> 1 },
91 nodes
=> { optional
=> 1 },
92 disable
=> { optional
=> 1 },
93 maxfiles
=> { optional
=> 1 },
94 options
=> { optional
=> 1 },
95 content
=> { optional
=> 1 },
96 format
=> { optional
=> 1 },
102 my ($class, $sectionId, $config, $create, $skipSchemaCheck) = @_;
104 $config->{path
} = "/mnt/pve/$sectionId" if $create && !$config->{path
};
106 return $class->SUPER::check_config
($sectionId, $config, $create, $skipSchemaCheck);
109 # Storage implementation
112 my ($class, $storeid, $scfg, $cache) = @_;
114 $cache->{mountdata
} = read_proc_mounts
() 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
} = read_proc_mounts
() if !$cache->{mountdata
};
130 my $path = $scfg->{path
};
131 my $server = $scfg->{server
};
132 my $export = $scfg->{export
};
134 if (!nfs_is_mounted
($server, $export, $path, $cache->{mountdata
})) {
136 # NOTE: only call mkpath when not mounted (avoid hang
137 # when NFS server is offline
141 die "unable to activate storage '$storeid' - " .
142 "directory '$path' does not exist\n" if ! -d
$path;
144 nfs_mount
($server, $export, $path, $scfg->{options
});
147 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
150 sub deactivate_storage
{
151 my ($class, $storeid, $scfg, $cache) = @_;
153 $cache->{mountdata
} = read_proc_mounts
() if !$cache->{mountdata
};
155 my $path = $scfg->{path
};
156 my $server = $scfg->{server
};
157 my $export = $scfg->{export
};
159 if (nfs_is_mounted
($server, $export, $path, $cache->{mountdata
})) {
160 my $cmd = ['/bin/umount', $path];
161 run_command
($cmd, errmsg
=> 'umount error');