00001 #ifndef __OFS_HANDLE__
00002 #define __OFS_HANDLE__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <stdlib.h>
00038
00039 #include "XrdOuc/XrdOucCRC.hh"
00040 #include "XrdSys/XrdSysPthread.hh"
00041
00042
00043
00044
00045
00046 class XrdOfsHanKey
00047 {
00048 public:
00049
00050 const char *Val;
00051 unsigned int Links;
00052 unsigned int Hash;
00053 short Len;
00054
00055 inline XrdOfsHanKey& operator=(const XrdOfsHanKey &rhs)
00056 {Val = strdup(rhs.Val); Hash = rhs.Hash;
00057 Len = rhs.Len;
00058 return *this;
00059 }
00060
00061 inline int operator==(const XrdOfsHanKey &oth)
00062 {return Hash == oth.Hash && Len == oth.Len
00063 && !strcmp(Val, oth.Val);
00064 }
00065
00066 inline int operator!=(const XrdOfsHanKey &oth)
00067 {return Hash != oth.Hash || Len != oth.Len
00068 || strcmp(Val, oth.Val);
00069 }
00070
00071 XrdOfsHanKey(const char *key=0, int kln=0)
00072 : Val(key), Links(0), Len(kln)
00073 {Hash = (key && kln ?
00074 XrdOucCRC::CRC32((const unsigned char *)key,kln) : 0);
00075 }
00076
00077 XrdOfsHanKey(const XrdOfsHanKey&) = default;
00078
00079 ~XrdOfsHanKey() {};
00080 };
00081
00082
00083
00084
00085
00086 class XrdOfsHandle;
00087
00088 class XrdOfsHanTab
00089 {
00090 public:
00091 void Add(XrdOfsHandle *hP);
00092
00093 XrdOfsHandle *Find(XrdOfsHanKey &Key);
00094
00095 int Remove(XrdOfsHandle *rip);
00096
00097
00098
00099
00100
00101 XrdOfsHanTab(int psize = 987, int size = 1597);
00102 ~XrdOfsHanTab() {}
00103
00104 private:
00105
00106 static const int LoadMax = 80;
00107
00108 void Expand();
00109
00110 XrdOfsHandle **nashtable;
00111 int prevtablesize;
00112 int nashtablesize;
00113 int nashnum;
00114 int Threshold;
00115 };
00116
00117
00118
00119
00120
00121 class XrdOssDF;
00122 class XrdOfsHanCB;
00123 class XrdOfsHanPsc;
00124
00125 class XrdOfsHandle
00126 {
00127 friend class XrdOfsHanTab;
00128 friend class XrdOfsHanXpr;
00129 public:
00130
00131 char isPending;
00132 char isChanged;
00133 char isCompressed;
00134 char isRW;
00135
00136 void Activate(XrdOssDF *ssP) {ssi = ssP;}
00137
00138 static const int opRW = 1;
00139 static const int opPC = 3;
00140
00141 static int Alloc(const char *thePath,int Opts,XrdOfsHandle **Handle);
00142 static int Alloc( XrdOfsHandle **Handle);
00143
00144 static void Hide(const char *thePath);
00145
00146 inline int Inactive() {return (ssi == ossDF);}
00147
00148 inline const char *Name() {return Path.Val;}
00149
00150 int PoscGet(short &Mode, int Done=0);
00151
00152 int PoscSet(const char *User, int Unum, short Mode);
00153
00154 const char *PoscUsr();
00155
00156 int Retire(int &retc, long long *retsz=0,
00157 char *buff=0, int blen=0);
00158
00159 int Retire(XrdOfsHanCB *, int DSec);
00160
00161 XrdOssDF &Select(void) {return *ssi;}
00162
00163 static int StartXpr(int Init=0);
00164
00165 int Usage() {return Path.Links;}
00166
00167 inline void Lock() {hMutex.Lock();}
00168 inline void UnLock() {hMutex.UnLock();}
00169
00170 XrdOfsHandle() : Path(0,0) {}
00171
00172 ~XrdOfsHandle() {int retc; Retire(retc);}
00173
00174 private:
00175 static int Alloc(XrdOfsHanKey, int Opts, XrdOfsHandle **Handle);
00176 int WaitLock(void);
00177
00178 static const int LockTries = 3;
00179 static const int LockWait = 333;
00180 static const int nolokDelay= 3;
00181 static const int nomemDelay= 15;
00182
00183 static XrdSysMutex myMutex;
00184 static XrdOfsHanTab roTable;
00185 static XrdOfsHanTab rwTable;
00186 static XrdOssDF *ossDF;
00187 static XrdOfsHandle *Free;
00188
00189 XrdSysMutex hMutex;
00190 XrdOssDF *ssi;
00191 XrdOfsHandle *Next;
00192 XrdOfsHanKey Path;
00193 XrdOfsHanPsc *Posc;
00194 };
00195
00196
00197
00198
00199
00200 class XrdOfsHanCB
00201 {
00202 public:
00203
00204 virtual void Retired(XrdOfsHandle *) = 0;
00205
00206 XrdOfsHanCB() {}
00207 virtual ~XrdOfsHanCB() {}
00208 };
00209 #endif