From c320742b0c9eb18a7713f5cce2486102361d6a70 Mon Sep 17 00:00:00 2001 From: Jan Pokorny Date: Fri, 27 Oct 2023 14:17:38 +0200 Subject: [PATCH] feat: Support for creating volumes without a FS Currently whenever volume is created without fs_type specification, a filesystem of default type (i.e. xfs) is automatically put on it. This change allows user to prevent FS creation by explicitly using "unformatted" value as a fs_type option. In the same manner it also allows to remove an existing FS. To be able to do that the safe mode has to be off. --- README.md | 3 +++ library/blivet.py | 15 +++++++++++---- tests/test-verify-volume-fs.yml | 4 +++- tests/tests_change_fs.yml | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e85817a2..3f6fa0fe 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,9 @@ variables: This indicates the desired file system type to use, e.g.: "xfs", "ext4", "swap". The default is determined according to the OS and release (currently `xfs` for all the supported systems). + Use "unformatted" if you do not want file system to be present. + __WARNING__: Using "unformatted" file system type on an existing filesystem + is a destructive operation and will destroy all data on the volume. - `fs_label` diff --git a/library/blivet.py b/library/blivet.py index 6b2b8673..db5103e6 100644 --- a/library/blivet.py +++ b/library/blivet.py @@ -20,7 +20,7 @@ description: - "WARNING: Do not use this module directly! It is only for role internal use." - "Module configures storage pools and volumes to match the state specified - in input parameters. It does not do any management of /etc/fstab entries." + in input parameters." options: pools: @@ -435,6 +435,11 @@ def _apply_defaults(self): def _get_format(self): """ Return a blivet.formats.DeviceFormat instance for this volume. """ + + if self._volume['fs_type'].lower() == 'unformatted': + # Do not create any fs when user explicitly said so + return None + fmt = get_format(self._volume['fs_type'], mountpoint=self._volume.get('mount_point'), label=self._volume['fs_label'], @@ -560,7 +565,8 @@ def _reformat(self): """ Schedule actions as needed to ensure the volume is formatted as specified. """ fmt = self._get_format() - if self._device.format.type == fmt.type: + if ((fmt is None and self._device.format.type is None) + or (fmt is not None and self._device.format.type == fmt.type)): # format is the same, no need to run reformatting dev_label = '' if self._device.format.label is None else self._device.format.label if dev_label != fmt.label: @@ -574,9 +580,10 @@ def _reformat(self): if self._device.format.status and (self._device.format.mountable or self._device.format.type == "swap"): self._device.format.teardown() - if not self._device.isleaf: + if not self._device.isleaf or fmt is None: self._blivet.devicetree.recursive_remove(self._device, remove_device=False) - self._blivet.format_device(self._device, fmt) + if fmt is not None: + self._blivet.format_device(self._device, fmt) def manage(self): """ Schedule actions to configure this volume according to the yaml input. """ diff --git a/tests/test-verify-volume-fs.yml b/tests/test-verify-volume-fs.yml index 5ec6bf9d..fc9078f6 100644 --- a/tests/test-verify-volume-fs.yml +++ b/tests/test-verify-volume-fs.yml @@ -3,7 +3,9 @@ - name: Verify fs type assert: that: storage_test_blkinfo.info[storage_test_volume._device].fstype == - storage_test_volume.fs_type + storage_test_volume.fs_type or + (storage_test_blkinfo.info[storage_test_volume._device].fstype | length + == 0 and storage_test_volume.fs_type == "unformatted") when: storage_test_volume.fs_type and _storage_test_volume_present # label diff --git a/tests/tests_change_fs.yml b/tests/tests_change_fs.yml index b2aae78f..a83bdb50 100644 --- a/tests/tests_change_fs.yml +++ b/tests/tests_change_fs.yml @@ -101,6 +101,22 @@ - name: Verify role results include_tasks: verify-role-results.yml + - name: Remove the FS + include_role: + name: linux-system-roles.storage + vars: + storage_pools: + - name: foo + disks: "{{ unused_disks }}" + volumes: + - name: test1 + size: "{{ volume_size }}" + fs_type: unformatted + + - name: Verify role results + include_tasks: verify-role-results.yml + + - name: Clean up include_role: name: linux-system-roles.storage