From 36202cc1addf7860f67611a80f6822aee973035f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Wed, 2 Nov 2016 23:06:55 +0000 Subject: [PATCH] Replace complicated QPair type with custom LvmPV class. --- src/core/devicescanner.cpp | 4 ++-- src/core/operationstack.h | 8 ++++---- src/fs/luks.cpp | 2 -- src/fs/lvm2_pv.cpp | 17 ++++++++++++----- src/fs/lvm2_pv.h | 35 ++++++++++++++++++++++++++++++----- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/core/devicescanner.cpp b/src/core/devicescanner.cpp index 13428a5..c34caf0 100644 --- a/src/core/devicescanner.cpp +++ b/src/core/devicescanner.cpp @@ -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()); } diff --git a/src/core/operationstack.h b/src/core/operationstack.h index fd9ce1f..211e404 100644 --- a/src/core/operationstack.h +++ b/src/core/operationstack.h @@ -19,6 +19,7 @@ #define OPERATIONSTACK__H +#include "fs/lvm2_pv.h" #include "util/libpartitionmanagerexport.h" #include @@ -48,7 +49,6 @@ class LIBKPMCORE_EXPORT OperationStack : public QObject public: typedef QList Devices; - typedef QList> PhysicalVolumes; typedef QList Operations; public: @@ -75,10 +75,10 @@ public: return m_PreviewDevices; /**< @return the list of Devices */ } - PhysicalVolumes& physicalVolumes() { + QList& physicalVolumes() { return m_LVMPhysicalVolumes; /**< @return the list of LVM PVs */ } - const PhysicalVolumes& physicalVolumes() const { + const QList& 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 m_LVMPhysicalVolumes; QReadWriteLock m_Lock; }; diff --git a/src/fs/luks.cpp b/src/fs/luks.cpp index 979b99b..303ea78 100644 --- a/src/fs/luks.cpp +++ b/src/fs/luks.cpp @@ -309,8 +309,6 @@ bool luks::cryptClose(const QString& deviceNode) m_isCryptOpen = (m_innerFs != nullptr); - if (m_isCryptOpen) - return false; return true; } diff --git a/src/fs/lvm2_pv.cpp b/src/fs/lvm2_pv.cpp index 53bd5f0..19fdd28 100644 --- a/src/fs/lvm2_pv.cpp +++ b/src/fs/lvm2_pv.cpp @@ -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 lvm2_pv::getPVinNode(const PartitionNode* parent) { - PhysicalVolumes partitions; + QList 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(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& devices) +QList lvm2_pv::getPVs(const QList& devices) { - PhysicalVolumes partitions; + QList partitions; for (auto const &d : devices) partitions.append(getPVinNode(d->partitionTable())); @@ -288,3 +288,10 @@ lvm2_pv::PhysicalVolumes lvm2_pv::getPVs(const QList& devices) } } + +LvmPV::LvmPV(const QString vgName, const Partition* p, bool isLuks) + : m_vgName(vgName) + , m_p(p) + , m_isLuks(isLuks) +{ +} diff --git a/src/fs/lvm2_pv.h b/src/fs/lvm2_pv.h index 6f74acd..0e62223 100644 --- a/src/fs/lvm2_pv.h +++ b/src/fs/lvm2_pv.h @@ -28,9 +28,36 @@ #include class Report; - class QString; +/** Stores information about LVM PV or potentially encrypted LVM PV + * @author Andrius Štikonas + */ + +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> 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& devices); + static QList getPVinNode(const PartitionNode* parent); + static QList getPVs(const QList& devices); qint64 allocatedPE() const { return m_AllocatedPE; }; qint64 freePE() const { return m_TotalPE - m_AllocatedPE; };