XRootD
Loading...
Searching...
No Matches
XrdOfsEvs Class Reference

#include <XrdOfsEvs.hh>

+ Collaboration diagram for XrdOfsEvs:

Public Types

enum  Event {
  All = 0x7fffff00 ,
  None = 0x00000000 ,
  Chmod = 0x00000100 ,
  Closer = 0x00000201 ,
  Closew = 0x00000402 ,
  Close = 0x00000600 ,
  Create = 0x00000803 ,
  Fwrite = 0x00001004 ,
  Mkdir = 0x00002005 ,
  Mv = 0x00004006 ,
  Openr = 0x00008007 ,
  Openw = 0x00010008 ,
  Open = 0x00018000 ,
  Rm = 0x00020009 ,
  Rmdir = 0x0004000a ,
  Trunc = 0x0008000b ,
  nCount = 12 ,
  Mask = 0X000000ff ,
  enMask = 0x7fffff00
}
 

Public Member Functions

 XrdOfsEvs (Event theEvents, const char *Target, int minq=90, int maxq=10)
 
 ~XrdOfsEvs ()
 
int Enabled (Event theEvents)
 
int maxLmsg ()
 
int maxSmsg ()
 
void Notify (Event eNum, XrdOfsEvsInfo &Info)
 
const char * Prog ()
 
void sendEvents (void)
 
int Start (XrdSysError *eobj)
 

Static Public Member Functions

static int Parse (XrdSysError &Eroute, Event eNum, char *mText)
 

Static Public Attributes

static const int maxMsgSize = 2384
 
static const int minMsgSize = 1360
 

Detailed Description

Definition at line 120 of file XrdOfsEvs.hh.

Member Enumeration Documentation

◆ Event

Enumerator
All 
None 
Chmod 
Closer 
Closew 
Close 
Create 
Fwrite 
Mkdir 
Mv 
Openr 
Openw 
Open 
Rm 
Rmdir 
Trunc 
nCount 
Mask 
enMask 

Definition at line 124 of file XrdOfsEvs.hh.

124 {All = 0x7fffff00, None = 0x00000000,
125 Chmod = 0x00000100, Closer = 0x00000201,
126 Closew = 0x00000402, Close = 0x00000600,
127 Create = 0x00000803, Fwrite = 0x00001004,
128 Mkdir = 0x00002005, Mv = 0x00004006,
129 Openr = 0x00008007, Openw = 0x00010008,
130 Open = 0x00018000, Rm = 0x00020009,
131 Rmdir = 0x0004000a, Trunc = 0x0008000b,
132 nCount = 12,
133 Mask = 0X000000ff, enMask = 0x7fffff00
134 };

Constructor & Destructor Documentation

◆ XrdOfsEvs()

XrdOfsEvs::XrdOfsEvs ( Event  theEvents,
const char *  Target,
int  minq = 90,
int  maxq = 10 
)

Definition at line 118 of file XrdOfsEvs.cc.

119{
120
121// Set common variables
122//
123 enEvents = static_cast<Event>(theEvents & enMask);
124 endIT = 0;
125 theTarget = strdup(Target);
126 eDest = 0;
127 theProg = 0;
128 maxMin = minq; maxMax = maxq;
129 msgFirst = msgLast = msgFreeMax = msgFreeMin = 0;
130 numMax = numMin = 0;
131 tid = 0;
132 msgFD = -1;
133
134// Initialize all static format entries that have not been initialized yet.
135// Note that format may be specified prior to this object being created!
136//
137// <tid> chmod <mode> <path>
138//
139 MsgFmt[Chmod & Mask].Def(XrdOfsEvsFormat::cvtMode, "%s chmod %s %s\n",
142// <tid> closer <path>
143//
144 MsgFmt[Closer & Mask].Def(XrdOfsEvsFormat::Null, "%s closer %s\n",
146
147// <tid> closew <path>
148//
149 MsgFmt[Closew & Mask].Def(XrdOfsEvsFormat::Null, "%s closew %s\n",
151
152// <tid> create <mode> <path>
153//
154 MsgFmt[Create & Mask].Def(XrdOfsEvsFormat::cvtMode, "%s create %s %s\n",
157// <tid> mkdir <mode> <path>
158//
159 MsgFmt[Mkdir & Mask].Def(XrdOfsEvsFormat::cvtMode, "%s mkdir %s %s\n",
162// <tid> mv <path> <path>
163//
164 MsgFmt[Mv & Mask].Def(XrdOfsEvsFormat::Null, "%s mv %s %s\n",
167// <tid> openr <path>
168//
169 MsgFmt[Openr & Mask].Def(XrdOfsEvsFormat::Null, "%s openr %s\n",
171
172// <tid> openw <path>
173//
174 MsgFmt[Openw & Mask].Def(XrdOfsEvsFormat::Null, "%s openw %s\n",
176
177// <tid> rm <path>
178//
179 MsgFmt[Rm & Mask].Def(XrdOfsEvsFormat::Null, "%s rm %s\n",
181
182// <tid> rmdir <path>
183//
184 MsgFmt[Rmdir & Mask].Def(XrdOfsEvsFormat::Null, "%s rmdir %s\n",
186
187// <tid> trunc <size>
188//
189 MsgFmt[Trunc & Mask].Def(XrdOfsEvsFormat::cvtFSize,"%s trunc %s\n",
191
192// <tid> fwrite <path>
193//
194 MsgFmt[Fwrite & Mask].Def(XrdOfsEvsFormat::Null, "%s fwrite %s\n",
196}
void Def(evFlags theFlags, const char *Fmt,...)
Definition XrdOfsEvs.cc:91

References Chmod, Closer, Closew, Create, XrdOfsEvsFormat::cvtFSize, XrdOfsEvsFormat::cvtMode, XrdOfsEvsFormat::Def(), enMask, XrdOfsEvsInfo::evFMODE, XrdOfsEvsInfo::evFSIZE, XrdOfsEvsInfo::evLFN1, XrdOfsEvsInfo::evLFN2, XrdOfsEvsInfo::evTID, Fwrite, Mask, Mkdir, Mv, XrdOfsEvsFormat::Null, Openr, Openw, Rm, Rmdir, and Trunc.

+ Here is the call graph for this function:

◆ ~XrdOfsEvs()

XrdOfsEvs::~XrdOfsEvs ( )

Definition at line 202 of file XrdOfsEvs.cc.

203{
204 XrdOfsEvsMsg *tp;
205
206// Kill the notification thread. This may cause a msg block to be orphaned
207// but, in practice, this object does not really get deleted after being
208// started. So, the problem is moot.
209//
210 endIT = 1;
211 if (tid) XrdSysThread::Kill(tid);
212
213// Release all queued message bocks
214//
215 qMut.Lock();
216 while ((tp = msgFirst)) {msgFirst = tp->next; delete tp;}
217 if (theTarget) free(theTarget);
218 if (msgFD >= 0)close(msgFD);
219 if (theProg) delete theProg;
220 qMut.UnLock();
221
222// Release all free message blocks
223//
224 fMut.Lock();
225 while ((tp = msgFreeMax)) {msgFreeMax = tp->next; delete tp;}
226 while ((tp = msgFreeMin)) {msgFreeMin = tp->next; delete tp;}
227 fMut.UnLock();
228}
#define close(a)
Definition XrdPosix.hh:48
XrdOfsEvsMsg * next
Definition XrdOfsEvs.cc:56
static int Kill(pthread_t tid)

References close, XrdSysThread::Kill(), XrdSysMutex::Lock(), XrdOfsEvsMsg::next, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

Member Function Documentation

◆ Enabled()

int XrdOfsEvs::Enabled ( Event  theEvents)
inline

Definition at line 139 of file XrdOfsEvs.hh.

139{return theEvents & enEvents;}

Referenced by XrdOfs::chmod(), XrdOfsFile::close(), XrdOfs::Config_Display(), XrdOfs::mkdir(), XrdOfsFile::open(), XrdOfsFile::pgWrite(), XrdOfsFile::pgWrite(), XrdOfs::rename(), XrdOfs::truncate(), XrdOfsFile::truncate(), XrdOfs::Unpersist(), XrdOfsFile::write(), and XrdOfsFile::write().

+ Here is the caller graph for this function:

◆ maxLmsg()

int XrdOfsEvs::maxLmsg ( )
inline

Definition at line 142 of file XrdOfsEvs.hh.

142{return maxMax;}

Referenced by XrdOfs::Config_Display().

+ Here is the caller graph for this function:

◆ maxSmsg()

int XrdOfsEvs::maxSmsg ( )
inline

Definition at line 141 of file XrdOfsEvs.hh.

141{return maxMin;}

Referenced by XrdOfs::Config_Display().

+ Here is the caller graph for this function:

◆ Notify()

void XrdOfsEvs::Notify ( Event  eNum,
XrdOfsEvsInfo Info 
)

Definition at line 234 of file XrdOfsEvs.cc.

235{
236 static int warnings = 0;
237 XrdOfsEvsFormat *fP;
238 XrdOfsEvsMsg *tp;
239 char modebuff[8], sizebuff[16];
240 int eNum, isBig = (eID & Mv), msgSize = (isBig ? maxMsgSize : minMsgSize);
241
242// Validate event number and set event name
243//
244 eNum = eID & Mask;
245 if (eNum < 0 || eNum >= nCount) return;
246
247// Check if we need to do any conversions
248//
249 fP = &MsgFmt[eNum];
251 {sprintf(modebuff, "%o", static_cast<int>((Info.FMode() & S_IAMB)));
252 Info.Set(XrdOfsEvsInfo::evFMODE, modebuff);
253 } else Info.Set(XrdOfsEvsInfo::evFMODE, "$FMODE");
255 {sprintf(sizebuff, "%lld", Info.FSize());
256 Info.Set(XrdOfsEvsInfo::evFSIZE, sizebuff);
257 } else Info.Set(XrdOfsEvsInfo::evFSIZE, "$FSIZE");
258
259// Get a message block
260//
261 if (!(tp = getMsg(isBig)))
262 {if ((++warnings & 0xff) == 1)
263 {eDest->Emsg("Notify", "Ran out of message objects;", eName(eNum),
264 "event notification not sent.");
265 }
266 return;
267 }
268
269// Format the message
270//
271 tp->tlen = fP->SNP(Info, tp->text, msgSize);
272
273// Put the message on the queue and return
274//
275 tp->next = 0;
276 qMut.Lock();
277 if (msgLast) {msgLast->next = tp; msgLast = tp;}
278 else msgFirst = msgLast = tp;
279 qMut.UnLock();
280 qSem.Post();
281}
#define S_IAMB
Definition XrdConfig.cc:160
int SNP(XrdOfsEvsInfo &Info, char *buff, int blen)
Definition XrdOfsEvs.hh:97
char * text
Definition XrdOfsEvs.cc:57
static const int maxMsgSize
Definition XrdOfsEvs.hh:137
static const int minMsgSize
Definition XrdOfsEvs.hh:136
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)

References XrdOfsEvsFormat::cvtFSize, XrdOfsEvsFormat::cvtMode, XrdSysError::Emsg(), XrdOfsEvsInfo::evFMODE, XrdOfsEvsInfo::evFSIZE, XrdOfsEvsFormat::Flags, XrdSysMutex::Lock(), Mask, maxMsgSize, minMsgSize, Mv, nCount, XrdOfsEvsMsg::next, XrdSysSemaphore::Post(), S_IAMB, XrdOfsEvsFormat::SNP(), XrdOfsEvsMsg::text, XrdOfsEvsMsg::tlen, and XrdSysMutex::UnLock().

Referenced by XrdOfs::chmod(), XrdOfsFile::close(), XrdOfs::mkdir(), XrdOfsFile::open(), XrdOfs::rename(), XrdOfs::truncate(), and XrdOfs::Unpersist().

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

◆ Parse()

int XrdOfsEvs::Parse ( XrdSysError Eroute,
XrdOfsEvs::Event  eNum,
char *  mText 
)
static

Definition at line 287 of file XrdOfsEvs.cc.

288{
289 static struct valVar {const char *vname;
292 Vars[] = {
302 };
303 int numvars = sizeof(Vars)/sizeof(struct valVar);
304 char parms[1024], *pP = parms;
305 char *pE = parms+sizeof(parms)-((XrdOfsEvsInfo::evARGS*2)-8);
306 char varbuff[16], *bVar, *eVar;
307 int i, j, aNum = 0, Args[XrdOfsEvsInfo::evARGS] = {0};
309
310// Parse the text
311//
312 parms[0] = '\0';
313 while(*mText && pP < pE)
314 {if (*mText == '\\' && *(mText+1) == '$')
315 {*pP++ = '$'; mText += 2; continue;}
316 else if (*mText != '$') {*pP++ = *mText++; continue;}
317 bVar = mText+1;
318 if (*mText == '{') {eVar = index(mText, '}'); j = 1;}
319 else if (*mText == '[') {eVar = index(mText, ']'); j = 1;}
320 else {eVar = bVar; while(isalpha(*eVar)) eVar++; j = 0;}
321 i = eVar - bVar;
322 if (i < 1 || i >= (int)sizeof(varbuff))
323 {Eroute.Emsg("Parse","Invalid notifymsg variable starting at",mText);
324 return 1;
325 }
326 strncpy(varbuff, bVar, i); varbuff[i] = '\0';
327 for (i = 0; i < numvars; i++)
328 if (!strcmp(varbuff, Vars[i].vname)) break;
329 if (i >= numvars)
330 {Eroute.Emsg("Parse", "Unknown notifymsg variable -",varbuff);
331 return 1;
332 }
333 if (aNum >= XrdOfsEvsInfo::evARGS)
334 {Eroute.Say("Parse", "Too many notifymsg variables"); return 1;}
335 strcpy(pP, "%s"); pP += 2;
336 Args[aNum++] = Vars[i].vnum;
337 ArgOpts = static_cast<XrdOfsEvsFormat::evFlags>(ArgOpts|Vars[i].vopt);
338 mText = eVar+j;
339 }
340
341// Check if we overran the buffer or didn't have any text
342//
343 if (pP >= pE)
344 {Eroute.Emsg("Parse","notifymsg text too long");return 1;}
345 if (!parms[0])
346 {Eroute.Emsg("Parse","notifymsg text not specified");return 1;}
347
348// Set the format
349//
350 strcpy(pP, "\n");
351 eNum = static_cast<Event>(eNum & Mask);
352 MsgFmt[eNum].Set(ArgOpts, strdup(parms), Args);
353
354// All done
355//
356 return 0;
357}
void Set(evFlags theFlags, const char *Fmt, int *fullArgs)
Definition XrdOfsEvs.hh:106
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)

References XrdOfsEvsFormat::cvtFSize, XrdOfsEvsFormat::cvtMode, XrdSysError::Emsg(), XrdOfsEvsInfo::evARGS, XrdOfsEvsInfo::evCGI1, XrdOfsEvsInfo::evCGI2, XrdOfsEvsInfo::evFMODE, XrdOfsEvsInfo::evFSIZE, XrdOfsEvsInfo::evLFN1, XrdOfsEvsInfo::evLFN2, XrdOfsEvsInfo::evTID, XrdOfsEvsFormat::freeFmt, Mask, XrdOfsEvsFormat::Null, XrdSysError::Say(), and XrdOfsEvsFormat::Set().

+ Here is the call graph for this function:

◆ Prog()

const char * XrdOfsEvs::Prog ( )
inline

Definition at line 148 of file XrdOfsEvs.hh.

148{return theTarget;}

Referenced by XrdOfs::Config_Display().

+ Here is the caller graph for this function:

◆ sendEvents()

void XrdOfsEvs::sendEvents ( void  )

Definition at line 363 of file XrdOfsEvs.cc.

364{
365 XrdOfsEvsMsg *tp;
366 const char *theData[2] = {0,0};
367 int theDlen[2] = {0,0};
368
369// This is an endless loop that just gets things off the event queue and
370// send them out. This allows us to only hang a simgle thread should the
371// receiver get blocked, instead of the whole process.
372//
373 while(1)
374 {qSem.Wait();
375 qMut.Lock();
376 if (endIT) break;
377 if ((tp = msgFirst) && !(msgFirst = tp->next)) msgLast = 0;
378 qMut.UnLock();
379 if (tp)
380 {if (!theProg) Feed(tp->text, tp->tlen);
381 else {theData[0] = tp->text; theDlen[0] = tp->tlen;
382 theProg->Feed(theData, theDlen);
383 }
384 retMsg(tp);
385 }
386 }
387 qMut.UnLock();
388}
int Feed(const char *data[], const int dlen[])
Definition XrdOucProg.cc:63

References XrdOucProg::Feed(), XrdSysMutex::Lock(), XrdOfsEvsMsg::next, XrdOfsEvsMsg::text, XrdOfsEvsMsg::tlen, XrdSysMutex::UnLock(), and XrdSysSemaphore::Wait().

Referenced by XrdOfsEvsSend().

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

◆ Start()

int XrdOfsEvs::Start ( XrdSysError eobj)

Definition at line 394 of file XrdOfsEvs.cc.

395{
396 int rc;
397
398// Set the error object pointer
399//
400 eDest = eobj;
401
402// Check if we need to create a socket to a path
403//
404 if (*theTarget == '>')
405 {XrdNetSocket *msgSock;
406 if (!(msgSock = XrdNetSocket::Create(eobj,theTarget+1,0,0660,XRDNET_FIFO)))
407 return -1;
408 msgFD = msgSock->Detach();
409 delete msgSock;
410
411 } else {
412
413 // Allocate a new program object if we don't have one
414 //
415 if (theProg) return 0;
416 theProg = new XrdOucProg(eobj);
417
418 // Setup the program
419 //
420 if (theProg->Setup(theTarget, eobj)) return -1;
421 if ((rc = theProg->Start()))
422 {eobj->Emsg("Evs", rc, "start event collector"); return -1;}
423 }
424
425// Now start a thread to get messages and send them to the collector
426//
427 if ((rc = XrdSysThread::Run(&tid, XrdOfsEvsSend, static_cast<void *>(this),
428 0, "Event notification sender")))
429 {eobj->Emsg("Evs", rc, "create event notification thread");
430 return -1;
431 }
432
433// All done
434//
435 return 0;
436}
#define XRDNET_FIFO
Definition XrdNetOpts.hh:83
void * XrdOfsEvsSend(void *pp)
Definition XrdOfsEvs.cc:71
static XrdNetSocket * Create(XrdSysError *Say, const char *path, const char *fn, mode_t mode, int isudp=0)
int Start(void)
int Setup(const char *prog, XrdSysError *errP=0, int(*Proc)(XrdOucStream *, char **, int)=0)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)

References XrdNetSocket::Create(), XrdNetSocket::Detach(), XrdSysError::Emsg(), XrdSysThread::Run(), XrdOucProg::Setup(), XrdOucProg::Start(), XRDNET_FIFO, and XrdOfsEvsSend().

Referenced by XrdOfs::Configure().

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

Member Data Documentation

◆ maxMsgSize

const int XrdOfsEvs::maxMsgSize = 2384
static

Definition at line 137 of file XrdOfsEvs.hh.

Referenced by Notify().

◆ minMsgSize

const int XrdOfsEvs::minMsgSize = 1360
static

Definition at line 136 of file XrdOfsEvs.hh.

Referenced by Notify().


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