XRootD
XrdOfsHandle.hh
Go to the documentation of this file.
1 #ifndef __OFS_HANDLE__
2 #define __OFS_HANDLE__
3 /******************************************************************************/
4 /* */
5 /* X r d O f s H a n d l e . h h */
6 /* */
7 /* (c) 2003 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 /* These are private data structures. They are allocated dynamically to the
34  appropriate size (yes, that means dbx has a tough time).
35 */
36 
37 #include <cstdlib>
38 
39 #include "XrdOuc/XrdOucCRC.hh"
40 #include "XrdSys/XrdSysPthread.hh"
41 
42 /******************************************************************************/
43 /* C l a s s X r d O f s H a n K e y */
44 /******************************************************************************/
45 
47 {
48 public:
49 
50 const char *Val;
51 unsigned int Links;
52 unsigned int Hash;
53 short Len;
54 
55 inline XrdOfsHanKey& operator=(const XrdOfsHanKey &rhs)
56  {Val = strdup(rhs.Val); Hash = rhs.Hash;
57  Len = rhs.Len;
58  return *this;
59  }
60 
61 inline int operator==(const XrdOfsHanKey &oth)
62  {return Hash == oth.Hash && Len == oth.Len
63  && !strcmp(Val, oth.Val);
64  }
65 
66 inline int operator!=(const XrdOfsHanKey &oth)
67  {return Hash != oth.Hash || Len != oth.Len
68  || strcmp(Val, oth.Val);
69  }
70 
71  XrdOfsHanKey(const char *key=0, int kln=0)
72  : Val(key), Links(0), Len(kln)
73  {Hash = (key && kln ?
74  XrdOucCRC::CRC32((const unsigned char *)key,kln) : 0);
75  }
76 
77  XrdOfsHanKey(const XrdOfsHanKey&) = default;
78 
80 };
81 
82 /******************************************************************************/
83 /* C l a s s X r d O f s H a n T a b */
84 /******************************************************************************/
85 
86 class XrdOfsHandle;
87 
89 {
90 public:
91 void Add(XrdOfsHandle *hP);
92 
94 
95 int Remove(XrdOfsHandle *rip);
96 
97 // When allocateing a new nash, specify the required starting size. Make
98 // sure that the previous number is the correct Fibonocci antecedent. The
99 // series is simply n[j] = n[j-1] + n[j-2].
100 //
101  XrdOfsHanTab(int psize = 987, int size = 1597);
102  ~XrdOfsHanTab() {} // Never gets deleted
103 
104 private:
105 
106 static const int LoadMax = 80;
107 
108 void Expand();
109 
110 XrdOfsHandle **nashtable;
111 int prevtablesize;
112 int nashtablesize;
113 int nashnum;
114 int Threshold;
115 };
116 
117 /******************************************************************************/
118 /* C l a s s X r d O f s H a n d l e */
119 /******************************************************************************/
120 
121 class XrdOssDF;
122 class XrdOfsHanCB;
123 class XrdOfsHanPsc;
124 
126 {
127 friend class XrdOfsHanTab;
128 friend class XrdOfsHanXpr;
129 public:
130 
131 char isPending; // 1-> File is pending sync()
132 char isChanged; // 1-> File was modified
133 char isCompressed; // 1-> File is compressed
134 char isRW; // T-> File is open in r/w mode
135 
136 void Activate(XrdOssDF *ssP) {ssi = ssP;}
137 
138 static const int opRW = 1;
139 static const int opPC = 3;
140 
141 static int Alloc(const char *thePath,int Opts,XrdOfsHandle **Handle);
142 static int Alloc( XrdOfsHandle **Handle);
143 
144 static void Hide(const char *thePath);
145 
146 inline int Inactive() {return (ssi == ossDF);}
147 
148 inline const char *Name() {return Path.Val;}
149 
150  int PoscGet(short &Mode, int Done=0);
151 
152  int PoscSet(const char *User, int Unum, short Mode);
153 
154  const char *PoscUsr();
155 
156  int Retire(int &retc, long long *retsz=0,
157  char *buff=0, int blen=0);
158 
159  int Retire(XrdOfsHanCB *, int DSec);
160 
161 XrdOssDF &Select(void) {return *ssi;} // To allow for mt interfaces
162 
163 static int StartXpr(int Init=0); // Internal use only!
164 
165  void Suppress(int rrc=-EDOM, int wrc=-EDOM); // Only for R/W!
166 
167  int Usage() {return Path.Links;}
168 
169 inline void Lock() {hMutex.Lock();}
170 inline void UnLock() {hMutex.UnLock();}
171 
172  XrdOfsHandle() : Path(0,0) {}
173 
174  ~XrdOfsHandle() {int retc; Retire(retc);}
175 
176 private:
177 static int Alloc(XrdOfsHanKey, int Opts, XrdOfsHandle **Handle);
178  int WaitLock(void);
179 
180 static const int LockTries = 3; // Times to try for a lock
181 static const int LockWait = 333; // Mills to wait between tries
182 static const int nolokDelay= 3; // Secs to delay client when lock failed
183 static const int nomemDelay= 15; // Secs to delay client when ENOMEM
184 
185 static XrdSysMutex myMutex;
186 static XrdOfsHanTab roTable; // File handles open r/o
187 static XrdOfsHanTab rwTable; // File Handles open r/w
188 static XrdOssDF *ossDF; // Dummy storage sysem
189 static XrdOfsHandle *Free; // List of free handles
190 
191  XrdSysMutex hMutex;
192  XrdOssDF *ssi; // Storage System Interface
193  XrdOfsHandle *Next;
194  XrdOfsHanKey Path; // Path for this handle
195  XrdOfsHanPsc *Posc; // -> Info for posc-type files
196 };
197 
198 /******************************************************************************/
199 /* C l a s s X r d O f s H a n C B */
200 /******************************************************************************/
201 
203 {
204 public:
205 
206 virtual void Retired(XrdOfsHandle *) = 0;
207 
209 virtual ~XrdOfsHanCB() {}
210 };
211 #endif
int Mode
XrdOucString Path
virtual void Retired(XrdOfsHandle *)=0
virtual ~XrdOfsHanCB()
XrdOfsHanKey(const char *key=0, int kln=0)
Definition: XrdOfsHandle.hh:71
XrdOfsHanKey & operator=(const XrdOfsHanKey &rhs)
Definition: XrdOfsHandle.hh:55
unsigned int Links
Definition: XrdOfsHandle.hh:51
unsigned int Hash
Definition: XrdOfsHandle.hh:52
int operator==(const XrdOfsHanKey &oth)
Definition: XrdOfsHandle.hh:61
XrdOfsHanKey(const XrdOfsHanKey &)=default
const char * Val
Definition: XrdOfsHandle.hh:50
int operator!=(const XrdOfsHanKey &oth)
Definition: XrdOfsHandle.hh:66
XrdOfsHandle * Find(XrdOfsHanKey &Key)
XrdOfsHanTab(int psize=987, int size=1597)
int Remove(XrdOfsHandle *rip)
void Add(XrdOfsHandle *hP)
int Retire(int &retc, long long *retsz=0, char *buff=0, int blen=0)
static void Hide(const char *thePath)
void Activate(XrdOssDF *ssP)
int PoscSet(const char *User, int Unum, short Mode)
static const int opRW
int PoscGet(short &Mode, int Done=0)
static int StartXpr(int Init=0)
static const int opPC
const char * Name()
void Suppress(int rrc=-EDOM, int wrc=-EDOM)
static int Alloc(const char *thePath, int Opts, XrdOfsHandle **Handle)
const char * PoscUsr()
XrdOssDF & Select(void)
static uint32_t CRC32(const unsigned char *data, int count)
Definition: XrdOucCRC.cc:171
int Opts
Definition: XrdMpxStats.cc:58