From 51b69463bcdef5ca31ba096de897f11113d1e64c Mon Sep 17 00:00:00 2001 From: Radek Vykydal Date: Wed, 18 Sep 2024 14:38:52 +0200 Subject: [PATCH] home reuse: check autopartitioning scheme against reused mountpoints --- .../automatic/automatic_partitioning.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/pyanaconda/modules/storage/partitioning/automatic/automatic_partitioning.py b/pyanaconda/modules/storage/partitioning/automatic/automatic_partitioning.py index c34d40fb1c7..f7c6b7a4bcf 100644 --- a/pyanaconda/modules/storage/partitioning/automatic/automatic_partitioning.py +++ b/pyanaconda/modules/storage/partitioning/automatic/automatic_partitioning.py @@ -33,6 +33,8 @@ get_default_partitioning, get_part_spec, get_disks_for_implicit_partitions from pyanaconda.modules.storage.platform import platform from pyanaconda.core.storage import suggest_swap_size +from pykickstart.constants import AUTOPART_TYPE_BTRFS, AUTOPART_TYPE_LVM, \ + AUTOPART_TYPE_LVM_THINP, AUTOPART_TYPE_PLAIN log = get_module_logger(__name__) @@ -142,8 +144,8 @@ def _clear_partitions(self, storage): storage.roots = find_existing_installations(storage.devicetree) log.debug("storage.roots.mounts %s", [root.mounts for root in storage.roots]) - # TODO check that partitioning scheme matches - do it earlier in the - # check but also here? + # Check that partitioning scheme matches + self._check_reused_scheme(storage, self._request) for mountpoint in self._request.removed_mount_points: if mountpoint == "bootloader": @@ -153,6 +155,21 @@ def _clear_partitions(self, storage): for mountpoint in self._request.reformatted_mount_points: self._reformat_mountpoint(storage, mountpoint) + def _check_reused_scheme(self, storage, request): + scheme = request.partitioning_scheme + required_home_device_type = { + AUTOPART_TYPE_BTRFS: "btrfs subvolume", + AUTOPART_TYPE_LVM: "lvmlv", + AUTOPART_TYPE_LVM_THINP: "lvmthinlv", + AUTOPART_TYPE_PLAIN: "partition", + } + for mountpoint in request.reused_mount_points: + device = self._get_mountpoint_device(storage, mountpoint) + if device.type != required_home_device_type[scheme]: + raise StorageError(_("Reused device type '{}' of mountpoint '{}' does not " + "match the required automatic partitioning scheme.") + .format(device.type, mountpoint)) + def _schedule_reused_mountpoint(self, storage, mountpoint): device = self._get_mountpoint_device(storage, mountpoint) log.debug("add mount device request for reused mountpoint: %s device: %s",