Commit 464f8daf authored by Iustin Pop's avatar Iustin Pop
Browse files

Change the bdev init signatures



This patch changes all the bdev.BlockDev constructors to take an
additional ‘size’ parameter, all the backend functions that call those
functions to pass it and also changes backend.BlocdevCreate() to not use
the size passed via the rpc call but instead directly disk.size (this is
the only way it's called).

Note that this patch doesn't do anything with this parameter, just
stores it on the blockdev objects.

With the patch, we actually have a more uniform init sequence (before
create had the parameter, but the other functions not).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 2cd855dd
...@@ -1124,7 +1124,7 @@ def BlockdevCreate(disk, size, owner, on_primary, info): ...@@ -1124,7 +1124,7 @@ def BlockdevCreate(disk, size, owner, on_primary, info):
clist.append(crdev) clist.append(crdev)
try: try:
device = bdev.Create(disk.dev_type, disk.physical_id, clist, size) device = bdev.Create(disk.dev_type, disk.physical_id, clist, disk.size)
except errors.BlockDeviceError, err: except errors.BlockDeviceError, err:
return False, "Can't create block device: %s" % str(err) return False, "Can't create block device: %s" % str(err)
...@@ -1234,7 +1234,7 @@ def _RecursiveAssembleBD(disk, owner, as_primary): ...@@ -1234,7 +1234,7 @@ def _RecursiveAssembleBD(disk, owner, as_primary):
children.append(cdev) children.append(cdev)
if as_primary or disk.AssembleOnSecondary(): if as_primary or disk.AssembleOnSecondary():
r_dev = bdev.Assemble(disk.dev_type, disk.physical_id, children) r_dev = bdev.Assemble(disk.dev_type, disk.physical_id, children, disk.size)
r_dev.SetSyncSpeed(constants.SYNC_SPEED) r_dev.SetSyncSpeed(constants.SYNC_SPEED)
result = r_dev result = r_dev
if as_primary or disk.OpenOnSecondary(): if as_primary or disk.OpenOnSecondary():
...@@ -1404,7 +1404,7 @@ def _RecursiveFindBD(disk): ...@@ -1404,7 +1404,7 @@ def _RecursiveFindBD(disk):
for chdisk in disk.children: for chdisk in disk.children:
children.append(_RecursiveFindBD(chdisk)) children.append(_RecursiveFindBD(chdisk))
return bdev.FindDevice(disk.dev_type, disk.physical_id, children) return bdev.FindDevice(disk.dev_type, disk.physical_id, children, disk.size)
def BlockdevFind(disk): def BlockdevFind(disk):
......
...@@ -108,13 +108,14 @@ class BlockDev(object): ...@@ -108,13 +108,14 @@ class BlockDev(object):
after assembly we'll have our correct major/minor. after assembly we'll have our correct major/minor.
""" """
def __init__(self, unique_id, children): def __init__(self, unique_id, children, size):
self._children = children self._children = children
self.dev_path = None self.dev_path = None
self.unique_id = unique_id self.unique_id = unique_id
self.major = None self.major = None
self.minor = None self.minor = None
self.attached = False self.attached = False
self.size = size
def Assemble(self): def Assemble(self):
"""Assemble the device from its components. """Assemble the device from its components.
...@@ -286,13 +287,13 @@ class LogicalVolume(BlockDev): ...@@ -286,13 +287,13 @@ class LogicalVolume(BlockDev):
"""Logical Volume block device. """Logical Volume block device.
""" """
def __init__(self, unique_id, children): def __init__(self, unique_id, children, size):
"""Attaches to a LV device. """Attaches to a LV device.
The unique_id is a tuple (vg_name, lv_name) The unique_id is a tuple (vg_name, lv_name)
""" """
super(LogicalVolume, self).__init__(unique_id, children) super(LogicalVolume, self).__init__(unique_id, children, size)
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2: if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
raise ValueError("Invalid configuration data %s" % str(unique_id)) raise ValueError("Invalid configuration data %s" % str(unique_id))
self._vg_name, self._lv_name = unique_id self._vg_name, self._lv_name = unique_id
...@@ -329,7 +330,7 @@ class LogicalVolume(BlockDev): ...@@ -329,7 +330,7 @@ class LogicalVolume(BlockDev):
if result.failed: if result.failed:
_ThrowError("LV create failed (%s): %s", _ThrowError("LV create failed (%s): %s",
result.fail_reason, result.output) result.fail_reason, result.output)
return LogicalVolume(unique_id, children) return LogicalVolume(unique_id, children, size)
@staticmethod @staticmethod
def GetPVInfo(vg_name): def GetPVInfo(vg_name):
...@@ -500,7 +501,7 @@ class LogicalVolume(BlockDev): ...@@ -500,7 +501,7 @@ class LogicalVolume(BlockDev):
snap_name = self._lv_name + ".snap" snap_name = self._lv_name + ".snap"
# remove existing snapshot if found # remove existing snapshot if found
snap = LogicalVolume((self._vg_name, snap_name), None) snap = LogicalVolume((self._vg_name, snap_name), None, size)
_IgnoreError(snap.Remove) _IgnoreError(snap.Remove)
pvs_info = self.GetPVInfo(self._vg_name) pvs_info = self.GetPVInfo(self._vg_name)
...@@ -805,10 +806,10 @@ class DRBD8(BaseDRBD): ...@@ -805,10 +806,10 @@ class DRBD8(BaseDRBD):
# timeout constants # timeout constants
_NET_RECONFIG_TIMEOUT = 60 _NET_RECONFIG_TIMEOUT = 60
def __init__(self, unique_id, children): def __init__(self, unique_id, children, size):
if children and children.count(None) > 0: if children and children.count(None) > 0:
children = [] children = []
super(DRBD8, self).__init__(unique_id, children) super(DRBD8, self).__init__(unique_id, children, size)
self.major = self._DRBD_MAJOR self.major = self._DRBD_MAJOR
version = self._GetVersion() version = self._GetVersion()
if version['k_major'] != 8 : if version['k_major'] != 8 :
...@@ -1535,7 +1536,7 @@ class DRBD8(BaseDRBD): ...@@ -1535,7 +1536,7 @@ class DRBD8(BaseDRBD):
aminor, meta) aminor, meta)
cls._CheckMetaSize(meta.dev_path) cls._CheckMetaSize(meta.dev_path)
cls._InitMeta(aminor, meta.dev_path) cls._InitMeta(aminor, meta.dev_path)
return cls(unique_id, children) return cls(unique_id, children, size)
def Grow(self, amount): def Grow(self, amount):
"""Resize the DRBD device and its backing storage. """Resize the DRBD device and its backing storage.
...@@ -1559,13 +1560,13 @@ class FileStorage(BlockDev): ...@@ -1559,13 +1560,13 @@ class FileStorage(BlockDev):
The unique_id for the file device is a (file_driver, file_path) tuple. The unique_id for the file device is a (file_driver, file_path) tuple.
""" """
def __init__(self, unique_id, children): def __init__(self, unique_id, children, size):
"""Initalizes a file device backend. """Initalizes a file device backend.
""" """
if children: if children:
raise errors.BlockDeviceError("Invalid setup for file device") raise errors.BlockDeviceError("Invalid setup for file device")
super(FileStorage, self).__init__(unique_id, children) super(FileStorage, self).__init__(unique_id, children, size)
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2: if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
raise ValueError("Invalid configuration data %s" % str(unique_id)) raise ValueError("Invalid configuration data %s" % str(unique_id))
self.driver = unique_id[0] self.driver = unique_id[0]
...@@ -1653,7 +1654,7 @@ class FileStorage(BlockDev): ...@@ -1653,7 +1654,7 @@ class FileStorage(BlockDev):
except IOError, err: except IOError, err:
_ThrowError("Error in file creation: %", str(err)) _ThrowError("Error in file creation: %", str(err))
return FileStorage(unique_id, children) return FileStorage(unique_id, children, size)
DEV_MAP = { DEV_MAP = {
...@@ -1663,7 +1664,7 @@ DEV_MAP = { ...@@ -1663,7 +1664,7 @@ DEV_MAP = {
} }
def FindDevice(dev_type, unique_id, children): def FindDevice(dev_type, unique_id, children, size):
"""Search for an existing, assembled device. """Search for an existing, assembled device.
This will succeed only if the device exists and is assembled, but it This will succeed only if the device exists and is assembled, but it
...@@ -1672,13 +1673,13 @@ def FindDevice(dev_type, unique_id, children): ...@@ -1672,13 +1673,13 @@ def FindDevice(dev_type, unique_id, children):
""" """
if dev_type not in DEV_MAP: if dev_type not in DEV_MAP:
raise errors.ProgrammerError("Invalid block device type '%s'" % dev_type) raise errors.ProgrammerError("Invalid block device type '%s'" % dev_type)
device = DEV_MAP[dev_type](unique_id, children) device = DEV_MAP[dev_type](unique_id, children, size)
if not device.attached: if not device.attached:
return None return None
return device return device
def Assemble(dev_type, unique_id, children): def Assemble(dev_type, unique_id, children, size):
"""Try to attach or assemble an existing device. """Try to attach or assemble an existing device.
This will attach to assemble the device, as needed, to bring it This will attach to assemble the device, as needed, to bring it
...@@ -1687,7 +1688,7 @@ def Assemble(dev_type, unique_id, children): ...@@ -1687,7 +1688,7 @@ def Assemble(dev_type, unique_id, children):
""" """
if dev_type not in DEV_MAP: if dev_type not in DEV_MAP:
raise errors.ProgrammerError("Invalid block device type '%s'" % dev_type) raise errors.ProgrammerError("Invalid block device type '%s'" % dev_type)
device = DEV_MAP[dev_type](unique_id, children) device = DEV_MAP[dev_type](unique_id, children, size)
device.Assemble() device.Assemble()
return device return device
......
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