Fixing device scanning process

This commit is contained in:
Caio Carvalho 2019-04-03 15:23:09 -06:00
parent 281289dfbb
commit 43da873c36
5 changed files with 27 additions and 14 deletions

View File

@ -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<const Partition*> s_DirtyPVs;
static QVector<const Partition*> s_OrphanPVs;
static void scanSystemLVM(QList<Device*>& devices);
static const QStringList getVGs();
static const QStringList getLVs(const QString& vgName);
@ -105,6 +105,9 @@ public:
protected:
std::unique_ptr<QHash<QString, qint64>>& LVSizeMap() const;
private:
static void scanSystemLVM(QList<Device*>& devices);
};
#endif

View File

@ -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<Device*>& 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<Device*>& devices);
static QString getDetail(const QString& path);
static QString getRAIDConfiguration(const QString& configurationPath);

View File

@ -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<VolumeManagerDevicePriv
{
}
void VolumeManagerDevice::scanDevices(QList<Device*>& 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(", "));

View File

@ -80,6 +80,8 @@ protected:
public:
static void scanDevices(QList<Device*>& devices);
/** join deviceNodes together into comma-separated list
*
* @return comma-separated list of deviceNodes

View File

@ -117,11 +117,11 @@ QList<Device*> 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<Device *> 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<const DiskDevice*>(&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<const SoftwareRAID*>(&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;