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):