From: David Lehman <dlehman(a)redhat.com>
With this flag the method will recursively clear a device without
removing it. This is the same behavior it has always had for disks.
---
blivet/devicetree.py | 5 +++--
blivet/populator/populator.py | 7 ++-----
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index a016edd..8d48a30 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -204,11 +204,12 @@ def _remove_device(self, dev, force=None, modparent=True):
dev.name,
dev.id)
- def recursive_remove(self, device, actions=True):
+ def recursive_remove(self, device, actions=True, remove_device=True):
""" Remove a device after removing its dependent devices.
:param :class:`~.devices.StorageDevice` device: the device to remove
:keyword bool actions: whether to schedule actions for the removal
+ :keyword bool remove_device: whether to remove the root device
If the device is not a leaf, all of its dependents are removed
recursively until it is a leaf device. At that point the device is
@@ -249,7 +250,7 @@ def recursive_remove(self, device, actions=True):
else:
device.format = None
- if not device.is_disk:
+ if remove_device and not device.is_disk:
if actions:
self.actions.add(ActionDestroyDevice(device))
else:
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index a72619a..f4e9a88 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -236,13 +236,10 @@ def _clear_new_multipath_member(self, device):
return
# newly added device (eg iSCSI) could make this one a multipath member
- if device.format and device.format.type != "multipath_member":
+ if device.format.type != "multipath_member":
log.debug("%s newly detected as multipath member, dropping old format and removing kids", device.name)
# remove children from tree so that we don't stumble upon them later
- for child in device.children:
- self.recursive_remove(child, actions=False)
-
- device.format = None
+ self.recursive_remove(device, actions=False, remove_device=False)
def _mark_readonly_device(self, info, device):
# If this device is read-only, mark it as such now.
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/6f5d3ffd2f2b4253222239c564f0ca…
From: David Lehman <dlehman(a)redhat.com>
There are several such mechanisms being employed elsewhere in blivet
and even in the lvm tools themselves. This should not be needed anymore.
---
blivet/formats/lvmpv.py | 6 ------
1 file changed, 6 deletions(-)
diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
index f0031ef..bc82612 100644
--- a/blivet/formats/lvmpv.py
+++ b/blivet/formats/lvmpv.py
@@ -117,12 +117,6 @@ def _create(self, **kwargs):
# Consider use of -Z|--zero
# -f|--force or -y|--yes may be required
-
- # lvm has issues with persistence of metadata, so here comes the
- # hammer...
- # XXX This format doesn't exist yet, so bypass the precondition checking
- # for destroy by calling _destroy directly.
- DeviceFormat._destroy(self, **kwargs)
blockdev.lvm.pvscan(self.device)
blockdev.lvm.pvcreate(self.device, data_alignment=self.data_alignment)
blockdev.lvm.pvscan(self.device)
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/743016b1a729513bb331d63344fee5…
From: David Lehman <dlehman(a)redhat.com>
libparted's clobber does not remove a protective MBR, which makes it
useless for our purposes.
---
blivet/formats/disklabel.py | 6 ------
1 file changed, 6 deletions(-)
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index 9ea89a3..093ba24 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -243,12 +243,6 @@ def _create(self, **kwargs):
# other problems.
self.commit()
- def _destroy(self, **kwargs):
- """ Wipe the disklabel from the device. """
- log_method_call(self, device=self.device,
- type=self.type, status=self.status)
- self.parted_device.clobber()
-
def commit(self):
""" Commit the current partition table to disk and notify the OS. """
log_method_call(self, device=self.device,
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/d096eb5db630ef8348d4a043771da2…
From: David Lehman <dlehman(a)redhat.com>
That includes any actions related by way of containers, too.
---
blivet/devicetree.py | 51 ++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 11 deletions(-)
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 7dc9009..a016edd 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -375,6 +375,45 @@ def get_related_disks(self, disk):
return set(d for dep in self.get_dependent_devices(disk, hidden=True)
for d in dep.disks)
+ def get_disk_actions(self, disks):
+ """ Return a list of actions related to the specified disk.
+
+ :keyword disk: list of disks
+ :type disk: list of :class:`~.devices.StorageDevices`
+ :returns: list of related actions
+ :rtype: list of :class:`~.deviceaction.DeviceAction`
+
+ This includes all actions on the specified disks, plus all actions
+ on disks that are in any way connected to the specified disk via
+ container devices.
+ """
+ # This is different from getRelatedDisks in that we are finding disks
+ # related by any action -- not just the current state of the devicetree.
+ related_disks = set()
+ for action in self.actions:
+ if any(action.device.depends_on(d) for d in disks):
+ related_disks.update(action.device.disks)
+
+ # now related_disks could be a superset of disks, so go through and
+ # build a list of actions related to any disk in related_disks
+ # Note that this list preserves the ordering of the action list.
+ related_actions = [a for a in self.actions
+ if set(a.device.disks).intersection(related_disks)]
+ return related_actions
+
+ def cancel_disk_actions(self, disks):
+ """ Cancel all actions related to the specified disk.
+
+ :keyword disk: list of disks
+ :type disk: list of :class:`~.devices.StorageDevices`
+
+ This includes actions related directly and indirectly (via container
+ membership, for example).
+ """
+ actions = self.get_disk_actions(disks)
+ for action in reversed(actions):
+ self.actions.remove(action)
+
#
# Device search by property
#
@@ -819,17 +858,7 @@ def hide(self, device):
if device.is_disk:
# Cancel all actions on this disk and any disk related by way of an
# aggregate/container device (eg: lvm volume group).
- disks = [device]
- related_actions = [a for a in self._actions
- if a.device.depends_on(device)]
- for related_device in (a.device for a in related_actions):
- disks.extend(related_device.disks)
-
- disks = set(disks)
- cancel = [a for a in self._actions
- if set(a.device.disks).intersection(disks)]
- for action in reversed(cancel):
- self.actions.remove(action)
+ self.cancel_disk_actions(device)
for d in device.children:
self.hide(d)
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/acb3b576314e3da9cf7592c3e034cb…