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
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
109 XrdCl::AnyObject *response) override;
110
111 void updLock() {updMutex.Lock();}
112
113 void updUnLock() {updMutex.UnLock();}
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
149inline 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
164inline void UpdtSize(size_t newsz)
165 {updMutex.Lock();
166 if (newsz > mySize) mySize = newsz;
167 updMutex.UnLock();
168 }
169
171
172inline 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
188static
193static char *sfSFX;
194static short sfSLN;
195static bool ddPosted;
196static int ddNum;
197
198static const int realFD = 1;
199static const int isStrm = 2;
200static const int isUpdt = 4;
201
202 XrdPosixFile(bool &aOK, const char *path, XrdPosixCallBack *cbP=0,
203 int Opts=0);
205
206private:
207
208union {long long currOffset;
209 XrdPosixCallBack *theCB;
210 XrdPosixFile *nextFile;
211 };
212
213char *fPath;
214char *fOpen;
215char *fLoc;
216union {int cOpt; int numTries;};
217char isStream;
218};
219#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:52
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
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
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)