Class: VagrantPlugins::ProviderLibvirt::Cap::Mount9P

Inherits:
Object
  • Object
show all
Extended by:
Vagrant::Util::Retryable
Defined in:
lib/vagrant-libvirt/cap/mount_9p.rb

Class Method Summary collapse

Class Method Details

.mount_9p_shared_folder(machine, folders) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vagrant-libvirt/cap/mount_9p.rb', line 12

def self.mount_9p_shared_folder(machine, folders)
  folders.each do |_name, opts|
    # Expand the guest path so we can handle things like "~/vagrant"
    expanded_guest_path = machine.guest.capability(
      :shell_expand_guest_path, opts[:guestpath]
    )

    # Do the actual creating and mounting
    machine.communicate.sudo("mkdir -p #{expanded_guest_path}")

    # Mount
    mount_tag = Digest::MD5.new.update(opts[:hostpath]).to_s[0, 31]

    mount_opts = '-o trans=virtio'
    mount_opts += ",access=#{opts[:access]}" if opts[:access]
    if opts[:owner]
      if opts[:access]
        machine.ui.warn('deprecated `:owner` option ignored as replacement `:access` option already set, please update your Vagrantfile and remove the `:owner` option to prevent this warning.')
      else
        machine.ui.warn('`:owner` option for 9p mount options deprecated in favour of `:access`, please update your Vagrantfile and replace `:owner` with `:access`')
        mount_opts += ",access=#{opts[:owner]}"
      end
    end
    mount_opts += ",version=#{opts[:version]}" if opts[:version]
    mount_opts += ",#{opts[:mount_opts]}" if opts[:mount_opts]

    mount_command = "mount -t 9p #{mount_opts} '#{mount_tag}' #{expanded_guest_path}"
    retryable(on: Vagrant::Errors::LinuxMountFailed,
              tries: 5,
              sleep: 3) do
      machine.communicate.sudo('modprobe 9p')
      machine.communicate.sudo('modprobe 9pnet_virtio')
      machine.communicate.sudo(mount_command,
                               error_class: Vagrant::Errors::LinuxMountFailed)
    end
  end
end