Add support for reading LVM PV info
This commit is contained in:
parent
d4062ef198
commit
8e11d3be0c
|
@ -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
|
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");
|
const QString len = QString::number(length / 512) + QStringLiteral("s");
|
||||||
|
|
||||||
ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvresize"), QStringLiteral("--yes"), QStringLiteral("--setphysicalvolumesize"), len, deviceNode });
|
ExternalCommand cmd(report, QStringLiteral("lvm"), { QStringLiteral("pvresize"), QStringLiteral("--yes"), QStringLiteral("--setphysicalvolumesize"), len, deviceNode });
|
||||||
|
@ -143,4 +143,65 @@ QString lvm2_pv::getVGName(const QString& deviceNode) //PV node
|
||||||
return QString();
|
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+(\\d+)"));
|
||||||
|
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+(\\d+)"));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ public:
|
||||||
bool updateUUID(Report& report, const QString& deviceNode) const override;
|
bool updateUUID(Report& report, const QString& deviceNode) const override;
|
||||||
bool canMount(const QString & deviceNode, const QString & mountPoint) const override;
|
bool canMount(const QString & deviceNode, const QString & mountPoint) const override;
|
||||||
|
|
||||||
|
|
||||||
CommandSupportType supportGetUsed() const override {
|
CommandSupportType supportGetUsed() const override {
|
||||||
return m_GetUsed;
|
return m_GetUsed;
|
||||||
}
|
}
|
||||||
|
@ -93,6 +94,12 @@ 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);
|
static QString getVGName(const QString& deviceNode);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue