2020-09-30 23:28:47 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
|
|
|
|
SPDX-FileCopyrightText: 2016-2018 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2016-08-08 06:53:48 +01:00
|
|
|
|
|
|
|
#include "ops/deactivatevolumegroupoperation.h"
|
|
|
|
#include "jobs/deactivatevolumegroupjob.h"
|
|
|
|
#include "jobs/deactivatelogicalvolumejob.h"
|
|
|
|
|
|
|
|
#include "core/volumemanagerdevice.h"
|
|
|
|
#include "core/partitiontable.h"
|
2016-08-14 18:25:06 +01:00
|
|
|
#include "core/partition.h"
|
2016-08-08 06:53:48 +01:00
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
/** Creates a new RemoveVolumeGroupOperation.
|
|
|
|
*/
|
2016-08-12 01:57:34 +01:00
|
|
|
DeactivateVolumeGroupOperation::DeactivateVolumeGroupOperation(VolumeManagerDevice& d) :
|
2016-08-08 06:53:48 +01:00
|
|
|
Operation(),
|
2016-08-12 01:57:34 +01:00
|
|
|
m_DeactivateVolumeGroupJob(new DeactivateVolumeGroupJob(d)),
|
|
|
|
m_DeactivateLogicalVolumeJob(new DeactivateLogicalVolumeJob(d)),
|
2016-08-14 16:22:51 +01:00
|
|
|
m_Device(d),
|
|
|
|
m_PartitionTable(d.partitionTable())
|
2016-08-08 06:53:48 +01:00
|
|
|
{
|
|
|
|
addJob(deactivateLogicalVolumeJob());
|
|
|
|
addJob(deactivateVolumeGroupJob());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DeactivateVolumeGroupOperation::description() const
|
|
|
|
{
|
|
|
|
return xi18nc("@info/plain", "Deactivate volume group.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeactivateVolumeGroupOperation::preview()
|
|
|
|
{
|
2016-11-05 13:10:30 +00:00
|
|
|
m_PartitionTable = device().partitionTable();
|
2016-08-14 16:22:51 +01:00
|
|
|
device().setPartitionTable(new PartitionTable(PartitionTable::vmd, 0, device().totalLogical() - 1));
|
2016-08-08 06:53:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeactivateVolumeGroupOperation::undo()
|
|
|
|
{
|
2016-11-05 13:10:30 +00:00
|
|
|
device().setPartitionTable(m_PartitionTable);
|
2016-08-08 06:53:48 +01:00
|
|
|
}
|
2016-08-14 18:25:06 +01:00
|
|
|
|
2016-08-15 07:18:40 +01:00
|
|
|
/** loop through given device's partitions to check if any is mounted.
|
|
|
|
*
|
2016-08-15 17:14:26 +01:00
|
|
|
* @param dev VolumeManagerDevice with initialized partitions
|
2016-08-15 07:18:40 +01:00
|
|
|
* @return false if any of the device's partition is mounted.
|
|
|
|
*/
|
2016-08-14 18:25:06 +01:00
|
|
|
bool DeactivateVolumeGroupOperation::isDeactivatable(const VolumeManagerDevice* dev)
|
|
|
|
{
|
2018-04-09 02:57:45 +01:00
|
|
|
if (dev->type() == Device::Type::LVM_Device) {
|
2016-08-14 18:25:06 +01:00
|
|
|
for (const auto &p : dev->partitionTable()->children()) {
|
|
|
|
if (p->isMounted()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|