Skip to content

Commit

Permalink
Merge pull request #5811 from KKoukiou/pr-5687-el10
Browse files Browse the repository at this point in the history
Do not mark ancestors of device with source or stage2 as protected
  • Loading branch information
M4rtinK authored Aug 15, 2024
2 parents 97e032a + dee8779 commit a784b46
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions pyanaconda/modules/storage/devicetree/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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.
Expand All @@ -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):
Expand Down

0 comments on commit a784b46

Please sign in to comment.