XRootD
Loading...
Searching...
No Matches
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"
41
42/******************************************************************************/
43/* C l a s s X r d O f s H a n K e y */
44/******************************************************************************/
45
47{
48public:
49
50const char *Val;
51unsigned int Links;
52unsigned int Hash;
53short Len;
54
56 {Val = strdup(rhs.Val); Hash = rhs.Hash;
57 Len = rhs.Len;
58 return *this;
59 }
60
61inline int operator==(const XrdOfsHanKey &oth)
62 {return Hash == oth.Hash && Len == oth.Len
63 && !strcmp(Val, oth.Val);
64 }
65
66inline 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
85class XrdOfsHandle;
86
88{
89public:
90void Add(XrdOfsHandle *hP);
91
93
94int 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
103private:
104
105static const int LoadMax = 80;
106
107void Expand();
108
109XrdOfsHandle **nashtable;
110int prevtablesize;
111int nashtablesize;
112int nashnum;
113int Threshold;
114};
115
116/******************************************************************************/
117/* C l a s s X r d O f s H a n d l e */
118/******************************************************************************/
119
120class XrdOssDF;
121class XrdOfsHanCB;
122class XrdOfsHanPsc;
123
125{
126friend class XrdOfsHanTab;
127friend class XrdOfsHanXpr;
128public:
129
130char isPending; // 1-> File is pending sync()
131char isChanged; // 1-> File was modified
132char isCompressed; // 1-> File is compressed
133char isRW; // T-> File is open in r/w mode
134
135void Activate(XrdOssDF *ssP) {ssi = ssP;}
136
137static const int opRW = 1;
138static const int opPC = 3;
139
140static int Alloc(const char *thePath,int Opts,XrdOfsHandle **Handle);
141static int Alloc( XrdOfsHandle **Handle);
142
143static void Hide(const char *thePath);
144
145inline int Inactive() {return (ssi == ossDF);}
146
147inline 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
160XrdOssDF &Select(void) {return *ssi;} // To allow for mt interfaces
161
162static 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
168inline void Lock() {hMutex.Lock();}
169inline void UnLock() {hMutex.UnLock();}
170
171 XrdOfsHandle() : Path(0,0) {}
172
173 ~XrdOfsHandle() {int retc; Retire(retc);}
174
175private:
176static int Alloc(XrdOfsHanKey, int Opts, XrdOfsHandle **Handle);
177 int WaitLock(void);
178
179static const int LockTries = 3; // Times to try for a lock
180static const int LockWait = 333; // Mills to wait between tries
181static const int nolokDelay= 3; // Secs to delay client when lock failed
182static const int nomemDelay= 15; // Secs to delay client when ENOMEM
183
184static XrdSysMutex myMutex;
185static XrdOfsHanTab roTable; // File handles open r/o
186static XrdOfsHanTab rwTable; // File Handles open r/w
187static XrdOssDF *ossDF; // Dummy storage sysem
188static 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{
203public:
204
205virtual void Retired(XrdOfsHandle *) = 0;
206
208virtual ~XrdOfsHanCB() {}
209};
210#endif
int Mode
XrdOucString Path
virtual void Retired(XrdOfsHandle *)=0
virtual ~XrdOfsHanCB()
XrdOfsHanKey(const char *key=0, int kln=0)
unsigned int Links
XrdOfsHanKey & operator=(const XrdOfsHanKey &rhs)
unsigned int Hash
int operator==(const XrdOfsHanKey &oth)
XrdOfsHanKey(const XrdOfsHanKey &)=default
const char * Val
int operator!=(const XrdOfsHanKey &oth)
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
friend class XrdOfsHanTab
void Suppress(int rrc=-EDOM, int wrc=-EDOM)
static int Alloc(const char *thePath, int Opts, XrdOfsHandle **Handle)
friend class XrdOfsHanXpr
const char * PoscUsr()
XrdOssDF & Select(void)
const char * Name()
static uint32_t Calc32C(const void *data, size_t count, uint32_t prevcs=0)
Definition XrdOucCRC.cc:190