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/types.h>
39 #include <sys/uio.h>
40 
41 #include "XrdCl/XrdClFileSystem.hh"
42 #include "XrdCl/XrdClFile.hh"
43 #include "XrdCl/XrdClURL.hh"
45 
46 #include "XrdOuc/XrdOucCache.hh"
47 
48 #include "XrdPosix/XrdPosixMap.hh"
50 
51 /******************************************************************************/
52 /* X r d P o s i x F i l e C l a s s */
53 /******************************************************************************/
54 
55 class XrdPosixCallBack;
56 class XrdPosixPrepIO;
57 
58 class XrdPosixFile : public XrdPosixObject,
59  public XrdOucCacheIO,
60  public XrdOucCacheIOCD,
62 {
63 public:
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)
73  mySize = currOffset;
74  long long retOffset = currOffset;
75  updMutex.UnLock();
76  return retOffset;
77  }
78 
79 //atic XrdPosixFile *Alloc(const char *path, XrdPosixCallBack *cbP, int Opts);
80 
81 static void* DelayedDestroy(void*);
82 
83 static void DelayedDestroy(XrdPosixFile *fp);
84 
85  bool Close(XrdCl::XRootDStatus &Status);
86 
87  bool Detach(XrdOucCacheIOCD &cdP) override
88  {(void)cdP; return true;}
89 
90  void DetachDone() override {unRef();}
91 
92  bool Finalize(XrdCl::XRootDStatus *Status);
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 
105  void HandleResponse(XrdCl::XRootDStatus *status,
106  XrdCl::AnyObject *response) override;
107 
108  void updLock() {updMutex.Lock();}
109 
111 
112  long long Offset() {AtomicRet(updMutex, currOffset);}
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 
122  void pgRead(XrdOucCacheIOCB &iocb,
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 
131  void pgWrite(XrdOucCacheIOCB &iocb,
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 
146 inline long long setOffset(long long offs)
147  {updMutex.Lock();
148  currOffset = offs;
149  updMutex.UnLock();
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 
161 inline void UpdtSize(size_t newsz)
162  {updMutex.Lock();
163  if (newsz > mySize) mySize = newsz;
164  updMutex.UnLock();
165  }
166 
167  using XrdPosixObject::Who;
168 
169 inline 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 
185 static
190 static char *sfSFX;
191 static short sfSLN;
192 static bool ddPosted;
193 static int ddNum;
194 
195 static const int realFD = 1;
196 static const int isStrm = 2;
197 static const int isUpdt = 4;
198 
199  XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP=0,
200  int Opts=0);
201  ~XrdPosixFile();
202 
203 private:
204 
205 union {long long currOffset;
206  XrdPosixCallBack *theCB;
207  XrdPosixFile *nextFile;
208  };
209 
210 char *fPath;
211 char *fOpen;
212 char *fLoc;
213 union {int cOpt; int numTries;};
214 char isStream;
215 };
216 #endif
int stat(const char *path, struct stat *buf)
struct myOpts opts
#define AtomicBeg(Mtx)
#define AtomicGet(x)
#define AtomicEnd(Mtx)
#define AtomicRet(mtx, x)
A file.
Definition: XrdClFile.hh:46
Handle an async response.
An abstract class to define a callback for Open() call.
XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP=0, int Opts=0)
static XrdSysSemaphore ddSem
static XrdSysMutex ddMutex
static char * sfSFX
const char * Path() override
bool Who(XrdPosixFile **fileP) override
int Write(char *Buff, long long Offs, int Len) override
static const int isUpdt
int Sync() override
static XrdPosixFile * ddLost
static const int isStrm
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
void UpdtSize(size_t newsz)
long long addOffset(long long offs, int updtSz=0)
Definition: XrdPosixFile.hh:69
int Fstat(struct stat &buf) override
static int ddNum
bool Detach(XrdOucCacheIOCD &cdP) override
Definition: XrdPosixFile.hh:87
const char * Origin()
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
bool Stat(XrdCl::XRootDStatus &Status, bool force=false)
void DetachDone() override
Indicate that the CacheIO object has been detached.
Definition: XrdPosixFile.hh:90
void updUnLock()
bool Close(XrdCl::XRootDStatus &Status)
static short sfSLN
XrdCl::File clFile
Definition: XrdPosixFile.hh:67
XrdOucCacheIO * XCio
Definition: XrdPosixFile.hh:65
static XrdPosixFile * ddList
long long Offset()
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
static const int realFD
bool Finalize(XrdCl::XRootDStatus *Status)
int ReadV(const XrdOucIOVec *readV, int n) override
long long setOffset(long long offs)
static void * DelayedDestroy(void *)
int pgWrite(char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0) override
XrdSysRecMutex updMutex
virtual bool Who(XrdPosixDir **dirP)
int Opts
Definition: XrdMpxStats.cc:58