Commit e739bd57 authored by Iustin Pop's avatar Iustin Pop
Browse files

Change the way remove children is called in bdev

For some cases, we don't have to have access to the children of a device
in order to remove them (e.g. md over lvs, or drbd over lvs). In order
to ease the removal process, skip over finding the child if it provides
a static dev path.

This is needed in order to support removal of children when the
underlying storage has gone away.

Reviewed-by: imsnah
parent 222f2dd5
...@@ -807,12 +807,20 @@ def MirrorRemoveChildren(parent_cdev, new_cdevs): ...@@ -807,12 +807,20 @@ def MirrorRemoveChildren(parent_cdev, new_cdevs):
if parent_bdev is None: if parent_bdev is None:
logger.Error("Can't find parent in remove children: %s" % parent_cdev) logger.Error("Can't find parent in remove children: %s" % parent_cdev)
return False return False
new_bdevs = [_RecursiveFindBD(disk) for disk in new_cdevs] devs = []
if new_bdevs.count(None) > 0: for disk in new_cdevs:
logger.Error("Can't find some devices while removing children: %s %s" % rpath = disk.StaticDevPath()
(new_cdevs, new_bdevs)) if rpath is None:
return False bd = _RecursiveFindBD(disk)
parent_bdev.RemoveChildren(new_bdevs) if bd is None:
logger.Error("Can't find dynamic device %s while removing children" %
disk)
return False
else:
devs.append(bd.dev_path)
else:
devs.append(rpath)
parent_bdev.RemoveChildren(devs)
return True return True
......
...@@ -744,9 +744,9 @@ class MDRaid1(BlockDev): ...@@ -744,9 +744,9 @@ class MDRaid1(BlockDev):
args = ["mdadm", "-f", self.dev_path] args = ["mdadm", "-f", self.dev_path]
orig_devs = [] orig_devs = []
for dev in devices: for dev in devices:
args.append(dev.dev_path) args.append(dev)
for c in self._children: for c in self._children:
if c.dev_path == dev.dev_path: if c.dev_path == dev:
orig_devs.append(c) orig_devs.append(c)
break break
else: else:
...@@ -1878,13 +1878,16 @@ class DRBD8(BaseDRBD): ...@@ -1878,13 +1878,16 @@ class DRBD8(BaseDRBD):
if len(self._children) != 2: if len(self._children) != 2:
raise errors.BlockDeviceError("We don't have two children: %s" % raise errors.BlockDeviceError("We don't have two children: %s" %
self._children) self._children)
if self._children.count(None) == 2: # we don't actually have children :)
logger.Error("Requested detach while detached")
return
if len(devices) != 2: if len(devices) != 2:
raise errors.BlockDeviceError("We need two children in RemoveChildren") raise errors.BlockDeviceError("We need two children in RemoveChildren")
for idx, dev in enumerate(devices): for child, dev in zip(self._children, devices):
if dev.dev_path != self._children[idx].dev_path: if dev != child.dev_path:
raise errors.BlockDeviceError("Mismatch in local storage (%d) in" raise errors.BlockDeviceError("Mismatch in local storage"
" RemoveChildren" % idx) " (%s != %s) in RemoveChildren" %
(dev, child.dev_path))
if not self._ShutdownLocal(self.minor): if not self._ShutdownLocal(self.minor):
raise errors.BlockDeviceError("Can't detach from local storage") raise errors.BlockDeviceError("Can't detach from local storage")
......
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