Sha256: f265248c0c586f6d147e47883bf7bb46fc3da3ef328a8cae25d822bbc26f778a

Contents?: true

Size: 1.51 KB

Versions: 18

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

require 'digest/md5'
require 'vagrant/util/retryable'

module VagrantPlugins
  module ProviderLibvirt
    module Cap
      class Mount9P
        extend Vagrant::Util::Retryable

        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[:owner]}" if opts[:owner]
            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
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
vagrant-libvirt-0.10.8 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.10.7 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.10.6 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.10.5 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.10.4 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.10.3 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.10.2 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.10.1 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.10.0 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.9.0 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.8.2 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.8.1 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.8.0 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.7.0 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.6.3 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.6.2 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.6.1 lib/vagrant-libvirt/cap/mount_9p.rb
vagrant-libvirt-0.6.0 lib/vagrant-libvirt/cap/mount_9p.rb