mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-27 09:25:36 -04:00
Merge branch 'master' of https://github.com/cjlcarvalho/calamares into lvm-update
This commit is contained in:
commit
5d5feeb0ab
26 changed files with 1736 additions and 13 deletions
|
@ -34,10 +34,14 @@
|
|||
#include "jobs/ClearTempMountsJob.h"
|
||||
#include "jobs/CreatePartitionJob.h"
|
||||
#include "jobs/CreatePartitionTableJob.h"
|
||||
#include "jobs/CreateVolumeGroupJob.h"
|
||||
#include "jobs/DeactivateVolumeGroupJob.h"
|
||||
#include "jobs/DeletePartitionJob.h"
|
||||
#include "jobs/FillGlobalStorageJob.h"
|
||||
#include "jobs/FormatPartitionJob.h"
|
||||
#include "jobs/RemoveVolumeGroupJob.h"
|
||||
#include "jobs/ResizePartitionJob.h"
|
||||
#include "jobs/ResizeVolumeGroupJob.h"
|
||||
#include "jobs/SetPartitionFlagsJob.h"
|
||||
|
||||
#include "Typedefs.h"
|
||||
|
@ -45,10 +49,13 @@
|
|||
|
||||
// KPMcore
|
||||
#include <kpmcore/core/device.h>
|
||||
#include <kpmcore/core/lvmdevice.h>
|
||||
#include <kpmcore/core/partition.h>
|
||||
#include <kpmcore/backend/corebackend.h>
|
||||
#include <kpmcore/backend/corebackendmanager.h>
|
||||
#include <kpmcore/fs/filesystemfactory.h>
|
||||
#include <kpmcore/fs/luks.h>
|
||||
#include <kpmcore/fs/lvm2_pv.h>
|
||||
|
||||
// Qt
|
||||
#include <QStandardItemModel>
|
||||
|
@ -62,6 +69,7 @@ PartitionCoreModule::DeviceInfo::DeviceInfo( Device* _device )
|
|||
: device( _device )
|
||||
, partitionModel( new PartitionModel )
|
||||
, immutableDevice( new Device( *_device ) )
|
||||
, isAvailable( true )
|
||||
{}
|
||||
|
||||
PartitionCoreModule::DeviceInfo::~DeviceInfo()
|
||||
|
@ -178,6 +186,8 @@ PartitionCoreModule::doInit()
|
|||
|
||||
m_bootLoaderModel->init( bootLoaderDevices );
|
||||
|
||||
scanForLVMPVs();
|
||||
|
||||
//FIXME: this should be removed in favor of
|
||||
// proper KPM support for EFI
|
||||
if ( PartUtils::isEfiSystem() )
|
||||
|
@ -265,6 +275,77 @@ PartitionCoreModule::createPartition( Device* device,
|
|||
refresh();
|
||||
}
|
||||
|
||||
void
|
||||
PartitionCoreModule::createVolumeGroup( QString &vgName,
|
||||
QVector< const Partition* > pvList,
|
||||
qint32 peSize )
|
||||
{
|
||||
// Appending '_' character in case of repeated VG name
|
||||
while ( hasVGwithThisName( vgName ) )
|
||||
vgName.append('_');
|
||||
|
||||
CreateVolumeGroupJob* job = new CreateVolumeGroupJob( vgName, pvList, peSize );
|
||||
job->updatePreview();
|
||||
|
||||
LvmDevice* device = new LvmDevice(vgName);
|
||||
|
||||
for ( const Partition* p : pvList )
|
||||
device->physicalVolumes() << p;
|
||||
|
||||
DeviceInfo* deviceInfo = new DeviceInfo( device );
|
||||
|
||||
deviceInfo->partitionModel->init( device, osproberEntries() );
|
||||
|
||||
m_deviceModel->addDevice( device );
|
||||
|
||||
m_deviceInfos << deviceInfo;
|
||||
deviceInfo->jobs << Calamares::job_ptr( job );
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void
|
||||
PartitionCoreModule::resizeVolumeGroup( LvmDevice *device, QVector< const Partition* >& pvList )
|
||||
{
|
||||
DeviceInfo* deviceInfo = infoForDevice( device );
|
||||
Q_ASSERT( deviceInfo );
|
||||
|
||||
ResizeVolumeGroupJob* job = new ResizeVolumeGroupJob( device, pvList );
|
||||
|
||||
deviceInfo->jobs << Calamares::job_ptr( job );
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void
|
||||
PartitionCoreModule::deactivateVolumeGroup( LvmDevice *device )
|
||||
{
|
||||
DeviceInfo* deviceInfo = infoForDevice( device );
|
||||
Q_ASSERT( deviceInfo );
|
||||
|
||||
deviceInfo->isAvailable = false;
|
||||
|
||||
DeactivateVolumeGroupJob* job = new DeactivateVolumeGroupJob( device );
|
||||
|
||||
// DeactivateVolumeGroupJob needs to be immediately called
|
||||
job->exec();
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void
|
||||
PartitionCoreModule::removeVolumeGroup( LvmDevice *device )
|
||||
{
|
||||
DeviceInfo* deviceInfo = infoForDevice( device );
|
||||
Q_ASSERT( deviceInfo );
|
||||
|
||||
RemoveVolumeGroupJob* job = new RemoveVolumeGroupJob( device );
|
||||
|
||||
deviceInfo->jobs << Calamares::job_ptr( job );
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void
|
||||
PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
||||
{
|
||||
|
@ -434,6 +515,37 @@ PartitionCoreModule::efiSystemPartitions() const
|
|||
return m_efiSystemPartitions;
|
||||
}
|
||||
|
||||
QVector< const Partition* >
|
||||
PartitionCoreModule::lvmPVs() const
|
||||
{
|
||||
return m_lvmPVs;
|
||||
}
|
||||
|
||||
bool
|
||||
PartitionCoreModule::hasVGwithThisName( const QString& name ) const
|
||||
{
|
||||
for ( DeviceInfo* d : m_deviceInfos )
|
||||
if ( dynamic_cast<LvmDevice*>(d->device.data()) &&
|
||||
d->device.data()->name() == name)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
PartitionCoreModule::isInVG( const Partition *partition ) const
|
||||
{
|
||||
for ( DeviceInfo* d : m_deviceInfos )
|
||||
{
|
||||
LvmDevice* vg = dynamic_cast<LvmDevice*>( d->device.data() );
|
||||
|
||||
if ( vg && vg->physicalVolumes().contains( partition ))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
PartitionCoreModule::dumpQueue() const
|
||||
{
|
||||
|
@ -473,6 +585,8 @@ PartitionCoreModule::refresh()
|
|||
updateIsDirty();
|
||||
m_bootLoaderModel->update();
|
||||
|
||||
scanForLVMPVs();
|
||||
|
||||
//FIXME: this should be removed in favor of
|
||||
// proper KPM support for EFI
|
||||
if ( PartUtils::isEfiSystem() )
|
||||
|
@ -525,6 +639,80 @@ PartitionCoreModule::scanForEfiSystemPartitions()
|
|||
m_efiSystemPartitions = efiSystemPartitions;
|
||||
}
|
||||
|
||||
void
|
||||
PartitionCoreModule::scanForLVMPVs()
|
||||
{
|
||||
m_lvmPVs.clear();
|
||||
|
||||
QList< Device* > physicalDevices;
|
||||
QList< LvmDevice* > vgDevices;
|
||||
|
||||
for ( DeviceInfo* deviceInfo : m_deviceInfos )
|
||||
{
|
||||
if ( deviceInfo->device.data()->type() == Device::Type::Disk_Device)
|
||||
physicalDevices << deviceInfo->device.data();
|
||||
else if ( deviceInfo->device.data()->type() == Device::Type::LVM_Device )
|
||||
{
|
||||
LvmDevice* device = dynamic_cast<LvmDevice*>(deviceInfo->device.data());
|
||||
|
||||
// Restoring physical volume list
|
||||
device->physicalVolumes().clear();
|
||||
|
||||
vgDevices << device;
|
||||
}
|
||||
}
|
||||
|
||||
// Update LVM::pvList
|
||||
LvmDevice::scanSystemLVM( physicalDevices );
|
||||
|
||||
for ( auto p : LVM::pvList )
|
||||
{
|
||||
m_lvmPVs << p.partition().data();
|
||||
|
||||
for ( LvmDevice* device : vgDevices )
|
||||
if ( p.vgName() == device->name() )
|
||||
{
|
||||
// Adding scanned VG to PV list
|
||||
device->physicalVolumes() << p.partition();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for ( DeviceInfo* d : m_deviceInfos )
|
||||
{
|
||||
for ( auto job : d->jobs )
|
||||
{
|
||||
// Including new LVM PVs
|
||||
CreatePartitionJob* partJob = dynamic_cast<CreatePartitionJob*>( job.data() );
|
||||
if ( partJob )
|
||||
{
|
||||
Partition* p = partJob->partition();
|
||||
|
||||
if ( p->fileSystem().type() == FileSystem::Type::Lvm2_PV )
|
||||
m_lvmPVs << p;
|
||||
else if ( p->fileSystem().type() == FileSystem::Type::Luks )
|
||||
{
|
||||
// Encrypted LVM PVs
|
||||
FileSystem* innerFS = static_cast<const FS::luks*>(&p->fileSystem())->innerFS();
|
||||
|
||||
if ( innerFS && innerFS->type() == FileSystem::Type::Lvm2_PV )
|
||||
m_lvmPVs << p;
|
||||
}
|
||||
#ifdef WITH_KPMCOREGT33
|
||||
else if ( p->fileSystem().type() == FileSystem::Type::Luks2 )
|
||||
{
|
||||
// Encrypted LVM PVs
|
||||
FileSystem* innerFS = static_cast<const FS::luks*>(&p->fileSystem())->innerFS();
|
||||
|
||||
if ( innerFS && innerFS->type() == FileSystem::Type::Lvm2_PV )
|
||||
m_lvmPVs << p;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PartitionCoreModule::DeviceInfo*
|
||||
PartitionCoreModule::infoForDevice( const Device* device ) const
|
||||
{
|
||||
|
@ -574,8 +762,36 @@ PartitionCoreModule::revert()
|
|||
void
|
||||
PartitionCoreModule::revertAllDevices()
|
||||
{
|
||||
foreach ( DeviceInfo* devInfo, m_deviceInfos )
|
||||
revertDevice( devInfo->device.data() );
|
||||
for ( auto it = m_deviceInfos.begin(); it != m_deviceInfos.end(); )
|
||||
{
|
||||
// In new VGs device info, there will be always a CreateVolumeGroupJob as the first job in jobs list
|
||||
if ( dynamic_cast<LvmDevice*>( ( *it )->device.data() ) )
|
||||
{
|
||||
( *it )->isAvailable = true;
|
||||
|
||||
if ( !( *it )->jobs.empty() )
|
||||
{
|
||||
CreateVolumeGroupJob* vgJob = dynamic_cast<CreateVolumeGroupJob*>( ( *it )->jobs[0].data() );
|
||||
|
||||
if ( vgJob )
|
||||
{
|
||||
vgJob->undoPreview();
|
||||
|
||||
( *it )->forgetChanges();
|
||||
|
||||
m_deviceModel->removeDevice( ( *it )->device.data() );
|
||||
|
||||
it = m_deviceInfos.erase( it );
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
revertDevice( ( *it )->device.data() );
|
||||
++it;
|
||||
}
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
@ -585,6 +801,7 @@ PartitionCoreModule::revertDevice( Device* dev )
|
|||
{
|
||||
QMutexLocker locker( &m_revertMutex );
|
||||
DeviceInfo* devInfo = infoForDevice( dev );
|
||||
|
||||
if ( !devInfo )
|
||||
return;
|
||||
devInfo->forgetChanges();
|
||||
|
@ -596,8 +813,13 @@ PartitionCoreModule::revertDevice( Device* dev )
|
|||
m_deviceModel->swapDevice( dev, newDev );
|
||||
|
||||
QList< Device* > devices;
|
||||
foreach ( auto info, m_deviceInfos )
|
||||
devices.append( info->device.data() );
|
||||
for ( auto info : m_deviceInfos )
|
||||
{
|
||||
if ( info->device.data()->type() != Device::Type::Disk_Device )
|
||||
continue;
|
||||
else
|
||||
devices.append( info->device.data() );
|
||||
}
|
||||
|
||||
m_bootLoaderModel->init( devices );
|
||||
|
||||
|
@ -637,6 +859,16 @@ PartitionCoreModule::isDirty()
|
|||
return m_isDirty;
|
||||
}
|
||||
|
||||
bool
|
||||
PartitionCoreModule::isVGdeactivated( LvmDevice *device )
|
||||
{
|
||||
for ( DeviceInfo* deviceInfo : m_deviceInfos )
|
||||
if ( device == deviceInfo->device.data() && !deviceInfo->isAvailable )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QList< PartitionCoreModule::SummaryInfo >
|
||||
PartitionCoreModule::createSummaryInfo() const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue