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 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <string.h>
14 #include <dirent.h>
15 #include <sys/types.h>
16 
17 #include "XrdOfs/XrdOfsEvr.hh"
18 #include "XrdOfs/XrdOfsHandle.hh"
19 #include "XrdOss/XrdOss.hh"
20 #include "XrdSys/XrdSysPthread.hh"
21 #include "XrdOuc/XrdOucPList.hh"
23 #include "XrdCms/XrdCmsClient.hh"
24 
25 class XrdOfsEvs;
26 class XrdOfsPocq;
27 class XrdOss;
28 class XrdOssDir;
29 class XrdOucEnv;
30 class XrdSysError;
31 class XrdSysLogger;
32 class XrdOucStream;
33 class XrdSfsAio;
34 
35 /******************************************************************************/
36 /* X r d O f s D i r e c t o r y */
37 /******************************************************************************/
38 
40 {
41 public:
42 
43  int open(const char *dirName,
44  const XrdSecEntity *client,
45  const char *opaque = 0);
46 
47  const char *nextEntry();
48 
49  int close();
50 
51 inline void copyError(XrdOucErrInfo &einfo) {einfo = error;}
52 
53 const char *FName() {return (const char *)fname;}
54 
55  XrdOfsDirectory(const char *user, int MonID)
56  : XrdSfsDirectory(user, MonID)
57  {dp = 0;
58  tident = (user ? user : "");
59  fname=0; atEOF=0;
60  }
61 virtual ~XrdOfsDirectory() {if (dp) close();}
62 
63 protected:
64 const char *tident;
65 char *fname;
66 
67 private:
69 int atEOF;
70 char dname[MAXNAMLEN];
71 };
72 
73 /******************************************************************************/
74 /* X r d O f s F i l e */
75 /******************************************************************************/
76 
77 class XrdOfsFile : public XrdSfsFile
78 {
79 public:
80 
81  int open(const char *fileName,
82  XrdSfsFileOpenMode openMode,
83  mode_t createMode,
84  const XrdSecEntity *client,
85  const char *opaque = 0);
86 
87  int close();
88 
89 virtual int fctl(const int cmd,
90  const char *args,
91  XrdOucErrInfo &out_error);
92 
93  const char *FName() {return (oh ? oh->Name() : "?");}
94 
95  int getMmap(void **Addr, off_t &Size);
96 
97  int read(XrdSfsFileOffset fileOffset, // Preread only
98  XrdSfsXferSize amount);
99 
101  char *buffer,
102  XrdSfsXferSize buffer_size);
103 
104  int read(XrdSfsAio *aioparm);
105 
107  const char *buffer,
108  XrdSfsXferSize buffer_size);
109 
110  int write(XrdSfsAio *aioparm);
111 
112  int sync();
113 
114  int sync(XrdSfsAio *aiop);
115 
116  int stat(struct stat *buf);
117 
118  int truncate(XrdSfsFileOffset fileOffset);
119 
120  int getCXinfo(char cxtype[4], int &cxrsz);
121 
122  XrdOfsFile(const char *user, int MonID);
123 
124 virtual ~XrdOfsFile() {viaDel = 1; if (oh) close();}
125 
126 protected:
127  const char *tident;
128 
129 private:
130 
131 void GenFWEvent();
132 
135 char viaDel;
136 };
137 
138 /******************************************************************************/
139 /* C l a s s X r d O f s */
140 /******************************************************************************/
141 
142 class XrdAccAuthorize;
143 class XrdCks;
144 class XrdCksConfig;
145 class XrdCmsClient;
146 class XrdOfsPoscq;
147 
148 class XrdOfs : public XrdSfsFileSystem
149 {
150 friend class XrdOfsDirectory;
151 friend class XrdOfsFile;
152 
153 public:
154 
155 // Object allocation
156 //
157  XrdSfsDirectory *newDir(char *user=0, int MonID=0)
158  {return (XrdSfsDirectory *)new XrdOfsDirectory(user,MonID);}
159 
160  XrdSfsFile *newFile(char *user=0,int MonID=0)
161  {return (XrdSfsFile *)new XrdOfsFile(user, MonID);}
162 
163 // Other functions
164 //
165  int chksum( csFunc Func,
166  const char *csName,
167  const char *Path,
168  XrdOucErrInfo &out_error,
169  const XrdSecEntity *client = 0,
170  const char *opaque = 0);
171 
172  int chmod(const char *Name,
174  XrdOucErrInfo &out_error,
175  const XrdSecEntity *client,
176  const char *opaque = 0);
177 
178  int exists(const char *fileName,
179  XrdSfsFileExistence &exists_flag,
180  XrdOucErrInfo &out_error,
181  const XrdSecEntity *client,
182  const char *opaque = 0);
183 
184  int fsctl(const int cmd,
185  const char *args,
186  XrdOucErrInfo &out_error,
187  const XrdSecEntity *client);
188 
189  int getStats(char *buff, int blen);
190 
191 const char *getVersion();
192 
193  int mkdir(const char *dirName,
195  XrdOucErrInfo &out_error,
196  const XrdSecEntity *client,
197  const char *opaque = 0);
198 
199  int prepare( XrdSfsPrep &pargs,
200  XrdOucErrInfo &out_error,
201  const XrdSecEntity *client = 0);
202 
203  int rem(const char *path,
204  XrdOucErrInfo &out_error,
205  const XrdSecEntity *client,
206  const char *info = 0)
207  {return remove('f', path, out_error, client, info);}
208 
209  int remdir(const char *dirName,
210  XrdOucErrInfo &out_error,
211  const XrdSecEntity *client,
212  const char *info = 0)
213  {return remove('d',dirName,out_error,client,info);}
214 
215  int rename(const char *oldFileName,
216  const char *newFileName,
217  XrdOucErrInfo &out_error,
218  const XrdSecEntity *client,
219  const char *infoO = 0,
220  const char *infoN = 0);
221 
222  int stat(const char *Name,
223  struct stat *buf,
224  XrdOucErrInfo &out_error,
225  const XrdSecEntity *client,
226  const char *opaque = 0);
227 
228  int stat(const char *Name,
229  mode_t &mode,
230  XrdOucErrInfo &out_error,
231  const XrdSecEntity *client,
232  const char *opaque = 0);
233 
234  int truncate(const char *Name,
235  XrdSfsFileOffset fileOffset,
236  XrdOucErrInfo &out_error,
237  const XrdSecEntity *client = 0,
238  const char *opaque = 0);
239 // Management functions
240 //
241 virtual int Configure(XrdSysError &); // Backward Compatability
242 
243 virtual int Configure(XrdSysError &, XrdOucEnv *);
244 
245  void Config_Cluster(XrdOss *);
246 
247  void Config_Display(XrdSysError &);
248 
249  XrdOfs();
250 virtual ~XrdOfs() {} // Too complicate to delete :-)
251 
252 /******************************************************************************/
253 /* C o n f i g u r a t i o n V a l u e s */
254 /******************************************************************************/
255 
256 // Configuration values for this filesystem
257 //
258 enum {Authorize = 0x0001, // Authorization wanted
259  isPeer = 0x0050, // Role peer
260  isProxy = 0x0020, // Role proxy
261  isManager = 0x0040, // Role manager
262  isServer = 0x0080, // Role server
263  isSuper = 0x00C0, // Role supervisor
264  isMeta = 0x0100, // Role meta + above
265  haveRole = 0x01F0, // A role is present
266  Forwarding= 0x1000 // Fowarding wanted
267  }; // These are set in Options below
268 
269 int Options; // Various options
270 int myPort; // Port number being used
271 
272 // Forward options
273 //
274 struct fwdOpt
275  {const char *Cmd;
276  char *Host;
277  int Port;
278  void Reset() {Cmd = 0; Port = 0;
279  if (Host) {free(Host); Host = 0;}
280  }
281  fwdOpt() : Cmd(0), Host(0), Port(0) {}
282  ~fwdOpt() {}
283  };
284 
288 struct fwdOpt fwdMV;
289 struct fwdOpt fwdRM;
292 
293 static int MaxDelay; // Max delay imposed during staging
294 static int OSSDelay; // Delay to impose when oss interface times out
295 
296 char *HostName; // ->Our hostname
297 char *HostPref; // ->Our hostname with domain removed
298 char *ConfigFN; // ->Configuration filename
299 char *OssLib; // ->Oss Library
300 char *CmsLib; // ->Cms Library
301 char *CmsParms; // ->Cms Library Parameters
302 
303 /******************************************************************************/
304 /* P r o t e c t e d I t e m s */
305 /******************************************************************************/
306 
307 protected:
308 
309 XrdOfsEvr evrObject; // Event receiver
310 XrdCmsClient *Finder; // ->Cluster Management Service
311 
312 virtual int ConfigXeq(char *var, XrdOucStream &, XrdSysError &);
313 static int Emsg(const char *, XrdOucErrInfo &, int, const char *x,
314  XrdOfsHandle *hP);
315 static int Emsg(const char *, XrdOucErrInfo &, int, const char *x,
316  const char *y="");
317 static int fsError(XrdOucErrInfo &myError, int rc);
318 const char *Split(const char *Args, const char **Opq, char *Path, int Plen);
319  int Stall(XrdOucErrInfo &, int, const char *);
320  void Unpersist(XrdOfsHandle *hP, int xcev=1);
321  char *WaitTime(int, char *, int);
322 
323 /******************************************************************************/
324 /* P r i v a t e C o n f i g u r a t i o n */
325 /******************************************************************************/
326 
327 private:
328 
329 char *AuthLib; // ->Authorization Library
330 char *AuthParm; // ->Authorization Parameters
331 char *myRole;
332 XrdAccAuthorize *Authorization; // ->Authorization Service
333 XrdCmsClient *Balancer; // ->Cluster Local Interface
334 XrdOfsEvs *evsObject; // ->Event Notifier
335 char *locResp; // ->Locate Response
336 int locRlen; // Length of locResp;
337 
338 XrdOfsPoscq *poscQ; // -> poscQ if persist on close enabled
339 char *poscLog; // -> Directory for posc recovery log
340 int poscHold; // Seconds to hold a forced close
341 int poscAuto; // 1 -> Automatic persist on close
342 
343 XrdCksConfig *CksConfig; // Checksum configurator
344 XrdCks *Cks; // Checksum manager
345 int CksRdsz; // Checksum read size
346 
348 XrdSysMutex ocMutex; // Global mutex for open/close
349 
350 /******************************************************************************/
351 /* O t h e r D a t a */
352 /******************************************************************************/
353 
354 // Common functions
355 //
356  int remove(const char type, const char *path,
357  XrdOucErrInfo &out_error, const XrdSecEntity *client,
358  const char *opaque);
359 
360 // Function used during Configuration
361 //
362 int ConfigDispFwd(char *buff, struct fwdOpt &Fwd);
363 int ConfigPosc(XrdSysError &Eroute);
364 int ConfigRedir(XrdSysError &Eroute, XrdOucEnv *EnvInfo);
365 const char *Fname(const char *);
366 int Forward(int &Result, XrdOucErrInfo &Resp, struct fwdOpt &Fwd,
367  const char *arg1=0, const char *arg2=0,
368  XrdOucEnv *Env1=0, XrdOucEnv *Env2=0);
369 int setupAuth(XrdSysError &);
370 const char *theRole(int opts);
371 int xalib(XrdOucStream &, XrdSysError &);
372 int xclib(XrdOucStream &, XrdSysError &);
373 int xcrds(XrdOucStream &, XrdSysError &);
374 int xcmsl(XrdOucStream &, XrdSysError &);
376 int xmaxd(XrdOucStream &, XrdSysError &);
377 int xnmsg(XrdOucStream &, XrdSysError &);
378 int xnot(XrdOucStream &, XrdSysError &);
379 int xolib(XrdOucStream &, XrdSysError &);
380 int xpers(XrdOucStream &, XrdSysError &);
381 int xrole(XrdOucStream &, XrdSysError &);
383 };
384 #endif