Add internal storage to LVM Device to keep track of its LVs and PVs.
This commit is contained in:
parent
81a35f0ffd
commit
53b154fe16
|
@ -27,7 +27,6 @@
|
||||||
#include "util/helpers.h"
|
#include "util/helpers.h"
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include <KDiskFreeSpaceInfo>
|
#include <KDiskFreeSpaceInfo>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
@ -50,10 +49,20 @@ LvmDevice::LvmDevice(const QString& name, const QString& iconname)
|
||||||
m_freePE = getFreePE(name);
|
m_freePE = getFreePE(name);
|
||||||
m_allocPE = m_totalPE - m_freePE;
|
m_allocPE = m_totalPE - m_freePE;
|
||||||
m_UUID = getUUID(name);
|
m_UUID = getUUID(name);
|
||||||
|
m_PVPathList = new QStringList(getPVs(name));
|
||||||
|
m_LVPathList = new QStringList(getLVs(name));
|
||||||
|
m_LVSizeMap = new QMap<QString, qint64>();
|
||||||
|
|
||||||
initPartitions();
|
initPartitions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LvmDevice::~LvmDevice()
|
||||||
|
{
|
||||||
|
delete m_PVPathList;
|
||||||
|
delete m_LVPathList;
|
||||||
|
delete m_LVSizeMap;
|
||||||
|
}
|
||||||
|
|
||||||
void LvmDevice::initPartitions()
|
void LvmDevice::initPartitions()
|
||||||
{
|
{
|
||||||
qint64 firstUsable = 0;
|
qint64 firstUsable = 0;
|
||||||
|
@ -61,6 +70,7 @@ void LvmDevice::initPartitions()
|
||||||
PartitionTable* pTable = new PartitionTable(PartitionTable::vmd, firstUsable, lastusable);
|
PartitionTable* pTable = new PartitionTable(PartitionTable::vmd, firstUsable, lastusable);
|
||||||
|
|
||||||
foreach (Partition* p, scanPartitions(pTable)) {
|
foreach (Partition* p, scanPartitions(pTable)) {
|
||||||
|
LVSizeMap()->insert(p->partitionPath(), p->length());
|
||||||
pTable->append(p);
|
pTable->append(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +188,6 @@ QList<LvmDevice*> LvmDevice::scanSystemLVM()
|
||||||
lvmList.append(new LvmDevice(vgname.trimmed()));
|
lvmList.append(new LvmDevice(vgname.trimmed()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lvmList;
|
return lvmList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,14 +199,26 @@ qint64 LvmDevice::mappedSector(const QString& lvpath, qint64 sector) const
|
||||||
|
|
||||||
if (devIndex) {
|
if (devIndex) {
|
||||||
for (int i = 0; i < devIndex; i++) {
|
for (int i = 0; i < devIndex; i++) {
|
||||||
//TODO: currently going over the same LV again and again is wasteful. Could use some more optimization
|
mSector += LVSizeMap()->value(lvpathList[i]);
|
||||||
mSector += getTotalLE(lvpathList[i]);
|
|
||||||
}
|
}
|
||||||
mSector += sector;
|
mSector += sector;
|
||||||
}
|
}
|
||||||
return mSector;
|
return mSector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList LvmDevice::deviceNodeList() const
|
||||||
|
{
|
||||||
|
return *PVPathList();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList LvmDevice::lvPathList() const
|
||||||
|
{
|
||||||
|
return *LVPathList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QStringList LvmDevice::getPVs(const QString& vgname)
|
QStringList LvmDevice::getPVs(const QString& vgname)
|
||||||
{
|
{
|
||||||
QStringList devPathList;
|
QStringList devPathList;
|
||||||
|
@ -212,11 +233,6 @@ QStringList LvmDevice::getPVs(const QString& vgname)
|
||||||
return devPathList;
|
return devPathList;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> LvmDevice::deviceNodeList() const
|
|
||||||
{
|
|
||||||
return getPVs(name());
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList LvmDevice::getLVs(const QString& vgname)
|
QStringList LvmDevice::getLVs(const QString& vgname)
|
||||||
{
|
{
|
||||||
QStringList lvPathList;
|
QStringList lvPathList;
|
||||||
|
@ -231,11 +247,6 @@ QStringList LvmDevice::getLVs(const QString& vgname)
|
||||||
return lvPathList;
|
return lvPathList;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> LvmDevice::lvPathList() const
|
|
||||||
{
|
|
||||||
return getLVs(name());
|
|
||||||
}
|
|
||||||
|
|
||||||
qint64 LvmDevice::getPeSize(const QString& vgname)
|
qint64 LvmDevice::getPeSize(const QString& vgname)
|
||||||
{
|
{
|
||||||
QString val = getField(QStringLiteral("vg_extent_size"), vgname);
|
QString val = getField(QStringLiteral("vg_extent_size"), vgname);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
class PartitionTable;
|
class PartitionTable;
|
||||||
class CreatePartitionTableOperation;
|
class CreatePartitionTableOperation;
|
||||||
|
@ -45,11 +46,13 @@ class LIBKPMCORE_EXPORT LvmDevice : public VolumeManagerDevice
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LvmDevice(const QString& name, const QString& iconname = QString());
|
LvmDevice(const QString& name, const QString& iconname = QString());
|
||||||
|
~LvmDevice();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QList<Partition*> scanPartitions(PartitionTable* pTable) const;
|
QList<Partition*> scanPartitions(PartitionTable* pTable) const;
|
||||||
Partition* scanPartition(const QString& lvPath, PartitionTable* pTable) const;
|
Partition* scanPartition(const QString& lvPath, PartitionTable* pTable) const;
|
||||||
|
|
||||||
|
public:
|
||||||
static QList<LvmDevice*> scanSystemLVM();
|
static QList<LvmDevice*> scanSystemLVM();
|
||||||
|
|
||||||
static qint64 getPeSize(const QString& vgname);
|
static qint64 getPeSize(const QString& vgname);
|
||||||
|
@ -78,10 +81,10 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initPartitions();
|
void initPartitions();
|
||||||
QList<QString> deviceNodeList() const override;
|
QStringList deviceNodeList() const override;
|
||||||
qint64 mappedSector(const QString& lvpath, qint64 sector) const override;
|
qint64 mappedSector(const QString& lvpath, qint64 sector) const override;
|
||||||
|
|
||||||
QList<QString> lvPathList() const;
|
QStringList lvPathList() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
qint64 peSize() const {
|
qint64 peSize() const {
|
||||||
|
@ -100,6 +103,18 @@ public:
|
||||||
return m_UUID;
|
return m_UUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList* LVPathList() const {
|
||||||
|
return m_LVPathList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList* PVPathList() const {
|
||||||
|
return m_PVPathList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, qint64>* LVSizeMap() const {
|
||||||
|
return m_LVSizeMap;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
qint64 m_peSize;
|
qint64 m_peSize;
|
||||||
qint64 m_totalPE;
|
qint64 m_totalPE;
|
||||||
|
@ -107,6 +122,9 @@ private:
|
||||||
qint64 m_freePE;
|
qint64 m_freePE;
|
||||||
QString m_UUID;
|
QString m_UUID;
|
||||||
|
|
||||||
|
mutable QStringList* m_LVPathList;
|
||||||
|
mutable QStringList* m_PVPathList;
|
||||||
|
mutable QMap<QString, qint64>* m_LVSizeMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "core/device.h"
|
#include "core/device.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
@ -44,18 +45,20 @@ class LIBKPMCORE_EXPORT VolumeManagerDevice : public Device
|
||||||
{
|
{
|
||||||
Q_DISABLE_COPY(VolumeManagerDevice)
|
Q_DISABLE_COPY(VolumeManagerDevice)
|
||||||
|
|
||||||
protected:
|
public:
|
||||||
VolumeManagerDevice(const QString& name, const QString& devicenode, const qint32 logicalSize, const qint64 totalLogical, const QString& iconname = QString(), Device::Type type = Device::Unknown_Device);
|
VolumeManagerDevice(const QString& name, const QString& devicenode, const qint32 logicalSize, const qint64 totalLogical, const QString& iconname = QString(), Device::Type type = Device::Unknown_Device);
|
||||||
virtual QList<QString> deviceNodeList() const = 0; /** Return list of physical device or partitions that makes up volumeManagerDevice */
|
virtual void initPartitions() = 0;
|
||||||
|
virtual QStringList deviceNodeList() const = 0; /** Return list of physical device or partitions that makes up volumeManagerDevice */
|
||||||
virtual qint64 mappedSector(const QString& devNode, qint64 sector) const = 0;
|
virtual qint64 mappedSector(const QString& devNode, qint64 sector) const = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** string deviceNodeList together into comma-sperated list */
|
/** string deviceNodeList together into comma-sperated list */
|
||||||
virtual QString prettyDeviceNodeList() const;
|
virtual QString prettyDeviceNodeList() const;
|
||||||
/** Mapper return absolute sector representing the VG */
|
|
||||||
|
|
||||||
private:
|
void setTotalLogical(qint64 num) {
|
||||||
//QMap<QString, qint32> deviceSizeMapper;
|
Q_ASSERT(num > 0);
|
||||||
|
m_TotalLogical = num;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue