Skip to content

Commit

Permalink
Fstab cleanup fix
Browse files Browse the repository at this point in the history
Formats with multiple layers (e.g. LUKS) were not handled properly in
fstab. This resulted in fstab entries not being properly cleaned from
fstab when destroy actions were executed. This fixes the issue by using
different variables with correct values based on action type.
  • Loading branch information
japokorn committed Feb 9, 2024
1 parent c55b3cc commit 205d7d1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion blivet/actionlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def process(self, callbacks=None, devices=None, fstab=None, dry_run=None):
# (device may not exist afterwards)
if not skip_fstab:
try:
entry = fstab.entry_from_device(action.device)
entry = fstab.entry_from_action(action)
except ValueError:
# this device should not be in fstab
bae_entry = None
Expand Down
47 changes: 44 additions & 3 deletions blivet/fstab.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,48 @@ def entry_from_device(self, device):
entry.spec = self._get_spec(device)
if entry.spec is None:
entry.spec = getattr(device, "fstab_spec", None)

entry.vfstype = device.format.type

return entry

def entry_from_action(self, action):
""" Generate FSTabEntry object based on given blivet Action
:keyword action: action to process
:type action: :class: `blivet.deviceaction.DeviceAction`
:returns: fstab entry object based on device processed by action
:rtype: :class: `FSTabEntry`
"""

if not action.is_format:
raise ValueError("""cannot generate fstab entry from action '%s' because
its type is not 'format'""" % action)

fmt = action.format
if action.is_destroy:
fmt = action.orig_format
if action.is_create:
fmt = action.device.format

entry = FSTabEntry()

entry.file = None
if fmt.mountable:
entry.file = fmt.mountpoint
elif fmt.type == "swap":
entry.file = "swap"
else:
raise ValueError("""cannot generate fstab entry from action '%s' because
it is neither mountable nor swap type""" % action)

entry.spec = self._get_spec(action.device)
if entry.spec is None:
entry.spec = getattr(action.device, "fstab_spec", None)

entry.vfstype = action.device.format.type

return entry

def read(self):
""" Read the fstab file from path stored in self.src_file. Resets currently loaded table contents.
"""
Expand Down Expand Up @@ -696,7 +733,11 @@ def _get_spec(self, device):
# Use "globally" set (on FSTabManager level) spec type otherwise

spec = None
spec_type = device.format.fstab.spec_type or self.spec_type

if hasattr(device.format, 'fstab') and device.format.fstab.spec_type:
spec_type = device.format.fstab.spec_type
else:
spec_type = self.spec_type

if spec_type == "LABEL" and device.format.label:
spec = "LABEL=%s" % device.format.label
Expand Down Expand Up @@ -737,7 +778,7 @@ def update(self, action, bae_entry):
# does not have UUID assigned yet, so we skip that one
return

if action.is_create and action.device.format.mountable:
if action.is_create and action.is_format and action.device.format.mountable:
# add the device to the fstab
# make sure it is not already present there
try:
Expand Down

0 comments on commit 205d7d1

Please sign in to comment.