XRootD
XrdOfsHandle Class Reference

#include <XrdOfsHandle.hh>

+ Collaboration diagram for XrdOfsHandle:

Public Member Functions

 XrdOfsHandle ()
 
 ~XrdOfsHandle ()
 
void Activate (XrdOssDF *ssP)
 
int Inactive ()
 
void Lock ()
 
const char * Name ()
 
int PoscGet (short &Mode, int Done=0)
 
int PoscSet (const char *User, int Unum, short Mode)
 
const char * PoscUsr ()
 
int Retire (int &retc, long long *retsz=0, char *buff=0, int blen=0)
 
int Retire (XrdOfsHanCB *, int DSec)
 
XrdOssDFSelect (void)
 
void Suppress (int rrc=-EDOM, int wrc=-EDOM)
 
void UnLock ()
 
int Usage ()
 

Static Public Member Functions

static int Alloc (const char *thePath, int Opts, XrdOfsHandle **Handle)
 
static int Alloc (XrdOfsHandle **Handle)
 
static void Hide (const char *thePath)
 
static int StartXpr (int Init=0)
 

Public Attributes

char isChanged
 
char isCompressed
 
char isPending
 
char isRW
 

Static Public Attributes

static const int opPC = 3
 
static const int opRW = 1
 

Friends

class XrdOfsHanTab
 
class XrdOfsHanXpr
 

Detailed Description

Definition at line 125 of file XrdOfsHandle.hh.

Constructor & Destructor Documentation

◆ XrdOfsHandle()

XrdOfsHandle::XrdOfsHandle ( )
inline

Definition at line 172 of file XrdOfsHandle.hh.

172 : Path(0,0) {}

◆ ~XrdOfsHandle()

XrdOfsHandle::~XrdOfsHandle ( )
inline

Definition at line 174 of file XrdOfsHandle.hh.

174 {int retc; Retire(retc);}
int Retire(int &retc, long long *retsz=0, char *buff=0, int blen=0)

References Retire().

+ Here is the call graph for this function:

Member Function Documentation

◆ Activate()

void XrdOfsHandle::Activate ( XrdOssDF ssP)
inline

Definition at line 136 of file XrdOfsHandle.hh.

136 {ssi = ssP;}

◆ Alloc() [1/2]

int XrdOfsHandle::Alloc ( const char *  thePath,
int  Opts,
XrdOfsHandle **  Handle 
)
static

Definition at line 260 of file XrdOfsHandle.cc.

261 {
262  XrdOfsHandle *hP;
263  XrdOfsHanTab *theTable = (Opts & opRW ? &rwTable : &roTable);
264  XrdOfsHanKey theKey(thePath, (int)strlen(thePath));
265  int retc;
266 
267 // Lock the search table and try to find the key. If found, increment the
268 // the link count (can only be done with the global lock) then release the
269 // lock and try to lock the handle. It can't escape between lock calls because
270 // the link count is positive. If we can't lock the handle then it must be the
271 // that a long running operation is occuring. Return the handle to its former
272 // state and return a delay. Otherwise, return the handle.
273 //
274  myMutex.Lock();
275  if ((hP = theTable->Find(theKey)))
276  {hP->Path.Links++; myMutex.UnLock();
277  if (hP->WaitLock()) {*Handle = hP; return 0;}
278  myMutex.Lock(); hP->Path.Links--; myMutex.UnLock();
279  return nolokDelay;
280  }
281 
282 // Get a new handle
283 //
284  if (!(retc = Alloc(theKey, Opts, Handle))) theTable->Add(*Handle);
286 
287 // All done
288 //
289  myMutex.UnLock();
290  return retc;
291 }
XrdOfsStats OfsStats
Definition: XrdOfs.cc:113
unsigned int Links
Definition: XrdOfsHandle.hh:51
XrdOfsHandle * Find(XrdOfsHanKey &Key)
void Add(XrdOfsHandle *hP)
static const int opRW
static int Alloc(const char *thePath, int Opts, XrdOfsHandle **Handle)
struct XrdOfsStats::StatsData Data
void Add(int &Cntr)
Definition: XrdOfsStats.hh:62
int Opts
Definition: XrdMpxStats.cc:58

References XrdOfsStats::Add(), XrdOfsHanTab::Add(), XrdOfsStats::Data, XrdOfsHanTab::Find(), XrdOfsHanKey::Links, XrdSysMutex::Lock(), XrdOfsStats::StatsData::numHandles, OfsStats, opRW, XrdMpx::Opts, and XrdSysMutex::UnLock().

Referenced by XrdOfs::XrdOfs(), Alloc(), and XrdOfsFile::open().

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

◆ Alloc() [2/2]

int XrdOfsHandle::Alloc ( XrdOfsHandle **  Handle)
static

Definition at line 297 of file XrdOfsHandle.cc.

298 {
299  XrdOfsHanKey myKey("dummy", 5);
300  int retc;
301 
302  myMutex.Lock();
303  if (!(retc = Alloc(myKey, 0, Handle)))
304  {(*Handle)->Path.Links = 0; (*Handle)->UnLock();}
305  myMutex.UnLock();
306  return retc;
307 }

References Alloc(), XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ Hide()

void XrdOfsHandle::Hide ( const char *  thePath)
static

Definition at line 346 of file XrdOfsHandle.cc.

347 {
348  XrdOfsHandle *hP;
349  XrdOfsHanKey theKey(thePath, (int)strlen(thePath));
350 
351 // Lock the search table and try to find the key in each table. If found,
352 // clear the length field to effectively hide the item.
353 //
354  myMutex.Lock();
355  if ((hP = roTable.Find(theKey))) hP->Path.Len = 0;
356  if ((hP = rwTable.Find(theKey))) hP->Path.Len = 0;
357  myMutex.UnLock();
358 }

References XrdOfsHanTab::Find(), XrdOfsHanKey::Len, XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

Referenced by XrdPfcFSctl::FSctl(), and XrdOfs::rename().

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

◆ Inactive()

int XrdOfsHandle::Inactive ( )
inline

Definition at line 146 of file XrdOfsHandle.hh.

146 {return (ssi == ossDF);}

Referenced by XrdOfsFile::checkpoint(), and XrdOfsFile::close().

+ Here is the caller graph for this function:

◆ Lock()

void XrdOfsHandle::Lock ( )
inline

Definition at line 169 of file XrdOfsHandle.hh.

169 {hMutex.Lock();}

References XrdSysMutex::Lock().

Referenced by XrdOfsFile::close(), XrdOfs::Emsg(), and XrdOfsFile::sync().

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

◆ Name()

const char* XrdOfsHandle::Name ( )
inline

Definition at line 148 of file XrdOfsHandle.hh.

148 {return Path.Val;}
const char * Val
Definition: XrdOfsHandle.hh:50

References Path.

Referenced by XrdOfsFile::checkpoint(), XrdOfsFile::close(), XrdOfs::Emsg(), XrdOfsFile::FName(), XrdOfsFile::pgRead(), XrdOfsFile::pgWrite(), XrdOfsFile::read(), XrdOfsFile::readv(), XrdOfsFile::stat(), XrdOfs::Unpersist(), and XrdOfsFile::write().

+ Here is the caller graph for this function:

◆ PoscGet()

int XrdOfsHandle::PoscGet ( short &  Mode,
int  Done = 0 
)

Definition at line 366 of file XrdOfsHandle.cc.

367 {
368  XrdOfsHanPsc *pP;
369  int pnum;
370 
371  if (Posc)
372  {pnum = Posc->Unum;
373  Mode = Posc->Mode;
374  if (Done)
375  {pP = Posc; Posc = 0;
376  if (pP->xprP) {myMutex.Lock(); Path.Links--; myMutex.UnLock();}
377  pP->Recycle();
378  }
379  return pnum;
380  }
381 
382  Mode = 0;
383  return 0;
384 }
int Mode
XrdOfsHanXpr * xprP

References XrdOfsHanKey::Links, XrdSysMutex::Lock(), XrdOfsHanPsc::Mode, Mode, XrdOfsHanPsc::Recycle(), XrdSysMutex::UnLock(), XrdOfsHanPsc::Unum, and XrdOfsHanPsc::xprP.

Referenced by XrdOfsFile::close(), and XrdOfs::Unpersist().

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

◆ PoscSet()

int XrdOfsHandle::PoscSet ( const char *  User,
int  Unum,
short  Mode 
)

Definition at line 392 of file XrdOfsHandle.cc.

393 {
394  static const char *Who = "?:0.0@?", *Whc = Who+1, *Whh = Who+5;
395  const char *Col, *At;
396  int retval = 0;
397 
398 // If we have no posc object then we may just be able to return
399 //
400  if (!Posc)
401  {if (Unum > 0) Posc = XrdOfsHanPsc::Alloc();
402  else return 0;
403  }
404 
405 // Find the markers in the incoming user
406 //
407  if (!(Col = index(User, ':')) || !(At = index(User, '@')))
408  {User = Who; Col = Whc; At = Whh;}
409 
410 // If we already have a user check if it matches. We allow the same user to
411 // reconnect to the file even when it is in posc mode to allow for write error
412 // recovery. Other users must re-enable posc for the file to show that they are
413 // aware that the file is under POSC mode as this is not a recovery.
414 //
415  if (Posc->User)
416  {if (!Unum)
417  {if (!strncmp(User, Posc->User, Posc->Ulen)
418  && !strcmp(Posc->User + Posc->Uhst, At+1)) return 0;
419  return -ETXTBSY;
420  } else {
421  char buff[1024];
422  sprintf(buff, "%s to %s for", Posc->User, User);
423  OfsEroute.Emsg("Posc", "Creator changed from", buff, Path.Val);
424  if (Unum < 0) Unum = Posc->Unum;
425  else if (Unum != Posc->Unum) retval = Posc->Unum;
426  }
427  free(Posc->User);
428  }
429 
430 // Assign creation values
431 //
432  Posc->User = strdup(User);
433  Posc->Ulen = Col - User + 1;
434  Posc->Uhst = At - User + 1;
435  Posc->Unum = Unum;
436  Posc->Mode = Umod;
437  return retval;
438 }
XrdSysError OfsEroute
static XrdOfsHanPsc * Alloc()
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95

References XrdOfsHanPsc::Alloc(), XrdSysError::Emsg(), XrdOfsHanPsc::Mode, OfsEroute, XrdOfsHanPsc::Uhst, XrdOfsHanPsc::Ulen, XrdOfsHanPsc::Unum, and XrdOfsHanKey::Val.

+ Here is the call graph for this function:

◆ PoscUsr()

const char * XrdOfsHandle::PoscUsr ( )

Definition at line 446 of file XrdOfsHandle.cc.

447 {
448  if (Posc) return Posc->User;
449  return "?@?";
450 }

Referenced by XrdOfs::Unpersist().

+ Here is the caller graph for this function:

◆ Retire() [1/2]

int XrdOfsHandle::Retire ( int &  retc,
long long *  retsz = 0,
char *  buff = 0,
int  blen = 0 
)

Definition at line 458 of file XrdOfsHandle.cc.

459 {
460  XrdOssDF *mySSI;
461  int numLeft;
462 
463 // Get the global lock as the links field can only be manipulated with it.
464 // Decrement the links count and if zero, remove it from the table and
465 // place it on the free list. Otherwise, it is still in use.
466 //
467  retc = 0;
468  myMutex.Lock();
469  if (Path.Links == 1)
470  {if (buff) strlcpy(buff, Path.Val, blen);
471  numLeft = 0; OfsStats.Dec(OfsStats.Data.numHandles);
472  if ( (isRW ? rwTable.Remove(this) : roTable.Remove(this)) )
473  {if (Posc) {Posc->Recycle(); Posc = 0;}
474  if (Path.Val) {free((void *)Path.Val); Path.Val = (char *)"";}
475  Path.Len = 0; mySSI = ssi; ssi = ossDF;
476  Next = Free; Free = this; UnLock(); myMutex.UnLock();
477  if (mySSI && mySSI != ossDF)
478  {retc = mySSI->Close(retsz); delete mySSI;}
479  } else {
480  UnLock(); myMutex.UnLock();
481  OfsEroute.Emsg("Retire", "Lost handle to", buff);
482  }
483  } else {numLeft = --Path.Links; UnLock(); myMutex.UnLock();}
484  return numLeft;
485 }
size_t strlcpy(char *dst, const char *src, size_t sz)
int Remove(XrdOfsHandle *rip)
void Dec(int &Cntr)
Definition: XrdOfsStats.hh:64
virtual int Close(long long *retsz=0)=0

References XrdOssDF::Close(), XrdOfsStats::Data, XrdOfsStats::Dec(), XrdSysError::Emsg(), isRW, XrdOfsHanKey::Len, XrdOfsHanKey::Links, XrdSysMutex::Lock(), XrdOfsStats::StatsData::numHandles, OfsEroute, OfsStats, XrdOfsHanPsc::Recycle(), XrdOfsHanTab::Remove(), strlcpy(), UnLock(), XrdSysMutex::UnLock(), and XrdOfsHanKey::Val.

Referenced by ~XrdOfsHandle(), XrdOfsFile::close(), XrdOfsFile::open(), Retire(), and StartXpr().

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

◆ Retire() [2/2]

int XrdOfsHandle::Retire ( XrdOfsHanCB cbP,
int  DSec 
)

Definition at line 489 of file XrdOfsHandle.cc.

490 {
491  static int allOK = StartXpr(1);
492  XrdOfsHanXpr *xP;
493  int retc;
494 
495 // The handle can only be held by one reference and only if it's a POSC and
496 // deferred handling was properly set up.
497 //
498  myMutex.Lock();
499  if (!Posc || !allOK)
500  {OfsEroute.Emsg("Retire", "ignoring deferred retire of", Path.Val);
501  if (Path.Links != 1 || !Posc || !cbP) myMutex.UnLock();
502  else {myMutex.UnLock(); cbP->Retired(this);}
503  return Retire(retc);
504  }
505  myMutex.UnLock();
506 
507 // If this object already has an xpr object (happens for bouncing connections)
508 // then reuse that object. Otherwise create a new one and put it on the queue.
509 //
510  if (Posc->xprP) Posc->xprP->Set(cbP, hTime+time(0));
511  else {xP = Posc->xprP = new XrdOfsHanXpr(this, cbP, hTime+time(0));
512  xP->add2Q();
513  }
514  UnLock();
515  return 0;
516 }
virtual void Retired(XrdOfsHandle *)=0
void Set(XrdOfsHanCB *cbP, time_t xtm)
void add2Q(int doLK=1)
static int StartXpr(int Init=0)
friend class XrdOfsHanXpr

References XrdOfsHanXpr::add2Q(), XrdSysError::Emsg(), XrdOfsHanKey::Links, XrdSysMutex::Lock(), OfsEroute, Retire(), XrdOfsHanCB::Retired(), XrdOfsHanXpr::Set(), StartXpr(), UnLock(), XrdSysMutex::UnLock(), XrdOfsHanKey::Val, XrdOfsHanPsc::xprP, and XrdOfsHanXpr.

+ Here is the call graph for this function:

◆ Select()

XrdOssDF& XrdOfsHandle::Select ( void  )
inline

Definition at line 161 of file XrdOfsHandle.hh.

161 {return *ssi;} // To allow for mt interfaces

Referenced by XrdOfsFile::checkpoint(), XrdOfsFile::close(), XrdOfsFile::fctl(), XrdOfsFile::getCXinfo(), XrdOfsFile::getMmap(), XrdOfsFile::pgRead(), XrdOfsFile::pgWrite(), XrdOfsFile::read(), XrdOfsFile::readv(), XrdOfsFile::stat(), XrdOfsFile::sync(), XrdOfsFile::truncate(), and XrdOfsFile::write().

+ Here is the caller graph for this function:

◆ StartXpr()

int XrdOfsHandle::StartXpr ( int  Init = 0)
static

Definition at line 522 of file XrdOfsHandle.cc.

523 {
524  static int InitDone = 0;
525  XrdOfsHanXpr *xP;
526  XrdOfsHandle *hP;
527  int retc;
528 
529 // If this is the initial all and we have not been initialized do so
530 //
531  if (Init)
532  {pthread_t tid;
533  int rc;
534  if (InitDone) return InitDone == 1;
535  if ((rc = XrdSysThread::Run(&tid, XrdOfsHanXpire, (void *)0,
536  0, "Handle Timeout")))
537  {OfsEroute.Emsg("StartXpr", rc, "create handle timeout thread");
538  InitDone = -1; return 0;
539  }
540  InitDone = 1; return 1;
541  }
542 
543 // Simply loop waiting for expired handles to become available. The Get() will
544 // return an Xpr object with the associated handle locked.
545 //
546 do{xP = XrdOfsHanXpr::Get(); hP = xP->Handle;
547 
548 // Perform validity check on the handle to catch instances where the handle
549 // was closed while we were in the process of getting it. While this is safe
550 // it should never happen, so issue a message so we know to fix it.
551 //
552  if (hP->Posc && xP == hP->Posc->xprP) hP->Posc->xprP = 0;
553  else {OfsEroute.Emsg("StarXtpr", "Invalid xpr ref to", hP->Path.Val);
554  hP->UnLock(); delete xP; continue;
555  }
556 
557 // As the handle is locked we can get the global handle lock to prevent
558 // additions and removals of handles as we need a stable reference count to
559 // effect the callout, if any. Do so only if the reference count is one (for us)
560 // and the handle is active. In all cases, drop the global lock.
561 //
562  myMutex.Lock();
563  if (hP->Path.Links != 1 || !xP->Call) myMutex.UnLock();
564  else {myMutex.UnLock();
565  xP->Call->Retired(hP);
566  }
567 
568 // We can now officially retire the handle and delete the xpr object
569 //
570  hP->Retire(retc);
571  delete xP;
572  } while(1);
573 
574 // Keep the compiler happy
575 //
576  return 0;
577 }
void * XrdOfsHanXpire(void *pp)
static XrdOfsHanXpr * Get()
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)

References XrdSysError::Emsg(), XrdOfsHanXpr::Get(), XrdOfsHanKey::Links, XrdSysMutex::Lock(), OfsEroute, Retire(), XrdOfsHanCB::Retired(), XrdSysThread::Run(), UnLock(), XrdSysMutex::UnLock(), XrdOfsHanKey::Val, XrdOfsHanPsc::xprP, and XrdOfsHanXpire().

Referenced by Retire(), and XrdOfsHanXpire().

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

◆ Suppress()

void XrdOfsHandle::Suppress ( int  rrc = -EDOM,
int  wrc = -EDOM 
)

Definition at line 583 of file XrdOfsHandle.cc.

584 {
585  ssi = new XrdOfsHanOssErr(ssi, rrc, wrc);
586 }

Referenced by XrdOfsFile::checkpoint().

+ Here is the caller graph for this function:

◆ UnLock()

void XrdOfsHandle::UnLock ( )
inline

Definition at line 170 of file XrdOfsHandle.hh.

170 {hMutex.UnLock();}

References XrdSysMutex::UnLock().

Referenced by XrdOfs::Emsg(), Retire(), StartXpr(), and XrdOfsFile::sync().

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

◆ Usage()

int XrdOfsHandle::Usage ( )
inline

Definition at line 167 of file XrdOfsHandle.hh.

167 {return Path.Links;}

References Path.

Referenced by XrdOfsFile::close(), and XrdOfsFile::open().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ XrdOfsHanTab

friend class XrdOfsHanTab
friend

Definition at line 127 of file XrdOfsHandle.hh.

◆ XrdOfsHanXpr

friend class XrdOfsHanXpr
friend

Definition at line 128 of file XrdOfsHandle.hh.

Referenced by Retire().

Member Data Documentation

◆ isChanged

char XrdOfsHandle::isChanged

Definition at line 132 of file XrdOfsHandle.hh.

Referenced by XrdOfsFile::pgWrite(), XrdOfsFile::truncate(), and XrdOfsFile::write().

◆ isCompressed

char XrdOfsHandle::isCompressed

Definition at line 133 of file XrdOfsHandle.hh.

Referenced by XrdOfsFile::open(), XrdOfsFile::pgRead(), and XrdOfsFile::read().

◆ isPending

char XrdOfsHandle::isPending

◆ isRW

char XrdOfsHandle::isRW

◆ opPC

const int XrdOfsHandle::opPC = 3
static

◆ opRW

const int XrdOfsHandle::opRW = 1
static

Definition at line 138 of file XrdOfsHandle.hh.

Referenced by Alloc(), and XrdOfsFile::open().


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