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:
Andrius Štikonas 2017-10-06 03:17:51 +01:00
parent 15eabf9859
commit 2760f02fbf
7 changed files with 32 additions and 31 deletions

View File

@ -71,9 +71,7 @@ back to a default backend suitable for the current platform.
Calling KPMcore functions before the library is initialized will
result in undefined behavior.
### Devices [FIXME: WIP]
#### Backend device scanner
### Devices
After the backend is initialized you can scan for available devices.
If you only want devices from the loaded backend you can call
@ -87,8 +85,7 @@ read only devices.
#### KPMcore device scanner
Alternatively, you can use KPMcore device scanner which also finds
LVM Volume Groups.
Alternatively, you can use KPMcore device scanner
```
#include <core/device.h>
@ -102,6 +99,6 @@ LVM Volume Groups.
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.
Then the devices can accessed using `operationStack->previewDevices()`.

View File

@ -23,7 +23,6 @@
#include "core/operationstack.h"
#include "core/device.h"
#include "core/lvmdevice.h"
#include "core/diskdevice.h"
#include "fs/lvm2_pv.h"
@ -65,27 +64,10 @@ void DeviceScanner::scan()
clear();
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)
operationStack().addDevice(d);
// Display alphabetically sorted disk devices above LVM VGs
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());
}

View File

@ -171,15 +171,30 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl
/** 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;
for (const auto &vgName : getVGs()) {
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

View File

@ -58,7 +58,7 @@ public:
static QVector<const Partition*> s_DirtyPVs;
public:
static QList<LvmDevice*> scanSystemLVM();
static void scanSystemLVM(QList<Device*>& devices);
static const QStringList getVGs();
static const QStringList getLVs(const QString& vgName);

View File

@ -554,6 +554,10 @@ void OperationStack::addDevice(Device* d)
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();
}

View File

@ -24,7 +24,7 @@
#include "plugins/libparted/libparteddevice.h"
#include "plugins/libparted/pedflags.h"
#include "core/diskdevice.h"
#include "core/lvmdevice.h"
#include "core/partition.h"
#include "core/partitiontable.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")
@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());
@ -456,6 +456,8 @@ QList<Device*> LibPartedBackend::scanDevices(bool excludeReadOnly)
result.append(device);
}
}
LvmDevice::scanSystemLVM(result);
}
return result;

View File

@ -23,6 +23,7 @@
#include "backend/corebackend.h"
#include "core/partitiontable.h"
#include "core/diskdevice.h"
#include "util/libpartitionmanagerexport.h"
#include "fs/filesystem.h"
@ -63,7 +64,7 @@ public:
CoreBackendDevice* openDevice(const QString& deviceNode) override;
CoreBackendDevice* openDeviceExclusive(const QString& deviceNode) 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;
FileSystem::Type detectFileSystem(const QString& partitionPath) override;