Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not mark ancestors of device with source or stage2 as protected #5811

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading