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

feat: Support for creating volumes without a FS #400

Merged
merged 1 commit into from
Nov 9, 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe this should be "unconfigured"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how we note destructive operations elsewhere, but seems to me like we should say something like **WARNING**: Using "unconfigured" on an existing filesystem will remove the filesystem.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The correct value is actually 'unformatted' in the code. I made sure the value is unified.
I have also added a warning note into the README.

__WARNING__: Using "unformatted" file system type on an existing filesystem
is a destructive operation and will destroy all data on the volume.

- `fs_label`

Expand Down
15 changes: 11 additions & 4 deletions library/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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:
Expand All @@ -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. """
Expand Down
4 changes: 3 additions & 1 deletion tests/test-verify-volume-fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/tests_change_fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading