diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index b32733b..90cf852 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -196,18 +196,19 @@ void LvmDevice::scanSystemLVM(QList& devices) lvmList.append(new LvmDevice(vgName)); } - // Some LVM operations require additional information about LVM physical volumes which we store in LVM::pvList - LVM::pvList = FS::lvm2_pv::getPVs(devices); + // Some LVM operations require additional information about LVM physical volumes which we store in LVM::pvList::list() + LVM::pvList::list().clear(); + LVM::pvList::list().append(FS::lvm2_pv::getPVs(devices)); // Look for LVM physical volumes in LVM VGs for (const auto &d : lvmList) { devices.append(d); - LVM::pvList.append(FS::lvm2_pv::getPVinNode(d->partitionTable())); + LVM::pvList::list().append(FS::lvm2_pv::getPVinNode(d->partitionTable())); } // Inform LvmDevice about which physical volumes form that particular LvmDevice for (const auto &d : lvmList) - for (const auto &p : qAsConst(LVM::pvList)) + for (const auto &p : qAsConst(LVM::pvList::list())) if (p.vgName() == d->name()) d->physicalVolumes().append(p.partition()); diff --git a/src/fs/luks.cpp b/src/fs/luks.cpp index ebd37e6..a79b0f9 100644 --- a/src/fs/luks.cpp +++ b/src/fs/luks.cpp @@ -287,7 +287,7 @@ bool luks::cryptOpen(QWidget* parent, const QString& deviceNode) if (!m_isCryptOpen) return false; - for (auto &p : LVM::pvList) + for (auto &p : LVM::pvList::list()) if (p.isLuks() && p.partition()->deviceNode() == deviceNode && p.partition()->fileSystem().type() == FileSystem::Type::Lvm2_PV) p.setLuks(false); @@ -326,7 +326,7 @@ bool luks::cryptClose(const QString& deviceNode) m_isCryptOpen = (m_innerFs != nullptr); - for (auto &p : LVM::pvList) + for (auto &p : LVM::pvList::list()) if (!p.isLuks() && p.partition()->deviceNode() == deviceNode) p.setLuks(true); diff --git a/src/fs/lvm2_pv.cpp b/src/fs/lvm2_pv.cpp index 92778e6..6a3a4c7 100644 --- a/src/fs/lvm2_pv.cpp +++ b/src/fs/lvm2_pv.cpp @@ -296,7 +296,11 @@ QList lvm2_pv::getPVs(const QList& devices) } -QList LVM::pvList; +namespace LVM { + +QList pvList::m_list; + +} LvmPV::LvmPV(const QString vgName, const Partition* p, bool isLuks) : m_vgName(vgName) diff --git a/src/fs/lvm2_pv.h b/src/fs/lvm2_pv.h index 895d26e..15bbd92 100644 --- a/src/fs/lvm2_pv.h +++ b/src/fs/lvm2_pv.h @@ -62,7 +62,22 @@ private: }; namespace LVM { - extern LIBKPMCORE_EXPORT QList pvList; +/** Class to access a global LVM PV list. + @author Caio Carvalho +*/ +class LIBKPMCORE_EXPORT pvList +{ +public: + static QList &list() { + return m_list; + } + +private: + pvList() { } + +private: + static QList m_list; +}; } namespace FS diff --git a/src/ops/deleteoperation.cpp b/src/ops/deleteoperation.cpp index f0168e4..3f2c52f 100644 --- a/src/ops/deleteoperation.cpp +++ b/src/ops/deleteoperation.cpp @@ -128,7 +128,7 @@ bool DeleteOperation::canDelete(const Partition* p, const QList pen } else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) { // See if innerFS is LVM - FileSystem *fs = dynamic_cast(&p->fileSystem())->innerFS(); + FileSystem *fs = static_cast(&p->fileSystem())->innerFS(); if (fs) { if (fs->type() == FileSystem::Type::Lvm2_PV) { diff --git a/src/ops/resizeoperation.cpp b/src/ops/resizeoperation.cpp index 8c44f7b..d73df26 100644 --- a/src/ops/resizeoperation.cpp +++ b/src/ops/resizeoperation.cpp @@ -329,11 +329,14 @@ bool ResizeOperation::grow(Report& report) @param p the Partition in question, may be nullptr. @return true if @p p can be grown. */ -bool ResizeOperation::canGrow(const Partition* p) +bool ResizeOperation::canGrow(const Partition* p, const QList pendingOps) { if (p == nullptr) return false; + if (isLVMPVinNewlyVG(p, pendingOps)) + return false; + // we can always grow, shrink or move a partition not yet written to disk if (p->state() == Partition::State::New && !p->roles().has(PartitionRole::Luks)) return true; @@ -353,27 +356,8 @@ bool ResizeOperation::canShrink(const Partition* p, const QList pen if (p == nullptr) return false; - if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV) { - // See if there is a newly created VG targeting this partition - for (Operation *op : qAsConst(pendingOps)) { - if (dynamic_cast(op) && op->targets(*p)) - return false; - } - } - else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) { - // See if innerFS is LVM - FileSystem *fs = dynamic_cast(&p->fileSystem())->innerFS(); - - if (fs) { - if (fs->type() == FileSystem::Type::Lvm2_PV) { - // See if there is a newly created VG targeting this partition - for (Operation *op : qAsConst(pendingOps)) { - if (dynamic_cast(op) && op->targets(*p)) - return false; - } - } - } - } + if (isLVMPVinNewlyVG(p, pendingOps)) + return false; // we can always grow, shrink or move a partition not yet written to disk if (p->state() == Partition::State::New && !p->roles().has(PartitionRole::Luks)) @@ -397,27 +381,8 @@ bool ResizeOperation::canMove(const Partition* p, const QList pendi if (p == nullptr) return false; - if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV) { - // See if there is a newly created VG targeting this partition - for (Operation *op : qAsConst(pendingOps)) { - if (dynamic_cast(op) && op->targets(*p)) - return false; - } - } - else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) { - // See if innerFS is LVM - FileSystem *fs = dynamic_cast(&p->fileSystem())->innerFS(); - - if (fs) { - if (fs->type() == FileSystem::Type::Lvm2_PV) { - // See if there is a newly created VG targeting this partition - for (Operation *op : qAsConst(pendingOps)) { - if (dynamic_cast(op) && op->targets(*p)) - return false; - } - } - } - } + if (isLVMPVinNewlyVG(p, pendingOps)) + return false; // we can always grow, shrink or move a partition not yet written to disk if (p->state() == Partition::State::New) @@ -433,3 +398,30 @@ bool ResizeOperation::canMove(const Partition* p, const QList pendi return p->fileSystem().supportMove() != FileSystem::cmdSupportNone; } + +bool ResizeOperation::isLVMPVinNewlyVG(const Partition *p, const QList pendingOps) +{ + if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV) { + // See if there is a newly created VG targeting this partition + for (Operation *op : qAsConst(pendingOps)) { + if (dynamic_cast(op) && op->targets(*p)) + return true; + } + } + else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) { + // See if innerFS is LVM + FileSystem *fs = static_cast(&p->fileSystem())->innerFS(); + + if (fs) { + if (fs->type() == FileSystem::Type::Lvm2_PV) { + // See if there is a newly created VG targeting this partition + for (Operation *op : qAsConst(pendingOps)) { + if (dynamic_cast(op) && op->targets(*p)) + return true; + } + } + } + } + + return false; +} diff --git a/src/ops/resizeoperation.h b/src/ops/resizeoperation.h index 820edc7..975d08f 100644 --- a/src/ops/resizeoperation.h +++ b/src/ops/resizeoperation.h @@ -85,7 +85,7 @@ public: bool targets(const Device& d) const override; bool targets(const Partition& p) const override; - static bool canGrow(const Partition* p); + static bool canGrow(const Partition* p, const QList pendingOps = QList()); static bool canShrink(const Partition* p, const QList pendingOps = QList()); static bool canMove(const Partition* p, const QList pendingOps = QList()); @@ -158,6 +158,9 @@ protected: return m_CheckResizedJob; } +private: + static bool isLVMPVinNewlyVG(const Partition* p, const QList pendingOps); + private: Device& m_TargetDevice; Partition& m_Partition;