diff --git a/src/core/raid/softwareraid.cpp b/src/core/raid/softwareraid.cpp index 0b3907b..85dd9d5 100644 --- a/src/core/raid/softwareraid.cpp +++ b/src/core/raid/softwareraid.cpp @@ -217,6 +217,14 @@ void SoftwareRAID::scanSoftwareRAID(QList& devices) d->setPartitionNodes(partitionNodes); + for (const Device* dev : qAsConst(devices)) { + if (dev->partitionTable()) { + for (const Partition* p : dev->partitionTable()->children()) + if (getRaidArrayName(p->deviceNode()) == d->deviceNode()) + d->physicalVolumes() << p; + } + } + devices << d; if (status == QStringLiteral("inactive")) diff --git a/src/jobs/movephysicalvolumejob.cpp b/src/jobs/movephysicalvolumejob.cpp index c961b8d..ee10d32 100644 --- a/src/jobs/movephysicalvolumejob.cpp +++ b/src/jobs/movephysicalvolumejob.cpp @@ -19,6 +19,7 @@ #include "jobs/movephysicalvolumejob.h" #include "core/lvmdevice.h" +#include "core/volumemanagerdevice.h" #include "util/report.h" @@ -27,7 +28,7 @@ /** Creates a new MovePhysicalVolumeJob * @param d Device representing LVM Volume Group */ -MovePhysicalVolumeJob::MovePhysicalVolumeJob(LvmDevice& d, const QList & partList) : +MovePhysicalVolumeJob::MovePhysicalVolumeJob(VolumeManagerDevice& d, const QList & partList) : Job(), m_Device(d), m_PartList(partList) diff --git a/src/jobs/movephysicalvolumejob.h b/src/jobs/movephysicalvolumejob.h index 452e8ab..1ae5eb3 100644 --- a/src/jobs/movephysicalvolumejob.h +++ b/src/jobs/movephysicalvolumejob.h @@ -22,7 +22,7 @@ #include "core/partition.h" #include "jobs/job.h" -class LvmDevice; +class VolumeManagerDevice; class Report; class QString; @@ -30,7 +30,7 @@ class QString; class MovePhysicalVolumeJob : public Job { public: - MovePhysicalVolumeJob(LvmDevice& dev, const QList & partlist); + MovePhysicalVolumeJob(VolumeManagerDevice& dev, const QList & partlist); public: bool run(Report& parent) override; @@ -38,10 +38,10 @@ public: protected: - LvmDevice& device() { + VolumeManagerDevice& device() { return m_Device; } - const LvmDevice& device() const { + const VolumeManagerDevice& device() const { return m_Device; } const QList & partList() const { @@ -49,7 +49,7 @@ protected: } private: - LvmDevice& m_Device; + VolumeManagerDevice& m_Device; const QList m_PartList; }; diff --git a/src/jobs/resizevolumegroupjob.cpp b/src/jobs/resizevolumegroupjob.cpp index 3dce190..0642b55 100644 --- a/src/jobs/resizevolumegroupjob.cpp +++ b/src/jobs/resizevolumegroupjob.cpp @@ -19,6 +19,7 @@ #include "jobs/resizevolumegroupjob.h" #include "core/lvmdevice.h" +#include "core/volumemanagerdevice.h" #include "fs/luks.h" #include "util/report.h" @@ -27,7 +28,7 @@ /** Creates a new ResizeVolumeGroupJob */ -ResizeVolumeGroupJob::ResizeVolumeGroupJob(LvmDevice& dev, const QList & partlist, const Type type) : +ResizeVolumeGroupJob::ResizeVolumeGroupJob(VolumeManagerDevice& dev, const QList & partlist, const Type type) : Job(), m_Device(dev), m_PartList(partlist), @@ -41,15 +42,18 @@ bool ResizeVolumeGroupJob::run(Report& parent) Report* report = jobStarted(parent); - for (const auto &p : partList()) { - const QString deviceNode = p->roles().has(PartitionRole::Luks) ? static_cast(&p->fileSystem())->mapperName() : p->partitionPath(); - if (type() == ResizeVolumeGroupJob::Type::Grow) - rval = LvmDevice::insertPV(*report, device(), deviceNode); - else if (type() == ResizeVolumeGroupJob::Type::Shrink) - rval = LvmDevice::removePV(*report, device(), deviceNode); + if (device().type() == Device::Type::LVM_Device) { + LvmDevice& lvm = static_cast(device()); + for (const auto &p : partList()) { + const QString deviceNode = p->roles().has(PartitionRole::Luks) ? static_cast(&p->fileSystem())->mapperName() : p->partitionPath(); + if (type() == ResizeVolumeGroupJob::Type::Grow) + rval = LvmDevice::insertPV(*report, lvm, deviceNode); + else if (type() == ResizeVolumeGroupJob::Type::Shrink) + rval = LvmDevice::removePV(*report, lvm, deviceNode); - if (rval == false) - break; + if (rval == false) + break; + } } jobFinished(*report, rval); diff --git a/src/jobs/resizevolumegroupjob.h b/src/jobs/resizevolumegroupjob.h index adb2a1d..fc0e944 100644 --- a/src/jobs/resizevolumegroupjob.h +++ b/src/jobs/resizevolumegroupjob.h @@ -22,7 +22,7 @@ #include "core/partition.h" #include "jobs/job.h" -class LvmDevice; +class VolumeManagerDevice; class Report; class QString; @@ -37,17 +37,17 @@ public: }; public: - ResizeVolumeGroupJob(LvmDevice& dev, const QList & partlist, const Type type); + ResizeVolumeGroupJob(VolumeManagerDevice& dev, const QList & partlist, const Type type); public: bool run(Report& parent) override; QString description() const override; protected: - LvmDevice& device() { + VolumeManagerDevice& device() { return m_Device; } - const LvmDevice& device() const { + const VolumeManagerDevice& device() const { return m_Device; } @@ -60,7 +60,7 @@ protected: } private: - LvmDevice& m_Device; + VolumeManagerDevice& m_Device; const QList m_PartList; ResizeVolumeGroupJob::Type m_Type; }; diff --git a/src/ops/resizevolumegroupoperation.cpp b/src/ops/resizevolumegroupoperation.cpp index 6996899..65b219a 100644 --- a/src/ops/resizevolumegroupoperation.cpp +++ b/src/ops/resizevolumegroupoperation.cpp @@ -25,6 +25,7 @@ #include "jobs/movephysicalvolumejob.h" #include "util/helpers.h" +#include #include #include @@ -33,7 +34,7 @@ @param d the Device to create the new PartitionTable on @param partList list of LVM Physical Volumes that should be in LVM Volume Group */ -ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(LvmDevice& d, const QVector& partList) +ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(VolumeManagerDevice& d, const QVector& partList) : Operation() , m_Device(d) , m_TargetList(partList) @@ -59,45 +60,16 @@ ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(LvmDevice& d, const QVect if (!currentList().contains(p)) toInsertList.append(p); - qint64 currentFreePE = 0; - for (const auto &p : currentList()) { - FS::lvm2_pv *lvm2PVFs; - innerFS(p, lvm2PVFs); - currentFreePE += lvm2PVFs->freePE(); - } - qint64 removedFreePE = 0; - for (const auto &p : qAsConst(toRemoveList)) { - FS::lvm2_pv *lvm2PVFs; - innerFS(p, lvm2PVFs); - removedFreePE += lvm2PVFs->freePE(); - } - qint64 freePE = currentFreePE - removedFreePE; - qint64 movePE = 0; - for (const auto &p : qAsConst(toRemoveList)) { - FS::lvm2_pv *lvm2PVFs; - innerFS(p, lvm2PVFs); - movePE += lvm2PVFs->allocatedPE(); - } - qint64 growPE = 0; - for (const auto &p : qAsConst(toInsertList)) { - growPE += p->capacity() / device().peSize(); + if (!toInsertList.isEmpty()) { + m_GrowVolumeGroupJob = new ResizeVolumeGroupJob(d, toInsertList, ResizeVolumeGroupJob::Type::Grow); + addJob(growVolumeGroupJob()); } - if ( movePE > (freePE + growPE)) { - // *ABORT* can't move - } else if (partList == currentList()) { - // *DO NOTHING* - } else { - if (!toInsertList.isEmpty()) { - m_GrowVolumeGroupJob = new ResizeVolumeGroupJob(d, toInsertList, ResizeVolumeGroupJob::Type::Grow); - addJob(growVolumeGroupJob()); - } - if (!toRemoveList.isEmpty()) { - m_MovePhysicalVolumeJob = new MovePhysicalVolumeJob(d, toRemoveList); - m_ShrinkVolumeGroupJob = new ResizeVolumeGroupJob(d, toRemoveList, ResizeVolumeGroupJob::Type::Shrink); - addJob(movePhysicalVolumeJob()); - addJob(shrinkvolumegroupjob()); - } + if (!toRemoveList.isEmpty()) { + m_MovePhysicalVolumeJob = new MovePhysicalVolumeJob(d, toRemoveList); + m_ShrinkVolumeGroupJob = new ResizeVolumeGroupJob(d, toRemoveList, ResizeVolumeGroupJob::Type::Shrink); + addJob(movePhysicalVolumeJob()); + addJob(shrinkvolumegroupjob()); } } diff --git a/src/ops/resizevolumegroupoperation.h b/src/ops/resizevolumegroupoperation.h index c46364c..6ae0285 100644 --- a/src/ops/resizevolumegroupoperation.h +++ b/src/ops/resizevolumegroupoperation.h @@ -24,9 +24,10 @@ #include "ops/operation.h" -#include "core/lvmdevice.h" +#include "core/volumemanagerdevice.h" #include +#include class ResizeVolumeGroupJob; class MovePhysicalVolumeJob; @@ -40,7 +41,7 @@ class LIBKPMCORE_EXPORT ResizeVolumeGroupOperation : public Operation friend class OperationStack; public: - ResizeVolumeGroupOperation(LvmDevice& dev, const QVector& partlist); + ResizeVolumeGroupOperation(VolumeManagerDevice& dev, const QVector& partlist); public: QString iconName() const override { @@ -59,10 +60,10 @@ public: QStringList getToInsertList(); protected: - LvmDevice& device() { + VolumeManagerDevice& device() { return m_Device; } - const LvmDevice& device() const { + const VolumeManagerDevice& device() const { return m_Device; } const QVector& targetList() const { @@ -94,7 +95,7 @@ protected: } private: - LvmDevice& m_Device; + VolumeManagerDevice& m_Device; QVector m_TargetList; QVector m_CurrentList;