[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.
This commit is contained in:
Adriaan de Groot 2021-11-02 15:33:34 +01:00
parent 7b45793b60
commit b5dba9108c
2 changed files with 43 additions and 2 deletions

View File

@ -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/<vg name>
// partition()->partitionPath() is /dev/<vg name>/<lv>
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 );
}
}

View File

@ -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();