From bbe392b5d23ccae090b3140ecabaaf022337edc4 Mon Sep 17 00:00:00 2001 From: Caio Carvalho Date: Fri, 12 Oct 2018 17:01:38 -0300 Subject: [PATCH] Support RAID resize --- src/gui/mainwindow.cpp | 5 ++- src/gui/resizevolumegroupdialog.cpp | 70 ++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 83c6670..d84c95e 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1158,8 +1158,9 @@ void MainWindow::onCreateNewVolumeGroup() void MainWindow::onResizeVolumeGroup() { - if (pmWidget().selectedDevice()->type() == Device::Type::LVM_Device) { - LvmDevice* d = dynamic_cast(pmWidget().selectedDevice()); + if (pmWidget().selectedDevice()->type() == Device::Type::LVM_Device || + pmWidget().selectedDevice()->type() == Device::Type::SoftwareRAID_Device) { + VolumeManagerDevice* d = dynamic_cast(pmWidget().selectedDevice()); QVector pvList; // *NOTE*: pvList will be modified and validated by the dialog diff --git a/src/gui/resizevolumegroupdialog.cpp b/src/gui/resizevolumegroupdialog.cpp index 9acfc28..b503eea 100644 --- a/src/gui/resizevolumegroupdialog.cpp +++ b/src/gui/resizevolumegroupdialog.cpp @@ -22,6 +22,8 @@ #include #include #include +#include + #include #include @@ -33,6 +35,8 @@ #include #include +#include + /** Creates a new ResizeVolumeGroupDialog @param parent pointer to the parent widget @param d the Device to show properties for @@ -54,7 +58,9 @@ ResizeVolumeGroupDialog::ResizeVolumeGroupDialog(QWidget* parent, VolumeManagerD void ResizeVolumeGroupDialog::setupDialog() { - if (dialogWidget().volumeType().currentText() == QStringLiteral("LVM")) { + if (device()->type() == Device::Type::LVM_Device) { + dialogWidget().volumeType().setCurrentIndex(0); + for (const auto &p : qAsConst(LVM::pvList::list())) { bool toBeDeleted = false; @@ -66,11 +72,9 @@ void ResizeVolumeGroupDialog::setupDialog() } } - if (toBeDeleted) + if (toBeDeleted || p.isLuks()) continue; - if (p.isLuks()) - continue; if (p.vgName() == device()->name()) dialogWidget().listPV().addPartition(*p.partition(), true); else if (p.vgName() == QString() && !LvmDevice::s_DirtyPVs.contains(p.partition())) // TODO: Remove LVM PVs in current VG @@ -102,17 +106,56 @@ void ResizeVolumeGroupDialog::setupDialog() for (const Partition *p : qAsConst(LvmDevice::s_OrphanPVs)) if (!LvmDevice::s_DirtyPVs.contains(p)) dialogWidget().listPV().addPartition(*p, false); - } - //update used size and LV infos - qint32 totalLV = 0; - LvmDevice *lvmDevice = dynamic_cast(device()); - if (lvmDevice != nullptr) { + LvmDevice *lvmDevice = static_cast(device()); + m_TotalUsedSize = lvmDevice->allocatedPE() * lvmDevice->peSize(); - totalLV = lvmDevice->partitionTable()->children().count(); + + dialogWidget().totalUsedSize().setText(Capacity::formatByteSize(m_TotalUsedSize)); + } + else if (device()->type() == Device::Type::SoftwareRAID_Device) { + dialogWidget().volumeType().setCurrentIndex(1); + + for (const Device *d : qAsConst(m_Devices)) { + if (d != device() && d->partitionTable() != nullptr) { + for (const Partition *p : qAsConst(d->partitionTable()->children())) { + QString arrayName = SoftwareRAID::getRaidArrayName(p->partitionPath()); + if (arrayName == device()->deviceNode()) + dialogWidget().listPV().addPartition(*p, true); + else if (((p->fileSystem().type() == FileSystem::Type::LinuxRaidMember && + arrayName.isEmpty()) || p->fileSystem().type() == FileSystem::Type::Unformatted || + p->fileSystem().type() == FileSystem::Type::Unknown) && !p->roles().has(PartitionRole::Role::Unallocated)) + dialogWidget().listPV().addPartition(*p, false); + } + } + } + + SoftwareRAID* raid = static_cast(device()); + + m_TotalUsedSize = 0; + + for (const Partition* p : device()->partitionTable()->children()) + if (!p->roles().has(PartitionRole::Unallocated)) + m_TotalUsedSize += p->used(); + + dialogWidget().totalUsedSize().setText(Capacity::formatByteSize(m_TotalUsedSize)); + + int index = dialogWidget().raidLevel().findText(QString::number(raid->raidLevel())); + + if (index != -1) + dialogWidget().raidLevel().setCurrentIndex(index); + + dialogWidget().chunkSize().setValue(raid->chunkSize()); + } + + int totalLV = 0; + + if (device()->partitionTable()) { + for (const Partition* p : device()->partitionTable()->children()) + if (!p->roles().has(PartitionRole::Role::Unallocated)) + totalLV++; } - dialogWidget().totalUsedSize().setText(Capacity::formatByteSize(m_TotalUsedSize)); dialogWidget().totalLV().setText(QString::number(totalLV)); } @@ -121,6 +164,11 @@ void ResizeVolumeGroupDialog::setupConstraints() dialogWidget().vgName().setEnabled(false); dialogWidget().spinPESize().setEnabled(false); dialogWidget().volumeType().setEnabled(false); + + // set constraints for raid + dialogWidget().raidLevel().setEnabled(false); + dialogWidget().chunkSize().setEnabled(false); + VolumeGroupDialog::setupConstraints(); }