xrootd
|
00001 #ifndef __XRDOSS_CACHE_H__ 00002 #define __XRDOSS_CACHE_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O s s C a c h 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$ 00014 00015 #include <time.h> 00016 #include <sys/stat.h> 00017 #include "XrdOuc/XrdOucDLlist.hh" 00018 #include "XrdSys/XrdSysError.hh" 00019 #include "XrdSys/XrdSysPthread.hh" 00020 00021 /******************************************************************************/ 00022 /* O S D e p e n d e n t D e f i n i t i o n s */ 00023 /******************************************************************************/ 00024 00025 #ifdef __solaris__ 00026 #include <sys/statvfs.h> 00027 #define STATFS_t struct statvfs 00028 #define FS_Stat(a,b) statvfs(a,b) 00029 #define FS_BLKSZ f_frsize 00030 #define FS_FFREE f_favail 00031 #endif 00032 #ifdef __linux__ 00033 #include <sys/vfs.h> 00034 #define FS_Stat(a,b) statfs(a,b) 00035 #define STATFS_t struct statfs 00036 #define FS_BLKSZ f_bsize 00037 #define FS_FFREE f_ffree 00038 #endif 00039 #ifdef AIX 00040 #include <sys/statfs.h> 00041 #define STATFS_t struct statfs 00042 #define FS_Stat(a,b) statfs(a,b) 00043 #define FS_BLKSZ f_bsize 00044 #define FS_FFREE f_ffree 00045 #endif 00046 #if defined(__macos__) || defined(__FreeBSD__) 00047 #include <sys/param.h> 00048 #include <sys/mount.h> 00049 #define STATFS_t struct statfs 00050 #define FS_Stat(a,b) statfs(a,b) 00051 #define FS_BLKSZ f_bsize 00052 #define FS_FFREE f_ffree 00053 #endif 00054 00055 /******************************************************************************/ 00056 /* X r d O s s C a c h e _ S p a c e */ 00057 /******************************************************************************/ 00058 00059 class XrdOssCache_Space 00060 { 00061 public: 00062 00063 long long Total; 00064 long long Free; 00065 long long Maxfree; 00066 long long Largest; 00067 long long Inodes; 00068 long long Inleft; 00069 long long Usage; 00070 long long Quota; 00071 00072 XrdOssCache_Space() : Total(0), Free(0), Maxfree(0), Largest(0), 00073 Inodes(0), Inleft(0), Usage(-1), Quota(-1) {} 00074 ~XrdOssCache_Space() {} 00075 }; 00076 00077 /******************************************************************************/ 00078 /* X r d O s s C a c h e _ F S D a t a */ 00079 /******************************************************************************/ 00080 00081 // Flags values for FSData 00082 // 00083 #define XrdOssFSData_OFFLINE 0x0001 00084 #define XrdOssFSData_ADJUSTED 0x0002 00085 #define XrdOssFSData_REFRESH 0x0004 00086 00087 class XrdOssCache_FSData 00088 { 00089 public: 00090 00091 XrdOssCache_FSData *next; 00092 long long size; 00093 long long frsz; 00094 dev_t fsid; 00095 const char *path; 00096 time_t updt; 00097 int stat; 00098 00099 XrdOssCache_FSData(const char *, STATFS_t &, dev_t); 00100 ~XrdOssCache_FSData() {if (path) free((void *)path);} 00101 }; 00102 00103 /******************************************************************************/ 00104 /* X r d O s s C a c h e _ F S */ 00105 /******************************************************************************/ 00106 00107 class XrdOssCache_Group; 00108 00109 class XrdOssCache_FS 00110 { 00111 public: 00112 00113 enum FSOpts {None = 0, isXA = 1}; 00114 00115 XrdOssCache_FS *next; 00116 const char *group; 00117 const char *path; 00118 int plen; 00119 FSOpts opts; 00120 char suffix[4]; // Corresponds to OssPath::sfxLen 00121 XrdOssCache_FSData *fsdata; 00122 XrdOssCache_Group *fsgroup; 00123 00124 static int Add(const char *Path); 00125 static long long freeSpace(long long &Size, const char *path=0); 00126 static long long freeSpace(XrdOssCache_Space &Space, const char *path); 00127 static int getSpace( XrdOssCache_Space &Space, const char *sname); 00128 static int getSpace( XrdOssCache_Space &Space, XrdOssCache_Group *fsg); 00129 00130 XrdOssCache_FS( int &retc, 00131 const char *fsg, 00132 const char *fsp, 00133 FSOpts opt); 00134 ~XrdOssCache_FS() {if (group) free((void *)group); 00135 if (path) free((void *)path); 00136 } 00137 }; 00138 00139 /******************************************************************************/ 00140 /* X r d O s s C a c h e _ G r o u p */ 00141 /******************************************************************************/ 00142 00143 // Eventually we will have management information associated with cache groups 00144 // 00145 class XrdOssCache_Group 00146 { 00147 public: 00148 00149 XrdOssCache_Group *next; 00150 char *group; 00151 XrdOssCache_FS *curr; 00152 long long Usage; 00153 long long Quota; 00154 int GRPid; 00155 static long long PubQuota; 00156 00157 static XrdOssCache_Group *fsgroups; 00158 00159 XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0) 00160 : next(0), group(strdup(grp)), curr(fsp), Usage(0), 00161 Quota(-1), GRPid(-1) {} 00162 ~XrdOssCache_Group() {if (group) free((void *)group);} 00163 }; 00164 00165 /******************************************************************************/ 00166 /* X r d O s s C a c h e */ 00167 /******************************************************************************/ 00168 00169 class XrdOssCache 00170 { 00171 public: 00172 00173 static void Adjust(dev_t devid, off_t size); 00174 00175 static void Adjust(const char *Path, off_t size, struct stat *buf=0); 00176 00177 static void Adjust(XrdOssCache_FS *fsp, off_t size); 00178 00179 struct allocInfo 00180 {const char *Path; // Req: Local file name 00181 const char *cgName; // Req: Cache group name 00182 long long cgSize; // Opt: Estimated size 00183 const char *cgPath; // Opt: Specific partition path 00184 int cgPlen; // Opt: Length of partition path 00185 int cgPFsz; // Req: Size of buffer 00186 char *cgPFbf; // Req: Buffer for cache pfn of size cgPFsz 00187 char *cgPsfx; // Out: -> pfn suffix area. If 0, non-xa cache 00188 XrdOssCache_FS *cgFSp; // Out: -> Cache file system definition 00189 mode_t aMode; // Opt: Create mode; if 0, pfn file not created 00190 00191 allocInfo(const char *pP, char *bP, int bL) 00192 : Path(pP), cgName(0), cgSize(0), cgPath(0), cgPlen(0), 00193 cgPFsz(bL), cgPFbf(bP), cgPsfx(0), cgFSp(0), aMode(0) {} 00194 ~allocInfo() {} 00195 }; 00196 00197 static int Alloc(allocInfo &aInfo); 00198 00199 static XrdOssCache_FS *Find(const char *Path, int lklen=0); 00200 00201 static int Init(const char *UDir, const char *Qfile, int isSOL); 00202 00203 static int Init(long long aMin, int ovhd, int aFuzz); 00204 00205 static void List(const char *lname, XrdSysError &Eroute); 00206 00207 static char *Parse(const char *token, char *cbuff, int cblen); 00208 00209 static void *Scan(int cscanint); 00210 00211 XrdOssCache() {} 00212 ~XrdOssCache() {} 00213 00214 static XrdSysMutex Mutex; // Cache context lock 00215 00216 static long long fsTotal; // Total number of bytes known 00217 static long long fsLarge; // Total number of bytes in largest fspart 00218 static long long fsTotFr; // Total number of bytes free 00219 static long long fsFree; // Maximum contiguous free space 00220 static long long fsSize; // Size of partition with fsFree 00221 static XrdOssCache_FS *fsfirst; // -> First filesystem 00222 static XrdOssCache_FS *fslast; // -> Last filesystem 00223 static XrdOssCache_FSData *fsdata; // -> Filesystem data 00224 static int fsCount; // Number of file systems 00225 00226 private: 00227 00228 static long long minAlloc; 00229 static double fuzAlloc; 00230 static int ovhAlloc; 00231 static int Quotas; 00232 static int Usage; 00233 }; 00234 #endif