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

Currently, the Remove() 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.

The patch also simplifies a little the Remove method of file-based
devices (no stat first, just try unlink).

Reviewed-by: ultrotter
---
 lib/backend.py |  2 +-
 lib/bdev.py    | 18 ++++++------------
 2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index 8d2cc110c..c9d251321 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -1145,7 +1145,7 @@ def BlockdevRemove(disk):
   if rdev is not None:
     r_path = rdev.dev_path
     try:
-      result = rdev.Remove()
+      rdev.Remove()
     except errors.BlockDeviceError, err:
       msgs.append(str(err))
       result = False
diff --git a/lib/bdev.py b/lib/bdev.py
index cfec2b2a0..8fa718dcf 100644
--- a/lib/bdev.py
+++ b/lib/bdev.py
@@ -368,14 +368,11 @@ class LogicalVolume(BlockDev):
     """
     if not self.minor and not self.Attach():
       # the LV does not exist
-      return True
+      return
     result = utils.RunCmd(["lvremove", "-f", "%s/%s" %
                            (self._vg_name, self._lv_name)])
     if result.failed:
-      logging.error("Can't lvremove: %s - %s",
-                    result.fail_reason, result.output)
-
-    return not result.failed
+      _ThrowError("Can't lvremove: %s - %s", result.fail_reason, result.output)
 
   def Rename(self, new_id):
     """Rename this logical volume.
@@ -506,7 +503,7 @@ class LogicalVolume(BlockDev):
 
     # remove existing snapshot if found
     snap = LogicalVolume((self._vg_name, snap_name), None)
-    snap.Remove()
+    _IgnoreError(snap.Remove)
 
     pvs_info = self.GetPVInfo(self._vg_name)
     if not pvs_info:
@@ -1511,7 +1508,7 @@ class DRBD8(BaseDRBD):
     """Stub remove for DRBD devices.
 
     """
-    return self.Shutdown()
+    self.Shutdown()
 
   @classmethod
   def Create(cls, unique_id, children, size):
@@ -1620,14 +1617,11 @@ class FileStorage(BlockDev):
     @return: True if the removal was successful
 
     """
-    if not os.path.exists(self.dev_path):
-      return True
     try:
       os.remove(self.dev_path)
-      return True
     except OSError, err:
-      logging.error("Can't remove file '%s': %s", self.dev_path, err)
-      return False
+      if err.errno != errno.ENOENT:
+        _ThrowError("Can't remove file '%s': %s", self.dev_path, err)
 
   def Attach(self):
     """Attach to an existing file.
-- 
GitLab