From 7b45793b60cf0bce74230a7f16194bbc4ad35d85 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 2 Nov 2021 15:26:25 +0100 Subject: [PATCH] [partition] Allow exceptions when closing /dev/mapper - some names should not be closed, like "control" - allow a list of names to be added which should not be closed --- src/modules/partition/jobs/ClearMountsJob.cpp | 8 ++++---- src/modules/partition/jobs/ClearMountsJob.h | 12 +++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/modules/partition/jobs/ClearMountsJob.cpp b/src/modules/partition/jobs/ClearMountsJob.cpp index cde4519a4..74a783d03 100644 --- a/src/modules/partition/jobs/ClearMountsJob.cpp +++ b/src/modules/partition/jobs/ClearMountsJob.cpp @@ -127,7 +127,7 @@ isFedoraSpecial( const QString& baseName ) * the list. */ STATICTEST QStringList -getCryptoDevices() +getCryptoDevices( const QStringList& mapperExceptions ) { QDir mapperDir( "/dev/mapper" ); const QFileInfoList fiList = mapperDir.entryInfoList( QDir::Files ); @@ -135,7 +135,7 @@ getCryptoDevices() for ( const QFileInfo& fi : fiList ) { QString baseName = fi.baseName(); - if ( isControl( baseName ) || isFedoraSpecial( baseName ) ) + if ( isControl( baseName ) || isFedoraSpecial( baseName ) || mapperExceptions.contains( baseName ) ) { continue; } @@ -371,11 +371,11 @@ ClearMountsJob::exec() CalamaresUtils::Partition::Syncer s; QList< MessageAndPath > goodNews; - apply( getCryptoDevices(), tryCryptoClose, goodNews ); + apply( getCryptoDevices( m_mapperExceptions ), tryCryptoClose, goodNews ); apply( getLVMVolumes(), tryUmount, goodNews ); apply( getPVGroups( deviceName ), tryVGDisable, goodNews ); - apply( getCryptoDevices(), tryCryptoClose, goodNews ); + apply( getCryptoDevices( m_mapperExceptions ), tryCryptoClose, goodNews ); apply( getPartitionsForDevice( deviceName ), tryUmount, goodNews ); apply( getSwapsForDevice( m_deviceNode ), tryClearSwap, goodNews ); diff --git a/src/modules/partition/jobs/ClearMountsJob.h b/src/modules/partition/jobs/ClearMountsJob.h index a49c07d3f..fb3aca1e4 100644 --- a/src/modules/partition/jobs/ClearMountsJob.h +++ b/src/modules/partition/jobs/ClearMountsJob.h @@ -23,8 +23,14 @@ class Device; * - physical volumes for LVM on the device are disabled * * In addition, regardless of device: - * - all /dev/mapper entries (crypto / LUKS) are closed + * - almost all(*) /dev/mapper entries (crypto / LUKS, also LVM) are closed * - all logical volumes for LVM are unmounted + * Exceptions to "all /dev/mapper" may be configured through + * the setMapperExceptions() method. Pass in names of mapper + * files that should not be closed (e.g. "myvg-mylv"). + * + * (*) Some exceptions always exist: /dev/mapper/control is never + * closed. /dev/mapper/live-* is never closed. * */ class ClearMountsJob : public Calamares::Job @@ -42,8 +48,12 @@ public: QString prettyStatusMessage() const override; Calamares::JobResult exec() override; + ///@brief Sets the list of exceptions (names) when closing /dev/mapper + void setMapperExceptions( const QStringList& names ) { m_mapperExceptions = names; } + private: const QString m_deviceNode; + QStringList m_mapperExceptions; }; #endif // CLEARMOUNTSJOB_H