Commit 2e32a79f authored by Bernd Lietzow's avatar Bernd Lietzow

Merge branch '896-quota-reporting-fstype-v6' into 'v6'

Resolve "quota reporting on autofs/systemd.automount, parsing of /etc/mtab - v6"

See merge request beegfs/projects0!731
parents 45274dfe 69441d01
#include "Quota.h"
std::ostream& operator<<(std::ostream& stream, const QuotaBlockDeviceFsType type)
{
switch (type)
{
case QuotaBlockDeviceFsType_UNKNOWN:
return stream << "Unknown";
case QuotaBlockDeviceFsType_EXTX:
return stream << "Ext2/3/4";
case QuotaBlockDeviceFsType_XFS:
return stream << "XFS";
case QuotaBlockDeviceFsType_ZFS:
return stream << "ZFS";
}
return stream << "Invalid";
}
#ifndef COMMON_STORAGE_QUOTA_QUOTA_H_
#define COMMON_STORAGE_QUOTA_QUOTA_H_
#include <ostream>
enum QuotaBlockDeviceFsType
{
QuotaBlockDeviceFsType_UNKNOWN=0,
......@@ -9,6 +11,8 @@ enum QuotaBlockDeviceFsType
QuotaBlockDeviceFsType_ZFS=3
};
std::ostream& operator<<(std::ostream& stream, const QuotaBlockDeviceFsType type);
enum QuotaInodeSupport
{
QuotaInodeSupport_UNKNOWN=0,
......
......@@ -7,6 +7,7 @@
#include <mntent.h>
#include <fstab.h>
#include <sys/statfs.h>
/**
* checks one storage target path and creates a QuotaBlockDevice
......@@ -21,7 +22,6 @@ QuotaBlockDevice QuotaBlockDevice::getBlockDeviceOfTarget(std::string& targetPat
std::string resMountPath;
std::string resBlockDevicePath;
QuotaBlockDeviceFsType resFsType = QuotaBlockDeviceFsType_UNKNOWN;
struct mntent* mntData;
FILE *mntFile = setmntent(mountInformationPath.c_str(), "r");
......@@ -41,24 +41,12 @@ QuotaBlockDevice QuotaBlockDevice::getBlockDeviceOfTarget(std::string& targetPat
{
resMountPath = mntData->mnt_dir;
resBlockDevicePath = mntData->mnt_fsname;
std::string type(mntData->mnt_type);
if ( type.compare("xfs") == 0 )
resFsType = QuotaBlockDeviceFsType_XFS;
else
if ( type.find("ext") == 0 )
resFsType = QuotaBlockDeviceFsType_EXTX;
else
if ( type.compare("zfs") == 0 )
resFsType = QuotaBlockDeviceFsType_ZFS;
else
resFsType = QuotaBlockDeviceFsType_UNKNOWN;
}
}
endmntent(mntFile);
QuotaBlockDevice blockDevice(resMountPath, resBlockDevicePath, resFsType, targetPath);
QuotaBlockDevice blockDevice(resMountPath, resBlockDevicePath, getFsType(targetPath), targetPath);
// check if the installed libzfs is compatible with implementation
if(blockDevice.getFsType() == QuotaBlockDeviceFsType_ZFS)
......@@ -140,3 +128,27 @@ QuotaInodeSupport QuotaBlockDevice::quotaInodeSupportFromBlockDevice()
break;
}
}
QuotaBlockDeviceFsType QuotaBlockDevice::getFsType(const std::string& path)
{
struct statfs stats;
const auto result = statfs(path.c_str(), &stats);
if (result != 0)
{
const auto err = errno;
throw std::runtime_error("Error getting FS Type of " + path + ":" + strerror(err));
}
switch (stats.f_type)
{
case 0xef53: // same magic for EXT2/3, from linux/magic.h (not available in older distros)
return QuotaBlockDeviceFsType_EXTX;
case 0x58465342: // from statfs man page
return QuotaBlockDeviceFsType_XFS;
case 0x2fc12fc1: // found by running statfs on a zfs
return QuotaBlockDeviceFsType_ZFS;
}
return QuotaBlockDeviceFsType_UNKNOWN;
}
......@@ -49,6 +49,8 @@ class QuotaBlockDevice
QuotaBlockDeviceFsType fsTypeBlockDevice);
QuotaInodeSupport quotaInodeSupportFromBlockDevice();
static QuotaBlockDeviceFsType getFsType(const std::string& path);
private:
std::string storageTargetPath;
......
#include <common/toolkit/UnitTk.h>
#include <common/storage/quota/Quota.h>
#include <program/Program.h>
#include "QuotaTk.h"
#include <boost/lexical_cast.hpp>
#include <dlfcn.h>
// xfs/xfs.h includes linux/fs.h, which (sometimes) defines MS_RDONLY.
// sys/mount.h is the canonical source of MS_RDONLY, but declares it as an enum - which is then
......@@ -197,7 +199,8 @@ bool QuotaTk::checkQuota(QuotaBlockDeviceMap* blockDevices, QuotaData* outData,
LogContext(logContext).logErr("Error: Quota request - quotactl failed. Type: " +
QuotaData::QuotaDataTypeToString(outData->getType() ) + "; ID: " +
StringTk::uintToStr(outData->getID()) + "; SysErr: " +
System::getErrString(errorCode) );
System::getErrString(errorCode) +"; fstype = " +
boost::lexical_cast<std::string>(iter->second.getFsType()));
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment