From 3e31ec1431a45029c5050746012066e1b1101b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sun, 14 Oct 2018 00:02:06 +0100 Subject: [PATCH] Fix free space handling when resizing LVM LVs. BUG: 399772 --- src/core/lvmdevice.cpp | 5 +++++ src/core/lvmdevice.h | 1 + src/ops/resizeoperation.cpp | 12 +++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index 203fb0b..d6b4a24 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -545,6 +545,11 @@ qint64 LvmDevice::freePE() const return d_ptr->m_freePE; } +void LvmDevice::setFreePE(qint64 freePE) const +{ + d_ptr->m_freePE = freePE; +} + QString LvmDevice::UUID() const { return d_ptr->m_UUID; diff --git a/src/core/lvmdevice.h b/src/core/lvmdevice.h index 089719b..18b546f 100644 --- a/src/core/lvmdevice.h +++ b/src/core/lvmdevice.h @@ -98,6 +98,7 @@ public: qint64 totalPE() const; qint64 allocatedPE() const; qint64 freePE() const; + void setFreePE(qint64 freePE) const; QString UUID() const; QVector & physicalVolumes(); const QVector & physicalVolumes() const; diff --git a/src/ops/resizeoperation.cpp b/src/ops/resizeoperation.cpp index 249f2b1..fee9207 100644 --- a/src/ops/resizeoperation.cpp +++ b/src/ops/resizeoperation.cpp @@ -67,7 +67,7 @@ ResizeOperation::ResizeOperation(Device& d, Partition& p, qint64 newfirst, qint6 m_GrowSetGeomJob(nullptr), m_CheckResizedJob(nullptr) { - if(CheckOperation::canCheck(&partition())) + if (CheckOperation::canCheck(&partition())) addJob(checkOriginalJob()); if (partition().roles().has(PartitionRole::Extended)) { @@ -121,6 +121,11 @@ 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. @@ -139,6 +144,11 @@ 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());