From d15ce56c9703f2509fb55b3b497d66ede2c806d9 Mon Sep 17 00:00:00 2001 From: Caio Date: Mon, 4 Jun 2018 16:31:58 -0300 Subject: [PATCH] [partition] Initial implementation of VolumeGroupBaseDialog. --- src/modules/partition/CMakeLists.txt | 4 + .../partition/core/PartitionCoreModule.cpp | 48 +++++ .../partition/core/PartitionCoreModule.h | 6 + src/modules/partition/core/PartitionInfo.cpp | 4 + .../gui/ListPhysicalVolumeWidgetItem.cpp | 36 ++++ .../gui/ListPhysicalVolumeWidgetItem.h | 37 ++++ src/modules/partition/gui/PartitionPage.cpp | 18 ++ src/modules/partition/gui/PartitionPage.h | 1 + src/modules/partition/gui/PartitionPage.ui | 9 +- .../partition/gui/VolumeGroupBaseDialog.cpp | 42 ++++ .../partition/gui/VolumeGroupBaseDialog.h | 48 +++++ .../partition/gui/VolumeGroupBaseDialog.ui | 193 ++++++++++++++++++ .../partition/jobs/CreateVolumeGroupJob.cpp | 88 ++++++++ .../partition/jobs/CreateVolumeGroupJob.h | 47 +++++ 14 files changed, 580 insertions(+), 1 deletion(-) create mode 100644 src/modules/partition/gui/ListPhysicalVolumeWidgetItem.cpp create mode 100644 src/modules/partition/gui/ListPhysicalVolumeWidgetItem.h create mode 100644 src/modules/partition/gui/VolumeGroupBaseDialog.cpp create mode 100644 src/modules/partition/gui/VolumeGroupBaseDialog.h create mode 100644 src/modules/partition/gui/VolumeGroupBaseDialog.ui create mode 100644 src/modules/partition/jobs/CreateVolumeGroupJob.cpp create mode 100644 src/modules/partition/jobs/CreateVolumeGroupJob.h diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 156ff86f5..2f0e46bea 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -38,6 +38,7 @@ if ( KPMcore_FOUND ) gui/DeviceInfoWidget.cpp gui/EditExistingPartitionDialog.cpp gui/EncryptWidget.cpp + gui/ListPhysicalVolumeWidgetItem.cpp gui/PartitionPage.cpp gui/PartitionBarsView.cpp gui/PartitionLabelsView.cpp @@ -47,10 +48,12 @@ if ( KPMcore_FOUND ) gui/PrettyRadioButton.cpp gui/ScanningDialog.cpp gui/ReplaceWidget.cpp + gui/VolumeGroupBaseDialog.cpp jobs/ClearMountsJob.cpp jobs/ClearTempMountsJob.cpp jobs/CreatePartitionJob.cpp jobs/CreatePartitionTableJob.cpp + jobs/CreateVolumeGroupJob.cpp jobs/DeletePartitionJob.cpp jobs/FillGlobalStorageJob.cpp jobs/FormatPartitionJob.cpp @@ -65,6 +68,7 @@ if ( KPMcore_FOUND ) gui/EncryptWidget.ui gui/PartitionPage.ui gui/ReplaceWidget.ui + gui/VolumeGroupBaseDialog.ui LINK_PRIVATE_LIBRARIES kpmcore calamaresui diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 43ba33d7b..7229c8305 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -33,6 +33,7 @@ #include "jobs/ClearTempMountsJob.h" #include "jobs/CreatePartitionJob.h" #include "jobs/CreatePartitionTableJob.h" +#include "jobs/CreateVolumeGroupJob.h" #include "jobs/DeletePartitionJob.h" #include "jobs/FillGlobalStorageJob.h" #include "jobs/FormatPartitionJob.h" @@ -44,10 +45,12 @@ // KPMcore #include +#include #include #include #include #include +#include // Qt #include @@ -177,6 +180,8 @@ PartitionCoreModule::doInit() m_bootLoaderModel->init( bootLoaderDevices ); + scanForLVMPVs(); + //FIXME: this should be removed in favor of // proper KPM support for EFI if ( PartUtils::isEfiSystem() ) @@ -263,6 +268,27 @@ PartitionCoreModule::createPartition( Device* device, refresh(); } +void +PartitionCoreModule::createVolumeGroup( QString &vgName, + QVector< const Partition* > pvList, + qint32 peSize ) +{ + 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 ); + + m_deviceInfos << deviceInfo; + deviceInfo->jobs << Calamares::job_ptr( job ); + + refresh(); +} + void PartitionCoreModule::deletePartition( Device* device, Partition* partition ) { @@ -432,6 +458,12 @@ PartitionCoreModule::efiSystemPartitions() const return m_efiSystemPartitions; } +QList< const Partition* > +PartitionCoreModule::lvmPVs() const +{ + return m_lvmPVs; +} + void PartitionCoreModule::dumpQueue() const { @@ -523,6 +555,22 @@ PartitionCoreModule::scanForEfiSystemPartitions() m_efiSystemPartitions = efiSystemPartitions; } +void +PartitionCoreModule::scanForLVMPVs() +{ + m_lvmPVs.clear(); + + QList< Device* > devices; + + for ( DeviceInfo* deviceInfo : m_deviceInfos ) + devices << deviceInfo->device.data(); + + LvmDevice::scanSystemLVM( devices ); + + for ( auto p : LVM::pvList ) + m_lvmPVs << p.partition().data(); +} + PartitionCoreModule::DeviceInfo* PartitionCoreModule::infoForDevice( const Device* device ) const { diff --git a/src/modules/partition/core/PartitionCoreModule.h b/src/modules/partition/core/PartitionCoreModule.h index 49564dad1..05c029381 100644 --- a/src/modules/partition/core/PartitionCoreModule.h +++ b/src/modules/partition/core/PartitionCoreModule.h @@ -111,6 +111,8 @@ public: void createPartition( Device* device, Partition* partition, PartitionTable::Flags flags = PartitionTable::FlagNone ); + void createVolumeGroup( QString &vgName, QVector< const Partition* > pvList, qint32 peSize ); + void deletePartition( Device* device, Partition* partition ); void formatPartition( Device* device, Partition* partition ); @@ -132,6 +134,8 @@ public: QList< Partition* > efiSystemPartitions() const; + QList< const Partition* > lvmPVs() const; + /** * @brief findPartitionByMountPoint returns a Partition* for a given mount point. * @param mountPoint the mount point to find a partition for. @@ -194,6 +198,7 @@ private: }; QList< DeviceInfo* > m_deviceInfos; QList< Partition* > m_efiSystemPartitions; + QList< const Partition* > m_lvmPVs; DeviceModel* m_deviceModel; BootLoaderModel* m_bootLoaderModel; @@ -205,6 +210,7 @@ private: void updateHasRootMountPoint(); void updateIsDirty(); void scanForEfiSystemPartitions(); + void scanForLVMPVs(); DeviceInfo* infoForDevice( const Device* ) const; diff --git a/src/modules/partition/core/PartitionInfo.cpp b/src/modules/partition/core/PartitionInfo.cpp index 72cca8976..20cd6f8a9 100644 --- a/src/modules/partition/core/PartitionInfo.cpp +++ b/src/modules/partition/core/PartitionInfo.cpp @@ -19,6 +19,7 @@ #include "core/PartitionInfo.h" // KPMcore +#include #include // Qt @@ -64,6 +65,9 @@ reset( Partition* partition ) bool isDirty( Partition* partition ) { + if ( LvmDevice::s_DirtyPVs.contains( partition ) ) + return true; + return !mountPoint( partition ).isEmpty() || format( partition ); } diff --git a/src/modules/partition/gui/ListPhysicalVolumeWidgetItem.cpp b/src/modules/partition/gui/ListPhysicalVolumeWidgetItem.cpp new file mode 100644 index 000000000..cd480aa55 --- /dev/null +++ b/src/modules/partition/gui/ListPhysicalVolumeWidgetItem.cpp @@ -0,0 +1,36 @@ +/* === This file is part of Calamares - === + * + * Copyright 2018, Caio Jordão Carvalho + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "ListPhysicalVolumeWidgetItem.h" + +#include + +ListPhysicalVolumeWidgetItem::ListPhysicalVolumeWidgetItem( const Partition* partition, bool checked ) + : QListWidgetItem(QString("%1 | %2").arg( partition->deviceNode(), Capacity::formatByteSize( partition->capacity() ))) + , m_partition(partition) +{ + setToolTip( partition->deviceNode() ); + setSizeHint( QSize(0, 32) ); + setCheckState( checked ? Qt::Checked : Qt::Unchecked ); +} + +const Partition* +ListPhysicalVolumeWidgetItem::partition() const +{ + return m_partition; +} diff --git a/src/modules/partition/gui/ListPhysicalVolumeWidgetItem.h b/src/modules/partition/gui/ListPhysicalVolumeWidgetItem.h new file mode 100644 index 000000000..44ba8c3bf --- /dev/null +++ b/src/modules/partition/gui/ListPhysicalVolumeWidgetItem.h @@ -0,0 +1,37 @@ +/* === This file is part of Calamares - === + * + * Copyright 2018, Caio Jordão Carvalho + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef LISTPHYSICALVOLUMEWIDGETITEM_H +#define LISTPHYSICALVOLUMEWIDGETITEM_H + +#include + +#include + +class ListPhysicalVolumeWidgetItem : public QListWidgetItem +{ +public: + ListPhysicalVolumeWidgetItem( const Partition* partition, bool checked ); + + const Partition* partition() const; + +private: + const Partition* m_partition; +}; + +#endif // LISTPHYSICALVOLUMEWIDGETITEM_H diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index c521604fb..adebb3418 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -30,6 +30,7 @@ #include "gui/CreatePartitionDialog.h" #include "gui/EditExistingPartitionDialog.h" #include "gui/ScanningDialog.h" +#include "gui/VolumeGroupBaseDialog.h" #include "ui_PartitionPage.h" #include "ui_CreatePartitionTableDialog.h" @@ -99,6 +100,7 @@ PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent ) connect( m_ui->partitionTreeView, &QAbstractItemView::doubleClicked, this, &PartitionPage::onPartitionViewActivated ); connect( m_ui->revertButton, &QAbstractButton::clicked, this, &PartitionPage::onRevertClicked ); + connect( m_ui->newVolumeGroupButton, &QAbstractButton::clicked, this, &PartitionPage::onNewVolumeGroupClicked ); connect( m_ui->newPartitionTableButton, &QAbstractButton::clicked, this, &PartitionPage::onNewPartitionTableClicked ); connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked ); connect( m_ui->editButton, &QAbstractButton::clicked, this, &PartitionPage::onEditClicked ); @@ -178,6 +180,22 @@ PartitionPage::onNewPartitionTableClicked() updateBootLoaderIndex(); } +void +PartitionPage::onNewVolumeGroupClicked() +{ + QString vgName; + qint32 peSize = 4; + + QPointer< VolumeGroupBaseDialog > dlg = new VolumeGroupBaseDialog( vgName, m_core->lvmPVs(), peSize, this ); + + if ( dlg->exec() == QDialog::Accepted ) + { + + } + + delete dlg; +} + void PartitionPage::onCreateClicked() { diff --git a/src/modules/partition/gui/PartitionPage.h b/src/modules/partition/gui/PartitionPage.h index 24cf65675..ef6eeea15 100644 --- a/src/modules/partition/gui/PartitionPage.h +++ b/src/modules/partition/gui/PartitionPage.h @@ -50,6 +50,7 @@ private: PartitionCoreModule* m_core; void updateButtons(); void onNewPartitionTableClicked(); + void onNewVolumeGroupClicked(); void onCreateClicked(); void onEditClicked(); void onDeleteClicked(); diff --git a/src/modules/partition/gui/PartitionPage.ui b/src/modules/partition/gui/PartitionPage.ui index 7d24204c9..2b3d568cf 100644 --- a/src/modules/partition/gui/PartitionPage.ui +++ b/src/modules/partition/gui/PartitionPage.ui @@ -88,6 +88,13 @@ + + + + New Volume Group + + + @@ -145,7 +152,7 @@ - Install boot &loader on: + I&nstall boot loader on: bootLoaderComboBox diff --git a/src/modules/partition/gui/VolumeGroupBaseDialog.cpp b/src/modules/partition/gui/VolumeGroupBaseDialog.cpp new file mode 100644 index 000000000..b3535a004 --- /dev/null +++ b/src/modules/partition/gui/VolumeGroupBaseDialog.cpp @@ -0,0 +1,42 @@ +/* === This file is part of Calamares - === + * + * Copyright 2018, Caio Jordão Carvalho + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "VolumeGroupBaseDialog.h" +#include "ui_VolumeGroupBaseDialog.h" + +#include "gui/ListPhysicalVolumeWidgetItem.h" + +VolumeGroupBaseDialog::VolumeGroupBaseDialog( QString& vgName, + QList< const Partition* > pvList, + qint32& peSize, + QWidget *parent) + : QDialog(parent) + , ui(new Ui::VolumeGroupBaseDialog) + , m_vgName(vgName) + , m_peSize(peSize) +{ + ui->setupUi(this); + + for ( const Partition* p : pvList ) + ui->pvList->addItem( new ListPhysicalVolumeWidgetItem(p, false) ); +} + +VolumeGroupBaseDialog::~VolumeGroupBaseDialog() +{ + delete ui; +} diff --git a/src/modules/partition/gui/VolumeGroupBaseDialog.h b/src/modules/partition/gui/VolumeGroupBaseDialog.h new file mode 100644 index 000000000..294effb1d --- /dev/null +++ b/src/modules/partition/gui/VolumeGroupBaseDialog.h @@ -0,0 +1,48 @@ +/* === This file is part of Calamares - === + * + * Copyright 2018, Caio Jordão Carvalho + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef VOLUMEGROUPBASEDIALOG_H +#define VOLUMEGROUPBASEDIALOG_H + +#include + +#include + +namespace Ui { +class VolumeGroupBaseDialog; +} + +class VolumeGroupBaseDialog : public QDialog +{ + Q_OBJECT + +public: + explicit VolumeGroupBaseDialog(QString& vgName, + QList< const Partition* > pvList, + qint32& peSize, + QWidget* parent = 0); + ~VolumeGroupBaseDialog(); + +private: + Ui::VolumeGroupBaseDialog *ui; + + QString &m_vgName; + qint32 &m_peSize; +}; + +#endif // VOLUMEGROUPBASEDIALOG_H diff --git a/src/modules/partition/gui/VolumeGroupBaseDialog.ui b/src/modules/partition/gui/VolumeGroupBaseDialog.ui new file mode 100644 index 000000000..c9cb853b8 --- /dev/null +++ b/src/modules/partition/gui/VolumeGroupBaseDialog.ui @@ -0,0 +1,193 @@ + + + VolumeGroupBaseDialog + + + + 0 + 0 + 611 + 367 + + + + VolumeGroupDialog + + + + + + List of Physical Volumes + + + + + + + + + + Volume Group Name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Volume Group Type: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Physical Extent Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Total Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + --- + + + Qt::AlignCenter + + + + + + + Used Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + --- + + + Qt::AlignCenter + + + + + + + Total Sectors: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + --- + + + Qt::AlignCenter + + + + + + + Quantity of LVs: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + --- + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + VolumeGroupBaseDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + VolumeGroupBaseDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/modules/partition/jobs/CreateVolumeGroupJob.cpp b/src/modules/partition/jobs/CreateVolumeGroupJob.cpp new file mode 100644 index 000000000..3b05b684a --- /dev/null +++ b/src/modules/partition/jobs/CreateVolumeGroupJob.cpp @@ -0,0 +1,88 @@ +/* === This file is part of Calamares - === + * + * Copyright 2018, Caio Jordão Carvalho + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "CreateVolumeGroupJob.h" + +// KPMcore +#include +#include +#include +#include + +CreateVolumeGroupJob::CreateVolumeGroupJob( QString& vgName, QVector< const Partition* > pvList, const qint32 peSize ) + : m_vgName(vgName) + , m_pvList(pvList) + , m_peSize(peSize) +{ + +} + +QString +CreateVolumeGroupJob::prettyName() const +{ + return tr( "Create new volume group named %1." ) + .arg( m_vgName ); +} + +QString +CreateVolumeGroupJob::prettyDescription() const +{ + return tr( "Create new volume group named %1." ) + .arg( m_vgName ); +} + +QString +CreateVolumeGroupJob::prettyStatusMessage() const +{ + return tr( "Creating new volume group named %1." ) + .arg( m_vgName ); +} + +Calamares::JobResult +CreateVolumeGroupJob::exec() +{ + Report report( nullptr ); + + QVector< const Partition* > pvList; + + pvList << m_pvList; + + CreateVolumeGroupOperation op( m_vgName, m_pvList, m_peSize ); + + op.setStatus( Operation::StatusRunning ); + + QString message = tr( "The installer failed to create a volume group named '%1'.").arg( m_vgName ); + if (op.execute(report)) + return Calamares::JobResult::ok(); + + return Calamares::JobResult::error(message, report.toText()); +} + +void +CreateVolumeGroupJob::updatePreview() +{ + LvmDevice::s_DirtyPVs << m_pvList; +} + +void +CreateVolumeGroupJob::undoPreview() +{ + for ( const auto& pv : m_pvList ) + if ( LvmDevice::s_DirtyPVs.contains( pv )) + LvmDevice::s_DirtyPVs.removeAll( pv ); +} diff --git a/src/modules/partition/jobs/CreateVolumeGroupJob.h b/src/modules/partition/jobs/CreateVolumeGroupJob.h new file mode 100644 index 000000000..9e84fba73 --- /dev/null +++ b/src/modules/partition/jobs/CreateVolumeGroupJob.h @@ -0,0 +1,47 @@ +/* === This file is part of Calamares - === + * + * Copyright 2018, Caio Jordão Carvalho + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef CREATEVOLUMEGROUPJOB_H +#define CREATEVOLUMEGROUPJOB_H + +#include + +#include + +#include + +class CreateVolumeGroupJob : public Calamares::Job +{ +public: + CreateVolumeGroupJob( QString& vgName, QVector< const Partition* > pvList, const qint32 peSize ); + + QString prettyName() const override; + QString prettyDescription() const override; + QString prettyStatusMessage() const override; + Calamares::JobResult exec() override; + + void updatePreview(); + void undoPreview(); + +private: + QString m_vgName; + QVector< const Partition* > m_pvList; + qint32 m_peSize; +}; + +#endif // CREATEVOLUMEGROUPJOB_H