- 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.
This commit is contained in:
Caio Carvalho 2018-05-07 21:55:49 -03:00
parent 34cfc63da4
commit 1e95d01923
6 changed files with 73 additions and 8 deletions

View File

@ -35,14 +35,15 @@
CreateVolumeGroupOperation::CreateVolumeGroupOperation(const QString& vgName, const QVector<const Partition*>& 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

View File

@ -69,6 +69,7 @@ protected:
private:
CreateVolumeGroupJob* m_CreateVolumeGroupJob;
const QVector<const Partition*> m_PVList;
QString m_vgName;
};
#endif

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/
#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<Operation *> 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<CreateVolumeGroupOperation *>(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<const FS::luks *>(&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<CreateVolumeGroupOperation *>(op) && op->targets(*p))
return false;
}
}
}
if (p->roles().has(PartitionRole::Unallocated))
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);
static bool canDelete(const Partition* p, const QList<Operation *> pendingOps = QList<Operation *>());
protected:
Device& targetDevice() {

View File

@ -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<Operation *> 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<CreateVolumeGroupOperation *>(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<const FS::luks *>(&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<CreateVolumeGroupOperation *>(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<Operation *> 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<CreateVolumeGroupOperation *>(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<const FS::luks *>(&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<CreateVolumeGroupOperation *>(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

View File

@ -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<Operation *> pendingOps = QList<Operation *>());
static bool canMove(const Partition* p, const QList<Operation *> pendingOps = QList<Operation *>());
protected:
Device& targetDevice() {