Loading...
Searching...
No Matches
XrdFrcReqFile Class Reference

`#include <XrdFrcReqFile.hh>`

Collaboration diagram for XrdFrcReqFile:

## Public Member Functions

| XrdFrcReqFile (const char *fn, int aVal)
| ~XrdFrcReqFile ()
void | Add (XrdFrcRequest *rP)
void | Can (XrdFrcRequest *rP)
void | Del (XrdFrcRequest *rP)
int | Get (XrdFrcRequest *rP)
int | Init ()
char * | List (char *Buff, int bsz, int &Offs, XrdFrcRequest::Item *ITList=0, int ITNum=0)
void | ListL (XrdFrcRequest &tmpReq, char *Buff, int bsz, XrdFrcRequest::Item *ITList, int ITNum)

## Detailed Description

Definition at line 36 of file XrdFrcReqFile.hh.

## Constructor & Destructor Documentation

## XrdFrcReqFile()

XrdFrcReqFile::XrdFrcReqFile | ( | const char * | fn,
|  | int | aVal )

Definition at line 60 of file XrdFrcReqFile.cc.

{
char buff[1200];
memset((void *)&HdrData, 0, sizeof(HdrData));
reqFN = strdup(fn);
strcpy(buff, fn); strcat(buff, ".lock");
lokFN = strdup(buff);
lokFD = reqFD = -1;
isAgent = aVal;
}

## ~XrdFrcReqFile()

XrdFrcReqFile::~XrdFrcReqFile | ( |  | ) |

inline

Definition at line 57 of file XrdFrcReqFile.hh.

{}

## Member Function Documentation

## Add()

void XrdFrcReqFile::Add | ( | XrdFrcRequest * | rP | ) |

Definition at line 76 of file XrdFrcReqFile.cc.

{
rqMonitor rqMon(isAgent);
XrdFrcRequest tmpReq;
int fP;
// Lock the file
//
if (!FileLock()) {FailAdd(rP->LFN, 0); return;}
// Obtain a free slot
//
if ((fP = HdrData.Free))
{if (!reqRead((void *)&tmpReq, fP)) {FailAdd(rP->LFN, 1); return;}
HdrData.Free = tmpReq.Next;
} else {
struct stat buf;
if (fstat(reqFD, &buf))
{Say.Emsg("Add",errno,"stat",reqFN); FailAdd(rP->LFN, 1); return;}
fP = buf.st_size;
}
// Chain in the request (registration requests go fifo)
//
if (rP->Options & XrdFrcRequest::Register)
{if (!(rP->Next = HdrData.First)) HdrData.Last = fP;
HdrData.First = fP;
} else {
if (HdrData.First && HdrData.Last)
{if (!reqRead((void *)&tmpReq, HdrData.Last))
{FailAdd(rP->LFN, 1); return;}
tmpReq.Next = fP;
if (!reqWrite((void *)&tmpReq, HdrData.Last, 0))
{FailAdd(rP->LFN, 1); return;}
} else HdrData.First = fP;
HdrData.Last = fP; rP->Next = 0;
}
// Write out the file
//
rP->This = fP;
if (!reqWrite(rP, fP)) FailAdd(rP->LFN, 0);
FileLock(lkNone);
}
Say
XrdOucPup XrdCmsParser::Pup & Say
Definition XrdCmsParser.cc:124
fstat
#define fstat(a, b)
Definition XrdPosix.hh:62
stat
#define stat(a, b)
Definition XrdPosix.hh:101
XrdFrcRequest::LFN
char LFN[3072]
Definition XrdFrcRequest.hh:37
XrdFrcRequest::This
int This
Definition XrdFrcRequest.hh:45
XrdFrcRequest::Options
int Options
Definition XrdFrcRequest.hh:47
XrdFrcRequest::Next
int Next
Definition XrdFrcRequest.hh:46
XrdFrcRequest::Register
static const int Register
Definition XrdFrcRequest.hh:63

References fstat, XrdFrcRequest::LFN, XrdFrcRequest::Next, XrdFrcRequest::Options, XrdFrcRequest::Register, Say, stat, and XrdFrcRequest::This.

## Can()

void XrdFrcReqFile::Can | ( | XrdFrcRequest * | rP | ) |

Definition at line 125 of file XrdFrcReqFile.cc.

{
rqMonitor rqMon(isAgent);
XrdFrcRequest tmpReq;
int Offs, numCan = 0, numBad = 0;
struct stat buf;
char txt[128];
// Lock the file and get its size
//
if (!FileLock() || fstat(reqFD, &buf)) {FailCan(rP->ID, 0); return;}
// Run through all of the file entries removing matching requests
//
for (Offs = ReqSize; Offs < buf.st_size; Offs += ReqSize)
{if (!reqRead((void *)&tmpReq, Offs)) return FailCan(rP->ID);
if (!strcmp(tmpReq.ID, rP->ID))
{tmpReq.LFN[0] = '\0';
if (!reqWrite((void *)&tmpReq, Offs, 0)) numBad++;
else numCan++;
}
}
// Make sure this is written to disk
//
if (numCan) fsync(reqFD);
// Document the action
//
if (numCan || numBad)
{sprintf(txt, "has %d entries; %d removed (%d failures).",
numCan+numBad, numCan, numBad);
Say.Emsg("Can", rP->ID, txt);
}
FileLock(lkNone);
}
fsync
#define fsync(a)
Definition XrdPosix.hh:64
XrdFrcRequest::ID
char ID[40]
Definition XrdFrcRequest.hh:39

References fstat, fsync, XrdFrcRequest::ID, Say, and stat.

## Del()

void XrdFrcReqFile::Del | ( | XrdFrcRequest * | rP | ) |

Definition at line 166 of file XrdFrcReqFile.cc.

{
rqMonitor rqMon(isAgent);
XrdFrcRequest tmpReq;
// Lock the file
//
if (!FileLock()) {FailDel(rP->LFN, 0); return;}
// Put entry on the free chain
//
memset(&tmpReq, 0, sizeof(tmpReq));
tmpReq.Next = HdrData.Free;
HdrData.Free = rP->This;
if (!reqWrite((void *)&tmpReq, rP->This)) FailDel(rP->LFN, 0);
FileLock(lkNone);
}

References XrdFrcRequest::LFN, XrdFrcRequest::Next, and XrdFrcRequest::This.

Referenced by XrdFrmXfrQueue::Add(), and XrdFrmXfrQueue::Done().

Here is the caller graph for this function:

## Get()

int XrdFrcReqFile::Get | ( | XrdFrcRequest * | rP | ) |

Definition at line 188 of file XrdFrcReqFile.cc.

{
int fP, rc;
// Lock the file
//
if (!FileLock()) return 0;
// Get the next request
//
while((fP = HdrData.First))
{if (!reqRead((void *)rP, fP)) {FileLock(lkNone); return 0;}
HdrData.First= rP->Next;
if (*(rP->LFN)) {reqWrite(0,0,1); break;}
rP->Next = HdrData.Free;
HdrData.Free = fP;
if (!reqWrite(rP, fP)) {fP = 0; break;}
}
if (fP) rc = (HdrData.First ? 1 : -1);
else rc = 0;
FileLock(lkNone);
return rc;
}

## Init()

int XrdFrcReqFile::Init | ( |  | ) |

Definition at line 216 of file XrdFrcReqFile.cc.

{
EPNAME("Init");
static const int Mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;
XrdFrcRequest tmpReq;
struct stat buf;
recEnt *RegList = 0, *First = 0, *rP, *pP, *tP;
int Offs, rc, numreq = 0;
// Open the lock file first in r/w mode
//
if ((lokFD = XrdSysFD_Open(lokFN, O_RDWR|O_CREAT, Mode)) < 0)
{Say.Emsg("Init",errno,"open",lokFN); return 0;}
// Obtain a lock
//
if (!FileLock(lkInit)) return 0;
// Open the file first in r/w mode
//
if ((reqFD = XrdSysFD_Open(reqFN, O_RDWR|O_CREAT, Mode)) < 0)
{FileLock(lkNone);
Say.Emsg("Init",errno,"open",reqFN);
return 0;
}
// Check for a new file here
//
if (fstat(reqFD, &buf)) return FailIni("stat");
if (buf.st_size < ReqSize)
{memset(&tmpReq, 0, sizeof(tmpReq));
HdrData.Free = ReqSize;
if (!reqWrite((void *)&tmpReq, ReqSize)) return FailIni("init file");
FileLock(lkNone);
return 1;
}
// We are done if this is a agent
//
if (isAgent)
{FileLock(lkNone);
return 1;
}
// Read the full file
//
for (Offs = ReqSize; Offs < buf.st_size; Offs += ReqSize)
{if (!reqRead((void *)&tmpReq, Offs)) return FailIni("read file");
if (*tmpReq.LFN == '\0' || !tmpReq.addTOD
|| tmpReq.Opaque >= int(sizeof(tmpReq.LFN))) continue;
pP = 0; rP = First; tP = new recEnt(tmpReq); numreq++;
if (tmpReq.Options & XrdFrcRequest::Register)
{tP->Next = RegList; RegList = tP;
} else {
while(rP && rP->reqData.addTOD < tmpReq.addTOD) {pP=rP;rP=rP->Next;}
if (pP) pP->Next = tP;
else First = tP;
tP->Next = rP;
}
}
// Plase registration requests in the front
//
while((rP = RegList))
{RegList = rP->Next;
rP->Next = First;
First = rP;
}
// Now write out the file
//
DEBUG(numreq <<" request(s) recovered from " <<reqFN);
rc = ReWrite(First);
// Delete all the entries in memory while referencing known instance names
//
while((tP = First))
{First = tP->Next;
CID.Ref(tP->reqData.iName);
delete tP;
}
// All done
//
FileLock(lkNone);
return rc;
}
DEBUG
#define DEBUG(x)
Definition XrdBwmTrace.hh:54
EPNAME
#define EPNAME(x)
Definition XrdBwmTrace.hh:56
Mode
int Mode
Definition XrdSecgsiProxy.cc:94
XrdFrcCID::Ref
void Ref(const char *iName)
Definition XrdFrcCID.cc:248
XrdFrc::CID
XrdFrcCID CID
Definition XrdFrcCID.cc:56

References XrdFrc::CID, DEBUG, EPNAME, fstat, Mode, XrdFrcRequest::Register, Say, and stat.

## List()

char * XrdFrcReqFile::List | ( | char * | Buff,
|  | int | bsz,
|  | int & | Offs,
|  | XrdFrcRequest::Item * | ITList = 0,
|  | int | ITNum = 0 )

Definition at line 308 of file XrdFrcReqFile.cc.

{
rqMonitor rqMon(isAgent);
XrdFrcRequest tmpReq;
int rc;
// Set Offs argument
//
if (Offs < ReqSize) Offs = ReqSize;
// Lock the file
//
if (!FileLock(lkShare)) return 0;
// Return next valid filename
//
do{do {rc = pread(reqFD, (void *)&tmpReq, ReqSize, Offs);}
while(rc < 0 && errno == EINTR);
if (rc == ReqSize)
{Offs += ReqSize;
if (*tmpReq.LFN == '\0' || !tmpReq.addTOD
|| tmpReq.Opaque >= int(sizeof(tmpReq.LFN))
|| tmpReq.Options & XrdFrcRequest::Register) continue;
FileLock(lkNone);
if (!ITNum || !ITList) strlcpy(Buff, tmpReq.LFN, bsz);
else ListL(tmpReq, Buff, bsz, ITList, ITNum);
return Buff;
}
} while(rc == ReqSize);
// Diagnose ending condition
//
if (rc < 0) Say.Emsg("List",errno,"read",reqFN);
// Return end of list
//
FileLock(lkNone);
return 0;
}
pread
#define pread(a, b, c, d)
Definition XrdPosix.hh:80
strlcpy
size_t strlcpy(char *dst, const char *src, size_t sz)
Definition XrdSysPlatform.cc:60
XrdFrcReqFile::ListL
void ListL(XrdFrcRequest &tmpReq, char *Buff, int bsz, XrdFrcRequest::Item *ITList, int ITNum)
Definition XrdFrcReqFile.cc:353
XrdFrcRequest::Opaque
short Opaque
Definition XrdFrcRequest.hh:49
XrdFrcRequest::addTOD
long long addTOD
Definition XrdFrcRequest.hh:44

References XrdFrcRequest::addTOD, XrdFrcRequest::LFN, ListL(), XrdFrcRequest::Opaque, XrdFrcRequest::Options, pread, XrdFrcRequest::Register, Say, and strlcpy().

Here is the call graph for this function:

## ListL()

void XrdFrcReqFile::ListL | ( | XrdFrcRequest & | tmpReq,
|  | char * | Buff,
|  | int | bsz,
|  | XrdFrcRequest::Item * | ITList,
|  | int | ITNum )

Definition at line 353 of file XrdFrcReqFile.cc.

{
char What, tbuf[32];
long long tval;
int i, k, n, bln = bsz-2, Lfo;
for (i = 0; i < ITNum && bln > 0; i++)
{Lfo = tmpReq.LFO;
switch(ITList[i])
{case XrdFrcRequest::getOBJ:
Lfo = 0;
n = strlen(tmpReq.LFN);
strlcpy(Buff, tmpReq.LFN, bln);
break;
case XrdFrcRequest::getLFN:
n = strlen(tmpReq.LFN+Lfo);
strlcpy(Buff, tmpReq.LFN+Lfo, bln);
break;
case XrdFrcRequest::getOBJCGI:
Lfo = 0;
n = strlen(tmpReq.LFN); tmpReq.LFN[n] = '?';
if (!tmpReq.Opaque) tmpReq.LFN[n+1] = '\0';
strlcpy(Buff, tmpReq.LFN, bln);
k = strlen(tmpReq.LFN);
tmpReq.LFN[n] = '\0'; n = k;
break;
case XrdFrcRequest::getLFNCGI:
n = strlen(tmpReq.LFN); tmpReq.LFN[n] = '?';
if (!tmpReq.Opaque) tmpReq.LFN[n+1] = '\0';
strlcpy(Buff, tmpReq.LFN+Lfo, bln);
k = strlen(tmpReq.LFN+Lfo);
tmpReq.LFN[n] = '\0'; n = k;
break;
case XrdFrcRequest::getMODE:
n = 0;
What = (tmpReq.Options & XrdFrcRequest::makeRW
? 'w' : 'r');
if (bln) {Buff[n] = What; n++;}
if (tmpReq.Options & XrdFrcRequest::msgFail)
if (bln-n > 0) {Buff[n] = 'f'; n++;}
if (tmpReq.Options & XrdFrcRequest::msgSucc)
if (bln-n > 0) {Buff[n] = 'n'; n++;}
break;
case XrdFrcRequest::getNOTE:
n = strlen(tmpReq.Notify);
strlcpy(Buff, tmpReq.Notify, bln);
break;
case XrdFrcRequest::getOP:
*Buff = tmpReq.OPc;
n = 1;
break;
case XrdFrcRequest::getPRTY:
if (tmpReq.Prty == 2) What = '2';
else if (tmpReq.Prty == 1) What = '1';
else What = '0';
n = 1;
if (bln) *Buff = What;
break;
case XrdFrcRequest::getQWT:
case XrdFrcRequest::getTOD:
tval = tmpReq.addTOD;
if (ITList[i] == XrdFrcRequest::getQWT) tval = time(0)-tval;
if ((n = sprintf(tbuf, "%lld", tval)) >= 0)
strlcpy(Buff, tbuf, bln);
break;
case XrdFrcRequest::getRID:
n = strlen(tmpReq.ID);
strlcpy(Buff, tmpReq.ID, bln);
break;
case XrdFrcRequest::getUSER:
n = strlen(tmpReq.User);
strlcpy(Buff, tmpReq.User, bln);
break;
default: n = 0; break;
}
if (bln > 0) {bln -= n; Buff += n;}
if (bln > 0) {*Buff++ = ' '; bln--;}
}
*Buff = '\0';
}
XrdFrcRequest::getMODE
@ getMODE
Definition XrdFrcRequest.hh:82
XrdFrcRequest::getNOTE
@ getNOTE
Definition XrdFrcRequest.hh:82
XrdFrcRequest::getQWT
@ getQWT
Definition XrdFrcRequest.hh:83
XrdFrcRequest::getUSER
@ getUSER
Definition XrdFrcRequest.hh:83
XrdFrcRequest::getPRTY
@ getPRTY
Definition XrdFrcRequest.hh:83
XrdFrcRequest::getOP
@ getOP
Definition XrdFrcRequest.hh:82
XrdFrcRequest::getLFNCGI
@ getLFNCGI
Definition XrdFrcRequest.hh:82
XrdFrcRequest::getRID
@ getRID
Definition XrdFrcRequest.hh:83
XrdFrcRequest::getTOD
@ getTOD
Definition XrdFrcRequest.hh:83
XrdFrcRequest::getOBJCGI
@ getOBJCGI
Definition XrdFrcRequest.hh:82
XrdFrcRequest::getOBJ
@ getOBJ
Definition XrdFrcRequest.hh:82
XrdFrcRequest::getLFN
@ getLFN
Definition XrdFrcRequest.hh:82
XrdFrcRequest::msgFail
static const int msgFail
Definition XrdFrcRequest.hh:58
XrdFrcRequest::User
char User[256]
Definition XrdFrcRequest.hh:38
XrdFrcRequest::makeRW
static const int makeRW
Definition XrdFrcRequest.hh:60
XrdFrcRequest::msgSucc
static const int msgSucc
Definition XrdFrcRequest.hh:59
XrdFrcRequest::LFO
short LFO
Definition XrdFrcRequest.hh:48
XrdFrcRequest::Prty
signed char Prty
Definition XrdFrcRequest.hh:54
XrdFrcRequest::OPc
char OPc
Definition XrdFrcRequest.hh:52
XrdFrcRequest::Notify
char Notify[512]
Definition XrdFrcRequest.hh:40

References XrdFrcRequest::addTOD, XrdFrcRequest::getLFN, XrdFrcRequest::getLFNCGI, XrdFrcRequest::getMODE, XrdFrcRequest::getNOTE, XrdFrcRequest::getOBJ, XrdFrcRequest::getOBJCGI, XrdFrcRequest::getOP, XrdFrcRequest::getPRTY, XrdFrcRequest::getQWT, XrdFrcRequest::getRID, XrdFrcRequest::getTOD, XrdFrcRequest::getUSER, XrdFrcRequest::ID, XrdFrcRequest::LFN, XrdFrcRequest::LFO, XrdFrcRequest::makeRW, XrdFrcRequest::msgFail, XrdFrcRequest::msgSucc, XrdFrcRequest::Notify, XrdFrcRequest::Opaque, XrdFrcRequest::OPc, XrdFrcRequest::Options, XrdFrcRequest::Prty, strlcpy(), and XrdFrcRequest::User.

Referenced by List().

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

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

- XrdFrcReqFile.hh
- XrdFrcReqFile.cc