xrootd
|
00001 #ifndef __OFS_API_H__ 00002 #define __OFS_API_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O f s . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id$ 00014 00015 #include <string.h> 00016 #include <dirent.h> 00017 #include <sys/types.h> 00018 00019 #include "XrdOfs/XrdOfsEvr.hh" 00020 #include "XrdOfs/XrdOfsHandle.hh" 00021 #include "XrdOss/XrdOss.hh" 00022 #include "XrdSys/XrdSysPthread.hh" 00023 #include "XrdOuc/XrdOucPList.hh" 00024 #include "XrdSfs/XrdSfsInterface.hh" 00025 #include "XrdCms/XrdCmsClient.hh" 00026 00027 class XrdOfsEvs; 00028 class XrdOfsPocq; 00029 class XrdOss; 00030 class XrdOssDir; 00031 class XrdOucEnv; 00032 class XrdSysError; 00033 class XrdSysLogger; 00034 class XrdOucStream; 00035 class XrdSfsAio; 00036 00037 /******************************************************************************/ 00038 /* X r d O f s D i r e c t o r y */ 00039 /******************************************************************************/ 00040 00041 class XrdOfsDirectory : public XrdSfsDirectory 00042 { 00043 public: 00044 00045 int open(const char *dirName, 00046 const XrdSecEntity *client, 00047 const char *opaque = 0); 00048 00049 const char *nextEntry(); 00050 00051 int close(); 00052 00053 inline void copyError(XrdOucErrInfo &einfo) {einfo = error;} 00054 00055 const char *FName() {return (const char *)fname;} 00056 00057 XrdOfsDirectory(const char *user) : XrdSfsDirectory(user) 00058 {dp = 0; 00059 tident = (user ? user : ""); 00060 fname=0; atEOF=0; 00061 } 00062 virtual ~XrdOfsDirectory() {if (dp) close();} 00063 00064 protected: 00065 const char *tident; 00066 char *fname; 00067 00068 private: 00069 XrdOssDF *dp; 00070 int atEOF; 00071 char dname[MAXNAMLEN]; 00072 }; 00073 00074 /******************************************************************************/ 00075 /* X r d O f s F i l e */ 00076 /******************************************************************************/ 00077 00078 class XrdOfsFile : public XrdSfsFile 00079 { 00080 public: 00081 00082 int open(const char *fileName, 00083 XrdSfsFileOpenMode openMode, 00084 mode_t createMode, 00085 const XrdSecEntity *client, 00086 const char *opaque = 0); 00087 00088 int close(); 00089 00090 virtual int fctl(const int cmd, 00091 const char *args, 00092 XrdOucErrInfo &out_error); 00093 00094 const char *FName() {return (oh ? oh->Name() : "?");} 00095 00096 int getMmap(void **Addr, off_t &Size); 00097 00098 int read(XrdSfsFileOffset fileOffset, // Preread only 00099 XrdSfsXferSize amount); 00100 00101 XrdSfsXferSize read(XrdSfsFileOffset fileOffset, 00102 char *buffer, 00103 XrdSfsXferSize buffer_size); 00104 00105 int read(XrdSfsAio *aioparm); 00106 00107 XrdSfsXferSize write(XrdSfsFileOffset fileOffset, 00108 const char *buffer, 00109 XrdSfsXferSize buffer_size); 00110 00111 int write(XrdSfsAio *aioparm); 00112 00113 int sync(); 00114 00115 int sync(XrdSfsAio *aiop); 00116 00117 int stat(struct stat *buf); 00118 00119 int truncate(XrdSfsFileOffset fileOffset); 00120 00121 int getCXinfo(char cxtype[4], int &cxrsz); 00122 00123 XrdOfsFile(const char *user); 00124 00125 virtual ~XrdOfsFile() {viaDel = 1; if (oh) close();} 00126 00127 protected: 00128 const char *tident; 00129 00130 private: 00131 00132 void GenFWEvent(); 00133 00134 XrdOfsHandle *oh; 00135 int dorawio; 00136 char viaDel; 00137 }; 00138 00139 /******************************************************************************/ 00140 /* C l a s s X r d O f s */ 00141 /******************************************************************************/ 00142 00143 class XrdAccAuthorize; 00144 class XrdCmsClient; 00145 class XrdOfsPoscq; 00146 00147 class XrdOfs : public XrdSfsFileSystem 00148 { 00149 friend class XrdOfsDirectory; 00150 friend class XrdOfsFile; 00151 00152 public: 00153 00154 // Object allocation 00155 // 00156 XrdSfsDirectory *newDir(char *user=0) 00157 {return (XrdSfsDirectory *)new XrdOfsDirectory(user);} 00158 00159 XrdSfsFile *newFile(char *user=0) 00160 {return (XrdSfsFile *)new XrdOfsFile(user);} 00161 00162 // Other functions 00163 // 00164 int chmod(const char *Name, 00165 XrdSfsMode Mode, 00166 XrdOucErrInfo &out_error, 00167 const XrdSecEntity *client, 00168 const char *opaque = 0); 00169 00170 int exists(const char *fileName, 00171 XrdSfsFileExistence &exists_flag, 00172 XrdOucErrInfo &out_error, 00173 const XrdSecEntity *client, 00174 const char *opaque = 0); 00175 00176 int fsctl(const int cmd, 00177 const char *args, 00178 XrdOucErrInfo &out_error, 00179 const XrdSecEntity *client); 00180 00181 int getStats(char *buff, int blen); 00182 00183 const char *getVersion(); 00184 00185 int mkdir(const char *dirName, 00186 XrdSfsMode Mode, 00187 XrdOucErrInfo &out_error, 00188 const XrdSecEntity *client, 00189 const char *opaque = 0); 00190 00191 int prepare( XrdSfsPrep &pargs, 00192 XrdOucErrInfo &out_error, 00193 const XrdSecEntity *client = 0); 00194 00195 int rem(const char *path, 00196 XrdOucErrInfo &out_error, 00197 const XrdSecEntity *client, 00198 const char *info = 0) 00199 {return remove('f', path, out_error, client, info);} 00200 00201 int remdir(const char *dirName, 00202 XrdOucErrInfo &out_error, 00203 const XrdSecEntity *client, 00204 const char *info = 0) 00205 {return remove('d',dirName,out_error,client,info);} 00206 00207 int rename(const char *oldFileName, 00208 const char *newFileName, 00209 XrdOucErrInfo &out_error, 00210 const XrdSecEntity *client, 00211 const char *infoO = 0, 00212 const char *infoN = 0); 00213 00214 int stat(const char *Name, 00215 struct stat *buf, 00216 XrdOucErrInfo &out_error, 00217 const XrdSecEntity *client, 00218 const char *opaque = 0); 00219 00220 int stat(const char *Name, 00221 mode_t &mode, 00222 XrdOucErrInfo &out_error, 00223 const XrdSecEntity *client, 00224 const char *opaque = 0); 00225 00226 int truncate(const char *Name, 00227 XrdSfsFileOffset fileOffset, 00228 XrdOucErrInfo &out_error, 00229 const XrdSecEntity *client = 0, 00230 const char *opaque = 0); 00231 // Management functions 00232 // 00233 virtual int Configure(XrdSysError &); 00234 00235 void Config_Cluster(XrdOss *); 00236 00237 void Config_Display(XrdSysError &); 00238 00239 XrdOfs(); 00240 virtual ~XrdOfs() {} // Too complicate to delete :-) 00241 00242 /******************************************************************************/ 00243 /* C o n f i g u r a t i o n V a l u e s */ 00244 /******************************************************************************/ 00245 00246 // Configuration values for this filesystem 00247 // 00248 enum {Authorize = 0x0001, // Authorization wanted 00249 isPeer = 0x0050, // Role peer 00250 isProxy = 0x0020, // Role proxy 00251 isManager = 0x0040, // Role manager 00252 isServer = 0x0080, // Role server 00253 isSuper = 0x00C0, // Role supervisor 00254 isMeta = 0x0100, // Role meta + above 00255 haveRole = 0x01F0, // A role is present 00256 Forwarding= 0x1000 // Fowarding wanted 00257 }; // These are set in Options below 00258 00259 int Options; // Various options 00260 int myPort; // Port number being used 00261 00262 // Forward options 00263 // 00264 struct fwdOpt 00265 {const char *Cmd; 00266 char *Host; 00267 int Port; 00268 void Reset() {Cmd = 0; Port = 0; 00269 if (Host) {free(Host); Host = 0;} 00270 } 00271 fwdOpt() : Cmd(0), Host(0), Port(0) {} 00272 ~fwdOpt() {} 00273 }; 00274 00275 struct fwdOpt fwdCHMOD; 00276 struct fwdOpt fwdMKDIR; 00277 struct fwdOpt fwdMKPATH; 00278 struct fwdOpt fwdMV; 00279 struct fwdOpt fwdRM; 00280 struct fwdOpt fwdRMDIR; 00281 struct fwdOpt fwdTRUNC; 00282 00283 static int MaxDelay; // Max delay imposed during staging 00284 static int OSSDelay; // Delay to impose when oss interface times out 00285 00286 char *HostName; // ->Our hostname 00287 char *HostPref; // ->Our hostname with domain removed 00288 char *ConfigFN; // ->Configuration filename 00289 char *OssLib; // ->Oss Library 00290 00291 /******************************************************************************/ 00292 /* P r o t e c t e d I t e m s */ 00293 /******************************************************************************/ 00294 00295 protected: 00296 00297 XrdOfsEvr evrObject; // Event receiver 00298 XrdCmsClient *Finder; // ->Cluster Management Service 00299 00300 virtual int ConfigXeq(char *var, XrdOucStream &, XrdSysError &); 00301 static int Emsg(const char *, XrdOucErrInfo &, int, const char *x, 00302 XrdOfsHandle *hP); 00303 static int Emsg(const char *, XrdOucErrInfo &, int, const char *x, 00304 const char *y=""); 00305 static int fsError(XrdOucErrInfo &myError, int rc); 00306 int Stall(XrdOucErrInfo &, int, const char *); 00307 void Unpersist(XrdOfsHandle *hP, int xcev=1); 00308 char *WaitTime(int, char *, int); 00309 00310 /******************************************************************************/ 00311 /* P r i v a t e C o n f i g u r a t i o n */ 00312 /******************************************************************************/ 00313 00314 private: 00315 00316 char *AuthLib; // ->Authorization Library 00317 char *AuthParm; // ->Authorization Parameters 00318 char *myRole; 00319 XrdAccAuthorize *Authorization; // ->Authorization Service 00320 XrdCmsClient *Balancer; // ->Cluster Local Interface 00321 XrdOfsEvs *evsObject; // ->Event Notifier 00322 char *locResp; // ->Locate Response 00323 int locRlen; // Length of locResp; 00324 00325 XrdOfsPoscq *poscQ; // -> poscQ if persist on close enabled 00326 char *poscLog; // -> Directory for posc recovery log 00327 int poscHold; // Seconds to hold a forced close 00328 int poscAuto; // 1 -> Automatic persist on close 00329 00330 static XrdOfsHandle *dummyHandle; 00331 XrdSysMutex ocMutex; // Global mutex for open/close 00332 00333 /******************************************************************************/ 00334 /* O t h e r D a t a */ 00335 /******************************************************************************/ 00336 00337 // Common functions 00338 // 00339 int remove(const char type, const char *path, 00340 XrdOucErrInfo &out_error, const XrdSecEntity *client, 00341 const char *opaque); 00342 00343 // Function used during Configuration 00344 // 00345 int ConfigDispFwd(char *buff, struct fwdOpt &Fwd); 00346 int ConfigPosc(XrdSysError &Eroute); 00347 int ConfigRedir(XrdSysError &Eroute); 00348 const char *Fname(const char *); 00349 int Forward(int &Result, XrdOucErrInfo &Resp, struct fwdOpt &Fwd, 00350 const char *arg1=0, const char *arg2=0, 00351 const char *arg3=0, const char *arg4=0); 00352 int setupAuth(XrdSysError &); 00353 const char *theRole(int opts); 00354 int xalib(XrdOucStream &, XrdSysError &); 00355 int xforward(XrdOucStream &, XrdSysError &); 00356 int xmaxd(XrdOucStream &, XrdSysError &); 00357 int xnmsg(XrdOucStream &, XrdSysError &); 00358 int xnot(XrdOucStream &, XrdSysError &); 00359 int xolib(XrdOucStream &, XrdSysError &); 00360 int xpers(XrdOucStream &, XrdSysError &); 00361 int xred(XrdOucStream &, XrdSysError &); 00362 int xrole(XrdOucStream &, XrdSysError &); 00363 int xtrace(XrdOucStream &, XrdSysError &); 00364 }; 00365 #endif