diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index 7c09ec1..2300456 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -61,12 +61,12 @@ module Vagrant end def share_folders(folders) - folders.each do |folder| - share_folder(folder[:hostpath], folder[:guestpath]) + folders.each do |f| + share_folder(f[:hostpath], f[:guestpath], f.fetch(:mount_options, 'bind')) end end - def share_folder(host_path, guest_path) + def share_folder(host_path, guest_path, mount_options = ['bind']) guest_path = rootfs_path.join(guest_path.gsub(/^\//, '')) unless guest_path.directory? begin @@ -77,7 +77,8 @@ module Vagrant end end - @customizations << ['mount.entry', "#{host_path} #{guest_path} none bind 0 0"] + mount_options = Array(mount_options) + @customizations << ['mount.entry', "#{host_path} #{guest_path} none #{mount_options.join(',')} 0 0"] end def start(customizations) diff --git a/lib/vagrant-lxc/synced_folder.rb b/lib/vagrant-lxc/synced_folder.rb index 0199d6a..e61b5b1 100644 --- a/lib/vagrant-lxc/synced_folder.rb +++ b/lib/vagrant-lxc/synced_folder.rb @@ -25,7 +25,8 @@ module Vagrant end end - machine.provider.driver.share_folder(host_path, guest_path) + mount_opts = data[:mount_options] + machine.provider.driver.share_folder(host_path, guest_path, mount_opts) # Guest path specified, so mount the folder to specified point machine.ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry", guestpath: data[:guestpath], diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb index ad52b29..8d61013 100644 --- a/spec/unit/driver_spec.rb +++ b/spec/unit/driver_spec.rb @@ -140,7 +140,8 @@ describe Vagrant::LXC::Driver do describe 'folder sharing' do let(:shared_folder) { {guestpath: '/vagrant', hostpath: '/path/to/host/dir'} } - let(:folders) { [shared_folder] } + let(:ro_rw_folder) { {guestpath: '/vagrant/ro_rw', hostpath: '/path/to/host/dir', mount_options: ['ro', 'rw']} } + let(:folders) { [shared_folder, ro_rw_folder] } let(:rootfs_path) { Pathname('/path/to/rootfs') } let(:expected_guest_path) { "#{rootfs_path}/vagrant" } let(:sudo_wrapper) { double(Vagrant::LXC::SudoWrapper, run: true) } @@ -162,5 +163,12 @@ describe Vagrant::LXC::Driver do "#{shared_folder[:hostpath]} #{expected_guest_path} none bind 0 0" ] end + + it 'supports additional mount options' do + subject.customizations.should include [ + 'mount.entry', + "#{ro_rw_folder[:hostpath]} #{rootfs_path}/vagrant/ro_rw none ro,rw 0 0" + ] + end end end