Replace complicated QPair type with custom LvmPV class.

This commit is contained in:
Andrius Štikonas 2016-11-02 23:06:55 +00:00
parent 5182c037db
commit 36202cc1ad
5 changed files with 48 additions and 18 deletions

View File

@ -81,7 +81,7 @@ void DeviceScanner::scan()
// Store list of physical volumes in LvmDevice
for (const auto &d : lvmList)
for (const auto &p : operationStack().physicalVolumes())
if (p.first == d->name())
d->physicalVolumes().append(p.second);
if (p.vgName() == d->name())
d->physicalVolumes().append(p.partition());
}

View File

@ -19,6 +19,7 @@
#define OPERATIONSTACK__H
#include "fs/lvm2_pv.h"
#include "util/libpartitionmanagerexport.h"
#include <QObject>
@ -48,7 +49,6 @@ class LIBKPMCORE_EXPORT OperationStack : public QObject
public:
typedef QList<Device*> Devices;
typedef QList<QPair<QString, const Partition *>> PhysicalVolumes;
typedef QList<Operation*> Operations;
public:
@ -75,10 +75,10 @@ public:
return m_PreviewDevices; /**< @return the list of Devices */
}
PhysicalVolumes& physicalVolumes() {
QList<LvmPV>& physicalVolumes() {
return m_LVMPhysicalVolumes; /**< @return the list of LVM PVs */
}
const PhysicalVolumes& physicalVolumes() const {
const QList<LvmPV>& physicalVolumes() const {
return m_LVMPhysicalVolumes; /**< @return the list of LVM PVs */
}
@ -110,7 +110,7 @@ protected:
private:
Operations m_Operations;
mutable Devices m_PreviewDevices;
mutable PhysicalVolumes m_LVMPhysicalVolumes;
mutable QList<LvmPV> m_LVMPhysicalVolumes;
QReadWriteLock m_Lock;
};

View File

@ -309,8 +309,6 @@ bool luks::cryptClose(const QString& deviceNode)
m_isCryptOpen = (m_innerFs != nullptr);
if (m_isCryptOpen)
return false;
return true;
}

View File

@ -250,9 +250,9 @@ QString lvm2_pv::getVGName(const QString& deviceNode)
return getpvField(QStringLiteral("vg_name"), deviceNode);
}
lvm2_pv::PhysicalVolumes lvm2_pv::getPVinNode(const PartitionNode* parent)
QList<LvmPV> lvm2_pv::getPVinNode(const PartitionNode* parent)
{
PhysicalVolumes partitions;
QList<LvmPV> partitions;
if (parent == nullptr)
return partitions;
@ -267,7 +267,7 @@ lvm2_pv::PhysicalVolumes lvm2_pv::getPVinNode(const PartitionNode* parent)
// FIXME: reenable newly created PVs (before applying) once everything works
if(p->fileSystem().type() == FileSystem::Lvm2_PV && p->deviceNode() == p->partitionPath())
partitions.append(QPair<QString, const Partition *>(p->mountPoint(), p));
partitions.append(LvmPV(p->mountPoint(), p));
}
return partitions;
@ -278,9 +278,9 @@ lvm2_pv::PhysicalVolumes lvm2_pv::getPVinNode(const PartitionNode* parent)
* @param devices list of Devices which we scan for LVM PVs
* @return list of LVM PVs
*/
lvm2_pv::PhysicalVolumes lvm2_pv::getPVs(const QList<Device*>& devices)
QList<LvmPV> lvm2_pv::getPVs(const QList<Device*>& devices)
{
PhysicalVolumes partitions;
QList<LvmPV> partitions;
for (auto const &d : devices)
partitions.append(getPVinNode(d->partitionTable()));
@ -288,3 +288,10 @@ lvm2_pv::PhysicalVolumes lvm2_pv::getPVs(const QList<Device*>& devices)
}
}
LvmPV::LvmPV(const QString vgName, const Partition* p, bool isLuks)
: m_vgName(vgName)
, m_p(p)
, m_isLuks(isLuks)
{
}

View File

@ -28,9 +28,36 @@
#include <QtGlobal>
class Report;
class QString;
/** Stores information about LVM PV or potentially encrypted LVM PV
* @author Andrius Štikonas <andrius@stikonas.eu>
*/
class LvmPV
{
public:
LvmPV(const QString vgName, const Partition* p, bool isLuks = false);
const QString vgName() const {
return m_vgName;
}
const Partition* partition() const {
return m_p;
}
bool isLuks() const {
return m_isLuks;
}
private:
QString m_vgName;
const Partition *m_p;
bool m_isLuks;
};
namespace FS
{
/** LVM2 physical volume.
@ -38,8 +65,6 @@ namespace FS
*/
class LIBKPMCORE_EXPORT lvm2_pv : public FileSystem
{
public:
typedef QList<QPair<QString, const Partition *>> PhysicalVolumes;
public:
lvm2_pv(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label);
@ -120,8 +145,8 @@ public:
static qint64 getTotalPE(const QString& deviceNode);
static qint64 getAllocatedPE(const QString& deviceNode);
static QString getVGName(const QString& deviceNode);
static PhysicalVolumes getPVinNode(const PartitionNode* parent);
static PhysicalVolumes getPVs(const QList<Device*>& devices);
static QList<LvmPV> getPVinNode(const PartitionNode* parent);
static QList<LvmPV> getPVs(const QList<Device*>& devices);
qint64 allocatedPE() const { return m_AllocatedPE; };
qint64 freePE() const { return m_TotalPE - m_AllocatedPE; };