Skip to content

Commit

Permalink
Fstab support
Browse files Browse the repository at this point in the history
 - added support for blivet to directly modify fstab based
on blivet actions
 - added tests and unit tests
  • Loading branch information
japokorn committed Oct 23, 2023
1 parent 57f1382 commit 3258334
Show file tree
Hide file tree
Showing 7 changed files with 587 additions and 3 deletions.
8 changes: 7 additions & 1 deletion blivet/actionlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,13 @@ def _post_process(self, devices=None):
partition.parted_partition = pdisk.getPartitionByPath(partition.path)

@with_flag("processing")
def process(self, callbacks=None, devices=None, dry_run=None):
def process(self, callbacks=None, devices=None, fstab=None, dry_run=None):
"""
Execute all registered actions.
:param callbacks: callbacks to be invoked when actions are executed
:param devices: a list of all devices current in the devicetree
:param fstab: FSTabManagerObject tied to blivet, if None fstab file will not be modified
:type callbacks: :class:`~.callbacks.DoItCallbacks`
"""
Expand All @@ -286,6 +287,7 @@ def process(self, callbacks=None, devices=None, dry_run=None):
continue

with blivet_lock:

try:
action.execute(callbacks)
except DiskLabelCommitError:
Expand All @@ -312,6 +314,10 @@ def process(self, callbacks=None, devices=None, dry_run=None):
device.update_name()
device.format.device = device.path

if fstab is not None:
fstab.update(devices)
fstab.write()

self._completed_actions.append(self._actions.pop(0))
_callbacks.action_executed(action=action)

Expand Down
10 changes: 9 additions & 1 deletion blivet/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from .errors import StorageError, DependencyError
from .size import Size
from .devicetree import DeviceTree
from .fstab import FSTabManager
from .formats import get_default_filesystem_type
from .flags import flags
from .formats import get_format
Expand Down Expand Up @@ -71,6 +72,10 @@ def __init__(self):
self.size_sets = []
self.set_default_fstype(get_default_filesystem_type())

# fstab write location purposedly set to None. It has to be overriden
# manually when using blivet.
self.fstab = FSTabManager(src_file="/etc/fstab", dest_file=None)

self._short_product_name = 'blivet'

self._next_id = 0
Expand Down Expand Up @@ -111,7 +116,8 @@ def do_it(self, callbacks=None):
"""

self.devicetree.actions.process(callbacks=callbacks, devices=self.devices)
self.devicetree.actions.process(callbacks=callbacks, devices=self.devices, fstab=self.fstab)
self.fstab.read()

@property
def next_id(self):
Expand Down Expand Up @@ -141,6 +147,8 @@ def reset(self, cleanup_only=False):
self.edd_dict = get_edd_dict(self.partitioned)
self.devicetree.edd_dict = self.edd_dict

self.fstab.read()

if flags.include_nodev:
self.devicetree.handle_nodev_filesystems()

Expand Down
8 changes: 7 additions & 1 deletion blivet/formats/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class FS(DeviceFormat):
# support for resize: grow/shrink, online/offline
_resize_support = 0

config_actions_map = {"label": "write_label"}
config_actions_map = {"label": "write_label",
"mountpoint": "change_mountpoint"}

def __init__(self, **kwargs):
"""
Expand Down Expand Up @@ -645,6 +646,11 @@ def _teardown(self, **kwargs):

udev.settle()

def change_mountpoint(self, dry_run=False):
# This function is intentionally left blank. Mountpoint change utilizes
# only the generic part of this code branch
pass

def read_label(self):
"""Read this filesystem's label.
Expand Down
Loading

0 comments on commit 3258334

Please sign in to comment.