diff --git a/src/jobs/createvolumegroupjob.cpp b/src/jobs/createvolumegroupjob.cpp index 1891bc8..8476757 100644 --- a/src/jobs/createvolumegroupjob.cpp +++ b/src/jobs/createvolumegroupjob.cpp @@ -1,61 +1,90 @@ /************************************************************************* * Copyright (C) 2016 by Chantara Tith * * Copyright (C) 2016 by Andrius Štikonas * + * Copyright (C) 2018 by Caio Carvalho * * * * 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 .* *************************************************************************/ #include "jobs/createvolumegroupjob.h" #include "core/lvmdevice.h" +#include "core/raid/softwareraid.h" #include "util/report.h" #include /** Creates a new CreateVolumeGroupJob * @param vgName LVM Volume Group name * @param pvList List of LVM Physical Volumes used to create Volume Group * @param peSize LVM Physical Extent size in MiB */ -CreateVolumeGroupJob::CreateVolumeGroupJob(const QString& vgName, const QVector& pvList, const qint32 peSize) : - Job(), - m_vgName(vgName), - m_pvList(pvList), - m_PESize(peSize) +CreateVolumeGroupJob::CreateVolumeGroupJob(const QString& vgName, const QVector& pvList, + const Device::Type type, const qint32 peSize) + : Job() + , m_vgName(vgName) + , m_pvList(pvList) + , m_type(type) + , m_PESize(peSize) + , m_raidLevel(-1) + , m_chunkSize(-1) +{ +} + +CreateVolumeGroupJob::CreateVolumeGroupJob(const QString& vgName, const QVector& pvList, + const Device::Type type, const qint32 raidLevel, const qint32 chunkSize) + : Job() + , m_vgName(vgName) + , m_pvList(pvList) + , m_type(type) + , m_PESize(-1) + , m_raidLevel(raidLevel) + , m_chunkSize(chunkSize) { } bool CreateVolumeGroupJob::run(Report& parent) { bool rval = false; Report* report = jobStarted(parent); - rval = LvmDevice::createVG(*report, vgName(), pvList(), peSize()); + if (type() == Device::Type::LVM_Device) + rval = LvmDevice::createVG(*report, vgName(), pvList(), peSize()); + else if (type() == Device::Type::SoftwareRAID_Device) { + QStringList pathList; + + for (auto partition : pvList()) + pathList << partition->partitionPath(); + + rval = SoftwareRAID::createSoftwareRAID(*report, vgName(), pathList, raidLevel(), chunkSize()); + } jobFinished(*report, rval); return rval; } QString CreateVolumeGroupJob::description() const { - QString tmp = QString(); - for (const auto &p : pvList()) { + QString tmp; + + for (const auto &p : pvList()) tmp += p->deviceNode() + QStringLiteral(", "); - } + tmp.chop(2); + return xi18nc("@info/plain", "Create a new Volume Group: %1 with PV: %2", vgName(), tmp); } diff --git a/src/jobs/createvolumegroupjob.h b/src/jobs/createvolumegroupjob.h index 3935ce6..5d3fc77 100644 --- a/src/jobs/createvolumegroupjob.h +++ b/src/jobs/createvolumegroupjob.h @@ -1,65 +1,81 @@ /************************************************************************* * Copyright (C) 2016 by Chantara Tith * + * Copyright (C) 2018 by Caio Carvalho * * * * 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 .* *************************************************************************/ #if !defined(KPMCORE_CREATEVOLUMEGROUPJOB_H) #define KPMCORE_CREATEVOLUMEGROUPJOB_H #include "core/partition.h" +#include "core/volumemanagerdevice.h" #include "jobs/job.h" #include class LvmDevice; class Report; class QString; class CreateVolumeGroupJob : public Job { public: - CreateVolumeGroupJob(const QString& vgName, const QVector& pvList, const qint32 peSize); + CreateVolumeGroupJob(const QString& vgName, const QVector& pvList, + const Device::Type type, const qint32 peSize); + + CreateVolumeGroupJob(const QString &vgName, const QVector &pvList, + const Device::Type type, const qint32 raidLevel, const qint32 chunkSize); public: bool run(Report& parent) override; QString description() const override; protected: - QString vgName() { - return m_vgName; - } const QString vgName() const { return m_vgName; } - QVector& pvList() { - return m_pvList; - } + const QVector& pvList() const { return m_pvList; } - qint32 peSize() { + qint32 peSize() const { return m_PESize; } + Device::Type type() const { + return m_type; + } + + qint32 raidLevel() const { + return m_raidLevel; + } + + qint32 chunkSize() const { + return m_chunkSize; + } + private: QString m_vgName; QVector m_pvList; + Device::Type m_type; qint32 m_PESize; + qint32 m_raidLevel; + qint32 m_chunkSize; }; #endif diff --git a/src/ops/createvolumegroupoperation.cpp b/src/ops/createvolumegroupoperation.cpp index 5930905..5911ed2 100644 --- a/src/ops/createvolumegroupoperation.cpp +++ b/src/ops/createvolumegroupoperation.cpp @@ -1,75 +1,96 @@ /************************************************************************* * Copyright (C) 2016 by Chantara Tith * * Copyright (C) 2016 by Andrius Štikonas * + * Copyright (C) 2018 by Caio Carvalho * * * * 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 .* *************************************************************************/ #include "ops/createvolumegroupoperation.h" #include "core/lvmdevice.h" #include "fs/lvm2_pv.h" #include "jobs/createvolumegroupjob.h" #include #include /** Creates a new CreateVolumeGroupOperation. * @param vgName LVM Volume Group name * @param pvList List of LVM Physical Volumes used to create Volume Group * @param peSize LVM Physical Extent size in MiB */ -CreateVolumeGroupOperation::CreateVolumeGroupOperation(const QString& vgName, const QVector& pvList, const qint32 peSize) : - Operation(), - m_CreateVolumeGroupJob(new CreateVolumeGroupJob(vgName, pvList, peSize)), - m_PVList(pvList), - m_vgName(vgName) +CreateVolumeGroupOperation::CreateVolumeGroupOperation(const QString& vgName, const QVector& pvList, + const Device::Type type, const qint32 peSize) + : Operation() + , m_CreateVolumeGroupJob(new CreateVolumeGroupJob(vgName, pvList, type, peSize)) + , m_PVList(pvList) + , m_vgName(vgName) +{ + addJob(createVolumeGroupJob()); +} + +CreateVolumeGroupOperation::CreateVolumeGroupOperation(const QString &vgName, const QVector &pvList, + const Device::Type type, const qint32 raidLevel, + const qint32 chunkSize) + : Operation() + , m_CreateVolumeGroupJob(new CreateVolumeGroupJob(vgName, pvList, type, raidLevel, chunkSize)) + , m_PVList(pvList) + , m_vgName(vgName) { addJob(createVolumeGroupJob()); } QString CreateVolumeGroupOperation::description() const { - return xi18nc("@info/plain", "Create a new LVM volume group named \'%1\'.", m_vgName); + return xi18nc("@info/plain", "Create a new volume group named \'%1\'.", m_vgName); } bool CreateVolumeGroupOperation::targets(const Partition& partition) const { for (const auto &p : m_PVList) { if (partition == *p) return true; } return false; } void CreateVolumeGroupOperation::preview() { - LvmDevice::s_DirtyPVs << PVList(); + if (type() == Device::Type::LVM_Device) + LvmDevice::s_DirtyPVs << PVList(); + else if (type() == Device::Type::SoftwareRAID_Device) { + // TODO: Set it for RAID + } } void CreateVolumeGroupOperation::undo() { - for (const auto &pvPath : PVList()) { - if (LvmDevice::s_DirtyPVs.contains(pvPath)) { - LvmDevice::s_DirtyPVs.removeAll(pvPath); - } + if (type() == Device::Type::LVM_Device) { + for (const auto &pvPath : PVList()) + if (LvmDevice::s_DirtyPVs.contains(pvPath)) + LvmDevice::s_DirtyPVs.removeAll(pvPath); + } + else if (type() == Device::Type::SoftwareRAID_Device) { + // TODO: Set it for RAID + } } bool CreateVolumeGroupOperation::canCreate() { return true; } diff --git a/src/ops/createvolumegroupoperation.h b/src/ops/createvolumegroupoperation.h index 4fa49f2..fd73261 100644 --- a/src/ops/createvolumegroupoperation.h +++ b/src/ops/createvolumegroupoperation.h @@ -1,75 +1,87 @@ /************************************************************************* * Copyright (C) 2016 by Chantara Tith * * Copyright (C) 2016 by Andrius Štikonas * + * Copyright (C) 2018 by Caio Carvalho * * * * 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 .* *************************************************************************/ #if !defined(KPMCORE_CREATEVOLUMEGROUPOPERATION_H) #define KPMCORE_CREATEVOLUMEGROUPOPERATION_H #include "util/libpartitionmanagerexport.h" #include "ops/operation.h" #include "core/lvmdevice.h" +#include "core/volumemanagerdevice.h" #include class CreateVolumeGroupJob; class OperationStack; class LIBKPMCORE_EXPORT CreateVolumeGroupOperation : public Operation { Q_DISABLE_COPY(CreateVolumeGroupOperation) friend class OperationStack; public: - CreateVolumeGroupOperation(const QString& vgName, const QVector& pvList, const qint32 peSize = 4); + CreateVolumeGroupOperation(const QString& vgName, const QVector& pvList, + const Device::Type type, const qint32 peSize = 4); + + CreateVolumeGroupOperation(const QString& vgName, const QVector& pvList, + const Device::Type type, const qint32 raidLevel, + const qint32 chunkSize); public: QString iconName() const override { return QStringLiteral("document-new"); } QString description() const override; virtual bool targets(const Device&) const override { return true; } virtual bool targets(const Partition&) const override; virtual void preview() override; virtual void undo() override; static bool canCreate(); protected: - CreateVolumeGroupJob* createVolumeGroupJob() { + CreateVolumeGroupJob* createVolumeGroupJob() const { return m_CreateVolumeGroupJob; } - const QVector& PVList() { + const QVector& PVList() const { return m_PVList; } + Device::Type type() const { + return m_type; + } + private: CreateVolumeGroupJob* m_CreateVolumeGroupJob; const QVector m_PVList; QString m_vgName; + Device::Type m_type; }; #endif