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