Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Add mount_options option. #68

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
18 changes: 10 additions & 8 deletions lib/vagrant-cachier/config.rb
Original file line number Diff line number Diff line change
@@ -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 = {})
Expand All @@ -31,10 +32,11 @@ def validate(machine)
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?
Expand Down
8 changes: 7 additions & 1 deletion lib/vagrant-cachier/provision_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ def call(env)
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried but would it be a problem to pass in a blank hash of mount_options to synced_folder?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why... It seems to work for me...
I'm not a ruby expert, so maybe I've missed some nuance.
What error are you getting?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe I misunderstood your comment...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand what you meant. You're asking, why do I optionally add the hash in or not pass it in at all?
this is because when you pass in a blank hash, it erases the defaults that are set from the synced_folder. By default if you pass nothing, it uses vers=3,udp,rw.

So afaik, this patch makes the most sense as is.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry it wasn't clear but I'm glad you understood my comment. So yeah, I wasn't sure why we need to omit the parameter instead of passing in a blank hash and what you said makes sense :)
I'm away for the weekend but will look into bringing this in by monday! 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Sat, 2013-12-14 at 08:50 -0800, Fabio Rehm wrote:

@@ -18,7 +18,13 @@ def call(env)
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
    

Oh, sorry it wasn't clear but I'm glad you understood my comment. So yeah, I wasn't sure why we need to omit the parameter instead of passing in a blank hash and what you said makes sense :)
I'm away for the weekend but will look into bringing this in by monday! 👍
Sounds good!
Have a nice weekend!

James


Reply to this email directly or view it on GitHub:
https://github.com/fgrehm/vagrant-cachier/pull/68/files#r8352205

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] = []

Expand Down