d-pointerize LvmDevice class.

This commit is contained in:
Andrius Štikonas 2018-04-09 02:40:24 +01:00
parent df364bdc7c
commit 7e8bab3b4e
8 changed files with 126 additions and 83 deletions

View File

@ -25,29 +25,6 @@
#include <KLocalizedString> #include <KLocalizedString>
/** Constructs a Device with an empty PartitionTable.
@param name the Device's name, usually some string defined by the manufacturer
@param deviceNode the Device's node, for example "/dev/sda"
*/
Device::Device(const QString& name,
const QString& deviceNode,
const qint64 logicalSectorSize,
const qint64 totalLogicalSectors,
const QString& iconName,
Device::Type type)
: QObject()
, d(std::make_shared<DevicePrivate>())
{
d->m_Name = name.length() > 0 ? name : i18n("Unknown Device");
d->m_DeviceNode = deviceNode;
d->m_LogicalSectorSize = logicalSectorSize;
d->m_TotalLogical = totalLogicalSectors;
d->m_PartitionTable = nullptr;
d->m_IconName = iconName.isEmpty() ? QStringLiteral("drive-harddisk") : iconName;
d->m_SmartStatus = type == Device::Disk_Device ? std::make_shared<SmartStatus>(deviceNode) : nullptr;
d->m_Type = type;
}
/** Constructs a Device with an empty PartitionTable. /** Constructs a Device with an empty PartitionTable.
@param name the Device's name, usually some string defined by the manufacturer @param name the Device's name, usually some string defined by the manufacturer
@param deviceNode the Device's node, for example "/dev/sda" @param deviceNode the Device's node, for example "/dev/sda"

View File

@ -58,8 +58,6 @@ public:
}; };
protected: protected:
explicit Device(const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogicalSectors, const QString& iconName = QString(), Device::Type type = Device::Disk_Device);
explicit Device(std::shared_ptr<DevicePrivate> d_ptr, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogicalSectors, const QString& iconName = QString(), Device::Type type = Device::Disk_Device); explicit Device(std::shared_ptr<DevicePrivate> d_ptr, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogicalSectors, const QString& iconName = QString(), Device::Type type = Device::Disk_Device);
public: public:

View File

@ -15,6 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.* * along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/ *************************************************************************/
#ifndef KPMCORE_DEVICE_P_H
#define KPMCORE_DEVICE_P_H
#include "core/device.h" #include "core/device.h"
#include <QString> #include <QString>
@ -36,3 +39,5 @@ public:
std::shared_ptr<SmartStatus> m_SmartStatus; std::shared_ptr<SmartStatus> m_SmartStatus;
Device::Type m_Type; Device::Type m_Type;
}; };
#endif

View File

@ -18,6 +18,7 @@
#include "core/lvmdevice.h" #include "core/lvmdevice.h"
#include "core/partition.h" #include "core/partition.h"
#include "core/volumemanagerdevice_p.h"
#include "fs/filesystem.h" #include "fs/filesystem.h"
#include "fs/lvm2_pv.h" #include "fs/lvm2_pv.h"
#include "fs/luks.h" #include "fs/luks.h"
@ -34,26 +35,43 @@
#include <KLocalizedString> #include <KLocalizedString>
#define d_ptr std::static_pointer_cast<LvmDevicePrivate>(d)
class LvmDevicePrivate : public VolumeManagerDevicePrivate
{
public:
qint64 m_peSize;
qint64 m_totalPE;
qint64 m_allocPE;
qint64 m_freePE;
QString m_UUID;
mutable QStringList* m_LVPathList;
QVector <const Partition*> m_PVs;
mutable QHash<QString, qint64>* m_LVSizeMap;
};
/** Constructs a representation of LVM device with initialized LV as Partitions /** Constructs a representation of LVM device with initialized LV as Partitions
* *
* @param vgName Volume Group name * @param vgName Volume Group name
* @param iconName Icon representing LVM Volume group * @param iconName Icon representing LVM Volume group
*/ */
LvmDevice::LvmDevice(const QString& vgName, const QString& iconName) LvmDevice::LvmDevice(const QString& vgName, const QString& iconName)
: VolumeManagerDevice(vgName, : VolumeManagerDevice(std::make_shared<LvmDevicePrivate>(),
vgName,
(QStringLiteral("/dev/") + vgName), (QStringLiteral("/dev/") + vgName),
getPeSize(vgName), getPeSize(vgName),
getTotalPE(vgName), getTotalPE(vgName),
iconName, iconName,
Device::LVM_Device) Device::LVM_Device)
{ {
m_peSize = logicalSize(); d_ptr->m_peSize = logicalSize();
m_totalPE = totalLogical(); d_ptr->m_totalPE = totalLogical();
m_freePE = getFreePE(vgName); d_ptr->m_freePE = getFreePE(vgName);
m_allocPE = m_totalPE - m_freePE; d_ptr->m_allocPE = d_ptr->m_totalPE - d_ptr->m_freePE;
m_UUID = getUUID(vgName); d_ptr->m_UUID = getUUID(vgName);
m_LVPathList = new QStringList(getLVs(vgName)); d_ptr->m_LVPathList = new QStringList(getLVs(vgName));
m_LVSizeMap = new QHash<QString, qint64>(); d_ptr->m_LVSizeMap = new QHash<QString, qint64>();
initPartitions(); initPartitions();
} }
@ -66,8 +84,8 @@ QVector<const Partition*> LvmDevice::s_DirtyPVs;
LvmDevice::~LvmDevice() LvmDevice::~LvmDevice()
{ {
delete m_LVPathList; delete d_ptr->m_LVPathList;
delete m_LVSizeMap; delete d_ptr->m_LVSizeMap;
} }
void LvmDevice::initPartitions() void LvmDevice::initPartitions()
@ -492,3 +510,48 @@ bool LvmDevice::activateLV(const QString& lvPath)
lvPath }); lvPath });
return deactivate.run(-1) && deactivate.exitCode() == 0; return deactivate.run(-1) && deactivate.exitCode() == 0;
} }
qint64 LvmDevice::peSize() const
{
return d_ptr->m_peSize;
}
qint64 LvmDevice::totalPE() const
{
return d_ptr->m_totalPE;
}
qint64 LvmDevice::allocatedPE() const
{
return d_ptr->m_allocPE;
}
qint64 LvmDevice::freePE() const
{
return d_ptr->m_freePE;
}
QString LvmDevice::UUID() const
{
return d_ptr->m_UUID;
}
QStringList* LvmDevice::LVPathList() const
{
return d_ptr->m_LVPathList;
}
QVector <const Partition*>& LvmDevice::physicalVolumes()
{
return d_ptr->m_PVs;
}
const QVector <const Partition*>& LvmDevice::physicalVolumes() const
{
return d_ptr->m_PVs;
}
QHash<QString, qint64>* LvmDevice::LVSizeMap() const
{
return d_ptr->m_LVSizeMap;
}

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.* * along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/ *************************************************************************/
#if !defined(KPMCORE_LVMDEVICE_H) #ifndef KPMCORE_LVMDEVICE_H
#define KPMCORE_LVMDEVICE_H #define KPMCORE_LVMDEVICE_H
#include "core/device.h" #include "core/device.h"
@ -57,7 +56,6 @@ public:
static QVector<const Partition*> s_DirtyPVs; static QVector<const Partition*> s_DirtyPVs;
public:
static void scanSystemLVM(QList<Device*>& devices); static void scanSystemLVM(QList<Device*>& devices);
static const QStringList getVGs(); static const QStringList getVGs();
@ -89,54 +87,23 @@ public:
static bool activateVG(Report& report, const LvmDevice& d); static bool activateVG(Report& report, const LvmDevice& d);
protected: protected:
void initPartitions() override; void initPartitions() override;
const QList<Partition*> scanPartitions(PartitionTable* pTable) const; const QList<Partition*> scanPartitions(PartitionTable* pTable) const;
Partition* scanPartition(const QString& lvPath, PartitionTable* pTable) const; Partition* scanPartition(const QString& lvPath, PartitionTable* pTable) const;
qint64 mappedSector(const QString& lvPath, qint64 sector) const override; qint64 mappedSector(const QString& lvPath, qint64 sector) const override;
public: public:
qint64 peSize() const { qint64 peSize() const;
return m_peSize; qint64 totalPE() const;
} qint64 allocatedPE() const;
qint64 totalPE() const { qint64 freePE() const;
return m_totalPE; QString UUID() const;
} QStringList* LVPathList() const;
qint64 allocatedPE() const { QVector <const Partition*>& physicalVolumes();
return m_allocPE; const QVector <const Partition*>& physicalVolumes() const;
}
qint64 freePE() const {
return m_freePE;
}
QString UUID() const {
return m_UUID;
}
QStringList* LVPathList() const {
return m_LVPathList;
}
QVector <const Partition*>& physicalVolumes() {
return m_PVs;
}
const QVector <const Partition*>& physicalVolumes() const {
return m_PVs;
}
protected: protected:
QHash<QString, qint64>* LVSizeMap() const { QHash<QString, qint64>* LVSizeMap() const;
return m_LVSizeMap;
}
private:
qint64 m_peSize;
qint64 m_totalPE;
qint64 m_allocPE;
qint64 m_freePE;
QString m_UUID;
mutable QStringList* m_LVPathList;
QVector <const Partition*> m_PVs;
mutable QHash<QString, qint64>* m_LVSizeMap;
}; };
#endif #endif

View File

@ -18,17 +18,22 @@
#include "core/device_p.h" #include "core/device_p.h"
#include "core/volumemanagerdevice.h" #include "core/volumemanagerdevice.h"
#include "core/volumemanagerdevice_p.h"
/** Constructs an abstract Volume Manager Device with an empty PartitionTable. /** Constructs an abstract Volume Manager Device with an empty PartitionTable.
* *
* @param name the Device's name
* @param deviceNode the Device's node
* @param logicalExtentSize the logical extent size that device uses
*/ */
VolumeManagerDevice::VolumeManagerDevice(const QString& name, VolumeManagerDevice::VolumeManagerDevice(std::shared_ptr<VolumeManagerDevicePrivate> d,
const QString& name,
const QString& deviceNode, const QString& deviceNode,
const qint64 logicalSize, const qint64 logicalExtentSize,
const qint64 totalLogical, const qint64 totalLogical,
const QString& iconName, const QString& iconName,
Device::Type type) Device::Type type)
: Device(name, deviceNode, logicalSize, totalLogical, iconName, type) : Device(std::static_pointer_cast<DevicePrivate>(d), name, deviceNode, logicalExtentSize, totalLogical, iconName, type)
{ {
} }

View File

@ -26,6 +26,8 @@
#include <QObject> #include <QObject>
#include <QtGlobal> #include <QtGlobal>
class VolumeManagerDevicePrivate;
/** A Volume Manager of physical devices represented as an abstract device. /** A Volume Manager of physical devices represented as an abstract device.
* *
* VolumeManagerDevice is an abstract device class for volume manager. e.g: LVM, SoftRAID. * VolumeManagerDevice is an abstract device class for volume manager. e.g: LVM, SoftRAID.
@ -40,8 +42,7 @@ class LIBKPMCORE_EXPORT VolumeManagerDevice : public Device
Q_DISABLE_COPY(VolumeManagerDevice) Q_DISABLE_COPY(VolumeManagerDevice)
public: public:
VolumeManagerDevice(std::shared_ptr<VolumeManagerDevicePrivate> d, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Unknown_Device);
VolumeManagerDevice(const QString& name, const QString& deviceNode, const qint64 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Unknown_Device);
/** /**
* @return list of physical device's path that makes up volumeManagerDevice.(e.g: /dev/sda, /dev/sdb1) * @return list of physical device's path that makes up volumeManagerDevice.(e.g: /dev/sda, /dev/sdb1)

View File

@ -0,0 +1,27 @@
/*************************************************************************
* Copyright (C) 2018 by Andrius Štikonas <andrius@stikonas.eu> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/
#ifndef KPMCORE_VOLUMEMANAGERDEVICE_P_H
#define KPMCORE_VOLUMEMANAGERDEVICE_P_H
#include "core/device_p.h"
class VolumeManagerDevicePrivate : public DevicePrivate
{
};
#endif