From af9fbe8a4ff273f85a874d3f33195aa5b6a166e0 Mon Sep 17 00:00:00 2001 From: Caio Carvalho Date: Thu, 3 May 2018 20:50:42 -0300 Subject: [PATCH] - Allow creating LVM VG with PVs that are going to be created in OperationStack. - Check if there is another CreateVolumeGroupOperation with the LVM PV before listing it in the LVM VG creation widget. - Disallow creating VG with some PV that will be deleted. --- src/gui/createvolumegroupdialog.cpp | 53 +++++++++++++++++++++++++++-- src/gui/createvolumegroupdialog.h | 5 ++- src/gui/mainwindow.cpp | 2 +- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/gui/createvolumegroupdialog.cpp b/src/gui/createvolumegroupdialog.cpp index 09dcd12..e4c136b 100644 --- a/src/gui/createvolumegroupdialog.cpp +++ b/src/gui/createvolumegroupdialog.cpp @@ -19,10 +19,15 @@ #include "gui/createvolumegroupdialog.h" #include "gui/volumegroupwidget.h" +#include #include +#include #include +#include +#include + #include #include @@ -32,10 +37,11 @@ #include #include -CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QVector& partList, qint32& peSize, QList devices) +CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QVector& partList, qint32& peSize, QList devices, QList pendingOps) : VolumeGroupDialog(parent, vgName, partList) , m_PESize(peSize) , m_Devices(devices) + , m_PendingOps(pendingOps) { setWindowTitle(xi18nc("@title:window", "Create new Volume Group")); @@ -52,9 +58,44 @@ CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgNam void CreateVolumeGroupDialog::setupDialog() { - for (const auto &p : qAsConst(LVM::pvList)) + for (const auto &p : qAsConst(LVM::pvList)) { + bool toBeDeleted = false; + + // Ignore partitions that are going to be deleted + for (const auto &o : qAsConst(m_PendingOps)) { + if (dynamic_cast(o) && o->targets(*p.partition())) { + toBeDeleted = true; + break; + } + } + + if (toBeDeleted) + continue; + if (!p.isLuks() && p.vgName() == QString() && !LvmDevice::s_DirtyPVs.contains(p.partition())) dialogWidget().listPV().addPartition(*p.partition(), false); + } + + for (const Device *d : qAsConst(m_Devices)) { + for (const Partition *p : qAsConst(d->partitionTable()->children())) { + bool alreadyInPendingVG = false; + + // Looking if there is another VG creation that contains this partition + for (const auto &o : qAsConst(m_PendingOps)) { + if (dynamic_cast(o) && o->targets(*p)) { + alreadyInPendingVG = true; + break; + } + } + + if (alreadyInPendingVG) + continue; + + // Including new LVM PVs (that are currently in OperationStack and that aren't at other VG creation) + if (p->state() == Partition::State::New && p->fileSystem().type() == FileSystem::Type::Lvm2_PV) + dialogWidget().listPV().addPartition(*p, false); + } + } } void CreateVolumeGroupDialog::setupConnections() @@ -76,6 +117,14 @@ void CreateVolumeGroupDialog::accept() QDialog::accept(); } +void CreateVolumeGroupDialog::updateOkButtonStatus() +{ + VolumeGroupDialog::updateOkButtonStatus(); + + if (okButton->isEnabled()) + okButton->setEnabled(!dialogWidget().listPV().checkedItems().empty()); +} + void CreateVolumeGroupDialog::onVGNameChanged(const QString& vgName) { for (const auto &d : m_Devices) { diff --git a/src/gui/createvolumegroupdialog.h b/src/gui/createvolumegroupdialog.h index 70d4867..1f40119 100644 --- a/src/gui/createvolumegroupdialog.h +++ b/src/gui/createvolumegroupdialog.h @@ -21,6 +21,7 @@ #include #include +#include #include "gui/volumegroupdialog.h" @@ -31,7 +32,7 @@ class CreateVolumeGroupDialog : public VolumeGroupDialog Q_DISABLE_COPY(CreateVolumeGroupDialog) public: - CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QVector& pvList, qint32& peSize, QList devices); + CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QVector& pvList, qint32& peSize, QList devices, QList pendingOps = QList()); protected: void accept() override; @@ -39,6 +40,7 @@ protected: void setupConnections() override; protected: + virtual void updateOkButtonStatus() override; void onVGNameChanged(const QString& vgname); void onSpinPESizeChanged(int newsize); @@ -50,6 +52,7 @@ protected: private: const QList m_Devices; // List of all devices found on the system + const QList m_PendingOps; // List of pending operations in KPM }; #endif diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 7355162..91500cf 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1105,7 +1105,7 @@ void MainWindow::onCreateNewVolumeGroup() QVector pvList; qint32 peSize = 4; // *NOTE*: vgName & pvList will be modified and validated by the dialog - QPointer dlg = new CreateVolumeGroupDialog(this, vgName, pvList, peSize, operationStack().previewDevices()); + QPointer dlg = new CreateVolumeGroupDialog(this, vgName, pvList, peSize, operationStack().previewDevices(), operationStack().operations()); if (dlg->exec() == QDialog::Accepted) operationStack().push(new CreateVolumeGroupOperation(vgName, pvList, peSize));