providers/docker: use a mutex for intra-process lock
This commit is contained in:
parent
4df8636c38
commit
447f407b0b
|
@ -1,5 +1,6 @@
|
||||||
require "digest/md5"
|
require "digest/md5"
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
|
require "thread"
|
||||||
|
|
||||||
require "log4r"
|
require "log4r"
|
||||||
|
|
||||||
|
@ -8,6 +9,8 @@ require "vagrant/util/silence_warnings"
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module DockerProvider
|
module DockerProvider
|
||||||
class Provider < Vagrant.plugin("2", :provider)
|
class Provider < Vagrant.plugin("2", :provider)
|
||||||
|
@@host_vm_mutex = Mutex.new
|
||||||
|
|
||||||
def initialize(machine)
|
def initialize(machine)
|
||||||
@logger = Log4r::Logger.new("vagrant::provider::docker")
|
@logger = Log4r::Logger.new("vagrant::provider::docker")
|
||||||
@machine = machine
|
@machine = machine
|
||||||
|
@ -94,11 +97,23 @@ module VagrantPlugins
|
||||||
# This acquires a lock on the host VM.
|
# This acquires a lock on the host VM.
|
||||||
def host_vm_lock
|
def host_vm_lock
|
||||||
hash = Digest::MD5.hexdigest(host_vm.data_dir.to_s)
|
hash = Digest::MD5.hexdigest(host_vm.data_dir.to_s)
|
||||||
@machine.env.lock(hash) do
|
|
||||||
return yield
|
# We do a process-level mutex on the outside, since we can
|
||||||
|
# wait for that a short amount of time. Then, we do a process lock
|
||||||
|
# on the inside, which will raise an exception if locked.
|
||||||
|
host_vm_mutex.synchronize do
|
||||||
|
@machine.env.lock(hash) do
|
||||||
|
return yield
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This is a process-local mutex that can be used by parallel
|
||||||
|
# providers to lock the host VM access.
|
||||||
|
def host_vm_mutex
|
||||||
|
@@host_vm_mutex
|
||||||
|
end
|
||||||
|
|
||||||
# This says whether or not Docker will be running within a VM
|
# This says whether or not Docker will be running within a VM
|
||||||
# rather than directly on our system. Docker needs to run in a VM
|
# rather than directly on our system. Docker needs to run in a VM
|
||||||
# when we're not on Linux, or not on a Linux that supports Docker.
|
# when we're not on Linux, or not on a Linux that supports Docker.
|
||||||
|
|
Loading…
Reference in New Issue