From eb0c32e9dccb362bd5e26925e8efcbb6a665b2ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sat, 5 Nov 2016 15:33:20 +0000 Subject: [PATCH] Improve checking whether LVM VG can be removed. E.g. if we remove all LVM LVs without applying operations then LVM VG removal should be possible. This still does not take into account inactive LVM volumes. --- src/ops/removevolumegroupoperation.cpp | 22 ++++++++++++++++++++++ src/ops/removevolumegroupoperation.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/ops/removevolumegroupoperation.cpp b/src/ops/removevolumegroupoperation.cpp index c680f47..e7eaf1f 100644 --- a/src/ops/removevolumegroupoperation.cpp +++ b/src/ops/removevolumegroupoperation.cpp @@ -18,6 +18,7 @@ #include "ops/removevolumegroupoperation.h" #include "jobs/removevolumegroupjob.h" +#include "core/partition.h" #include "core/partitiontable.h" #include "core/volumemanagerdevice.h" @@ -50,3 +51,24 @@ void RemoveVolumeGroupOperation::undo() { device().setPartitionTable(m_PartitionTable); } + +/** Check if Volume Group can be safely removed + * + * @param dev VolumeManagerDevice with initialized partitions + * @return true if there are no LVM partitions. + */ +bool RemoveVolumeGroupOperation::isRemovable(const VolumeManagerDevice* dev) +{ + // TODO: allow removal when LVs are inactive. + if (dev->type() == Device::LVM_Device) { + if (dev->partitionTable()->children().count() == 0) // This is necessary to prevent a crash during applying of operations + return true; + else if (dev->partitionTable()->children().count() > 1) + return false; + else + if (dev->partitionTable()->children().first()->fileSystem().type() == FileSystem::Unknown) + return true; + } + + return false; +} diff --git a/src/ops/removevolumegroupoperation.h b/src/ops/removevolumegroupoperation.h index 23cac18..c1e94f8 100644 --- a/src/ops/removevolumegroupoperation.h +++ b/src/ops/removevolumegroupoperation.h @@ -56,6 +56,8 @@ public: virtual void preview() override; virtual void undo() override; + static bool isRemovable(const VolumeManagerDevice* dev); + protected: RemoveVolumeGroupJob* removeVolumeGroupJob() { return m_RemoveVolumeGroupJob;