diff --git a/src/core/devicescanner.cpp b/src/core/devicescanner.cpp index 1e4da1d..d4b4f7b 100644 --- a/src/core/devicescanner.cpp +++ b/src/core/devicescanner.cpp @@ -63,33 +63,14 @@ void DeviceScanner::scan() clear(); QList deviceList = CoreBackendManager::self()->backend()->scanDevices(); - QList lvmList = scanLvmDevices(); + QList 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 DeviceScanner::scanLvmDevices() const -{ - QList 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; -} diff --git a/src/core/devicescanner.h b/src/core/devicescanner.h index deec515..741c406 100644 --- a/src/core/devicescanner.h +++ b/src/core/devicescanner.h @@ -23,7 +23,6 @@ #include class OperationStack; -class LvmDevice; /** Thread to scan for all available Devices on this computer. @@ -55,8 +54,6 @@ protected: return m_OperationStack; } - QList scanLvmDevices() const; - private: OperationStack& m_OperationStack; }; diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index 5fd2f13..9eee081 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -163,6 +163,21 @@ Partition* LvmDevice::scanPartition(const QString& lvpath, const LvmDevice& dev, return part; } +QList LvmDevice::scanSystemLVM() +{ + QList 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; diff --git a/src/core/lvmdevice.h b/src/core/lvmdevice.h index ac80038..751b614 100644 --- a/src/core/lvmdevice.h +++ b/src/core/lvmdevice.h @@ -52,6 +52,8 @@ public: QList scanPartitions(const LvmDevice& dev, PartitionTable* pTable) const; Partition* scanPartition(const QString& lvPath, const LvmDevice& dev, PartitionTable* pTable) const; + static QList scanSystemLVM(); + static qint64 getPeSize(const QString& vgname); static qint64 getTotalPE(const QString& vgname); static qint64 getAllocatedPE(const QString& vgname);