Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef __OFS_API_H__
0002 #define __OFS_API_H__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                             X r d O f s . h h                              */
0006 /*                                                                            */
0007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0010 /*                                                                            */
0011 /* This file is part of the XRootD software suite.                            */
0012 /*                                                                            */
0013 /* XRootD is free software: you can redistribute it and/or modify it under    */
0014 /* the terms of the GNU Lesser General Public License as published by the     */
0015 /* Free Software Foundation, either version 3 of the License, or (at your     */
0016 /* option) any later version.                                                 */
0017 /*                                                                            */
0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0021 /* License for more details.                                                  */
0022 /*                                                                            */
0023 /* You should have received a copy of the GNU Lesser General Public License   */
0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0026 /*                                                                            */
0027 /* The copyright holder's institutional names and contributor's names may not */
0028 /* be used to endorse or promote products derived from this software without  */
0029 /* specific prior written permission of the institution or contributor.       */
0030 /******************************************************************************/
0031 
0032 #include <cstring>
0033 #include <dirent.h>
0034 #include <sys/types.h>
0035   
0036 #include "XrdOfs/XrdOfsEvr.hh"
0037 #include "XrdOfs/XrdOfsHandle.hh"
0038 #include "XrdSys/XrdSysPthread.hh"
0039 #include "XrdSfs/XrdSfsInterface.hh"
0040 #include "XrdCms/XrdCmsClient.hh"
0041 
0042 class XrdNetIF;
0043 class XrdOfsEvs;
0044 class XrdOfsPocq;
0045 class XrdOfsPrepare;
0046 class XrdOss;
0047 class XrdOssDF;
0048 class XrdOssDir;
0049 class XrdOucEnv;
0050 class XrdOucPListAnchor;
0051 class XrdSysError;
0052 class XrdSysLogger;
0053 class XrdOucStream;
0054 class XrdSfsAio;
0055 
0056 struct XrdVersionInfo;
0057 
0058 /******************************************************************************/
0059 /*                       X r d O f s D i r e c t o r y                        */
0060 /******************************************************************************/
0061   
0062 class XrdOfsDirectory : public XrdSfsDirectory
0063 {
0064 public:
0065 
0066         int         open(const char              *dirName,
0067                          const XrdSecEntity      *client,
0068                          const char              *opaque = 0);
0069 
0070         const char *nextEntry();
0071 
0072         int         close();
0073 
0074 inline  void        copyError(XrdOucErrInfo &einfo) {einfo = error;}
0075 
0076 const   char       *FName() {return (const char *)fname;}
0077 
0078         int         autoStat(struct stat *buf);
0079 
0080                     XrdOfsDirectory(XrdOucErrInfo &eInfo, const char *user)
0081                           : XrdSfsDirectory(eInfo), tident(user ? user : ""),
0082                             fname(0), dp(0), atEOF(0) {}
0083 
0084 virtual            ~XrdOfsDirectory() {if (dp) close();}
0085 
0086 protected:
0087 const char    *tident;
0088 char          *fname;
0089 XrdOssDF      *dp;
0090 int            atEOF;
0091 char           dname[MAXNAMLEN];
0092 };
0093 
0094 class XrdOfsDirFull : public XrdOfsDirectory
0095 {
0096 public:
0097                     XrdOfsDirFull(const char *user, int MonID)
0098                           : XrdOfsDirectory(myEInfo, user), myEInfo(user, MonID)
0099                           {}
0100 
0101 virtual            ~XrdOfsDirFull() {}
0102 
0103 private:
0104 XrdOucErrInfo  myEInfo; // Accessible only by reference error
0105 };
0106 
0107 /******************************************************************************/
0108 /*                            X r d O f s F i l e                             */
0109 /******************************************************************************/
0110 
0111 class XrdOfsTPC;
0112 class XrdOucChkPnt;
0113   
0114 class XrdOfsFile : public XrdSfsFile
0115 {
0116 public:
0117 
0118         int            open(const char                *fileName,
0119                                   XrdSfsFileOpenMode   openMode,
0120                                   mode_t               createMode,
0121                             const XrdSecEntity        *client,
0122                             const char                *opaque = 0);
0123 
0124         int            checkpoint(XrdSfsFile::cpAct act,
0125                                   struct iov *range=0, int n=0);
0126 
0127         int            close();
0128 
0129         using          XrdSfsFile::fctl;
0130 
0131         int            fctl(const int               cmd,
0132                             const char             *args,
0133                                   XrdOucErrInfo    &out_error);
0134 
0135         int            fctl(const int               cmd,
0136                                   int               alen,
0137                                   const char       *args,
0138                             const XrdSecEntity     *client = 0);
0139 
0140         const char    *FName() {return (oh ? oh->Name() : "?");}
0141 
0142         int            getMmap(void **Addr, off_t &Size);
0143 
0144         XrdSfsXferSize pgRead(XrdSfsFileOffset   offset,
0145                               char              *buffer,
0146                               XrdSfsXferSize     rdlen,
0147                               uint32_t          *csvec,
0148                               uint64_t           opts=0);
0149 
0150         int            pgRead(XrdSfsAio *aioparm, uint64_t opts=0);
0151 
0152 
0153         XrdSfsXferSize pgWrite(XrdSfsFileOffset   offset,
0154                                char              *buffer,
0155                                XrdSfsXferSize     wrlen,
0156                                uint32_t          *csvec,
0157                                uint64_t           opts=0);
0158 
0159         int            pgWrite(XrdSfsAio *aioparm, uint64_t opts=0);
0160 
0161 
0162         int            read(XrdSfsFileOffset   fileOffset,   // Preread only
0163                             XrdSfsXferSize     amount);
0164 
0165         XrdSfsXferSize read(XrdSfsFileOffset   fileOffset,
0166                             char              *buffer,
0167                             XrdSfsXferSize     buffer_size);
0168 
0169         XrdSfsXferSize readv(XrdOucIOVec      *readV,
0170                              int               readCount);
0171 
0172         int            read(XrdSfsAio *aioparm);
0173 
0174         XrdSfsXferSize write(XrdSfsFileOffset   fileOffset,
0175                              const char        *buffer,
0176                              XrdSfsXferSize     buffer_size);
0177 
0178         int            write(XrdSfsAio *aioparm);
0179 
0180         int            sync();
0181 
0182         int            sync(XrdSfsAio *aiop);
0183 
0184         int            stat(struct stat *buf);
0185 
0186         int            truncate(XrdSfsFileOffset   fileOffset);
0187 
0188         int            getCXinfo(char cxtype[4], int &cxrsz);
0189 
0190                        XrdOfsFile(XrdOucErrInfo &eInfo, const char *user);
0191 
0192                       ~XrdOfsFile() {viaDel = 1; if (oh) close();}
0193 
0194 protected:
0195 
0196 const char    *tident;
0197 XrdOfsHandle  *oh;
0198 XrdOfsTPC     *myTPC;
0199 XrdOucChkPnt  *myCKP;
0200 int            dorawio;
0201 char           viaDel;
0202 bool           ckpBad;
0203 
0204 private:
0205 
0206 void           GenFWEvent();
0207 int            CreateCKP();
0208 };
0209 
0210 class XrdOfsFileFull : public XrdOfsFile
0211 {
0212 public:
0213                     XrdOfsFileFull(const char *user, int MonID)
0214                           : XrdOfsFile(myEInfo, user), myEInfo(user, MonID)
0215                           {}
0216 
0217 virtual            ~XrdOfsFileFull() {}
0218 
0219 private:
0220 XrdOucErrInfo  myEInfo; // Accessible only by reference error
0221 };
0222 
0223 /******************************************************************************/
0224 /*                          C l a s s   X r d O f s                           */
0225 /******************************************************************************/
0226 
0227 class XrdAccAuthorize;
0228 class XrdCks;
0229 class XrdCmsClient;
0230 class XrdOfsConfigPI;
0231 class XrdOfsFSctl_PI;
0232 class XrdOfsPoscq;
0233 struct XrdSfsFACtl;
0234   
0235 class XrdOfs : public XrdSfsFileSystem
0236 {
0237 friend class XrdOfsDirectory;
0238 friend class XrdOfsFile;
0239 
0240 public:
0241 
0242 // Object allocation
0243 //
0244         XrdSfsDirectory *newDir(char *user=0, int MonID=0)
0245                         {return new XrdOfsDirFull(user, MonID);}
0246 
0247         XrdSfsDirectory *newDir(XrdOucErrInfo &eInfo)
0248                         {return new XrdOfsDirectory(eInfo, eInfo.getErrUser());}
0249 
0250         XrdSfsFile      *newFile(char *user=0,int MonID=0)
0251                         {return new XrdOfsFileFull(user, MonID);}
0252 
0253         XrdSfsFile      *newFile(XrdOucErrInfo &eInfo)
0254                         {return new XrdOfsFile(eInfo, eInfo.getErrUser());}
0255 
0256 // Other functions
0257 //
0258         int            chksum(      csFunc            Func,
0259                               const char             *csName,
0260                               const char             *Path,
0261                                     XrdOucErrInfo    &out_error,
0262                               const XrdSecEntity     *client = 0,
0263                               const char             *opaque = 0);
0264 
0265         int            chmod(const char             *Name,
0266                                    XrdSfsMode        Mode,
0267                                    XrdOucErrInfo    &out_error,
0268                              const XrdSecEntity     *client,
0269                              const char             *opaque = 0);
0270 
0271         void           Connect(const XrdSecEntity     *client = 0);
0272 
0273         void           Disc(const XrdSecEntity *client = 0);
0274 
0275         int            exists(const char                *fileName,
0276                                     XrdSfsFileExistence &exists_flag,
0277                                     XrdOucErrInfo       &out_error,
0278                               const XrdSecEntity        *client,
0279                               const char                *opaque = 0);
0280 
0281         int            FAttr(      XrdSfsFACtl      *faReq,
0282                                    XrdOucErrInfo    &eInfo,
0283                              const XrdSecEntity     *client = 0);
0284 
0285         int            FSctl(const int               cmd,
0286                                    XrdSfsFSctl      &args,
0287                                    XrdOucErrInfo    &eInfo,
0288                              const XrdSecEntity     *client = 0);
0289 
0290         int            fsctl(const int               cmd,
0291                              const char             *args,
0292                                    XrdOucErrInfo    &out_error,
0293                              const XrdSecEntity     *client = 0);
0294 
0295         int            getStats(char *buff, int blen);
0296 
0297 const   char          *getVersion();
0298 
0299         int            mkdir(const char             *dirName,
0300                                    XrdSfsMode        Mode,
0301                                    XrdOucErrInfo    &out_error,
0302                              const XrdSecEntity     *client,
0303                              const char             *opaque = 0);
0304 
0305         int            prepare(      XrdSfsPrep       &pargs,
0306                                      XrdOucErrInfo    &out_error,
0307                                const XrdSecEntity     *client = 0);
0308 
0309         int            rem(const char             *path,
0310                                  XrdOucErrInfo    &out_error,
0311                            const XrdSecEntity     *client,
0312                            const char             *info = 0)
0313                           {return remove('f', path, out_error, client, info);}
0314 
0315         int            remdir(const char             *dirName,
0316                                     XrdOucErrInfo    &out_error,
0317                               const XrdSecEntity     *client,
0318                               const char             *info = 0)
0319                              {return remove('d',dirName,out_error,client,info);}
0320 
0321         int            rename(const char             *oldFileName,
0322                               const char             *newFileName,
0323                                     XrdOucErrInfo    &out_error,
0324                               const XrdSecEntity     *client,
0325                               const char             *infoO = 0,
0326                                const char            *infoN = 0);
0327 
0328         int            stat(const char             *Name,
0329                                   struct stat      *buf,
0330                                   XrdOucErrInfo    &out_error,
0331                             const XrdSecEntity     *client,
0332                             const char             *opaque = 0);
0333 
0334         int            stat(const char             *Name,
0335                                   mode_t           &mode,
0336                                   XrdOucErrInfo    &out_error,
0337                             const XrdSecEntity     *client,
0338                             const char             *opaque = 0);
0339 
0340         int            truncate(const char             *Name,
0341                                       XrdSfsFileOffset fileOffset,
0342                                       XrdOucErrInfo    &out_error,
0343                                 const XrdSecEntity     *client = 0,
0344                                 const char             *opaque = 0);
0345 // Management functions
0346 //
0347 virtual int            Configure(XrdSysError &); // Backward Compatibility
0348 
0349 virtual int            Configure(XrdSysError &, XrdOucEnv *);
0350 
0351         void           Config_Cluster(XrdOss *);
0352 
0353         void           Config_Display(XrdSysError &);
0354 
0355                        XrdOfs();
0356 virtual               ~XrdOfs() {}  // Too complicate to delete :-)
0357 
0358 /******************************************************************************/
0359 /*                  C o n f i g u r a t i o n   V a l u e s                   */
0360 /******************************************************************************/
0361   
0362 // Configuration values for this filesystem
0363 //
0364 enum {Authorize = 0x0001,    // Authorization wanted
0365       XAttrPlug = 0x0002,    // Extended Attribute Plugin
0366       isPeer    = 0x0050,    // Role peer
0367       isProxy   = 0x0020,    // Role proxy
0368       isManager = 0x0040,    // Role manager
0369       isServer  = 0x0080,    // Role server
0370       isSuper   = 0x00C0,    // Role supervisor
0371       isMeta    = 0x0100,    // Role meta + above
0372       haveRole  = 0x01F0,    // A role is present
0373       Forwarding= 0x1000,    // Fowarding wanted
0374       ThirdPC   = 0x2000,    // This party copy wanted
0375       SubCluster= 0x4000,    // all.subcluster directive encountered
0376       RdrTPC    = 0x8000
0377      };                      // These are set in Options below
0378 
0379 int   Options;               // Various options
0380 int   myPort;                // Port number being used
0381 
0382 // Directory and file creation mode controls
0383 //
0384 mode_t            dMask[2];  // Min/Max directory mode
0385 mode_t            fMask[2];  // Min/Max file      mode
0386 
0387 // TPC related things
0388 //
0389 char             *tpcRdrHost[2];  // TPC redirect target or null if none
0390 int               tpcRdrPort[2];  // TPC redirect target port number
0391 
0392 // Networking
0393 //
0394 XrdNetIF *myIF;
0395 
0396 // Forward options
0397 //
0398 struct fwdOpt
0399       {const char *Cmd;
0400              char *Host;
0401              int   Port;
0402              void  Reset() {Cmd = 0; Port = 0;
0403                             if (Host) {free(Host); Host = 0;}
0404                            }
0405                    fwdOpt() : Cmd(0), Host(0), Port(0) {}
0406                   ~fwdOpt() {}
0407       };
0408 
0409 struct fwdOpt fwdCHMOD;
0410 struct fwdOpt fwdMKDIR;
0411 struct fwdOpt fwdMKPATH;
0412 struct fwdOpt fwdMV;
0413 struct fwdOpt fwdRM;
0414 struct fwdOpt fwdRMDIR;
0415 struct fwdOpt fwdTRUNC;
0416 
0417 static int MaxDelay;  //    Max delay imposed during staging
0418 static int OSSDelay;  //    Delay to impose when oss interface times out
0419 
0420 char *ConfigFN;       //    ->Configuration filename
0421 
0422 /******************************************************************************/
0423 /*                       P r o t e c t e d   I t e m s                        */
0424 /******************************************************************************/
0425 
0426 protected:
0427 
0428 XrdOfsEvr     evrObject;      // Event receiver
0429 XrdCmsClient *Finder;         // ->Cluster Management Service
0430 
0431 virtual int   ConfigXeq(char *var, XrdOucStream &, XrdSysError &);
0432 static  int   Emsg(const char *, XrdOucErrInfo  &, int, const char *x,
0433                    XrdOfsHandle *hP);
0434 static  int   Emsg(const char *, XrdOucErrInfo  &, int, const char *x,
0435                    const char *y="");
0436 static  int   fsError(XrdOucErrInfo &myError, int rc);
0437 const char   *Split(const char *Args, const char **Opq, char *Path, int Plen);
0438         int   Stall(XrdOucErrInfo  &, int, const char *);
0439         void  Unpersist(XrdOfsHandle *hP, int xcev=1);
0440         char *WaitTime(int, char *, int);
0441 
0442 /******************************************************************************/
0443 /*                 P r i v a t e   C o n f i g u r a t i o n                  */
0444 /******************************************************************************/
0445 
0446 private:
0447   
0448 char             *myRole;
0449 XrdOfsFSctl_PI   *FSctl_PC;       //    ->FSctl plugin (cache specific)
0450 XrdOfsFSctl_PI   *FSctl_PI;       //    ->FSctl plugin
0451 XrdAccAuthorize  *Authorization;  //    ->Authorization   Service
0452 XrdCmsClient     *Balancer;       //    ->Cluster Local   Interface
0453 XrdOfsEvs        *evsObject;      //    ->Event Notifier
0454 XrdOucPListAnchor*ossRPList;      //    ->Oss exoprt list
0455 
0456 XrdOfsPoscq      *poscQ;          //    -> poscQ if  persist on close enabled
0457 char             *poscLog;        //    -> Directory for posc recovery log
0458 int               poscHold;       //       Seconds to hold a forced close
0459 short             poscSync;       //       Number of requests before sync
0460 signed char       poscAuto;       //  1 -> Automatic persist on close
0461 
0462 char              ossRW;          // The oss r/w capability
0463 
0464 XrdOfsConfigPI   *ofsConfig;      // Plugin   configurator
0465 XrdOfsPrepare    *prepHandler;    // Plugin   prepare
0466 XrdCks           *Cks;            // Checksum manager
0467 bool              CksPfn;         // Checksum needs a pfn
0468 bool              CksRdr;         // Checksum may be redirected (i.e. not local)
0469 bool              prepAuth;       // Prepare requires authorization
0470 char              OssIsProxy;     // !0 if we detect the oss plugin is a proxy
0471 char              myRType[4];     // Role type for consistency with the cms
0472 
0473 uint64_t          ossFeatures;    // The oss features
0474 
0475 int               usxMaxNsz;      // Maximum length of attribute name
0476 int               usxMaxVsz;      // Maximum length of attribute value
0477 
0478 static XrdOfsHandle     *dummyHandle;
0479 XrdSysMutex              ocMutex; // Global mutex for open/close
0480 
0481 bool              DirRdr;         // Opendir() can be redirected.
0482 bool              reProxy;        // Reproxying required for TPC
0483 bool              OssHasPGrw;     // True: oss implements full rgRead/Write
0484 
0485 /******************************************************************************/
0486 /*                            O t h e r   D a t a                             */
0487 /******************************************************************************/
0488 
0489 // Internal file attribute methods
0490 //
0491 int ctlFADel(XrdSfsFACtl &faCtl, XrdOucEnv &faEnv, XrdOucErrInfo &einfo);
0492 int ctlFAGet(XrdSfsFACtl &faCtl, XrdOucEnv &faEnv, XrdOucErrInfo &einfo);
0493 int ctlFALst(XrdSfsFACtl &faCtl, XrdOucEnv &faEnv, XrdOucErrInfo &einfo);
0494 int ctlFASet(XrdSfsFACtl &faCtl, XrdOucEnv &faEnv, XrdOucErrInfo &einfo);
0495 
0496 // Common functions
0497 //
0498 int   remove(const char type, const char *path, XrdOucErrInfo &out_error,
0499              const XrdSecEntity *client, const char *opaque);
0500 
0501 // Function used during Configuration
0502 //
0503 int           ConfigDispFwd(char *buff, struct fwdOpt &Fwd);
0504 int           ConfigPosc(XrdSysError &Eroute);
0505 int           ConfigRedir(XrdSysError &Eroute, XrdOucEnv *EnvInfo);
0506 int           ConfigTPC(XrdSysError &Eroute, XrdOucEnv *EnvInfo);
0507 int           ConfigTPC(XrdSysError &Eroute);
0508 char         *ConfigTPCDir(XrdSysError &Eroute, const char *sfx,
0509                                                 const char *xPath=0);
0510 const char   *Fname(const char *);
0511 int           Forward(int &Result, XrdOucErrInfo &Resp, struct fwdOpt &Fwd,
0512                       const char *arg1=0, const char *arg2=0,
0513                       XrdOucEnv  *Env1=0, XrdOucEnv  *Env2=0);
0514 int           FSctl(XrdOfsFile &file, int cmd, int alen, const char *args,
0515                     const XrdSecEntity *client);
0516 int           Reformat(XrdOucErrInfo &);
0517 const char   *theRole(int opts);
0518 int           xcrds(XrdOucStream &, XrdSysError &);
0519 int           xcrm(XrdOucStream &, XrdSysError &);
0520 int           xdirl(XrdOucStream &, XrdSysError &);
0521 int           xexp(XrdOucStream &, XrdSysError &, bool);
0522 int           xforward(XrdOucStream &, XrdSysError &);
0523 int           xmaxd(XrdOucStream &, XrdSysError &);
0524 int           xnmsg(XrdOucStream &, XrdSysError &);
0525 int           xnot(XrdOucStream &, XrdSysError &);
0526 int           xpers(XrdOucStream &, XrdSysError &);
0527 int           xrole(XrdOucStream &, XrdSysError &);
0528 int           xtpc(XrdOucStream &, XrdSysError &);
0529 int           xtpcal(XrdOucStream &, XrdSysError &);
0530 int           xtpcr(XrdOucStream &, XrdSysError &);
0531 int           xtrace(XrdOucStream &, XrdSysError &);
0532 int           xatr(XrdOucStream &, XrdSysError &);
0533 };
0534 #endif