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