From 7a4312ac80845bc1f090dfbde0fffafb8f12bb75 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 10 Dec 2013 10:52:51 -0500 Subject: [PATCH] Add mount_options option. This option can be very useful with the existing enable_nfs option to choose a different protocol like tcp (udp is the default), and to add other nfs options like nolock. --- README.md | 9 ++++++++- lib/vagrant-cachier/config.rb | 18 ++++++++++-------- lib/vagrant-cachier/provision_ext.rb | 8 +++++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 32c382b..510d95d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,14 @@ Vagrant.configure("2") do |config| config.vm.box = 'your-box' config.cache.auto_detect = true # If you are using VirtualBox, you might want to enable NFS for shared folders - # config.cache.enable_nfs = true + # This is also very useful for vagrant-libvirt if you want bi-directional sync + # config.cache.enable_nfs = true + # You can now specify mount options if needed, eg: + # config.cache.mount_options = ['rw', 'vers=3', 'tcp', 'nolock'] + # The nolock option can be useful for an NFSv3 client that wants to avoid the + # NLM sideband protocol. Without this option, apt-get might hang if it tries + # to lock files needed for /var/cache/* operations. All of this can be avoided + # by using NFSv4 everywhere. die NFSv3, die! The tcp option is not the default. end ``` diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index a450505..f559007 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -1,15 +1,16 @@ module VagrantPlugins module Cachier class Config < Vagrant.plugin(2, :config) - attr_accessor :scope, :auto_detect, :enable_nfs + attr_accessor :scope, :auto_detect, :enable_nfs, :mount_options attr_reader :buckets ALLOWED_SCOPES = %w( box machine ) def initialize - @scope = UNSET_VALUE - @auto_detect = UNSET_VALUE - @enable_nfs = UNSET_VALUE + @scope = UNSET_VALUE + @auto_detect = UNSET_VALUE + @enable_nfs = UNSET_VALUE + @mount_options = UNSET_VALUE end def enable(bucket, opts = {}) @@ -31,10 +32,11 @@ module VagrantPlugins def finalize! return unless enabled? - @scope = :box if @scope == UNSET_VALUE - @auto_detect = false if @auto_detect == UNSET_VALUE - @enable_nfs = false if @enable_nfs == UNSET_VALUE - @buckets = @buckets ? @buckets.dup : {} + @scope = :box if @scope == UNSET_VALUE + @auto_detect = false if @auto_detect == UNSET_VALUE + @enable_nfs = false if @enable_nfs == UNSET_VALUE + @mount_options = false if @mount_options == UNSET_VALUE + @buckets = @buckets ? @buckets.dup : {} end def enabled? diff --git a/lib/vagrant-cachier/provision_ext.rb b/lib/vagrant-cachier/provision_ext.rb index e378d3c..9af8b8a 100644 --- a/lib/vagrant-cachier/provision_ext.rb +++ b/lib/vagrant-cachier/provision_ext.rb @@ -18,7 +18,13 @@ module VagrantPlugins FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? nfs_flag = env[:machine].config.cache.enable_nfs - env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', id: "vagrant-cache", nfs: nfs_flag + mount_options = env[:machine].config.cache.mount_options + + if mount_options + env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', id: "vagrant-cache", nfs: nfs_flag, mount_options: mount_options + else + env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', id: "vagrant-cache", nfs: nfs_flag + end env[:cache_dirs] = []