xrootd

XrdCmsBaseFS.hh

Go to the documentation of this file.
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 
00013 #include <stdlib.h>
00014 #include <string.h>
00015 
00016 #include "XrdCms/XrdCmsPList.hh"
00017 #include "XrdCms/XrdCmsRRData.hh"
00018 #include "XrdCms/XrdCmsTypes.hh"
00019 #include "XrdOuc/XrdOucHash.hh"
00020 #include "XrdSys/XrdSysPthread.hh"
00021 
00022 /******************************************************************************/
00023 /*                    C l a s s   X r d C m s B a s e F R                     */
00024 /******************************************************************************/
00025 
00026 class XrdCmsPInfo;
00027 
00028 class XrdCmsBaseFR
00029 {
00030 public:
00031 
00032 SMask_t          Route;
00033 SMask_t          RouteW;
00034 XrdCmsBaseFR    *Next;
00035 char            *Buff;
00036 char            *Path;
00037 short            PathLen;
00038 short            PDirLen;
00039 kXR_unt32        Sid;
00040 kXR_char         Mod;
00041 
00042                  XrdCmsBaseFR(XrdCmsRRData &Arg, XrdCmsPInfo &Who, int Dln)
00043                              : Route(Who.rovec), RouteW(Who.rwvec), Next(0),
00044                                PathLen(Arg.PathLen), PDirLen(Dln),
00045                                Sid(Arg.Request.streamid),
00046                                Mod(Arg.Request.modifier)
00047                              {if (Arg.Buff)
00048                                  {Path=Arg.Path; Buff=Arg.Buff; Arg.Buff=0;}
00049                                  else Buff = Path = strdup(Arg.Path);
00050                              }
00051 
00052                  XrdCmsBaseFR(XrdCmsRRData *aP,  XrdCmsPInfo &Who, int Dln)
00053                              : Route(Who.rovec), RouteW(Who.rwvec),
00054                                Next(0), Buff(0), Path(aP->Path),
00055                                PathLen(aP->PathLen), PDirLen(Dln),
00056                                Sid(aP->Request.streamid),
00057                                Mod(aP->Request.modifier)
00058                              {}
00059 
00060                ~XrdCmsBaseFR() {if (Buff) free(Buff); Buff = 0;}
00061 };
00062   
00063 /******************************************************************************/
00064 /*                    C l a s s   X r d C m s B a s e F S                     */
00065 /******************************************************************************/
00066 
00067 class XrdCmsBaseFS
00068 {
00069 public:
00070 
00071 // Exists() returns a tri-logic state:
00072 // CmsHaveRequest::Online  -> File is known to exist and is available
00073 // CmsHaveRequest::Pending -> File is known to exist but is not available
00074 //  0                      -> File state unknown, result will be provided later
00075 // -1                      -> File is known not to exist
00076 //
00077        int              Exists(XrdCmsRRData &Arg,XrdCmsPInfo &Who,int noLim=0);
00078 
00079 // The following exists works as above but limits are never enforced and it
00080 // never returns 0. Additionally, the fnpos parameter works as follows:
00081 //
00082 // > 0 -> Offset into path to the last slash before the filename.
00083 // = 0 -> A valid offset has not been calculated nor should it be calculated.
00084 // < 0 -> A valid offset has not been calculated, fnpos = -(length of Path).
00085 
00086        int              Exists(char *Path, int fnPos, int UpAT=0);
00087 
00088 // Valid Opts for Init()
00089 //
00090 static const int        Cntrl  = 0x0001; // Centralize stat() o/w distribute it
00091 static const int        DFSys  = 0x0002; // Distributed filesystem o/w jbods
00092 static const int        Immed  = 0x0004; // Redirect immediately o/w preselect
00093 static const int        Servr  = 0x0100; // This is a pure server node
00094 
00095        void             Init(int Opts, int DMlife, int DPLife);
00096 
00097 inline int              isDFS() {return dfsSys;}
00098 
00099 inline int              Limit() {return theQ.rLimit;}
00100 
00101        void             Limit(int rLim, int qMax);
00102 
00103 inline int              Local() {return lclStat;}
00104 
00105        void             Pacer();
00106 
00107        void             Runner();
00108 
00109        void             Start();
00110 
00111 inline int              Trim() {return preSel;}
00112 
00113 inline int              Traverse() {return Punt;}
00114 
00115        XrdCmsBaseFS(void (*theCB)(XrdCmsBaseFR *, int))
00116                    : cBack(theCB), dmLife(0), dpLife(0), lclStat(0), preSel(1),
00117                      dfsSys(0), Server(0), Fixed(0), Punt(0) {}
00118       ~XrdCmsBaseFS() {}
00119 
00120 private:
00121 
00122 struct dMoP {int        Present;};
00123 
00124        int              Bypass();
00125        int              FStat( char *Path, int fnPos, int upat=0);
00126        int              hasDir(char *Path, int fnPos);
00127        void             Queue(XrdCmsRRData &Arg, XrdCmsPInfo &Who,
00128                               int dln, int Frc=0);
00129        void             Xeq(XrdCmsBaseFR *rP);
00130 
00131        XrdSysMutex      fsMutex;
00132        XrdOucHash<dMoP> fsDirMP;
00133        void             (*cBack)(XrdCmsBaseFR *, int);
00134 
00135 struct RequestQ
00136       {XrdSysMutex      Mutex;
00137        XrdSysSemaphore  pqAvail;
00138        XrdSysSemaphore  rqAvail;
00139        XrdCmsBaseFR    *pqFirst;
00140        XrdCmsBaseFR    *pqLast;
00141        XrdCmsBaseFR    *rqFirst;
00142        XrdCmsBaseFR    *rqLast;
00143        int              rLimit;   // Maximum number of requests per second
00144        int              qHWM;     // Queue high watermark
00145        int              qMax;     // Maximum elements to be queued
00146        int              qNum;     // Total number of queued elements (pq + rq)
00147        int              rLeft;    // Number of non-queue requests allowed
00148        int              rAgain;   // Value to reinitialize rLeft
00149        RequestQ() : pqAvail(0), rqAvail(0),
00150                     pqFirst(0), pqLast(0), rqFirst(0), rqLast(0),
00151                     rLimit(0),  qHWM(0),   qMax(1),    qNum(0),
00152                     rLeft(0),   rAgain(0)  {}
00153       ~RequestQ() {}
00154       }                 theQ;
00155 
00156        int              dmLife;
00157        int              dpLife;
00158        char             lclStat;  // 1-> Local stat() calls wanted
00159        char             preSel;   // 1-> Preselect before redirect
00160        char             dfsSys;   // 1-> Distributed Filesystem
00161        char             Server;   // 1-> This is a data server
00162        char             Fixed;    // 1-> Use fixed rate processing
00163        char             Punt;     // 1-> Pass through any forwarding
00164 };
00165 namespace XrdCms
00166 {
00167 extern XrdCmsBaseFS baseFS;
00168 }
00169 #endif