XRootD
XrdXrootdFileTable Class Reference

#include <XrdXrootdFile.hh>

+ Collaboration diagram for XrdXrootdFileTable:

Public Member Functions

 XrdXrootdFileTable (unsigned int mid=0)
 
int Add (XrdXrootdFile *fp)
 
XrdXrootdFileDel (XrdXrootdMonitor *monP, int fnum, bool dodel=true)
 
XrdXrootdFileGet (int fnum)
 
void Recycle (XrdXrootdMonitor *monP)
 

Static Public Attributes

static XrdXrootdFileheldSpotP = (XrdXrootdFile *)1
 

Detailed Description

Definition at line 161 of file XrdXrootdFile.hh.

Constructor & Destructor Documentation

◆ XrdXrootdFileTable()

XrdXrootdFileTable::XrdXrootdFileTable ( unsigned int  mid = 0)
inline

Definition at line 186 of file XrdXrootdFile.hh.

186  : fhProc(0), FTfree(0), monID(mid),
187  XTab(0), XTnum(0), XTfree(0)
188  {memset((void *)FTab, 0, sizeof(FTab));}

Member Function Documentation

◆ Add()

int XrdXrootdFileTable::Add ( XrdXrootdFile fp)

Definition at line 206 of file XrdXrootdFile.cc.

207 {
208  const int allocsz = XRD_FTABSIZE*sizeof(fp);
209  XrdXrootdFile **newXTab, **oldXTab;
210  int i;
211 
212 // If we have a file handle processor, see if it can give us a file handle
213 // that's already in our table.
214 //
215  if (fhProc && (i = fhProc->Get()) >= 0)
216  {XrdXrootdFile **fP;
217  if (i < XRD_FTABSIZE) fP = &FTab[i];
218  else {i -= XRD_FTABSIZE;
219  if (XTab && i < XTnum) fP = &XTab[i];
220  else fP = 0;
221  i += XRD_FTABSIZE;
222  }
223  if (fP && *fP == heldSpotP)
224  {*fP = fp;
225  TRACEI(FS, "reusing fh " <<i <<" for " <<fp->FileKey);
226  return i;
227  }
228  char fhn[32];
229  snprintf(fhn, sizeof(fhn), "%d", i);
230  eDest->Emsg("FTab_Add", "Invalid recycled fHandle",fhn,"ignored.");
231  }
232 
233 // Find a free spot in the internal table
234 //
235  for (i = FTfree; i < XRD_FTABSIZE; i++) if (!FTab[i]) break;
236 
237  if (i < XRD_FTABSIZE)
238  {FTab[i] = fp; FTfree = i+1; return i;}
239 
240 // Allocate an external table if we do not have one
241 //
242  if (!XTab)
243  {if (!(XTab = (XrdXrootdFile **)malloc(allocsz))) return -1;
244  memset((void *)XTab, 0, allocsz);
245  XTnum = XRD_FTABSIZE;
246  XTfree = 1;
247  XTab[0] = fp;
248  return XRD_FTABSIZE;
249  }
250 
251 // Find a free spot in the external table
252 //
253  for (i = XTfree; i < XTnum; i++) if (!XTab[i]) break;
254  if (i < XTnum)
255  {XTab[i] = fp; XTfree = i+1; return i+XRD_FTABSIZE;}
256 
257 // Extend the table
258 //
259  if (!(newXTab = (XrdXrootdFile **)malloc(XTnum*sizeof(XrdXrootdFile *)+allocsz)))
260  return -1;
261  memcpy((void *)newXTab, (const void *)XTab, XTnum*sizeof(XrdXrootdFile *));
262  memset((void *)(newXTab+XTnum), 0, allocsz);
263  oldXTab = XTab;
264  XTab = newXTab;
265  XTab[XTnum] = fp;
266  i = XTnum;
267  XTfree = XTnum+1;
268  XTnum += XRD_FTABSIZE;
269  free(oldXTab);
270  return i+XRD_FTABSIZE;
271 }
static XrdSysError eDest(0,"crypto_")
#define TRACEI(act, x)
Definition: XrdTrace.hh:66
#define XRD_FTABSIZE
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
static XrdXrootdFile * heldSpotP

References eDest, XrdSysError::Emsg(), XrdXrootdFile::FileKey, XrdXrootdFileHP::Get(), heldSpotP, TRACEI, and XRD_FTABSIZE.

+ Here is the call graph for this function:

◆ Del()

XrdXrootdFile * XrdXrootdFileTable::Del ( XrdXrootdMonitor monP,
int  fnum,
bool  dodel = true 
)

!! For now we add pgreads to normal reads and pgwrite to normal writes !! Once we figure out how to report them separately, we need to do this.

Definition at line 277 of file XrdXrootdFile.cc.

279 {
280  union {XrdXrootdFile *fp; unsigned long fv;};
281  XrdXrootdFile *repVal = (dodel ? 0 : heldSpotP);
282  int fh = fnum;
283 
284  if (fnum < XRD_FTABSIZE)
285  {fp = FTab[fnum];
286  FTab[fnum] = repVal;
287  if (fnum < FTfree) FTfree = fnum;
288  } else {
289  fnum -= XRD_FTABSIZE;
290  if (XTab && fnum < XTnum)
291  {fp = XTab[fnum];
292  XTab[fnum] = repVal;
293  if (fnum < XTfree) XTfree = fnum;
294  }
295  else fp = 0;
296  }
297 
298  fv &= heldMask;
299 
300  if (fp)
301  {XrdXrootdFileStats &Stats = fp->Stats;
304 
305  Stats.xfr.read += Stats.prw.rBytes;
306  Stats.xfr.write += Stats.prw.wBytes;
307  Stats.ops.read += Stats.prw.rCount;
308  Stats.ops.write += Stats.prw.wCount; // Doesn't include retries!!!
309 
310  if (monP) monP->Close(Stats.FileID,
311  Stats.xfr.read + Stats.xfr.readv,
312  Stats.xfr.write);
313  if (Stats.MonEnt != -1) XrdXrootdMonFile::Close(&Stats, false);
314  if (dodel) {delete fp; fp = 0;} // Will do the close
315  else {if (!fhProc) fhProc = new XrdXrootdFileHP;
316  else fhProc->Ref();
317  fp->fHandle = fh;
318  fp->fhProc = fhProc;
319  TRACEI(FS, "defer fh " <<fh <<" del for " <<fp->FileKey);
320  }
321  }
322  return fp;
323 }
static void Close(XrdXrootdFileStats *fsP, bool isDisc=false)
void Close(kXR_unt32 dictid, long long rTot, long long wTot)
XrdPosixStats Stats
Definition: XrdPosixFile.cc:64

References XrdXrootdMonitor::Close(), XrdXrootdMonFile::Close(), heldSpotP, XrdXrootdFileHP::Ref(), XrdPosixGlobals::Stats, TRACEI, and XRD_FTABSIZE.

+ Here is the call graph for this function:

◆ Get()

XrdXrootdFile* XrdXrootdFileTable::Get ( int  fnum)
inline

Definition at line 169 of file XrdXrootdFile.hh.

170  {if (fnum >= 0)
171  {if (fnum < XRD_FTABSIZE)
172  {if (FTab[fnum] != heldSpotP) return FTab[fnum];
173  } else {
174  if (XTab)
175  {int i = fnum - XRD_FTABSIZE;
176  if (i < XTnum && XTab[i] != heldSpotP)
177  return XTab[i];
178  }
179  }
180  }
181  return (XrdXrootdFile *)0;
182  }

References heldSpotP, and XRD_FTABSIZE.

Referenced by XrdXrootdProtocol::do_WriteSpan(), and XrdXrootdProtocol::SetSF().

+ Here is the caller graph for this function:

◆ Recycle()

void XrdXrootdFileTable::Recycle ( XrdXrootdMonitor monP)

Definition at line 333 of file XrdXrootdFile.cc.

334 {
335  int i;
336 
337 // Delete all objects from the internal table (see warning)
338 //
339  FTfree = 0;
340  for (i = 0; i < XRD_FTABSIZE; i++)
341  if (FTab[i] && FTab[i] != heldSpotP)
342  {XrdXrootdFileStats &Stats = FTab[i]->Stats;
343  if (monP) monP->Close(Stats.FileID,
344  Stats.xfr.read+Stats.xfr.readv,
345  Stats.xfr.write);
346  if (Stats.MonEnt != -1) XrdXrootdMonFile::Close(&Stats, true);
347  delete FTab[i]; FTab[i] = 0;
348  }
349 
350 // Delete all objects from the external table (see warning)
351 //
352 if (XTab)
353  {for (i = 0; i < XTnum; i++)
354  {if (XTab[i] && XTab[i] != heldSpotP)
355  {XrdXrootdFileStats &Stats = XTab[i]->Stats;
356  if (monP) monP->Close(Stats.FileID,
357  Stats.xfr.read+Stats.xfr.readv,
358  Stats.xfr.write);
359  if (Stats.MonEnt != -1) XrdXrootdMonFile::Close(&Stats, true);
360  delete XTab[i];
361  }
362  }
363  free(XTab); XTab = 0; XTnum = 0; XTfree = 0;
364  }
365 
366 // If we have a filehandle processor, delete it. Note that it will stay alive
367 // until all requests for file handles against it are resolved.
368 //
369  if (fhProc) fhProc->Delete();
370 
371 // Delete this object
372 //
373  delete this;
374 }
XrdXrootdFileStats Stats

References XrdXrootdMonitor::Close(), XrdXrootdMonFile::Close(), XrdXrootdFileHP::Delete(), heldSpotP, XrdPosixGlobals::Stats, XrdXrootdFile::Stats, and XRD_FTABSIZE.

+ Here is the call graph for this function:

Member Data Documentation

◆ heldSpotP

XrdXrootdFile * XrdXrootdFileTable::heldSpotP = (XrdXrootdFile *)1
static

Definition at line 190 of file XrdXrootdFile.hh.

Referenced by Add(), Del(), Get(), and Recycle().


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