Enable used space reporting for swap.

BUG: 367473
This commit is contained in:
Andrius Štikonas 2016-08-29 12:00:25 +01:00
parent 742905ef7f
commit 5ab60c6dfa
4 changed files with 40 additions and 5 deletions

View File

@ -145,6 +145,8 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl
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);
@ -161,6 +163,9 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl
QString();
const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint);
if (mountPoint == QStringLiteral("none"))
mountPoint = QString();
//TODO: test used space report. probably incorrect
if (logicalSize() > 0) {
if (mounted && freeSpaceInfo.isValid() && mountPoint != QString()) {

View File

@ -21,7 +21,9 @@
#include "util/externalcommand.h"
#include <KLocalizedString>
#include <QDebug>
#include <QFileInfo>
#include <QTextStream>
namespace FS
{
@ -30,6 +32,7 @@ FileSystem::CommandSupportType linuxswap::m_Grow = FileSystem::cmdSupportNone;
FileSystem::CommandSupportType linuxswap::m_Shrink = FileSystem::cmdSupportNone;
FileSystem::CommandSupportType linuxswap::m_Move = FileSystem::cmdSupportNone;
FileSystem::CommandSupportType linuxswap::m_Copy = FileSystem::cmdSupportNone;
FileSystem::CommandSupportType linuxswap::m_GetUsed = FileSystem::cmdSupportNone;
FileSystem::CommandSupportType linuxswap::m_GetLabel = FileSystem::cmdSupportNone;
FileSystem::CommandSupportType linuxswap::m_SetLabel = FileSystem::cmdSupportNone;
FileSystem::CommandSupportType linuxswap::m_GetUUID = FileSystem::cmdSupportNone;
@ -44,6 +47,7 @@ void linuxswap::init()
{
m_SetLabel = m_Shrink = m_Grow = m_Create = m_UpdateUUID = (findExternal(QStringLiteral("mkswap"))) ? cmdSupportFileSystem : cmdSupportNone;
m_GetLabel = cmdSupportCore;
m_GetUsed = cmdSupportFileSystem;
m_Copy = cmdSupportFileSystem;
m_Move = cmdSupportCore;
m_GetUUID = cmdSupportCore;
@ -52,17 +56,17 @@ void linuxswap::init()
bool linuxswap::supportToolFound() const
{
return
// m_GetUsed != cmdSupportNone &&
m_GetUsed != cmdSupportNone &&
m_GetLabel != cmdSupportNone &&
m_SetLabel != cmdSupportNone &&
m_Create != cmdSupportNone &&
// m_Check != cmdSupportNone &&
// m_Check != cmdSupportNone &&
m_UpdateUUID != cmdSupportNone &&
m_Grow != cmdSupportNone &&
m_Shrink != cmdSupportNone &&
m_Copy != cmdSupportNone &&
m_Move != cmdSupportNone &&
// m_Backup != cmdSupportNone &&
// m_Backup != cmdSupportNone &&
m_GetUUID != cmdSupportNone;
}
@ -136,7 +140,6 @@ QString linuxswap::unmountTitle() const
bool linuxswap::canMount(const QString& deviceNode, const QString& mountPoint) const {
Q_UNUSED(deviceNode);
// linux swap doesn't require mount point to activate
qDebug() << mountPoint;
return mountPoint != QStringLiteral("/");
}
@ -166,4 +169,22 @@ bool linuxswap::updateUUID(Report& report, const QString& deviceNode) const
ExternalCommand cmd(report, QStringLiteral("mkswap"), args);
return cmd.run(-1) && cmd.exitCode() == 0;
}
qint64 linuxswap::readUsedCapacity(const QString& deviceNode) const
{
QFile swapsFile(QStringLiteral("/proc/swaps"));
if (swapsFile.open(QIODevice::ReadOnly)) {
QByteArray data = swapsFile.readAll();
swapsFile.close();
QTextStream in(&data);
while (!in.atEnd()) {
QStringList line = in.readLine().split(QRegExp(QStringLiteral("\\s+")));
QFileInfo kernelPath(deviceNode);
if (line[0] == kernelPath.canonicalFilePath())
return line[3].toLongLong() * 1024;
}
}
return -1;
}
}

View File

@ -47,6 +47,7 @@ public:
bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel) override;
bool copy(Report& report, const QString& targetDeviceNode, const QString& sourceDeviceNode) const override;
bool updateUUID(Report& report, const QString& deviceNode) const override;
qint64 readUsedCapacity(const QString& deviceNode) const override;
bool canMount(const QString& deviceNode, const QString& mountPoint) const override;
bool mount(Report& report, const QString& deviceNode, const QString& mountPoint) override;
@ -70,6 +71,9 @@ public:
CommandSupportType supportCopy() const override {
return m_Copy;
}
CommandSupportType supportGetUsed() const override {
return m_GetUsed;
}
CommandSupportType supportGetLabel() const override {
return m_GetLabel;
}
@ -98,6 +102,7 @@ public:
static CommandSupportType m_Copy;
static CommandSupportType m_SetLabel;
static CommandSupportType m_GetLabel;
static CommandSupportType m_GetUsed;
static CommandSupportType m_UpdateUUID;
static CommandSupportType m_GetUUID;
};

View File

@ -261,6 +261,8 @@ Device* LibPartedBackend::scanDevice(const QString& deviceNode)
mountPoint = mountPoints.findByDevice(mapperNode) ?
mountPoints.findByDevice(mapperNode)->mountPoint() :
QString();
if (mountPoint == QStringLiteral("none"))
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);
@ -283,6 +285,8 @@ Device* LibPartedBackend::scanDevice(const QString& deviceNode)
mountPoint = mountPoints.findByDevice(partitionNode) ?
mountPoints.findByDevice(partitionNode)->mountPoint() :
QString();
if (mountPoint == QStringLiteral("none"))
mountPoint = QString();
mounted = busy;
}