]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/NFSPlugin.pm
1 package PVE
::Storage
::NFSPlugin
;
7 use PVE
::Storage
::Plugin
;
8 use PVE
::JSONSchema
qw(get_standard_option);
10 use base
qw(PVE::Storage::Plugin);
12 # NFS helper functions
14 sub read_proc_mounts
{
16 local $/; # enable slurp mode
19 if (my $fd = IO
::File-
>new("/proc/mounts", "r")) {
28 my ($server, $export, $mountpoint, $mountdata) = @_;
30 my $source = "$server:$export";
32 $mountdata = read_proc_mounts
() if !$mountdata;
34 if ($mountdata =~ m
|^$source/?\s$mountpoint\snfs|m
) {
42 my ($server, $export, $mountpoint, $options) = @_;
44 my $source = "$server:$export";
46 my $cmd = ['/bin/mount', '-t', 'nfs', $source, $mountpoint];
48 push @$cmd, '-o', $options;
51 run_command
($cmd, errmsg
=> "mount error");
62 content
=> [ { images
=> 1, rootdir
=> 1, vztmpl
=> 1, iso
=> 1, backup
=> 1},
64 format
=> [ { raw
=> 1, qcow2
=> 1, vmdk
=> 1 } , 'raw' ],
71 description
=> "NFS export path.",
72 type
=> 'string', format
=> 'pve-storage-path',
75 description
=> "Server IP or DNS name.",
76 type
=> 'string', format
=> 'pve-storage-server',
79 description
=> "NFS mount options (see 'man nfs')",
80 type
=> 'string', format
=> 'pve-storage-options',
87 path
=> { fixed
=> 1 },
88 server
=> { fixed
=> 1 },
89 export
=> { fixed
=> 1 },
90 nodes
=> { optional
=> 1 },
91 disable
=> { optional
=> 1 },
92 maxfiles
=> { optional
=> 1 },
93 options
=> { optional
=> 1 },
94 content
=> { optional
=> 1 },
95 format
=> { 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
} = read_proc_mounts
() if !$cache->{mountdata
};
115 my $path = $scfg->{path
};
116 my $server = $scfg->{server
};
117 my $export = $scfg->{export
};
119 return undef if !nfs_is_mounted
($server, $export, $path, $cache->{mountdata
});
121 return $class->SUPER::status
($storeid, $scfg, $cache);
124 sub activate_storage
{
125 my ($class, $storeid, $scfg, $cache) = @_;
127 $cache->{mountdata
} = read_proc_mounts
() if !$cache->{mountdata
};
129 my $path = $scfg->{path
};
130 my $server = $scfg->{server
};
131 my $export = $scfg->{export
};
133 if (!nfs_is_mounted
($server, $export, $path, $cache->{mountdata
})) {
135 # NOTE: only call mkpath when not mounted (avoid hang
136 # when NFS server is offline
140 die "unable to activate storage '$storeid' - " .
141 "directory '$path' does not exist\n" if ! -d
$path;
143 nfs_mount
($server, $export, $path, $scfg->{options
});
146 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
149 sub deactivate_storage
{
150 my ($class, $storeid, $scfg, $cache) = @_;
152 $cache->{mountdata
} = read_proc_mounts
() 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');