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  int dfsTries() {return dfsMaxTries;}
92 
93 // Exists() returns a tri-logic state:
94 // CmsHaveRequest::Online -> File is known to exist and is available
95 // CmsHaveRequest::Pending -> File is known to exist but is not available
96 // 0 -> File state unknown, result will be provided later
97 // -1 -> File is known not to exist
98 //
99  int Exists(XrdCmsRRData &Arg,XrdCmsPInfo &Who,int noLim=0);
100 
101 // The following exists works as above but limits are never enforced and it
102 // never returns 0. Additionally, the fnpos parameter works as follows:
103 //
104 // > 0 -> Offset into path to the last slash before the filename.
105 // = 0 -> A valid offset has not been calculated nor should it be calculated.
106 // < 0 -> A valid offset has not been calculated, fnpos = -(length of Path).
107 
108  int Exists(char *Path, int fnPos, int UpAT=0);
109 
110 // Valid Opts for Init()
111 //
112 static const int Cntrl = 0x0001; // Centralize stat() o/w distribute it
113 static const int DFSys = 0x0002; // Distributed filesystem o/w jbods
114 static const int Immed = 0x0004; // Redirect immediately o/w preselect
115 static const int Servr = 0x0100; // This is a pure server node
116 
117  void Init(int Opts, int DMlife, int DPLife);
118 
119 inline int isDFS() {return dfsSys;}
120 
121 inline int Limit() {return theQ.rLimit;}
122 
123  void Limit(int rLim, int qMax);
124 
125 inline int Local() {return lclStat;}
126 
127  void Pacer();
128 
129  void Runner();
130 
131 static const int dfltDfsTries = 2;
132 static const int dfltStgTries = 3;
133 
134  void SetTries(bool xdfs, int tcnt)
135  {if (xdfs) dfsMaxTries =
136  (tcnt < 0 ? dfltDfsTries : tcnt);
137  else stgMaxTries =
138  (tcnt < 1 ? dfltStgTries : tcnt);
139  }
140 
141  void Start();
142 
143  int stgTries() {return stgMaxTries;}
144 
145 inline int Trim() {return preSel;}
146 
147 inline int Traverse() {return Punt;}
148 
149  XrdCmsBaseFS(void (*theCB)(XrdCmsBaseFR *, int))
150  : cBack(theCB), dfsMaxTries(dfltDfsTries),
152  dmLife(0), dpLife(0), lclStat(0), preSel(1),
153  dfsSys(0), Server(0), Fixed(0), Punt(0) {}
155 
156 private:
157 
158 struct dMoP {int Present;};
159 
160  int Bypass();
161  int FStat( char *Path, int fnPos, int upat=0);
162  int hasDir(char *Path, int fnPos);
163  void Queue(XrdCmsRRData &Arg, XrdCmsPInfo &Who,
164  int dln, int Frc=0);
165  void Xeq(XrdCmsBaseFR *rP);
166 
169  void (*cBack)(XrdCmsBaseFR *, int);
170 
171 struct RequestQ
179  int rLimit; // Maximum number of requests per second
180  int qHWM; // Queue high watermark
181  int qMax; // Maximum elements to be queued
182  int qNum; // Total number of queued elements (pq + rq)
183  int rLeft; // Number of non-queue requests allowed
184  int rAgain; // Value to reinitialize rLeft
186  pqFirst(0), pqLast(0), rqFirst(0), rqLast(0),
187  rLimit(0), qHWM(0), qMax(1), qNum(0),
188  rLeft(0), rAgain(0) {}
190  } theQ;
191 
194  int dmLife;
195  int dpLife;
196  char lclStat; // 1-> Local stat() calls wanted
197  char preSel; // 1-> Preselect before redirect
198  char dfsSys; // 1-> Distributed Filesystem
199  char Server; // 1-> This is a data server
200  char Fixed; // 1-> Use fixed rate processing
201  char Punt; // 1-> Pass through any forwarding
202 };
203 namespace XrdCms
204 {
205 extern XrdCmsBaseFS baseFS;
206 }
207 #endif
unsigned char kXR_char
Definition: XPtypes.hh:65
int rLimit
Definition: XrdCmsBaseFS.hh:179
kXR_char Mod
Definition: XrdCmsBaseFS.hh:60
Definition: YProtocol.hh:77
static const int dfltStgTries
Definition: XrdCmsBaseFS.hh:132
XrdSysMutex Mutex
Definition: XrdCmsBaseFS.hh:172
int hasDir(char *Path, int fnPos)
int qMax
Definition: XrdCmsBaseFS.hh:181
~XrdCmsBaseFS()
Definition: XrdCmsBaseFS.hh:154
char Punt
Definition: XrdCmsBaseFS.hh:201
static const int dfltDfsTries
Definition: XrdCmsBaseFS.hh:131
static const int Immed
Definition: XrdCmsBaseFS.hh:114
char * Path
Definition: XrdCmsRRData.hh:55
~XrdCmsBaseFR()
Definition: XrdCmsBaseFS.hh:80
int rAgain
Definition: XrdCmsBaseFS.hh:184
void Init(int Opts, int DMlife, int DPLife)
int dfsMaxTries
Definition: XrdCmsBaseFS.hh:192
void Queue(XrdCmsRRData &Arg, XrdCmsPInfo &Who, int dln, int Frc=0)
char lclStat
Definition: XrdCmsBaseFS.hh:196
char dfsSys
Definition: XrdCmsBaseFS.hh:198
~RequestQ()
Definition: XrdCmsBaseFS.hh:189
char preSel
Definition: XrdCmsBaseFS.hh:197
XrdCmsBaseFS baseFS
int qNum
Definition: XrdCmsBaseFS.hh:182
XrdOucHash< dMoP > fsDirMP
Definition: XrdCmsBaseFS.hh:168
int qHWM
Definition: XrdCmsBaseFS.hh:180
XrdCmsBaseFR * rqFirst
Definition: XrdCmsBaseFS.hh:177
void SetTries(bool xdfs, int tcnt)
Definition: XrdCmsBaseFS.hh:134
void(* cBack)(XrdCmsBaseFR *, int)
Definition: XrdCmsBaseFS.hh:169
static const int DFSys
Definition: XrdCmsBaseFS.hh:113
int Exists(XrdCmsRRData &Arg, XrdCmsPInfo &Who, int noLim=0)
Definition: XrdCmsBaseFS.hh:48
char * Buff
Definition: XrdCmsRRData.hh:71
short PathLen
Definition: XrdCmsBaseFS.hh:57
int Present
Definition: XrdCmsBaseFS.hh:158
XrdSysMutex fsMutex
Definition: XrdCmsBaseFS.hh:167
Definition: XrdSysPthread.hh:165
int dmLife
Definition: XrdCmsBaseFS.hh:194
char Fixed
Definition: XrdCmsBaseFS.hh:200
int dfsTries()
Definition: XrdCmsBaseFS.hh:91
void Xeq(XrdCmsBaseFR *rP)
XrdCmsBaseFR(XrdCmsRRData *aP, XrdCmsPInfo &Who, int Dln)
Definition: XrdCmsBaseFS.hh:72
XrdCmsBaseFR(XrdCmsRRData &Arg, XrdCmsPInfo &Who, int Dln)
Definition: XrdCmsBaseFS.hh:62
int dpLife
Definition: XrdCmsBaseFS.hh:195
Definition: XrdCmsRRData.hh:51
XrdCmsBaseFR * Next
Definition: XrdCmsBaseFS.hh:54
Definition: XrdSysPthread.hh:405
Definition: XrdCmsBaseFS.hh:87
int isDFS()
Definition: XrdCmsBaseFS.hh:119
unsigned long long SMask_t
Definition: XrdCmsTypes.hh:33
Definition: XrdCmsPList.hh:44
int Traverse()
Definition: XrdCmsBaseFS.hh:147
XrdCmsBaseFR * rqLast
Definition: XrdCmsBaseFS.hh:178
XrdSysSemaphore rqAvail
Definition: XrdCmsBaseFS.hh:174
int stgTries()
Definition: XrdCmsBaseFS.hh:143
Definition: XrdCmsBaseFS.hh:158
unsigned int kXR_unt32
Definition: XPtypes.hh:90
int Trim()
Definition: XrdCmsBaseFS.hh:145
kXR_unt32 Sid
Definition: XrdCmsBaseFS.hh:59
XrdSysSemaphore pqAvail
Definition: XrdCmsBaseFS.hh:173
XrdCmsBaseFR * pqFirst
Definition: XrdCmsBaseFS.hh:175
int stgMaxTries
Definition: XrdCmsBaseFS.hh:193
int FStat(char *Path, int fnPos, int upat=0)
XrdCmsBaseFS(void(*theCB)(XrdCmsBaseFR *, int))
Definition: XrdCmsBaseFS.hh:149
int Local()
Definition: XrdCmsBaseFS.hh:125
static const int Cntrl
Definition: XrdCmsBaseFS.hh:112
RequestQ()
Definition: XrdCmsBaseFS.hh:185
static const int Servr
Definition: XrdCmsBaseFS.hh:115
Definition: XrdCmsBaseFS.hh:171
Definition: XrdOucHash.hh:127
struct XrdCmsBaseFS::RequestQ theQ
int rLeft
Definition: XrdCmsBaseFS.hh:183
XrdCmsBaseFR * pqLast
Definition: XrdCmsBaseFS.hh:176
char * Buff
Definition: XrdCmsBaseFS.hh:55
short PDirLen
Definition: XrdCmsBaseFS.hh:58
int Limit()
Definition: XrdCmsBaseFS.hh:121
SMask_t RouteW
Definition: XrdCmsBaseFS.hh:53
char Server
Definition: XrdCmsBaseFS.hh:199
char * Path
Definition: XrdCmsBaseFS.hh:56
SMask_t Route
Definition: XrdCmsBaseFS.hh:52