xrootd
XrdBwm.hh
Go to the documentation of this file.
00001 #ifndef __BWM_API_H__
00002 #define __BWM_API_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                             X r d B w m . h h                              */
00006 /*                                                                            */
00007 /* (c) 2008 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 "XrdBwm/XrdBwmHandle.hh"
00037 #include "XrdSys/XrdSysPthread.hh"
00038 #include "XrdSfs/XrdSfsInterface.hh"
00039 
00040 class XrdOucEnv;
00041 class XrdSysError;
00042 class XrdSysLogger;
00043 class XrdOucStream;
00044 class XrdSfsAio;
00045 
00046 struct XrdVersionInfo;
00047 
00048 /******************************************************************************/
00049 /*                       X r d B w m D i r e c t o r y                        */
00050 /******************************************************************************/
00051   
00052 class XrdBwmDirectory : public XrdSfsDirectory
00053 {
00054 public:
00055 
00056         int         open(const char              *dirName,
00057                          const XrdSecEntity      *client,
00058                          const char              *opaque = 0);
00059 
00060         const char *nextEntry();
00061 
00062         int         close();
00063 
00064 inline  void        copyError(XrdOucErrInfo &einfo) {einfo = error;}
00065 
00066 const   char       *FName() {return "";}
00067 
00068                     XrdBwmDirectory(const char *user, int monid)
00069                                    : XrdSfsDirectory(user, monid),
00070                                      tident(user ? user : "") {}
00071 
00072 virtual            ~XrdBwmDirectory() {}
00073 
00074 protected:
00075 const char    *tident;
00076 };
00077 
00078 /******************************************************************************/
00079 /*                            X r d B w m F i l e                             */
00080 /******************************************************************************/
00081   
00082 class XrdBwmFile : public XrdSfsFile
00083 {
00084 public:
00085 
00086         int          open(const char                *fileName,
00087                                 XrdSfsFileOpenMode   openMode,
00088                                 mode_t               createMode,
00089                           const XrdSecEntity        *client,
00090                           const char                *opaque = 0);
00091 
00092         int          close();
00093 
00094         int          fctl(const int               cmd,
00095                           const char             *args,
00096                                 XrdOucErrInfo    &out_error);
00097 
00098         const char  *FName() {return (oh ? oh->Name() : "?");}
00099 
00100         int          getMmap(void **Addr, off_t &Size);
00101 
00102         int            read(XrdSfsFileOffset   fileOffset,   // Preread only
00103                             XrdSfsXferSize     amount);
00104 
00105         XrdSfsXferSize read(XrdSfsFileOffset   fileOffset,
00106                             char              *buffer,
00107                             XrdSfsXferSize     buffer_size);
00108 
00109         int            read(XrdSfsAio *aioparm);
00110 
00111         XrdSfsXferSize write(XrdSfsFileOffset   fileOffset,
00112                              const char        *buffer,
00113                              XrdSfsXferSize     buffer_size);
00114 
00115         int            write(XrdSfsAio *aioparm);
00116 
00117         int            sync();
00118 
00119         int            sync(XrdSfsAio *aiop);
00120 
00121         int            stat(struct stat *buf);
00122 
00123         int            truncate(XrdSfsFileOffset   fileOffset);
00124 
00125         int            getCXinfo(char cxtype[4], int &cxrsz);
00126 
00127                        XrdBwmFile(const char *user, int monid);
00128 
00129 virtual               ~XrdBwmFile() {if (oh) close();}
00130 
00131 protected:
00132        const char   *tident;
00133 
00134 private:
00135 
00136 XrdBwmHandle  *oh;
00137 };
00138 
00139 /******************************************************************************/
00140 /*                          C l a s s   X r d B w m                           */
00141 /******************************************************************************/
00142 
00143 class XrdAccAuthorize;
00144 class XrdBwmLogger;
00145 class XrdBwmPolicy;
00146 
00147 class XrdBwm : public XrdSfsFileSystem
00148 {
00149 friend class XrdBwmDirectory;
00150 friend class XrdBwmFile;
00151 
00152 public:
00153 
00154 // Object allocation
00155 //
00156         XrdSfsDirectory *newDir(char *user=0, int monid=0)
00157                         {return (XrdSfsDirectory *)new XrdBwmDirectory(user,monid);}
00158 
00159         XrdSfsFile      *newFile(char *user=0, int monid=0)
00160                         {return      (XrdSfsFile *)new XrdBwmFile(user,monid);}
00161 
00162 // Other functions
00163 //
00164         int            chmod(const char             *Name,
00165                                    XrdSfsMode        Mode,
00166                                    XrdOucErrInfo    &out_error,
00167                              const XrdSecEntity     *client,
00168                              const char             *opaque = 0);
00169 
00170         int            exists(const char                *fileName,
00171                                     XrdSfsFileExistence &exists_flag,
00172                                     XrdOucErrInfo       &out_error,
00173                               const XrdSecEntity        *client,
00174                               const char                *opaque = 0);
00175 
00176         int            fsctl(const int               cmd,
00177                              const char             *args,
00178                                    XrdOucErrInfo    &out_error,
00179                              const XrdSecEntity     *client);
00180 
00181         int            getStats(char *buff, int blen) {return 0;}
00182 
00183 const   char          *getVersion();
00184 
00185         int            mkdir(const char             *dirName,
00186                                    XrdSfsMode        Mode,
00187                                    XrdOucErrInfo    &out_error,
00188                              const XrdSecEntity     *client,
00189                              const char             *opaque = 0);
00190 
00191         int            prepare(      XrdSfsPrep       &pargs,
00192                                      XrdOucErrInfo    &out_error,
00193                                const XrdSecEntity     *client = 0);
00194 
00195         int            rem(const char             *path,
00196                                  XrdOucErrInfo    &out_error,
00197                            const XrdSecEntity     *client,
00198                            const char             *info = 0)
00199                           {return remove('f', path, out_error, client, info);}
00200 
00201         int            remdir(const char             *dirName,
00202                                     XrdOucErrInfo    &out_error,
00203                               const XrdSecEntity     *client,
00204                               const char             *info = 0)
00205                              {return remove('d',dirName,out_error,client,info);}
00206 
00207         int            rename(const char             *oldFileName,
00208                               const char             *newFileName,
00209                                     XrdOucErrInfo    &out_error,
00210                               const XrdSecEntity     *client,
00211                               const char             *infoO = 0,
00212                                const char            *infoN = 0);
00213 
00214         int            stat(const char             *Name,
00215                                   struct stat      *buf,
00216                                   XrdOucErrInfo    &out_error,
00217                             const XrdSecEntity     *client,
00218                             const char             *opaque = 0);
00219 
00220         int            stat(const char             *Name,
00221                                   mode_t           &mode,
00222                                   XrdOucErrInfo    &out_error,
00223                             const XrdSecEntity     *client,
00224                             const char             *opaque = 0);
00225 
00226         int            truncate(const char             *Name,
00227                                       XrdSfsFileOffset fileOffset,
00228                                       XrdOucErrInfo    &out_error,
00229                                 const XrdSecEntity     *client = 0,
00230                                 const char             *opaque = 0);
00231 // Management functions
00232 //
00233 virtual int            Configure(XrdSysError &);
00234 
00235                        XrdBwm();
00236 virtual               ~XrdBwm() {}  // Too complicate to delete :-)
00237 
00238 /******************************************************************************/
00239 /*                  C o n f i g u r a t i o n   V a l u e s                   */
00240 /******************************************************************************/
00241 
00242 XrdVersionInfo *myVersion;  //    ->Version compiled with
00243 
00244 char *ConfigFN;       //    ->Configuration filename
00245 char *HostName;       //    ->Our hostname
00246 char *HostPref;       //    ->Our hostname with domain removed
00247 char *myDomain;       //    ->Our domain name
00248 int   myDomLen;       //
00249 char  Authorize;
00250 char  Reserved[7];
00251 
00252 /******************************************************************************/
00253 /*                       P r o t e c t e d   I t e m s                        */
00254 /******************************************************************************/
00255 
00256 protected:
00257 
00258 virtual int   ConfigXeq(char *var, XrdOucStream &, XrdSysError &);
00259         int   Emsg(const char *, XrdOucErrInfo  &, int,
00260                    const char *, const char *y="");
00261         int   Emsg(const char *, XrdOucErrInfo  &, const char *,
00262                    const char *, const char *y="");
00263         int   Stall(XrdOucErrInfo  &, int, const char *);
00264   
00265 /******************************************************************************/
00266 /*                 P r i v a t e   C o n f i g u r a t i o n                  */
00267 /******************************************************************************/
00268 
00269 private:
00270   
00271 XrdAccAuthorize  *Authorization;  //    ->Authorization   Service
00272 char             *AuthLib;        //    ->Authorization   Library
00273 char             *AuthParm;       //    ->Authorization   Parameters
00274 XrdBwmLogger     *Logger;         //    ->Logger
00275 XrdBwmPolicy     *Policy;         //    ->Policy
00276 char             *PolLib;
00277 char             *PolParm;
00278 char             *locResp;        //    ->Locate Response
00279 int               locRlen;        //      Length of locResp;
00280 int               PolSlotsIn;
00281 int               PolSlotsOut;
00282 
00283 static XrdBwmHandle     *dummyHandle;
00284 XrdSysMutex              ocMutex; // Global mutex for open/close
00285 
00286 /******************************************************************************/
00287 /*                            O t h e r   D a t a                             */
00288 /******************************************************************************/
00289 
00290 int           remove(const char type, const char *path,
00291                      XrdOucErrInfo &out_error, const XrdSecEntity     *client,
00292                      const char *opaque);
00293 // Function used during Configuration
00294 //
00295 int           setupAuth(XrdSysError &);
00296 int           setupPolicy(XrdSysError &);
00297 int           xalib(XrdOucStream &, XrdSysError &);
00298 int           xlog(XrdOucStream &, XrdSysError &);
00299 int           xpol(XrdOucStream &, XrdSysError &);
00300 int           xtrace(XrdOucStream &, XrdSysError &);
00301 };
00302 #endif