Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Serialize attach/detach ops for the same vm #808

Merged
merged 1 commit into from
Dec 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions esx_service/vmdk_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def executeRequest(vm_uuid, vm_name, config_path, cmd, full_vol_name, opts):
# Set thread name to vm_name-lockname
threadutils.set_thread_name("{0}-{1}".format(vm_name, lockname))

# Get a resource lock
# Get a lock for the volume
logging.debug("Trying to acquire lock: %s", lockname)
with lockManager.get_lock(lockname):
logging.debug("Acquired lock: %s", lockname)
Expand All @@ -748,10 +748,14 @@ def executeRequest(vm_uuid, vm_name, config_path, cmd, full_vol_name, opts):
vm_name=vm_name,
tenant_uuid=tenant_uuid,
datastore=datastore)

# For attach/detach reconfigure tasks, hold a per vm lock.
elif cmd == "attach":
response = attachVMDK(vmdk_path, vm_uuid)
with lockManager.get_lock(vm_uuid):
response = attachVMDK(vmdk_path, vm_uuid)
elif cmd == "detach":
response = detachVMDK(vmdk_path, vm_uuid)
with lockManager.get_lock(vm_uuid):
response = detachVMDK(vmdk_path, vm_uuid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client plugin also has a lock (per docker-host), do we need one more lock in the ESX service? The disk level locks are good?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disk level locks are good. :)
The error comes from already having a reconfig task running for the same VM. (different volumes)
I didn't investigated why the mutex in the plugin driver is not protecting this situation, but serialization for attach/detach is really needed on the esx part. I might be missing something, but in the plugin we need to protect the refcount part only?

else:
return err("Unknown command:" + cmd)

Expand Down