Move LVM device scanning code.
Now it's the backend's responsibility to find LVM devices. All LVM scanning code was moved into LvmDevice::scanSystemLVM helper, so that it is very easy to plug LVM into backend. LVM devices are now intentionally not detected in Dummy Backend.
This commit is contained in:
parent
15eabf9859
commit
2760f02fbf
|
@ -71,9 +71,7 @@ back to a default backend suitable for the current platform.
|
||||||
Calling KPMcore functions before the library is initialized will
|
Calling KPMcore functions before the library is initialized will
|
||||||
result in undefined behavior.
|
result in undefined behavior.
|
||||||
|
|
||||||
### Devices [FIXME: WIP]
|
### Devices
|
||||||
|
|
||||||
#### Backend device scanner
|
|
||||||
|
|
||||||
After the backend is initialized you can scan for available devices.
|
After the backend is initialized you can scan for available devices.
|
||||||
If you only want devices from the loaded backend you can call
|
If you only want devices from the loaded backend you can call
|
||||||
|
@ -87,8 +85,7 @@ read only devices.
|
||||||
|
|
||||||
#### KPMcore device scanner
|
#### KPMcore device scanner
|
||||||
|
|
||||||
Alternatively, you can use KPMcore device scanner which also finds
|
Alternatively, you can use KPMcore device scanner
|
||||||
LVM Volume Groups.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
#include <core/device.h>
|
#include <core/device.h>
|
||||||
|
@ -102,6 +99,6 @@ LVM Volume Groups.
|
||||||
QList<Device*> devices = operationStack->previewDevices();
|
QList<Device*> devices = operationStack->previewDevices();
|
||||||
```
|
```
|
||||||
|
|
||||||
When `deviceScanner` scans for the devices in a background thread. After
|
Then `deviceScanner` scans for the devices in a background thread. After
|
||||||
scanning is complete `DeviceScanner::finished()` signal will be emitted.
|
scanning is complete `DeviceScanner::finished()` signal will be emitted.
|
||||||
Then the devices can accessed using `operationStack->previewDevices()`.
|
Then the devices can accessed using `operationStack->previewDevices()`.
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
#include "core/operationstack.h"
|
#include "core/operationstack.h"
|
||||||
#include "core/device.h"
|
#include "core/device.h"
|
||||||
#include "core/lvmdevice.h"
|
|
||||||
#include "core/diskdevice.h"
|
#include "core/diskdevice.h"
|
||||||
|
|
||||||
#include "fs/lvm2_pv.h"
|
#include "fs/lvm2_pv.h"
|
||||||
|
@ -65,27 +64,10 @@ void DeviceScanner::scan()
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
const QList<Device*> deviceList = CoreBackendManager::self()->backend()->scanDevices();
|
const QList<Device*> deviceList = CoreBackendManager::self()->backend()->scanDevices();
|
||||||
const QList<LvmDevice*> lvmList = LvmDevice::scanSystemLVM();
|
|
||||||
|
|
||||||
// Some LVM operations require additional information about LVM physical volumes which we store in LVM::pvList
|
|
||||||
LVM::pvList = FS::lvm2_pv::getPVs(deviceList);
|
|
||||||
|
|
||||||
for (const auto &d : deviceList)
|
for (const auto &d : deviceList)
|
||||||
operationStack().addDevice(d);
|
operationStack().addDevice(d);
|
||||||
|
|
||||||
// Display alphabetically sorted disk devices above LVM VGs
|
|
||||||
operationStack().sortDevices();
|
operationStack().sortDevices();
|
||||||
|
|
||||||
// Look for LVM physical volumes in LVM VGs
|
|
||||||
for (const auto &d : lvmList) {
|
|
||||||
operationStack().addDevice(d);
|
|
||||||
LVM::pvList.append(FS::lvm2_pv::getPVinNode(d->partitionTable()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inform LvmDevice about which physical volumes form that particular LvmDevice
|
|
||||||
for (const auto &d : lvmList)
|
|
||||||
for (const auto &p : qAsConst(LVM::pvList))
|
|
||||||
if (p.vgName() == d->name())
|
|
||||||
d->physicalVolumes().append(p.partition());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,15 +171,30 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl
|
||||||
|
|
||||||
/** scan and construct list of initialized LvmDevice objects.
|
/** scan and construct list of initialized LvmDevice objects.
|
||||||
*
|
*
|
||||||
* @return list of initialized LvmDevices
|
* @param devices list of initialized Devices
|
||||||
*/
|
*/
|
||||||
QList<LvmDevice*> LvmDevice::scanSystemLVM()
|
void LvmDevice::scanSystemLVM(QList<Device*>& devices)
|
||||||
{
|
{
|
||||||
QList<LvmDevice*> lvmList;
|
QList<LvmDevice*> lvmList;
|
||||||
for (const auto &vgName : getVGs()) {
|
for (const auto &vgName : getVGs()) {
|
||||||
lvmList.append(new LvmDevice(vgName));
|
lvmList.append(new LvmDevice(vgName));
|
||||||
}
|
}
|
||||||
return lvmList;
|
|
||||||
|
// Some LVM operations require additional information about LVM physical volumes which we store in LVM::pvList
|
||||||
|
LVM::pvList = FS::lvm2_pv::getPVs(devices);
|
||||||
|
|
||||||
|
// Look for LVM physical volumes in LVM VGs
|
||||||
|
for (const auto &d : lvmList) {
|
||||||
|
devices.append(d);
|
||||||
|
LVM::pvList.append(FS::lvm2_pv::getPVinNode(d->partitionTable()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inform LvmDevice about which physical volumes form that particular LvmDevice
|
||||||
|
for (const auto &d : lvmList)
|
||||||
|
for (const auto &p : qAsConst(LVM::pvList))
|
||||||
|
if (p.vgName() == d->name())
|
||||||
|
d->physicalVolumes().append(p.partition());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LvmDevice::mappedSector(const QString& lvPath, qint64 sector) const
|
qint64 LvmDevice::mappedSector(const QString& lvPath, qint64 sector) const
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
static QVector<const Partition*> s_DirtyPVs;
|
static QVector<const Partition*> s_DirtyPVs;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QList<LvmDevice*> scanSystemLVM();
|
static void scanSystemLVM(QList<Device*>& devices);
|
||||||
|
|
||||||
static const QStringList getVGs();
|
static const QStringList getVGs();
|
||||||
static const QStringList getLVs(const QString& vgName);
|
static const QStringList getLVs(const QString& vgName);
|
||||||
|
|
|
@ -554,6 +554,10 @@ void OperationStack::addDevice(Device* d)
|
||||||
|
|
||||||
static bool deviceLessThan(const Device* d1, const Device* d2)
|
static bool deviceLessThan(const Device* d1, const Device* d2)
|
||||||
{
|
{
|
||||||
|
// Display alphabetically sorted disk devices above LVM VGs
|
||||||
|
if (d1->type() == Device::LVM_Device && d2->type() == Device::Disk_Device )
|
||||||
|
return false;
|
||||||
|
|
||||||
return d1->deviceNode() <= d2->deviceNode();
|
return d1->deviceNode() <= d2->deviceNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "plugins/libparted/libparteddevice.h"
|
#include "plugins/libparted/libparteddevice.h"
|
||||||
#include "plugins/libparted/pedflags.h"
|
#include "plugins/libparted/pedflags.h"
|
||||||
|
|
||||||
#include "core/diskdevice.h"
|
#include "core/lvmdevice.h"
|
||||||
#include "core/partition.h"
|
#include "core/partition.h"
|
||||||
#include "core/partitiontable.h"
|
#include "core/partitiontable.h"
|
||||||
#include "core/partitionalignment.h"
|
#include "core/partitionalignment.h"
|
||||||
|
@ -384,7 +384,7 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk)
|
||||||
@param deviceNode the device node (e.g. "/dev/sda")
|
@param deviceNode the device node (e.g. "/dev/sda")
|
||||||
@return the created Device object. callers need to free this.
|
@return the created Device object. callers need to free this.
|
||||||
*/
|
*/
|
||||||
Device* LibPartedBackend::scanDevice(const QString& deviceNode)
|
DiskDevice* LibPartedBackend::scanDevice(const QString& deviceNode)
|
||||||
{
|
{
|
||||||
PedDevice* pedDevice = ped_device_get(deviceNode.toLocal8Bit().constData());
|
PedDevice* pedDevice = ped_device_get(deviceNode.toLocal8Bit().constData());
|
||||||
|
|
||||||
|
@ -456,6 +456,8 @@ QList<Device*> LibPartedBackend::scanDevices(bool excludeReadOnly)
|
||||||
result.append(device);
|
result.append(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LvmDevice::scanSystemLVM(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "backend/corebackend.h"
|
#include "backend/corebackend.h"
|
||||||
|
|
||||||
#include "core/partitiontable.h"
|
#include "core/partitiontable.h"
|
||||||
|
#include "core/diskdevice.h"
|
||||||
#include "util/libpartitionmanagerexport.h"
|
#include "util/libpartitionmanagerexport.h"
|
||||||
|
|
||||||
#include "fs/filesystem.h"
|
#include "fs/filesystem.h"
|
||||||
|
@ -63,7 +64,7 @@ public:
|
||||||
CoreBackendDevice* openDevice(const QString& deviceNode) override;
|
CoreBackendDevice* openDevice(const QString& deviceNode) override;
|
||||||
CoreBackendDevice* openDeviceExclusive(const QString& deviceNode) override;
|
CoreBackendDevice* openDeviceExclusive(const QString& deviceNode) override;
|
||||||
bool closeDevice(CoreBackendDevice* core_device) override;
|
bool closeDevice(CoreBackendDevice* core_device) override;
|
||||||
Device* scanDevice(const QString& deviceNode) override;
|
DiskDevice* scanDevice(const QString& deviceNode) override;
|
||||||
QList<Device*> scanDevices(bool excludeReadOnly = false) override;
|
QList<Device*> scanDevices(bool excludeReadOnly = false) override;
|
||||||
FileSystem::Type detectFileSystem(const QString& partitionPath) override;
|
FileSystem::Type detectFileSystem(const QString& partitionPath) override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue