From 746f7476f3f28da87dc757f686b64ebd3de4f87f Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 10 Feb 2009 14:44:18 +0000
Subject: [PATCH] Change BlockDev.Shutdown() failure result

Currently, the Shutdown() methods of block devices return True/False.
This doesn't permit any error detail reporting.

This patch changes the return type to None for success, and raises
BlockDeviceError in case of failure. This permits the details to be
passed up the stack.

For LVM and file-backed devices, this is a simple change. For DRBD, we
first remove the shutdown of disks in case of network activation
failures (since with static minors the minor is used anyway, we don't
gain anything by clearing it), and the we simply change _ShutdownAll()
to raise an exception.

Reviewed-by: ultrotter
---
 lib/backend.py | 10 +++++-----
 lib/bdev.py    | 21 +++++++--------------
 2 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index e56628e99..c2b66f778 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -1249,24 +1249,24 @@ def BlockdevShutdown(disk):
 
   """
   msgs = []
+  result = True
   r_dev = _RecursiveFindBD(disk)
   if r_dev is not None:
     r_path = r_dev.dev_path
     try:
-      result = r_dev.Shutdown()
+      r_dev.Shutdown()
+      DevCacheManager.RemoveCache(r_path)
     except errors.BlockDeviceError, err:
       msgs.append(str(err))
       result = False
-    if result:
-      DevCacheManager.RemoveCache(r_path)
-  else:
-    result = True
+
   if disk.children:
     for child in disk.children:
       c_status, c_msg = BlockdevShutdown(child)
       result = result and c_status
       if c_msg: # not an empty message
         msgs.append(c_msg)
+
   return (result, "; ".join(msgs))
 
 
diff --git a/lib/bdev.py b/lib/bdev.py
index 2517c59a2..cfec2b2a0 100644
--- a/lib/bdev.py
+++ b/lib/bdev.py
@@ -455,7 +455,7 @@ class LogicalVolume(BlockDev):
     volumes on shutdown.
 
     """
-    return True
+    pass
 
   def GetSyncStatus(self):
     """Returns the sync status of the device.
@@ -1447,7 +1447,6 @@ class DRBD8(BaseDRBD):
                                    self._children[1].dev_path)
       if not result:
         return False
-      need_localdev_teardown = True
     if self._lhost and self._lport and self._rhost and self._rport:
       result = self._AssembleNet(minor,
                                  (self._lhost, self._lport,
@@ -1456,10 +1455,6 @@ class DRBD8(BaseDRBD):
                                  hmac=constants.DRBD_HMAC_ALG,
                                  secret=self._secret)
       if not result:
-        if need_localdev_teardown:
-          # we will ignore failures from this
-          logging.error("net setup failed, tearing down local device")
-          self._ShutdownAll(minor)
         return False
     self._SetFromMinor(minor)
     return True
@@ -1498,21 +1493,19 @@ class DRBD8(BaseDRBD):
     """
     result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "down"])
     if result.failed:
-      logging.error("Can't shutdown drbd device: %s", result.output)
-    return not result.failed
+      _ThrowError("Can't shutdown drbd device: %s", result.output)
 
   def Shutdown(self):
     """Shutdown the DRBD device.
 
     """
     if self.minor is None and not self.Attach():
-      logging.info("DRBD device not attached to a device during Shutdown")
-      return True
-    if not self._ShutdownAll(self.minor):
-      return False
+      logging.info("drbd%d: not attached during Shutdown()", self._aminor)
+      return
+    minor = self.minor
     self.minor = None
     self.dev_path = None
-    return True
+    self._ShutdownAll(minor)
 
   def Remove(self):
     """Stub remove for DRBD devices.
@@ -1602,7 +1595,7 @@ class FileStorage(BlockDev):
     the file on shutdown.
 
     """
-    return True
+    pass
 
   def Open(self, force=False):
     """Make the device ready for I/O.
-- 
GitLab