From 03ece5f3a513a91c3dacabd806b7c5049aa1f038 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 6 Nov 2007 17:01:07 +0000
Subject: [PATCH] Enhance mirror operations for DRBD8

Currently, the mirror operations (add and remove children) test against
the instance's attributes. This patch changes the check tests to work
against the actual status of the device (i.e. live data) which is more
realistic.

The changes are:
  - allow add children if the device doesn't have local storage (even if
    we believe it has)
  - early return from remove children if the device is already without
    local storage

Reviewed-by: imsnah
---
 lib/bdev.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/bdev.py b/lib/bdev.py
index abedc90c2..f6d535f87 100644
--- a/lib/bdev.py
+++ b/lib/bdev.py
@@ -1850,10 +1850,10 @@ class DRBD8(BaseDRBD):
     """
     if self.minor is None:
       raise errors.BlockDeviceError("Can't attach to dbrd8 during AddChildren")
-
     if len(devices) != 2:
       raise errors.BlockDeviceError("Need two devices for AddChildren")
-    if self._children:
+    info = self._GetDevInfo(self.minor)
+    if "local_dev" in info:
       raise errors.BlockDeviceError("DRBD8 already attached to a local disk")
     backend, meta = devices
     if backend.dev_path is None or meta.dev_path is None:
@@ -1877,6 +1877,10 @@ class DRBD8(BaseDRBD):
     if self.minor is None:
       raise errors.BlockDeviceError("Can't attach to drbd8 during"
                                     " RemoveChildren")
+    # early return if we don't actually have backing storage
+    info = self._GetDevInfo(self.minor)
+    if "local_dev" not in info:
+      return
     if len(self._children) != 2:
       raise errors.BlockDeviceError("We don't have two children: %s" %
                                     self._children)
-- 
GitLab