|
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 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #include <string.h> 00033 #include <dirent.h> 00034 #include <sys/types.h> 00035 00036 #include "XrdOfs/XrdOfsEvr.hh" 00037 #include "XrdOfs/XrdOfsHandle.hh" 00038 #include "XrdSys/XrdSysPthread.hh" 00039 #include "XrdSfs/XrdSfsInterface.hh" 00040 #include "XrdCms/XrdCmsClient.hh" 00041 00042 class XrdOfsEvs; 00043 class XrdOfsPocq; 00044 class XrdOss; 00045 class XrdOssDF; 00046 class XrdOssDir; 00047 class XrdOucEnv; 00048 class XrdSysError; 00049 class XrdSysLogger; 00050 class XrdOucStream; 00051 class XrdSfsAio; 00052 00053 struct XrdVersionInfo; 00054 00055 /******************************************************************************/ 00056 /* X r d O f s D i r e c t o r y */ 00057 /******************************************************************************/ 00058 00059 class XrdOfsDirectory : public XrdSfsDirectory 00060 { 00061 public: 00062 00063 int open(const char *dirName, 00064 const XrdSecEntity *client, 00065 const char *opaque = 0); 00066 00067 const char *nextEntry(); 00068 00069 int close(); 00070 00071 inline void copyError(XrdOucErrInfo &einfo) {einfo = error;} 00072 00073 const char *FName() {return (const char *)fname;} 00074 00075 XrdOfsDirectory(const char *user, int MonID) 00076 : XrdSfsDirectory(user, MonID) 00077 {dp = 0; 00078 tident = (user ? user : ""); 00079 fname=0; atEOF=0; 00080 } 00081 virtual ~XrdOfsDirectory() {if (dp) close();} 00082 00083 protected: 00084 const char *tident; 00085 char *fname; 00086 00087 private: 00088 XrdOssDF *dp; 00089 int atEOF; 00090 char dname[MAXNAMLEN]; 00091 }; 00092 00093 /******************************************************************************/ 00094 /* X r d O f s F i l e */ 00095 /******************************************************************************/ 00096 00097 class XrdOfsTPC; 00098 00099 class XrdOfsFile : public XrdSfsFile 00100 { 00101 public: 00102 00103 int open(const char *fileName, 00104 XrdSfsFileOpenMode openMode, 00105 mode_t createMode, 00106 const XrdSecEntity *client, 00107 const char *opaque = 0); 00108 00109 int close(); 00110 00111 virtual int fctl(const int cmd, 00112 const char *args, 00113 XrdOucErrInfo &out_error); 00114 00115 const char *FName() {return (oh ? oh->Name() : "?");} 00116 00117 int getMmap(void **Addr, off_t &Size); 00118 00119 int read(XrdSfsFileOffset fileOffset, // Preread only 00120 XrdSfsXferSize amount); 00121 00122 XrdSfsXferSize read(XrdSfsFileOffset fileOffset, 00123 char *buffer, 00124 XrdSfsXferSize buffer_size); 00125 00126 int read(XrdSfsAio *aioparm); 00127 00128 XrdSfsXferSize write(XrdSfsFileOffset fileOffset, 00129 const char *buffer, 00130 XrdSfsXferSize buffer_size); 00131 00132 int write(XrdSfsAio *aioparm); 00133 00134 int sync(); 00135 00136 int sync(XrdSfsAio *aiop); 00137 00138 int stat(struct stat *buf); 00139 00140 int truncate(XrdSfsFileOffset fileOffset); 00141 00142 int getCXinfo(char cxtype[4], int &cxrsz); 00143 00144 XrdOfsFile(const char *user, int MonID); 00145 00146 virtual ~XrdOfsFile() {viaDel = 1; if (oh) close();} 00147 00148 protected: 00149 const char *tident; 00150 00151 private: 00152 00153 void GenFWEvent(); 00154 00155 XrdOfsHandle *oh; 00156 XrdOfsTPC *myTPC; 00157 int dorawio; 00158 char viaDel; 00159 }; 00160 00161 /******************************************************************************/ 00162 /* C l a s s X r d O f s */ 00163 /******************************************************************************/ 00164 00165 class XrdAccAuthorize; 00166 class XrdCks; 00167 class XrdCksConfig; 00168 class XrdCmsClient; 00169 class XrdOfsPoscq; 00170 00171 class XrdOfs : public XrdSfsFileSystem 00172 { 00173 friend class XrdOfsDirectory; 00174 friend class XrdOfsFile; 00175 00176 public: 00177 00178 // Object allocation 00179 // 00180 XrdSfsDirectory *newDir(char *user=0, int MonID=0) 00181 {return (XrdSfsDirectory *)new XrdOfsDirectory(user,MonID);} 00182 00183 XrdSfsFile *newFile(char *user=0,int MonID=0) 00184 {return (XrdSfsFile *)new XrdOfsFile(user, MonID);} 00185 00186 // Other functions 00187 // 00188 int chksum( csFunc Func, 00189 const char *csName, 00190 const char *Path, 00191 XrdOucErrInfo &out_error, 00192 const XrdSecEntity *client = 0, 00193 const char *opaque = 0); 00194 00195 int chmod(const char *Name, 00196 XrdSfsMode Mode, 00197 XrdOucErrInfo &out_error, 00198 const XrdSecEntity *client, 00199 const char *opaque = 0); 00200 00201 int exists(const char *fileName, 00202 XrdSfsFileExistence &exists_flag, 00203 XrdOucErrInfo &out_error, 00204 const XrdSecEntity *client, 00205 const char *opaque = 0); 00206 00207 int fsctl(const int cmd, 00208 const char *args, 00209 XrdOucErrInfo &out_error, 00210 const XrdSecEntity *client); 00211 00212 int getStats(char *buff, int blen); 00213 00214 const char *getVersion(); 00215 00216 int mkdir(const char *dirName, 00217 XrdSfsMode Mode, 00218 XrdOucErrInfo &out_error, 00219 const XrdSecEntity *client, 00220 const char *opaque = 0); 00221 00222 int prepare( XrdSfsPrep &pargs, 00223 XrdOucErrInfo &out_error, 00224 const XrdSecEntity *client = 0); 00225 00226 int rem(const char *path, 00227 XrdOucErrInfo &out_error, 00228 const XrdSecEntity *client, 00229 const char *info = 0) 00230 {return remove('f', path, out_error, client, info);} 00231 00232 int remdir(const char *dirName, 00233 XrdOucErrInfo &out_error, 00234 const XrdSecEntity *client, 00235 const char *info = 0) 00236 {return remove('d',dirName,out_error,client,info);} 00237 00238 int rename(const char *oldFileName, 00239 const char *newFileName, 00240 XrdOucErrInfo &out_error, 00241 const XrdSecEntity *client, 00242 const char *infoO = 0, 00243 const char *infoN = 0); 00244 00245 int stat(const char *Name, 00246 struct stat *buf, 00247 XrdOucErrInfo &out_error, 00248 const XrdSecEntity *client, 00249 const char *opaque = 0); 00250 00251 int stat(const char *Name, 00252 mode_t &mode, 00253 XrdOucErrInfo &out_error, 00254 const XrdSecEntity *client, 00255 const char *opaque = 0); 00256 00257 int truncate(const char *Name, 00258 XrdSfsFileOffset fileOffset, 00259 XrdOucErrInfo &out_error, 00260 const XrdSecEntity *client = 0, 00261 const char *opaque = 0); 00262 // Management functions 00263 // 00264 virtual int Configure(XrdSysError &); // Backward Compatability 00265 00266 virtual int Configure(XrdSysError &, XrdOucEnv *); 00267 00268 void Config_Cluster(XrdOss *); 00269 00270 void Config_Display(XrdSysError &); 00271 00272 XrdOfs(); 00273 virtual ~XrdOfs() {} // Too complicate to delete :-) 00274 00275 /******************************************************************************/ 00276 /* C o n f i g u r a t i o n V a l u e s */ 00277 /******************************************************************************/ 00278 00279 // Configuration values for this filesystem 00280 // 00281 enum {Authorize = 0x0001, // Authorization wanted 00282 isPeer = 0x0050, // Role peer 00283 isProxy = 0x0020, // Role proxy 00284 isManager = 0x0040, // Role manager 00285 isServer = 0x0080, // Role server 00286 isSuper = 0x00C0, // Role supervisor 00287 isMeta = 0x0100, // Role meta + above 00288 haveRole = 0x01F0, // A role is present 00289 Forwarding= 0x1000, // Fowarding wanted 00290 ThirdPC = 0x2000 // This party copy wanted 00291 }; // These are set in Options below 00292 00293 int Options; // Various options 00294 int myPort; // Port number being used 00295 00296 // Forward options 00297 // 00298 struct fwdOpt 00299 {const char *Cmd; 00300 char *Host; 00301 int Port; 00302 void Reset() {Cmd = 0; Port = 0; 00303 if (Host) {free(Host); Host = 0;} 00304 } 00305 fwdOpt() : Cmd(0), Host(0), Port(0) {} 00306 ~fwdOpt() {} 00307 }; 00308 00309 struct fwdOpt fwdCHMOD; 00310 struct fwdOpt fwdMKDIR; 00311 struct fwdOpt fwdMKPATH; 00312 struct fwdOpt fwdMV; 00313 struct fwdOpt fwdRM; 00314 struct fwdOpt fwdRMDIR; 00315 struct fwdOpt fwdTRUNC; 00316 00317 static int MaxDelay; // Max delay imposed during staging 00318 static int OSSDelay; // Delay to impose when oss interface times out 00319 00320 char *HostName; // ->Our hostname 00321 char *HostPref; // ->Our hostname with domain removed 00322 char *ConfigFN; // ->Configuration filename 00323 char *OssLib; // ->Oss Library 00324 char *OssParms; // ->Oss Library Parameters 00325 char *CmsLib; // ->Cms Library 00326 char *CmsParms; // ->Cms Library Parameters 00327 00328 /******************************************************************************/ 00329 /* P r o t e c t e d I t e m s */ 00330 /******************************************************************************/ 00331 00332 protected: 00333 00334 XrdOfsEvr evrObject; // Event receiver 00335 XrdCmsClient *Finder; // ->Cluster Management Service 00336 00337 virtual int ConfigXeq(char *var, XrdOucStream &, XrdSysError &); 00338 static int Emsg(const char *, XrdOucErrInfo &, int, const char *x, 00339 XrdOfsHandle *hP); 00340 static int Emsg(const char *, XrdOucErrInfo &, int, const char *x, 00341 const char *y=""); 00342 static int fsError(XrdOucErrInfo &myError, int rc); 00343 const char *Split(const char *Args, const char **Opq, char *Path, int Plen); 00344 int Stall(XrdOucErrInfo &, int, const char *); 00345 void Unpersist(XrdOfsHandle *hP, int xcev=1); 00346 char *WaitTime(int, char *, int); 00347 00348 /******************************************************************************/ 00349 /* P r i v a t e C o n f i g u r a t i o n */ 00350 /******************************************************************************/ 00351 00352 private: 00353 00354 char *AuthLib; // ->Authorization Library 00355 char *AuthParm; // ->Authorization Parameters 00356 char *myRole; 00357 XrdAccAuthorize *Authorization; // ->Authorization Service 00358 XrdCmsClient *Balancer; // ->Cluster Local Interface 00359 XrdOfsEvs *evsObject; // ->Event Notifier 00360 char *locResp; // ->Locate Response 00361 int locRlen; // Length of locResp; 00362 00363 XrdOfsPoscq *poscQ; // -> poscQ if persist on close enabled 00364 char *poscLog; // -> Directory for posc recovery log 00365 int poscHold; // Seconds to hold a forced close 00366 int poscAuto; // 1 -> Automatic persist on close 00367 00368 XrdCksConfig *CksConfig; // Checksum configurator 00369 XrdCks *Cks; // Checksum manager 00370 int CksRdsz; // Checksum read size 00371 00372 XrdVersionInfo *myVersion; // Version number compiled against 00373 00374 static XrdOfsHandle *dummyHandle; 00375 XrdSysMutex ocMutex; // Global mutex for open/close 00376 00377 /******************************************************************************/ 00378 /* O t h e r D a t a */ 00379 /******************************************************************************/ 00380 00381 // Common functions 00382 // 00383 int remove(const char type, const char *path, 00384 XrdOucErrInfo &out_error, const XrdSecEntity *client, 00385 const char *opaque); 00386 00387 // Function used during Configuration 00388 // 00389 int ConfigDispFwd(char *buff, struct fwdOpt &Fwd); 00390 int ConfigPosc(XrdSysError &Eroute); 00391 int ConfigRedir(XrdSysError &Eroute, XrdOucEnv *EnvInfo); 00392 const char *Fname(const char *); 00393 int Forward(int &Result, XrdOucErrInfo &Resp, struct fwdOpt &Fwd, 00394 const char *arg1=0, const char *arg2=0, 00395 XrdOucEnv *Env1=0, XrdOucEnv *Env2=0); 00396 int setupAuth(XrdSysError &); 00397 const char *theRole(int opts); 00398 int xalib(XrdOucStream &, XrdSysError &); 00399 int xclib(XrdOucStream &, XrdSysError &); 00400 int xcrds(XrdOucStream &, XrdSysError &); 00401 int xcmsl(XrdOucStream &, XrdSysError &); 00402 int xforward(XrdOucStream &, XrdSysError &); 00403 int xmaxd(XrdOucStream &, XrdSysError &); 00404 int xnmsg(XrdOucStream &, XrdSysError &); 00405 int xnot(XrdOucStream &, XrdSysError &); 00406 int xolib(XrdOucStream &, XrdSysError &); 00407 int xpers(XrdOucStream &, XrdSysError &); 00408 int xrole(XrdOucStream &, XrdSysError &); 00409 int xtpc(XrdOucStream &, XrdSysError &); 00410 int xtpcal(XrdOucStream &, XrdSysError &); 00411 int xtrace(XrdOucStream &, XrdSysError &); 00412 }; 00413 #endif
1.7.6.1