Browse Source

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.
raid-support
Andrius Štikonas 4 years ago
parent
commit
2760f02fbf
7 changed files with 32 additions and 31 deletions
  1. +3
    -6
      README.md
  2. +0
    -18
      src/core/devicescanner.cpp
  3. +18
    -3
      src/core/lvmdevice.cpp
  4. +1
    -1
      src/core/lvmdevice.h
  5. +4
    -0
      src/core/operationstack.cpp
  6. +4
    -2
      src/plugins/libparted/libpartedbackend.cpp
  7. +2
    -1
      src/plugins/libparted/libpartedbackend.h

+ 3
- 6
README.md 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()`.

+ 0
- 18
src/core/devicescanner.cpp 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());
}

+ 18
- 3
src/core/lvmdevice.cpp 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


+ 1
- 1
src/core/lvmdevice.h 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);


+ 4
- 0
src/core/operationstack.cpp 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();
}


+ 4
- 2
src/plugins/libparted/libpartedbackend.cpp 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;


+ 2
- 1
src/plugins/libparted/libpartedbackend.h 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;


Loading…
Cancel
Save