From 76800ea872496e610980d74b4d6ffa336dbd21c9 Mon Sep 17 00:00:00 2001 From: Chantara Tith Date: Sun, 19 Jun 2016 03:58:40 +0700 Subject: [PATCH] Add LVM delete partition job --- src/core/lvmdevice.cpp | 15 ++++++++++++++ src/core/lvmdevice.h | 2 ++ src/jobs/deletefilesystemjob.cpp | 6 +++++- src/jobs/deletepartitionjob.cpp | 35 ++++++++++++++++++-------------- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index ee1f99e..888cb89 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -241,3 +241,18 @@ qint32 LvmDevice::getTotalLE(const QString& lvpath) } return -1; } + +bool LvmDevice::removeLV(Device& dev, Partition& part) +{ + ExternalCommand cmd(QStringLiteral("lvm"), + { QStringLiteral("lvremove"), + QStringLiteral("--yes"), + part.partitionPath()}); + + if (cmd.run(-1) && cmd.exitCode() == 0) { + //TODO: remove Partition from PartitionTable and delete from memory + dev.partitionTable()->remove(&part); + return true; + } + return false; +} diff --git a/src/core/lvmdevice.h b/src/core/lvmdevice.h index d352be6..9a1cfda 100644 --- a/src/core/lvmdevice.h +++ b/src/core/lvmdevice.h @@ -60,6 +60,8 @@ public: static qint32 getTotalLE(const QString& lvpath); + static bool removeLV(Device& dev, Partition& part); + protected: void initPartitions(); QList deviceNodeList() const override; diff --git a/src/jobs/deletefilesystemjob.cpp b/src/jobs/deletefilesystemjob.cpp index f719fa7..6853420 100644 --- a/src/jobs/deletefilesystemjob.cpp +++ b/src/jobs/deletefilesystemjob.cpp @@ -63,8 +63,12 @@ bool DeleteFileSystemJob::run(Report& parent) return false; } - if (partition().roles().has(PartitionRole::Extended)) + if (partition().roles().has(PartitionRole::Extended)) { rval = true; + } else if (device().type() == Device::LVM_Device) { + //TODO: LVM delete Filesystem Job. libparted can't help us here. + rval = true; + } else { if (!partition().fileSystem().remove(*report, partition().deviceNode())) { jobFinished(*report, rval); diff --git a/src/jobs/deletepartitionjob.cpp b/src/jobs/deletepartitionjob.cpp index b7df76a..54219c4 100644 --- a/src/jobs/deletepartitionjob.cpp +++ b/src/jobs/deletepartitionjob.cpp @@ -25,6 +25,7 @@ #include "core/partition.h" #include "core/device.h" +#include "core/lvmdevice.h" #include "util/report.h" @@ -56,27 +57,31 @@ bool DeletePartitionJob::run(Report& parent) Report* report = jobStarted(parent); - CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode()); + if (device().type() == Device::Disk_Device) { + CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode()); - if (backendDevice) { - CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable(); + if (backendDevice) { + CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable(); - if (backendPartitionTable) { - rval = backendPartitionTable->deletePartition(*report, partition()); + if (backendPartitionTable) { + rval = backendPartitionTable->deletePartition(*report, partition()); - if (!rval) - report->line() << xi18nc("@info:progress", "Could not delete partition %1.", partition().deviceNode()); - else - backendPartitionTable->commit(); + if (!rval) + report->line() << xi18nc("@info:progress", "Could not delete partition %1.", partition().deviceNode()); + else + backendPartitionTable->commit(); - delete backendPartitionTable; + delete backendPartitionTable; + } else + report->line() << xi18nc("@info:progress", "Could not open partition table on device %1 to delete partition %2.", device().deviceNode(), partition().deviceNode()); + + delete backendDevice; } else - report->line() << xi18nc("@info:progress", "Could not open partition table on device %1 to delete partition %2.", device().deviceNode(), partition().deviceNode()); - - delete backendDevice; - } else - report->line() << xi18nc("@info:progress", "Deleting partition failed: Could not open device %1.", device().deviceNode()); + report->line() << xi18nc("@info:progress", "Deleting partition failed: Could not open device %1.", device().deviceNode()); + } else if (device().type() == Device::LVM_Device) { + rval = LvmDevice::removeLV(device(), partition()); + } jobFinished(*report, rval);