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

#include <XrdBwmHandle.hh>

Collaboration diagram for XrdBwmHandle:

Public Types

enum  HandleState {
  Idle = 0 ,
  Scheduled ,
  Dispatched
}

Public Member Functions

 XrdBwmHandle ()
 ~XrdBwmHandle ()
int Activate (XrdOucErrInfo &einfo)
const char * Name ()
void Retire ()

Static Public Member Functions

static XrdBwmHandleAlloc (const char *theUsr, const char *thePath, const char *lclNode, const char *rmtNode, int Incoming)
static void * Dispatch ()
static int setPolicy (XrdBwmPolicy *pP, XrdBwmLogger *lP)

Public Attributes

HandleState Status

Detailed Description

Definition at line 41 of file XrdBwmHandle.hh.

Member Enumeration Documentation

◆ HandleState

Enumerator
Idle 
Scheduled 
Dispatched 

Definition at line 45 of file XrdBwmHandle.hh.

Constructor & Destructor Documentation

◆ XrdBwmHandle()

XrdBwmHandle::XrdBwmHandle ( )
inline

Definition at line 63 of file XrdBwmHandle.hh.

63 : Status(Idle), Next(0), qTime(0), rTime(0),
64 xSize(0), xTime(0)
65 {}
HandleState Status

References Idle, and Status.

Referenced by Alloc(), and Dispatch().

Here is the caller graph for this function:

◆ ~XrdBwmHandle()

XrdBwmHandle::~XrdBwmHandle ( )
inline

Definition at line 67 of file XrdBwmHandle.hh.

67{}

Member Function Documentation

◆ Activate()

int XrdBwmHandle::Activate ( XrdOucErrInfo & einfo)

Definition at line 111 of file XrdBwmHandle.cc.

112{
113 EPNAME("Activate");
114 XrdSysMutexHelper myHelper(hMutex);
115 char *rBuff;
116 int rSize, rc;
117
118// Check the status of this request.
119//
120 if (Status != Idle)
121 {if (Status == Scheduled)
122 einfo.setErrInfo(kXR_inProgress, "Request already scheduled.");
123 else einfo.setErrInfo(kXR_InvalidRequest, "Visa already issued.");
124 return SFS_ERROR;
125 }
126
127// Try to schedule this request.
128//
129 qTime = time(0);
130 rBuff = einfo.getMsgBuff(rSize);
131 if (!(rc = Policy->Schedule(rBuff, rSize, Parms))) return SFS_ERROR;
132
133// If resource immediately available, let client run
134//
135 if (rc > 0)
136 {rHandle = rc;
138 rTime = time(0);
139 ZTRACE(sched,"Run " <<Parms.Lfn <<' ' <<Parms.LclNode
140 <<(Parms.Direction==XrdBwmPolicy::Incoming?" <- ":" -> ")
141 <<Parms.RmtNode);
142 einfo.setErrCode(strlen(rBuff));
143 return (*rBuff ? SFS_DATA : SFS_OK);
144 }
145
146// Request was queued. We need to hold on to this so we can issue an async
147// response later when the resource becomes available.
148//
149 rHandle = -rc;
150 ErrCB = einfo.getErrCB(ErrCBarg);
151 einfo.setErrCB((XrdOucEICB *)&myEICB);
153 refHandle(rHandle, this);
154 ZTRACE(sched, "inQ " <<Parms.Lfn <<' ' <<Parms.LclNode
155 <<(Parms.Direction==XrdBwmPolicy::Incoming?" <- ":" -> ")
156 <<Parms.RmtNode);
157
158// Indicate that client needs to wait
159//
160 return SFS_STARTED;
161}
@ kXR_InvalidRequest
Definition XProtocol.hh:996
@ kXR_inProgress
#define EPNAME(x)
#define ZTRACE(act, x)
#define SFS_DATA
#define SFS_ERROR
#define SFS_STARTED
#define SFS_OK
XrdOucEICB * getErrCB()
char * getMsgBuff(int &mblen)
void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
int setErrInfo(int code, const char *emsg)
int setErrCode(int code)

References Dispatched, EPNAME, XrdOucErrInfo::getErrCB(), XrdOucErrInfo::getMsgBuff(), Idle, XrdBwmPolicy::Incoming, kXR_inProgress, kXR_InvalidRequest, Scheduled, XrdOucErrInfo::setErrCB(), XrdOucErrInfo::setErrCode(), XrdOucErrInfo::setErrInfo(), SFS_DATA, SFS_ERROR, SFS_OK, SFS_STARTED, Status, and ZTRACE.

Here is the call graph for this function:

◆ Alloc()

XrdBwmHandle * XrdBwmHandle::Alloc ( const char * theUsr,
const char * thePath,
const char * lclNode,
const char * rmtNode,
int Incoming )
static

Definition at line 168 of file XrdBwmHandle.cc.

171{
172 XrdBwmHandle *hP = Alloc();
173
174// Initialize the hanlde
175//
176 if (hP)
177 {hP->Parms.Tident = theUsr; // Always available
178 hP->Parms.Lfn = strdup(thePath);
179 hP->Parms.LclNode = strdup(LclNode);
180 hP->Parms.RmtNode = strdup(RmtNode);
181 hP->Parms.Direction = (Incoming ? XrdBwmPolicy::Incoming
183 hP->Status = Idle;
184 hP->qTime = 0;
185 hP->rTime = 0;
186 hP->xSize = 0;
187 hP->xTime = 0;
188 }
189
190// All done
191//
192 return hP;
193}
static XrdBwmHandle * Alloc(const char *theUsr, const char *thePath, const char *lclNode, const char *rmtNode, int Incoming)

References XrdBwmHandle(), Alloc(), XrdBwmPolicy::SchedParms::Direction, Idle, XrdBwmPolicy::Incoming, XrdBwmPolicy::SchedParms::LclNode, XrdBwmPolicy::SchedParms::Lfn, XrdBwmPolicy::Outgoing, XrdBwmPolicy::SchedParms::RmtNode, Status, and XrdBwmPolicy::SchedParms::Tident.

Referenced by XrdBwm::XrdBwm(), Alloc(), XrdBwmFile::open(), and Retire().

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

◆ Dispatch()

void * XrdBwmHandle::Dispatch ( )
static

Definition at line 226 of file XrdBwmHandle.cc.

227{
228 EPNAME("Dispatch");
229 XrdBwmHandleCB *erP = XrdBwmHandleCB::Alloc();
230 XrdBwmHandle *hP;
231 char *RespBuff;
232 int RespSize, readyH, Result, Err;
233
234// Dispatch ready requests in an endless loop
235//
236 do {
237
238// Setup buffer
239//
240 RespBuff = erP->getMsgBuff(RespSize);
241 *RespBuff = '\0';
242 erP->setErrCode(0);
243
244// Get next ready request and test if it ended with an error
245//
246 if ((Err = (readyH = Policy->Dispatch(RespBuff, RespSize)) < 0))
247 readyH = -readyH;
248
249// Find the matching handle
250//
251 if (!(hP = refHandle(readyH)))
252 {sprintf(RespBuff, "%d", readyH);
253 BwmEroute.Emsg("Dispatch", "Lost handle from", RespBuff);
254 if (!Err) Policy->Done(readyH);
255 continue;
256 }
257
258// Lock the handle and make sure it can be dispatched
259//
260 hP->hMutex.Lock();
261 if (hP->Status != Scheduled)
262 {BwmEroute.Emsg("Dispatch", "ref to unscheduled handle",
263 hP->Parms.Tident, hP->Parms.Lfn);
264 if (!Err) Policy->Done(readyH);
265 } else {
266 hP->myEICB.Wait(); hP->rTime = time(0);
267 erP->setErrCB((XrdOucEICB *)erP, hP->ErrCBarg);
268 if (Err) {hP->Status = Idle; Result = SFS_ERROR;}
269 else {hP->Status = Dispatched;
270 erP->setErrCode(strlen(RespBuff));
271 Result = (*RespBuff ? SFS_DATA : SFS_OK);
272 }
273 ZTRACE(sched,(Err?"Err ":"Run ") <<hP->Parms.Lfn <<' ' <<hP->Parms.LclNode
274 <<(hP->Parms.Direction == XrdBwmPolicy::Incoming ? " <- ":" -> ")
275 <<hP->Parms.RmtNode);
276 hP->ErrCB->Done(Result, (XrdOucErrInfo *)erP);
277 erP = XrdBwmHandleCB::Alloc();
278 }
279 hP->hMutex.UnLock();
280 } while(1);
281
282// Keep the compiler happy
283//
284 return (void *)0;
285}
XrdSysError BwmEroute(0)
Definition XrdBwm.cc:69
#define Err(p, a, b, c)
static XrdBwmHandleCB * Alloc()
virtual void Done(int &Result, XrdOucErrInfo *eInfo, const char *Path=0)=0
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)

References XrdBwmHandle(), XrdBwmHandleCB::Alloc(), BwmEroute, XrdBwmPolicy::SchedParms::Direction, Dispatched, XrdOucEICB::Done(), EPNAME, Err, XrdOucErrInfo::getMsgBuff(), Idle, XrdBwmPolicy::Incoming, XrdBwmPolicy::SchedParms::LclNode, XrdBwmPolicy::SchedParms::Lfn, XrdSysMutex::Lock(), XrdBwmPolicy::SchedParms::RmtNode, Scheduled, XrdOucErrInfo::setErrCB(), XrdOucErrInfo::setErrCode(), SFS_DATA, SFS_ERROR, SFS_OK, Status, XrdBwmPolicy::SchedParms::Tident, XrdSysMutex::UnLock(), and ZTRACE.

Referenced by XrdBwmHanXeq().

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

◆ Name()

const char * XrdBwmHandle::Name ( )
inline

Definition at line 57 of file XrdBwmHandle.hh.

57{return Parms.Lfn;}

◆ Retire()

void XrdBwmHandle::Retire ( )

Definition at line 333 of file XrdBwmHandle.cc.

334{
335 XrdSysMutexHelper myHelper(hMutex);
336
337// Get the global lock as the links field can only be manipulated with it.
338// If not idle, cancel the resource. If scheduled, remove it from the table.
339//
340 if (Status != Idle)
341 {Policy->Done(rHandle);
342 if (Status == Scheduled && !refHandle(rHandle, this))
343 BwmEroute.Emsg("Retire", "Lost handle to", Parms.Tident, Parms.Lfn);
344 Status = Idle; rHandle = 0;
345 }
346
347// If we have a logger, then log this event
348//
349 if (Logger && qTime)
350 {XrdBwmLogger::Info myInfo;
351 myInfo.Tident = Parms.Tident;
352 myInfo.Lfn = Parms.Lfn;
353 myInfo.lclNode = Parms.LclNode;
354 myInfo.rmtNode = Parms.RmtNode;
355 myInfo.ATime = qTime;
356 myInfo.BTime = rTime;
357 myInfo.CTime = time(0);
358 myInfo.Size = xSize;
359 myInfo.ESec = xTime;
360 myInfo.Flow = (Parms.Direction == XrdBwmPolicy::Incoming ? 'I':'O');
361 Policy->Status(myInfo.numqIn, myInfo.numqOut, myInfo.numqXeq);
362 Logger->Event(myInfo);
363 }
364
365// Free storage appendages and recycle handle
366//
367 if (Parms.Lfn) {free(Parms.Lfn); Parms.Lfn = 0;}
368 if (Parms.LclNode) {free(Parms.LclNode); Parms.LclNode = 0;}
369 if (Parms.RmtNode) {free(Parms.RmtNode); Parms.RmtNode = 0;}
370 Alloc(this);
371}
const char * rmtNode
const char * lclNode
const char * Tident

References Alloc(), XrdBwmLogger::Info::ATime, XrdBwmLogger::Info::BTime, BwmEroute, XrdBwmLogger::Info::CTime, XrdBwmLogger::Info::ESec, XrdBwmLogger::Info::Flow, Idle, XrdBwmPolicy::Incoming, XrdBwmLogger::Info::lclNode, XrdBwmLogger::Info::Lfn, XrdBwmLogger::Info::numqIn, XrdBwmLogger::Info::numqOut, XrdBwmLogger::Info::numqXeq, XrdBwmLogger::Info::rmtNode, Scheduled, XrdBwmLogger::Info::Size, Status, and XrdBwmLogger::Info::Tident.

Referenced by XrdBwmFile::close().

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

◆ setPolicy()

int XrdBwmHandle::setPolicy ( XrdBwmPolicy * pP,
XrdBwmLogger * lP )
static

Definition at line 377 of file XrdBwmHandle.cc.

378{
379 pthread_t tid;
380 int rc, startThread = (Policy == 0);
381
382// Set the policy and then start a thread to do dispatching if we have none
383//
384 Policy = pP;
385 if (startThread)
386 if ((rc = XrdSysThread::Run(&tid, XrdBwmHanXeq, (void *)0,
387 0, "Handle Dispatcher")))
388 {BwmEroute.Emsg("setPolicy", rc, "create handle dispatch thread");
389 return 1;
390 }
391
392// All done
393//
394 Logger = lP;
395 return 0;
396}
void * XrdBwmHanXeq(void *pp)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)

References BwmEroute, XrdSysThread::Run(), and XrdBwmHanXeq().

Referenced by XrdBwm::Configure().

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

Member Data Documentation

◆ Status

HandleState XrdBwmHandle::Status

Definition at line 47 of file XrdBwmHandle.hh.

Referenced by XrdBwmHandle(), Activate(), Alloc(), Dispatch(), and Retire().


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