Changing volume group resize to support RAID
This commit is contained in:
parent
6a349f7bc8
commit
daacc0bfb7
|
@ -217,6 +217,14 @@ void SoftwareRAID::scanSoftwareRAID(QList<Device*>& 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"))
|
||||
|
|
|
@ -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 <const Partition*>& partList) :
|
||||
MovePhysicalVolumeJob::MovePhysicalVolumeJob(VolumeManagerDevice& d, const QList <const Partition*>& partList) :
|
||||
Job(),
|
||||
m_Device(d),
|
||||
m_PartList(partList)
|
||||
|
|
|
@ -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 <const Partition*>& partlist);
|
||||
MovePhysicalVolumeJob(VolumeManagerDevice& dev, const QList <const Partition*>& 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 <const Partition*>& partList() const {
|
||||
|
@ -49,7 +49,7 @@ protected:
|
|||
}
|
||||
|
||||
private:
|
||||
LvmDevice& m_Device;
|
||||
VolumeManagerDevice& m_Device;
|
||||
const QList <const Partition*> m_PartList;
|
||||
};
|
||||
|
||||
|
|
|
@ -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 <const Partition*>& partlist, const Type type) :
|
||||
ResizeVolumeGroupJob::ResizeVolumeGroupJob(VolumeManagerDevice& dev, const QList <const Partition*>& 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<const FS::luks*>(&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<LvmDevice&>(device());
|
||||
for (const auto &p : partList()) {
|
||||
const QString deviceNode = p->roles().has(PartitionRole::Luks) ? static_cast<const FS::luks*>(&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);
|
||||
|
|
|
@ -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 <const Partition*>& partlist, const Type type);
|
||||
ResizeVolumeGroupJob(VolumeManagerDevice& dev, const QList <const Partition*>& 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 <const Partition*> m_PartList;
|
||||
ResizeVolumeGroupJob::Type m_Type;
|
||||
};
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "jobs/movephysicalvolumejob.h"
|
||||
#include "util/helpers.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
|
||||
#include <KLocalizedString>
|
||||
|
@ -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<const Partition*>& partList)
|
||||
ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(VolumeManagerDevice& d, const QVector<const Partition*>& 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,10 @@
|
|||
|
||||
#include "ops/operation.h"
|
||||
|
||||
#include "core/lvmdevice.h"
|
||||
#include "core/volumemanagerdevice.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
class ResizeVolumeGroupJob;
|
||||
class MovePhysicalVolumeJob;
|
||||
|
@ -40,7 +41,7 @@ class LIBKPMCORE_EXPORT ResizeVolumeGroupOperation : public Operation
|
|||
friend class OperationStack;
|
||||
|
||||
public:
|
||||
ResizeVolumeGroupOperation(LvmDevice& dev, const QVector<const Partition*>& partlist);
|
||||
ResizeVolumeGroupOperation(VolumeManagerDevice& dev, const QVector<const Partition*>& 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<const Partition*>& targetList() const {
|
||||
|
@ -94,7 +95,7 @@ protected:
|
|||
}
|
||||
|
||||
private:
|
||||
LvmDevice& m_Device;
|
||||
VolumeManagerDevice& m_Device;
|
||||
|
||||
QVector<const Partition*> m_TargetList;
|
||||
QVector<const Partition*> m_CurrentList;
|
||||
|
|
Loading…
Reference in New Issue