From 3310c3cbf534f5d75477ed206a8fb68eb53c6c10 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Wed, 13 Feb 2019 09:50:14 -0800 Subject: [PATCH] Lock detach_volume A detach_volume operation may take place during a attach_volume or delete_instance opertaion. This may lead to a race condition which would result in an instance going into an error state as the volume operation is not atomic. Commit 4c4dc3a6d added the lock around the attach_volume. This follows that same pattern. Co-Authored-By: Matthew Booth Change-Id: I7261135a44f0c2eca4732c8360b9c74b729991a8 Closes-bug: #1662483 (cherry picked from commit 2e4e203c1a4c4f91dd1aabae8c8d7b745df99be7) --- nova/compute/manager.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 5d15a84ee546..12386cfefb3e 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -5657,10 +5657,14 @@ class ComputeManager(manager.Manager): and volume. """ - bdm = objects.BlockDeviceMapping.get_by_volume_and_instance( - context, volume_id, instance.uuid) - self._detach_volume(context, bdm, instance, - attachment_id=attachment_id) + @utils.synchronized(instance.uuid) + def do_detach_volume(context, volume_id, instance, attachment_id): + bdm = objects.BlockDeviceMapping.get_by_volume_and_instance( + context, volume_id, instance.uuid) + self._detach_volume(context, bdm, instance, + attachment_id=attachment_id) + + do_detach_volume(context, volume_id, instance, attachment_id) def _init_volume_connection(self, context, new_volume, old_volume_id, connector, bdm,