Store the list of LVM Physical Volumes in operationStack.

This is necessary in order to make LVM LV formatted as LVM PV work.
This commit is contained in:
Andrius Štikonas 2016-09-10 22:08:21 +01:00
parent 1995a8de84
commit 123369f78b
6 changed files with 59 additions and 34 deletions

View File

@ -26,6 +26,8 @@
#include "core/lvmdevice.h" #include "core/lvmdevice.h"
#include "core/diskdevice.h" #include "core/diskdevice.h"
#include "fs/lvm2_pv.h"
#include "util/externalcommand.h" #include "util/externalcommand.h"
#include <QRegularExpression> #include <QRegularExpression>
#include <QDebug> #include <QDebug>
@ -63,15 +65,18 @@ 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(deviceList); // NOTE: PVs inside LVM won't be scanned const QList<LvmDevice*> lvmList = LvmDevice::scanSystemLVM(); // NOTE: PVs inside LVM won't be scanned
operationStack().physicalVolumes() = FS::lvm2_pv::getPVs(deviceList);
for (const auto &d : deviceList) for (const auto &d : deviceList)
operationStack().addDevice(d); operationStack().addDevice(d);
operationStack().sortDevices(); operationStack().sortDevices();
for (const auto &d : lvmList) for (const auto &d : lvmList) {
operationStack().addDevice(d); operationStack().addDevice(d);
operationStack().physicalVolumes().append(FS::lvm2_pv::getPVinNode(d->partitionTable()));
}
} }

View File

@ -37,10 +37,9 @@
/** Constructs a representation of LVM device with initialized LV as Partitions /** Constructs a representation of LVM device with initialized LV as Partitions
* *
* @param vgName Volume Group name * @param vgName Volume Group name
* @param devices list of devices where we look for LVM PVs belonging to this VG.
* @param iconName Icon representing LVM Volume group * @param iconName Icon representing LVM Volume group
*/ */
LvmDevice::LvmDevice(const QString& vgName, const QList<Device*>& devices, const QString& iconName) LvmDevice::LvmDevice(const QString& vgName, const QString& iconName)
: VolumeManagerDevice(vgName, : VolumeManagerDevice(vgName,
(QStringLiteral("/dev/") + vgName), (QStringLiteral("/dev/") + vgName),
getPeSize(vgName), getPeSize(vgName),
@ -53,7 +52,6 @@ LvmDevice::LvmDevice(const QString& vgName, const QList<Device*>& devices, const
m_freePE = getFreePE(vgName); m_freePE = getFreePE(vgName);
m_allocPE = m_totalPE - m_freePE; m_allocPE = m_totalPE - m_freePE;
m_UUID = getUUID(vgName); m_UUID = getUUID(vgName);
m_PVs = FS::lvm2_pv::getPVs(devices, vgName);
m_LVPathList = new QStringList(getLVs(vgName)); m_LVPathList = new QStringList(getLVs(vgName));
m_LVSizeMap = new QMap<QString, qint64>(); m_LVSizeMap = new QMap<QString, qint64>();
@ -144,22 +142,35 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl
if (isCryptOpen) { if (isCryptOpen) {
luksFs->loadInnerFileSystem(mapperNode); luksFs->loadInnerFileSystem(mapperNode);
mountPoint = mountPointList.findByDevice(mapperNode) ?
mountPointList.findByDevice(mapperNode)->mountPoint() : if (luksFs->type() == FileSystem::Lvm2_PV) {
QString(); mountPoint = FS::lvm2_pv::getVGName(mapperNode);
if (mountPoint == QStringLiteral("none")) mounted = false;
mountPoint = QString(); }
mounted = isMounted(mapperNode); else {
if (mounted) { mountPoint = mountPointList.findByDevice(mapperNode) ?
const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint); mountPointList.findByDevice(mapperNode)->mountPoint() :
if (freeSpaceInfo.isValid() && mountPoint != QString()) QString();
luksFs->setSectorsUsed((freeSpaceInfo.used() + luksFs->payloadOffset()) / logicalSize()); if (mountPoint == QStringLiteral("none"))
mountPoint = QString();
mounted = isMounted(mapperNode);
if (mounted) {
const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint);
if (freeSpaceInfo.isValid() && mountPoint != QString())
luksFs->setSectorsUsed((freeSpaceInfo.used() + luksFs->payloadOffset()) / logicalSize());
}
} }
} else { } else {
mounted = false; mounted = false;
} }
luksFs->setMounted(mounted); luksFs->setMounted(mounted);
} else { }
else if (type == FileSystem::Lvm2_PV) {
r |= PartitionRole::Lvm_Lv;
mountPoint = FS::lvm2_pv::getVGName(lvPath);
mounted = false;
}
else {
mountPoint = mountPointList.findByDevice(lvPath) ? mountPoint = mountPointList.findByDevice(lvPath) ?
mountPointList.findByDevice(lvPath)->mountPoint() : mountPointList.findByDevice(lvPath)->mountPoint() :
QString(); QString();
@ -198,14 +209,13 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl
/** scan and contruct list of initialized LvmDevice objects. /** scan and contruct list of initialized LvmDevice objects.
* *
* @param devices list of Devices which we scan for LVM PVs
* @return list of initialized LvmDevices * @return list of initialized LvmDevices
*/ */
QList<LvmDevice*> LvmDevice::scanSystemLVM(const QList<Device*>& devices) QList<LvmDevice*> LvmDevice::scanSystemLVM()
{ {
QList<LvmDevice*> lvmList; QList<LvmDevice*> lvmList;
for (const auto &vgName : getVGs()) { for (const auto &vgName : getVGs()) {
lvmList.append(new LvmDevice(vgName, devices)); lvmList.append(new LvmDevice(vgName));
} }
return lvmList; return lvmList;
} }

View File

@ -44,7 +44,7 @@ class LIBKPMCORE_EXPORT LvmDevice : public VolumeManagerDevice
Q_DISABLE_COPY(LvmDevice) Q_DISABLE_COPY(LvmDevice)
public: public:
LvmDevice(const QString& name, const QList<Device *>& devices, const QString& iconName = QString()); LvmDevice(const QString& name, const QString& iconName = QString());
~LvmDevice(); ~LvmDevice();
public: public:
@ -55,7 +55,7 @@ public:
static QStringList s_DirtyPVs; static QStringList s_DirtyPVs;
public: public:
static QList<LvmDevice*> scanSystemLVM(const QList<Device*>& devices); static QList<LvmDevice*> scanSystemLVM();
static const QStringList getVGs(); static const QStringList getVGs();
static const QStringList getLVs(const QString& vgName); static const QStringList getLVs(const QString& vgName);

View File

@ -48,6 +48,7 @@ class LIBKPMCORE_EXPORT OperationStack : public QObject
public: public:
typedef QList<Device*> Devices; typedef QList<Device*> Devices;
typedef QList<QPair<QString, const Partition *>> PhysicalVolumes;
typedef QList<Operation*> Operations; typedef QList<Operation*> Operations;
public: public:
@ -74,6 +75,13 @@ public:
return m_PreviewDevices; /**< @return the list of Devices */ return m_PreviewDevices; /**< @return the list of Devices */
} }
PhysicalVolumes& physicalVolumes() {
return m_LVMPhysicalVolumes; /**< @return the list of LVM PVs */
}
const PhysicalVolumes& physicalVolumes() const {
return m_LVMPhysicalVolumes; /**< @return the list of LVM PVs */
}
Operations& operations() { Operations& operations() {
return m_Operations; /**< @return the list of operations */ return m_Operations; /**< @return the list of operations */
} }
@ -102,6 +110,7 @@ protected:
private: private:
Operations m_Operations; Operations m_Operations;
mutable Devices m_PreviewDevices; mutable Devices m_PreviewDevices;
mutable PhysicalVolumes m_LVMPhysicalVolumes;
QReadWriteLock m_Lock; QReadWriteLock m_Lock;
}; };

View File

@ -17,8 +17,8 @@
*************************************************************************/ *************************************************************************/
#include "core/device.h"
#include "fs/lvm2_pv.h" #include "fs/lvm2_pv.h"
#include "core/device.h"
#include "util/externalcommand.h" #include "util/externalcommand.h"
#include "util/capacity.h" #include "util/capacity.h"
@ -316,9 +316,9 @@ QString lvm2_pv::getVGName(const QString& deviceNode)
return getpvField(QStringLiteral("vg_name"), deviceNode); return getpvField(QStringLiteral("vg_name"), deviceNode);
} }
QList<const Partition *> lvm2_pv::getPVinNode(const PartitionNode* parent, const QString& vgName) lvm2_pv::PhysicalVolumes lvm2_pv::getPVinNode(const PartitionNode* parent)
{ {
QList<const Partition *> partitions; PhysicalVolumes partitions;
if (parent == nullptr) if (parent == nullptr)
return partitions; return partitions;
@ -329,11 +329,11 @@ QList<const Partition *> lvm2_pv::getPVinNode(const PartitionNode* parent, const
continue; continue;
if (node->children().size() > 0) if (node->children().size() > 0)
partitions.append(getPVinNode(node, vgName)); partitions.append(getPVinNode(node));
// FIXME: reenable newly created PVs (before applying) once everything works // FIXME: reenable newly created PVs (before applying) once everything works
if(p->fileSystem().type() == FileSystem::Lvm2_PV && p->mountPoint() == QString() && p->deviceNode() == p->partitionPath()) if(p->fileSystem().type() == FileSystem::Lvm2_PV && p->deviceNode() == p->partitionPath())
partitions.append(p); partitions.append(QPair<QString, const Partition *>(p->mountPoint(), p));
} }
return partitions; return partitions;
@ -342,14 +342,13 @@ QList<const Partition *> lvm2_pv::getPVinNode(const PartitionNode* parent, const
/** construct a list of Partition objects for LVM PVs that are either unused or belong to some VG. /** construct a list of Partition objects for LVM PVs that are either unused or belong to some VG.
* *
* @param devices list of Devices which we scan for LVM PVs * @param devices list of Devices which we scan for LVM PVs
* @param vgName name of the volume group
* @return list of LVM PVs * @return list of LVM PVs
*/ */
QList<const Partition *> lvm2_pv::getPVs(const QList<Device*>& devices, const QString& vgName) lvm2_pv::PhysicalVolumes lvm2_pv::getPVs(const QList<Device*>& devices)
{ {
QList<const Partition *> partitions; PhysicalVolumes partitions;
for (auto const &d : devices) for (auto const &d : devices)
partitions.append(getPVinNode(d->partitionTable(), vgName)); partitions.append(getPVinNode(d->partitionTable()));
return partitions; return partitions;
} }

View File

@ -38,6 +38,9 @@ namespace FS
*/ */
class LIBKPMCORE_EXPORT lvm2_pv : public FileSystem class LIBKPMCORE_EXPORT lvm2_pv : public FileSystem
{ {
public:
typedef QList<QPair<QString, const Partition *>> PhysicalVolumes;
public: public:
lvm2_pv(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label); lvm2_pv(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label);
@ -114,8 +117,8 @@ public:
static qint64 getPVSize(const QString& deviceNode); // return PV size in bytes static qint64 getPVSize(const QString& deviceNode); // return PV size in bytes
static qint64 getPVSize(const QStringList& deviceNodeList); static qint64 getPVSize(const QStringList& deviceNodeList);
static QString getVGName(const QString& deviceNode); static QString getVGName(const QString& deviceNode);
static QList<const Partition *> getPVinNode(const PartitionNode* parent, const QString& vgName = QString()); static PhysicalVolumes getPVinNode(const PartitionNode* parent);
static QList<const Partition *> getPVs(const QList<Device*>& devices, const QString& vgName = QString()); static PhysicalVolumes getPVs(const QList<Device*>& devices);
qint64 allocatedPE() const { return m_AllocatedPE; }; qint64 allocatedPE() const { return m_AllocatedPE; };
qint64 freePE() const { return m_TotalPE - m_AllocatedPE; }; qint64 freePE() const { return m_TotalPE - m_AllocatedPE; };
@ -140,7 +143,6 @@ private:
qint64 m_PESize; qint64 m_PESize;
qint64 m_TotalPE; qint64 m_TotalPE;
qint64 m_AllocatedPE; qint64 m_AllocatedPE;
}; };
} }