- 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.
This commit is contained in:
Caio Carvalho 2018-05-03 20:50:42 -03:00
parent 2482eba7de
commit af9fbe8a4f
3 changed files with 56 additions and 4 deletions

View File

@ -19,10 +19,15 @@
#include "gui/createvolumegroupdialog.h"
#include "gui/volumegroupwidget.h"
#include <core/device.h>
#include <core/lvmdevice.h>
#include <core/partitiontable.h>
#include <fs/lvm2_pv.h>
#include <ops/createvolumegroupoperation.h>
#include <ops/deleteoperation.h>
#include <util/capacity.h>
#include <util/helpers.h>
@ -32,10 +37,11 @@
#include <KLocalizedString>
#include <KSharedConfig>
CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QVector<const Partition*>& partList, qint32& peSize, QList<Device*> devices)
CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QVector<const Partition*>& partList, qint32& peSize, QList<Device*> devices, QList<Operation*> 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<DeleteOperation *>(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<CreateVolumeGroupOperation *>(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) {

View File

@ -21,6 +21,7 @@
#include <core/device.h>
#include <fs/lvm2_pv.h>
#include <ops/operation.h>
#include "gui/volumegroupdialog.h"
@ -31,7 +32,7 @@ class CreateVolumeGroupDialog : public VolumeGroupDialog
Q_DISABLE_COPY(CreateVolumeGroupDialog)
public:
CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QVector<const Partition*>& pvList, qint32& peSize, QList<Device*> devices);
CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QVector<const Partition*>& pvList, qint32& peSize, QList<Device*> devices, QList<Operation*> pendingOps = QList<Operation *>());
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<Device*> m_Devices; // List of all devices found on the system
const QList<Operation*> m_PendingOps; // List of pending operations in KPM
};
#endif

View File

@ -1105,7 +1105,7 @@ void MainWindow::onCreateNewVolumeGroup()
QVector<const Partition*> pvList;
qint32 peSize = 4;
// *NOTE*: vgName & pvList will be modified and validated by the dialog
QPointer<CreateVolumeGroupDialog> dlg = new CreateVolumeGroupDialog(this, vgName, pvList, peSize, operationStack().previewDevices());
QPointer<CreateVolumeGroupDialog> dlg = new CreateVolumeGroupDialog(this, vgName, pvList, peSize, operationStack().previewDevices(), operationStack().operations());
if (dlg->exec() == QDialog::Accepted)
operationStack().push(new CreateVolumeGroupOperation(vgName, pvList, peSize));