From dee8779c2b2df70b854752494c6da26d4f12690d Mon Sep 17 00:00:00 2001 From: Radek Vykydal Date: Fri, 31 May 2024 13:55:19 +0200 Subject: [PATCH] Do not mark ancestors of device with source or stage2 as protected Resolves: RHEL-35701 I am not able to find any reason why we started to protect also ancestors of the devices in this case (ie disk in case of source on a partition). The change (marking also ancestors of protected devices as protected in general) was introduced during modularization of Payload. commit 93fdbff37171972632118c547a0afddd796ffa76 commit 26de57d311c53d3f1833375399e11e926d43cc90 commit 19703fc2ff6e5dfccc74fb45788a10847fd4452c commit 71dda920a75be5baad7d5b8a93f4f998701b168e The patch tries to limit the changes to the case of the issue. From what I was able to look at it seems that it should be OK not to include ancestors also in other cases. Cherry-picked from master commit 4779d5f4d24832a3465fa81184a0d64a1e77ff25 --- .../modules/storage/devicetree/model.py | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/pyanaconda/modules/storage/devicetree/model.py b/pyanaconda/modules/storage/devicetree/model.py index 084622080ca..258c6c2b378 100644 --- a/pyanaconda/modules/storage/devicetree/model.py +++ b/pyanaconda/modules/storage/devicetree/model.py @@ -285,6 +285,7 @@ def _mark_protected_devices(self): identify protected devices. """ protected = [] + protected_with_ancestors = [] # Resolve the protected device specs to devices. for spec in self.protected_devices: @@ -306,7 +307,7 @@ def _mark_protected_devices(self): if live_device: log.debug("Resolved live device to %s.", live_device.name) - protected.append(live_device) + protected_with_ancestors.append(live_device) # Find the backing device of a stage2 source and its parents. source_device = find_backing_device(self.devicetree, DRACUT_REPO_DIR) @@ -319,16 +320,20 @@ def _mark_protected_devices(self): # storage disks as ignored so they are protected from teardown. # Here we protect also cdrom devices from tearing down that, in case of # cdroms, involves unmounting which is undesirable (see bug #1671713). - protected.extend(dev for dev in self.devicetree.devices if dev.type == "cdrom") + protected_with_ancestors.extend(dev for dev in self.devicetree.devices + if dev.type == "cdrom") # Protect also all devices with an iso9660 file system. It will protect # NVDIMM devices that can be used only as an installation source anyway # (see the bug #1856264). - protected.extend(dev for dev in self.devicetree.devices if dev.format.type == "iso9660") + protected_with_ancestors.extend(dev for dev in self.devicetree.devices + if dev.format.type == "iso9660") # Mark the collected devices as protected. for dev in protected: self._mark_protected_device(dev) + for dev in protected_with_ancestors: + self._mark_protected_device(dev, include_ancestors=True) def protect_devices(self, protected_names): """Protect given devices. @@ -353,23 +358,31 @@ def protect_devices(self, protected_names): # Update the list. self.protected_devices = protected_names - def _mark_protected_device(self, device): + def _mark_protected_device(self, device, include_ancestors=False): """Mark a device and its ancestors as protected.""" if not device: return - for d in device.ancestors: - log.debug("Marking device %s as protected.", d.name) - d.protected = True + device.protected = True + log.debug("Marking device %s as protected.", device.name) + if include_ancestors: + for d in device.ancestors: + log.debug("Marking ancestor %s of device %s as protected.", + d.name, device.name) + d.protected = True - def _mark_unprotected_device(self, device): + def _mark_unprotected_device(self, device, include_ancestors=False): """Mark a device and its ancestors as unprotected.""" if not device: return - for d in device.ancestors: - log.debug("Marking device %s as unprotected.", d.name) - d.protected = False + device.protected = False + log.debug("Marking device %s as unprotected.", device.name) + if include_ancestors: + for d in device.ancestors: + log.debug("Marking ancestor %s of device %s as unprotected.", + d.name, device.name) + d.protected = False @property def usable_disks(self):