[pve-devel] [PATCH 2/2] NFSPlugin: deal with ipv6 addresses and fix regexps

Wolfgang Bumiller w.bumiller at proxmox.com
Wed May 20 16:57:31 CEST 2015


NFS needs brackets around ipv6 addresses.
Also: nfs_is_mounted needs to quote the variables. This becomes apparent
when ipv6 addresses are used as then the address would otherwise be
treated as a character class, causing the check to always fail.
---
 PVE/Storage/NFSPlugin.pm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/PVE/Storage/NFSPlugin.pm b/PVE/Storage/NFSPlugin.pm
index 79a7730..14aa4ed 100644
--- a/PVE/Storage/NFSPlugin.pm
+++ b/PVE/Storage/NFSPlugin.pm
@@ -3,6 +3,7 @@ package PVE::Storage::NFSPlugin;
 use strict;
 use warnings;
 use IO::File;
+use Net::IP;
 use File::Path;
 use PVE::Tools qw(run_command);
 use PVE::Storage::Plugin;
@@ -28,11 +29,12 @@ sub read_proc_mounts {
 sub nfs_is_mounted {
     my ($server, $export, $mountpoint, $mountdata) = @_;
 
+    $server = "[$server]" if Net::IP::ip_is_ipv6($server);
     my $source = "$server:$export";
 
     $mountdata = read_proc_mounts() if !$mountdata;
 
-    if ($mountdata =~ m|^$source/?\s$mountpoint\snfs|m) {
+    if ($mountdata =~ m|^\Q$source\E/?\s\Q$mountpoint\E\snfs|m) {
 	return $mountpoint;
     } 
 
@@ -42,6 +44,7 @@ sub nfs_is_mounted {
 sub nfs_mount {
     my ($server, $export, $mountpoint, $options) = @_;
 
+    $server = "[$server]" if Net::IP::ip_is_ipv6($server);
     my $source = "$server:$export";
 
     my $cmd = ['/bin/mount', '-t', 'nfs', $source, $mountpoint];
-- 
2.1.4





More information about the pve-devel mailing list