Fix free space handling when resizing LVM LVs.

BUG: 399772
This commit is contained in:
Andrius Štikonas 2018-10-14 00:02:06 +01:00
parent 5dc4986bc9
commit 3e31ec1431
3 changed files with 17 additions and 1 deletions

View File

@ -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;

View File

@ -98,6 +98,7 @@ public:
qint64 totalPE() const;
qint64 allocatedPE() const;
qint64 freePE() const;
void setFreePE(qint64 freePE) const;
QString UUID() const;
QVector <const Partition*>& physicalVolumes();
const QVector <const Partition*>& physicalVolumes() const;

View File

@ -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<const LvmDevice&>(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<const LvmDevice&>(targetDevice());
lvm.setFreePE(lvm.freePE() - origLastSector() + partition().lastSector());
}
removePreviewPartition(targetDevice(), partition());
partition().setFirstSector(origFirstSector());
partition().setLastSector(origLastSector());