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)
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
81static void* DelayedDestroy(void*);
82
83static 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
106 XrdCl::AnyObject *response) override;
107
108 void updLock() {updMutex.Lock();}
109
110 void updUnLock() {updMutex.UnLock();}
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
146inline 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
161inline void UpdtSize(size_t newsz)
162 {updMutex.Lock();
163 if (newsz > mySize) mySize = newsz;
164 updMutex.UnLock();
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;
206 XrdPosixCallBack *theCB;
207 XrdPosixFile *nextFile;
208 };
209
210char *fPath;
211char *fOpen;
212char *fLoc;
213union {int cOpt; int numTries;};
214char isStream;
215};
216#endif
struct stat Stat
Definition XrdCks.cc:49
#define stat(a, b)
Definition XrdPosix.hh:101
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.
XrdOucCacheIO()
Construct and Destructor.
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
bool Who(XrdPosixFile **fileP) override
const char * Origin()
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
long long FSize() override
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)
int Fstat(struct stat &buf) override
static int ddNum
bool Detach(XrdOucCacheIOCD &cdP) override
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
void DetachDone() override
Indicate that the CacheIO object has been detached.
bool Close(XrdCl::XRootDStatus &Status)
static short sfSLN
XrdCl::File clFile
XrdOucCacheIO * XCio
const char * Path() override
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)