From b5dba9108c626ecc46b444f0b70e0d62a3e76bf0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 2 Nov 2021 15:33:34 +0100 Subject: [PATCH] [partition] Check for LVs that will be formatted, don't close them - when (manually) using an existing LV, it shouldn't be closed prior to formatting, since that kills the volume and then the path (/dev/myvg/mylv) no longer exists. Then creating the filesysytem on that device path fails. --- .../partition/core/PartitionCoreModule.cpp | 42 ++++++++++++++++++- .../partition/core/PartitionCoreModule.h | 3 +- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 0f53ba413..f9a4706c4 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -580,6 +580,42 @@ PartitionCoreModule::setPartitionFlags( Device* device, Partition* partition, Pa PartitionInfo::setFlags( partition, flags ); } +STATICTEST QStringList +findEssentialLVs( const QList< PartitionCoreModule::DeviceInfo* >& infos ) +{ + QStringList doNotClose; + cDebug() << "Checking LVM use on" << infos.count() << "devices"; + for ( const auto* info : infos ) + { + if ( info->device->type() != Device::Type::LVM_Device ) + { + continue; + } + + for ( const auto& j : qAsConst( info->jobs() ) ) + { + FormatPartitionJob* format = dynamic_cast< FormatPartitionJob* >( j.data() ); + if ( format ) + { + // device->deviceNode() is /dev/ + // partition()->partitionPath() is /dev// + const auto* partition = format->partition(); + const QString partPath = partition->partitionPath(); + const QString devicePath = info->device->deviceNode() + '/'; + const bool isLvm = partition->roles().has( PartitionRole::Lvm_Lv ); + if ( isLvm && partPath.startsWith( devicePath ) ) + { + cDebug() << Logger::SubEntry << partPath + << "is an essential LV filesystem=" << partition->fileSystem().type(); + QString lvName = partPath.right( partPath.length() - devicePath.length() ); + doNotClose.append( info->device->name() + '-' + lvName ); + } + } + } + } + return doNotClose; +} + Calamares::JobList PartitionCoreModule::jobs( const Config* config ) const { @@ -604,11 +640,15 @@ PartitionCoreModule::jobs( const Config* config ) const lst << automountControl; lst << Calamares::job_ptr( new ClearTempMountsJob() ); + const QStringList doNotClose = findEssentialLVs( m_deviceInfos ); + for ( const auto* info : m_deviceInfos ) { if ( info->isDirty() ) { - lst << Calamares::job_ptr( new ClearMountsJob( info->device.data() ) ); + auto* job = new ClearMountsJob( info->device.data() ); + job->setMapperExceptions( doNotClose ); + lst << Calamares::job_ptr( job ); } } diff --git a/src/modules/partition/core/PartitionCoreModule.h b/src/modules/partition/core/PartitionCoreModule.h index 693569310..eae16f0be 100644 --- a/src/modules/partition/core/PartitionCoreModule.h +++ b/src/modules/partition/core/PartitionCoreModule.h @@ -84,6 +84,8 @@ public: PartitionModel* partitionModelAfter; }; + struct DeviceInfo; + PartitionCoreModule( QObject* parent = nullptr ); ~PartitionCoreModule() override; @@ -239,7 +241,6 @@ Q_SIGNALS: void deviceReverted( Device* device ); private: - struct DeviceInfo; void refreshAfterModelChange(); void doInit();