Move LVM scanning logic from DeviceScanner to LvmDevice.

This commit is contained in:
Chantara Tith 2016-07-28 20:21:31 +07:00 committed by Andrius Štikonas
parent 12a74b4a2b
commit 1c7dd64e68
4 changed files with 19 additions and 24 deletions

View File

@ -63,33 +63,14 @@ void DeviceScanner::scan()
clear();
QList<Device*> deviceList = CoreBackendManager::self()->backend()->scanDevices();
QList<LvmDevice*> lvmList = scanLvmDevices();
QList<LvmDevice*> lvmList = LvmDevice::scanSystemLVM();
foreach(Device * d, deviceList)
operationStack().addDevice(d);
foreach(Device * d, lvmList)
operationStack().addDevice(d);
operationStack().addDevice(d);
operationStack().sortDevices();
}
/* Return list of VG (LvmDevice) on the system */
QList<LvmDevice*> DeviceScanner::scanLvmDevices() const
{
QList<LvmDevice*> lvmList;
ExternalCommand scanLvm(QStringLiteral("lvm"),
{ QStringLiteral("vgdisplay")});
if (scanLvm.run(-1) && scanLvm.exitCode() == 0) {
QRegularExpression re(QStringLiteral("VG Name\\h+(\\w+)"));
QRegularExpressionMatchIterator i = re.globalMatch(scanLvm.output());
while(i.hasNext()) {
QRegularExpressionMatch vgName = i.next();
LvmDevice* temp = new LvmDevice(vgName.captured(1));
lvmList.append(temp);
}
}
return lvmList;
}

View File

@ -23,7 +23,6 @@
#include <QThread>
class OperationStack;
class LvmDevice;
/** Thread to scan for all available Devices on this computer.
@ -55,8 +54,6 @@ protected:
return m_OperationStack;
}
QList<LvmDevice*> scanLvmDevices() const;
private:
OperationStack& m_OperationStack;
};

View File

@ -163,6 +163,21 @@ Partition* LvmDevice::scanPartition(const QString& lvpath, const LvmDevice& dev,
return part;
}
QList<LvmDevice*> LvmDevice::scanSystemLVM()
{
QList<LvmDevice*> lvmList;
QString output = getField(QStringLiteral("vg_name"));
if (!output.isEmpty()) {
QStringList vgnameList = output.split(QStringLiteral("\n"), QString::SkipEmptyParts);
foreach(QString vgname, vgnameList) {
lvmList.append(new LvmDevice(vgname.trimmed()));
}
}
return lvmList;
}
qint64 LvmDevice::mappedSector(const QString& lvpath, qint64 sector) const
{
qint64 mSector = 0;

View File

@ -52,6 +52,8 @@ public:
QList<Partition*> scanPartitions(const LvmDevice& dev, PartitionTable* pTable) const;
Partition* scanPartition(const QString& lvPath, const LvmDevice& dev, PartitionTable* pTable) const;
static QList<LvmDevice*> scanSystemLVM();
static qint64 getPeSize(const QString& vgname);
static qint64 getTotalPE(const QString& vgname);
static qint64 getAllocatedPE(const QString& vgname);