XRootD
XrdPfcPurgeQuota.cc
Go to the documentation of this file.
3 
4 #include "XrdOuc/XrdOucEnv.hh"
5 #include "XrdOuc/XrdOucUtils.hh"
6 #include "XrdOuc/XrdOucStream.hh"
7 #include "XrdOuc/XrdOuca2x.hh"
8 
9 #include <fcntl.h>
10 
12 {
13  XrdSysError &m_log;
14 public:
15 
16  XrdPfcPurgeQuota(XrdSysError &log) : m_log(log) {}
17 
18  //----------------------------------------------------------------------------
20  //----------------------------------------------------------------------------
22  {
23  for (list_i it = m_list.begin(); it != m_list.end(); ++it)
24  {
25  it->dirUsage = purge_shot.find_dir_usage_for_dir_path(it->path);
26  }
27  }
28 
29  //----------------------------------------------------------------------------
31  //----------------------------------------------------------------------------
32  long long GetBytesToRecover(const XrdPfc::DataFsPurgeshot &purge_shot) override
33  {
34  // setup diskusage for each dir path
35  InitDirStatesForLocalPaths(purge_shot);
36 
37  long long totalToRemove = 0;
38  // get bytes to remove
39  for (list_i it = m_list.begin(); it != m_list.end(); ++it)
40  {
41  if (it->dirUsage == nullptr)
42  {
43  m_log.Emsg("PurgeQuotaPin--GetBytesToRecover", "directory not found:", it->path.c_str());
44  continue;
45  }
46  long long cv = 512ll * it->dirUsage->m_StBlocks - it->nBytesQuota;
47  if (cv > 0)
48  it->nBytesToRecover = cv;
49  else
50  it->nBytesToRecover = 0;
51 
52  totalToRemove += it->nBytesToRecover;
53  }
54 
55  return totalToRemove;
56  }
57 
58  //----------------------------------------------------------------------------
60  //----------------------------------------------------------------------------
61  bool ConfigPurgePin(const char *parms) override
62  {
63  // retrive configuration file name
64  if (!parms || !parms[0] || (strlen(parms) == 0))
65  {
66  m_log.Emsg("ConfigPurgePin", "Quota file not specified.");
67  return false;
68  }
69  m_log.Emsg("ConfigPurgePin", "Using directory list", parms);
70 
71  // parse the file to get directory quotas
72  const char *config_filename = parms;
73  const char *theINS = getenv("XRDINSTANCE");
74  XrdOucEnv myEnv;
75  XrdOucStream Config(&m_log, theINS, &myEnv, "=====> PurgeQuota ");
76 
77  int fd;
78  if ((fd = open(config_filename, O_RDONLY, 0)) < 0)
79  {
80  m_log.Emsg("ConfigPurgePin() can't open configuration file ", config_filename);
81  }
82 
83  Config.Attach(fd);
84  static const char *cvec[] = {"*** pfc purge plugin :", 0};
85  Config.Capture(cvec);
86 
87  char *var;
88  while ((var = Config.GetMyFirstWord()))
89  {
90  std::string dirpath = var;
91  const char *val;
92 
93  if (!(val = Config.GetWord()))
94  {
95  m_log.Emsg("PurgeQuota plugin", "quota not specified");
96  continue;
97  }
98 
99  std::string tmpc = val;
100  long long quota = 0;
101  if (::isalpha(*(tmpc.rbegin())))
102  {
103  if (XrdOuca2x::a2sz(m_log, "Error getting quota", tmpc.c_str(), &quota))
104  {
105  continue;
106  }
107  }
108  else
109  {
110  if (XrdOuca2x::a2ll(m_log, "Error getting quota", tmpc.c_str(), &quota))
111  {
112  continue;
113  }
114  }
115 
116  DirInfo d;
117  d.path = dirpath;
118  d.nBytesQuota = quota;
119  m_list.push_back(d);
120  }
121 
122  return true;
123  }
124 };
125 
126 /******************************************************************************/
127 /* XrdPfcGetPurgePin */
128 /******************************************************************************/
129 
130 // Return a purge object to use.
131 extern "C"
132 {
134  {
135  return new XrdPfcPurgeQuota(log);
136  }
137 }
XrdPfc::PurgePin * XrdPfcGetPurgePin(XrdSysError &log)
int open(const char *path, int oflag,...)
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
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
bool ConfigPurgePin(const char *parms) override
Provide bytes to erase from dir quota listed in a text file.
void InitDirStatesForLocalPaths(const XrdPfc::DataFsPurgeshot &purge_shot)
Set directory statistics.
long long GetBytesToRecover(const XrdPfc::DataFsPurgeshot &purge_shot) override
Provide bytes to erase from dir quota listed in a text file.
XrdPfcPurgeQuota(XrdSysError &log)
Base class for reguesting directory space to obtain.
list_t::iterator list_i
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
XrdCmsConfig Config
const DirUsage * find_dir_usage_for_dir_path(const std::string &dir_path) const