From 43da873c36320e6951b0e84c69ba124068d2546e Mon Sep 17 00:00:00 2001 From: Caio Carvalho Date: Wed, 3 Apr 2019 15:23:09 -0600 Subject: [PATCH] Fixing device scanning process --- src/core/lvmdevice.h | 7 +++++-- src/core/raid/softwareraid.h | 6 ++++-- src/core/volumemanagerdevice.cpp | 8 ++++++++ src/core/volumemanagerdevice.h | 2 ++ src/plugins/sfdisk/sfdiskbackend.cpp | 18 ++++++++---------- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/core/lvmdevice.h b/src/core/lvmdevice.h index 18b546f..922ed01 100644 --- a/src/core/lvmdevice.h +++ b/src/core/lvmdevice.h @@ -45,6 +45,8 @@ class LIBKPMCORE_EXPORT LvmDevice : public VolumeManagerDevice { Q_DISABLE_COPY(LvmDevice) + friend class VolumeManagerDevice; + public: LvmDevice(const QString& name, const QString& iconName = QString()); ~LvmDevice(); @@ -57,8 +59,6 @@ public: static QVector s_DirtyPVs; static QVector s_OrphanPVs; - static void scanSystemLVM(QList& devices); - static const QStringList getVGs(); static const QStringList getLVs(const QString& vgName); @@ -105,6 +105,9 @@ public: protected: std::unique_ptr>& LVSizeMap() const; + +private: + static void scanSystemLVM(QList& devices); }; #endif diff --git a/src/core/raid/softwareraid.h b/src/core/raid/softwareraid.h index 803ec54..447856b 100644 --- a/src/core/raid/softwareraid.h +++ b/src/core/raid/softwareraid.h @@ -26,6 +26,8 @@ class LIBKPMCORE_EXPORT SoftwareRAID : public VolumeManagerDevice { Q_DISABLE_COPY(SoftwareRAID) + friend class VolumeManagerDevice; + public: enum class Status { Active, @@ -61,8 +63,6 @@ public: void setStatus(SoftwareRAID::Status status); public: - static void scanSoftwareRAID(QList& devices); - static qint32 getRaidLevel(const QString& path); static qint64 getChunkSize(const QString& path); static qint64 getTotalChunk(const QString& path); @@ -95,6 +95,8 @@ protected: qint64 mappedSector(const QString &partitionPath, qint64 sector) const override; private: + static void scanSoftwareRAID(QList& devices); + static QString getDetail(const QString& path); static QString getRAIDConfiguration(const QString& configurationPath); diff --git a/src/core/volumemanagerdevice.cpp b/src/core/volumemanagerdevice.cpp index 7c339af..68036d1 100644 --- a/src/core/volumemanagerdevice.cpp +++ b/src/core/volumemanagerdevice.cpp @@ -19,6 +19,8 @@ #include "core/device_p.h" #include "core/volumemanagerdevice.h" #include "core/volumemanagerdevice_p.h" +#include "core/lvmdevice.h" +#include "core/raid/softwareraid.h" /** Constructs an abstract Volume Manager Device with an empty PartitionTable. * @@ -37,6 +39,12 @@ VolumeManagerDevice::VolumeManagerDevice(std::shared_ptr& devices) +{ + SoftwareRAID::scanSoftwareRAID(devices); + LvmDevice::scanSystemLVM(devices); // LVM scanner needs all other devices, so should be last +} + QString VolumeManagerDevice::prettyDeviceNodeList() const { return deviceNodes().join(QStringLiteral(", ")); diff --git a/src/core/volumemanagerdevice.h b/src/core/volumemanagerdevice.h index f1750dd..787d573 100644 --- a/src/core/volumemanagerdevice.h +++ b/src/core/volumemanagerdevice.h @@ -80,6 +80,8 @@ protected: public: + static void scanDevices(QList& devices); + /** join deviceNodes together into comma-separated list * * @return comma-separated list of deviceNodes diff --git a/src/plugins/sfdisk/sfdiskbackend.cpp b/src/plugins/sfdisk/sfdiskbackend.cpp index 42ef5c0..f9cc60b 100644 --- a/src/plugins/sfdisk/sfdiskbackend.cpp +++ b/src/plugins/sfdisk/sfdiskbackend.cpp @@ -117,11 +117,11 @@ QList SfdiskBackend::scanDevices(const ScanFlags scanFlags) result.append(device); } } - - SoftwareRAID::scanSoftwareRAID(result); - LvmDevice::scanSystemLVM(result); // LVM scanner needs all other devices, so should be last + } + VolumeManagerDevice::scanDevices(result); // scan all types of VolumeManagerDevices + return result; } @@ -224,8 +224,6 @@ Device* SfdiskBackend::scanDevice(const QString& deviceNode) { QList availableDevices = scanDevices(); - LvmDevice::scanSystemLVM(availableDevices); - for (Device *device : qAsConst(availableDevices)) if (device->deviceNode() == deviceNode) return device; @@ -329,16 +327,15 @@ bool SfdiskBackend::updateDevicePartitionTable(Device &d, const QJsonObject &jso QString tableType = jsonPartitionTable[QLatin1String("label")].toString(); const PartitionTable::TableType type = PartitionTable::nameToTableType(tableType); - qint64 firstUsableSector = 0, lastUsableSector; + qint64 firstUsableSector = 0; + qint64 lastUsableSector; - if ( d.type() == Device::Type::Disk_Device ) - { + if (d.type() == Device::Type::Disk_Device) { const DiskDevice* diskDevice = static_cast(&d); lastUsableSector = diskDevice->totalSectors(); } - else if ( d.type() == Device::Type::SoftwareRAID_Device ) - { + else if (d.type() == Device::Type::SoftwareRAID_Device) { const SoftwareRAID* raidDevice = static_cast(&d); lastUsableSector = raidDevice->totalLogical() - 1; @@ -373,6 +370,7 @@ bool SfdiskBackend::updateDevicePartitionTable(Device &d, const QJsonObject &jso else maxEntries = 128; CoreBackend::setPartitionTableMaxPrimaries(*d.partitionTable(), maxEntries); + break; } default: break;