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