[DRE-commits] [vagrant-libvirt] 94/163: Add lock around base box upload
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Apr 24 13:57:10 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag 0.0.26
in repository vagrant-libvirt.
commit 0da3b232b305c8dda09cc1e6f2ad8c0c64c0e6d5
Author: Brian Pitts <brian at polibyte.com>
Date: Sun Dec 7 16:30:35 2014 -0600
Add lock around base box upload
I'm not entirely happy with this, because we only really need a lock
when multiple VMs are using the same base box. If they are using
different boxes, we could safely upload in parallel. I did not see an
obvious way to implement that, so this will work. Parallel uploads are
likely not a performance improvement, anyway.
---
lib/vagrant-libvirt/action/handle_box_image.rb | 83 ++++++++++++++------------
1 file changed, 44 insertions(+), 39 deletions(-)
diff --git a/lib/vagrant-libvirt/action/handle_box_image.rb b/lib/vagrant-libvirt/action/handle_box_image.rb
index 4983111..7c972de 100644
--- a/lib/vagrant-libvirt/action/handle_box_image.rb
+++ b/lib/vagrant-libvirt/action/handle_box_image.rb
@@ -4,6 +4,9 @@ module VagrantPlugins
module ProviderLibvirt
module Action
class HandleBoxImage
+
+ @@lock = Mutex.new
+
def initialize(app, env)
@logger = Log4r::Logger.new('vagrant_libvirt::action::handle_box_image')
@app = app
@@ -34,49 +37,51 @@ module VagrantPlugins
env[:box_volume_name] = env[:machine].box.name.to_s.dup.gsub("/", "-VAGRANTSLASH-")
env[:box_volume_name] << '_vagrant_box_image.img'
- # Don't continue if image already exists in storage pool.
- return @app.call(env) if ProviderLibvirt::Util::Collection.find_matching(
- env[:libvirt_compute].volumes.all, env[:box_volume_name])
-
- # Box is not available as a storage pool volume. Create and upload
- # it as a copy of local box image.
- env[:ui].info(I18n.t('vagrant_libvirt.uploading_volume'))
+ @@lock.synchronize do
+ # Don't continue if image already exists in storage pool.
+ return @app.call(env) if ProviderLibvirt::Util::Collection.find_matching(
+ env[:libvirt_compute].volumes.all, env[:box_volume_name])
- # Create new volume in storage pool
- box_image_size = File.size(box_image_file) # B
- message = "Creating volume #{env[:box_volume_name]}"
- message << " in storage pool #{config.storage_pool_name}."
- @logger.info(message)
- begin
- fog_volume = env[:libvirt_compute].volumes.create(
- name: env[:box_volume_name],
- allocation: "#{box_image_size/1024/1024}M",
- capacity: "#{box_virtual_size}G",
- format_type: box_format,
- pool_name: config.storage_pool_name)
- rescue Fog::Errors::Error => e
- raise Errors::FogCreateVolumeError,
- :error_message => e.message
- end
+ # Box is not available as a storage pool volume. Create and upload
+ # it as a copy of local box image.
+ env[:ui].info(I18n.t('vagrant_libvirt.uploading_volume'))
- # Upload box image to storage pool
- ret = upload_image(box_image_file, config.storage_pool_name,
- env[:box_volume_name], env) do |progress|
- env[:ui].clear_line
- env[:ui].report_progress(progress, box_image_size, false)
- end
+ # Create new volume in storage pool
+ box_image_size = File.size(box_image_file) # B
+ message = "Creating volume #{env[:box_volume_name]}"
+ message << " in storage pool #{config.storage_pool_name}."
+ @logger.info(message)
+ begin
+ fog_volume = env[:libvirt_compute].volumes.create(
+ name: env[:box_volume_name],
+ allocation: "#{box_image_size/1024/1024}M",
+ capacity: "#{box_virtual_size}G",
+ format_type: box_format,
+ pool_name: config.storage_pool_name)
+ rescue Fog::Errors::Error => e
+ raise Errors::FogCreateVolumeError,
+ :error_message => e.message
+ end
- # Clear the line one last time since the progress meter doesn't
- # disappear immediately.
- env[:ui].clear_line
+ # Upload box image to storage pool
+ ret = upload_image(box_image_file, config.storage_pool_name,
+ env[:box_volume_name], env) do |progress|
+ env[:ui].clear_line
+ env[:ui].report_progress(progress, box_image_size, false)
+ end
- # If upload failed or was interrupted, remove created volume from
- # storage pool.
- if env[:interrupted] || !ret
- begin
- fog_volume.destroy
- rescue
- nil
+ # Clear the line one last time since the progress meter doesn't
+ # disappear immediately.
+ env[:ui].clear_line
+
+ # If upload failed or was interrupted, remove created volume from
+ # storage pool.
+ if env[:interrupted] || !ret
+ begin
+ fog_volume.destroy
+ rescue
+ nil
+ end
end
end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/vagrant-libvirt.git
More information about the Pkg-ruby-extras-commits
mailing list