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 ?
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
86class XrdOfsHandle;
87
89{
90public:
91void Add(XrdOfsHandle *hP);
92
94
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
104private:
105
106static const int LoadMax = 80;
107
108void Expand();
109
115};
116
117/******************************************************************************/
118/* C l a s s X r d O f s H a n d l e */
119/******************************************************************************/
120
121class XrdOssDF;
122class XrdOfsHanCB;
123class XrdOfsHanPsc;
124
126{
127friend class XrdOfsHanTab;
128friend class XrdOfsHanXpr;
129public:
130
131char isPending; // 1-> File is pending sync()
132char isChanged; // 1-> File was modified
133char isCompressed; // 1-> File is compressed
134char isRW; // T-> File is open in r/w mode
135
136void Activate(XrdOssDF *ssP) {ssi = ssP;}
137
138static const int opRW = 1;
139static const int opPC = 3;
140
141static int Alloc(const char *thePath,int Opts,XrdOfsHandle **Handle);
142static int Alloc( XrdOfsHandle **Handle);
143
144static void Hide(const char *thePath);
145
146inline int Inactive() {return (ssi == ossDF);}
147
148inline 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
161XrdOssDF &Select(void) {return *ssi;} // To allow for mt interfaces
162
163static 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
169inline void Lock() {hMutex.Lock();}
170inline void UnLock() {hMutex.UnLock();}
171
172 XrdOfsHandle() : Path(0,0) {}
173
174 ~XrdOfsHandle() {int retc; Retire(retc);}
175
176private:
177static int Alloc(XrdOfsHanKey, int Opts, XrdOfsHandle **Handle);
178 int WaitLock(void);
179
180static const int LockTries = 3; // Times to try for a lock
181static const int LockWait = 333; // Mills to wait between tries
182static const int nolokDelay= 3; // Secs to delay client when lock failed
183static const int nomemDelay= 15; // Secs to delay client when ENOMEM
184
186static XrdOfsHanTab roTable; // File handles open r/o
187static XrdOfsHanTab rwTable; // File Handles open r/w
188static XrdOssDF *ossDF; // Dummy storage sysem
189static XrdOfsHandle *Free; // List of free handles
190
192 XrdOssDF *ssi; // Storage System Interface
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{
204public:
205
206virtual void Retired(XrdOfsHandle *) = 0;
207
209virtual ~XrdOfsHanCB() {}
210};
211#endif
Definition XrdOfsHandle.hh:203
virtual void Retired(XrdOfsHandle *)=0
virtual ~XrdOfsHanCB()
Definition XrdOfsHandle.hh:209
XrdOfsHanCB()
Definition XrdOfsHandle.hh:208
Definition XrdOfsHandle.hh:47
XrdOfsHanKey(const char *key=0, int kln=0)
Definition XrdOfsHandle.hh:71
short Len
Definition XrdOfsHandle.hh:53
unsigned int Links
Definition XrdOfsHandle.hh:51
~XrdOfsHanKey()
Definition XrdOfsHandle.hh:79
XrdOfsHanKey & operator=(const XrdOfsHanKey &rhs)
Definition XrdOfsHandle.hh:55
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
Definition XrdOfsHandle.hh:89
XrdOfsHandle ** nashtable
Definition XrdOfsHandle.hh:110
~XrdOfsHanTab()
Definition XrdOfsHandle.hh:102
int prevtablesize
Definition XrdOfsHandle.hh:111
int Threshold
Definition XrdOfsHandle.hh:114
XrdOfsHandle * Find(XrdOfsHanKey &Key)
XrdOfsHanTab(int psize=987, int size=1597)
static const int LoadMax
Definition XrdOfsHandle.hh:106
int Remove(XrdOfsHandle *rip)
void Add(XrdOfsHandle *hP)
int nashtablesize
Definition XrdOfsHandle.hh:112
int nashnum
Definition XrdOfsHandle.hh:113
Definition XrdOfsHandle.hh:126
static const int nolokDelay
Definition XrdOfsHandle.hh:182
static XrdOfsHandle * Free
Definition XrdOfsHandle.hh:189
void Lock()
Definition XrdOfsHandle.hh:169
static XrdOssDF * ossDF
Definition XrdOfsHandle.hh:188
XrdOssDF * ssi
Definition XrdOfsHandle.hh:192
static void Hide(const char *thePath)
int Retire(int &retc, long long *retsz=0, char *buff=0, int blen=0)
char isPending
Definition XrdOfsHandle.hh:131
~XrdOfsHandle()
Definition XrdOfsHandle.hh:174
static const int nomemDelay
Definition XrdOfsHandle.hh:183
static int Alloc(XrdOfsHandle **Handle)
XrdOfsHanPsc * Posc
Definition XrdOfsHandle.hh:195
int Inactive()
Definition XrdOfsHandle.hh:146
static int StartXpr(int Init=0)
int Retire(XrdOfsHanCB *, int DSec)
void Activate(XrdOssDF *ssP)
Definition XrdOfsHandle.hh:136
static XrdOfsHanTab rwTable
Definition XrdOfsHandle.hh:187
XrdSysMutex hMutex
Definition XrdOfsHandle.hh:191
int PoscSet(const char *User, int Unum, short Mode)
static const int opRW
Definition XrdOfsHandle.hh:138
XrdOfsHandle * Next
Definition XrdOfsHandle.hh:193
static const int LockWait
Definition XrdOfsHandle.hh:181
static XrdOfsHanTab roTable
Definition XrdOfsHandle.hh:186
int WaitLock(void)
XrdOfsHandle()
Definition XrdOfsHandle.hh:172
int PoscGet(short &Mode, int Done=0)
static int Alloc(const char *thePath, int Opts, XrdOfsHandle **Handle)
static const int opPC
Definition XrdOfsHandle.hh:139
static const int LockTries
Definition XrdOfsHandle.hh:180
char isChanged
Definition XrdOfsHandle.hh:132
void Suppress(int rrc=-EDOM, int wrc=-EDOM)
void UnLock()
Definition XrdOfsHandle.hh:170
char isRW
Definition XrdOfsHandle.hh:134
static XrdSysMutex myMutex
Definition XrdOfsHandle.hh:185
friend class XrdOfsHanXpr
Definition XrdOfsHandle.hh:128
const char * PoscUsr()
XrdOfsHanKey Path
Definition XrdOfsHandle.hh:194
static int Alloc(XrdOfsHanKey, int Opts, XrdOfsHandle **Handle)
XrdOssDF & Select(void)
Definition XrdOfsHandle.hh:161
char isCompressed
Definition XrdOfsHandle.hh:133
int Usage()
Definition XrdOfsHandle.hh:167
const char * Name()
Definition XrdOfsHandle.hh:148
Definition XrdOss.hh:63
static uint32_t CRC32(const unsigned char *data, int count)
Definition XrdSysPthread.hh:165
void Lock()
Definition XrdSysPthread.hh:222
void UnLock()
Definition XrdSysPthread.hh:224