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 <stdlib.h>
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 Hash;
52 short Len;
53 unsigned short Links;
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), Len(kln), Links(0)
73  {Hash = (key && kln ?
74  XrdOucCRC::CRC32((const unsigned char *)key,kln) : 0);
75  }
76 
78 };
79 
80 /******************************************************************************/
81 /* C l a s s X r d O f s H a n T a b */
82 /******************************************************************************/
83 
84 class XrdOfsHandle;
85 
87 {
88 public:
89 void Add(XrdOfsHandle *hP);
90 
92 
93 int Remove(XrdOfsHandle *rip);
94 
95 // When allocateing a new nash, specify the required starting size. Make
96 // sure that the previous number is the correct Fibonocci antecedent. The
97 // series is simply n[j] = n[j-1] + n[j-2].
98 //
99  XrdOfsHanTab(int psize = 987, int size = 1597);
100  ~XrdOfsHanTab() {} // Never gets deleted
101 
102 private:
103 
104 static const int LoadMax = 80;
105 
106 void Expand();
107 
113 };
114 
115 /******************************************************************************/
116 /* C l a s s X r d O f s H a n d l e */
117 /******************************************************************************/
118 
119 class XrdOssDF;
120 class XrdOfsHanCB;
121 class XrdOfsHanPsc;
122 
124 {
125 friend class XrdOfsHanTab;
126 friend class XrdOfsHanXpr;
127 public:
128 
129 char isPending; // 1-> File is pending sync()
130 char isChanged; // 1-> File was modified
131 char isCompressed; // 1-> File is compressed
132 char isRW; // T-> File is open in r/w mode
133 
134 void Activate(XrdOssDF *ssP) {ssi = ssP;}
135 
136 static const int opRW = 1;
137 static const int opPC = 3;
138 
139 static int Alloc(const char *thePath,int Opts,XrdOfsHandle **Handle);
140 static int Alloc( XrdOfsHandle **Handle);
141 
142 static void Hide(const char *thePath);
143 
144 inline int Inactive() {return (ssi == ossDF);}
145 
146 inline const char *Name() {return Path.Val;}
147 
148  int PoscGet(short &Mode, int Done=0);
149 
150  int PoscSet(const char *User, int Unum, short Mode);
151 
152  const char *PoscUsr();
153 
154  int Retire(long long *retsz=0, char *buff=0, int blen=0);
155 
156  int Retire(XrdOfsHanCB *, int DSec);
157 
158 XrdOssDF &Select(void) {return *ssi;} // To allow for mt interfaces
159 
160 static int StartXpr(int Init=0); // Internal use only!
161 
162  int Usage() {return Path.Links;}
163 
164 inline void Lock() {hMutex.Lock();}
165 inline void UnLock() {hMutex.UnLock();}
166 
167  XrdOfsHandle() : Path(0,0) {}
168 
170 
171 private:
172 static int Alloc(XrdOfsHanKey, int Opts, XrdOfsHandle **Handle);
173  int WaitLock(void);
174 
175 static const int LockTries = 3; // Times to try for a lock
176 static const int LockWait = 333; // Mills to wait between tries
177 static const int nolokDelay= 3; // Secs to delay client when lock failed
178 static const int nomemDelay= 15; // Secs to delay client when ENOMEM
179 
181 static XrdOfsHanTab roTable; // File handles open r/o
182 static XrdOfsHanTab rwTable; // File Handles open r/w
183 static XrdOssDF *ossDF; // Dummy storage sysem
184 static XrdOfsHandle *Free; // List of free handles
185 
187  XrdOssDF *ssi; // Storage System Interface
189  XrdOfsHanKey Path; // Path for this handle
190  XrdOfsHanPsc *Posc; // -> Info for posc-type files
191 };
192 
193 /******************************************************************************/
194 /* C l a s s X r d O f s H a n C B */
195 /******************************************************************************/
196 
198 {
199 public:
200 
201 virtual void Retired(XrdOfsHandle *) = 0;
202 
204 virtual ~XrdOfsHanCB() {}
205 };
206 #endif