|
xrootd
|
00001 #ifndef __CMS_BASEFS_H__ 00002 #define __CMS_BASEFS_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C m s B a s e F S . h h */ 00006 /* */ 00007 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <stdlib.h> 00034 #include <string.h> 00035 00036 #include "XrdCms/XrdCmsPList.hh" 00037 #include "XrdCms/XrdCmsRRData.hh" 00038 #include "XrdCms/XrdCmsTypes.hh" 00039 #include "XrdOuc/XrdOucHash.hh" 00040 #include "XrdSys/XrdSysPthread.hh" 00041 00042 /******************************************************************************/ 00043 /* C l a s s X r d C m s B a s e F R */ 00044 /******************************************************************************/ 00045 00046 class XrdCmsPInfo; 00047 00048 class XrdCmsBaseFR 00049 { 00050 public: 00051 00052 SMask_t Route; 00053 SMask_t RouteW; 00054 XrdCmsBaseFR *Next; 00055 char *Buff; 00056 char *Path; 00057 short PathLen; 00058 short PDirLen; 00059 kXR_unt32 Sid; 00060 kXR_char Mod; 00061 00062 XrdCmsBaseFR(XrdCmsRRData &Arg, XrdCmsPInfo &Who, int Dln) 00063 : Route(Who.rovec), RouteW(Who.rwvec), Next(0), 00064 PathLen(Arg.PathLen), PDirLen(Dln), 00065 Sid(Arg.Request.streamid), 00066 Mod(Arg.Request.modifier) 00067 {if (Arg.Buff) 00068 {Path=Arg.Path; Buff=Arg.Buff; Arg.Buff=0;} 00069 else Buff = Path = strdup(Arg.Path); 00070 } 00071 00072 XrdCmsBaseFR(XrdCmsRRData *aP, XrdCmsPInfo &Who, int Dln) 00073 : Route(Who.rovec), RouteW(Who.rwvec), 00074 Next(0), Buff(0), Path(aP->Path), 00075 PathLen(aP->PathLen), PDirLen(Dln), 00076 Sid(aP->Request.streamid), 00077 Mod(aP->Request.modifier) 00078 {} 00079 00080 ~XrdCmsBaseFR() {if (Buff) free(Buff); Buff = 0;} 00081 }; 00082 00083 /******************************************************************************/ 00084 /* C l a s s X r d C m s B a s e F S */ 00085 /******************************************************************************/ 00086 00087 class XrdCmsBaseFS 00088 { 00089 public: 00090 00091 // Exists() returns a tri-logic state: 00092 // CmsHaveRequest::Online -> File is known to exist and is available 00093 // CmsHaveRequest::Pending -> File is known to exist but is not available 00094 // 0 -> File state unknown, result will be provided later 00095 // -1 -> File is known not to exist 00096 // 00097 int Exists(XrdCmsRRData &Arg,XrdCmsPInfo &Who,int noLim=0); 00098 00099 // The following exists works as above but limits are never enforced and it 00100 // never returns 0. Additionally, the fnpos parameter works as follows: 00101 // 00102 // > 0 -> Offset into path to the last slash before the filename. 00103 // = 0 -> A valid offset has not been calculated nor should it be calculated. 00104 // < 0 -> A valid offset has not been calculated, fnpos = -(length of Path). 00105 00106 int Exists(char *Path, int fnPos, int UpAT=0); 00107 00108 // Valid Opts for Init() 00109 // 00110 static const int Cntrl = 0x0001; // Centralize stat() o/w distribute it 00111 static const int DFSys = 0x0002; // Distributed filesystem o/w jbods 00112 static const int Immed = 0x0004; // Redirect immediately o/w preselect 00113 static const int Servr = 0x0100; // This is a pure server node 00114 00115 void Init(int Opts, int DMlife, int DPLife); 00116 00117 inline int isDFS() {return dfsSys;} 00118 00119 inline int Limit() {return theQ.rLimit;} 00120 00121 void Limit(int rLim, int qMax); 00122 00123 inline int Local() {return lclStat;} 00124 00125 void Pacer(); 00126 00127 void Runner(); 00128 00129 void Start(); 00130 00131 inline int Trim() {return preSel;} 00132 00133 inline int Traverse() {return Punt;} 00134 00135 XrdCmsBaseFS(void (*theCB)(XrdCmsBaseFR *, int)) 00136 : cBack(theCB), dmLife(0), dpLife(0), lclStat(0), preSel(1), 00137 dfsSys(0), Server(0), Fixed(0), Punt(0) {} 00138 ~XrdCmsBaseFS() {} 00139 00140 private: 00141 00142 struct dMoP {int Present;}; 00143 00144 int Bypass(); 00145 int FStat( char *Path, int fnPos, int upat=0); 00146 int hasDir(char *Path, int fnPos); 00147 void Queue(XrdCmsRRData &Arg, XrdCmsPInfo &Who, 00148 int dln, int Frc=0); 00149 void Xeq(XrdCmsBaseFR *rP); 00150 00151 XrdSysMutex fsMutex; 00152 XrdOucHash<dMoP> fsDirMP; 00153 void (*cBack)(XrdCmsBaseFR *, int); 00154 00155 struct RequestQ 00156 {XrdSysMutex Mutex; 00157 XrdSysSemaphore pqAvail; 00158 XrdSysSemaphore rqAvail; 00159 XrdCmsBaseFR *pqFirst; 00160 XrdCmsBaseFR *pqLast; 00161 XrdCmsBaseFR *rqFirst; 00162 XrdCmsBaseFR *rqLast; 00163 int rLimit; // Maximum number of requests per second 00164 int qHWM; // Queue high watermark 00165 int qMax; // Maximum elements to be queued 00166 int qNum; // Total number of queued elements (pq + rq) 00167 int rLeft; // Number of non-queue requests allowed 00168 int rAgain; // Value to reinitialize rLeft 00169 RequestQ() : pqAvail(0), rqAvail(0), 00170 pqFirst(0), pqLast(0), rqFirst(0), rqLast(0), 00171 rLimit(0), qHWM(0), qMax(1), qNum(0), 00172 rLeft(0), rAgain(0) {} 00173 ~RequestQ() {} 00174 } theQ; 00175 00176 int dmLife; 00177 int dpLife; 00178 char lclStat; // 1-> Local stat() calls wanted 00179 char preSel; // 1-> Preselect before redirect 00180 char dfsSys; // 1-> Distributed Filesystem 00181 char Server; // 1-> This is a data server 00182 char Fixed; // 1-> Use fixed rate processing 00183 char Punt; // 1-> Pass through any forwarding 00184 }; 00185 namespace XrdCms 00186 { 00187 extern XrdCmsBaseFS baseFS; 00188 } 00189 #endif
1.7.6.1