Commit 746f7476 authored by Iustin Pop's avatar Iustin Pop
Browse files

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
parent cacfd1fd
...@@ -1249,24 +1249,24 @@ def BlockdevShutdown(disk): ...@@ -1249,24 +1249,24 @@ def BlockdevShutdown(disk):
""" """
msgs = [] msgs = []
result = True
r_dev = _RecursiveFindBD(disk) r_dev = _RecursiveFindBD(disk)
if r_dev is not None: if r_dev is not None:
r_path = r_dev.dev_path r_path = r_dev.dev_path
try: try:
result = r_dev.Shutdown() r_dev.Shutdown()
DevCacheManager.RemoveCache(r_path)
except errors.BlockDeviceError, err: except errors.BlockDeviceError, err:
msgs.append(str(err)) msgs.append(str(err))
result = False result = False
if result:
DevCacheManager.RemoveCache(r_path)
else:
result = True
if disk.children: if disk.children:
for child in disk.children: for child in disk.children:
c_status, c_msg = BlockdevShutdown(child) c_status, c_msg = BlockdevShutdown(child)
result = result and c_status result = result and c_status
if c_msg: # not an empty message if c_msg: # not an empty message
msgs.append(c_msg) msgs.append(c_msg)
return (result, "; ".join(msgs)) return (result, "; ".join(msgs))
......
...@@ -455,7 +455,7 @@ class LogicalVolume(BlockDev): ...@@ -455,7 +455,7 @@ class LogicalVolume(BlockDev):
volumes on shutdown. volumes on shutdown.
""" """
return True pass
def GetSyncStatus(self): def GetSyncStatus(self):
"""Returns the sync status of the device. """Returns the sync status of the device.
...@@ -1447,7 +1447,6 @@ class DRBD8(BaseDRBD): ...@@ -1447,7 +1447,6 @@ class DRBD8(BaseDRBD):
self._children[1].dev_path) self._children[1].dev_path)
if not result: if not result:
return False return False
need_localdev_teardown = True
if self._lhost and self._lport and self._rhost and self._rport: if self._lhost and self._lport and self._rhost and self._rport:
result = self._AssembleNet(minor, result = self._AssembleNet(minor,
(self._lhost, self._lport, (self._lhost, self._lport,
...@@ -1456,10 +1455,6 @@ class DRBD8(BaseDRBD): ...@@ -1456,10 +1455,6 @@ class DRBD8(BaseDRBD):
hmac=constants.DRBD_HMAC_ALG, hmac=constants.DRBD_HMAC_ALG,
secret=self._secret) secret=self._secret)
if not result: 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 return False
self._SetFromMinor(minor) self._SetFromMinor(minor)
return True return True
...@@ -1498,21 +1493,19 @@ class DRBD8(BaseDRBD): ...@@ -1498,21 +1493,19 @@ class DRBD8(BaseDRBD):
""" """
result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "down"]) result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "down"])
if result.failed: if result.failed:
logging.error("Can't shutdown drbd device: %s", result.output) _ThrowError("Can't shutdown drbd device: %s", result.output)
return not result.failed
def Shutdown(self): def Shutdown(self):
"""Shutdown the DRBD device. """Shutdown the DRBD device.
""" """
if self.minor is None and not self.Attach(): if self.minor is None and not self.Attach():
logging.info("DRBD device not attached to a device during Shutdown") logging.info("drbd%d: not attached during Shutdown()", self._aminor)
return True return
if not self._ShutdownAll(self.minor): minor = self.minor
return False
self.minor = None self.minor = None
self.dev_path = None self.dev_path = None
return True self._ShutdownAll(minor)
def Remove(self): def Remove(self):
"""Stub remove for DRBD devices. """Stub remove for DRBD devices.
...@@ -1602,7 +1595,7 @@ class FileStorage(BlockDev): ...@@ -1602,7 +1595,7 @@ class FileStorage(BlockDev):
the file on shutdown. the file on shutdown.
""" """
return True pass
def Open(self, force=False): def Open(self, force=False):
"""Make the device ready for I/O. """Make the device ready for I/O.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment