XrdOfsHandle.hh

Go to the documentation of this file.
00001 #ifndef __OFS_HANDLE__
00002 #define __OFS_HANDLE__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                       X r d O f s H a n d l e . h h                        */
00006 /*                                                                            */
00007 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00011 /******************************************************************************/
00012 
00013 //         $Id: XrdOfsHandle.hh 29874 2009-08-21 16:56:04Z ganis $
00014 
00015 /* These are private data structures. They are allocated dynamically to the
00016    appropriate size (yes, that means dbx has a tough time).
00017 */
00018 
00019 #include <stdlib.h>
00020 
00021 #include "XrdOuc/XrdOucCRC.hh"
00022 #include "XrdSys/XrdSysPthread.hh"
00023 
00024 /******************************************************************************/
00025 /*                    C l a s s   X r d O f s H a n K e y                     */
00026 /******************************************************************************/
00027   
00028 class XrdOfsHanKey
00029 {
00030 public:
00031 
00032 const char          *Val;
00033 unsigned int         Hash;
00034 short                Len;
00035 unsigned short       Links;
00036 
00037 inline XrdOfsHanKey& operator=(const XrdOfsHanKey &rhs)
00038                                  {Val = strdup(rhs.Val); Hash = rhs.Hash;
00039                                   Len = rhs.Len;
00040                                   return *this;
00041                                  }
00042 
00043 inline int           operator==(const XrdOfsHanKey &oth)
00044                                  {return Hash == oth.Hash && Len == oth.Len
00045                                       && !strcmp(Val, oth.Val);
00046                                  }
00047 
00048 inline int           operator!=(const XrdOfsHanKey &oth)
00049                                  {return Hash != oth.Hash || Len != oth.Len
00050                                       || strcmp(Val, oth.Val);
00051                                  }
00052 
00053                     XrdOfsHanKey(const char *key=0, int kln=0)
00054                                 : Val(key), Len(kln), Links(0)
00055                     {Hash = (key && kln ?
00056                           XrdOucCRC::CRC32((const unsigned char *)key,kln) : 0);
00057                     }
00058 
00059                    ~XrdOfsHanKey() {};
00060 };
00061 
00062 /******************************************************************************/
00063 /*                    C l a s s   X r d O f s H a n T a b                     */
00064 /******************************************************************************/
00065 
00066 class XrdOfsHandle;
00067   
00068 class XrdOfsHanTab
00069 {
00070 public:
00071 void           Add(XrdOfsHandle *hP);
00072 
00073 XrdOfsHandle  *Find(XrdOfsHanKey &Key);
00074 
00075 int            Remove(XrdOfsHandle *rip);
00076 
00077 // When allocateing a new nash, specify the required starting size. Make
00078 // sure that the previous number is the correct Fibonocci antecedent. The
00079 // series is simply n[j] = n[j-1] + n[j-2].
00080 //
00081     XrdOfsHanTab(int psize = 987, int size = 1597);
00082    ~XrdOfsHanTab() {} // Never gets deleted
00083 
00084 private:
00085 
00086 static const int LoadMax = 80;
00087 
00088 void             Expand();
00089 
00090 XrdOfsHandle   **nashtable;
00091 int              prevtablesize;
00092 int              nashtablesize;
00093 int              nashnum;
00094 int              Threshold;
00095 };
00096 
00097 /******************************************************************************/
00098 /*                    C l a s s   X r d O f s H a n d l e                     */
00099 /******************************************************************************/
00100   
00101 class XrdOssDF;
00102 class XrdOfsHanCB;
00103 class XrdOfsHanPsc;
00104 
00105 class XrdOfsHandle
00106 {
00107 friend class XrdOfsHanTab;
00108 friend class XrdOfsHanXpr;
00109 public:
00110 
00111 char                isPending;    // 1-> File  is pending sync()
00112 char                isChanged;    // 1-> File was modified
00113 char                isCompressed; // 1-> File  is compressed
00114 char                isRW;         // T-> File  is open in r/w mode
00115 
00116 void                Activate(XrdOssDF *ssP) {ssi = ssP;}
00117 
00118 static const int    opRW = 1;
00119 static const int    opPC = 3;
00120 
00121 static       int    Alloc(const char *thePath,int Opts,XrdOfsHandle **Handle);
00122 static       int    Alloc(                             XrdOfsHandle **Handle);
00123 
00124 static       void   Hide(const char *thePath);
00125 
00126 inline       int    Inactive() {return (ssi == ossDF);}
00127 
00128 inline const char  *Name() {return Path.Val;}
00129 
00130              int    PoscGet(short &Mode, int Done=0);
00131 
00132              int    PoscSet(const char *User, int Unum, short Mode);
00133 
00134        const char  *PoscUsr();
00135 
00136              int    Retire(long long *retsz=0, char *buff=0, int blen=0);
00137 
00138              int    Retire(XrdOfsHanCB *, int DSec);
00139 
00140 XrdOssDF           &Select(void) {return *ssi;}   // To allow for mt interfaces
00141 
00142 static       int    StartXpr(int Init=0);         // Internal use only!
00143 
00144              int    Usage() {return Path.Links;}
00145 
00146 inline       void   Lock()   {hMutex.Lock();}
00147 inline       void   UnLock() {hMutex.UnLock();}
00148 
00149           XrdOfsHandle() : Path(0,0) {}
00150 
00151          ~XrdOfsHandle() {Retire();}
00152 
00153 private:
00154 static int           Alloc(XrdOfsHanKey, int Opts, XrdOfsHandle **Handle);
00155        int           WaitLock(void);
00156 
00157 static const int     LockTries =   3; // Times to try for a lock
00158 static const int     LockWait  = 333; // Mills to wait between tries
00159 static const int     nolokDelay=   3; // Secs to delay client when lock failed
00160 static const int     nomemDelay=  15; // Secs to delay client when ENOMEM
00161 
00162 static XrdSysMutex   myMutex;
00163 static XrdOfsHanTab  roTable;    // File handles open r/o
00164 static XrdOfsHanTab  rwTable;    // File Handles open r/w
00165 static XrdOssDF     *ossDF;      // Dummy storage sysem
00166 static XrdOfsHandle *Free;       // List of free handles
00167 
00168        XrdSysMutex   hMutex;
00169        XrdOssDF     *ssi;        // Storage System Interface
00170        XrdOfsHandle *Next;
00171        XrdOfsHanKey  Path;       // Path for this handle
00172        XrdOfsHanPsc *Posc;       // -> Info for posc-type files
00173 };
00174   
00175 /******************************************************************************/
00176 /*                     C l a s s   X r d O f s H a n C B                      */
00177 /******************************************************************************/
00178   
00179 class XrdOfsHanCB
00180 {
00181 public:
00182 
00183 virtual void Retired(XrdOfsHandle *) = 0;
00184 
00185              XrdOfsHanCB() {}
00186 virtual     ~XrdOfsHanCB() {}
00187 };
00188 #endif

Generated on Tue Jul 5 14:46:44 2011 for ROOT_528-00b_version by  doxygen 1.5.1