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