xrootd
XrdXrootdFile.hh
Go to the documentation of this file.
00001 #ifndef _XROOTD_FILE_H_
00002 #define _XROOTD_FILE_H_
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                      X r d X r o o t d F i l e . h h                       */
00006 /*                                                                            */
00007 /* (c) 2004 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 
00034 #include "XProtocol/XPtypes.hh"
00035 #include "XrdXrootd/XrdXrootdFileStats.hh"
00036 
00037 /******************************************************************************/
00038 /*                         X r d X r o o t d F i l e                          */
00039 /******************************************************************************/
00040 
00041 class XrdSfsFile;
00042 class XrdXrootdFileLock;
00043 class XrdXrootdMonitor;
00044 
00045 class XrdXrootdFile
00046 {
00047 public:
00048 
00049 XrdSfsFile  *XrdSfsp;           // -> Actual file object
00050 char        *mmAddr;            // Memory mapped location, if any
00051 char         FileKey[34];       // -> Unique hash name for the file
00052 char         Reserved[2];
00053 char         FileMode;          // 'r' or 'w'
00054 char         AsyncMode;         // 1 -> if file in async r/w mode
00055 char         isMMapped;         // 1 -> file is memory mapped
00056 char         sfEnabled;         // 1 -> file is sendfile enabled
00057 int          fdNum;             // File descriptor number if regular file
00058 const char  *ID;                // File user
00059 
00060 XrdXrootdFileStats Stats;       // File access statistics
00061 
00062 static void Init(XrdXrootdFileLock *lp, int sfok) {Locker = lp; sfOK = sfok;}
00063 
00064            XrdXrootdFile(const char *id, XrdSfsFile *fp, char mode='r',
00065                          char async='\0', int sfOK=0, struct stat *sP=0);
00066           ~XrdXrootdFile();
00067 
00068 private:
00069 int bin2hex(char *outbuff, char *inbuff, int inlen);
00070 static XrdXrootdFileLock *Locker;
00071 static int                sfOK;
00072 static const char        *TraceID;
00073 };
00074  
00075 /******************************************************************************/
00076 /*                    X r d X r o o t d F i l e T a b l e                     */
00077 /******************************************************************************/
00078 
00079 // The before define the structure of the file table. We will have FTABSIZE
00080 // internal table entries. We will then provide an external linear table
00081 // that increases by FTABSIZE entries. There is one file table per link and
00082 // it is owned by the base protocol object.
00083 //
00084 #define XRD_FTABSIZE   16
00085   
00086 // WARNING! Manipulation (i.e., Add/Del/delete) of this object must be
00087 //          externally serialized at the link level. Only one thread
00088 //          may be active w.r.t this object during manipulation!
00089 //
00090 class XrdXrootdFileTable
00091 {
00092 public:
00093 
00094        int            Add(XrdXrootdFile *fp);
00095 
00096        void           Del(int fnum);
00097 
00098 inline XrdXrootdFile *Get(int fnum)
00099                          {if (fnum >= 0)
00100                              {if (fnum < XRD_FTABSIZE) return FTab[fnum];
00101                               if (XTab && (fnum-XRD_FTABSIZE)<XTnum)
00102                                  return XTab[fnum-XRD_FTABSIZE];
00103                              }
00104                           return (XrdXrootdFile *)0;
00105                          }
00106 
00107        void           Recycle(XrdXrootdMonitor *monP=0, bool monF=false);
00108 
00109        XrdXrootdFileTable(unsigned int mid=0) : FTfree(0), monID(mid),
00110                                                 XTab(0), XTnum(0), XTfree(0)
00111                          {memset((void *)FTab, 0, sizeof(FTab));}
00112 
00113 private:
00114 
00115       ~XrdXrootdFileTable() {} // Always use Recycle() to delete this object!
00116 
00117 static const char *TraceID;
00118 
00119 XrdXrootdFile *FTab[XRD_FTABSIZE];
00120 int            FTfree;
00121 unsigned int   monID;
00122 
00123 XrdXrootdFile **XTab;
00124 int             XTnum;
00125 int             XTfree;
00126 };
00127 #endif