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

◆ ~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:994
@ kXR_inProgress
#define EPNAME(x)
#define ZTRACE(act, x)
#define SFS_DATA
#define SFS_ERROR
#define SFS_STARTED
#define SFS_OK
virtual int Schedule(char *RespBuff, int RespSize, SchedParms &Parms)=0
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 XrdBwmPolicy::SchedParms::Direction, Dispatched, EPNAME, XrdOucErrInfo::getErrCB(), XrdOucErrInfo::getMsgBuff(), Idle, XrdBwmPolicy::Incoming, kXR_inProgress, kXR_InvalidRequest, XrdBwmPolicy::SchedParms::LclNode, XrdBwmPolicy::SchedParms::Lfn, XrdBwmPolicy::SchedParms::RmtNode, XrdBwmPolicy::Schedule(), Scheduled, XrdOucErrInfo::setErrCB(), XrdOucErrInfo::setErrCode(), XrdOucErrInfo::setErrInfo(), SFS_DATA, SFS_ERROR, SFS_OK, SFS_STARTED, Status, and ZTRACE.

Referenced by XrdBwmFile::fctl().

+ Here is the call graph for this function:
+ Here is the caller 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 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 225 of file XrdBwmHandle.cc.

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

References XrdBwmPolicy::SchedParms::Lfn.

Referenced by XrdBwmFile::close(), XrdBwmFile::FName(), and XrdBwmFile::truncate().

+ Here is the caller graph for this function:

◆ Retire()

void XrdBwmHandle::Retire ( )

Definition at line 332 of file XrdBwmHandle.cc.

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

References Alloc(), XrdBwmLogger::Info::ATime, XrdBwmLogger::Info::BTime, BwmEroute, XrdBwmLogger::Info::CTime, XrdBwmPolicy::SchedParms::Direction, XrdBwmPolicy::Done(), XrdSysError::Emsg(), XrdBwmLogger::Info::ESec, XrdBwmLogger::Event(), XrdBwmLogger::Info::Flow, Idle, XrdBwmPolicy::Incoming, XrdBwmPolicy::SchedParms::LclNode, XrdBwmLogger::Info::lclNode, XrdBwmLogger::Info::Lfn, XrdBwmPolicy::SchedParms::Lfn, XrdBwmLogger::Info::numqIn, XrdBwmLogger::Info::numqOut, XrdBwmLogger::Info::numqXeq, XrdBwmPolicy::SchedParms::RmtNode, XrdBwmLogger::Info::rmtNode, Scheduled, XrdBwmLogger::Info::Size, Status, XrdBwmPolicy::Status(), XrdBwmLogger::Info::Tident, and XrdBwmPolicy::SchedParms::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 376 of file XrdBwmHandle.cc.

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

References BwmEroute, XrdSysError::Emsg(), 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 Activate(), Alloc(), Dispatch(), and Retire().


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