2016-07-09 01:10:57 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2016 by Chantara Tith <tith.chantara@gmail.com> *
|
2016-11-04 14:20:11 +00:00
|
|
|
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
2016-07-09 01:10:57 +01:00
|
|
|
* *
|
|
|
|
* 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"
|
2016-10-30 13:36:01 +00:00
|
|
|
#include "fs/luks.h"
|
2016-07-09 01:10:57 +01:00
|
|
|
|
|
|
|
#include "util/report.h"
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
/** Creates a new ResizeVolumeGroupJob
|
|
|
|
*/
|
2016-09-18 01:53:42 +01:00
|
|
|
ResizeVolumeGroupJob::ResizeVolumeGroupJob(LvmDevice& dev, const QList <const Partition*>& partlist, const Type type) :
|
2016-07-09 01:10:57 +01:00
|
|
|
Job(),
|
|
|
|
m_Device(dev),
|
|
|
|
m_PartList(partlist),
|
|
|
|
m_Type(type)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ResizeVolumeGroupJob::run(Report& parent)
|
|
|
|
{
|
|
|
|
bool rval = false;
|
|
|
|
|
|
|
|
Report* report = jobStarted(parent);
|
|
|
|
|
2016-09-18 01:53:42 +01:00
|
|
|
for (const auto &p : partList()) {
|
2016-10-30 13:36:01 +00:00
|
|
|
const QString deviceNode = p->roles().has(PartitionRole::Luks) ? static_cast<const FS::luks*>(&p->fileSystem())->mapperName() : p->partitionPath();
|
2016-09-18 01:53:42 +01:00
|
|
|
if (type() == ResizeVolumeGroupJob::Grow)
|
2016-10-30 13:36:01 +00:00
|
|
|
rval = LvmDevice::insertPV(*report, device(), deviceNode);
|
2016-09-18 01:53:42 +01:00
|
|
|
else if (type() == ResizeVolumeGroupJob::Shrink)
|
2016-10-30 13:36:01 +00:00
|
|
|
rval = LvmDevice::removePV(*report, device(), deviceNode);
|
2016-09-18 01:53:42 +01:00
|
|
|
|
|
|
|
if (rval == false)
|
2016-07-09 01:10:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobFinished(*report, rval);
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ResizeVolumeGroupJob::description() const
|
|
|
|
{
|
2016-09-18 01:53:42 +01:00
|
|
|
QString partitionList = QString();
|
|
|
|
for (const auto &p : partList()) {
|
2016-11-03 22:15:43 +00:00
|
|
|
partitionList += p->deviceNode() + QStringLiteral(", ");
|
2016-09-18 01:53:42 +01:00
|
|
|
}
|
|
|
|
partitionList.chop(2);
|
2016-08-26 13:29:24 +01:00
|
|
|
const qint32 count = partList().count();
|
2016-08-12 01:56:50 +01:00
|
|
|
|
2016-07-09 01:10:57 +01:00
|
|
|
if (type() == ResizeVolumeGroupJob::Grow) {
|
2016-08-26 13:29:24 +01:00
|
|
|
return xi18ncp("@info/plain", "Adding LVM Physical Volume %2 to %3.", "Adding LVM Physical Volumes %2 to %3.", count, partitionList, device().name());
|
2016-07-09 01:10:57 +01:00
|
|
|
}
|
|
|
|
if (type() == ResizeVolumeGroupJob::Shrink) {
|
2016-08-26 13:29:24 +01:00
|
|
|
return xi18ncp("@info/plain", "Removing LVM Physical Volume %2 from %3.", "Removing LVM Physical Volumes %2 from %3.", count, partitionList, device().name());
|
2016-07-09 01:10:57 +01:00
|
|
|
}
|
2016-08-26 13:29:24 +01:00
|
|
|
return xi18nc("@info/plain", "Resizing Volume Group %1 to %2.", device().name(), partitionList);
|
2016-07-09 01:10:57 +01:00
|
|
|
}
|