Load partitions for RAID in CreateVolumeGroupDialog.
This commit is contained in:
parent
a4773460f0
commit
a87f042468
|
@ -49,7 +49,7 @@ CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgNam
|
|||
setupConnections();
|
||||
|
||||
// disable volume type and PE size for now, until the features are implemented.
|
||||
dialogWidget().volumeType().setEnabled(false);
|
||||
dialogWidget().volumeType().setEnabled(true);
|
||||
|
||||
KConfigGroup kcg(KSharedConfig::openConfig(), "createVolumeDialog");
|
||||
restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray()));
|
||||
|
@ -57,49 +57,7 @@ CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgNam
|
|||
|
||||
void CreateVolumeGroupDialog::setupDialog()
|
||||
{
|
||||
for (const auto &p : qAsConst(LVM::pvList::list())) {
|
||||
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)) {
|
||||
if (d->partitionTable() != nullptr) {
|
||||
for (const Partition *p : qAsConst(d->partitionTable()->children())) {
|
||||
// Looking if there is another VG creation that contains this partition
|
||||
if (LvmDevice::s_DirtyPVs.contains(p))
|
||||
continue;
|
||||
|
||||
// Including new LVM PVs (that are currently in OperationStack and that aren't at other VG creation)
|
||||
if (p->state() == Partition::State::New) {
|
||||
if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV)
|
||||
dialogWidget().listPV().addPartition(*p, false);
|
||||
else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) {
|
||||
FileSystem *fs = static_cast<const FS::luks *>(&p->fileSystem())->innerFS();
|
||||
|
||||
if (fs->type() == FileSystem::Type::Lvm2_PV)
|
||||
dialogWidget().listPV().addPartition(*p, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const Partition *p : qAsConst(LvmDevice::s_OrphanPVs))
|
||||
if (!LvmDevice::s_DirtyPVs.contains(p))
|
||||
dialogWidget().listPV().addPartition(*p, false);
|
||||
updatePartitionList();
|
||||
}
|
||||
|
||||
void CreateVolumeGroupDialog::setupConnections()
|
||||
|
@ -108,7 +66,69 @@ void CreateVolumeGroupDialog::setupConnections()
|
|||
connect(&dialogWidget().spinPESize(), qOverload<int>(&QSpinBox::valueChanged), this, &CreateVolumeGroupDialog::onSpinPESizeChanged);
|
||||
}
|
||||
|
||||
void CreateVolumeGroupDialog::accept()
|
||||
void CreateVolumeGroupDialog::updatePartitionList()
|
||||
{
|
||||
if (dialogWidget().volumeType().currentText() == QStringLiteral("LVM")) {
|
||||
dialogWidget().listPV().clear();
|
||||
|
||||
for (const auto &p : qAsConst(LVM::pvList::list())) {
|
||||
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)) {
|
||||
if (d->partitionTable() != nullptr) {
|
||||
for (const Partition *p : qAsConst(d->partitionTable()->children())) {
|
||||
// Looking if there is another VG creation that contains this partition
|
||||
if (LvmDevice::s_DirtyPVs.contains(p))
|
||||
continue;
|
||||
|
||||
// Including new LVM PVs (that are currently in OperationStack and that aren't at other VG creation)
|
||||
if (p->state() == Partition::State::New) {
|
||||
if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV)
|
||||
dialogWidget().listPV().addPartition(*p, false);
|
||||
else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) {
|
||||
FileSystem *fs = static_cast<const FS::luks *>(&p->fileSystem())->innerFS();
|
||||
|
||||
if (fs->type() == FileSystem::Type::Lvm2_PV)
|
||||
dialogWidget().listPV().addPartition(*p, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const Partition *p : qAsConst(LvmDevice::s_OrphanPVs))
|
||||
if (!LvmDevice::s_DirtyPVs.contains(p))
|
||||
dialogWidget().listPV().addPartition(*p, false);
|
||||
}
|
||||
else if (dialogWidget().volumeType().currentText() == QStringLiteral("RAID")) {
|
||||
for (const Device *d : qAsConst(m_Devices)) {
|
||||
if (d->type() != Device::Type::SoftwareRAID_Device && d->partitionTable() != nullptr) {
|
||||
for (const Partition *p : qAsConst(d->partitionTable()->children())) {
|
||||
if (p->fileSystem().type() != FileSystem::Type::LinuxRaidMember &&
|
||||
!p->roles().has(PartitionRole::Role::Unallocated))
|
||||
dialogWidget().listPV().addPartition(*p, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CreateVolumeGroupDialog::accept()
|
||||
{
|
||||
QString& tname = targetName();
|
||||
tname = dialogWidget().vgName().text();
|
||||
|
|
|
@ -37,6 +37,7 @@ protected:
|
|||
void accept() override;
|
||||
void setupDialog() override;
|
||||
void setupConnections() override;
|
||||
void updatePartitionList() override;
|
||||
|
||||
protected:
|
||||
virtual void updateOkButtonStatus() override;
|
||||
|
|
|
@ -35,6 +35,11 @@ void ListPhysicalVolumes::addPartition(const Partition& p, bool checked)
|
|||
listPhysicalVolumes().addItem(item);
|
||||
}
|
||||
|
||||
void ListPhysicalVolumes::clear()
|
||||
{
|
||||
listPhysicalVolumes().clear();
|
||||
}
|
||||
|
||||
QVector<const Partition *> ListPhysicalVolumes::checkedItems()
|
||||
{
|
||||
QVector<const Partition *> partitionList;
|
||||
|
|
|
@ -50,6 +50,8 @@ public:
|
|||
|
||||
void addPartition(const Partition& p, bool checked);
|
||||
|
||||
void clear();
|
||||
|
||||
QVector<const Partition *> checkedItems();
|
||||
|
||||
QListWidget& listPhysicalVolumes() {
|
||||
|
|
|
@ -1111,7 +1111,9 @@ 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(), operationStack().operations());
|
||||
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));
|
||||
|
||||
|
|
|
@ -76,18 +76,12 @@ VolumeGroupDialog::~VolumeGroupDialog()
|
|||
|
||||
void VolumeGroupDialog::setupDialog()
|
||||
{
|
||||
/* LVM Volume group name can consist of: letters numbers _ . - +
|
||||
* It cannot start with underscore _ and must not be equal to . or .. or any entry in /dev/
|
||||
* QLineEdit accepts QValidator::Intermediate, so we just disable . at the beginning */
|
||||
QRegularExpression re(QStringLiteral(R"(^(?!_|\.)[\w\-.+]+)"));
|
||||
QRegularExpressionValidator *validator = new QRegularExpressionValidator(re, this);
|
||||
dialogWidget().vgName().setValidator(validator);
|
||||
dialogWidget().vgName().setText(targetName());
|
||||
|
||||
dialogWidget().volumeType().addItem(QStringLiteral("LVM"));
|
||||
dialogWidget().volumeType().addItem(QStringLiteral("RAID"));
|
||||
dialogWidget().volumeType().setCurrentIndex(0);
|
||||
|
||||
updateNameValidator();
|
||||
|
||||
setMinimumSize(dialogWidget().size());
|
||||
resize(dialogWidget().size());
|
||||
}
|
||||
|
@ -153,6 +147,23 @@ void VolumeGroupDialog::updatePartitionList()
|
|||
{
|
||||
}
|
||||
|
||||
void VolumeGroupDialog::updateNameValidator()
|
||||
{
|
||||
if (dialogWidget().volumeType().currentText() == QStringLiteral("LVM")) {
|
||||
/* LVM Volume group name can consist of: letters numbers _ . - +
|
||||
* It cannot start with underscore _ and must not be equal to . or .. or any entry in /dev/
|
||||
* QLineEdit accepts QValidator::Intermediate, so we just disable . at the beginning */
|
||||
|
||||
QRegularExpression re(QStringLiteral(R"(^(?!_|\.)[\w\-.+]+)"));
|
||||
QRegularExpressionValidator *validator = new QRegularExpressionValidator(re, this);
|
||||
dialogWidget().vgName().setValidator(validator);
|
||||
dialogWidget().vgName().setText(targetName());
|
||||
}
|
||||
else if (dialogWidget().volumeType().currentText() == QStringLiteral("RAID")) {
|
||||
// TODO: See how Software RAID names should be validated.
|
||||
}
|
||||
}
|
||||
|
||||
void VolumeGroupDialog::onPartitionListChanged()
|
||||
{
|
||||
}
|
||||
|
@ -160,5 +171,6 @@ void VolumeGroupDialog::onPartitionListChanged()
|
|||
void VolumeGroupDialog::onVolumeTypeChanged(int index)
|
||||
{
|
||||
Q_UNUSED(index)
|
||||
updateNameValidator();
|
||||
updatePartitionList();
|
||||
}
|
||||
|
|
|
@ -86,6 +86,9 @@ protected:
|
|||
protected:
|
||||
virtual void onPartitionListChanged();
|
||||
|
||||
private:
|
||||
virtual void updateNameValidator();
|
||||
|
||||
protected:
|
||||
VolumeGroupWidget* m_DialogWidget;
|
||||
QString& m_TargetName;
|
||||
|
|
Loading…
Reference in New Issue