xrootd
XrdCmsBaseFS.hh
Go to the documentation of this file.
1 #ifndef __CMS_BASEFS_H__
2 #define __CMS_BASEFS_H__
3 /******************************************************************************/
4 /* */
5 /* X r d C m s B a s e F S . h h */
6 /* */
7 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <stdlib.h>
14 #include <string.h>
15 
16 #include "XrdCms/XrdCmsPList.hh"
17 #include "XrdCms/XrdCmsRRData.hh"
18 #include "XrdCms/XrdCmsTypes.hh"
19 #include "XrdOuc/XrdOucHash.hh"
20 #include "XrdSys/XrdSysPthread.hh"
21 
22 /******************************************************************************/
23 /* C l a s s X r d C m s B a s e F R */
24 /******************************************************************************/
25 
26 class XrdCmsPInfo;
27 
29 {
30 public:
31 
35 char *Buff;
36 char *Path;
37 short PathLen;
38 short PDirLen;
41 
42  XrdCmsBaseFR(XrdCmsRRData &Arg, XrdCmsPInfo &Who, int Dln)
43  : Route(Who.rovec), RouteW(Who.rwvec), Next(0),
44  PathLen(Arg.PathLen), PDirLen(Dln),
45  Sid(Arg.Request.streamid),
46  Mod(Arg.Request.modifier)
47  {if (Arg.Buff)
48  {Path=Arg.Path; Buff=Arg.Buff; Arg.Buff=0;}
49  else Buff = Path = strdup(Arg.Path);
50  }
51 
53  : Route(Who.rovec), RouteW(Who.rwvec),
54  Next(0), Buff(0), Path(aP->Path),
55  PathLen(aP->PathLen), PDirLen(Dln),
56  Sid(aP->Request.streamid),
57  Mod(aP->Request.modifier)
58  {}
59 
60  ~XrdCmsBaseFR() {if (Buff) free(Buff); Buff = 0;}
61 };
62 
63 /******************************************************************************/
64 /* C l a s s X r d C m s B a s e F S */
65 /******************************************************************************/
66 
68 {
69 public:
70 
71 // Exists() returns a tri-logic state:
72 // CmsHaveRequest::Online -> File is known to exist and is available
73 // CmsHaveRequest::Pending -> File is known to exist but is not available
74 // 0 -> File state unknown, result will be provided later
75 // -1 -> File is known not to exist
76 //
77  int Exists(XrdCmsRRData &Arg,XrdCmsPInfo &Who,int noLim=0);
78 
79 // The following exists works as above but limits are never enforced and it
80 // never returns 0. Additionally, the fnpos parameter works as follows:
81 //
82 // > 0 -> Offset into path to the last slash before the filename.
83 // = 0 -> A valid offset has not been calculated nor should it be calculated.
84 // < 0 -> A valid offset has not been calculated, fnpos = -(length of Path).
85 
86  int Exists(char *Path, int fnPos, int UpAT=0);
87 
88 // Valid Opts for Init()
89 //
90 static const int Cntrl = 0x0001; // Centralize stat() o/w distribute it
91 static const int DFSys = 0x0002; // Distributed filesystem o/w jbods
92 static const int Immed = 0x0004; // Redirect immediately o/w preselect
93 static const int Servr = 0x0100; // This is a pure server node
94 
95  void Init(int Opts, int DMlife, int DPLife);
96 
97 inline int isDFS() {return dfsSys;}
98 
99 inline int Limit() {return theQ.rLimit;}
100 
101  void Limit(int rLim, int qMax);
102 
103 inline int Local() {return lclStat;}
104 
105  void Pacer();
106 
107  void Runner();
108 
109  void Start();
110 
111 inline int Trim() {return preSel;}
112 
113 inline int Traverse() {return Punt;}
114 
115  XrdCmsBaseFS(void (*theCB)(XrdCmsBaseFR *, int))
116  : cBack(theCB), dmLife(0), dpLife(0), lclStat(0), preSel(1),
117  dfsSys(0), Server(0), Fixed(0), Punt(0) {}
119 
120 private:
121 
122 struct dMoP {int Present;};
123 
124  int Bypass();
125  int FStat( char *Path, int fnPos, int upat=0);
126  int hasDir(char *Path, int fnPos);
127  void Queue(XrdCmsRRData &Arg, XrdCmsPInfo &Who,
128  int dln, int Frc=0);
129  void Xeq(XrdCmsBaseFR *rP);
130 
133  void (*cBack)(XrdCmsBaseFR *, int);
134 
135 struct RequestQ
143  int rLimit; // Maximum number of requests per second
144  int qHWM; // Queue high watermark
145  int qMax; // Maximum elements to be queued
146  int qNum; // Total number of queued elements (pq + rq)
147  int rLeft; // Number of non-queue requests allowed
148  int rAgain; // Value to reinitialize rLeft
150  pqFirst(0), pqLast(0), rqFirst(0), rqLast(0),
151  rLimit(0), qHWM(0), qMax(1), qNum(0),
152  rLeft(0), rAgain(0) {}
154  } theQ;
155 
156  int dmLife;
157  int dpLife;
158  char lclStat; // 1-> Local stat() calls wanted
159  char preSel; // 1-> Preselect before redirect
160  char dfsSys; // 1-> Distributed Filesystem
161  char Server; // 1-> This is a data server
162  char Fixed; // 1-> Use fixed rate processing
163  char Punt; // 1-> Pass through any forwarding
164 };
165 namespace XrdCms
166 {
167 extern XrdCmsBaseFS baseFS;
168 }
169 #endif