Skip to content

Instantly share code, notes, and snippets.

@cristiroma
Created November 10, 2017 08:19
Show Gist options
  • Save cristiroma/687d50dd06ccf09c9c2d2d27d3c9cd4f to your computer and use it in GitHub Desktop.
Save cristiroma/687d50dd06ccf09c9c2d2d27d3c9cd4f to your computer and use it in GitHub Desktop.
Fixes issue https://github.com/hashicorp/vagrant/issues/4666 in vagrant 1.9.1 - Duplicate NFS exports
diff --git a/nfs.rb.bak b/nfs.rb
index 731399b..13c3207 100644
--- a/nfs.rb.bak
+++ b/nfs.rb
@@ -29,6 +29,7 @@ module VagrantPlugins
nfs_start_command = env.host.capability(:nfs_start_command)
nfs_opts_setup(folders)
+ folders = folder_dupe_check(folders)
output = Vagrant::Util::TemplateRenderer.render('nfs/exports_linux',
uuid: id,
ips: ips,
@@ -49,6 +50,40 @@ module VagrantPlugins
end
end
+ protected
+
+ # Takes a hash of folders and removes any duplicate exports that
+ # share the same hostpath to avoid duplicate entries in /etc/exports
+ # ref: GH-4666
+ def self.folder_dupe_check(folders)
+ return_folders = {}
+ # Group by hostpath to see if there are multiple exports coming
+ # from the same folder
+ export_groups = folders.values.group_by { |h| h[:hostpath] }
+
+ # We need to check that each group key only has 1 value,
+ # and if not, check each nfs option. If all nfs options are the same
+ # we're good, otherwise throw an exception
+ export_groups.each do |path,group|
+ if group.size > 1
+ # if the linux nfs options aren't all the same throw an exception
+ group1_opts = group.first[:linux__nfs_options]
+
+ if !group.all? {|g| g[:linux__nfs_options] == group1_opts}
+ raise Vagrant::Errors::NFSDupePerms, hostpath: group.first[:hostpath]
+ else
+ # if they're the same just pick the first one
+ return_folders[path] = group.first
+ end
+ else
+ # just return folder, there are no duplicates
+ return_folders[path] = group.first
+ end
+ end
+ return_folders
+ end
+
+
def self.nfs_installed(environment)
retryable(tries: 10, on: TypeError) do
# Check procfs to see if NFSd is a supported filesystem
@cristiroma
Copy link
Author

On Fedora 26, after executing blt vm using Acquia BLT, the NFS mount is failing due to a bug in Vagrant 1.9.1 - hashicorp/vagrant#4666

Nov 09 19:54:10 prometheus.edw.ro systemd[1]: Starting NFS server and services...
Nov 09 19:54:10 prometheus.edw.ro exportfs[8532]: exportfs: duplicated export entries:
Nov 09 19:54:10 prometheus.edw.ro exportfs[8532]: exportfs:         192.168.116.154:/home/cristiroma/Work/test
Nov 09 19:54:10 prometheus.edw.ro exportfs[8532]: exportfs:         192.168.116.154:/home/cristiroma/Work/test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment