xrootd
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/uio.h>
39 
40 #include "XrdCl/XrdClFileSystem.hh"
41 #include "XrdCl/XrdClFile.hh"
42 #include "XrdCl/XrdClURL.hh"
44 
45 #include "XrdOuc/XrdOucCache.hh"
46 
47 #include "XrdPosix/XrdPosixMap.hh"
49 
50 /******************************************************************************/
51 /* X r d P o s i x F i l e C l a s s */
52 /******************************************************************************/
53 
54 class XrdPosixCallBack;
55 class XrdPosixPrepIO;
56 
57 class XrdPosixFile : public XrdPosixObject,
58  public XrdOucCacheIO,
59  public XrdOucCacheIOCD,
61 {
62 public:
63 
67 
68  long long addOffset(long long offs, int updtSz=0)
69  {updMutex.Lock();
70  currOffset += offs;
71  if (updtSz && currOffset > (long long)mySize)
73  long long retOffset = currOffset;
74  updMutex.UnLock();
75  return retOffset;
76  }
77 
78 //atic XrdPosixFile *Alloc(const char *path, XrdPosixCallBack *cbP, int Opts);
79 
80 static void* DelayedDestroy(void*);
81 
82 static void DelayedDestroy(XrdPosixFile *fp);
83 
84  bool Close(XrdCl::XRootDStatus &Status);
85 
86  bool Detach(XrdOucCacheIOCD &cdP) override
87  {(void)cdP; return true;}
88 
89  void DetachDone() override {unRef();}
90 
92 
93  long long FSize() override
95  long long retSize = AtomicGet(mySize);
97  return retSize;
98  }
99 
100  int Fstat(struct stat &buf) override;
101 
102  const char *Location(bool refresh=false) override;
103 
105  XrdCl::AnyObject *response) override;
106 
107  void updLock() {updMutex.Lock();}
108 
110 
112 
113  const char *Origin() {return fOpen;}
114 
115  const char *Path() override {return fPath;}
116 
117  int pgRead(char *buff, long long offs, int rdlen,
118  std::vector<uint32_t> &csvec, uint64_t opts=0,
119  int *csfix=0) override;
120 
122  char *buff, long long offs, int rdlen,
123  std::vector<uint32_t> &csvec, uint64_t opts=0,
124  int *csfix=0) override;
125 
126  int pgWrite(char *buff, long long offs, int wrlen,
127  std::vector<uint32_t> &csvec, uint64_t opts=0,
128  int *csfix=0) override;
129 
131  char *buff, long long offs, int wrlen,
132  std::vector<uint32_t> &csvec, uint64_t opts=0,
133  int *csfix=0) override;
134 
135  int Read (char *Buff, long long Offs, int Len) override;
136 
137  void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs,
138  int rlen) override;
139 
140  int ReadV (const XrdOucIOVec *readV, int n) override;
141 
142  void ReadV (XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV,
143  int n) override;
144 
145 inline long long setOffset(long long offs)
146  {updMutex.Lock();
147  currOffset = offs;
148  updMutex.UnLock();
149  return offs;
150  }
151 
152  bool Stat(XrdCl::XRootDStatus &Status, bool force=false);
153 
154  int Sync() override;
155 
156  void Sync(XrdOucCacheIOCB &iocb) override;
157 
158  int Trunc(long long Offset) override;
159 
160 inline void UpdtSize(size_t newsz)
161  {updMutex.Lock();
162  if (newsz > mySize) mySize = newsz;
163  updMutex.UnLock();
164  }
165 
166  using XrdPosixObject::Who;
167 
168 inline bool Who(XrdPosixFile **fileP)
169  {*fileP = this; return true;}
170 
171  int Write(char *Buff, long long Offs, int Len) override;
172 
173  void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs,
174  int wlen) override;
175 
176  size_t mySize;
177  time_t myAtime;
178  time_t myCtime;
179  time_t myMtime;
180  dev_t myRdev;
181  ino_t myInode;
182  mode_t myMode;
183 
184 static
189 static char *sfSFX;
190 static short sfSLN;
191 static bool ddPosted;
192 static int ddNum;
193 
194 static const int realFD = 1;
195 static const int isStrm = 2;
196 static const int isUpdt = 4;
197 
198  XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP=0,
199  int Opts=0);
201 
202 private:
203 
204 union {long long currOffset;
207  };
208 
209 char *fPath;
210 char *fOpen;
211 char *fLoc;
212 union {int cOpt; int numTries;};
213 char isStream;
214 };
215 #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:61
XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP=0, int Opts=0)
static XrdSysSemaphore ddSem
Definition: XrdPosixFile.hh:185
void Read(XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen) override
static XrdSysMutex ddMutex
Definition: XrdPosixFile.hh:186
time_t myCtime
Definition: XrdPosixFile.hh:178
XrdPosixFile * nextFile
Definition: XrdPosixFile.hh:206
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:179
void pgWrite(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0) override
const char * Path() override
Definition: XrdPosixFile.hh:115
void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int n) override
static XrdPosixFile * ddLost
Definition: XrdPosixFile.hh:188
void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen) override
static char * sfSFX
Definition: XrdPosixFile.hh:189
const char * Location(bool refresh=false) override
int Write(char *Buff, long long Offs, int Len) override
bool Who(XrdPosixFile **fileP)
Definition: XrdPosixFile.hh:168
void Sync(XrdOucCacheIOCB &iocb) override
char * fPath
Definition: XrdPosixFile.hh:209
XrdPosixCallBack * theCB
Definition: XrdPosixFile.hh:205
static const int isUpdt
Definition: XrdPosixFile.hh:196
int Sync() override
static void * DelayedDestroy(void *)
static XrdPosixFile * ddList
Definition: XrdPosixFile.hh:187
static void DelayedDestroy(XrdPosixFile *fp)
static const int isStrm
Definition: XrdPosixFile.hh:195
int cOpt
Definition: XrdPosixFile.hh:212
XrdPosixPrepIO * PrepIO
Definition: XrdPosixFile.hh:65
long long FSize() override
Definition: XrdPosixFile.hh:93
int Read(char *Buff, long long Offs, int Len) override
static bool ddPosted
Definition: XrdPosixFile.hh:191
void UpdtSize(size_t newsz)
Definition: XrdPosixFile.hh:160
long long addOffset(long long offs, int updtSz=0)
Definition: XrdPosixFile.hh:68
dev_t myRdev
Definition: XrdPosixFile.hh:180
int Fstat(struct stat &buf) override
static int ddNum
Definition: XrdPosixFile.hh:192
char isStream
Definition: XrdPosixFile.hh:213
char * fOpen
Definition: XrdPosixFile.hh:210
size_t mySize
Definition: XrdPosixFile.hh:176
bool Detach(XrdOucCacheIOCD &cdP) override
Definition: XrdPosixFile.hh:86
void updLock()
Definition: XrdPosixFile.hh:107
const char * Origin()
Definition: XrdPosixFile.hh:113
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
mode_t myMode
Definition: XrdPosixFile.hh:182
bool Stat(XrdCl::XRootDStatus &Status, bool force=false)
void DetachDone() override
Indicate that the CacheIO object has been detached.
Definition: XrdPosixFile.hh:89
long long currOffset
Definition: XrdPosixFile.hh:204
void updUnLock()
Definition: XrdPosixFile.hh:109
char * fLoc
Definition: XrdPosixFile.hh:211
bool Close(XrdCl::XRootDStatus &Status)
static short sfSLN
Definition: XrdPosixFile.hh:190
XrdCl::File clFile
Definition: XrdPosixFile.hh:66
XrdOucCacheIO * XCio
Definition: XrdPosixFile.hh:64
ino_t myInode
Definition: XrdPosixFile.hh:181
time_t myAtime
Definition: XrdPosixFile.hh:177
long long Offset()
Definition: XrdPosixFile.hh:111
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
int numTries
Definition: XrdPosixFile.hh:212
static const int realFD
Definition: XrdPosixFile.hh:194
bool Finalize(XrdCl::XRootDStatus *Status)
int ReadV(const XrdOucIOVec *readV, int n) override
long long setOffset(long long offs)
Definition: XrdPosixFile.hh:145
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