xrootd
Loading...
Searching...
No Matches
XrdXrootdFile.hh
Go to the documentation of this file.
1#ifndef _XROOTD_FILE_H_
2#define _XROOTD_FILE_H_
3/******************************************************************************/
4/* */
5/* X r d X r o o t d F i l e . h h */
6/* */
7/* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* Produced by Andrew Hanushevsky for Stanford University under contract */
9/* DE-AC02-76-SFO0515 with the Department of Energy */
10/* */
11/* This file is part of the XRootD software suite. */
12/* */
13/* XRootD is free software: you can redistribute it and/or modify it under */
14/* the terms of the GNU Lesser General Public License as published by the */
15/* Free Software Foundation, either version 3 of the License, or (at your */
16/* option) any later version. */
17/* */
18/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21/* License for more details. */
22/* */
23/* You should have received a copy of the GNU Lesser General Public License */
24/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26/* */
27/* The copyright holder's institutional names and contributor's names may not */
28/* be used to endorse or promote products derived from this software without */
29/* specific prior written permission of the institution or contributor. */
30/******************************************************************************/
31
32#include <cstring>
33#include <set>
34#include <vector>
35
36#include "XProtocol/XPtypes.hh"
39
40/******************************************************************************/
41/* X r d X r o o t d F i l e H P */
42/******************************************************************************/
43
45{
46public:
47
48void Avail(int fHandle) {fhMutex.Lock();
49 bool done = (1 == refs--);
50 if (noMore)
51 {fhMutex.UnLock();
52 if (done) delete this;
53 } else {
54 fhAvail.push_back(fHandle);
56 }
57 }
58
60 if (!refs) {fhMutex.UnLock(); delete this;}
61 else {noMore = true; fhMutex.UnLock();}
62 }
63
64int Get() {int fh;
65 fhMutex.Lock();
66 if (fhAvail.empty()) fh = -1;
67 else {fh = fhAvail.back();
68 fhAvail.pop_back();
69 }
71 return fh;
72 }
73
74void Ref() {fhMutex.Lock(); refs++; fhMutex.UnLock();}
75
76 XrdXrootdFileHP(int rsv=2) : refs(1), noMore(false)
77 {fhAvail.reserve(rsv);}
78
79private:
80
82
84std::vector<int> fhAvail;
85int refs;
86bool noMore;
87};
88
89
90/******************************************************************************/
91/* X r d X r o o t d F i l e */
92/******************************************************************************/
93
94class XrdSfsFile;
96class XrdXrootdAioFob;
98class XrdXrootdPgwFob;
99
101{
102public:
103
104XrdSfsFile *XrdSfsp; // -> Actual file object
105union {char *mmAddr; // Memory mapped location, if any
106 unsigned
107 long long cbArg; // Callback argument upon close()
108 };
109char *FileKey; // -> File hash name (actual file name now)
110char FileMode; // 'r' or 'w'
111bool AsyncMode; // 1 -> if file in async r/w mode
112bool isMMapped; // 1 -> file is memory mapped
113bool sfEnabled; // 1 -> file is sendfile enabled
114union {int fdNum; // File descriptor number if regular file
115 int fHandle; // The file handle upon close()
116 };
117XrdXrootdAioFob *aioFob; // Aio freight pointer for reads
118XrdXrootdPgwFob *pgwFob; // Pgw freight pointer for writes
119XrdXrootdFileHP *fhProc; // File handle processor (set at close time)
120const char *ID; // File user
121
122XrdXrootdFileStats Stats; // File access statistics
123
124static void Init(XrdXrootdFileLock *lp, XrdSysError *erP, bool sfok);
125
126 void Ref(int num);
127
128 void Serialize();
129
130 XrdXrootdFile(const char *id, const char *path, XrdSfsFile *fp,
131 char mode='r', bool async=false, struct stat *sP=0);
133
134private:
135int bin2hex(char *outbuff, char *inbuff, int inlen);
137static int sfOK;
138static const char *TraceID;
139
140int refCount; // Reference counter
144};
145
146/******************************************************************************/
147/* X r d X r o o t d F i l e T a b l e */
148/******************************************************************************/
149
150// The before define the structure of the file table. We will have FTABSIZE
151// internal table entries. We will then provide an external linear table
152// that increases by FTABSIZE entries. There is one file table per link and
153// it is owned by the base protocol object.
154//
155#define XRD_FTABSIZE 16
156
157// WARNING! Manipulation (i.e., Add/Del/delete) of this object must be
158// externally serialized at the link level. Only one thread
159// may be active w.r.t this object during manipulation!
160//
162{
163public:
164
166
167 XrdXrootdFile *Del(XrdXrootdMonitor *monP, int fnum, bool dodel=true);
168
169inline XrdXrootdFile *Get(int fnum)
170 {if (fnum >= 0)
171 {if (fnum < XRD_FTABSIZE)
172 {if (FTab[fnum] != heldSpotP) return FTab[fnum];
173 } else {
174 if (XTab)
175 {int i = fnum - XRD_FTABSIZE;
176 if (i < XTnum && XTab[i] != heldSpotP)
177 return XTab[i];
178 }
179 }
180 }
181 return (XrdXrootdFile *)0;
182 }
183
185
186 XrdXrootdFileTable(unsigned int mid=0) : fhProc(0), FTfree(0), monID(mid),
187 XTab(0), XTnum(0), XTfree(0)
188 {memset((void *)FTab, 0, sizeof(FTab));}
189
191
192private:
193
194 ~XrdXrootdFileTable() {} // Always use Recycle() to delete this object!
195
196static const char *TraceID;
197static const char *ID;
199
202unsigned int monID;
203
207};
208#endif
#define stat(a, b)
Definition XrdPosix.hh:96
#define XRD_FTABSIZE
Definition XrdXrootdFile.hh:155
Definition XrdSfsInterface.hh:369
Definition XrdSysError.hh:90
Definition XrdSysPthread.hh:165
void Lock()
Definition XrdSysPthread.hh:222
void UnLock()
Definition XrdSysPthread.hh:224
Definition XrdSysPthread.hh:494
Definition XrdXrootdAioFob.hh:38
Definition XrdXrootdFile.hh:45
int Get()
Definition XrdXrootdFile.hh:64
void Avail(int fHandle)
Definition XrdXrootdFile.hh:48
void Delete()
Definition XrdXrootdFile.hh:59
~XrdXrootdFileHP()
Definition XrdXrootdFile.hh:81
int refs
Definition XrdXrootdFile.hh:85
XrdSysMutex fhMutex
Definition XrdXrootdFile.hh:83
void Ref()
Definition XrdXrootdFile.hh:74
XrdXrootdFileHP(int rsv=2)
Definition XrdXrootdFile.hh:76
std::vector< int > fhAvail
Definition XrdXrootdFile.hh:84
bool noMore
Definition XrdXrootdFile.hh:86
Definition XrdXrootdFileLock.hh:33
Definition XrdXrootdFileStats.hh:36
Definition XrdXrootdFile.hh:162
int XTnum
Definition XrdXrootdFile.hh:205
static XrdXrootdFile * heldSpotP
Definition XrdXrootdFile.hh:190
void Recycle(XrdXrootdMonitor *monP)
int XTfree
Definition XrdXrootdFile.hh:206
XrdXrootdFile * FTab[XRD_FTABSIZE]
Definition XrdXrootdFile.hh:200
XrdXrootdFileTable(unsigned int mid=0)
Definition XrdXrootdFile.hh:186
int Add(XrdXrootdFile *fp)
XrdXrootdFileHP * fhProc
Definition XrdXrootdFile.hh:198
unsigned int monID
Definition XrdXrootdFile.hh:202
int FTfree
Definition XrdXrootdFile.hh:201
~XrdXrootdFileTable()
Definition XrdXrootdFile.hh:194
XrdXrootdFile ** XTab
Definition XrdXrootdFile.hh:204
static const char * TraceID
Definition XrdXrootdFile.hh:196
static const char * ID
Definition XrdXrootdFile.hh:197
XrdXrootdFile * Get(int fnum)
Definition XrdXrootdFile.hh:169
XrdXrootdFile * Del(XrdXrootdMonitor *monP, int fnum, bool dodel=true)
Definition XrdXrootdFile.hh:101
const char * ID
Definition XrdXrootdFile.hh:120
XrdSysSemaphore * syncWait
Definition XrdXrootdFile.hh:142
static const char * TraceID
Definition XrdXrootdFile.hh:138
int reserved
Definition XrdXrootdFile.hh:141
bool isMMapped
Definition XrdXrootdFile.hh:112
XrdXrootdFileHP * fhProc
Definition XrdXrootdFile.hh:119
bool sfEnabled
Definition XrdXrootdFile.hh:113
int fdNum
Definition XrdXrootdFile.hh:114
XrdXrootdFile(const char *id, const char *path, XrdSfsFile *fp, char mode='r', bool async=false, struct stat *sP=0)
static XrdXrootdFileLock * Locker
Definition XrdXrootdFile.hh:136
int bin2hex(char *outbuff, char *inbuff, int inlen)
static int sfOK
Definition XrdXrootdFile.hh:137
void Ref(int num)
int fHandle
Definition XrdXrootdFile.hh:115
XrdXrootdPgwFob * pgwFob
Definition XrdXrootdFile.hh:118
void Serialize()
static void Init(XrdXrootdFileLock *lp, XrdSysError *erP, bool sfok)
bool AsyncMode
Definition XrdXrootdFile.hh:111
XrdSfsFile * XrdSfsp
Definition XrdXrootdFile.hh:104
char * FileKey
Definition XrdXrootdFile.hh:109
char FileMode
Definition XrdXrootdFile.hh:110
XrdXrootdAioFob * aioFob
Definition XrdXrootdFile.hh:117
XrdSysMutex fileMutex
Definition XrdXrootdFile.hh:143
int refCount
Definition XrdXrootdFile.hh:140
XrdXrootdFileStats Stats
Definition XrdXrootdFile.hh:122
char * mmAddr
Definition XrdXrootdFile.hh:105
unsigned long long cbArg
Definition XrdXrootdFile.hh:107
Definition XrdXrootdMonitor.hh:78
Definition XrdXrootdPgwFob.hh:42