From 123369f78bb9a1d92ed93f1a4bca0b716edf5b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sat, 10 Sep 2016 22:08:21 +0100 Subject: [PATCH] Store the list of LVM Physical Volumes in operationStack. This is necessary in order to make LVM LV formatted as LVM PV work. --- src/core/devicescanner.cpp | 9 ++++++-- src/core/lvmdevice.cpp | 44 +++++++++++++++++++++++--------------- src/core/lvmdevice.h | 4 ++-- src/core/operationstack.h | 9 ++++++++ src/fs/lvm2_pv.cpp | 19 ++++++++-------- src/fs/lvm2_pv.h | 8 ++++--- 6 files changed, 59 insertions(+), 34 deletions(-) diff --git a/src/core/devicescanner.cpp b/src/core/devicescanner.cpp index aa5be4e..632cb9b 100644 --- a/src/core/devicescanner.cpp +++ b/src/core/devicescanner.cpp @@ -26,6 +26,8 @@ #include "core/lvmdevice.h" #include "core/diskdevice.h" +#include "fs/lvm2_pv.h" + #include "util/externalcommand.h" #include #include @@ -63,15 +65,18 @@ void DeviceScanner::scan() clear(); const QList deviceList = CoreBackendManager::self()->backend()->scanDevices(); - const QList lvmList = LvmDevice::scanSystemLVM(deviceList); // NOTE: PVs inside LVM won't be scanned + const QList lvmList = LvmDevice::scanSystemLVM(); // NOTE: PVs inside LVM won't be scanned + operationStack().physicalVolumes() = FS::lvm2_pv::getPVs(deviceList); for (const auto &d : deviceList) operationStack().addDevice(d); operationStack().sortDevices(); - for (const auto &d : lvmList) + for (const auto &d : lvmList) { operationStack().addDevice(d); + operationStack().physicalVolumes().append(FS::lvm2_pv::getPVinNode(d->partitionTable())); + } } diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index f99bc6e..4bff050 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -37,10 +37,9 @@ /** Constructs a representation of LVM device with initialized LV as Partitions * * @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 */ -LvmDevice::LvmDevice(const QString& vgName, const QList& devices, const QString& iconName) +LvmDevice::LvmDevice(const QString& vgName, const QString& iconName) : VolumeManagerDevice(vgName, (QStringLiteral("/dev/") + vgName), getPeSize(vgName), @@ -53,7 +52,6 @@ LvmDevice::LvmDevice(const QString& vgName, const QList& devices, const m_freePE = getFreePE(vgName); m_allocPE = m_totalPE - m_freePE; m_UUID = getUUID(vgName); - m_PVs = FS::lvm2_pv::getPVs(devices, vgName); m_LVPathList = new QStringList(getLVs(vgName)); m_LVSizeMap = new QMap(); @@ -144,22 +142,35 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl if (isCryptOpen) { luksFs->loadInnerFileSystem(mapperNode); - mountPoint = mountPointList.findByDevice(mapperNode) ? - mountPointList.findByDevice(mapperNode)->mountPoint() : - QString(); - 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()); + + if (luksFs->type() == FileSystem::Lvm2_PV) { + mountPoint = FS::lvm2_pv::getVGName(mapperNode); + mounted = false; + } + else { + mountPoint = mountPointList.findByDevice(mapperNode) ? + mountPointList.findByDevice(mapperNode)->mountPoint() : + QString(); + 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 { mounted = false; } 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) ? mountPointList.findByDevice(lvPath)->mountPoint() : QString(); @@ -198,14 +209,13 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl /** scan and contruct list of initialized LvmDevice objects. * - * @param devices list of Devices which we scan for LVM PVs * @return list of initialized LvmDevices */ -QList LvmDevice::scanSystemLVM(const QList& devices) +QList LvmDevice::scanSystemLVM() { QList lvmList; for (const auto &vgName : getVGs()) { - lvmList.append(new LvmDevice(vgName, devices)); + lvmList.append(new LvmDevice(vgName)); } return lvmList; } diff --git a/src/core/lvmdevice.h b/src/core/lvmdevice.h index 535d805..fff4077 100644 --- a/src/core/lvmdevice.h +++ b/src/core/lvmdevice.h @@ -44,7 +44,7 @@ class LIBKPMCORE_EXPORT LvmDevice : public VolumeManagerDevice Q_DISABLE_COPY(LvmDevice) public: - LvmDevice(const QString& name, const QList& devices, const QString& iconName = QString()); + LvmDevice(const QString& name, const QString& iconName = QString()); ~LvmDevice(); public: @@ -55,7 +55,7 @@ public: static QStringList s_DirtyPVs; public: - static QList scanSystemLVM(const QList& devices); + static QList scanSystemLVM(); static const QStringList getVGs(); static const QStringList getLVs(const QString& vgName); diff --git a/src/core/operationstack.h b/src/core/operationstack.h index b6fbfac..fd9ce1f 100644 --- a/src/core/operationstack.h +++ b/src/core/operationstack.h @@ -48,6 +48,7 @@ class LIBKPMCORE_EXPORT OperationStack : public QObject public: typedef QList Devices; + typedef QList> PhysicalVolumes; typedef QList Operations; public: @@ -74,6 +75,13 @@ public: 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() { return m_Operations; /**< @return the list of operations */ } @@ -102,6 +110,7 @@ protected: private: Operations m_Operations; mutable Devices m_PreviewDevices; + mutable PhysicalVolumes m_LVMPhysicalVolumes; QReadWriteLock m_Lock; }; diff --git a/src/fs/lvm2_pv.cpp b/src/fs/lvm2_pv.cpp index 36ba4d2..aa0f73c 100644 --- a/src/fs/lvm2_pv.cpp +++ b/src/fs/lvm2_pv.cpp @@ -17,8 +17,8 @@ *************************************************************************/ -#include "core/device.h" #include "fs/lvm2_pv.h" +#include "core/device.h" #include "util/externalcommand.h" #include "util/capacity.h" @@ -316,9 +316,9 @@ QString lvm2_pv::getVGName(const QString& deviceNode) return getpvField(QStringLiteral("vg_name"), deviceNode); } -QList lvm2_pv::getPVinNode(const PartitionNode* parent, const QString& vgName) +lvm2_pv::PhysicalVolumes lvm2_pv::getPVinNode(const PartitionNode* parent) { - QList partitions; + PhysicalVolumes partitions; if (parent == nullptr) return partitions; @@ -329,11 +329,11 @@ QList lvm2_pv::getPVinNode(const PartitionNode* parent, const continue; if (node->children().size() > 0) - partitions.append(getPVinNode(node, vgName)); + partitions.append(getPVinNode(node)); // FIXME: reenable newly created PVs (before applying) once everything works - if(p->fileSystem().type() == FileSystem::Lvm2_PV && p->mountPoint() == QString() && p->deviceNode() == p->partitionPath()) - partitions.append(p); + if(p->fileSystem().type() == FileSystem::Lvm2_PV && p->deviceNode() == p->partitionPath()) + partitions.append(QPair(p->mountPoint(), p)); } return partitions; @@ -342,14 +342,13 @@ QList 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. * * @param devices list of Devices which we scan for LVM PVs - * @param vgName name of the volume group * @return list of LVM PVs */ -QList lvm2_pv::getPVs(const QList& devices, const QString& vgName) +lvm2_pv::PhysicalVolumes lvm2_pv::getPVs(const QList& devices) { - QList partitions; + PhysicalVolumes partitions; for (auto const &d : devices) - partitions.append(getPVinNode(d->partitionTable(), vgName)); + partitions.append(getPVinNode(d->partitionTable())); return partitions; } diff --git a/src/fs/lvm2_pv.h b/src/fs/lvm2_pv.h index b175411..a28ae48 100644 --- a/src/fs/lvm2_pv.h +++ b/src/fs/lvm2_pv.h @@ -38,6 +38,9 @@ namespace FS */ class LIBKPMCORE_EXPORT lvm2_pv : public FileSystem { +public: + typedef QList> PhysicalVolumes; + public: 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 QStringList& deviceNodeList); static QString getVGName(const QString& deviceNode); - static QList getPVinNode(const PartitionNode* parent, const QString& vgName = QString()); - static QList getPVs(const QList& devices, const QString& vgName = QString()); + static PhysicalVolumes getPVinNode(const PartitionNode* parent); + static PhysicalVolumes getPVs(const QList& devices); qint64 allocatedPE() const { return m_AllocatedPE; }; qint64 freePE() const { return m_TotalPE - m_AllocatedPE; }; @@ -140,7 +143,6 @@ private: qint64 m_PESize; qint64 m_TotalPE; qint64 m_AllocatedPE; - }; }