Add deactivating VG and LV jobs.

This commit is contained in:
Chantara Tith 2016-08-08 12:53:24 +07:00 committed by Andrius Štikonas
parent ca2bbb27d7
commit d033dc9827
5 changed files with 226 additions and 0 deletions

View File

@ -8,6 +8,8 @@ set(JOBS_SRC
jobs/createpartitiontablejob.cpp
jobs/createvolumegroupjob.cpp
jobs/removevolumegroupjob.cpp
jobs/deactivatevolumegroupjob.cpp
jobs/deactivatelogicalvolumejob.cpp
jobs/resizevolumegroupjob.cpp
jobs/movephysicalvolumejob.cpp
jobs/setfilesystemlabeljob.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/deactivatelogicalvolumejob.h"
#include "core/lvmdevice.h"
#include "core/partition.h"
#include "core/partitiontable.h"
#include "util/report.h"
#include <KLocalizedString>
/** Creates a new DeactivateLogicalVolumeJob
@param vgname
@parem pvList
*/
DeactivateLogicalVolumeJob::DeactivateLogicalVolumeJob(VolumeManagerDevice& dev, QStringList lvPaths) :
Job(),
m_Device(dev),
m_LVList(lvPaths)
{
}
bool DeactivateLogicalVolumeJob::run(Report& parent)
{
bool rval = true;
Report* report = jobStarted(parent);
if (device().type() == Device::LVM_Device) {
foreach (Partition* part, device().partitionTable()->children()) {
if (!part->roles().has(PartitionRole::Unallocated)) {
if (!LvmDevice::deactivateLV(*report, dynamic_cast<LvmDevice&>(device()), *part)) {
rval = false;
}
}
}
}
jobFinished(*report, rval);
return rval;
}
QString DeactivateLogicalVolumeJob::description() const
{
return xi18nc("@info/plain", "Deactivate Logical Volumes: <filename>%1</filename>", device().prettyDeviceNodeList());
}

View File

@ -0,0 +1,56 @@
/*************************************************************************
* 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(DEACTIVATELOGICALVOLUMEJOB_H)
#define DEACTIVATELOGICALVOLUMEJOB_H
#include "jobs/job.h"
class VolumeManagerDevice;
class Partition;
class Report;
class QString;
class DeactivateLogicalVolumeJob : public Job
{
public:
DeactivateLogicalVolumeJob(VolumeManagerDevice& dev, QStringList lvPaths = {});
public:
bool run(Report& parent) override;
QString description() const override;
protected:
VolumeManagerDevice& device() {
return m_Device;
}
const VolumeManagerDevice& device() const {
return m_Device;
}
QStringList LVList() const {
return m_LVList;
}
private:
VolumeManagerDevice& m_Device;
QStringList m_LVList;
};
#endif

View File

@ -0,0 +1,54 @@
/*************************************************************************
* 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/deactivatevolumegroupjob.h"
#include "core/lvmdevice.h"
#include "util/report.h"
#include <KLocalizedString>
/** Deactivate LVM Volume Group
@param vgname
@parem pvList
*/
DeactivateVolumeGroupJob::DeactivateVolumeGroupJob(VolumeManagerDevice& dev) :
Job(),
m_Device(dev)
{
}
bool DeactivateVolumeGroupJob::run(Report& parent)
{
bool rval = false;
Report* report = jobStarted(parent);
if (device().type() == Device::LVM_Device) {
rval = LvmDevice::deactivateVG(*report, dynamic_cast<LvmDevice&>(device()));
}
jobFinished(*report, rval);
return rval;
}
QString DeactivateVolumeGroupJob::description() const
{
return xi18nc("@info/plain", "Deactivate Volume Group: <filename>%1</filename>", device().name());
}

View File

@ -0,0 +1,51 @@
/*************************************************************************
* 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(DEACTIVATEVOLUMEGROUPJOB_H)
#define DEACTIVATEVOLUMEGROUPJOB_H
#include "jobs/job.h"
class VolumeManagerDevice;
class Partition;
class Report;
class QString;
class DeactivateVolumeGroupJob : public Job
{
public:
DeactivateVolumeGroupJob(VolumeManagerDevice& dev);
public:
bool run(Report& parent) override;
QString description() const override;
protected:
VolumeManagerDevice& device() {
return m_Device;
}
const VolumeManagerDevice& device() const {
return m_Device;
}
private:
VolumeManagerDevice& m_Device;
};
#endif