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/>.*
*************************************************************************/
#include "ops/createvolumegroupoperation.h"
#include "ops/deleteoperation.h"
#include "core/partition.h"
#include "core/device.h"
#include "core/lvmdevice.h"
#include "core/partitiontable.h"
#include "core/raid/softwareraid.h"
#include "fs/luks.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.
@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)
return false;
@ -120,11 +121,12 @@ bool DeleteOperation::canDelete(const Partition* p, const QList<Operation *> pen
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<CreateVolumeGroupOperation *>(op) && op->targets(*p))
return false;
}
if (LvmDevice::s_DirtyPVs.contains(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) {
// See if innerFS is LVM
@ -132,11 +134,12 @@ bool DeleteOperation::canDelete(const Partition* p, const QList<Operation *> pen
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<CreateVolumeGroupOperation *>(op) && op->targets(*p))
return false;
}
if (LvmDevice::s_DirtyPVs.contains(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 Partition& p) const override;
static bool canDelete(const Partition* p, const QList<Operation *> pendingOps = QList<Operation *>());
static bool canDelete(const Partition* p);
protected:
Device& targetDevice() {

View File

@ -20,6 +20,7 @@
#include "core/partition.h"
#include "core/device.h"
#include "core/lvmdevice.h"
#include "core/partitiontable.h"
#include "core/copysourcedevice.h"
#include "core/copytargetdevice.h"
@ -30,7 +31,6 @@
#include "jobs/movefilesystemjob.h"
#include "ops/checkoperation.h"
#include "ops/createvolumegroupoperation.h"
#include "fs/filesystem.h"
#include "fs/luks.h"
@ -329,12 +329,12 @@ 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, const QList<Operation *> pendingOps)
bool ResizeOperation::canGrow(const Partition* p)
{
if (p == nullptr)
return false;
if (isLVMPVinNewlyVG(p, pendingOps))
if (isLVMPVinNewlyVG(p))
return false;
// 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.
@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)
return false;
if (isLVMPVinNewlyVG(p, pendingOps))
if (isLVMPVinNewlyVG(p))
return false;
// 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.
@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)
return false;
if (isLVMPVinNewlyVG(p, pendingOps))
if (isLVMPVinNewlyVG(p))
return false;
// 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;
}
bool ResizeOperation::isLVMPVinNewlyVG(const Partition *p, const QList<Operation *> pendingOps)
bool ResizeOperation::isLVMPVinNewlyVG(const Partition *p)
{
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<CreateVolumeGroupOperation *>(op) && op->targets(*p))
return true;
}
if (LvmDevice::s_DirtyPVs.contains(p))
return true;
}
else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) {
// See if innerFS is LVM
@ -414,11 +411,8 @@ bool ResizeOperation::isLVMPVinNewlyVG(const Partition *p, const QList<Operation
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<CreateVolumeGroupOperation *>(op) && op->targets(*p))
return true;
}
if (LvmDevice::s_DirtyPVs.contains(p))
return true;
}
}
}

View File

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