Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef __OFS_HANDLE__
0002 #define __OFS_HANDLE__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                       X r d O f s H a n d l e . h h                        */
0006 /*                                                                            */
0007 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 /* These are private data structures. They are allocated dynamically to the
0034    appropriate size (yes, that means dbx has a tough time).
0035 */
0036 
0037 #include <cstdlib>
0038 
0039 #include "XrdOuc/XrdOucCRC.hh"
0040 #include "XrdSys/XrdSysPthread.hh"
0041 
0042 /******************************************************************************/
0043 /*                    C l a s s   X r d O f s H a n K e y                     */
0044 /******************************************************************************/
0045   
0046 class XrdOfsHanKey
0047 {
0048 public:
0049 
0050 const char          *Val;
0051 unsigned int         Links;
0052 unsigned int         Hash;
0053 short                Len;
0054 
0055 inline XrdOfsHanKey& operator=(const XrdOfsHanKey &rhs)
0056                                  {Val = strdup(rhs.Val); Hash = rhs.Hash;
0057                                   Len = rhs.Len;
0058                                   return *this;
0059                                  }
0060 
0061 inline int           operator==(const XrdOfsHanKey &oth)
0062                                  {return Hash == oth.Hash && Len == oth.Len
0063                                       && !strcmp(Val, oth.Val);
0064                                  }
0065 
0066 inline int           operator!=(const XrdOfsHanKey &oth)
0067                                  {return Hash != oth.Hash || Len != oth.Len
0068                                       || strcmp(Val, oth.Val);
0069                                  }
0070 
0071                     XrdOfsHanKey(const char *key=0, int kln=0)
0072                                 : Val(key), Links(0), Len(kln)
0073                     {Hash = (key && kln ?
0074                           XrdOucCRC::CRC32((const unsigned char *)key,kln) : 0);
0075                     }
0076 
0077             XrdOfsHanKey(const XrdOfsHanKey&) = default;
0078 
0079                    ~XrdOfsHanKey() {};
0080 };
0081 
0082 /******************************************************************************/
0083 /*                    C l a s s   X r d O f s H a n T a b                     */
0084 /******************************************************************************/
0085 
0086 class XrdOfsHandle;
0087   
0088 class XrdOfsHanTab
0089 {
0090 public:
0091 void           Add(XrdOfsHandle *hP);
0092 
0093 XrdOfsHandle  *Find(XrdOfsHanKey &Key);
0094 
0095 int            Remove(XrdOfsHandle *rip);
0096 
0097 // When allocateing a new nash, specify the required starting size. Make
0098 // sure that the previous number is the correct Fibonocci antecedent. The
0099 // series is simply n[j] = n[j-1] + n[j-2].
0100 //
0101     XrdOfsHanTab(int psize = 987, int size = 1597);
0102    ~XrdOfsHanTab() {} // Never gets deleted
0103 
0104 private:
0105 
0106 static const int LoadMax = 80;
0107 
0108 void             Expand();
0109 
0110 XrdOfsHandle   **nashtable;
0111 int              prevtablesize;
0112 int              nashtablesize;
0113 int              nashnum;
0114 int              Threshold;
0115 };
0116 
0117 /******************************************************************************/
0118 /*                    C l a s s   X r d O f s H a n d l e                     */
0119 /******************************************************************************/
0120   
0121 class XrdOssDF;
0122 class XrdOfsHanCB;
0123 class XrdOfsHanPsc;
0124 
0125 class XrdOfsHandle
0126 {
0127 friend class XrdOfsHanTab;
0128 friend class XrdOfsHanXpr;
0129 public:
0130 
0131 char                isPending;    // 1-> File  is pending sync()
0132 char                isChanged;    // 1-> File was modified
0133 char                isCompressed; // 1-> File  is compressed
0134 char                isRW;         // T-> File  is open in r/w mode
0135 
0136 void                Activate(XrdOssDF *ssP) {ssi = ssP;}
0137 
0138 static const int    opRW = 1;
0139 static const int    opPC = 3;
0140 
0141 static       int    Alloc(const char *thePath,int Opts,XrdOfsHandle **Handle);
0142 static       int    Alloc(                             XrdOfsHandle **Handle);
0143 
0144 static       void   Hide(const char *thePath);
0145 
0146 inline       int    Inactive() {return (ssi == ossDF);}
0147 
0148 inline const char  *Name() {return Path.Val;}
0149 
0150              int    PoscGet(short &Mode, int Done=0);
0151 
0152              int    PoscSet(const char *User, int Unum, short Mode);
0153 
0154        const char  *PoscUsr();
0155 
0156              int    Retire(int &retc, long long *retsz=0,
0157                            char *buff=0, int blen=0);
0158 
0159              int    Retire(XrdOfsHanCB *, int DSec);
0160 
0161 XrdOssDF           &Select(void) {return *ssi;}   // To allow for mt interfaces
0162 
0163 static       int    StartXpr(int Init=0);         // Internal use only!
0164 
0165              void   Suppress(int rrc=-EDOM, int wrc=-EDOM); // Only for R/W!
0166 
0167              int    Usage() {return Path.Links;}
0168 
0169 inline       void   Lock()   {hMutex.Lock();}
0170 inline       void   UnLock() {hMutex.UnLock();}
0171 
0172           XrdOfsHandle() : Path(0,0) {}
0173 
0174          ~XrdOfsHandle() {int retc; Retire(retc);}
0175 
0176 private:
0177 static int           Alloc(XrdOfsHanKey, int Opts, XrdOfsHandle **Handle);
0178        int           WaitLock(void);
0179 
0180 static const int     LockTries =   3; // Times to try for a lock
0181 static const int     LockWait  = 333; // Mills to wait between tries
0182 static const int     nolokDelay=   3; // Secs to delay client when lock failed
0183 static const int     nomemDelay=  15; // Secs to delay client when ENOMEM
0184 
0185 static XrdSysMutex   myMutex;
0186 static XrdOfsHanTab  roTable;    // File handles open r/o
0187 static XrdOfsHanTab  rwTable;    // File Handles open r/w
0188 static XrdOssDF     *ossDF;      // Dummy storage sysem
0189 static XrdOfsHandle *Free;       // List of free handles
0190 
0191        XrdSysMutex   hMutex;
0192        XrdOssDF     *ssi;        // Storage System Interface
0193        XrdOfsHandle *Next;
0194        XrdOfsHanKey  Path;       // Path for this handle
0195        XrdOfsHanPsc *Posc;       // -> Info for posc-type files
0196 };
0197   
0198 /******************************************************************************/
0199 /*                     C l a s s   X r d O f s H a n C B                      */
0200 /******************************************************************************/
0201   
0202 class XrdOfsHanCB
0203 {
0204 public:
0205 
0206 virtual void Retired(XrdOfsHandle *) = 0;
0207 
0208              XrdOfsHanCB() {}
0209 virtual     ~XrdOfsHanCB() {}
0210 };
0211 #endif