From ae26a2876850eac2bf91cd81bd21b23b74db459d Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 24 Oct 2007 13:30:17 +0000
Subject: [PATCH] Move/rename _IsValidMeta to base drbd class

The DRBDev._IsValidMeta only checks for the metadata device size. Since
this is a useful check (but not complete) for DRBD8, move it to the base
class and name it _CheckMetaSize.

Reviewed-by: imsnah
---
 lib/bdev.py | 57 ++++++++++++++++++++++++++---------------------------
 1 file changed, 28 insertions(+), 29 deletions(-)

diff --git a/lib/bdev.py b/lib/bdev.py
index 7d717c981..2d27ba71f 100644
--- a/lib/bdev.py
+++ b/lib/bdev.py
@@ -1017,6 +1017,32 @@ class BaseDRBD(BlockDev):
       self.minor = minor
       self.dev_path = self._DevPath(minor)
 
+  @staticmethod
+  def _CheckMetaSize(meta_device):
+    """Check if the given meta device looks like a valid one.
+
+    This currently only check the size, which must be around
+    128MiB.
+
+    """
+    result = utils.RunCmd(["blockdev", "--getsize", meta_device])
+    if result.failed:
+      logger.Error("Failed to get device size: %s" % result.fail_reason)
+      return False
+    try:
+      sectors = int(result.stdout)
+    except ValueError:
+      logger.Error("Invalid output from blockdev: '%s'" % result.stdout)
+      return False
+    bytes = sectors * 512
+    if bytes < 128 * 1024 * 1024: # less than 128MiB
+      logger.Error("Meta device too small (%.2fMib)" % (bytes / 1024 / 1024))
+      return False
+    if bytes > (128 + 32) * 1024 * 1024: # account for an extra (big) PE on LVM
+      logger.Error("Meta device too big (%.2fMiB)" % (bytes / 1024 / 1024))
+      return False
+    return True
+
 
 class DRBDev(BaseDRBD):
   """DRBD block device.
@@ -1168,33 +1194,6 @@ class DRBDev(BaseDRBD):
     return retval
 
 
-  @staticmethod
-  def _IsValidMeta(meta_device):
-    """Check if the given meta device looks like a valid one.
-
-    This currently only check the size, which must be around
-    128MiB.
-
-    """
-    result = utils.RunCmd(["blockdev", "--getsize", meta_device])
-    if result.failed:
-      logger.Error("Failed to get device size: %s" % result.fail_reason)
-      return False
-    try:
-      sectors = int(result.stdout)
-    except ValueError:
-      logger.Error("Invalid output from blockdev: '%s'" % result.stdout)
-      return False
-    bytes = sectors * 512
-    if bytes < 128*1024*1024: # less than 128MiB
-      logger.Error("Meta device too small (%.2fMib)" % (bytes/1024/1024))
-      return False
-    if bytes > (128+32)*1024*1024: # account for an extra (big) PE on LVM
-      logger.Error("Meta device too big (%.2fMiB)" % (bytes/1024/1024))
-      return False
-    return True
-
-
   @classmethod
   def _AssembleLocal(cls, minor, backend, meta):
     """Configure the local part of a DRBD device.
@@ -1203,7 +1202,7 @@ class DRBDev(BaseDRBD):
     device. And it must be done only once.
 
     """
-    if not cls._IsValidMeta(meta):
+    if not cls._CheckMetaSize(meta):
       return False
     result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "disk",
                            backend, meta, "0", "-e", "detach"])
@@ -1536,7 +1535,7 @@ class DRBDev(BaseDRBD):
     meta.Assemble()
     if not meta.Attach():
       raise errors.BlockDeviceError("Can't attach to meta device")
-    if not cls._IsValidMeta(meta.dev_path):
+    if not cls._CheckMetaSize(meta.dev_path):
       raise errors.BlockDeviceError("Invalid meta device")
     logger.Info("Started zeroing device %s" % meta.dev_path)
     cls._ZeroDevice(meta.dev_path)
-- 
GitLab