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  int Fcntl(XrdOucCacheOp::Code opc,
93  const std::string& args, std::string& resp) override;
94 
95  bool Finalize(XrdCl::XRootDStatus *Status);
96 
97  long long FSize() override
99  long long retSize = AtomicGet(mySize);
101  return retSize;
102  }
103 
104  int Fstat(struct stat &buf) override;
105 
106  const char *Location(bool refresh=false) override;
107 
108  void HandleResponse(XrdCl::XRootDStatus *status,
109  XrdCl::AnyObject *response) override;
110 
111  void updLock() {updMutex.Lock();}
112 
114 
115  long long Offset() {AtomicRet(updMutex, currOffset);}
116 
117  const char *Origin() {return fOpen;}
118 
119  const char *Path() override {return fPath;}
120 
121  int pgRead(char *buff, long long offs, int rdlen,
122  std::vector<uint32_t> &csvec, uint64_t opts=0,
123  int *csfix=0) override;
124 
125  void pgRead(XrdOucCacheIOCB &iocb,
126  char *buff, long long offs, int rdlen,
127  std::vector<uint32_t> &csvec, uint64_t opts=0,
128  int *csfix=0) override;
129 
130  int pgWrite(char *buff, long long offs, int wrlen,
131  std::vector<uint32_t> &csvec, uint64_t opts=0,
132  int *csfix=0) override;
133 
134  void pgWrite(XrdOucCacheIOCB &iocb,
135  char *buff, long long offs, int wrlen,
136  std::vector<uint32_t> &csvec, uint64_t opts=0,
137  int *csfix=0) override;
138 
139  int Read (char *Buff, long long Offs, int Len) override;
140 
141  void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs,
142  int rlen) override;
143 
144  int ReadV (const XrdOucIOVec *readV, int n) override;
145 
146  void ReadV (XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV,
147  int n) override;
148 
149 inline long long setOffset(long long offs)
150  {updMutex.Lock();
151  currOffset = offs;
152  updMutex.UnLock();
153  return offs;
154  }
155 
156  bool Stat(XrdCl::XRootDStatus &Status, bool force=false);
157 
158  int Sync() override;
159 
160  void Sync(XrdOucCacheIOCB &iocb) override;
161 
162  int Trunc(long long Offset) override;
163 
164 inline void UpdtSize(size_t newsz)
165  {updMutex.Lock();
166  if (newsz > mySize) mySize = newsz;
167  updMutex.UnLock();
168  }
169 
170  using XrdPosixObject::Who;
171 
172 inline bool Who(XrdPosixFile **fileP) override
173  {*fileP = this; return true;}
174 
175  int Write(char *Buff, long long Offs, int Len) override;
176 
177  void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs,
178  int wlen) override;
179 
180  size_t mySize;
181  time_t myAtime;
182  time_t myCtime;
183  time_t myMtime;
184  dev_t myRdev;
185  ino_t myInode;
186  mode_t myMode;
187 
188 static
193 static char *sfSFX;
194 static short sfSLN;
195 static bool ddPosted;
196 static int ddNum;
197 
198 static const int realFD = 1;
199 static const int isStrm = 2;
200 static const int isUpdt = 4;
201 
202  XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP=0,
203  int Opts=0);
204  ~XrdPosixFile();
205 
206 private:
207 
208 union {long long currOffset;
209  XrdPosixCallBack *theCB;
210  XrdPosixFile *nextFile;
211  };
212 
213 char *fPath;
214 char *fOpen;
215 char *fLoc;
216 union {int cOpt; int numTries;};
217 char isStream;
218 };
219 #endif
#define stat(a, b)
Definition: XrdPosix.hh:105
struct myOpts opts
#define AtomicBeg(Mtx)
#define AtomicGet(x)
#define AtomicEnd(Mtx)
#define AtomicRet(mtx, x)
A file.
Definition: XrdClFile.hh:52
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
int Fcntl(XrdOucCacheOp::Code opc, const std::string &args, std::string &resp) 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:97
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