xrootd
XrdOssApi.hh
Go to the documentation of this file.
1 #ifndef _XRDOSS_API_H
2 #define _XRDOSS_API_H
3 /******************************************************************************/
4 /* */
5 /* X r d O s s A p i . h h */
6 /* */
7 /* (c) 2003 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 <sys/types.h>
34 #include <errno.h>
35 #include "XrdSys/XrdSysHeaders.hh"
36 
37 #include "XrdOss/XrdOss.hh"
38 #include "XrdOss/XrdOssConfig.hh"
39 #include "XrdOss/XrdOssError.hh"
40 #include "XrdOuc/XrdOucExport.hh"
41 #include "XrdOuc/XrdOucPList.hh"
42 #include "XrdOuc/XrdOucStream.hh"
43 #include "XrdSys/XrdSysError.hh"
44 #include "XrdSys/XrdSysPthread.hh"
45 
46 /******************************************************************************/
47 /* o o s s _ D i r */
48 /******************************************************************************/
49 
50 class XrdOssDir : public XrdOssDF
51 {
52 public:
53 int Close(long long *retsz=0);
54 int Opendir(const char *, XrdOucEnv &);
55 int Readdir(char *buff, int blen);
56 
57  // Constructor and destructor
58  XrdOssDir(const char *tid)
59  {lclfd=0; mssfd=0; pflags=ateof=isopen=0; tident=tid;}
60  ~XrdOssDir() {if (isopen > 0) Close(); isopen = 0;}
61 private:
62  DIR *lclfd;
63  void *mssfd;
64 const char *tident;
65 unsigned long long pflags;
66  int ateof;
67  int isopen;
68 };
69 
70 /******************************************************************************/
71 /* o o s s _ F i l e */
72 /******************************************************************************/
73 
74 class oocx_CXFile;
75 class XrdSfsAio;
76 class XrdOssCache_FS;
77 class XrdOssMioFile;
78 
79 class XrdOssFile : public XrdOssDF
80 {
81 public:
82 
83 // The following two are virtual functions to allow for upcasting derivations
84 // of this implementation
85 //
86 virtual int Close(long long *retsz=0);
87 virtual int Open(const char *, int, mode_t, XrdOucEnv &);
88 
89 int Fchmod(mode_t mode);
90 int Fstat(struct stat *);
91 int Fsync();
92 int Fsync(XrdSfsAio *aiop);
93 int Ftruncate(unsigned long long);
94 int getFD() {return fd;}
95 off_t getMmap(void **addr);
96 int isCompressed(char *cxidp=0);
97 ssize_t Read( off_t, size_t);
98 ssize_t Read( void *, off_t, size_t);
99 int Read(XrdSfsAio *aiop);
100 ssize_t ReadRaw( void *, off_t, size_t);
101 ssize_t Write(const void *, off_t, size_t);
102 int Write(XrdSfsAio *aiop);
103 
104  // Constructor and destructor
105  XrdOssFile(const char *tid)
106  {cxobj = 0; rawio = 0; cxpgsz = 0; cxid[0] = '\0';
107  mmFile = 0; tident = tid;
108  }
109 
110 virtual ~XrdOssFile() {if (fd >= 0) Close();}
111 
112 private:
113 int Open_ufs(const char *, int, int, unsigned long long);
114 
115 static int AioFailure;
116 oocx_CXFile *cxobj;
119 const char *tident;
120 long long FSize;
121 int rawio;
122 int cxpgsz;
123 char cxid[4];
124 };
125 
126 /******************************************************************************/
127 /* o o s s _ S y s */
128 /******************************************************************************/
129 
130 class XrdFrcProxy;
131 class XrdOssCache_Group;
132 class XrdOssCache_Space;
133 class XrdOssCreateInfo;
134 class XrdOucMsubs;
135 class XrdOucName2Name;
136 class XrdOucProg;
137 class XrdOssSpace;
138 class XrdOssStage_Req;
139 
140 struct XrdVersionInfo;
141 
142 class XrdOssSys : public XrdOss
143 {
144 public:
145 virtual XrdOssDF *newDir(const char *tident)
146  {return (XrdOssDF *)new XrdOssDir(tident);}
147 virtual XrdOssDF *newFile(const char *tident)
148  {return (XrdOssDF *)new XrdOssFile(tident);}
149 
150 int Chmod(const char *, mode_t mode, XrdOucEnv *eP=0);
151 int Configure(const char *, XrdSysError &);
153 virtual
154 int Create(const char *, const char *, mode_t, XrdOucEnv &, int opts=0);
155 int GenLocalPath(const char *, char *);
156 int GenRemotePath(const char *, char *);
157 int Init(XrdSysLogger *, const char *);
158 int IsRemote(const char *path)
159  {return (RPList.Find(path) & XRDEXP_REMOTE) != 0;}
160 int Lfn2Pfn(const char *Path, char *buff, int blen);
161 const char *Lfn2Pfn(const char *Path, char *buff, int blen, int &rc);
162 int Mkdir(const char *, mode_t mode, int mkpath=0, XrdOucEnv *eP=0);
163 int Mkpath(const char *, mode_t mode);
164 unsigned long long PathOpts(const char *path) {return RPList.Find(path);}
165 int Reloc(const char *tident, const char *path,
166  const char *cgName, const char *anchor=0);
167 int Remdir(const char *, int Opts=0, XrdOucEnv *eP=0); // In Unlink()
168 int Rename(const char *, const char *,
169  XrdOucEnv *eP1=0, XrdOucEnv *eP2=0);
170 virtual
171 int Stage(const char *, const char *, XrdOucEnv &, int, mode_t, unsigned long long );
172 void *Stage_In(void *carg);
173 int Stat(const char *, struct stat *, int opts=0, XrdOucEnv *Env=0);
174 int StatFS(const char *path, char *buff, int &blen, XrdOucEnv *Env=0);
175 int StatFS(const char *path, unsigned long long &Opt,
176  long long &fSize, long long &fSpace);
177 int StatLS(XrdOucEnv &env, const char *path, char *buff, int &blen);
178 int StatVS(XrdOssVSInfo *sP, const char *sname=0, int updt=0);
179 int StatXA(const char *path, char *buff, int &blen, XrdOucEnv *Env=0);
180 int StatXP(const char *path, unsigned long long &attr, XrdOucEnv *Env=0);
181 int Truncate(const char *, unsigned long long Size, XrdOucEnv *eP=0);
182 int Unlink(const char *, int Opts=0, XrdOucEnv *eP=0);
183 
184 int Stats(char *bp, int bl);
185 
186 static int AioInit();
187 static int AioAllOk;
188 
189 static int runOld; // Run in backward compatability mode
190 
191 static char tryMmap; // Memory mapped files enabled
192 static char chkMmap; // Memory mapped files are selective
193 
194 int MSS_Closedir(void *);
195 int MSS_Create(const char *path, mode_t, XrdOucEnv &);
196 void *MSS_Opendir(const char *, int &rc);
197 int MSS_Readdir(void *fd, char *buff, int blen);
198 int MSS_Remdir(const char *, const char *) {return -ENOTSUP;}
199 int MSS_Rename(const char *, const char *);
200 int MSS_Stat(const char *, struct stat *buff=0);
201 int MSS_Unlink(const char *);
202 
203 static const int MaxArgs = 15;
204 
205 char *ConfigFN; // -> Pointer to the config file name
206 int Hard_FD_Limit; // Hard file descriptor limit
207 int MaxTwiddle; // Maximum seconds of internal wait
208 char *LocalRoot; // -> Path prefix for local filename
209 char *RemoteRoot; // -> Path prefix for remote filename
210 int StageRealTime; // If 1, Invoke stage command on demand
211 int StageAsync; // If 1, return EINPROGRESS to the caller
212 int StageCreate; // If 1, use open path to create files
213 int StageFormat; // Format for default stagecmd
214 char *StageCmd; // -> Staging command to use
215 char *StageMsg; // -> Staging message to be passed
216 XrdOucMsubs *StageSnd; // -> Parsed Message
217 XrdFrcProxy *StageFrm; // -> Built-in stagecmd or zero
218 
219 char *StageEvents; // -> file:////<adminpath> if async staging
220 int StageEvSize; // Length of above
221 int StageActLen; // Length of below
222 char *StageAction; // -> "wq " if sync | "wfn " if async
223 
226 int StageAnum; // Count of valid Arg/Aln array elements
227 char *RSSCmd; // -> Remote Storage Service Command
228 int isMSSC; // RSSCmd is old-style msscmd
229 int RSSTout; // RSSCmd response timeout
230 long long MaxSize; // Maximum file size (*obsolete*)
231 int FDFence; // Smallest file FD number allowed
232 int FDLimit; // Largest file FD number allowed
233 unsigned long long DirFlags;// Default directory settings
234 int Trace; // Trace flags
235 int Solitary; // True if running in stand-alone mode
236 int OptFlags; // General option flags
237 
238 char *N2N_Lib; // -> Name2Name Library Path
239 char *N2N_Parms; // -> Name2Name Object Parameters
240 XrdOucName2Name *lcl_N2N; // -> File mapper for local files
241 XrdOucName2Name *rmt_N2N; // -> File mapper for remote files
242 XrdOucName2Name *the_N2N; // -> File mapper object
243 XrdOucPListAnchor RPList; // The real path list
244 OssDPath *DPList; // The stat path list
245 int lenDP;
246 short numDP;
247 short numCG;
248 
249 XrdVersionInfo *myVersion; // Compilation version set by constructor
250 
251  XrdOssSys();
252 virtual ~XrdOssSys() {}
253 
254 protected:
255 // Cache management related data and methods
256 //
257 long long minalloc; // Minimum allocation
258 int ovhalloc; // Allocation overage
259 int fuzalloc; // Allocation fuzz
260 int cscanint; // Seconds between cache scans
261 int xfrspeed; // Average transfer speed (bytes/second)
262 int xfrovhd; // Minimum seconds to get a file
263 int xfrhold; // Second hold limit on failing requests
264 int xfrkeep; // Second keep queued requests
265 int xfrthreads; // Number of threads for staging
266 int xfrtcount; // Actual count of threads (used for dtr)
267 long long pndbytes; // Total bytes to be staged (pending)
268 long long stgbytes; // Total bytes being staged (active)
269 long long totbytes; // Total bytes were staged (active+pending)
270 int totreqs; // Total successful requests
271 int badreqs; // Total unsuccessful requests
272 
273 XrdOucProg *StageProg; // Command or manager than handles staging
274 XrdOucProg *RSSProg; // Command for Remote Storage Services
275 
276 char *UDir; // -> Usage logdir
277 char *QFile; // -> Quota file
278 char *xfrFdir; // -> Fail file base dir
279 int xfrFdln; // strlen(xfrFDir)
280 
283 int BreakLink(const char *local_path, struct stat &statbuff);
284 int CalcTime();
285 int CalcTime(XrdOssStage_Req *req);
286 int SetFattr(XrdOssCreateInfo &crInfo, int datfd, time_t mtime);
287 void doScrub();
288 int Find(XrdOssStage_Req *req, void *carg);
289 int getCname(const char *path, struct stat *sbuff, char *cgbuff);
290 int getStats(char *buff, int blen);
291 int GetFile(XrdOssStage_Req *req);
292 int getID(const char *, XrdOucEnv &, char *, int);
293 time_t HasFile(const char *fn, const char *sfx, time_t *mTime=0);
294 int Stage_QT(const char *, const char *, XrdOucEnv &, int, mode_t);
295 int Stage_RT(const char *, const char *, XrdOucEnv &, unsigned long long);
296 
297 // Configuration related methods
298 //
299 void ConfigMio(XrdSysError &Eroute);
300 int ConfigN2N(XrdSysError &Eroute);
301 int ConfigProc(XrdSysError &Eroute);
302 void ConfigSpace();
303 void ConfigSpace(const char *Lfn);
304 void ConfigSpath(XrdSysError &Eroute, const char *Pn,
305  unsigned long long &Fv, int noMSS);
306 int ConfigStage(XrdSysError &Eroute);
307 int ConfigStageC(XrdSysError &Eroute);
308 void ConfigStats(XrdSysError &Eroute);
309 void ConfigStats(dev_t Devnum, char *lP);
310 int ConfigXeq(char *, XrdOucStream &, XrdSysError &);
311 void List_Path(const char *, const char *, unsigned long long, XrdSysError &);
312 int xalloc(XrdOucStream &Config, XrdSysError &Eroute);
313 int xcache(XrdOucStream &Config, XrdSysError &Eroute);
315 int xdefault(XrdOucStream &Config, XrdSysError &Eroute);
316 int xfdlimit(XrdOucStream &Config, XrdSysError &Eroute);
317 int xmaxsz(XrdOucStream &Config, XrdSysError &Eroute);
318 int xmemf(XrdOucStream &Config, XrdSysError &Eroute);
319 int xnml(XrdOucStream &Config, XrdSysError &Eroute);
320 int xpath(XrdOucStream &Config, XrdSysError &Eroute);
321 int xspace(XrdOucStream &Config, XrdSysError &Eroute, int *isCD=0);
322 int xspaceBuild(char *grp, char *fn, int isxa, XrdSysError &Eroute);
323 int xstg(XrdOucStream &Config, XrdSysError &Eroute);
324 int xusage(XrdOucStream &Config, XrdSysError &Eroute);
325 int xtrace(XrdOucStream &Config, XrdSysError &Eroute);
326 int xxfr(XrdOucStream &Config, XrdSysError &Eroute);
327 
328 // Mass storage related methods
329 //
330 int tranmode(char *);
331 int MSS_Xeq(XrdOucStream **xfd, int okerr,
332  const char *cmd, const char *arg1=0, const char *arg2=0);
333 
334 // Other methods
335 //
336 int RenameLink(char *old_path, char *new_path);
337 int RenameLink2(int Llen, char *oLnk, char *old_path,
338  char *nLnk, char *new_path);
339 int RenameLink3(char *cPath, char *old_path, char *new_path);
340 };
341 
342 /******************************************************************************/
343 /* A P I S p e c i f i c D e f i n e s */
344 /******************************************************************************/
345 
346 // The Check_RO macro is valid only for XrdOssSys objects.
347 //
348 #define Check_RO(act, flags, path, opname) \
349  XRDEXP_REMOTE & (flags = PathOpts(path)); \
350  if (flags & XRDEXP_NOTRW) \
351  return OssEroute.Emsg(#act, -XRDOSS_E8005, opname, path)
352 #endif