xrootd
Loading...
Searching...
No Matches
XrdPosixFile.hh
Go to the documentation of this file.
1#ifndef __XRDPOSIXFILE_HH__
2#define __XRDPOSIXFILE_HH__
3/******************************************************************************/
4/* */
5/* X r d P o s i x F i l e . h h */
6/* */
7/* (c) 2013 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#include <cerrno>
34#include <fcntl.h>
35#include <sys/time.h>
36#include <sys/param.h>
37#include <sys/resource.h>
38#include <sys/types.h>
39#include <sys/uio.h>
40
42#include "XrdCl/XrdClFile.hh"
43#include "XrdCl/XrdClURL.hh"
45
46#include "XrdOuc/XrdOucCache.hh"
47
50
51/******************************************************************************/
52/* X r d P o s i x F i l e C l a s s */
53/******************************************************************************/
54
56class XrdPosixPrepIO;
57
59 public XrdOucCacheIO,
60 public XrdOucCacheIOCD,
62{
63public:
64
68
69 long long addOffset(long long offs, int updtSz=0)
70 {updMutex.Lock();
71 currOffset += offs;
72 if (updtSz && currOffset > (long long)mySize)
74 long long retOffset = currOffset;
76 return retOffset;
77 }
78
79//atic XrdPosixFile *Alloc(const char *path, XrdPosixCallBack *cbP, int Opts);
80
81static void* DelayedDestroy(void*);
82
84
86
87 bool Detach(XrdOucCacheIOCD &cdP) override
88 {(void)cdP; return true;}
89
90 void DetachDone() override {unRef();}
91
93
94 long long FSize() override
96 long long retSize = AtomicGet(mySize);
98 return retSize;
99 }
100
101 int Fstat(struct stat &buf) override;
102
103 const char *Location(bool refresh=false) override;
104
106 XrdCl::AnyObject *response) override;
107
109
111
113
114 const char *Origin() {return fOpen;}
115
116 const char *Path() override {return fPath;}
117
118 int pgRead(char *buff, long long offs, int rdlen,
119 std::vector<uint32_t> &csvec, uint64_t opts=0,
120 int *csfix=0) override;
121
123 char *buff, long long offs, int rdlen,
124 std::vector<uint32_t> &csvec, uint64_t opts=0,
125 int *csfix=0) override;
126
127 int pgWrite(char *buff, long long offs, int wrlen,
128 std::vector<uint32_t> &csvec, uint64_t opts=0,
129 int *csfix=0) override;
130
132 char *buff, long long offs, int wrlen,
133 std::vector<uint32_t> &csvec, uint64_t opts=0,
134 int *csfix=0) override;
135
136 int Read (char *Buff, long long Offs, int Len) override;
137
138 void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs,
139 int rlen) override;
140
141 int ReadV (const XrdOucIOVec *readV, int n) override;
142
143 void ReadV (XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV,
144 int n) override;
145
146inline long long setOffset(long long offs)
147 {updMutex.Lock();
148 currOffset = offs;
150 return offs;
151 }
152
153 bool Stat(XrdCl::XRootDStatus &Status, bool force=false);
154
155 int Sync() override;
156
157 void Sync(XrdOucCacheIOCB &iocb) override;
158
159 int Trunc(long long Offset) override;
160
161inline void UpdtSize(size_t newsz)
162 {updMutex.Lock();
163 if (newsz > mySize) mySize = newsz;
165 }
166
168
169inline bool Who(XrdPosixFile **fileP) override
170 {*fileP = this; return true;}
171
172 int Write(char *Buff, long long Offs, int Len) override;
173
174 void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs,
175 int wlen) override;
176
177 size_t mySize;
178 time_t myAtime;
179 time_t myCtime;
180 time_t myMtime;
181 dev_t myRdev;
182 ino_t myInode;
183 mode_t myMode;
184
185static
190static char *sfSFX;
191static short sfSLN;
192static bool ddPosted;
193static int ddNum;
194
195static const int realFD = 1;
196static const int isStrm = 2;
197static const int isUpdt = 4;
198
199 XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP=0,
200 int Opts=0);
202
203private:
204
205union {long long currOffset;
208 };
209
210char *fPath;
211char *fOpen;
212char *fLoc;
213union {int cOpt; int numTries;};
215};
216#endif
#define stat(a, b)
Definition XrdPosix.hh:96
#define AtomicBeg(Mtx)
Definition XrdSysAtomics.hh:63
#define AtomicGet(x)
Definition XrdSysAtomics.hh:71
#define AtomicEnd(Mtx)
Definition XrdSysAtomics.hh:64
#define AtomicRet(mtx, x)
Definition XrdSysAtomics.hh:76
Definition XrdClAnyObject.hh:33
A file.
Definition XrdClFile.hh:46
Handle an async response.
Definition XrdClXRootDResponses.hh:1126
Request status.
Definition XrdClXRootDResponses.hh:219
Definition XrdOucCache.hh:53
Definition XrdOucCache.hh:82
Definition XrdOucCache.hh:105
An abstract class to define a callback for Open() call.
Definition XrdPosixCallBack.hh:52
Definition XrdPosixFile.hh:62
XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP=0, int Opts=0)
static XrdSysSemaphore ddSem
Definition XrdPosixFile.hh:186
void Read(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen) override
static XrdSysMutex ddMutex
Definition XrdPosixFile.hh:187
time_t myCtime
Definition XrdPosixFile.hh:179
XrdPosixFile * nextFile
Definition XrdPosixFile.hh:207
void pgRead(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0) override
time_t myMtime
Definition XrdPosixFile.hh:180
void pgWrite(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0) override
void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int n) override
static XrdPosixFile * ddLost
Definition XrdPosixFile.hh:189
void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen) override
bool Who(XrdPosixFile **fileP) override
Definition XrdPosixFile.hh:169
static char * sfSFX
Definition XrdPosixFile.hh:190
const char * Origin()
Definition XrdPosixFile.hh:114
int Write(char *Buff, long long Offs, int Len) override
void Sync(XrdOucCacheIOCB &iocb) override
char * fPath
Definition XrdPosixFile.hh:210
XrdPosixCallBack * theCB
Definition XrdPosixFile.hh:206
static const int isUpdt
Definition XrdPosixFile.hh:197
int Sync() override
static XrdPosixFile * ddList
Definition XrdPosixFile.hh:188
static void DelayedDestroy(XrdPosixFile *fp)
static const int isStrm
Definition XrdPosixFile.hh:196
int cOpt
Definition XrdPosixFile.hh:213
XrdPosixPrepIO * PrepIO
Definition XrdPosixFile.hh:66
long long FSize() override
Definition XrdPosixFile.hh:94
int Read(char *Buff, long long Offs, int Len) override
static bool ddPosted
Definition XrdPosixFile.hh:192
void UpdtSize(size_t newsz)
Definition XrdPosixFile.hh:161
long long addOffset(long long offs, int updtSz=0)
Definition XrdPosixFile.hh:69
dev_t myRdev
Definition XrdPosixFile.hh:181
int Fstat(struct stat &buf) override
static int ddNum
Definition XrdPosixFile.hh:193
char isStream
Definition XrdPosixFile.hh:214
char * fOpen
Definition XrdPosixFile.hh:211
size_t mySize
Definition XrdPosixFile.hh:177
bool Detach(XrdOucCacheIOCD &cdP) override
Definition XrdPosixFile.hh:87
void updLock()
Definition XrdPosixFile.hh:108
int pgRead(char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0) override
int Trunc(long long Offset) override
const char * Location(bool refresh=false) override
mode_t myMode
Definition XrdPosixFile.hh:183
bool Stat(XrdCl::XRootDStatus &Status, bool force=false)
void DetachDone() override
Indicate that the CacheIO object has been detached.
Definition XrdPosixFile.hh:90
long long currOffset
Definition XrdPosixFile.hh:205
void updUnLock()
Definition XrdPosixFile.hh:110
char * fLoc
Definition XrdPosixFile.hh:212
bool Close(XrdCl::XRootDStatus &Status)
static void * DelayedDestroy(void *)
static short sfSLN
Definition XrdPosixFile.hh:191
XrdCl::File clFile
Definition XrdPosixFile.hh:67
XrdOucCacheIO * XCio
Definition XrdPosixFile.hh:65
const char * Path() override
Definition XrdPosixFile.hh:116
ino_t myInode
Definition XrdPosixFile.hh:182
time_t myAtime
Definition XrdPosixFile.hh:178
long long Offset()
Definition XrdPosixFile.hh:112
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
int numTries
Definition XrdPosixFile.hh:213
static const int realFD
Definition XrdPosixFile.hh:195
bool Finalize(XrdCl::XRootDStatus *Status)
int ReadV(const XrdOucIOVec *readV, int n) override
long long setOffset(long long offs)
Definition XrdPosixFile.hh:146
int pgWrite(char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0) override
Definition XrdPosixObject.hh:42
void unRef()
Definition XrdPosixObject.hh:67
XrdSysRecMutex updMutex
Definition XrdPosixObject.hh:94
virtual bool Who(XrdPosixDir **dirP)
Definition XrdPosixObject.hh:86
Definition XrdPosixPrepIO.hh:39
Definition XrdSysPthread.hh:165
void Lock()
Definition XrdSysPthread.hh:222
void UnLock()
Definition XrdSysPthread.hh:224
Definition XrdSysPthread.hh:494
Definition XrdOucIOVec.hh:41