diff --git a/CHANGELOG.md b/CHANGELOG.md index de1a8dc11..fb5a55f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ FEATURES: the VM if a fatal error occurs. [GH-2011] - NFS: Arbitrary mount options can be specified using the `mount_options` option on synced folders. [GH-1029] + - NFS: Arbitrary export options can be specified using + `bsd__nfs_options` and `linux__nfs_options`. [GH-1029] IMPROVEMENTS: diff --git a/plugins/hosts/bsd/host.rb b/plugins/hosts/bsd/host.rb index 51bbf58ef..a8dc08504 100644 --- a/plugins/hosts/bsd/host.rb +++ b/plugins/hosts/bsd/host.rb @@ -75,6 +75,29 @@ module VagrantPlugins dirs.sort_by! { |d| d.length } end + # Setup the NFS options + dirmap.each do |dirs, opts| + if !opts[:bsd__nfs_options] + opts[:bsd__nfs_options] = ["alldirs"] + end + + hasmapall = false + opts[:bsd__nfs_options].each do |opt| + if opt =~ /^mapall=/ + hasmapall = true + break + end + end + + if !hasmapall + opts[:bsd__nfs_options] << "mapall=#{opts[:map_uid]}:#{opts[:map_gid]}" + end + + opts[:bsd__compiled_nfs_options] = opts[:bsd__nfs_options].map do |opt| + "-#{opt}" + end.join(" ") + end + @logger.info("Exporting the following for NFS...") dirmap.each do |dirs, opts| @logger.info("NFS DIR: #{dirs.inspect}") diff --git a/plugins/hosts/linux/host.rb b/plugins/hosts/linux/host.rb index 12c1f3246..c4b6b49d9 100644 --- a/plugins/hosts/linux/host.rb +++ b/plugins/hosts/linux/host.rb @@ -35,6 +35,25 @@ module VagrantPlugins end def nfs_export(id, ips, folders) + folders.each do |k, opts| + if !opts[:linux__nfs_options] + opts[:linux__nfs_options] ||= ["rw", "no_subtree", "check", "all_squash"] + end + + # Only automatically set anonuid/anongid if they weren't + # explicitly set by the user. + hasgid = false + hasuid = false + opts[:linux__nfs_options].each do |opt| + hasgid = !!(opt =~ /^anongid=/) if !hasgid + hasuid = !!(opt =~ /^anonuid=/) if !hasuid + end + + opts[:linux__nfs_options] << "anonuid=#{opts[:map_uid]}" if !hasuid + opts[:linux__nfs_options] << "anongid=#{opts[:map_gid]}" if !hasgid + opts[:linux__nfs_options] << "fsid=#{opts[:uuid]}" + end + output = TemplateRenderer.render('nfs/exports_linux', :uuid => id, :ip => ip, diff --git a/templates/nfs/exports.erb b/templates/nfs/exports.erb index f0f0494a8..57741e420 100644 --- a/templates/nfs/exports.erb +++ b/templates/nfs/exports.erb @@ -1,5 +1,5 @@ # VAGRANT-BEGIN: <%= user %> <%= uuid %> <% folders.each do |dirs, opts| %> -<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ips.join(" ") %><% if opts[:map_uid] -%> -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%> +<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ips.join(" ") %> <%=opts[:bsd__compiled_nfs_options] %> <% end %> # VAGRANT-END: <%= user %> <%= uuid %> diff --git a/templates/nfs/exports_freebsd.erb b/templates/nfs/exports_freebsd.erb index ef07829b6..57741e420 100644 --- a/templates/nfs/exports_freebsd.erb +++ b/templates/nfs/exports_freebsd.erb @@ -1,5 +1,5 @@ # VAGRANT-BEGIN: <%= user %> <%= uuid %> <% folders.each do |dirs, opts| %> -<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ips.join(" ") %><% if opts[:map_uid] -%> -alldirs -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%> +<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ips.join(" ") %> <%=opts[:bsd__compiled_nfs_options] %> <% end %> # VAGRANT-END: <%= user %> <%= uuid %> diff --git a/templates/nfs/exports_linux.erb b/templates/nfs/exports_linux.erb index f9e17ba15..dc816c81e 100644 --- a/templates/nfs/exports_linux.erb +++ b/templates/nfs/exports_linux.erb @@ -1,7 +1,7 @@ # VAGRANT-BEGIN: <%= user %> <%= uuid %> <% ips.each do |ip| %> <% folders.each do |name, opts| %> -"<%= opts[:hostpath] %>" <%= ip %>(rw,no_subtree_check,all_squash<% if opts[:map_uid] %>,anonuid=<%= opts[:map_uid] %><% end %><% if opts[:map_gid] %>,anongid=<%= opts[:map_gid] %><% end %>,fsid=<%= opts[:uuid] %>) +"<%= opts[:hostpath] %>" <%= ip %>(<%= opts[:linux__nfs_options].join(",") %>) <% end %> <% end %> # VAGRANT-END: <%= user %> <%= uuid %>