Set VG as PV's mount point if it belong to one. #3
|
@ -22,6 +22,7 @@
|
||||||
#include "util/capacity.h"
|
#include "util/capacity.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
namespace FS
|
namespace FS
|
||||||
{
|
{
|
||||||
|
@ -47,6 +48,8 @@ void lvm2_pv::init()
|
||||||
{
|
{
|
||||||
m_Create = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone;
|
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_GetLabel = cmdSupportCore;
|
||||||
m_UpdateUUID = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone;
|
m_UpdateUUID = findExternal(QStringLiteral("lvm")) ? cmdSupportFileSystem : cmdSupportNone;
|
||||||
|
@ -68,8 +71,8 @@ bool lvm2_pv::supportToolFound() const
|
||||||
m_Create != cmdSupportNone &&
|
m_Create != cmdSupportNone &&
|
||||||
m_Check != cmdSupportNone &&
|
m_Check != cmdSupportNone &&
|
||||||
m_UpdateUUID != cmdSupportNone &&
|
m_UpdateUUID != cmdSupportNone &&
|
||||||
// m_Grow != cmdSupportNone &&
|
m_Grow != cmdSupportNone &&
|
||||||
// m_Shrink != cmdSupportNone &&
|
m_Shrink != cmdSupportNone &&
|
||||||
// m_Copy != cmdSupportNone &&
|
// m_Copy != cmdSupportNone &&
|
||||||
m_Move != cmdSupportNone &&
|
m_Move != cmdSupportNone &&
|
||||||
m_Backup != cmdSupportNone &&
|
m_Backup != cmdSupportNone &&
|
||||||
|
@ -105,9 +108,93 @@ bool lvm2_pv::remove(Report& report, const QString& deviceNode) const
|
||||||
return cmd.run(-1) && cmd.exitCode() == 0;
|
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 resize
|
||||||
|
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
|
bool lvm2_pv::updateUUID(Report& report, const QString& deviceNode) const
|
||||||
{
|
{
|
||||||
ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvchange"), QStringLiteral("--uuid"), deviceNode });
|
ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvchange"), QStringLiteral("--uuid"), deviceNode });
|
||||||
return cmd.run(-1) && cmd.exitCode() == 0;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,10 +47,11 @@ public:
|
||||||
bool check(Report& report, const QString& deviceNode) const override;
|
bool check(Report& report, const QString& deviceNode) const override;
|
||||||
bool create(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 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 writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override;
|
||||||
bool updateUUID(Report& report, const QString& deviceNode) const override;
|
bool updateUUID(Report& report, const QString& deviceNode) const override;
|
||||||
|
|
||||||
|
|
||||||
CommandSupportType supportGetUsed() const override {
|
CommandSupportType supportGetUsed() const override {
|
||||||
return m_GetUsed;
|
return m_GetUsed;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +93,14 @@ public:
|
||||||
SupportTool supportToolName() const override;
|
SupportTool supportToolName() const override;
|
||||||
bool supportToolFound() 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:
|
public:
|
||||||
static CommandSupportType m_GetUsed;
|
static CommandSupportType m_GetUsed;
|
||||||
static CommandSupportType m_GetLabel;
|
static CommandSupportType m_GetLabel;
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "fs/hfs.h"
|
#include "fs/hfs.h"
|
||||||
#include "fs/hfsplus.h"
|
#include "fs/hfsplus.h"
|
||||||
#include "fs/luks.h"
|
#include "fs/luks.h"
|
||||||
|
#include "fs/lvm2_pv.h"
|
||||||
|
|
||||||
#include "util/globallog.h"
|
#include "util/globallog.h"
|
||||||
#include "util/helpers.h"
|
#include "util/helpers.h"
|
||||||
|
@ -369,12 +370,18 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk)
|
||||||
if (isCryptOpen) {
|
if (isCryptOpen) {
|
||||||
luksFs->loadInnerFileSystem(node, mapperNode);
|
luksFs->loadInnerFileSystem(node, mapperNode);
|
||||||
|
|
||||||
|
if (luksFs->type() == FileSystem::Lvm2_PV) {
|
||||||
|
mountPoint = FS::lvm2_pv::getVGName(mapperNode);
|
||||||
|
mounted = false;
|
||||||
|
} else {
|
||||||
|
|
||||||
mountPoint = mountPoints.findByDevice(mapperNode) ?
|
mountPoint = mountPoints.findByDevice(mapperNode) ?
|
||||||
mountPoints.findByDevice(mapperNode)->mountPoint() :
|
mountPoints.findByDevice(mapperNode)->mountPoint() :
|
||||||
QString();
|
QString();
|
||||||
// We cannot use libparted to check the mounted status because
|
// We cannot use libparted to check the mounted status because
|
||||||
// we don't have a PedPartition for the mapper device, so we use lsblk
|
// we don't have a PedPartition for the mapper device, so we use lsblk
|
||||||
mounted = isMounted(mapperNode);
|
mounted = isMounted(mapperNode);
|
||||||
|
}
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint);
|
const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint);
|
||||||
if (freeSpaceInfo.isValid() && mountPoint != QString())
|
if (freeSpaceInfo.isValid() && mountPoint != QString())
|
||||||
|
@ -385,6 +392,10 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk)
|
||||||
}
|
}
|
||||||
|
|
||||||
luksFs->setMounted(mounted);
|
luksFs->setMounted(mounted);
|
||||||
|
} else if (type == FileSystem::Lvm2_PV) {
|
||||||
|
//TODO: adding PartitionRole
|
||||||
|
mountPoint = FS::lvm2_pv::getVGName(node);
|
||||||
|
mounted = false;
|
||||||
} else {
|
} else {
|
||||||
mountPoint = mountPoints.findByDevice(node) ?
|
mountPoint = mountPoints.findByDevice(node) ?
|
||||||
mountPoints.findByDevice(node)->mountPoint() :
|
mountPoints.findByDevice(node)->mountPoint() :
|
||||||
|
|
Loading…
Reference in New Issue