From 61cf6b5e3b99d2bfe608352e2754d4332290c225 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 21 Jan 2009 14:15:39 +0000
Subject: [PATCH] Automatically release DRBD minors on success

This patch converts the DRBD minors reservation protocol from explicit
release to automatic release on the success paths. On the errors paths,
it's still needed to manual release.

The patch doesn't bring much by itself, but is needed for a future patch
which enhances the automatic verification of configuration consistency.

Reviewed-by: ultrotter
---
 lib/cmdlib.py |  5 -----
 lib/config.py | 27 ++++++++++++++++++++++-----
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 40c0ee3cf..9ba28e988 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -4566,8 +4566,6 @@ class LUCreateInstance(LogicalUnit):
     # Declare that we don't want to remove the instance lock anymore, as we've
     # added the instance to the config
     del self.remove_locks[locking.LEVEL_INSTANCE]
-    # Remove the temp. assignements for the instance's drbds
-    self.cfg.ReleaseDRBDMinors(instance)
     # Unlock all the nodes
     if self.op.mode == constants.INSTANCE_IMPORT:
       nodes_keep = [self.op.src_node]
@@ -5164,9 +5162,6 @@ class LUReplaceDisks(LogicalUnit):
       dev.logical_id = new_logical_id
       cfg.SetDiskID(dev, pri_node)
     cfg.Update(instance)
-    # we can remove now the temp minors as now the new values are
-    # written to the config file (and therefore stable)
-    self.cfg.ReleaseDRBDMinors(instance.name)
 
     # and now perform the drbd attach
     info("attaching primary drbds to new secondary (standalone => connected)")
diff --git a/lib/config.py b/lib/config.py
index bbbbeb09c..f34aa9e75 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -478,13 +478,9 @@ class ConfigWriter:
                   nodes, result)
     return result
 
-  @locking.ssynchronized(_config_lock)
-  def ReleaseDRBDMinors(self, instance):
+  def _UnlockedReleaseDRBDMinors(self, instance):
     """Release temporary drbd minors allocated for a given instance.
 
-    This should be called on both the error paths and on the success
-    paths (after the instance has been added or updated).
-
     @type instance: string
     @param instance: the instance for which temporary minors should be
                      released
@@ -496,6 +492,23 @@ class ConfigWriter:
       if name == instance:
         del self._temporary_drbds[key]
 
+  @locking.ssynchronized(_config_lock)
+  def ReleaseDRBDMinors(self, instance):
+    """Release temporary drbd minors allocated for a given instance.
+
+    This should be called on the error paths, on the success paths
+    it's automatically called by the ConfigWriter add and update
+    functions.
+
+    This function is just a wrapper over L{_UnlockedReleaseDRBDMinors}.
+
+    @type instance: string
+    @param instance: the instance for which temporary minors should be
+                     released
+
+    """
+    self._UnlockedReleaseDRBDMinors(instance)
+
   @locking.ssynchronized(_config_lock, shared=1)
   def GetConfigVersion(self):
     """Get the configuration version.
@@ -582,6 +595,7 @@ class ConfigWriter:
 
     instance.serial_no = 1
     self._config_data.instances[instance.name] = instance
+    self._UnlockedReleaseDRBDMinors(instance.name)
     self._WriteConfig()
 
   def _SetInstanceStatus(self, instance_name, status):
@@ -1118,4 +1132,7 @@ class ConfigWriter:
       # for node updates, we need to increase the cluster serial too
       self._config_data.cluster.serial_no += 1
 
+    if isinstance(target, objects.Instance):
+      self._UnlockedReleaseDRBDMinors(target.name)
+
     self._WriteConfig()
-- 
GitLab