From 1e95d01923e7d363ea7fe6e68d5280ec58bc64ef Mon Sep 17 00:00:00 2001 From: Caio Carvalho Date: Mon, 7 May 2018 21:55:49 -0300 Subject: [PATCH] - Including vgName in CreateVolumeGroupOperation description. - Don't delete LVM PVs that are being targeted by CreateVolumeGroupOperations. - Don't shrink or move LVM PVs that are being targeted by CreateVolumeGroupOperations. --- src/ops/createvolumegroupoperation.cpp | 5 +-- src/ops/createvolumegroupoperation.h | 1 + src/ops/deleteoperation.cpp | 23 ++++++++++++- src/ops/deleteoperation.h | 2 +- src/ops/resizeoperation.cpp | 46 ++++++++++++++++++++++++-- src/ops/resizeoperation.h | 4 +-- 6 files changed, 73 insertions(+), 8 deletions(-) diff --git a/src/ops/createvolumegroupoperation.cpp b/src/ops/createvolumegroupoperation.cpp index 90c4826..5930905 100644 --- a/src/ops/createvolumegroupoperation.cpp +++ b/src/ops/createvolumegroupoperation.cpp @@ -35,14 +35,15 @@ CreateVolumeGroupOperation::CreateVolumeGroupOperation(const QString& vgName, const QVector& pvList, const qint32 peSize) : Operation(), m_CreateVolumeGroupJob(new CreateVolumeGroupJob(vgName, pvList, peSize)), - m_PVList(pvList) + m_PVList(pvList), + m_vgName(vgName) { addJob(createVolumeGroupJob()); } QString CreateVolumeGroupOperation::description() const { - return xi18nc("@info/plain", "Create a new LVM volume group."); + return xi18nc("@info/plain", "Create a new LVM volume group named \'%1\'.", m_vgName); } bool CreateVolumeGroupOperation::targets(const Partition& partition) const diff --git a/src/ops/createvolumegroupoperation.h b/src/ops/createvolumegroupoperation.h index c75c45c..4fa49f2 100644 --- a/src/ops/createvolumegroupoperation.h +++ b/src/ops/createvolumegroupoperation.h @@ -69,6 +69,7 @@ protected: private: CreateVolumeGroupJob* m_CreateVolumeGroupJob; const QVector m_PVList; + QString m_vgName; }; #endif diff --git a/src/ops/deleteoperation.cpp b/src/ops/deleteoperation.cpp index b0cea05..768051c 100644 --- a/src/ops/deleteoperation.cpp +++ b/src/ops/deleteoperation.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see .* *************************************************************************/ +#include "ops/createvolumegroupoperation.h" #include "ops/deleteoperation.h" #include "core/partition.h" @@ -110,7 +111,7 @@ void DeleteOperation::checkAdjustLogicalNumbers(Partition& p, bool undo) @param p the Partition in question, may be nullptr. @return true if @p p can be deleted. */ -bool DeleteOperation::canDelete(const Partition* p) +bool DeleteOperation::canDelete(const Partition* p, const QList pendingOps) { if (p == nullptr) return false; @@ -118,6 +119,26 @@ bool DeleteOperation::canDelete(const Partition* p) if (p->isMounted()) 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 = static_cast(&p->fileSystem())->innerFS(); + + 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 (p->roles().has(PartitionRole::Unallocated)) return false; diff --git a/src/ops/deleteoperation.h b/src/ops/deleteoperation.h index 682abd2..39faccd 100644 --- a/src/ops/deleteoperation.h +++ b/src/ops/deleteoperation.h @@ -68,7 +68,7 @@ public: bool targets(const Device& d) const override; bool targets(const Partition& p) const override; - static bool canDelete(const Partition* p); + static bool canDelete(const Partition* p, const QList pendingOps = QList()); protected: Device& targetDevice() { diff --git a/src/ops/resizeoperation.cpp b/src/ops/resizeoperation.cpp index 3bac007..57b7361 100644 --- a/src/ops/resizeoperation.cpp +++ b/src/ops/resizeoperation.cpp @@ -30,8 +30,10 @@ #include "jobs/movefilesystemjob.h" #include "ops/checkoperation.h" +#include "ops/createvolumegroupoperation.h" #include "fs/filesystem.h" +#include "fs/luks.h" #include "util/capacity.h" #include "util/report.h" @@ -346,11 +348,31 @@ bool ResizeOperation::canGrow(const Partition* p) @param p the Partition in question, may be nullptr. @return true if @p p can be shrunk. */ -bool ResizeOperation::canShrink(const Partition* p) +bool ResizeOperation::canShrink(const Partition* p, const QList pendingOps) { 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 = static_cast(&p->fileSystem())->innerFS(); + + 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; + } + } + } + // 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; @@ -368,11 +390,31 @@ bool ResizeOperation::canShrink(const Partition* p) @param p the Partition in question, may be nullptr. @return true if @p p can be moved. */ -bool ResizeOperation::canMove(const Partition* p) +bool ResizeOperation::canMove(const Partition* p, const QList pendingOps) { 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 = static_cast(&p->fileSystem())->innerFS(); + + 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; + } + } + } + // we can always grow, shrink or move a partition not yet written to disk if (p->state() == Partition::State::New) // too many bad things can happen for LUKS partitions diff --git a/src/ops/resizeoperation.h b/src/ops/resizeoperation.h index e620b5a..820edc7 100644 --- a/src/ops/resizeoperation.h +++ b/src/ops/resizeoperation.h @@ -86,8 +86,8 @@ public: bool targets(const Partition& p) const override; static bool canGrow(const Partition* p); - static bool canShrink(const Partition* p); - static bool canMove(const Partition* p); + static bool canShrink(const Partition* p, const QList pendingOps = QList()); + static bool canMove(const Partition* p, const QList pendingOps = QList()); protected: Device& targetDevice() {