Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-08 10:33:33

0001 #ifndef _XRDOSS_API_H
0002 #define _XRDOSS_API_H
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                          X r d O s s A p i . h h                           */
0006 /*                                                                            */
0007 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 #include <sys/types.h>
0034 #include <cerrno>
0035 #include "XrdSys/XrdSysHeaders.hh"
0036 
0037 #include "XrdOss/XrdOss.hh"
0038 #include "XrdOss/XrdOssConfig.hh"
0039 #include "XrdOss/XrdOssError.hh"
0040 #include "XrdOss/XrdOssStatInfo.hh"
0041 #include "XrdOuc/XrdOucExport.hh"
0042 #include "XrdOuc/XrdOucPList.hh"
0043 #include "XrdOuc/XrdOucStream.hh"
0044 #include "XrdSys/XrdSysError.hh"
0045 #include "XrdSys/XrdSysPthread.hh"
0046 
0047 /******************************************************************************/
0048 /*                              o o s s _ D i r                               */
0049 /******************************************************************************/
0050 
0051 class XrdOssDir : public XrdOssDF
0052 {
0053 public:
0054 int     Close(long long *retsz=0);
0055 int     Opendir(const char *, XrdOucEnv &);
0056 int     Readdir(char *buff, int blen);
0057 int     StatRet(struct stat *buff);
0058 int     getFD() {return fd;}
0059 
0060         // Constructor and destructor
0061         XrdOssDir(const char *tid, DIR *dP=0)
0062                  : XrdOssDF(tid, DF_isDir),
0063                    lclfd(dP), mssfd(0), Stat(0), ateof(false),
0064                    isopen(dP != 0), dOpts(0) {if (dP) fd = dirfd(dP);}
0065 
0066        ~XrdOssDir() {if (isopen) Close();}
0067 private:
0068          DIR       *lclfd;
0069          void      *mssfd;
0070 struct   stat      *Stat;
0071          bool       ateof;
0072          bool       isopen;
0073 unsigned char       dOpts;
0074 static const int    isStage  = 0x01;
0075 static const int    noCheck  = 0x02;
0076 static const int    noDread  = 0x04;
0077 };
0078   
0079 /******************************************************************************/
0080 /*                             o o s s _ F i l e                              */
0081 /******************************************************************************/
0082 
0083 class oocx_CXFile;
0084 class XrdSfsAio;
0085 class XrdOssCache_FS;
0086 class XrdOssMioFile;
0087   
0088 class XrdOssFile : public XrdOssDF
0089 {
0090 public:
0091 
0092 // The following two are virtual functions to allow for upcasting derivations
0093 // of this implementation
0094 //
0095 virtual int     Close(long long *retsz=0);
0096 virtual int     Open(const char *, int, mode_t, XrdOucEnv &);
0097 
0098 int     Fchmod(mode_t mode);
0099 int     Fctl(int cmd, int alen, const char *args, char **resp=0);
0100 void    Flush();
0101 int     Fstat(struct stat *);
0102 int     Fsync();
0103 int     Fsync(XrdSfsAio *aiop);
0104 int     Ftruncate(unsigned long long);
0105 int     getFD() {return fd;}
0106 off_t   getMmap(void **addr);
0107 int     isCompressed(char *cxidp=0);
0108 ssize_t Read(               off_t, size_t);
0109 ssize_t Read(       void *, off_t, size_t);
0110 int     Read(XrdSfsAio *aiop);
0111 ssize_t ReadV(XrdOucIOVec *readV, int);
0112 ssize_t ReadRaw(    void *, off_t, size_t);
0113 ssize_t Write(const void *, off_t, size_t);
0114 int     Write(XrdSfsAio *aiop);
0115  
0116         // Constructor and destructor
0117         XrdOssFile(const char *tid, int fdnum=-1)
0118                   : XrdOssDF(tid, DF_isFile, fdnum),
0119                     cxobj(0), cacheP(0), mmFile(0),
0120                     rawio(0), cxpgsz(0) {cxid[0] = '\0';}
0121 
0122 virtual ~XrdOssFile() {if (fd >= 0) Close();}
0123 
0124 private:
0125 int     Open_ufs(const char *, int, int, unsigned long long);
0126 
0127 static int      AioFailure;
0128 oocx_CXFile    *cxobj;
0129 XrdOssCache_FS *cacheP;
0130 XrdOssMioFile  *mmFile;
0131 long long       FSize;
0132 int             rawio;
0133 int             cxpgsz;
0134 char            cxid[4];
0135 };
0136 
0137 /******************************************************************************/
0138 /*                              o o s s _ S y s                               */
0139 /******************************************************************************/
0140   
0141 class XrdFrcProxy;
0142 class XrdOssCache_Group;
0143 class XrdOssCache_Space;
0144 class XrdOssCreateInfo;
0145 class XrdOucMsubs;
0146 class XrdOucName2Name;
0147 class XrdOucProg;
0148 class XrdOssSpace;
0149 class XrdOssStage_Req;
0150 
0151 struct XrdVersionInfo;
0152 
0153 class XrdOssSys : public XrdOss
0154 {
0155 public:
0156 virtual XrdOssDF *newDir(const char *tident)
0157                        {return (XrdOssDF *)new XrdOssDir(tident);}
0158 virtual XrdOssDF *newFile(const char *tident)
0159                        {return (XrdOssDF *)new XrdOssFile(tident);}
0160 
0161 int       Chmod(const char *, mode_t mode, XrdOucEnv *eP=0);
0162 int       Configure(const char *, XrdSysError &, XrdOucEnv *envP);
0163 void      Config_Display(XrdSysError &);
0164 virtual
0165 int       Create(const char *, const char *, mode_t, XrdOucEnv &, int opts=0);
0166 uint64_t  Features() {return XRDOSS_HASNAIO;} // Turn async I/O off for disk
0167 int       GenLocalPath(const char *, char *);
0168 int       GenRemotePath(const char *, char *);
0169 int       Init(XrdSysLogger *, const char *, XrdOucEnv *envP);
0170 int       Init(XrdSysLogger *lP, const char *cP) {return Init(lP, cP, 0);}
0171 int       IsRemote(const char *path) 
0172                   {return (RPList.Find(path) & XRDEXP_REMOTE) != 0;}
0173 int       Lfn2Pfn(const char *Path, char *buff, int blen);
0174 const char *Lfn2Pfn(const char *Path, char *buff, int blen, int &rc);
0175 int       Mkdir(const char *, mode_t mode, int mkpath=0, XrdOucEnv *eP=0);
0176 int       Mkpath(const char *, mode_t mode);
0177 unsigned long long PathOpts(const char *path) {return RPList.Find(path);}
0178 int       Reloc(const char *tident, const char *path,
0179                 const char *cgName, const char *anchor=0);
0180 int       Remdir(const char *, int Opts=0, XrdOucEnv *eP=0);  // In Unlink()
0181 int       Rename(const char *, const char *,
0182                  XrdOucEnv *eP1=0, XrdOucEnv *eP2=0);
0183 virtual 
0184 int       Stage(const char *, const char *, XrdOucEnv &, int, mode_t, unsigned long long );
0185 void     *Stage_In(void *carg);
0186 int       Stat(const char *, struct stat *, int opts=0, XrdOucEnv *Env=0);
0187 int       StatFS(const char *path, char *buff, int &blen, XrdOucEnv *Env=0);
0188 int       StatFS(const char *path, unsigned long long &Opt,
0189                  long long &fSize, long long &fSpace);
0190 int       StatLS(XrdOucEnv &env, const char *path, char *buff, int &blen);
0191 int       StatPF(const char *, struct stat *, int);
0192 int       StatVS(XrdOssVSInfo *sP, const char *sname=0, int updt=0);
0193 int       StatXA(const char *path, char *buff, int &blen, XrdOucEnv *Env=0);
0194 int       StatXP(const char *path, unsigned long long &attr, XrdOucEnv *Env=0);
0195 int       Truncate(const char *, unsigned long long Size, XrdOucEnv *eP=0);
0196 int       Unlink(const char *, int Opts=0, XrdOucEnv *eP=0);
0197 
0198 int       Stats(char *bp, int bl);
0199 
0200 static int   AioInit();
0201 static int   AioAllOk;
0202 
0203 static char  tryMmap;           // Memory mapped files enabled
0204 static char  chkMmap;           // Memory mapped files are selective
0205    
0206 int       MSS_Closedir(void *);
0207 int       MSS_Create(const char *path, mode_t, XrdOucEnv &);
0208 void     *MSS_Opendir(const char *, int &rc);
0209 int       MSS_Readdir(void *fd, char *buff, int blen);
0210 int       MSS_Remdir(const char *, const char *) {return -ENOTSUP;}
0211 int       MSS_Rename(const char *, const char *);
0212 int       MSS_Stat(const char *, struct stat *buff=0);
0213 int       MSS_Unlink(const char *);
0214 
0215 static const int MaxArgs = 15;
0216 
0217 char     *ConfigFN;       // -> Pointer to the config file name
0218 char     *LocalRoot;      // -> Path prefix for local  filename
0219 char     *RemoteRoot;     // -> Path prefix for remote filename
0220 int       MaxTwiddle;     //    Maximum seconds of internal wait
0221 int       StageRealTime;  //    If 1, Invoke stage command on demand
0222 int       StageAsync;     //    If 1, return EINPROGRESS to the caller
0223 int       StageCreate;    //    If 1, use open path to create files
0224 int       StageFormat;    //    Format for default stagecmd
0225 char     *StageCmd;       // -> Staging command to use
0226 char     *StageMsg;       // -> Staging message to be passed
0227 XrdOucMsubs *StageSnd;    // -> Parsed Message
0228 XrdFrcProxy *StageFrm;    // -> Built-in stagecmd or zero
0229 
0230 char     *StageEvents;    // -> file:////<adminpath> if async staging
0231 int       StageEvSize;    //    Length of above
0232 int       StageActLen;    //    Length of below
0233 char     *StageAction;    // -> "wq " if sync | "wfn " if async
0234 
0235 char     *StageArg[MaxArgs];
0236 int       StageAln[MaxArgs];
0237 int       StageAnum;      //    Count of valid Arg/Aln array elements
0238 char     *RSSCmd;         // -> Remote Storage Service Command
0239 int       isMSSC;         //    RSSCmd is old-style msscmd
0240 int       RSSTout;        //    RSSCmd response timeout
0241 long long MaxSize;        //    Maximum file size (*obsolete*)
0242 int       FDFence;        //    Smallest file FD number allowed
0243 int       FDLimit;        //    Largest  file FD number allowed
0244 unsigned long long DirFlags;//  Default directory settings
0245 int       Trace;          //    Trace flags
0246 int       Solitary;       //    True if running in stand-alone mode
0247 int       OptFlags;       //    General option flags
0248 
0249 XrdOucPListAnchor SPList;    // The path to space list
0250 #define           spAssign 1
0251 
0252 char             *N2N_Lib;   // -> Name2Name Library Path
0253 char             *N2N_Parms; // -> Name2Name Object Parameters
0254 XrdOucName2Name  *lcl_N2N;   // -> File mapper for local  files
0255 XrdOucName2Name  *rmt_N2N;   // -> File mapper for remote files
0256 XrdOucName2Name  *the_N2N;   // -> File mapper object
0257 XrdOucPListAnchor RPList;    //    The real path list
0258 OssDPath         *DPList;    //    The stat path list
0259 int               lenDP;
0260 short             numDP;
0261 short             numCG;
0262 
0263 char             *STT_Lib;   // -> StatInfo  Library Path
0264 char             *STT_Parms; // -> StatInfo  Library Paramaters
0265 union {
0266 XrdOssStatInfo_t  STT_Func;
0267 XrdOssStatInfo2_t STT_Fund;
0268       };
0269 int               STT_PreOp;
0270 char              STT_DoN2N;
0271 char              STT_V2;
0272 char              STT_DoARE;
0273 
0274 long long         prPBits;   //    Page lo order bit mask
0275 long long         prPMask;   //    Page hi order bit mask
0276 int               prPSize;   //    preread page size
0277 int               prBytes;   //    preread byte limit
0278 int               prActive;  //    preread activity count
0279 short             prDepth;   //    preread depth
0280 short             prQSize;   //    preread maximum allowed
0281 
0282 XrdVersionInfo   *myVersion; //    Compilation version set by constructor
0283    
0284          XrdOssSys();
0285 virtual ~XrdOssSys() {}
0286 
0287 protected:
0288 // Cache management related data and methods
0289 //
0290 long long minalloc;          //    Minimum allocation
0291 int       ovhalloc;          //    Allocation overage
0292 int       fuzalloc;          //    Allocation fuzz
0293 int       cscanint;          //    Seconds between cache scans
0294 int       xfrspeed;          //    Average transfer speed (bytes/second)
0295 int       xfrovhd;           //    Minimum seconds to get a file
0296 int       xfrhold;           //    Second hold limit on failing requests
0297 int       xfrkeep;           //    Second keep queued requests
0298 int       xfrthreads;        //    Number of threads for staging
0299 int       xfrtcount;         //    Actual count of threads (used for dtr)
0300 long long pndbytes;          //    Total bytes to be staged (pending)
0301 long long stgbytes;          //    Total bytes being staged (active)
0302 long long totbytes;          //    Total bytes were  staged (active+pending)
0303 int       totreqs;           //    Total   successful requests
0304 int       badreqs;           //    Total unsuccessful requests
0305 
0306 XrdOucProg     *StageProg;    //    Command or manager than handles staging
0307 XrdOucProg     *RSSProg;      //    Command for Remote Storage Services
0308 
0309 char           *UDir;         // -> Usage logdir
0310 char           *QFile;        // -> Quota file
0311 char           *xfrFdir;      // -> Fail file base dir
0312 int             xfrFdln;      //    strlen(xfrFDir)
0313 short           USync;        // Usage sync interval
0314 bool            pfcMode;      // Setup for Proxy File Cache
0315 
0316 int                Alloc_Cache(XrdOssCreateInfo &, XrdOucEnv &);
0317 int                Alloc_Local(XrdOssCreateInfo &, XrdOucEnv &);
0318 int                BreakLink(const char *local_path, struct stat &statbuff);
0319 int                CalcTime();
0320 int                CalcTime(XrdOssStage_Req *req);
0321 int                SetFattr(XrdOssCreateInfo &crInfo, int datfd, time_t mtime);
0322 void               doScrub();
0323 int                Find(XrdOssStage_Req *req, void *carg);
0324 int                getCname(const char *path, struct stat *sbuff, char *cgbuff);
0325 int                getStats(char *buff, int blen);
0326 int                GetFile(XrdOssStage_Req *req);
0327 int                getID(const char *, XrdOucEnv &, char *, int);
0328 time_t             HasFile(const char *fn, const char *sfx, time_t *mTime=0);
0329 int                Stage_QT(const char *, const char *, XrdOucEnv &, int, mode_t);
0330 int                Stage_RT(const char *, const char *, XrdOucEnv &, unsigned long long);
0331 
0332 // Configuration related methods
0333 //
0334 void   ConfigCache(XrdSysError &Eroute, bool pass2=false);
0335 void   ConfigMio(XrdSysError &Eroute);
0336 int    ConfigN2N(XrdSysError &Eroute, XrdOucEnv *envP);
0337 int    ConfigProc(XrdSysError &Eroute);
0338 void   ConfigSpace(XrdSysError &Eroute);
0339 void   ConfigSpace(const char *Lfn);
0340 void   ConfigSpath(XrdSysError &Eroute, const char *Pn,
0341                    unsigned long long &Fv, int noMSS);
0342 int    ConfigStage(XrdSysError &Eroute);
0343 int    ConfigStageC(XrdSysError &Eroute);
0344 int    ConfigStatLib(XrdSysError &Eroute, XrdOucEnv *envP);
0345 void   ConfigStats(XrdSysError &Eroute);
0346 void   ConfigStats(dev_t Devnum, char *lP);
0347 int    ConfigXeq(char *, XrdOucStream &, XrdSysError &);
0348 void   List_Path(const char *, const char *, unsigned long long, XrdSysError &);
0349 int    xalloc(XrdOucStream &Config, XrdSysError &Eroute);
0350 int    xcache(XrdOucStream &Config, XrdSysError &Eroute);
0351 int    xcachescan(XrdOucStream &Config, XrdSysError &Eroute);
0352 int    xdefault(XrdOucStream &Config, XrdSysError &Eroute);
0353 int    xfdlimit(XrdOucStream &Config, XrdSysError &Eroute);
0354 int    xmaxsz(XrdOucStream &Config, XrdSysError &Eroute);
0355 int    xmemf(XrdOucStream &Config, XrdSysError &Eroute);
0356 int    xnml(XrdOucStream &Config, XrdSysError &Eroute);
0357 int    xpath(XrdOucStream &Config, XrdSysError &Eroute);
0358 int    xprerd(XrdOucStream &Config, XrdSysError &Eroute);
0359 int    xspace(XrdOucStream &Config, XrdSysError &Eroute, int *isCD=0);
0360 int    xspace(XrdOucStream &Config, XrdSysError &Eroute,
0361               const char *grp, bool isAsgn);
0362 int    xspaceBuild(OssSpaceConfig &sInfo, XrdSysError &Eroute);
0363 int    xstg(XrdOucStream &Config, XrdSysError &Eroute);
0364 int    xstl(XrdOucStream &Config, XrdSysError &Eroute);
0365 int    xusage(XrdOucStream &Config, XrdSysError &Eroute);
0366 int    xtrace(XrdOucStream &Config, XrdSysError &Eroute);
0367 int    xxfr(XrdOucStream &Config, XrdSysError &Eroute);
0368 
0369 // Mass storage related methods
0370 //
0371 int    tranmode(char *);
0372 int    MSS_Xeq(XrdOucStream **xfd, int okerr,
0373                const char *cmd, const char *arg1=0, const char *arg2=0);
0374 
0375 // Other methods
0376 //
0377 int    RenameLink(char *old_path, char *new_path);
0378 int    RenameLink3(char *cPath, char *old_path, char *new_path);
0379 };
0380 
0381 /******************************************************************************/
0382 /*                  A P I   S p e c i f i c   D e f i n e s                   */
0383 /******************************************************************************/
0384 
0385 // The Check_RO macro is valid only for XrdOssSys objects.
0386 //
0387 #define Check_RO(act, flags, path, opname) \
0388    XRDEXP_REMOTE & (flags = PathOpts(path)); \
0389    if (flags & XRDEXP_NOTRW) \
0390       return OssEroute.Emsg(#act, -XRDOSS_E8005, opname, path)
0391 
0392 #define Check_RW(act, path, opname) \
0393    if (PathOpts(path) & XRDEXP_NOTRW) \
0394       return OssEroute.Emsg(#act, -XRDOSS_E8005, opname, path)
0395 #endif