From 2f700570e0dbf16a181c8c6cdd36b89e88d3d437 Mon Sep 17 00:00:00 2001 From: Chantara Tith Date: Mon, 23 May 2016 17:29:33 +0700 Subject: [PATCH 1/3] setting VG name as PV mount point --- src/fs/lvm2_pv.cpp | 15 ++++++++++++++ src/fs/lvm2_pv.h | 2 ++ src/plugins/libparted/libpartedbackend.cpp | 23 ++++++++++++++++------ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/fs/lvm2_pv.cpp b/src/fs/lvm2_pv.cpp index 5af3c7c..c47ffef 100644 --- a/src/fs/lvm2_pv.cpp +++ b/src/fs/lvm2_pv.cpp @@ -22,6 +22,7 @@ #include "util/capacity.h" #include +#include namespace FS { @@ -110,4 +111,18 @@ bool lvm2_pv::updateUUID(Report& report, const QString& deviceNode) const ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvchange"), QStringLiteral("--uuid"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } + +QString lvm2_pv::getVGName(const QString& deviceNode) //PV node +{ + ExternalCommand cmd( QStringLiteral("lvm"), + { QStringLiteral("pvdisplay"), QStringLiteral("--verbose"), deviceNode }); + if (cmd.run(-1) && cmd.exitCode() == 0) { + QRegularExpression re(QStringLiteral("VG Name\\h+(\\w+)")); + QRegularExpressionMatch vgName = re.match(cmd.output()); + if (vgName.hasMatch()) + return vgName.captured(1); + } + return QString(); +} + } diff --git a/src/fs/lvm2_pv.h b/src/fs/lvm2_pv.h index 398fce5..a63ff5c 100644 --- a/src/fs/lvm2_pv.h +++ b/src/fs/lvm2_pv.h @@ -92,6 +92,8 @@ public: SupportTool supportToolName() const override; bool supportToolFound() const override; + static QString getVGName(const QString& deviceNode); + public: static CommandSupportType m_GetUsed; static CommandSupportType m_GetLabel; diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index a6fa3c4..2f4eec4 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -35,6 +35,7 @@ #include "fs/hfs.h" #include "fs/hfsplus.h" #include "fs/luks.h" +#include "fs/lvm2_pv.h" #include "util/globallog.h" #include "util/helpers.h" @@ -369,12 +370,18 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk) if (isCryptOpen) { luksFs->loadInnerFileSystem(node, mapperNode); - mountPoint = mountPoints.findByDevice(mapperNode) ? - mountPoints.findByDevice(mapperNode)->mountPoint() : - QString(); - // We cannot use libparted to check the mounted status because - // we don't have a PedPartition for the mapper device, so we use lsblk - mounted = isMounted(mapperNode); + if (luksFs->type() == FileSystem::Lvm2_PV) { + mountPoint = FS::lvm2_pv::getVGName(mapperNode); + mounted = false; + } else { + + mountPoint = mountPoints.findByDevice(mapperNode) ? + mountPoints.findByDevice(mapperNode)->mountPoint() : + QString(); + // We cannot use libparted to check the mounted status because + // we don't have a PedPartition for the mapper device, so we use lsblk + mounted = isMounted(mapperNode); + } if (mounted) { const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint); if (freeSpaceInfo.isValid() && mountPoint != QString()) @@ -385,6 +392,10 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk) } luksFs->setMounted(mounted); + } else if (type == FileSystem::Lvm2_PV) { + //TODO: adding PartitionRole + mountPoint = FS::lvm2_pv::getVGName(node); + mounted = false; } else { mountPoint = mountPoints.findByDevice(node) ? mountPoints.findByDevice(node)->mountPoint() : -- 2.43.2 From 97db1c006ed6f06d13756ddead300d2c5d526d86 Mon Sep 17 00:00:00 2001 From: Chantara Tith Date: Wed, 25 May 2016 03:13:23 +0700 Subject: [PATCH 2/3] Implement lvm PV resizing --- src/fs/lvm2_pv.cpp | 17 ++++++++++++++--- src/fs/lvm2_pv.h | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/fs/lvm2_pv.cpp b/src/fs/lvm2_pv.cpp index c47ffef..85bc640 100644 --- a/src/fs/lvm2_pv.cpp +++ b/src/fs/lvm2_pv.cpp @@ -47,7 +47,9 @@ lvm2_pv::lvm2_pv(qint64 firstsector, qint64 lastsector, qint64 sectorsused, cons void lvm2_pv::init() { m_Create = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone; - m_Check = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone; + m_Check = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone; + m_Grow = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone; + m_Shrink = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; m_UpdateUUID = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone; @@ -69,8 +71,8 @@ bool lvm2_pv::supportToolFound() const m_Create != cmdSupportNone && m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && -// m_Grow != cmdSupportNone && -// m_Shrink != cmdSupportNone && + m_Grow != cmdSupportNone && + m_Shrink != cmdSupportNone && // m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && @@ -106,6 +108,15 @@ bool lvm2_pv::remove(Report& report, const QString& deviceNode) const return cmd.run(-1) && cmd.exitCode() == 0; } +bool lvm2_pv::resize(Report& report, const QString& deviceNode, qint64 length) const +{ + // TODO: check if the it is legal to reize + const QString len = QString::number(length / 512) + QStringLiteral("s"); + + ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvresize"), QStringLiteral("--setphysicalvolumesize"), len, deviceNode }); + return cmd.run(-1) && cmd.exitCode() == 0; +} + bool lvm2_pv::updateUUID(Report& report, const QString& deviceNode) const { ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvchange"), QStringLiteral("--uuid"), deviceNode }); diff --git a/src/fs/lvm2_pv.h b/src/fs/lvm2_pv.h index a63ff5c..5bee583 100644 --- a/src/fs/lvm2_pv.h +++ b/src/fs/lvm2_pv.h @@ -47,7 +47,7 @@ public: bool check(Report& report, const QString& deviceNode) const override; bool create(Report& report, const QString& deviceNode) const override; bool remove(Report& report, const QString& deviceNode) const override; -// bool resize(Report& report, const QString& deviceNode, qint64 length) const override; + bool resize(Report& report, const QString& deviceNode, qint64 length) const override; // bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; bool updateUUID(Report& report, const QString& deviceNode) const override; -- 2.43.2 From b1cd46ef97898251b0e5b970c99e933e0a100a64 Mon Sep 17 00:00:00 2001 From: Chantara Tith Date: Thu, 26 May 2016 00:03:03 +0700 Subject: [PATCH 3/3] Add support for reading LVM PV info --- src/fs/lvm2_pv.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++- src/fs/lvm2_pv.h | 7 ++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/fs/lvm2_pv.cpp b/src/fs/lvm2_pv.cpp index 85bc640..99fc26e 100644 --- a/src/fs/lvm2_pv.cpp +++ b/src/fs/lvm2_pv.cpp @@ -110,7 +110,7 @@ bool lvm2_pv::remove(Report& report, const QString& deviceNode) const bool lvm2_pv::resize(Report& report, const QString& deviceNode, qint64 length) const { - // TODO: check if the it is legal to reize + // TODO: check if the it is legal to resize const QString len = QString::number(length / 512) + QStringLiteral("s"); ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvresize"), QStringLiteral("--setphysicalvolumesize"), len, deviceNode }); @@ -136,4 +136,65 @@ QString lvm2_pv::getVGName(const QString& deviceNode) //PV node return QString(); } +qint64 lvm2_pv::getTotalPE(const QString& deviceNode) const { + ExternalCommand cmd( QStringLiteral("lvm"), + { QStringLiteral("pvdisplay"), QStringLiteral("--verbose"), deviceNode }); + if (cmd.run(-1) && cmd.exitCode() == 0) { + QRegularExpression re(QStringLiteral("Total PE\\h+(\\w+)")); + QRegularExpressionMatch totalPE = re.match(cmd.output()); + if (totalPE.hasMatch()) + return totalPE.captured(1).toLongLong(); + } + return -1; + +} + +qint64 lvm2_pv::getFreePE(const QString& deviceNode) const { + ExternalCommand cmd( QStringLiteral("lvm"), + { QStringLiteral("pvdisplay"), QStringLiteral("--verbose"), deviceNode }); + if (cmd.run(-1) && cmd.exitCode() == 0) { + QRegularExpression re(QStringLiteral("Free PE\\h+(\\w+)")); + QRegularExpressionMatch freePE = re.match(cmd.output()); + if (freePE.hasMatch()) + return freePE.captured(1).toLongLong(); + } + return -1; +} + +qint64 lvm2_pv::getAllocatedPE(const QString& deviceNode) const { + ExternalCommand cmd( QStringLiteral("lvm"), + { QStringLiteral("pvdisplay"), QStringLiteral("--verbose"), deviceNode }); + if (cmd.run(-1) && cmd.exitCode() == 0) { + QRegularExpression re(QStringLiteral("Allocated PE\\h+(\\d+)")); + QRegularExpressionMatch allocatedPE = re.match(cmd.output()); + if (allocatedPE.hasMatch()) + return allocatedPE.captured(1).toLongLong(); + } + return -1; +} + +qint64 lvm2_pv::getPVSize(const QString& deviceNode) const { + ExternalCommand cmd( QStringLiteral("lvm"), + { QStringLiteral("pvdisplay"), QStringLiteral("--verbose"), QStringLiteral("--units"), QStringLiteral("B"), deviceNode }); + if (cmd.run(-1) && cmd.exitCode() == 0) { + QRegularExpression re(QStringLiteral("PV Size\\h+(\\d+)")); + QRegularExpressionMatch PVSize = re.match(cmd.output()); + if (PVSize.hasMatch()) + return PVSize.captured(1).toLongLong(); + } + return -1; +} + +qint64 lvm2_pv::getPESize(const QString& deviceNode) const { + ExternalCommand cmd( QStringLiteral("lvm"), + { QStringLiteral("pvdisplay"), QStringLiteral("--verbose"), QStringLiteral("--units"), QStringLiteral("B"), deviceNode }); + if (cmd.run(-1) && cmd.exitCode() == 0) { + QRegularExpression re(QStringLiteral("PE Size\\h+(\\d+)")); + QRegularExpressionMatch PESize = re.match(cmd.output()); + if (PESize.hasMatch()) + return PESize.captured(1).toLongLong(); + } + return -1; +} + } diff --git a/src/fs/lvm2_pv.h b/src/fs/lvm2_pv.h index 5bee583..029881f 100644 --- a/src/fs/lvm2_pv.h +++ b/src/fs/lvm2_pv.h @@ -51,6 +51,7 @@ public: // bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override; bool updateUUID(Report& report, const QString& deviceNode) const override; + CommandSupportType supportGetUsed() const override { return m_GetUsed; } @@ -92,6 +93,12 @@ public: SupportTool supportToolName() const override; bool supportToolFound() const override; + qint64 getTotalPE(const QString& deviceNode) const; + qint64 getFreePE(const QString& deviceNode) const; + qint64 getAllocatedPE(const QString& deviceNode) const; + qint64 getPESize(const QString& deviceNode) const; // return PE size in bytes + qint64 getPVSize(const QString& deviceNode) const; // return PV size in bytes + static QString getVGName(const QString& deviceNode); public: -- 2.43.2