getPESize does not have to be static.

This commit is contained in:
Andrius Štikonas 2016-09-04 11:55:49 +01:00
parent 68539ad97a
commit b5b5ac9cb4
3 changed files with 10 additions and 9 deletions

View File

@ -127,7 +127,7 @@ bool lvm2_pv::resize(Report& report, const QString& deviceNode, qint64 length) c
qint64 lastPE = getTotalPE(deviceNode) - 1; // starts from 0 qint64 lastPE = getTotalPE(deviceNode) - 1; // starts from 0
if (lastPE > 0) { // make sure that the PV is already in a VG if (lastPE > 0) { // make sure that the PV is already in a VG
qint64 targetPE = (length - metadataOffset)/ getPESize(deviceNode) - 1; // starts from 0 qint64 targetPE = (length - metadataOffset) / getPESize(deviceNode) - 1; // starts from 0
if (targetPE < lastPE) { //shrinking FS if (targetPE < lastPE) { //shrinking FS
qint64 firstMovedPE = qMax(targetPE + 1, getAllocatedPE(deviceNode)); // starts from 1 qint64 firstMovedPE = qMax(targetPE + 1, getAllocatedPE(deviceNode)); // starts from 1
ExternalCommand moveCmd(report, ExternalCommand moveCmd(report,
@ -206,7 +206,7 @@ qint64 lvm2_pv::getTotalPE(const QStringList& deviceNodeList)
{ {
qint64 sum = 0; qint64 sum = 0;
for (const auto &deviceNode : deviceNodeList) { for (const auto &deviceNode : deviceNodeList) {
qint64 totalPE = getTotalPE(deviceNode); qint64 totalPE = getTotalPE(deviceNode);
if (totalPE < 0) { if (totalPE < 0) {
sum = -1; sum = -1;
break; break;
@ -275,7 +275,7 @@ qint64 lvm2_pv::getPVSize(const QStringList& deviceNodeList)
return sum; return sum;
} }
qint64 lvm2_pv::getPESize(const QString& deviceNode) qint64 lvm2_pv::getPESize(const QString& deviceNode) const
{ {
QString val = getpvField(QStringLiteral("vg_extent_size"), deviceNode); QString val = getpvField(QStringLiteral("vg_extent_size"), deviceNode);
return val.isEmpty() ? -1 : val.toLongLong(); return val.isEmpty() ? -1 : val.toLongLong();
@ -313,7 +313,7 @@ QString lvm2_pv::getVGName(const QString& deviceNode)
return getpvField(QStringLiteral("vg_name"), deviceNode); return getpvField(QStringLiteral("vg_name"), deviceNode);
} }
const QStringList lvm2_pv::getFreePV() QStringList lvm2_pv::getFreePV()
{ {
QStringList rlist; QStringList rlist;

View File

@ -106,7 +106,7 @@ public:
static qint64 getFreePE(const QStringList& deviceNodeList); static qint64 getFreePE(const QStringList& deviceNodeList);
static qint64 getAllocatedPE(const QString& deviceNode); static qint64 getAllocatedPE(const QString& deviceNode);
static qint64 getAllocatedPE(const QStringList& deviceNodeList); static qint64 getAllocatedPE(const QStringList& deviceNodeList);
static qint64 getPESize(const QString& deviceNode); // return PE size in bytes qint64 getPESize(const QString& deviceNode) const; // return PE size in bytes
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);
@ -115,7 +115,7 @@ public:
static QString getVGName(const QString& deviceNode); static QString getVGName(const QString& deviceNode);
static QString getpvField(const QString& fieldName, const QString& deviceNode = QString()); static QString getpvField(const QString& fieldName, const QString& deviceNode = QString());
static const QStringList getFreePV(); static QStringList getFreePV();
public: public:
static CommandSupportType m_GetUsed; static CommandSupportType m_GetUsed;
@ -130,6 +130,7 @@ public:
static CommandSupportType m_SetLabel; static CommandSupportType m_SetLabel;
static CommandSupportType m_UpdateUUID; static CommandSupportType m_UpdateUUID;
static CommandSupportType m_GetUUID; static CommandSupportType m_GetUUID;
}; };
} }

View File

@ -46,14 +46,14 @@ ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(LvmDevice& d, const QStri
m_CurrentSize = FS::lvm2_pv::getPVSize(currentList()); m_CurrentSize = FS::lvm2_pv::getPVSize(currentList());
QStringList toRemoveList = curList; QStringList toRemoveList = curList;
for (QString path : partlist) { for (const QString &path : partlist) {
if (toRemoveList.contains(path)) { if (toRemoveList.contains(path)) {
toRemoveList.removeAll(path); toRemoveList.removeAll(path);
} }
} }
QStringList toInsertList = partlist; QStringList toInsertList = partlist;
for (QString path : curList) { for (const QString &path : curList) {
if (toInsertList.contains(path)) { if (toInsertList.contains(path)) {
toInsertList.removeAll(path); toInsertList.removeAll(path);
} }
@ -96,7 +96,7 @@ bool ResizeVolumeGroupOperation::targets(const Device& d) const
bool ResizeVolumeGroupOperation::targets(const Partition& p) const bool ResizeVolumeGroupOperation::targets(const Partition& p) const
{ {
for (QString partPath : targetList()) { for (const QString &partPath : targetList()) {
if (partPath == p.partitionPath()) { if (partPath == p.partitionPath()) {
return true; return true;
} }