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

Fstab support (rebased to 3.9) #1119

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/anaconda_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
podman run -i --rm -v ./blivet:/blivet:z -v ./anaconda:/anaconda:z quay.io/rhinstaller/anaconda-ci:$TARGET_BRANCH sh -c " \
set -xe; \
dnf remove -y python3-blivet; \
dnf install -y python3-blockdev libblockdev-plugins-all python3-bytesize libbytesize python3-pyparted parted libselinux-python3; \
dnf install -y python3-blockdev libblockdev-plugins-all python3-bytesize libbytesize python3-pyparted python3-libmount parted libselinux-python3; \
cd /blivet; \
python3 ./setup.py install; \
cd /anaconda; \
Expand Down
19 changes: 18 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 @@ -285,7 +286,19 @@ def process(self, callbacks=None, devices=None, dry_run=None):
if dry_run:
continue

# get (b)efore (a)ction.(e)xecute fstab entry
# (device may not exist afterwards)
if fstab is not None:
try:
entry = fstab.entry_from_device(action.device)
except ValueError:
# this device should not be in fstab
bae_entry = None
else:
bae_entry = fstab.find_entry(entry=entry)

with blivet_lock:

try:
action.execute(callbacks)
except DiskLabelCommitError:
Expand Down Expand Up @@ -315,4 +328,8 @@ def process(self, callbacks=None, devices=None, dry_run=None):
self._completed_actions.append(self._actions.pop(0))
_callbacks.action_executed(action=action)

if fstab is not None:
fstab.update(action, bae_entry)
fstab.write()

self._post_process(devices=devices)
13 changes: 12 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 All @@ -55,6 +56,9 @@
log = logging.getLogger("blivet")


FSTAB_PATH = "/etc/fstab"


@six.add_metaclass(SynchronizedMeta)
class Blivet(object):

Expand All @@ -71,6 +75,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=FSTAB_PATH, dest_file=None)

self._short_product_name = 'blivet'

self._next_id = 0
Expand Down Expand Up @@ -111,7 +119,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 +150,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
11 changes: 10 additions & 1 deletion blivet/formats/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from . import DeviceFormat, register_device_format
from .. import util
from ..flags import flags
from ..fstab import FSTabOptions
from ..storage_log import log_exception_info, log_method_call
from .. import arch
from ..size import Size, ROUND_UP
Expand Down Expand Up @@ -91,7 +92,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 @@ -120,6 +122,8 @@ def __init__(self, **kwargs):

DeviceFormat.__init__(self, **kwargs)

self.fstab = FSTabOptions()

# Create task objects
self._fsck = self._fsck_class(self)
self._mkfs = self._mkfs_class(self)
Expand Down Expand Up @@ -645,6 +649,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
Loading