XRootD
XrdCmsPrepare Class Reference

#include <XrdCmsPrepare.hh>

+ Inheritance diagram for XrdCmsPrepare:
+ Collaboration diagram for XrdCmsPrepare:

Public Member Functions

 XrdCmsPrepare ()
 
 ~XrdCmsPrepare ()
 
int Add (XrdCmsPrepArgs &pargs)
 
int Del (char *reqid)
 
void DoIt ()
 
int Exists (char *path)
 
void Gone (char *path)
 
void Inform (const char *cmd, XrdCmsPrepArgs *pargs)
 
void Init ()
 
int isOK ()
 
int Pending ()
 
void Prepare (XrdCmsPrepArgs *pargs)
 
void Reset (const char *iName, const char *aPath, int aMode)
 
int setParms (const char *ifpgm, char *ifmsg=0)
 
int setParms (int rcnt, int stime, int deco=0)
 
int setParms (XrdOucName2Name *n2n)
 
- Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 

Additional Inherited Members

- Public Attributes inherited from XrdJob
const char * Comment
 
XrdJobNextJob
 

Detailed Description

Definition at line 46 of file XrdCmsPrepare.hh.

Constructor & Destructor Documentation

◆ XrdCmsPrepare()

XrdCmsPrepare::XrdCmsPrepare ( )

Definition at line 77 of file XrdCmsPrepare.cc.

77  : XrdJob("Prep cache scrubber"),
78  prepSched(&Say)
79 {prepif = 0;
80  preppid = 0;
81  resetcnt = scrub2rst = 3;
82  scrubtime= 20*60;
83  NumFiles = 0;
84  lastemsg = time(0);
85  Relay = 0; // This will be initialized via Init()!
86  PrepFrm = 0;
87  prepOK = 0;
88  N2N = 0;
89 }
XrdJob(const char *desc="")
Definition: XrdJob.hh:51
XrdSysError Say

◆ ~XrdCmsPrepare()

XrdCmsPrepare::~XrdCmsPrepare ( )
inline

Definition at line 79 of file XrdCmsPrepare.hh.

79 {} // Never gets deleted

Member Function Documentation

◆ Add()

int XrdCmsPrepare::Add ( XrdCmsPrepArgs pargs)

Definition at line 95 of file XrdCmsPrepare.cc.

96 {
97  char *pdata[XrdOucMsubs::maxElem+2], prtybuff[8], *pP=prtybuff;
98  int rc, pdlen[XrdOucMsubs::maxElem + 2];
99 
100 // Check if we are using the built-in mechanism
101 //
102  if (PrepFrm)
103  {rc = PrepFrm->Add('+',pargs.path, pargs.opaque,pargs.Ident,pargs.reqid,
104  pargs.notify,pargs.mode,atoi(pargs.prty));
105  if (rc) Say.Emsg("Add", rc, "prepare", pargs.path);
106  else {PTMutex.Lock();
107  if (!PTable.Add(pargs.path, 0, 0, Hash_data_is_key)) NumFiles++;
108  PTMutex.UnLock();
109  }
110  return rc == 0;
111  }
112 
113 // Restart the scheduler if need be
114 //
115  PTMutex.Lock();
116  if (!prepif || !prepSched.isAlive())
117  {Say.Emsg("Add","No prepare manager; prepare",pargs.reqid,"ignored.");
118  PTMutex.UnLock();
119  return 0;
120  }
121 
122 // Write out the header line
123 //
124  if (!prepMsg)
125  {*pP++ = pargs.prty[0]; *pP = '\0';
126  pdata[0] = (char *)"+ "; pdlen[0] = 2;
127  pdata[1] = pargs.reqid; pdlen[1] = strlen(pargs.reqid);
128  pdata[2] = (char *)" "; pdlen[2] = 1;
129  pdata[3] = pargs.notify; pdlen[3] = strlen(pargs.notify);
130  pdata[4] = (char *)" "; pdlen[4] = 1;
131  pdata[5] = prtybuff; pdlen[5] = strlen(prtybuff);
132  pdata[6] = (char *)" "; pdlen[6] = 1;
133  pdata[7] = pargs.mode; pdlen[7] = strlen(pargs.mode);
134  pdata[8] = (char *)" "; pdlen[8] = 1;
135  pdata[9] = pargs.path; pdlen[9] = strlen(pargs.path);
136  pdata[10] = (char *)"\n"; pdlen[10] = 1;
137  pdata[11]= 0; pdlen[11]= 0;
138  if (!(rc = prepSched.Put((const char **)pdata, (const int *)pdlen)))
139  if (!PTable.Add(pargs.path, 0, 0, Hash_data_is_key)) NumFiles++;
140  } else {
141  int Oflag = (index(pargs.mode, (int)'w') ? O_RDWR : 0);
142  mode_t Prty = atoi(pargs.prty);
143  XrdOucEnv Env(pargs.opaque);
144  XrdOucMsubsInfo Info(pargs.Ident, &Env, N2N, pargs.path,
145  pargs.notify, Prty, Oflag, pargs.mode, pargs.reqid);
146  int k = prepMsg->Subs(Info, pdata, pdlen);
147  pdata[k] = (char *)"\n"; pdlen[k++] = 1;
148  pdata[k] = 0; pdlen[k] = 0;
149  if (!(rc = prepSched.Put((const char **)pdata, (const int *)pdlen)))
150  if (!PTable.Add(pargs.path, 0, 0, Hash_data_is_key)) NumFiles++;
151  }
152 
153 // All done
154 //
155  PTMutex.UnLock();
156  return rc == 0;
157 }
@ Info
@ Hash_data_is_key
Definition: XrdOucHash.hh:52
int Add(char Opc, const char *Lfn, const char *Opq, const char *Usr, const char *Rid, const char *Nop, const char *Pop, int Prty=1)
Definition: XrdFrcProxy.cc:95
T * Add(const char *KeyVal, T *KeyData, const int LifeTime=0, XrdOucHash_Options opt=Hash_default)
Definition: XrdOucHash.icc:61
int Subs(XrdOucMsubsInfo &Info, char **Data, int *Dlen)
Definition: XrdOucMsubs.cc:146
static const int maxElem
Definition: XrdOucMsubs.hh:94
int Put(const char *data, const int dlen)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95

References XrdFrcProxy::Add(), XrdOucHash< T >::Add(), XrdSysError::Emsg(), Hash_data_is_key, XrdCmsPrepArgs::Ident, Info, XrdOucStream::isAlive(), XrdSysMutex::Lock(), XrdOucMsubs::maxElem, XrdCmsPrepArgs::mode, XrdCmsPrepArgs::notify, XrdCmsPrepArgs::opaque, XrdCmsPrepArgs::path, XrdCmsPrepArgs::prty, XrdOucStream::Put(), XrdCmsPrepArgs::reqid, XrdCms::Say, XrdOucMsubs::Subs(), and XrdSysMutex::UnLock().

Referenced by Prepare().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Del()

int XrdCmsPrepare::Del ( char *  reqid)

Definition at line 163 of file XrdCmsPrepare.cc.

164 {
165  char *pdata[4];
166  int rc, pdlen[4];
167 
168 // Use our built-in mechanism if so wanted
169 //
170  if (PrepFrm)
171  {if ((rc = PrepFrm->Del('-', reqid)))
172  Say.Emsg("Del", rc, "unprepare", reqid);
173  return rc == 0;
174  }
175 
176 // Restart the scheduler if need be
177 //
178  PTMutex.Lock();
179  if (!prepif || !prepSched.isAlive())
180  {Say.Emsg("Del","No prepare manager; unprepare",reqid,"ignored.");
181  PTMutex.UnLock();
182  return 0;
183  }
184 
185 // Write out the delete request
186 //
187  pdata[0] = (char *)"- ";
188  pdlen[0] = 2;
189  pdata[1] = reqid;
190  pdlen[1] = strlen(reqid);
191  pdata[2] = (char *)"\n";
192  pdlen[2] = 1;
193  pdata[3] = (char *)0;
194  pdlen[3] = 0;
195  rc = prepSched.Put((const char **)pdata, (const int *)pdlen);
196  PTMutex.UnLock();
197  return rc == 0;
198 }
int Del(char Opc, const char *Rid)
Definition: XrdFrcProxy.cc:150

References XrdFrcProxy::Del(), XrdSysError::Emsg(), XrdOucStream::isAlive(), XrdSysMutex::Lock(), XrdOucStream::Put(), XrdCms::Say, and XrdSysMutex::UnLock().

Referenced by XrdCmsNode::do_PrepDel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoIt()

void XrdCmsPrepare::DoIt ( )
virtual

Implements XrdJob.

Definition at line 204 of file XrdCmsPrepare.cc.

205 {
206 // Simply scrub the cache
207 //
208  Scrub();
209  Sched->Schedule((XrdJob *)this,scrubtime+time(0));
210 }
Definition: XrdJob.hh:43
void Schedule(XrdJob *jp)
XrdScheduler Sched
Definition: XrdLinkCtl.cc:54

References XrdGlobal::Sched, and XrdScheduler::Schedule().

+ Here is the call graph for this function:

◆ Exists()

int XrdCmsPrepare::Exists ( char *  path)

Definition at line 216 of file XrdCmsPrepare.cc.

217 {
218  int Found;
219 
220 // Lock the hash table
221 //
222  PTMutex.Lock();
223 
224 // Look up the entry
225 //
226  Found = (NumFiles ? PTable.Find(path) != 0 : 0);
227 
228 // All done
229 //
230  PTMutex.UnLock();
231  return Found;
232 }
T * Find(const char *KeyVal, time_t *KeyTime=0)
Definition: XrdOucHash.icc:160

References XrdOucHash< T >::Find(), XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

Referenced by XrdCmsBaseFS::Exists().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Gone()

void XrdCmsPrepare::Gone ( char *  path)

Definition at line 238 of file XrdCmsPrepare.cc.

239 {
240 
241 // Lock the hash table
242 //
243  PTMutex.Lock();
244 
245 // Delete the entry
246 //
247  if (NumFiles > 0 && PTable.Del(path) == 0) NumFiles--;
248 
249 // All done
250 //
251  PTMutex.UnLock();
252 }
int Del(const char *KeyVal, XrdOucHash_Options opt=Hash_default)
Definition: XrdOucHash.icc:136

References XrdOucHash< T >::Del(), XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

Referenced by XrdCmsNode::do_Gone().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Inform()

void XrdCmsPrepare::Inform ( const char *  cmd,
XrdCmsPrepArgs pargs 
)

Definition at line 258 of file XrdCmsPrepare.cc.

259 {
260  EPNAME("Inform")
261  struct iovec Msg[8];
262  char *mdest, *minfo;
263 
264 // See if requestor wants a response
265 //
266  if (!index(pargs->mode, (int)'n')
267  || strncmp("udp://", pargs->notify, 6)
268  || !Relay)
269  {DEBUG(pargs->Ident <<' ' <<cmd <<' ' <<pargs->reqid <<" not sent to "
270  <<pargs->notify);
271  return;
272  }
273 
274 // Extract out destination and argument
275 //
276  mdest = pargs->notify+6;
277  if ((minfo = index(mdest, (int)'/')))
278  {*minfo = '\0'; minfo++;}
279  if (!minfo || !*minfo) minfo = (char *)"*";
280  DEBUG("Sending " <<mdest <<": " <<cmd <<' '<<pargs->reqid <<' ' <<minfo);
281 
282 // Create message to be sent
283 //
284  Msg[0].iov_base = (char *)cmd; Msg[0].iov_len = strlen(cmd);
285  Msg[1].iov_base = (char *)" "; Msg[1].iov_len = 1;
286  Msg[2].iov_base = pargs->reqid; Msg[2].iov_len = strlen(pargs->reqid);
287  Msg[3].iov_base = (char *)" "; Msg[3].iov_len = 1;
288  Msg[4].iov_base = minfo; Msg[4].iov_len = strlen(minfo);
289  Msg[5].iov_base = (char *)" "; Msg[5].iov_len = 1;
290  Msg[6].iov_base = pargs->path; Msg[6].iov_len = (pargs->pathlen)-1;
291  Msg[7].iov_base = (char *)"\n"; Msg[7].iov_len = 1;
292 
293 // Send the message and return
294 //
295  Relay->Send(Msg, 8, mdest);
296 }
#define DEBUG(x)
Definition: XrdBwmTrace.hh:54
#define EPNAME(x)
Definition: XrdBwmTrace.hh:56
if(Avsz)
int Send(const char *buff, int blen=0, const char *dest=0, int tmo=-1)
Definition: XrdNetMsg.cc:70

References DEBUG, EPNAME, XrdCmsPrepArgs::Ident, XrdCmsPrepArgs::mode, XrdCmsPrepArgs::notify, XrdCmsPrepArgs::path, XrdCmsPrepArgs::pathlen, XrdCmsPrepArgs::reqid, and XrdNetMsg::Send().

Referenced by XrdCmsNode::do_SelPrep(), and Prepare().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Init()

void XrdCmsPrepare::Init ( )

Definition at line 302 of file XrdCmsPrepare.cc.

303 {
304 // Obtain a msg object. We need to do it outside of a global constructor!
305 //
306  Relay = new XrdNetMsg(&Say);
307 }

References XrdCms::Say.

Referenced by XrdCmsConfig::Configure2().

+ Here is the caller graph for this function:

◆ isOK()

int XrdCmsPrepare::isOK ( )
inline

Definition at line 64 of file XrdCmsPrepare.hh.

64 {return prepOK;}

◆ Pending()

int XrdCmsPrepare::Pending ( )
inline

Definition at line 66 of file XrdCmsPrepare.hh.

66 {return NumFiles;}

◆ Prepare()

void XrdCmsPrepare::Prepare ( XrdCmsPrepArgs pargs)

Definition at line 313 of file XrdCmsPrepare.cc.

314 {
315  EPNAME("Prepare");
316  int rc;
317 
318 // Check if this file is not online, prepare it
319 //
320  if (!(rc = isOnline(pargs->path)))
321  {DEBUG("Preparing " <<pargs->reqid <<' ' <<pargs->notify <<' '
322  <<pargs->prty <<' ' <<pargs->mode <<' ' <<pargs->path);
323  if (!Config.DiskSS) Say.Emsg("Prepare","staging disallowed; ignoring prep",
324  pargs->Ident, pargs->reqid);
325  else Add(*pargs);
326  return;
327  }
328 
329 // If the file is really online, inform the requestor
330 //
331  if (rc > 0) Inform("avail", pargs);
332 }
void Inform(const char *cmd, XrdCmsPrepArgs *pargs)
int Add(XrdCmsPrepArgs &pargs)
XrdCmsConfig Config

References Add(), XrdCms::Config, DEBUG, XrdCmsConfig::DiskSS, XrdSysError::Emsg(), EPNAME, XrdCmsPrepArgs::Ident, Inform(), XrdCmsPrepArgs::mode, XrdCmsPrepArgs::notify, XrdCmsPrepArgs::path, XrdCmsPrepArgs::prty, XrdCmsPrepArgs::reqid, and XrdCms::Say.

Referenced by XrdCmsPrepArgs::Process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Reset()

void XrdCmsPrepare::Reset ( const char *  iName,
const char *  aPath,
int  aMode 
)

Definition at line 338 of file XrdCmsPrepare.cc.

339 {
340  EPNAME("Reset");
341  char baseAP[1024], *Slash;
342 
343 // This is a call from the configurator. No need to do anything if we have
344 // no interface to initialize.
345 //
346  if (!prepif) return;
347 
348 // If this is a built-in mechanism, then allocate the prepare interface
349 // and initialize it. This is a one-time thing and it better work right away.
350 // In any case, do a standard reset.
351 //
352  if (!*prepif)
353  {PrepFrm = new XrdFrcProxy(Say.logger(), iName);
354  DEBUG("Initializing internal FRM prepare interface.");
355  strcpy(baseAP, aPath); baseAP[strlen(baseAP)-1] = '\0';
356  if ((Slash = rindex(baseAP, '/'))) *Slash = '\0';
357  if (!(prepOK = PrepFrm->Init(XrdFrcProxy::opStg, baseAP, aMode)))
358  {Say.Emsg("Reset", "Built-in prepare init failed; prepare disabled.");
359  return;
360  }
361  }
362 
363 // Reset the interface and schedule a scrub
364 //
365  Reset();
366  if (scrubtime) Sched->Schedule((XrdJob *)this,scrubtime+time(0));
367 
368 }
void Reset(const char *iName, const char *aPath, int aMode)
int Init(int opX, const char *aPath, int aMode, const char *qPath=0)
Definition: XrdFrcProxy.cc:229
static const int opStg
Definition: XrdFrcProxy.hh:52
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition: XrdSysError.hh:141

References DEBUG, XrdSysError::Emsg(), EPNAME, XrdFrcProxy::Init(), XrdSysError::logger(), XrdFrcProxy::opStg, Reset(), XrdCms::Say, XrdGlobal::Sched, and XrdScheduler::Schedule().

Referenced by Reset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setParms() [1/3]

int XrdCmsPrepare::setParms ( const char *  ifpgm,
char *  ifmsg = 0 
)

Definition at line 381 of file XrdCmsPrepare.cc.

382 {if (ifpgm)
383  {const char *Slash = rindex(ifpgm, '/');
384  if (prepif) free(prepif);
385  if (Slash && !strcmp(Slash+1, "frm_xfragent")) ifpgm = "";
386  prepif = strdup(ifpgm);
387  }
388  if (ifmsg)
389  {if (prepMsg) delete prepMsg;
390  prepMsg = new XrdOucMsubs(&Say);
391  if (!(prepMsg->Parse("prepmsg", ifmsg)))
392  {delete prepMsg; prepMsg = 0; return 1;}
393  }
394  return 0;
395 }
int Parse(const char *oname, char *msg)
Definition: XrdOucMsubs.cc:100

References XrdOucMsubs::Parse(), and XrdCms::Say.

+ Here is the call graph for this function:

◆ setParms() [2/3]

int XrdCmsPrepare::setParms ( int  rcnt,
int  stime,
int  deco = 0 
)

Definition at line 374 of file XrdCmsPrepare.cc.

375 {if (rcnt > 0) resetcnt = scrub2rst = rcnt;
376  if (stime > 0) scrubtime = stime;
377  doEcho = deco;
378  return 0;
379 }

◆ setParms() [3/3]

int XrdCmsPrepare::setParms ( XrdOucName2Name n2n)
inline

Definition at line 76 of file XrdCmsPrepare.hh.

76 {N2N = n2n; return 0;}

The documentation for this class was generated from the following files: