From caa4b8ab53c8f26d8506d59b357b8fb7773ca147 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 9 Oct 2018 05:30:14 -0400 Subject: [PATCH 1/2] [partition] Document intention of new-style swap config --- .../partition/gui/PartitionViewStep.cpp | 35 +++++++++------ src/modules/partition/partition.conf | 43 +++++++++++-------- 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 6ad1a6c77..608ca0d22 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -487,25 +487,36 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) gs->insert( "efiSystemPartition", QStringLiteral( "/boot/efi" ) ); } + // SWAP SETTINGS + // + // This is a bit convoluted because there's legacy settings to handle as well + // as the new-style list of choices, with mapping back-and-forth. + if ( configurationMap.contains( "userSwapChoices" ) && + ( configurationMap.contains( "ensureSuspendToDisk" ) || configurationMap.contains( "neverCreateSwap" ) ) ) + cError() << "Partition-module configuration mixes old- and new-style swap settings."; + + bool ensureSuspendToDisk = true; + if ( configurationMap.contains( "ensureSuspendToDisk" ) ) + cWarning() << "Partition-module setting *ensureSuspendToDisk* is deprecated."; if ( configurationMap.contains( "ensureSuspendToDisk" ) && configurationMap.value( "ensureSuspendToDisk" ).type() == QVariant::Bool ) - { - gs->insert( "ensureSuspendToDisk", configurationMap.value( "ensureSuspendToDisk" ).toBool() ); - } + ensureSuspendToDisk = configurationMap.value( "ensureSuspendToDisk" ).toBool(); else - { - gs->insert( "ensureSuspendToDisk", true ); - } + ensureSuspendToDisk = true; + bool neverCreateSwap = false; + if ( configurationMap.contains( "neverCreateSwap" ) ) + cWarning() << "Partition-module setting *neverCreateSwap* is deprecated."; if ( configurationMap.contains( "neverCreateSwap" ) && configurationMap.value( "neverCreateSwap" ).type() == QVariant::Bool ) - { - gs->insert( "neverCreateSwap", configurationMap.value( "neverCreateSwap" ).toBool() ); - } + neverCreateSwap = configurationMap.value( "neverCreateSwap" ).toBool(); else - { - gs->insert( "neverCreateSwap", false ); - } + neverCreateSwap = false; + + // These gs settings seem to be unused (in upstream Calamares) outside of + // the partition module itself. + gs->insert( "ensureSuspendToDisk", ensureSuspendToDisk ); + gs->insert( "neverCreateSwap", neverCreateSwap ); if ( configurationMap.contains( "drawNestedPartitions" ) && configurationMap.value( "drawNestedPartitions" ).type() == QVariant::Bool ) diff --git a/src/modules/partition/partition.conf b/src/modules/partition/partition.conf index 3e0ce5950..70d0ea17f 100644 --- a/src/modules/partition/partition.conf +++ b/src/modules/partition/partition.conf @@ -3,28 +3,37 @@ # etc.) use just /boot. efiSystemPartition: "/boot/efi" -# Make sure an autogenerated swap partition is big enough for hibernation in -# automated partitioning modes. Swap can be disabled through *neverCreateSwap*. +# In autogenerated partitioning, allow the user to select a swap size? +# If there is exactly one choice, no UI is presented, and the user +# cannot make a choice -- this setting is used. If there is more than +# one choice, a UI is presented. # -# - *neverCreateSwap* is true: no swap is created -# - *neverCreateSwap* is false (the default): swap is created, as follows: -# - *ensureSuspendToDisk* is true (default): Swap is always at least total -# memory size, and up to 4GiB RAM follows the rule-of-thumb 2 * memory; +# Legacy settings *neverCreateSwap* and *ensureSuspendToDisk* correspond +# to values of *userSwapChoices* as follows: +# - *neverCreateSwap* is true, means [none] +# - *neverCreateSwap* is false, *ensureSuspendToDisk* is false, [small] +# - *neverCreateSwap* is false, *ensureSuspendToDisk* is true, [suspend] +# +# Autogenerated swap sizes are as follows: +# - *suspend*: Swap is always at least total memory size, +# and up to 4GiB RAM follows the rule-of-thumb 2 * memory; # from 4GiB to 8 GiB it stays steady at 8GiB, and over 8 GiB memory # swap is the size of main memory. -# - *ensureSuspendToDisk* is false: Follows the rules above, but Swap is at +# - *small*: Follows the rules above, but Swap is at # most 8GiB, and no more than 10% of available disk. -# In both cases, a fudge factor (usually 10% extra) is applied so that there -# is some space for administrative overhead (e.g. 8 GiB swap will allocate -# 8.8GiB on disk in the end). -# -# Default is true. -ensureSuspendToDisk: true +# In both cases, a fudge factor (usually 10% extra) is applied so that there +# is some space for administrative overhead (e.g. 8 GiB swap will allocate +# 8.8GiB on disk in the end). +userSwapChoices: + - none # Create no swap, use no swap + # - reuse # Re-use existing swap, but don't create any + - small # Up to 4GB + - suspend # At least main memory size + # - file # To swap file instead of partition (unsupported right now) -# Never create swap partitions in automated partitioning modes. -# If this is true, ensureSuspendToDisk is ignored. -# Default is false. -neverCreateSwap: false +# LEGACY SETTINGS (these will generate a warning) +# ensureSuspendToDisk: true +# neverCreateSwap: false # Correctly draw nested (e.g. logical) partitions as such. drawNestedPartitions: false From 3d543e9063000e4e40ccd2d01a2f008c58162dfb Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 9 Oct 2018 05:46:12 -0400 Subject: [PATCH 2/2] [partition] Refactor to use current config-reading methods --- .../partition/gui/PartitionViewStep.cpp | 86 ++++--------------- 1 file changed, 18 insertions(+), 68 deletions(-) diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 608ca0d22..9e8a120a7 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -476,16 +476,10 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) // Copy the efiSystemPartition setting to the global storage. It is needed not only in // the EraseDiskPage, but also in the bootloader configuration modules (grub, bootloader). Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - if ( configurationMap.contains( "efiSystemPartition" ) && - configurationMap.value( "efiSystemPartition" ).type() == QVariant::String && - !configurationMap.value( "efiSystemPartition" ).toString().isEmpty() ) - { - gs->insert( "efiSystemPartition", configurationMap.value( "efiSystemPartition" ).toString() ); - } - else - { - gs->insert( "efiSystemPartition", QStringLiteral( "/boot/efi" ) ); - } + QString efiSP = CalamaresUtils::getString( configurationMap, "efiSystemPartition" ); + if ( efiSP.isEmpty() ) + efiSP = QStringLiteral( "/boot/efi" ); + gs->insert( "efiSystemPartition", efiSP ); // SWAP SETTINGS // @@ -495,78 +489,34 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) ( configurationMap.contains( "ensureSuspendToDisk" ) || configurationMap.contains( "neverCreateSwap" ) ) ) cError() << "Partition-module configuration mixes old- and new-style swap settings."; - bool ensureSuspendToDisk = true; if ( configurationMap.contains( "ensureSuspendToDisk" ) ) cWarning() << "Partition-module setting *ensureSuspendToDisk* is deprecated."; - if ( configurationMap.contains( "ensureSuspendToDisk" ) && - configurationMap.value( "ensureSuspendToDisk" ).type() == QVariant::Bool ) - ensureSuspendToDisk = configurationMap.value( "ensureSuspendToDisk" ).toBool(); - else - ensureSuspendToDisk = true; + bool ensureSuspendToDisk = CalamaresUtils::getBool( configurationMap, "ensureSuspendToDisk", true ); - bool neverCreateSwap = false; if ( configurationMap.contains( "neverCreateSwap" ) ) cWarning() << "Partition-module setting *neverCreateSwap* is deprecated."; - if ( configurationMap.contains( "neverCreateSwap" ) && - configurationMap.value( "neverCreateSwap" ).type() == QVariant::Bool ) - neverCreateSwap = configurationMap.value( "neverCreateSwap" ).toBool(); - else - neverCreateSwap = false; + bool neverCreateSwap = CalamaresUtils::getBool( configurationMap, "neverCreateSwap", false ); // These gs settings seem to be unused (in upstream Calamares) outside of // the partition module itself. gs->insert( "ensureSuspendToDisk", ensureSuspendToDisk ); gs->insert( "neverCreateSwap", neverCreateSwap ); - if ( configurationMap.contains( "drawNestedPartitions" ) && - configurationMap.value( "drawNestedPartitions" ).type() == QVariant::Bool ) - { - gs->insert( "drawNestedPartitions", - configurationMap.value( "drawNestedPartitions", false ).toBool() ); - } - else - { - gs->insert( "drawNestedPartitions", false ); - } + // OTHER SETTINGS + // + gs->insert( "drawNestedPartitions", CalamaresUtils::getBool( configurationMap, "drawNestedPartitions", false ) ); + gs->insert( "alwaysShowPartitionLabels", CalamaresUtils::getBool( configurationMap, "alwaysShowPartitionLabels", true ) ); + gs->insert( "enableLuksAutomatedPartitioning", CalamaresUtils::getBool( configurationMap, "enableLuksAutomatedPartitioning", true ) ); - if ( configurationMap.contains( "alwaysShowPartitionLabels" ) && - configurationMap.value( "alwaysShowPartitionLabels" ).type() == QVariant::Bool ) + QString defaultFS = CalamaresUtils::getString( configurationMap, "defaultFileSystemType" ); + if ( defaultFS.isEmpty() ) + defaultFS = QStringLiteral( "ext4" ); + if ( FileSystem::typeForName( defaultFS ) == FileSystem::Unknown ) { - gs->insert( "alwaysShowPartitionLabels", - configurationMap.value( "alwaysShowPartitionLabels", true ).toBool() ); - } - else - { - gs->insert( "alwaysShowPartitionLabels", true ); - } - - if ( configurationMap.contains( "defaultFileSystemType" ) && - configurationMap.value( "defaultFileSystemType" ).type() == QVariant::String && - !configurationMap.value( "defaultFileSystemType" ).toString().isEmpty() ) - { - QString typeString = configurationMap.value( "defaultFileSystemType" ).toString(); - gs->insert( "defaultFileSystemType", typeString ); - if ( FileSystem::typeForName( typeString ) == FileSystem::Unknown ) - { - cWarning() << "bad default filesystem configuration for partition module. Reverting to ext4 as default."; - gs->insert( "defaultFileSystemType", "ext4" ); - } - } - else - { - gs->insert( "defaultFileSystemType", QStringLiteral( "ext4" ) ); - } - - if ( configurationMap.contains( "enableLuksAutomatedPartitioning" ) && - configurationMap.value( "enableLuksAutomatedPartitioning" ).type() == QVariant::Bool ) - { - gs->insert( "enableLuksAutomatedPartitioning", - configurationMap.value( "enableLuksAutomatedPartitioning" ).toBool() ); - } - else - { - gs->insert( "enableLuksAutomatedPartitioning", true ); + cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << defaultFS << ") using ext4."; + defaultFS = QStringLiteral( "ext4" ); } + gs->insert( "defaultFileSystemType", defaultFS ); // Now that we have the config, we load the PartitionCoreModule in the background