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 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <stdlib.h>
34 #include <string.h>
35 
36 #include "XrdCms/XrdCmsPList.hh"
37 #include "XrdCms/XrdCmsRRData.hh"
38 #include "XrdCms/XrdCmsTypes.hh"
39 #include "XrdOuc/XrdOucHash.hh"
40 #include "XrdSys/XrdSysPthread.hh"
41 
42 /******************************************************************************/
43 /* C l a s s X r d C m s B a s e F R */
44 /******************************************************************************/
45 
46 class XrdCmsPInfo;
47 
49 {
50 public:
51 
55 char *Buff;
56 char *Path;
57 short PathLen;
58 short PDirLen;
61 
62  XrdCmsBaseFR(XrdCmsRRData &Arg, XrdCmsPInfo &Who, int Dln)
63  : Route(Who.rovec), RouteW(Who.rwvec), Next(0),
64  PathLen(Arg.PathLen), PDirLen(Dln),
65  Sid(Arg.Request.streamid),
66  Mod(Arg.Request.modifier)
67  {if (Arg.Buff)
68  {Path=Arg.Path; Buff=Arg.Buff; Arg.Buff=0;}
69  else Buff = Path = strdup(Arg.Path);
70  }
71 
73  : Route(Who.rovec), RouteW(Who.rwvec),
74  Next(0), Buff(0), Path(aP->Path),
75  PathLen(aP->PathLen), PDirLen(Dln),
76  Sid(aP->Request.streamid),
77  Mod(aP->Request.modifier)
78  {}
79 
80  ~XrdCmsBaseFR() {if (Buff) free(Buff); Buff = 0;}
81 };
82 
83 /******************************************************************************/
84 /* C l a s s X r d C m s B a s e F S */
85 /******************************************************************************/
86 
88 {
89 public:
90 
91 // Exists() returns a tri-logic state:
92 // CmsHaveRequest::Online -> File is known to exist and is available
93 // CmsHaveRequest::Pending -> File is known to exist but is not available
94 // 0 -> File state unknown, result will be provided later
95 // -1 -> File is known not to exist
96 //
97  int Exists(XrdCmsRRData &Arg,XrdCmsPInfo &Who,int noLim=0);
98 
99 // The following exists works as above but limits are never enforced and it
100 // never returns 0. Additionally, the fnpos parameter works as follows:
101 //
102 // > 0 -> Offset into path to the last slash before the filename.
103 // = 0 -> A valid offset has not been calculated nor should it be calculated.
104 // < 0 -> A valid offset has not been calculated, fnpos = -(length of Path).
105 
106  int Exists(char *Path, int fnPos, int UpAT=0);
107 
108 // Valid Opts for Init()
109 //
110 static const int Cntrl = 0x0001; // Centralize stat() o/w distribute it
111 static const int DFSys = 0x0002; // Distributed filesystem o/w jbods
112 static const int Immed = 0x0004; // Redirect immediately o/w preselect
113 static const int Servr = 0x0100; // This is a pure server node
114 
115  void Init(int Opts, int DMlife, int DPLife);
116 
117 inline int isDFS() {return dfsSys;}
118 
119 inline int Limit() {return theQ.rLimit;}
120 
121  void Limit(int rLim, int qMax);
122 
123 inline int Local() {return lclStat;}
124 
125  void Pacer();
126 
127  void Runner();
128 
129  void Start();
130 
131 inline int Trim() {return preSel;}
132 
133 inline int Traverse() {return Punt;}
134 
135  XrdCmsBaseFS(void (*theCB)(XrdCmsBaseFR *, int))
136  : cBack(theCB), dmLife(0), dpLife(0), lclStat(0), preSel(1),
137  dfsSys(0), Server(0), Fixed(0), Punt(0) {}
139 
140 private:
141 
142 struct dMoP {int Present;};
143 
144  int Bypass();
145  int FStat( char *Path, int fnPos, int upat=0);
146  int hasDir(char *Path, int fnPos);
147  void Queue(XrdCmsRRData &Arg, XrdCmsPInfo &Who,
148  int dln, int Frc=0);
149  void Xeq(XrdCmsBaseFR *rP);
150 
153  void (*cBack)(XrdCmsBaseFR *, int);
154 
155 struct RequestQ
163  int rLimit; // Maximum number of requests per second
164  int qHWM; // Queue high watermark
165  int qMax; // Maximum elements to be queued
166  int qNum; // Total number of queued elements (pq + rq)
167  int rLeft; // Number of non-queue requests allowed
168  int rAgain; // Value to reinitialize rLeft
170  pqFirst(0), pqLast(0), rqFirst(0), rqLast(0),
171  rLimit(0), qHWM(0), qMax(1), qNum(0),
172  rLeft(0), rAgain(0) {}
174  } theQ;
175 
176  int dmLife;
177  int dpLife;
178  char lclStat; // 1-> Local stat() calls wanted
179  char preSel; // 1-> Preselect before redirect
180  char dfsSys; // 1-> Distributed Filesystem
181  char Server; // 1-> This is a data server
182  char Fixed; // 1-> Use fixed rate processing
183  char Punt; // 1-> Pass through any forwarding
184 };
185 namespace XrdCms
186 {
187 extern XrdCmsBaseFS baseFS;
188 }
189 #endif