Adding LvmDevice::s_OrphanPVs shared list to store PVs paths that are member of VGs that will be deleted soon.

This commit is contained in:
Caio Carvalho 2018-07-23 13:34:40 -03:00
parent 75bfd09c9c
commit 4b723be585
3 changed files with 27 additions and 0 deletions

View File

@ -83,6 +83,12 @@ LvmDevice::LvmDevice(const QString& vgName, const QString& iconName)
*/
QVector<const Partition*> LvmDevice::s_DirtyPVs;
/**
* shared list of PVs paths that are member of VGs that will be deleted soon.
*/
QVector<const Partition*> LvmDevice::s_OrphanPVs;
LvmDevice::~LvmDevice()
{
}
@ -199,6 +205,8 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl
*/
void LvmDevice::scanSystemLVM(QList<Device*>& devices)
{
LvmDevice::s_OrphanPVs.clear();
QList<LvmDevice*> lvmList;
for (const auto &vgName : getVGs()) {
lvmList.append(new LvmDevice(vgName));

View File

@ -55,6 +55,7 @@ public:
qint64 partitionSize(QString& partitionPath) const override;
static QVector<const Partition*> s_DirtyPVs;
static QVector<const Partition*> s_OrphanPVs;
static void scanSystemLVM(QList<Device*>& devices);

View File

@ -18,6 +18,7 @@
#include "ops/removevolumegroupoperation.h"
#include "jobs/removevolumegroupjob.h"
#include "core/lvmdevice.h"
#include "core/partition.h"
#include "core/partitiontable.h"
#include "core/volumemanagerdevice.h"
@ -45,11 +46,28 @@ QString RemoveVolumeGroupOperation::description() const
void RemoveVolumeGroupOperation::preview()
{
m_PartitionTable = device().partitionTable();
if (device().type() == Device::Type::LVM_Device) {
LvmDevice& lvm = static_cast<LvmDevice&>(device());
LvmDevice::s_OrphanPVs << lvm.physicalVolumes();
}
device().setPartitionTable(new PartitionTable(PartitionTable::vmd, 0, device().totalLogical() - 1));
}
void RemoveVolumeGroupOperation::undo()
{
if (device().type() == Device::Type::LVM_Device) {
LvmDevice& lvm = static_cast<LvmDevice&>(device());
const QVector<const Partition*> constOrphanList = LvmDevice::s_OrphanPVs;
for (const Partition* p : constOrphanList)
if (lvm.physicalVolumes().contains(p))
LvmDevice::s_OrphanPVs.removeAll(p);
}
device().setPartitionTable(m_PartitionTable);
}