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