XRootD
Loading...
Searching...
No Matches
XrdPosixObject Class Reference

#include <XrdPosixObject.hh>

+ Inheritance diagram for XrdPosixObject:
+ Collaboration diagram for XrdPosixObject:

Public Member Functions

 XrdPosixObject ()
 
virtual ~XrdPosixObject ()
 
bool AssignFD (bool isStream=false)
 
int FDNum ()
 
XrdOucECMsggetECMsg ()
 
void Lock (bool wr=true)
 
void Ref ()
 
int Refs ()
 
void UnLock ()
 
void unRef ()
 
virtual bool Who (XrdPosixDir **dirP)
 
virtual bool Who (XrdPosixFile **fileP)
 

Static Public Member Functions

static bool CanStream ()
 
static XrdPosixDirDir (int fildes, bool glk=false)
 
static XrdPosixFileFile (int fildes, bool glk=false)
 
static int Init (int numfd)
 
static void Release (XrdPosixObject *oP, bool needlk=true)
 
static XrdPosixDirReleaseDir (int fildes)
 
static XrdPosixFileReleaseFile (int fildes)
 
static void Shutdown ()
 
static bool Valid (int fd)
 

Public Attributes

XrdOucECMsg ecMsg
 

Protected Attributes

int fdNum
 
XrdSysRWLock objMutex
 
int refCnt
 
XrdSysRecMutex updMutex
 

Detailed Description

Definition at line 42 of file XrdPosixObject.hh.

Constructor & Destructor Documentation

◆ XrdPosixObject()

XrdPosixObject::XrdPosixObject ( )
inline

Definition at line 93 of file XrdPosixObject.hh.

93: ecMsg("[posix]"),fdNum(-1),refCnt(0) {}
XrdOucECMsg ecMsg

◆ ~XrdPosixObject()

virtual XrdPosixObject::~XrdPosixObject ( )
inlinevirtual

Definition at line 94 of file XrdPosixObject.hh.

94{if (fdNum >= 0) Release(this);}
static void Release(XrdPosixObject *oP, bool needlk=true)

References fdNum, and Release().

+ Here is the call graph for this function:

Member Function Documentation

◆ AssignFD()

bool XrdPosixObject::AssignFD ( bool  isStream = false)

Definition at line 67 of file XrdPosixObject.cc.

68{
69 XrdSysMutexHelper fdHelper(fdMutex);
70 int fd;
71
72// Obtain a new filedscriptor from the system. Use the fd to track the object.
73// Streams are not supported for virtual file descriptors.
74//
75 if (baseFD)
76 { if (isStream) return 0;
77 for (fd = freeFD; fd < posxFD && myFiles[fd]; fd++) {}
78 if (fd >= posxFD) return 0;
79 freeFD = fd+1;
80 } else {
81 do{if ((fd = dup(devNull)) < 0) return false;
82 if (fd >= lastFD || (isStream && fd > 255))
83 {close(fd); return 0;}
84 if (!myFiles[fd]) break;
85 DMSG("AssignFD", "FD " <<fd <<" closed outside of XrdPosix!");
86 } while(1);
87 }
88
89// Enter object in out vector of objects and assign it the FD
90//
91 myFiles[fd] = this;
92 if (fd > highFD) highFD = fd;
93 fdNum = fd + baseFD;
94
95// All done.
96//
97 return true;
98}
#define DMSG(x, y)
#define close(a)
Definition XrdPosix.hh:43

References close, DMSG, and fdNum.

Referenced by XrdPosixXrootd::Opendir().

+ Here is the caller graph for this function:

◆ CanStream()

static bool XrdPosixObject::CanStream ( )
inlinestatic

Definition at line 48 of file XrdPosixObject.hh.

48{return baseFD == 0 && freeFD < 255;}

◆ Dir()

XrdPosixDir * XrdPosixObject::Dir ( int  fildes,
bool  glk = false 
)
static

Definition at line 104 of file XrdPosixObject.cc.

105{
106 XrdPosixDir *dP;
107 XrdPosixObject *oP;
108 int waitCount = 0;
109 bool haveLock;
110
111// Validate the fildes
112//
113do{if (fd >= lastFD || fd < baseFD)
114 {errno = EBADF; return (XrdPosixDir *)0;}
115
116// Obtain the file object, if any
117//
118 fdMutex.Lock();
119 if (!(oP = myFiles[fd - baseFD]) || !(oP->Who(&dP)))
120 {fdMutex.UnLock(); errno = EBADF; return (XrdPosixDir *)0;}
121
122// Attempt to lock the object in the appropriate mode. If we fail, then we need
123// to retry this after dropping the global lock. We pause a bit to let the
124// current lock holder a chance to unlock the lock. We only do this a limited
125// amount of time (1 minute) so that we don't get stuck here forever.
126//
127 if (glk) haveLock = oP->objMutex.CondWriteLock();
128 else haveLock = oP->objMutex.CondReadLock();
129 if (!haveLock)
130 {fdMutex.UnLock();
131 waitCount++;
132 if (waitCount > 120) break;
133 XrdSysTimer::Wait(500); // We wait 500 milliseconds
134 continue;
135 }
136
137// If the global lock is to be held, then release the object lock as this
138// is a call to destroy the object and there is no need for the local lock.
139//
140 if (glk) oP->UnLock();
141 else fdMutex.UnLock();
142 return dP;
143 } while(1);
144
145// If we get here then we timedout waiting for the object lock
146//
147 errno = ETIMEDOUT;
148 return (XrdPosixDir *)0;
149}
XrdSysRWLock objMutex
virtual bool Who(XrdPosixDir **dirP)
static void Wait(int milliseconds)

References XrdSysRWLock::CondReadLock(), XrdSysRWLock::CondWriteLock(), XrdSysMutex::Lock(), objMutex, UnLock(), XrdSysMutex::UnLock(), XrdSysTimer::Wait(), and Who().

Referenced by XrdPosixXrootd::isXrootdDir(), XrdPosixXrootd::QueryError(), XrdPosixXrootd::Readdir64(), XrdPosixXrootd::Readdir64_r(), XrdPosixXrootd::Rewinddir(), XrdPosixXrootd::Seekdir(), and XrdPosixXrootd::Telldir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FDNum()

int XrdPosixObject::FDNum ( )
inline

Definition at line 54 of file XrdPosixObject.hh.

54{return fdNum;}

References fdNum.

◆ File()

XrdPosixFile * XrdPosixObject::File ( int  fildes,
bool  glk = false 
)
static

Definition at line 155 of file XrdPosixObject.cc.

156{
157 XrdPosixFile *fP;
158 XrdPosixObject *oP;
159 int waitCount = 0;
160 bool haveLock;
161
162// Validate the fildes
163//
164do{if (fd >= lastFD || fd < baseFD)
165 {errno = EBADF; return (XrdPosixFile *)0;}
166
167// Obtain the file object, if any
168//
169 fdMutex.Lock();
170 if (!(oP = myFiles[fd - baseFD]) || !(oP->Who(&fP)))
171 {fdMutex.UnLock(); errno = EBADF; return (XrdPosixFile *)0;}
172
173// Attempt to lock the object in the appropriate mode. If we fail, then we need
174// to retry this after dropping the global lock. We pause a bit to let the
175// current lock holder a chance to unlock the lock. We only do this a limited
176// amount of time (1 minute) so that we don't get stuck here forever.
177//
178 if (glk) haveLock = oP->objMutex.CondWriteLock();
179 else haveLock = oP->objMutex.CondReadLock();
180 if (!haveLock)
181 {fdMutex.UnLock();
182 waitCount++;
183 if (waitCount > 120) break;
184 XrdSysTimer::Wait(500); // We wait 500 milliseconds
185 continue;
186 }
187
188// If the global lock is to be held, then release the object lock as this
189// is a call to destroy the object and there is no need for the local lock.
190//
191 if (glk) oP->UnLock();
192 else fdMutex.UnLock();
193 return fP;
194 } while(1);
195
196// If we get here then we timedout waiting for the object lock
197//
198 errno = ETIMEDOUT;
199 return (XrdPosixFile *)0;
200}

References XrdSysRWLock::CondReadLock(), XrdSysRWLock::CondWriteLock(), XrdSysMutex::Lock(), objMutex, UnLock(), XrdSysMutex::UnLock(), XrdSysTimer::Wait(), and Who().

Referenced by XrdPosixXrootd::endPoint(), XrdPosixXrootd::Fstat(), XrdPosixXrootd::Fsync(), XrdPosixXrootd::Fsync(), XrdPosixXrootd::Ftruncate(), XrdPosixXrootd::Lseek(), XrdPosixExtra::pgRead(), XrdPosixExtra::pgWrite(), XrdPosixXrootd::Pread(), XrdPosixXrootd::Pread(), XrdPosixXrootd::Pwrite(), XrdPosixXrootd::Pwrite(), XrdPosixXrootd::QueryError(), XrdPosixXrootd::Read(), XrdPosixXrootd::VRead(), XrdPosixXrootd::VRead(), and XrdPosixXrootd::Write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getECMsg()

XrdOucECMsg * XrdPosixObject::getECMsg ( )
inline

Definition at line 56 of file XrdPosixObject.hh.

56{return &ecMsg;}

References ecMsg.

Referenced by XrdPosixXrootd::QueryError(), and XrdPosixXrootd::QueryError().

+ Here is the caller graph for this function:

◆ Init()

int XrdPosixObject::Init ( int  numfd)
static

Definition at line 206 of file XrdPosixObject.cc.

207{
208 static const int maxFD = 1048576;
209 struct rlimit rlim;
210 int isize, limfd;
211
212// Initialize the /dev/null file descriptors, bail if we cannot
213//
214 devNull = open("/dev/null", O_RDWR, 0744);
215 if (devNull < 0) return -1;
216
217// Obtain the file descriptor limit but be careful of infinity
218//
219 if (getrlimit(RLIMIT_NOFILE, &rlim)) limfd = maxFD;
220 else {if (rlim.rlim_max == RLIM_INFINITY || (int)rlim.rlim_max > maxFD)
221 {rlim.rlim_cur = maxFD;
222 setrlimit(RLIMIT_NOFILE, &rlim);
223 } else {
224 if (rlim.rlim_cur != rlim.rlim_max)
225 {rlim.rlim_cur = rlim.rlim_max;
226 setrlimit(RLIMIT_NOFILE, &rlim);
227 }
228 }
229 limfd = static_cast<int>(rlim.rlim_cur);
230 }
231
232// Compute size of table. if the passed fdnum is negative then the caller does
233// not want us to shadow fd's (ther caller promises to be honest). Otherwise,
234// the actual fdnum limit will be based on the current limit.
235//
236 if (fdnum < 0) {posxFD = fdnum = -fdnum; baseFD = limfd;}
237 else fdnum = limfd;
238 isize = fdnum * sizeof(XrdPosixFile *);
239
240// Allocate the table for fd-type pointers
241//
242 if (!(myFiles = (XrdPosixObject **)malloc(isize))) lastFD = -1;
243 else {memset((void *)myFiles, 0, isize); lastFD = fdnum+baseFD;}
244
245// All done
246//
247 return baseFD;
248}
#define open
Definition XrdPosix.hh:71

References open.

Referenced by XrdPosixXrootd::XrdPosixXrootd().

+ Here is the caller graph for this function:

◆ Lock()

void XrdPosixObject::Lock ( bool  wr = true)
inline

Definition at line 60 of file XrdPosixObject.hh.

61 {if (wr) objMutex.WriteLock();
62 else objMutex.ReadLock();
63 }

References objMutex, XrdSysRWLock::ReadLock(), and XrdSysRWLock::WriteLock().

+ Here is the call graph for this function:

◆ Ref()

void XrdPosixObject::Ref ( )
inline

◆ Refs()

int XrdPosixObject::Refs ( )
inline

Definition at line 69 of file XrdPosixObject.hh.

#define AtomicRet(mtx, x)

References AtomicRet, refCnt, and updMutex.

Referenced by XrdPosixXrootd::Close(), and XrdPosixFile::DelayedDestroy().

+ Here is the caller graph for this function:

◆ Release()

void XrdPosixObject::Release ( XrdPosixObject oP,
bool  needlk = true 
)
static

Definition at line 254 of file XrdPosixObject.cc.

255{
256// Get the lock if need be
257//
258 if (needlk) fdMutex.Lock();
259
260// Remove the object from the table
261//
262 if (baseFD)
263 {int myFD = oP->fdNum - baseFD;
264 if (myFD < freeFD) freeFD = myFD;
265 myFiles[myFD] = 0;
266 } else {
267 myFiles[oP->fdNum] = 0;
268 close(oP->fdNum);
269 }
270
271// Zorch the object fd and release the global lock
272//
273 oP->fdNum = -1;
274 fdMutex.UnLock();
275}

References close, fdNum, XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

Referenced by ~XrdPosixObject(), ReleaseDir(), and ReleaseFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReleaseDir()

XrdPosixDir * XrdPosixObject::ReleaseDir ( int  fildes)
static

Definition at line 281 of file XrdPosixObject.cc.

282{
283 XrdPosixDir *dP;
284
285// Find the directory object
286//
287 if (!(dP = Dir(fd, true))) return (XrdPosixDir *)0;
288
289// Release it and return the underlying object
290//
291 Release((XrdPosixObject *)dP, false);
292 return dP;
293}
XrdOucString Dir

References Dir, and Release().

Referenced by XrdPosixXrootd::Closedir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReleaseFile()

XrdPosixFile * XrdPosixObject::ReleaseFile ( int  fildes)
static

Definition at line 299 of file XrdPosixObject.cc.

300{
301 XrdPosixFile *fP;
302
303// Find the file object
304//
305 if (!(fP = File(fd, true))) return (XrdPosixFile *)0;
306
307// Release it and return the underlying object
308//
309 Release((XrdPosixObject *)fP, false);
310 return fP;
311}
XrdOucString File

References File, and Release().

Referenced by XrdPosixXrootd::Close().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Shutdown()

void XrdPosixObject::Shutdown ( )
static

Definition at line 317 of file XrdPosixObject.cc.

318{
319 XrdPosixObject *oP;
320 int i;
321
322// Destroy all files and static data
323//
324 fdMutex.Lock();
325 if (myFiles)
326 {for (i = 0; i <= highFD; i++)
327 if ((oP = myFiles[i]))
328 {myFiles[i] = 0;
329 if (oP->fdNum >= 0) close(oP->fdNum);
330 oP->fdNum = -1;
331 delete oP;
332 };
333 free(myFiles); myFiles = 0;
334 }
335 fdMutex.UnLock();
336}

References close, fdNum, XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

Referenced by XrdPosixXrootd::~XrdPosixXrootd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UnLock()

void XrdPosixObject::UnLock ( )
inline

◆ unRef()

void XrdPosixObject::unRef ( )
inline

◆ Valid()

static bool XrdPosixObject::Valid ( int  fd)
inlinestatic

Definition at line 85 of file XrdPosixObject.hh.

86 {return fd >= baseFD && fd <= (highFD+baseFD)
87 && myFiles && myFiles[fd-baseFD];}

Referenced by XrdPosixXrootd::myFD().

+ Here is the caller graph for this function:

◆ Who() [1/2]

virtual bool XrdPosixObject::Who ( XrdPosixDir **  dirP)
inlinevirtual

Reimplemented in XrdPosixDir, XrdPosixDir, and XrdPosixFile.

Definition at line 89 of file XrdPosixObject.hh.

89{return false;}

Referenced by Dir(), and File().

+ Here is the caller graph for this function:

◆ Who() [2/2]

virtual bool XrdPosixObject::Who ( XrdPosixFile **  fileP)
inlinevirtual

Reimplemented in XrdPosixDir, XrdPosixFile, and XrdPosixFile.

Definition at line 91 of file XrdPosixObject.hh.

91{return false;}

Member Data Documentation

◆ ecMsg

◆ fdNum

int XrdPosixObject::fdNum
protected

◆ objMutex

XrdSysRWLock XrdPosixObject::objMutex
protected

Definition at line 100 of file XrdPosixObject.hh.

Referenced by Dir(), File(), Lock(), XrdPosixDir::rewind(), and UnLock().

◆ refCnt

int XrdPosixObject::refCnt
protected

Definition at line 102 of file XrdPosixObject.hh.

Referenced by Ref(), Refs(), and unRef().

◆ updMutex


The documentation for this class was generated from the following files: