From 9c8971d718dcdaa232c6e84748e2e56f67f71520 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Tue, 2 Dec 2008 10:19:02 +0000
Subject: [PATCH] LUCreateInstance: keep src node lock on import

Currently the node lock also guards against removing the import at the
wrong time, so if we're importing an instance image we want to keep the
source node locked. In the future we might want to put export locks at a
different level than node locks.

Reviewed-by: iustinp
---
 lib/cmdlib.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index c89e9a0cb..ae5055245 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -3941,8 +3941,15 @@ class LUCreateInstance(LogicalUnit):
     # Remove the temp. assignements for the instance's drbds
     self.cfg.ReleaseDRBDMinors(instance)
     # Unlock all the nodes
-    self.context.glm.release(locking.LEVEL_NODE)
-    del self.acquired_locks[locking.LEVEL_NODE]
+    if self.op.mode == constants.INSTANCE_IMPORT:
+      nodes_keep = [self.op.src_node]
+      nodes_release = [node for node in self.acquired_locks[locking.LEVEL_NODE]
+                       if node != self.op.src_node]
+      self.context.glm.release(locking.LEVEL_NODE, nodes_release)
+      self.acquired_locks[locking.LEVEL_NODE] = nodes_keep
+    else:
+      self.context.glm.release(locking.LEVEL_NODE)
+      del self.acquired_locks[locking.LEVEL_NODE]
 
     if self.op.wait_for_sync:
       disk_abort = not _WaitForSync(self, iobj)
-- 
GitLab