Operations should check LvmDevice::s_DirtyPVs instead of check pending CreateVolumeGroupOperations to search for newly LVM PVs.

This commit is contained in:
Caio Carvalho 2018-07-15 19:41:44 -03:00
parent c1e393240b
commit 9138e02726
4 changed files with 32 additions and 35 deletions

View File

@ -16,12 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.* * along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/ *************************************************************************/
#include "ops/createvolumegroupoperation.h"
#include "ops/deleteoperation.h" #include "ops/deleteoperation.h"
#include "core/partition.h" #include "core/partition.h"
#include "core/device.h" #include "core/device.h"
#include "core/lvmdevice.h"
#include "core/partitiontable.h" #include "core/partitiontable.h"
#include "core/raid/softwareraid.h"
#include "fs/luks.h" #include "fs/luks.h"
#include "jobs/deletepartitionjob.h" #include "jobs/deletepartitionjob.h"
@ -111,7 +112,7 @@ void DeleteOperation::checkAdjustLogicalNumbers(Partition& p, bool undo)
@param p the Partition in question, may be nullptr. @param p the Partition in question, may be nullptr.
@return true if @p p can be deleted. @return true if @p p can be deleted.
*/ */
bool DeleteOperation::canDelete(const Partition* p, const QList<Operation *> pendingOps) bool DeleteOperation::canDelete(const Partition* p)
{ {
if (p == nullptr) if (p == nullptr)
return false; return false;
@ -120,11 +121,12 @@ bool DeleteOperation::canDelete(const Partition* p, const QList<Operation *> pen
return false; return false;
if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV) { if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV) {
// See if there is a newly created VG targeting this partition if (LvmDevice::s_DirtyPVs.contains(p))
for (Operation *op : qAsConst(pendingOps)) { return false;
if (dynamic_cast<CreateVolumeGroupOperation *>(op) && op->targets(*p)) }
return false; else if (p->fileSystem().type() == FileSystem::Type::LinuxRaidMember) {
} if (SoftwareRAID::isRaidMember(p->partitionPath()))
return false;
} }
else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) { else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) {
// See if innerFS is LVM // See if innerFS is LVM
@ -132,11 +134,12 @@ bool DeleteOperation::canDelete(const Partition* p, const QList<Operation *> pen
if (fs) { if (fs) {
if (fs->type() == FileSystem::Type::Lvm2_PV) { if (fs->type() == FileSystem::Type::Lvm2_PV) {
// See if there is a newly created VG targeting this partition if (LvmDevice::s_DirtyPVs.contains(p))
for (Operation *op : qAsConst(pendingOps)) { return false;
if (dynamic_cast<CreateVolumeGroupOperation *>(op) && op->targets(*p)) }
return false; else if (fs->type() == FileSystem::Type::LinuxRaidMember) {
} if (SoftwareRAID::isRaidMember(p->partitionPath()))
return false;
} }
} }
} }

View File

@ -68,7 +68,7 @@ public:
bool targets(const Device& d) const override; bool targets(const Device& d) const override;
bool targets(const Partition& p) const override; bool targets(const Partition& p) const override;
static bool canDelete(const Partition* p, const QList<Operation *> pendingOps = QList<Operation *>()); static bool canDelete(const Partition* p);
protected: protected:
Device& targetDevice() { Device& targetDevice() {

View File

@ -20,6 +20,7 @@
#include "core/partition.h" #include "core/partition.h"
#include "core/device.h" #include "core/device.h"
#include "core/lvmdevice.h"
#include "core/partitiontable.h" #include "core/partitiontable.h"
#include "core/copysourcedevice.h" #include "core/copysourcedevice.h"
#include "core/copytargetdevice.h" #include "core/copytargetdevice.h"
@ -30,7 +31,6 @@
#include "jobs/movefilesystemjob.h" #include "jobs/movefilesystemjob.h"
#include "ops/checkoperation.h" #include "ops/checkoperation.h"
#include "ops/createvolumegroupoperation.h"
#include "fs/filesystem.h" #include "fs/filesystem.h"
#include "fs/luks.h" #include "fs/luks.h"
@ -329,12 +329,12 @@ bool ResizeOperation::grow(Report& report)
@param p the Partition in question, may be nullptr. @param p the Partition in question, may be nullptr.
@return true if @p p can be grown. @return true if @p p can be grown.
*/ */
bool ResizeOperation::canGrow(const Partition* p, const QList<Operation *> pendingOps) bool ResizeOperation::canGrow(const Partition* p)
{ {
if (p == nullptr) if (p == nullptr)
return false; return false;
if (isLVMPVinNewlyVG(p, pendingOps)) if (isLVMPVinNewlyVG(p))
return false; return false;
// we can always grow, shrink or move a partition not yet written to disk // we can always grow, shrink or move a partition not yet written to disk
@ -351,12 +351,12 @@ bool ResizeOperation::canGrow(const Partition* p, const QList<Operation *> pendi
@param p the Partition in question, may be nullptr. @param p the Partition in question, may be nullptr.
@return true if @p p can be shrunk. @return true if @p p can be shrunk.
*/ */
bool ResizeOperation::canShrink(const Partition* p, const QList<Operation *> pendingOps) bool ResizeOperation::canShrink(const Partition* p)
{ {
if (p == nullptr) if (p == nullptr)
return false; return false;
if (isLVMPVinNewlyVG(p, pendingOps)) if (isLVMPVinNewlyVG(p))
return false; return false;
// we can always grow, shrink or move a partition not yet written to disk // we can always grow, shrink or move a partition not yet written to disk
@ -376,12 +376,12 @@ bool ResizeOperation::canShrink(const Partition* p, const QList<Operation *> pen
@param p the Partition in question, may be nullptr. @param p the Partition in question, may be nullptr.
@return true if @p p can be moved. @return true if @p p can be moved.
*/ */
bool ResizeOperation::canMove(const Partition* p, const QList<Operation *> pendingOps) bool ResizeOperation::canMove(const Partition* p)
{ {
if (p == nullptr) if (p == nullptr)
return false; return false;
if (isLVMPVinNewlyVG(p, pendingOps)) if (isLVMPVinNewlyVG(p))
return false; return false;
// we can always grow, shrink or move a partition not yet written to disk // we can always grow, shrink or move a partition not yet written to disk
@ -399,14 +399,11 @@ bool ResizeOperation::canMove(const Partition* p, const QList<Operation *> pendi
return p->fileSystem().supportMove() != FileSystem::cmdSupportNone; return p->fileSystem().supportMove() != FileSystem::cmdSupportNone;
} }
bool ResizeOperation::isLVMPVinNewlyVG(const Partition *p, const QList<Operation *> pendingOps) bool ResizeOperation::isLVMPVinNewlyVG(const Partition *p)
{ {
if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV) { if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV) {
// See if there is a newly created VG targeting this partition if (LvmDevice::s_DirtyPVs.contains(p))
for (Operation *op : qAsConst(pendingOps)) { return true;
if (dynamic_cast<CreateVolumeGroupOperation *>(op) && op->targets(*p))
return true;
}
} }
else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) { else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) {
// See if innerFS is LVM // See if innerFS is LVM
@ -414,11 +411,8 @@ bool ResizeOperation::isLVMPVinNewlyVG(const Partition *p, const QList<Operation
if (fs) { if (fs) {
if (fs->type() == FileSystem::Type::Lvm2_PV) { if (fs->type() == FileSystem::Type::Lvm2_PV) {
// See if there is a newly created VG targeting this partition if (LvmDevice::s_DirtyPVs.contains(p))
for (Operation *op : qAsConst(pendingOps)) { return true;
if (dynamic_cast<CreateVolumeGroupOperation *>(op) && op->targets(*p))
return true;
}
} }
} }
} }

View File

@ -85,9 +85,9 @@ public:
bool targets(const Device& d) const override; bool targets(const Device& d) const override;
bool targets(const Partition& p) const override; bool targets(const Partition& p) const override;
static bool canGrow(const Partition* p, const QList<Operation *> pendingOps = QList<Operation *>()); static bool canGrow(const Partition* p);
static bool canShrink(const Partition* p, const QList<Operation *> pendingOps = QList<Operation *>()); static bool canShrink(const Partition* p);
static bool canMove(const Partition* p, const QList<Operation *> pendingOps = QList<Operation *>()); static bool canMove(const Partition* p);
protected: protected:
Device& targetDevice() { Device& targetDevice() {
@ -159,7 +159,7 @@ protected:
} }
private: private:
static bool isLVMPVinNewlyVG(const Partition* p, const QList<Operation *> pendingOps); static bool isLVMPVinNewlyVG(const Partition* p);
private: private:
Device& m_TargetDevice; Device& m_TargetDevice;