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);
|
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;
|
devices << d;
|
||||||
|
|
||||||
if (status == QStringLiteral("inactive"))
|
if (status == QStringLiteral("inactive"))
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "jobs/movephysicalvolumejob.h"
|
#include "jobs/movephysicalvolumejob.h"
|
||||||
|
|
||||||
#include "core/lvmdevice.h"
|
#include "core/lvmdevice.h"
|
||||||
|
#include "core/volumemanagerdevice.h"
|
||||||
|
|
||||||
#include "util/report.h"
|
#include "util/report.h"
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@
|
||||||
/** Creates a new MovePhysicalVolumeJob
|
/** Creates a new MovePhysicalVolumeJob
|
||||||
* @param d Device representing LVM Volume Group
|
* @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(),
|
Job(),
|
||||||
m_Device(d),
|
m_Device(d),
|
||||||
m_PartList(partList)
|
m_PartList(partList)
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "core/partition.h"
|
#include "core/partition.h"
|
||||||
#include "jobs/job.h"
|
#include "jobs/job.h"
|
||||||
|
|
||||||
class LvmDevice;
|
class VolumeManagerDevice;
|
||||||
class Report;
|
class Report;
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
|
@ -30,7 +30,7 @@ class QString;
|
||||||
class MovePhysicalVolumeJob : public Job
|
class MovePhysicalVolumeJob : public Job
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MovePhysicalVolumeJob(LvmDevice& dev, const QList <const Partition*>& partlist);
|
MovePhysicalVolumeJob(VolumeManagerDevice& dev, const QList <const Partition*>& partlist);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool run(Report& parent) override;
|
bool run(Report& parent) override;
|
||||||
|
@ -38,10 +38,10 @@ public:
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LvmDevice& device() {
|
VolumeManagerDevice& device() {
|
||||||
return m_Device;
|
return m_Device;
|
||||||
}
|
}
|
||||||
const LvmDevice& device() const {
|
const VolumeManagerDevice& device() const {
|
||||||
return m_Device;
|
return m_Device;
|
||||||
}
|
}
|
||||||
const QList <const Partition*>& partList() const {
|
const QList <const Partition*>& partList() const {
|
||||||
|
@ -49,7 +49,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LvmDevice& m_Device;
|
VolumeManagerDevice& m_Device;
|
||||||
const QList <const Partition*> m_PartList;
|
const QList <const Partition*> m_PartList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "jobs/resizevolumegroupjob.h"
|
#include "jobs/resizevolumegroupjob.h"
|
||||||
|
|
||||||
#include "core/lvmdevice.h"
|
#include "core/lvmdevice.h"
|
||||||
|
#include "core/volumemanagerdevice.h"
|
||||||
#include "fs/luks.h"
|
#include "fs/luks.h"
|
||||||
|
|
||||||
#include "util/report.h"
|
#include "util/report.h"
|
||||||
|
@ -27,7 +28,7 @@
|
||||||
|
|
||||||
/** Creates a new ResizeVolumeGroupJob
|
/** 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(),
|
Job(),
|
||||||
m_Device(dev),
|
m_Device(dev),
|
||||||
m_PartList(partlist),
|
m_PartList(partlist),
|
||||||
|
@ -41,15 +42,18 @@ bool ResizeVolumeGroupJob::run(Report& parent)
|
||||||
|
|
||||||
Report* report = jobStarted(parent);
|
Report* report = jobStarted(parent);
|
||||||
|
|
||||||
for (const auto &p : partList()) {
|
if (device().type() == Device::Type::LVM_Device) {
|
||||||
const QString deviceNode = p->roles().has(PartitionRole::Luks) ? static_cast<const FS::luks*>(&p->fileSystem())->mapperName() : p->partitionPath();
|
LvmDevice& lvm = static_cast<LvmDevice&>(device());
|
||||||
if (type() == ResizeVolumeGroupJob::Type::Grow)
|
for (const auto &p : partList()) {
|
||||||
rval = LvmDevice::insertPV(*report, device(), deviceNode);
|
const QString deviceNode = p->roles().has(PartitionRole::Luks) ? static_cast<const FS::luks*>(&p->fileSystem())->mapperName() : p->partitionPath();
|
||||||
else if (type() == ResizeVolumeGroupJob::Type::Shrink)
|
if (type() == ResizeVolumeGroupJob::Type::Grow)
|
||||||
rval = LvmDevice::removePV(*report, device(), deviceNode);
|
rval = LvmDevice::insertPV(*report, lvm, deviceNode);
|
||||||
|
else if (type() == ResizeVolumeGroupJob::Type::Shrink)
|
||||||
|
rval = LvmDevice::removePV(*report, lvm, deviceNode);
|
||||||
|
|
||||||
if (rval == false)
|
if (rval == false)
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jobFinished(*report, rval);
|
jobFinished(*report, rval);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "core/partition.h"
|
#include "core/partition.h"
|
||||||
#include "jobs/job.h"
|
#include "jobs/job.h"
|
||||||
|
|
||||||
class LvmDevice;
|
class VolumeManagerDevice;
|
||||||
class Report;
|
class Report;
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
|
@ -37,17 +37,17 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
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:
|
public:
|
||||||
bool run(Report& parent) override;
|
bool run(Report& parent) override;
|
||||||
QString description() const override;
|
QString description() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LvmDevice& device() {
|
VolumeManagerDevice& device() {
|
||||||
return m_Device;
|
return m_Device;
|
||||||
}
|
}
|
||||||
const LvmDevice& device() const {
|
const VolumeManagerDevice& device() const {
|
||||||
return m_Device;
|
return m_Device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LvmDevice& m_Device;
|
VolumeManagerDevice& m_Device;
|
||||||
const QList <const Partition*> m_PartList;
|
const QList <const Partition*> m_PartList;
|
||||||
ResizeVolumeGroupJob::Type m_Type;
|
ResizeVolumeGroupJob::Type m_Type;
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "jobs/movephysicalvolumejob.h"
|
#include "jobs/movephysicalvolumejob.h"
|
||||||
#include "util/helpers.h"
|
#include "util/helpers.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
@ -33,7 +34,7 @@
|
||||||
@param d the Device to create the new PartitionTable on
|
@param d the Device to create the new PartitionTable on
|
||||||
@param partList list of LVM Physical Volumes that should be in LVM Volume Group
|
@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()
|
: Operation()
|
||||||
, m_Device(d)
|
, m_Device(d)
|
||||||
, m_TargetList(partList)
|
, m_TargetList(partList)
|
||||||
|
@ -59,45 +60,16 @@ ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(LvmDevice& d, const QVect
|
||||||
if (!currentList().contains(p))
|
if (!currentList().contains(p))
|
||||||
toInsertList.append(p);
|
toInsertList.append(p);
|
||||||
|
|
||||||
qint64 currentFreePE = 0;
|
if (!toInsertList.isEmpty()) {
|
||||||
for (const auto &p : currentList()) {
|
m_GrowVolumeGroupJob = new ResizeVolumeGroupJob(d, toInsertList, ResizeVolumeGroupJob::Type::Grow);
|
||||||
FS::lvm2_pv *lvm2PVFs;
|
addJob(growVolumeGroupJob());
|
||||||
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 ( movePE > (freePE + growPE)) {
|
if (!toRemoveList.isEmpty()) {
|
||||||
// *ABORT* can't move
|
m_MovePhysicalVolumeJob = new MovePhysicalVolumeJob(d, toRemoveList);
|
||||||
} else if (partList == currentList()) {
|
m_ShrinkVolumeGroupJob = new ResizeVolumeGroupJob(d, toRemoveList, ResizeVolumeGroupJob::Type::Shrink);
|
||||||
// *DO NOTHING*
|
addJob(movePhysicalVolumeJob());
|
||||||
} else {
|
addJob(shrinkvolumegroupjob());
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,10 @@
|
||||||
|
|
||||||
#include "ops/operation.h"
|
#include "ops/operation.h"
|
||||||
|
|
||||||
#include "core/lvmdevice.h"
|
#include "core/volumemanagerdevice.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
class ResizeVolumeGroupJob;
|
class ResizeVolumeGroupJob;
|
||||||
class MovePhysicalVolumeJob;
|
class MovePhysicalVolumeJob;
|
||||||
|
@ -40,7 +41,7 @@ class LIBKPMCORE_EXPORT ResizeVolumeGroupOperation : public Operation
|
||||||
friend class OperationStack;
|
friend class OperationStack;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ResizeVolumeGroupOperation(LvmDevice& dev, const QVector<const Partition*>& partlist);
|
ResizeVolumeGroupOperation(VolumeManagerDevice& dev, const QVector<const Partition*>& partlist);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QString iconName() const override {
|
QString iconName() const override {
|
||||||
|
@ -59,10 +60,10 @@ public:
|
||||||
QStringList getToInsertList();
|
QStringList getToInsertList();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LvmDevice& device() {
|
VolumeManagerDevice& device() {
|
||||||
return m_Device;
|
return m_Device;
|
||||||
}
|
}
|
||||||
const LvmDevice& device() const {
|
const VolumeManagerDevice& device() const {
|
||||||
return m_Device;
|
return m_Device;
|
||||||
}
|
}
|
||||||
const QVector<const Partition*>& targetList() const {
|
const QVector<const Partition*>& targetList() const {
|
||||||
|
@ -94,7 +95,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LvmDevice& m_Device;
|
VolumeManagerDevice& m_Device;
|
||||||
|
|
||||||
QVector<const Partition*> m_TargetList;
|
QVector<const Partition*> m_TargetList;
|
||||||
QVector<const Partition*> m_CurrentList;
|
QVector<const Partition*> m_CurrentList;
|
||||||
|
|
Loading…
Reference in New Issue