From 3531896892da84a60723fb98ca1d58805505d290 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 6 Jul 2021 15:31:00 +0200 Subject: [PATCH] [mount] Factor out the default btrfs configuration --- src/modules/mount/main.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/modules/mount/main.py b/src/modules/mount/main.py index 5e5233935..8f019f1a3 100644 --- a/src/modules/mount/main.py +++ b/src/modules/mount/main.py @@ -29,6 +29,24 @@ _ = gettext.translation("calamares-python", def pretty_name(): return _("Mounting partitions.") + +def get_btrfs_subvolumes(): + """ + Gets the job-configuration for btrfs subvolumes, or if there is + none given, returns a default configuration that matches + the setup (/ and /home) from before configurability was introduced. + """ + btrfs_subvolumes = libcalamares.job.configuration.get("btrfsSubvolumes", None) + # Warn if there's no configuration at all, and empty configurations are + # replaced by a simple root-only layout. + if btrfs_subvolumes is None: + libcalamares.utils.warning("No configuration for btrfsSubvolumes") + if not btrfs_subvolumes: + btrfs_subvolumes = [ dict(mountPoint="/", subvolume="/@") ] + + return btrfs_subvolumes + + def mount_partition(root_mount_point, partition, partitions): """ Do a single mount of @p partition inside @p root_mount_point. @@ -74,13 +92,7 @@ def mount_partition(root_mount_point, partition, partitions): # Special handling for btrfs subvolumes. Create the subvolumes listed in mount.conf if fstype == "btrfs" and partition["mountPoint"] == '/': # Root has been mounted to btrfs volume -> create subvolumes from configuration - btrfs_subvolumes = libcalamares.job.configuration.get("btrfsSubvolumes", None) - # Warn if there's no configuration at all, and empty configurations are - # replaced by a simple root-only layout. - if btrfs_subvolumes is None: - libcalamares.utils.warning("No configuration for btrfsSubvolumes") - if not btrfs_subvolumes: - btrfs_subvolumes = [ dict(mountPoint="/", subvolume="/@") ] + btrfs_subvolumes = get_btrfs_subvolumes() subvolume_mountpoints = [d['mountPoint'] for d in btrfs_subvolumes] # Check if listed mountpoints besides / are already present and don't create subvolume for those