2020-09-30 23:28:47 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
|
|
|
|
SPDX-FileCopyrightText: 2016-2017 Andrius Štikonas <andrius@stikonas.eu>
|
2020-10-01 00:33:19 +01:00
|
|
|
SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho <caiojcarvalho@gmail.com>
|
2020-09-30 23:28:47 +01:00
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2016-06-30 00:18:46 +01:00
|
|
|
|
|
|
|
#include "ops/createvolumegroupoperation.h"
|
|
|
|
|
|
|
|
#include "core/lvmdevice.h"
|
2016-07-03 13:41:20 +01:00
|
|
|
#include "fs/lvm2_pv.h"
|
2016-06-30 00:18:46 +01:00
|
|
|
|
|
|
|
#include "jobs/createvolumegroupjob.h"
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
/** Creates a new CreateVolumeGroupOperation.
|
2016-08-12 01:57:34 +01:00
|
|
|
* @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
|
2016-06-30 00:18:46 +01:00
|
|
|
*/
|
2018-08-14 00:08:17 +01:00
|
|
|
CreateVolumeGroupOperation::CreateVolumeGroupOperation(const QString& vgName, const QVector<const Partition*>& 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<const Partition *> &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)
|
2016-06-30 00:18:46 +01:00
|
|
|
{
|
|
|
|
addJob(createVolumeGroupJob());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CreateVolumeGroupOperation::description() const
|
|
|
|
{
|
2018-08-14 00:08:17 +01:00
|
|
|
return xi18nc("@info/plain", "Create a new volume group named \'%1\'.", m_vgName);
|
2016-06-30 00:18:46 +01:00
|
|
|
}
|
|
|
|
|
2018-05-04 00:48:11 +01:00
|
|
|
bool CreateVolumeGroupOperation::targets(const Partition& partition) const
|
2016-06-30 00:18:46 +01:00
|
|
|
{
|
2018-05-04 00:48:11 +01:00
|
|
|
for (const auto &p : m_PVList) {
|
|
|
|
if (partition == *p)
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-30 00:18:46 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-03 13:41:20 +01:00
|
|
|
void CreateVolumeGroupOperation::preview()
|
2016-06-30 00:18:46 +01:00
|
|
|
{
|
2018-08-14 00:08:17 +01:00
|
|
|
if (type() == Device::Type::LVM_Device)
|
|
|
|
LvmDevice::s_DirtyPVs << PVList();
|
|
|
|
else if (type() == Device::Type::SoftwareRAID_Device) {
|
|
|
|
// TODO: Set it for RAID
|
|
|
|
}
|
2016-06-30 00:18:46 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 13:41:20 +01:00
|
|
|
void CreateVolumeGroupOperation::undo()
|
2016-06-30 00:18:46 +01:00
|
|
|
{
|
2018-08-14 00:08:17 +01:00
|
|
|
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
|
|
|
|
|
2016-08-08 08:03:58 +01:00
|
|
|
}
|
2016-06-30 00:18:46 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 13:41:20 +01:00
|
|
|
bool CreateVolumeGroupOperation::canCreate()
|
2016-06-30 00:18:46 +01:00
|
|
|
{
|
2016-07-03 13:41:20 +01:00
|
|
|
return true;
|
2016-06-30 00:18:46 +01:00
|
|
|
}
|