Loading...
Searching...
No Matches
XrdPfcPurgeQuota.cc
Go to the documentation of this file.
#include "XrdPfc/XrdPfcPurgePin.hh"
#include "XrdPfc/XrdPfcDirStatePurgeshot.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucUtils.hh"
#include "XrdOuc/XrdOucStream.hh"
#include "XrdOuc/XrdOuca2x.hh"
#include <fcntl.h>
class XrdPfcPurgeQuota : public XrdPfc::PurgePin
{
XrdSysError &m_log;
public:
XrdPfcPurgeQuota(XrdSysError &log) : m_log(log) {}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void InitDirStatesForLocalPaths(const XrdPfc::DataFsPurgeshot &purge_shot)
{
for (list_i it = m_list.begin(); it != m_list.end(); ++it)
{
it->dirUsage = purge_shot.find_dir_usage_for_dir_path(it->path);
}
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
long long GetBytesToRecover(const XrdPfc::DataFsPurgeshot &purge_shot) override
{
// setup diskusage for each dir path
InitDirStatesForLocalPaths(purge_shot);
long long totalToRemove = 0;
// get bytes to remove
for (list_i it = m_list.begin(); it != m_list.end(); ++it)
{
if (it->dirUsage == nullptr)
{
m_log.Emsg("PurgeQuotaPin--GetBytesToRecover", "directory not found:", it->path.c_str());
continue;
}
long long cv = 512ll * it->dirUsage->m_StBlocks - it->nBytesQuota;
if (cv > 0)
it->nBytesToRecover = cv;
else
it->nBytesToRecover = 0;
totalToRemove += it->nBytesToRecover;
}
return totalToRemove;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool ConfigPurgePin(const char *parms) override
{
// retrive configuration file name
if (!parms || !parms[0] || (strlen(parms) == 0))
{
m_log.Emsg("ConfigPurgePin", "Quota file not specified.");
return false;
}
m_log.Emsg("ConfigPurgePin", "Using directory list", parms);
// parse the file to get directory quotas
const char *config_filename = parms;
const char *theINS = getenv("XRDINSTANCE");
XrdOucEnv myEnv;
XrdOucStream Config(&m_log, theINS, &myEnv, "=====> PurgeQuota ");
int fd;
if ((fd = open(config_filename, O_RDONLY, 0)) < 0)
{
m_log.Emsg("ConfigPurgePin() can't open configuration file ", config_filename);
}
Config.Attach(fd);
static const char *cvec[] = {"*** pfc purge plugin :", 0};
Config.Capture(cvec);
char *var;
while ((var = Config.GetMyFirstWord()))
{
std::string dirpath = var;
const char *val;
if (!(val = Config.GetWord()))
{
m_log.Emsg("PurgeQuota plugin", "quota not specified");
continue;
}
std::string tmpc = val;
long long quota = 0;
if (::isalpha(*(tmpc.rbegin())))
{
if (XrdOuca2x::a2sz(m_log, "Error getting quota", tmpc.c_str(), &quota))
{
continue;
}
}
else
{
if (XrdOuca2x::a2ll(m_log, "Error getting quota", tmpc.c_str(), &quota))
{
continue;
}
}
DirInfo d;
d.path = dirpath;
d.nBytesQuota = quota;
m_list.push_back(d);
}
return true;
}
};
/******************************************************************************/
/* XrdPfcGetPurgePin */
/******************************************************************************/
// Return a purge object to use.
extern "C"
{
XrdPfc::PurgePin *XrdPfcGetPurgePin(XrdSysError &log)
{
return new XrdPfcPurgeQuota(log);
}
}
XrdOucEnv.hh
XrdOucStream.hh
XrdOucUtils.hh
XrdOuca2x.hh
XrdPfcDirStatePurgeshot.hh
XrdPfcPurgePin.hh
XrdPfcGetPurgePin
XrdPfc::PurgePin * XrdPfcGetPurgePin(XrdSysError &log)
Definition XrdPfcPurgeQuota.cc:133
open
#define open
Definition XrdPosix.hh:76
XrdOucEnv
Definition XrdOucEnv.hh:42
XrdOucStream
Definition XrdOucStream.hh:47
XrdOuca2x::a2sz
static int a2sz(XrdSysError &, const char *emsg, const char *item, long long *val, long long minv=-1, long long maxv=-1)
Definition XrdOuca2x.cc:257
XrdOuca2x::a2ll
static int a2ll(XrdSysError &, const char *emsg, const char *item, long long *val, long long minv=-1, long long maxv=-1)
Definition XrdOuca2x.cc:70
XrdPfcPurgeQuota
Definition XrdPfcPurgeQuota.cc:12
XrdPfcPurgeQuota::ConfigPurgePin
bool ConfigPurgePin(const char *parms) override
Provide bytes to erase from dir quota listed in a text file.
Definition XrdPfcPurgeQuota.cc:61
XrdPfcPurgeQuota::InitDirStatesForLocalPaths
void InitDirStatesForLocalPaths(const XrdPfc::DataFsPurgeshot &purge_shot)
Set directory statistics.
Definition XrdPfcPurgeQuota.cc:21
XrdPfcPurgeQuota::GetBytesToRecover
long long GetBytesToRecover(const XrdPfc::DataFsPurgeshot &purge_shot) override
Provide bytes to erase from dir quota listed in a text file.
Definition XrdPfcPurgeQuota.cc:32
XrdPfcPurgeQuota::XrdPfcPurgeQuota
XrdPfcPurgeQuota(XrdSysError &log)
Definition XrdPfcPurgeQuota.cc:16
XrdPfc::PurgePin
Base class for reguesting directory space to obtain.
Definition XrdPfcPurgePin.hh:16
XrdPfc::PurgePin::m_list
list_t m_list
Definition XrdPfcPurgePin.hh:32
XrdPfc::PurgePin::list_i
list_t::iterator list_i
Definition XrdPfcPurgePin.hh:29
XrdPfc::PurgePin::DirInfo::nBytesQuota
long long nBytesQuota
Definition XrdPfcPurgePin.hh:21
XrdPfc::PurgePin::DirInfo::path
std::string path
Definition XrdPfcPurgePin.hh:20
XrdPfc::PurgePin::DirInfo
Definition XrdPfcPurgePin.hh:19
XrdSysError
Definition XrdSysError.hh:90
XrdPfc::DataFsPurgeshot
Definition XrdPfcDirStatePurgeshot.hh:25
XrdPfc::DataFsPurgeshot::find_dir_usage_for_dir_path
const DirUsage * find_dir_usage_for_dir_path(const std::string &dir_path) const
Definition XrdPfcDirStatePurgeshot.hh:73