Initial work on Resize operation and move/resize jobs.

This commit is contained in:
Chantara Tith 2016-07-09 07:10:57 +07:00
parent 6805269dd0
commit 5a36f03632
8 changed files with 479 additions and 0 deletions

View File

@ -8,6 +8,8 @@ set(JOBS_SRC
jobs/createpartitiontablejob.cpp
jobs/createvolumegroupjob.cpp
jobs/removevolumegroupjob.cpp
jobs/resizevolumegroupjob.cpp
jobs/movephysicalvolumejob.cpp
jobs/setfilesystemlabeljob.cpp
jobs/deletepartitionjob.cpp
jobs/restorefilesystemjob.cpp

View File

@ -0,0 +1,63 @@
/*************************************************************************
* Copyright (C) 2016 by Chantara Tith <tith.chantara@gmail.com> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/
#include "jobs/movephysicalvolumejob.h"
#include "core/lvmdevice.h"
#include "util/report.h"
#include <KLocalizedString>
/** Creates a new MovePhysicalVolumeJob
@param vgname
@parem pvList
*/
MovePhysicalVolumeJob::MovePhysicalVolumeJob(LvmDevice& dev, const QStringList partlist) :
Job(),
m_Device(dev),
m_PartList(partlist)
{
}
bool MovePhysicalVolumeJob::run(Report& parent)
{
bool rval = false;
Report* report = jobStarted(parent);
//TODO:check that the provided list is legal
foreach (QString partPath, partList()) {
rval = LvmDevice::movePV(*report, device(), partPath);
if (rval == false) {
break;
}
}
jobFinished(*report, rval);
return rval;
}
QString MovePhysicalVolumeJob::description() const
{
QString tmp = QString();
foreach (QString path, partList()) {
tmp += path + QStringLiteral(",");
}
return xi18nc("@info/plain", "Move used PE in %1 on %2 to other available Physical Volumes", tmp, device().name());
}

View File

@ -0,0 +1,55 @@
/*************************************************************************
* Copyright (C) 2016 by Chantara Tith <tith.chantara@gmail.com> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/
#if !defined(MOVEPHYSICALVOLUMEJOB_H)
#define MOVEPHYSICALVOLUMEJOB_H
#include "jobs/job.h"
class LvmDevice;
class Report;
class QString;
class MovePhysicalVolumeJob : public Job
{
public:
MovePhysicalVolumeJob(LvmDevice& dev, const QStringList partlist);
public:
bool run(Report& parent) override;
QString description() const override;
protected:
LvmDevice& device() {
return m_Device;
}
const LvmDevice& device() const {
return m_Device;
}
const QStringList partList() const {
return m_PartList;
}
private:
LvmDevice& m_Device;
const QStringList m_PartList;
};
#endif

View File

@ -0,0 +1,74 @@
/*************************************************************************
* Copyright (C) 2016 by Chantara Tith <tith.chantara@gmail.com> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/
#include "jobs/resizevolumegroupjob.h"
#include "core/lvmdevice.h"
#include "util/report.h"
#include <KLocalizedString>
/** Creates a new ResizeVolumeGroupJob
@param vgname
@parem pvList
*/
ResizeVolumeGroupJob::ResizeVolumeGroupJob(LvmDevice& dev, const QStringList partlist, const Type type) :
Job(),
m_Device(dev),
m_PartList(partlist),
m_Type(type)
{
}
bool ResizeVolumeGroupJob::run(Report& parent)
{
bool rval = false;
Report* report = jobStarted(parent);
//TODO:check that the provided list is legal
foreach (QString pvpath, partList()) {
if (type() == ResizeVolumeGroupJob::Grow) {
rval = LvmDevice::insertPV(*report, device(), pvpath);
} else if (type() == ResizeVolumeGroupJob::Shrink) {
rval = LvmDevice::removePV(*report, device(), pvpath);
}
if (rval == false) {
break;
}
}
jobFinished(*report, rval);
return rval;
}
QString ResizeVolumeGroupJob::description() const
{
QString tmp = QString();
foreach (QString path, partList()) {
tmp += path + QStringLiteral(",");
}
if (type() == ResizeVolumeGroupJob::Grow) {
return xi18nc("@info/plain", "Inserting Volume: %1 to %2.", tmp, device().name());
}
if (type() == ResizeVolumeGroupJob::Shrink) {
return xi18nc("@info/plain", "Removing Volume: %1 from %2.", tmp, device().name());
}
return xi18nc("@info/plain", "Resizing Volume: %1 to %2.", device().name(), tmp);
}

View File

@ -0,0 +1,67 @@
/*************************************************************************
* Copyright (C) 2016 by Chantara Tith <tith.chantara@gmail.com> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/
#if !defined(RESIZEVOLUMEGROUPJOB_H)
#define RESIZEVOLUMEGROUPJOB_H
#include "jobs/job.h"
class LvmDevice;
class Report;
class QString;
class ResizeVolumeGroupJob : public Job
{
public:
enum Type {
Grow = 0,
Shrink = 1
};
public:
ResizeVolumeGroupJob(LvmDevice& dev, const QStringList partlist, const Type type);
public:
bool run(Report& parent) override;
QString description() const override;
protected:
LvmDevice& device() {
return m_Device;
}
const LvmDevice& device() const {
return m_Device;
}
const QStringList partList() const {
return m_PartList;
}
const Type type() const {
return m_Type;
}
private:
LvmDevice& m_Device;
const QStringList m_PartList;
const Type m_Type;
};
#endif

View File

@ -8,6 +8,7 @@ set(OPS_SRC
ops/createpartitiontableoperation.cpp
ops/createvolumegroupoperation.cpp
ops/removevolumegroupoperation.cpp
ops/resizevolumegroupoperation.cpp
ops/setfilesystemlabeloperation.cpp
ops/setpartflagsoperation.cpp
ops/checkoperation.cpp
@ -23,6 +24,7 @@ set(OPS_LIB_HDRS
ops/createpartitiontableoperation.h
ops/createvolumegroupoperation.h
ops/removevolumegroupoperation.h
ops/resizevolumegroupoperation.h
ops/deleteoperation.h
ops/newoperation.h
ops/operation.h

View File

@ -0,0 +1,118 @@
/*************************************************************************
* Copyright (C) 2016 by Chantara Tith <tith.chantara@gmail.com> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/
#include "ops/resizevolumegroupoperation.h"
#include "core/lvmdevice.h"
#include "fs/lvm2_pv.h"
#include "core/partition.h"
#include "jobs/resizevolumegroupjob.h"
#include "jobs/movephysicalvolumejob.h"
#include <QString>
#include <KLocalizedString>
/** Creates a new ResizeVolumeGroupOperation.
@param d the Device to create the new PartitionTable on
@param t the type for the new PartitionTable
*/
ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(LvmDevice& dev, const QStringList partlist) :
Operation(),
m_Device(dev),
m_TargetList(partlist),
m_CurrentList(LvmDevice::getPVs(dev.name())),
m_GrowVolumeGroupJob(nullptr),
m_ShrinkVolumeGroupJob(nullptr),
m_MovePhysicalVolumeJob(nullptr)
{
const QStringList clist = LvmDevice::getPVs(dev.name());
QStringList toRemoveList = clist;
foreach (QString path, partlist) {
if (toRemoveList.contains(path)) {
toRemoveList.removeAll(path);
}
}
QStringList toInsertList = partlist;
foreach (QString path, clist) {
if (toInsertList.contains(path)) {
toInsertList.removeAll(path);
}
}
qint64 freePE = FS::lvm2_pv::getFreePE(clist) - FS::lvm2_pv::getFreePE(toRemoveList);
qint64 movePE = FS::lvm2_pv::getAllocatedPE(toRemoveList);
qint64 growPE = FS::lvm2_pv::getPVSize(toInsertList) / LvmDevice::getPeSize(dev.name());
if ( movePE > (freePE + growPE)) {
// *ABORT* can't move
} else if (partlist == clist) {
// *DO NOTHING*
} else {
if (!toInsertList.isEmpty()) {
m_GrowVolumeGroupJob = new ResizeVolumeGroupJob(dev, toInsertList, ResizeVolumeGroupJob::Grow);
addJob(growVolumeGroupJob());
}
if (!toRemoveList.isEmpty()) {
m_MovePhysicalVolumeJob = new MovePhysicalVolumeJob(dev, toRemoveList);
m_ShrinkVolumeGroupJob = new ResizeVolumeGroupJob(dev, toRemoveList, ResizeVolumeGroupJob::Shrink);
addJob(movePhysicalVolumeJob());
addJob(shrinkvolumegroupjob());
}
}
}
QString ResizeVolumeGroupOperation::description() const
{
QString tlist = QString();
foreach (QString path, targetList()) {
tlist += path + QStringLiteral(",");
}
QString clist = QString();
foreach (QString path, currentList()) {
clist += path + QStringLiteral(",");
}
return xi18nc("@info/plain", "Resize volume %1 From\n%2 To\n%3", device().name(), clist, tlist);
}
bool ResizeVolumeGroupOperation::targets(const Device& d) const
{
return d == device();
}
bool ResizeVolumeGroupOperation::targets(const Partition& part) const
{
foreach (QString partPath, targetList()) {
if (partPath == part.partitionPath()) {
return true;
}
}
return false;
}
void ResizeVolumeGroupOperation::preview()
{
}
void ResizeVolumeGroupOperation::undo()
{
}

View File

@ -0,0 +1,98 @@
/*************************************************************************
* Copyright (C) 2016 by Chantara Tith <tith.chantara@gmail.com> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/
#if !defined(RESIZEVOLUMEGROUPOPERATION_H)
#define RESIZEVOLUMEGROUPOPERATION_H
#include "util/libpartitionmanagerexport.h"
#include "ops/operation.h"
#include "core/lvmdevice.h"
#include <QString>
class ResizeVolumeGroupJob;
class MovePhysicalVolumeJob;
class OperationStack;
class LvmDevice;
class LIBKPMCORE_EXPORT ResizeVolumeGroupOperation : public Operation
{
Q_DISABLE_COPY(ResizeVolumeGroupOperation)
friend class OperationStack;
public:
ResizeVolumeGroupOperation(LvmDevice& dev, const QStringList partlist);
public:
QString iconName() const override {
return QStringLiteral("arrow-right-double");
}
QString description() const override;
virtual bool targets(const Device&) const override;
virtual bool targets(const Partition&) const override;
virtual void preview() override;
virtual void undo() override;
QStringList getToRemoveList();
QStringList getToInsertList();
protected:
LvmDevice& device() {
return m_Device;
}
const LvmDevice& device() const {
return m_Device;
}
const QStringList targetList() const {
return m_TargetList;
}
const QStringList currentList() const {
return m_CurrentList;
}
ResizeVolumeGroupJob* growVolumeGroupJob() {
return m_GrowVolumeGroupJob;
}
ResizeVolumeGroupJob* shrinkvolumegroupjob() {
return m_ShrinkVolumeGroupJob;
}
MovePhysicalVolumeJob* movePhysicalVolumeJob() {
return m_MovePhysicalVolumeJob;
}
private:
LvmDevice& m_Device;
const QStringList m_TargetList;
const QStringList m_CurrentList;
ResizeVolumeGroupJob *m_GrowVolumeGroupJob;
ResizeVolumeGroupJob *m_ShrinkVolumeGroupJob;
MovePhysicalVolumeJob *m_MovePhysicalVolumeJob;
};
#endif