From b06af11357a57bc582e3ee571053a0bd5f070028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Fri, 19 Oct 2018 19:55:35 +0100 Subject: [PATCH] Fix free space handling with LVM LVs. The previous commit worked for resizing LVM. However, it is better to do special handling of LVMs in insert/removePreviewPartition. BUG: 399772 --- src/ops/operation.cpp | 13 ++++++++++++- src/ops/resizeoperation.cpp | 10 ---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ops/operation.cpp b/src/ops/operation.cpp index c837f29..d575fb9 100644 --- a/src/ops/operation.cpp +++ b/src/ops/operation.cpp @@ -20,6 +20,7 @@ #include "core/partition.h" #include "core/device.h" +#include "core/lvmdevice.h" #include "jobs/job.h" @@ -51,6 +52,10 @@ void Operation::insertPreviewPartition(Device& device, Partition& p) device.partitionTable()->removeUnallocated(); p.parent()->insert(&p); + if (device.type() == Device::Type::LVM_Device) { + const LvmDevice& lvm = static_cast(device); + lvm.setFreePE(lvm.freePE() - p.length()); + } device.partitionTable()->updateUnallocated(device); } @@ -59,8 +64,14 @@ void Operation::removePreviewPartition(Device& device, Partition& p) { Q_ASSERT(device.partitionTable()); - if (p.parent()->remove(&p)) + if (p.parent()->remove(&p)) { + if (device.type() == Device::Type::LVM_Device) { + const LvmDevice& lvm = static_cast(device); + lvm.setFreePE(lvm.freePE() + p.length()); + } + device.partitionTable()->updateUnallocated(device); + } else qWarning() << "failed to remove partition " << p.deviceNode() << " at " << &p << " from preview."; } diff --git a/src/ops/resizeoperation.cpp b/src/ops/resizeoperation.cpp index fee9207..3527a96 100644 --- a/src/ops/resizeoperation.cpp +++ b/src/ops/resizeoperation.cpp @@ -121,11 +121,6 @@ bool ResizeOperation::targets(const Partition& p) const void ResizeOperation::preview() { - if (targetDevice().type() == Device::Type::LVM_Device) { - const LvmDevice& lvm = static_cast(targetDevice()); - lvm.setFreePE(lvm.freePE() + partition().lastSector() - newLastSector()); - } - // If the operation has already been executed, the partition will of course have newFirstSector and // newLastSector as first and last sector. But to remove it from its original position, we need to // temporarily set these values back to where they were before the operation was executed. @@ -144,11 +139,6 @@ void ResizeOperation::preview() void ResizeOperation::undo() { - if (targetDevice().type() == Device::Type::LVM_Device) { - const LvmDevice& lvm = static_cast(targetDevice()); - lvm.setFreePE(lvm.freePE() - origLastSector() + partition().lastSector()); - } - removePreviewPartition(targetDevice(), partition()); partition().setFirstSector(origFirstSector()); partition().setLastSector(origLastSector());