xrootd
XrdOfs.hh
Go to the documentation of this file.
1 #ifndef __OFS_API_H__
2 #define __OFS_API_H__
3 /******************************************************************************/
4 /* */
5 /* X r d O f s . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <string.h>
33 #include <dirent.h>
34 #include <sys/types.h>
35 
36 #include "XrdOfs/XrdOfsEvr.hh"
37 #include "XrdOfs/XrdOfsHandle.hh"
38 #include "XrdSys/XrdSysPthread.hh"
40 #include "XrdCms/XrdCmsClient.hh"
41 
42 class XrdOfsEvs;
43 class XrdOfsPocq;
44 class XrdOss;
45 class XrdOssDF;
46 class XrdOssDir;
47 class XrdOucEnv;
48 class XrdSysError;
49 class XrdSysLogger;
50 class XrdOucStream;
51 class XrdSfsAio;
52 
53 struct XrdVersionInfo;
54 
55 /******************************************************************************/
56 /* X r d O f s D i r e c t o r y */
57 /******************************************************************************/
58 
60 {
61 public:
62 
63  int open(const char *dirName,
64  const XrdSecEntity *client,
65  const char *opaque = 0);
66 
67  const char *nextEntry();
68 
69  int close();
70 
71 inline void copyError(XrdOucErrInfo &einfo) {einfo = error;}
72 
73 const char *FName() {return (const char *)fname;}
74 
75  XrdOfsDirectory(const char *user, int MonID)
76  : XrdSfsDirectory(user, MonID)
77  {dp = 0;
78  tident = (user ? user : "");
79  fname=0; atEOF=0;
80  }
81 virtual ~XrdOfsDirectory() {if (dp) close();}
82 
83 protected:
84 const char *tident;
85 char *fname;
86 
87 private:
89 int atEOF;
90 char dname[MAXNAMLEN];
91 };
92 
93 /******************************************************************************/
94 /* X r d O f s F i l e */
95 /******************************************************************************/
96 
97 class XrdOfsTPC;
98 
99 class XrdOfsFile : public XrdSfsFile
100 {
101 public:
102 
103  int open(const char *fileName,
104  XrdSfsFileOpenMode openMode,
105  mode_t createMode,
106  const XrdSecEntity *client,
107  const char *opaque = 0);
108 
109  int close();
110 
111 virtual int fctl(const int cmd,
112  const char *args,
113  XrdOucErrInfo &out_error);
114 
115  const char *FName() {return (oh ? oh->Name() : "?");}
116 
117  int getMmap(void **Addr, off_t &Size);
118 
119  int read(XrdSfsFileOffset fileOffset, // Preread only
120  XrdSfsXferSize amount);
121 
123  char *buffer,
124  XrdSfsXferSize buffer_size);
125 
126  int read(XrdSfsAio *aioparm);
127 
129  const char *buffer,
130  XrdSfsXferSize buffer_size);
131 
132  int write(XrdSfsAio *aioparm);
133 
134  int sync();
135 
136  int sync(XrdSfsAio *aiop);
137 
138  int stat(struct stat *buf);
139 
140  int truncate(XrdSfsFileOffset fileOffset);
141 
142  int getCXinfo(char cxtype[4], int &cxrsz);
143 
144  XrdOfsFile(const char *user, int MonID);
145 
146 virtual ~XrdOfsFile() {viaDel = 1; if (oh) close();}
147 
148 protected:
149  const char *tident;
150 
151 private:
152 
153 void GenFWEvent();
154 
158 char viaDel;
159 };
160 
161 /******************************************************************************/
162 /* C l a s s X r d O f s */
163 /******************************************************************************/
164 
165 class XrdAccAuthorize;
166 class XrdCks;
167 class XrdCksConfig;
168 class XrdCmsClient;
169 class XrdOfsPoscq;
170 
171 class XrdOfs : public XrdSfsFileSystem
172 {
173 friend class XrdOfsDirectory;
174 friend class XrdOfsFile;
175 
176 public:
177 
178 // Object allocation
179 //
180  XrdSfsDirectory *newDir(char *user=0, int MonID=0)
181  {return (XrdSfsDirectory *)new XrdOfsDirectory(user,MonID);}
182 
183  XrdSfsFile *newFile(char *user=0,int MonID=0)
184  {return (XrdSfsFile *)new XrdOfsFile(user, MonID);}
185 
186 // Other functions
187 //
188  int chksum( csFunc Func,
189  const char *csName,
190  const char *Path,
191  XrdOucErrInfo &out_error,
192  const XrdSecEntity *client = 0,
193  const char *opaque = 0);
194 
195  int chmod(const char *Name,
197  XrdOucErrInfo &out_error,
198  const XrdSecEntity *client,
199  const char *opaque = 0);
200 
201  int exists(const char *fileName,
202  XrdSfsFileExistence &exists_flag,
203  XrdOucErrInfo &out_error,
204  const XrdSecEntity *client,
205  const char *opaque = 0);
206 
207  int fsctl(const int cmd,
208  const char *args,
209  XrdOucErrInfo &out_error,
210  const XrdSecEntity *client);
211 
212  int getStats(char *buff, int blen);
213 
214 const char *getVersion();
215 
216  int mkdir(const char *dirName,
218  XrdOucErrInfo &out_error,
219  const XrdSecEntity *client,
220  const char *opaque = 0);
221 
222  int prepare( XrdSfsPrep &pargs,
223  XrdOucErrInfo &out_error,
224  const XrdSecEntity *client = 0);
225 
226  int rem(const char *path,
227  XrdOucErrInfo &out_error,
228  const XrdSecEntity *client,
229  const char *info = 0)
230  {return remove('f', path, out_error, client, info);}
231 
232  int remdir(const char *dirName,
233  XrdOucErrInfo &out_error,
234  const XrdSecEntity *client,
235  const char *info = 0)
236  {return remove('d',dirName,out_error,client,info);}
237 
238  int rename(const char *oldFileName,
239  const char *newFileName,
240  XrdOucErrInfo &out_error,
241  const XrdSecEntity *client,
242  const char *infoO = 0,
243  const char *infoN = 0);
244 
245  int stat(const char *Name,
246  struct stat *buf,
247  XrdOucErrInfo &out_error,
248  const XrdSecEntity *client,
249  const char *opaque = 0);
250 
251  int stat(const char *Name,
252  mode_t &mode,
253  XrdOucErrInfo &out_error,
254  const XrdSecEntity *client,
255  const char *opaque = 0);
256 
257  int truncate(const char *Name,
258  XrdSfsFileOffset fileOffset,
259  XrdOucErrInfo &out_error,
260  const XrdSecEntity *client = 0,
261  const char *opaque = 0);
262 // Management functions
263 //
264 virtual int Configure(XrdSysError &); // Backward Compatability
265 
266 virtual int Configure(XrdSysError &, XrdOucEnv *);
267 
268  void Config_Cluster(XrdOss *);
269 
270  void Config_Display(XrdSysError &);
271 
272  XrdOfs();
273 virtual ~XrdOfs() {} // Too complicate to delete :-)
274 
275 /******************************************************************************/
276 /* C o n f i g u r a t i o n V a l u e s */
277 /******************************************************************************/
278 
279 // Configuration values for this filesystem
280 //
281 enum {Authorize = 0x0001, // Authorization wanted
282  isPeer = 0x0050, // Role peer
283  isProxy = 0x0020, // Role proxy
284  isManager = 0x0040, // Role manager
285  isServer = 0x0080, // Role server
286  isSuper = 0x00C0, // Role supervisor
287  isMeta = 0x0100, // Role meta + above
288  haveRole = 0x01F0, // A role is present
289  Forwarding= 0x1000, // Fowarding wanted
290  ThirdPC = 0x2000 // This party copy wanted
291  }; // These are set in Options below
292 
293 int Options; // Various options
294 int myPort; // Port number being used
295 
296 // Forward options
297 //
298 struct fwdOpt
299  {const char *Cmd;
300  char *Host;
301  int Port;
302  void Reset() {Cmd = 0; Port = 0;
303  if (Host) {free(Host); Host = 0;}
304  }
305  fwdOpt() : Cmd(0), Host(0), Port(0) {}
306  ~fwdOpt() {}
307  };
308 
312 struct fwdOpt fwdMV;
313 struct fwdOpt fwdRM;
316 
317 static int MaxDelay; // Max delay imposed during staging
318 static int OSSDelay; // Delay to impose when oss interface times out
319 
320 char *HostName; // ->Our hostname
321 char *HostPref; // ->Our hostname with domain removed
322 char *ConfigFN; // ->Configuration filename
323 char *OssLib; // ->Oss Library
324 char *OssParms; // ->Oss Library Parameters
325 char *CmsLib; // ->Cms Library
326 char *CmsParms; // ->Cms Library Parameters
327 
328 /******************************************************************************/
329 /* P r o t e c t e d I t e m s */
330 /******************************************************************************/
331 
332 protected:
333 
334 XrdOfsEvr evrObject; // Event receiver
335 XrdCmsClient *Finder; // ->Cluster Management Service
336 
337 virtual int ConfigXeq(char *var, XrdOucStream &, XrdSysError &);
338 static int Emsg(const char *, XrdOucErrInfo &, int, const char *x,
339  XrdOfsHandle *hP);
340 static int Emsg(const char *, XrdOucErrInfo &, int, const char *x,
341  const char *y="");
342 static int fsError(XrdOucErrInfo &myError, int rc);
343 const char *Split(const char *Args, const char **Opq, char *Path, int Plen);
344  int Stall(XrdOucErrInfo &, int, const char *);
345  void Unpersist(XrdOfsHandle *hP, int xcev=1);
346  char *WaitTime(int, char *, int);
347 
348 /******************************************************************************/
349 /* P r i v a t e C o n f i g u r a t i o n */
350 /******************************************************************************/
351 
352 private:
353 
354 char *AuthLib; // ->Authorization Library
355 char *AuthParm; // ->Authorization Parameters
356 char *myRole;
357 XrdAccAuthorize *Authorization; // ->Authorization Service
358 XrdCmsClient *Balancer; // ->Cluster Local Interface
359 XrdOfsEvs *evsObject; // ->Event Notifier
360 char *locResp; // ->Locate Response
361 int locRlen; // Length of locResp;
362 
363 XrdOfsPoscq *poscQ; // -> poscQ if persist on close enabled
364 char *poscLog; // -> Directory for posc recovery log
365 int poscHold; // Seconds to hold a forced close
366 int poscAuto; // 1 -> Automatic persist on close
367 
368 XrdCksConfig *CksConfig; // Checksum configurator
369 XrdCks *Cks; // Checksum manager
370 int CksRdsz; // Checksum read size
371 
372 XrdVersionInfo *myVersion; // Version number compiled against
373 
375 XrdSysMutex ocMutex; // Global mutex for open/close
376 
377 /******************************************************************************/
378 /* O t h e r D a t a */
379 /******************************************************************************/
380 
381 // Common functions
382 //
383  int remove(const char type, const char *path,
384  XrdOucErrInfo &out_error, const XrdSecEntity *client,
385  const char *opaque);
386 
387 // Function used during Configuration
388 //
389 int ConfigDispFwd(char *buff, struct fwdOpt &Fwd);
390 int ConfigPosc(XrdSysError &Eroute);
391 int ConfigRedir(XrdSysError &Eroute, XrdOucEnv *EnvInfo);
392 const char *Fname(const char *);
393 int Forward(int &Result, XrdOucErrInfo &Resp, struct fwdOpt &Fwd,
394  const char *arg1=0, const char *arg2=0,
395  XrdOucEnv *Env1=0, XrdOucEnv *Env2=0);
396 int setupAuth(XrdSysError &);
397 const char *theRole(int opts);
398 int xalib(XrdOucStream &, XrdSysError &);
399 int xclib(XrdOucStream &, XrdSysError &);
400 int xcrds(XrdOucStream &, XrdSysError &);
401 int xcmsl(XrdOucStream &, XrdSysError &);
403 int xmaxd(XrdOucStream &, XrdSysError &);
404 int xnmsg(XrdOucStream &, XrdSysError &);
405 int xnot(XrdOucStream &, XrdSysError &);
406 int xolib(XrdOucStream &, XrdSysError &);
407 int xpers(XrdOucStream &, XrdSysError &);
408 int xrole(XrdOucStream &, XrdSysError &);
409 int xtpc(XrdOucStream &, XrdSysError &);
412 };
413 #endif