Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NFSv4. #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ Currently undocumented.
Currently undocumented.

####`sync`
Currently undocumented.
This configures the protocol that will be used to share files between the host machine and the
guests. You may set this to "rsync", "nfs", or "nfs4". "rsync" is the default.

####`folder`
Currently undocumented.
Expand Down
22 changes: 15 additions & 7 deletions vagrant/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ end

# XXX: workaround for: https://github.com/mitchellh/vagrant/issues/2447
# only run on 'vagrant init' or if it's the first time running vagrant
if sync == 'nfs' and ((ARGV.length > 0 and ARGV[0] == 'init') or not(File.exist?(f)))
if sync.start_with?('nfs') and ((ARGV.length > 0 and ARGV[0] == 'init') or not(File.exist?(f)))
`sudo systemctl restart nfs-server`
`firewall-cmd --permanent --zone public --add-service mountd`
`firewall-cmd --permanent --zone public --add-service rpc-bind`
Expand Down Expand Up @@ -815,12 +815,16 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if not ARGV.include?('--no-parallel') # when running in parallel,
config.cache.scope = :machine # use the per machine cache
end
if sync == 'nfs' # TODO: support other sync types here...
if sync.start_with?('nfs') # TODO: support other sync types here...
config.cache.enable_nfs = true # sets nfs => true on the synced_folder
# the nolock option is required, otherwise the NFSv3 client will try to
# access the NLM sideband protocol to lock files needed for /var/cache/
# all of this can be avoided by using NFSv4 everywhere. die NFSv3, die!
config.cache.mount_options = ['rw', 'vers=3', 'tcp', 'nolock']
if sync == 'nfs'
# the nolock option is required, otherwise the NFSv3 client will try to
# access the NLM sideband protocol to lock files needed for /var/cache/
# all of this can be avoided by using NFSv4 everywhere. die NFSv3, die!
config.cache.mount_options = ['rw', 'vers=3', 'tcp', 'nolock']
elsif sync == 'nfs4'
config.cache.mount_options = ['rw', 'vers=4', 'tcp']
end
end
end

Expand Down Expand Up @@ -970,7 +974,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if vm.vm.box.start_with? 'atomic-' or vm_sync == ''
disabled = true
end
vm.vm.synced_folder "#{dot}", '/vagrant', disabled: disabled, type: vm_sync # nfs, rsync
if vm_sync == 'nfs4'
vm.vm.synced_folder "#{dot}", '/vagrant', disabled: disabled, type: 'nfs', nfs_version: 4, nfs_udp: false
else
vm.vm.synced_folder "#{dot}", '/vagrant', disabled: disabled, type: vm_sync # nfs, rsync
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the above code, I wanted to dynamically construct the arguments type, nfs_version, and nfs_udp so I could not have to copy the other parameters. Sadly, my Ruby skills are nonexistent, and I'm coding on an airplane without Internet access for Ruby documentation. In Python, I'd do something like this:

params = {type: 'nfs'}
if vm_sync == "nfs4":
    params['nfs_version'] = 4
    params['nfs_udp'] = False
    function(some_stuff, **params)

If you can tell me how to do that I'll change it.


if vm.vm.box.start_with? 'atomic-'
synced_folder = '/home/vagrant/sync'
Expand Down