xrootd
XrdOssApi.hh
Go to the documentation of this file.
00001 #ifndef _XRDOSS_API_H
00002 #define _XRDOSS_API_H
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                          X r d O s s A p i . h h                           */
00006 /*                                                                            */
00007 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00033 #include <sys/types.h>
00034 #include <errno.h>
00035 #include "XrdSys/XrdSysHeaders.hh"
00036 
00037 #include "XrdOss/XrdOss.hh"
00038 #include "XrdOss/XrdOssConfig.hh"
00039 #include "XrdOss/XrdOssError.hh"
00040 #include "XrdOuc/XrdOucExport.hh"
00041 #include "XrdOuc/XrdOucPList.hh"
00042 #include "XrdOuc/XrdOucStream.hh"
00043 #include "XrdSys/XrdSysError.hh"
00044 #include "XrdSys/XrdSysPthread.hh"
00045 
00046 /******************************************************************************/
00047 /*                              o o s s _ D i r                               */
00048 /******************************************************************************/
00049 
00050 class XrdOssDir : public XrdOssDF
00051 {
00052 public:
00053 int     Close(long long *retsz=0);
00054 int     Opendir(const char *, XrdOucEnv &);
00055 int     Readdir(char *buff, int blen);
00056 
00057         // Constructor and destructor
00058         XrdOssDir(const char *tid) 
00059                  {lclfd=0; mssfd=0; pflags=ateof=isopen=0; tident=tid;}
00060        ~XrdOssDir() {if (isopen > 0) Close(); isopen = 0;}
00061 private:
00062          DIR       *lclfd;
00063          void      *mssfd;
00064 const    char      *tident;
00065 unsigned long long  pflags;
00066          int        ateof;
00067          int        isopen;
00068 };
00069   
00070 /******************************************************************************/
00071 /*                             o o s s _ F i l e                              */
00072 /******************************************************************************/
00073 
00074 class oocx_CXFile;
00075 class XrdSfsAio;
00076 class XrdOssCache_FS;
00077 class XrdOssMioFile;
00078   
00079 class XrdOssFile : public XrdOssDF
00080 {
00081 public:
00082 
00083 // The following two are virtual functions to allow for upcasting derivations
00084 // of this implementation
00085 //
00086 virtual int     Close(long long *retsz=0);
00087 virtual int     Open(const char *, int, mode_t, XrdOucEnv &);
00088 
00089 int     Fchmod(mode_t mode);
00090 int     Fstat(struct stat *);
00091 int     Fsync();
00092 int     Fsync(XrdSfsAio *aiop);
00093 int     Ftruncate(unsigned long long);
00094 int     getFD() {return fd;}
00095 off_t   getMmap(void **addr);
00096 int     isCompressed(char *cxidp=0);
00097 ssize_t Read(               off_t, size_t);
00098 ssize_t Read(       void *, off_t, size_t);
00099 int     Read(XrdSfsAio *aiop);
00100 ssize_t ReadRaw(    void *, off_t, size_t);
00101 ssize_t Write(const void *, off_t, size_t);
00102 int     Write(XrdSfsAio *aiop);
00103  
00104         // Constructor and destructor
00105         XrdOssFile(const char *tid)
00106                   {cxobj = 0; rawio = 0; cxpgsz = 0; cxid[0] = '\0';
00107                    mmFile = 0; tident = tid;
00108                   }
00109 
00110 virtual ~XrdOssFile() {if (fd >= 0) Close();}
00111 
00112 private:
00113 int     Open_ufs(const char *, int, int, unsigned long long);
00114 
00115 static int      AioFailure;
00116 oocx_CXFile    *cxobj;
00117 XrdOssCache_FS *cacheP;
00118 XrdOssMioFile  *mmFile;
00119 const char     *tident;
00120 long long       FSize;
00121 int             rawio;
00122 int             cxpgsz;
00123 char            cxid[4];
00124 };
00125 
00126 /******************************************************************************/
00127 /*                              o o s s _ S y s                               */
00128 /******************************************************************************/
00129   
00130 class XrdFrcProxy;
00131 class XrdOssCache_Group;
00132 class XrdOssCache_Space;
00133 class XrdOssCreateInfo;
00134 class XrdOucMsubs;
00135 class XrdOucName2Name;
00136 class XrdOucProg;
00137 class XrdOssSpace;
00138 class XrdOssStage_Req;
00139 
00140 struct XrdVersionInfo;
00141 
00142 class XrdOssSys : public XrdOss
00143 {
00144 public:
00145 virtual XrdOssDF *newDir(const char *tident)
00146                        {return (XrdOssDF *)new XrdOssDir(tident);}
00147 virtual XrdOssDF *newFile(const char *tident)
00148                        {return (XrdOssDF *)new XrdOssFile(tident);}
00149 
00150 int       Chmod(const char *, mode_t mode, XrdOucEnv *eP=0);
00151 int       Configure(const char *, XrdSysError &);
00152 void      Config_Display(XrdSysError &);
00153 virtual
00154 int       Create(const char *, const char *, mode_t, XrdOucEnv &, int opts=0);
00155 int       GenLocalPath(const char *, char *);
00156 int       GenRemotePath(const char *, char *);
00157 int       Init(XrdSysLogger *, const char *);
00158 int       IsRemote(const char *path) 
00159                   {return (RPList.Find(path) & XRDEXP_REMOTE) != 0;}
00160 int       Lfn2Pfn(const char *Path, char *buff, int blen);
00161 const char *Lfn2Pfn(const char *Path, char *buff, int blen, int &rc);
00162 int       Mkdir(const char *, mode_t mode, int mkpath=0, XrdOucEnv *eP=0);
00163 int       Mkpath(const char *, mode_t mode);
00164 unsigned long long PathOpts(const char *path) {return RPList.Find(path);}
00165 int       Reloc(const char *tident, const char *path,
00166                 const char *cgName, const char *anchor=0);
00167 int       Remdir(const char *, int Opts=0, XrdOucEnv *eP=0);  // In Unlink()
00168 int       Rename(const char *, const char *,
00169                  XrdOucEnv *eP1=0, XrdOucEnv *eP2=0);
00170 virtual 
00171 int       Stage(const char *, const char *, XrdOucEnv &, int, mode_t, unsigned long long );
00172 void     *Stage_In(void *carg);
00173 int       Stat(const char *, struct stat *, int opts=0, XrdOucEnv *Env=0);
00174 int       StatFS(const char *path, char *buff, int &blen, XrdOucEnv *Env=0);
00175 int       StatFS(const char *path, unsigned long long &Opt,
00176                  long long &fSize, long long &fSpace);
00177 int       StatLS(XrdOucEnv &env, const char *path, char *buff, int &blen);
00178 int       StatVS(XrdOssVSInfo *sP, const char *sname=0, int updt=0);
00179 int       StatXA(const char *path, char *buff, int &blen, XrdOucEnv *Env=0);
00180 int       StatXP(const char *path, unsigned long long &attr, XrdOucEnv *Env=0);
00181 int       Truncate(const char *, unsigned long long Size, XrdOucEnv *eP=0);
00182 int       Unlink(const char *, int Opts=0, XrdOucEnv *eP=0);
00183 
00184 int       Stats(char *bp, int bl);
00185 
00186 static int   AioInit();
00187 static int   AioAllOk;
00188 
00189 static int   runOld;            // Run in backward compatability mode
00190 
00191 static char  tryMmap;           // Memory mapped files enabled
00192 static char  chkMmap;           // Memory mapped files are selective
00193    
00194 int       MSS_Closedir(void *);
00195 int       MSS_Create(const char *path, mode_t, XrdOucEnv &);
00196 void     *MSS_Opendir(const char *, int &rc);
00197 int       MSS_Readdir(void *fd, char *buff, int blen);
00198 int       MSS_Remdir(const char *, const char *) {return -ENOTSUP;}
00199 int       MSS_Rename(const char *, const char *);
00200 int       MSS_Stat(const char *, struct stat *buff=0);
00201 int       MSS_Unlink(const char *);
00202 
00203 static const int MaxArgs = 15;
00204 
00205 char     *ConfigFN;       // -> Pointer to the config file name
00206 int       Hard_FD_Limit;  //    Hard file descriptor limit
00207 int       MaxTwiddle;     //    Maximum seconds of internal wait
00208 char     *LocalRoot;      // -> Path prefix for local  filename
00209 char     *RemoteRoot;     // -> Path prefix for remote filename
00210 int       StageRealTime;  //    If 1, Invoke stage command on demand
00211 int       StageAsync;     //    If 1, return EINPROGRESS to the caller
00212 int       StageCreate;    //    If 1, use open path to create files
00213 int       StageFormat;    //    Format for default stagecmd
00214 char     *StageCmd;       // -> Staging command to use
00215 char     *StageMsg;       // -> Staging message to be passed
00216 XrdOucMsubs *StageSnd;    // -> Parsed Message
00217 XrdFrcProxy *StageFrm;    // -> Built-in stagecmd or zero
00218 
00219 char     *StageEvents;    // -> file:////<adminpath> if async staging
00220 int       StageEvSize;    //    Length of above
00221 int       StageActLen;    //    Length of below
00222 char     *StageAction;    // -> "wq " if sync | "wfn " if async
00223 
00224 char     *StageArg[MaxArgs];
00225 int       StageAln[MaxArgs];
00226 int       StageAnum;      //    Count of valid Arg/Aln array elements
00227 char     *RSSCmd;         // -> Remote Storage Service Command
00228 int       isMSSC;         //    RSSCmd is old-style msscmd
00229 int       RSSTout;        //    RSSCmd response timeout
00230 long long MaxSize;        //    Maximum file size (*obsolete*)
00231 int       FDFence;        //    Smallest file FD number allowed
00232 int       FDLimit;        //    Largest  file FD number allowed
00233 unsigned long long DirFlags;//  Default directory settings
00234 int       Trace;          //    Trace flags
00235 int       Solitary;       //    True if running in stand-alone mode
00236 int       OptFlags;       //    General option flags
00237 
00238 char             *N2N_Lib;   // -> Name2Name Library Path
00239 char             *N2N_Parms; // -> Name2Name Object Parameters
00240 XrdOucName2Name  *lcl_N2N;   // -> File mapper for local  files
00241 XrdOucName2Name  *rmt_N2N;   // -> File mapper for remote files
00242 XrdOucName2Name  *the_N2N;   // -> File mapper object
00243 XrdOucPListAnchor RPList;    //    The real path list
00244 OssDPath         *DPList;    //    The stat path list
00245 int               lenDP;
00246 short             numDP;
00247 short             numCG;
00248 
00249 XrdVersionInfo   *myVersion; //    Compilation version set by constructor
00250    
00251          XrdOssSys();
00252 virtual ~XrdOssSys() {}
00253 
00254 protected:
00255 // Cache management related data and methods
00256 //
00257 long long minalloc;          //    Minimum allocation
00258 int       ovhalloc;          //    Allocation overage
00259 int       fuzalloc;          //    Allocation fuzz
00260 int       cscanint;          //    Seconds between cache scans
00261 int       xfrspeed;          //    Average transfer speed (bytes/second)
00262 int       xfrovhd;           //    Minimum seconds to get a file
00263 int       xfrhold;           //    Second hold limit on failing requests
00264 int       xfrkeep;           //    Second keep queued requests
00265 int       xfrthreads;        //    Number of threads for staging
00266 int       xfrtcount;         //    Actual count of threads (used for dtr)
00267 long long pndbytes;          //    Total bytes to be staged (pending)
00268 long long stgbytes;          //    Total bytes being staged (active)
00269 long long totbytes;          //    Total bytes were  staged (active+pending)
00270 int       totreqs;           //    Total   successful requests
00271 int       badreqs;           //    Total unsuccessful requests
00272 
00273 XrdOucProg     *StageProg;    //    Command or manager than handles staging
00274 XrdOucProg     *RSSProg;      //    Command for Remote Storage Services
00275 
00276 char           *UDir;         // -> Usage logdir
00277 char           *QFile;        // -> Quota file
00278 char           *xfrFdir;      // -> Fail file base dir
00279 int             xfrFdln;      //    strlen(xfrFDir)
00280 
00281 int                Alloc_Cache(XrdOssCreateInfo &, XrdOucEnv &);
00282 int                Alloc_Local(XrdOssCreateInfo &, XrdOucEnv &);
00283 int                BreakLink(const char *local_path, struct stat &statbuff);
00284 int                CalcTime();
00285 int                CalcTime(XrdOssStage_Req *req);
00286 int                SetFattr(XrdOssCreateInfo &crInfo, int datfd, time_t mtime);
00287 void               doScrub();
00288 int                Find(XrdOssStage_Req *req, void *carg);
00289 int                getCname(const char *path, struct stat *sbuff, char *cgbuff);
00290 int                getStats(char *buff, int blen);
00291 int                GetFile(XrdOssStage_Req *req);
00292 int                getID(const char *, XrdOucEnv &, char *, int);
00293 time_t             HasFile(const char *fn, const char *sfx, time_t *mTime=0);
00294 int                Stage_QT(const char *, const char *, XrdOucEnv &, int, mode_t);
00295 int                Stage_RT(const char *, const char *, XrdOucEnv &, unsigned long long);
00296 
00297 // Configuration related methods
00298 //
00299 void   ConfigMio(XrdSysError &Eroute);
00300 int    ConfigN2N(XrdSysError &Eroute);
00301 int    ConfigProc(XrdSysError &Eroute);
00302 void   ConfigSpace();
00303 void   ConfigSpace(const char *Lfn);
00304 void   ConfigSpath(XrdSysError &Eroute, const char *Pn,
00305                    unsigned long long &Fv, int noMSS);
00306 int    ConfigStage(XrdSysError &Eroute);
00307 int    ConfigStageC(XrdSysError &Eroute);
00308 void   ConfigStats(XrdSysError &Eroute);
00309 void   ConfigStats(dev_t Devnum, char *lP);
00310 int    ConfigXeq(char *, XrdOucStream &, XrdSysError &);
00311 void   List_Path(const char *, const char *, unsigned long long, XrdSysError &);
00312 int    xalloc(XrdOucStream &Config, XrdSysError &Eroute);
00313 int    xcache(XrdOucStream &Config, XrdSysError &Eroute);
00314 int    xcachescan(XrdOucStream &Config, XrdSysError &Eroute);
00315 int    xdefault(XrdOucStream &Config, XrdSysError &Eroute);
00316 int    xfdlimit(XrdOucStream &Config, XrdSysError &Eroute);
00317 int    xmaxsz(XrdOucStream &Config, XrdSysError &Eroute);
00318 int    xmemf(XrdOucStream &Config, XrdSysError &Eroute);
00319 int    xnml(XrdOucStream &Config, XrdSysError &Eroute);
00320 int    xpath(XrdOucStream &Config, XrdSysError &Eroute);
00321 int    xspace(XrdOucStream &Config, XrdSysError &Eroute, int *isCD=0);
00322 int    xspaceBuild(char *grp, char *fn, int isxa, XrdSysError &Eroute);
00323 int    xstg(XrdOucStream &Config, XrdSysError &Eroute);
00324 int    xusage(XrdOucStream &Config, XrdSysError &Eroute);
00325 int    xtrace(XrdOucStream &Config, XrdSysError &Eroute);
00326 int    xxfr(XrdOucStream &Config, XrdSysError &Eroute);
00327 
00328 // Mass storage related methods
00329 //
00330 int    tranmode(char *);
00331 int    MSS_Xeq(XrdOucStream **xfd, int okerr,
00332                const char *cmd, const char *arg1=0, const char *arg2=0);
00333 
00334 // Other methods
00335 //
00336 int    RenameLink(char *old_path, char *new_path);
00337 int    RenameLink2(int Llen, char *oLnk, char *old_path,
00338                              char *nLnk, char *new_path);
00339 int    RenameLink3(char *cPath, char *old_path, char *new_path);
00340 };
00341 
00342 /******************************************************************************/
00343 /*                  A P I   S p e c i f i c   D e f i n e s                   */
00344 /******************************************************************************/
00345 
00346 // The Check_RO macro is valid only for XrdOssSys objects.
00347 //
00348 #define Check_RO(act, flags, path, opname) \
00349    XRDEXP_REMOTE & (flags = PathOpts(path)); \
00350    if (flags & XRDEXP_NOTRW) \
00351       return OssEroute.Emsg(#act, -XRDOSS_E8005, opname, path)
00352 #endif