|
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-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <time.h> 00034 #include <sys/stat.h> 00035 #include "XrdOuc/XrdOucDLlist.hh" 00036 #include "XrdSys/XrdSysError.hh" 00037 #include "XrdSys/XrdSysPthread.hh" 00038 00039 /******************************************************************************/ 00040 /* O S D e p e n d e n t D e f i n i t i o n s */ 00041 /******************************************************************************/ 00042 00043 #ifdef __solaris__ 00044 #include <sys/statvfs.h> 00045 #define STATFS_t struct statvfs 00046 #define FS_Stat(a,b) statvfs(a,b) 00047 #define FS_BLKSZ f_frsize 00048 #define FS_FFREE f_favail 00049 #endif 00050 #ifdef __linux__ 00051 #include <sys/vfs.h> 00052 #define FS_Stat(a,b) statfs(a,b) 00053 #define STATFS_t struct statfs 00054 #define FS_BLKSZ f_bsize 00055 #define FS_FFREE f_ffree 00056 #endif 00057 #ifdef AIX 00058 #include <sys/statfs.h> 00059 #define STATFS_t struct statfs 00060 #define FS_Stat(a,b) statfs(a,b) 00061 #define FS_BLKSZ f_bsize 00062 #define FS_FFREE f_ffree 00063 #endif 00064 #if defined(__macos__) || defined(__FreeBSD__) 00065 #include <sys/param.h> 00066 #include <sys/mount.h> 00067 #define STATFS_t struct statfs 00068 #define FS_Stat(a,b) statfs(a,b) 00069 #define FS_BLKSZ f_bsize 00070 #define FS_FFREE f_ffree 00071 #endif 00072 00073 /******************************************************************************/ 00074 /* X r d O s s C a c h e _ S p a c e */ 00075 /******************************************************************************/ 00076 00077 class XrdOssCache_Space 00078 { 00079 public: 00080 00081 long long Total; 00082 long long Free; 00083 long long Maxfree; 00084 long long Largest; 00085 long long Inodes; 00086 long long Inleft; 00087 long long Usage; 00088 long long Quota; 00089 00090 XrdOssCache_Space() : Total(0), Free(0), Maxfree(0), Largest(0), 00091 Inodes(0), Inleft(0), Usage(-1), Quota(-1) {} 00092 ~XrdOssCache_Space() {} 00093 }; 00094 00095 /******************************************************************************/ 00096 /* X r d O s s C a c h e _ F S D a t a */ 00097 /******************************************************************************/ 00098 00099 // Flags values for FSData 00100 // 00101 #define XrdOssFSData_OFFLINE 0x0001 00102 #define XrdOssFSData_ADJUSTED 0x0002 00103 #define XrdOssFSData_REFRESH 0x0004 00104 00105 class XrdOssCache_FSData 00106 { 00107 public: 00108 00109 XrdOssCache_FSData *next; 00110 long long size; 00111 long long frsz; 00112 dev_t fsid; 00113 const char *path; 00114 time_t updt; 00115 int stat; 00116 00117 XrdOssCache_FSData(const char *, STATFS_t &, dev_t); 00118 ~XrdOssCache_FSData() {if (path) free((void *)path);} 00119 }; 00120 00121 /******************************************************************************/ 00122 /* X r d O s s C a c h e _ F S */ 00123 /******************************************************************************/ 00124 00125 class XrdOssCache_Group; 00126 00127 class XrdOssCache_FS 00128 { 00129 public: 00130 00131 enum FSOpts {None = 0, isXA = 1}; 00132 00133 XrdOssCache_FS *next; 00134 const char *group; 00135 const char *path; 00136 int plen; 00137 FSOpts opts; 00138 char suffix[4]; // Corresponds to OssPath::sfxLen 00139 XrdOssCache_FSData *fsdata; 00140 XrdOssCache_Group *fsgroup; 00141 00142 static int Add(const char *Path); 00143 static long long freeSpace(long long &Size, const char *path=0); 00144 static long long freeSpace(XrdOssCache_Space &Space, const char *path); 00145 static int getSpace( XrdOssCache_Space &Space, const char *sname); 00146 static int getSpace( XrdOssCache_Space &Space, XrdOssCache_Group *fsg); 00147 00148 XrdOssCache_FS( int &retc, 00149 const char *fsg, 00150 const char *fsp, 00151 FSOpts opt); 00152 ~XrdOssCache_FS() {if (group) free((void *)group); 00153 if (path) free((void *)path); 00154 } 00155 }; 00156 00157 /******************************************************************************/ 00158 /* X r d O s s C a c h e _ G r o u p */ 00159 /******************************************************************************/ 00160 00161 // Eventually we will have management information associated with cache groups 00162 // 00163 class XrdOssCache_Group 00164 { 00165 public: 00166 00167 XrdOssCache_Group *next; 00168 char *group; 00169 XrdOssCache_FS *curr; 00170 long long Usage; 00171 long long Quota; 00172 int GRPid; 00173 static long long PubQuota; 00174 00175 static XrdOssCache_Group *fsgroups; 00176 00177 XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0) 00178 : next(0), group(strdup(grp)), curr(fsp), Usage(0), 00179 Quota(-1), GRPid(-1) {} 00180 ~XrdOssCache_Group() {if (group) free((void *)group);} 00181 }; 00182 00183 /******************************************************************************/ 00184 /* X r d O s s C a c h e */ 00185 /******************************************************************************/ 00186 00187 class XrdOssCache 00188 { 00189 public: 00190 00191 static void Adjust(dev_t devid, off_t size); 00192 00193 static void Adjust(const char *Path, off_t size, struct stat *buf=0); 00194 00195 static void Adjust(XrdOssCache_FS *fsp, off_t size); 00196 00197 struct allocInfo 00198 {const char *Path; // Req: Local file name 00199 const char *cgName; // Req: Cache group name 00200 long long cgSize; // Opt: Estimated size 00201 const char *cgPath; // Opt: Specific partition path 00202 int cgPlen; // Opt: Length of partition path 00203 int cgPFsz; // Req: Size of buffer 00204 char *cgPFbf; // Req: Buffer for cache pfn of size cgPFsz 00205 char *cgPsfx; // Out: -> pfn suffix area. If 0, non-xa cache 00206 XrdOssCache_FS *cgFSp; // Out: -> Cache file system definition 00207 mode_t aMode; // Opt: Create mode; if 0, pfn file not created 00208 00209 allocInfo(const char *pP, char *bP, int bL) 00210 : Path(pP), cgName(0), cgSize(0), cgPath(0), cgPlen(0), 00211 cgPFsz(bL), cgPFbf(bP), cgPsfx(0), cgFSp(0), aMode(0) {} 00212 ~allocInfo() {} 00213 }; 00214 00215 static int Alloc(allocInfo &aInfo); 00216 00217 static XrdOssCache_FS *Find(const char *Path, int lklen=0); 00218 00219 static int Init(const char *UDir, const char *Qfile, int isSOL); 00220 00221 static int Init(long long aMin, int ovhd, int aFuzz); 00222 00223 static void List(const char *lname, XrdSysError &Eroute); 00224 00225 static char *Parse(const char *token, char *cbuff, int cblen); 00226 00227 static void *Scan(int cscanint); 00228 00229 XrdOssCache() {} 00230 ~XrdOssCache() {} 00231 00232 static XrdSysMutex Mutex; // Cache context lock 00233 00234 static long long fsTotal; // Total number of bytes known 00235 static long long fsLarge; // Total number of bytes in largest fspart 00236 static long long fsTotFr; // Total number of bytes free 00237 static long long fsFree; // Maximum contiguous free space 00238 static long long fsSize; // Size of partition with fsFree 00239 static XrdOssCache_FS *fsfirst; // -> First filesystem 00240 static XrdOssCache_FS *fslast; // -> Last filesystem 00241 static XrdOssCache_FSData *fsdata; // -> Filesystem data 00242 static int fsCount; // Number of file systems 00243 00244 private: 00245 00246 static long long minAlloc; 00247 static double fuzAlloc; 00248 static int ovhAlloc; 00249 static int Quotas; 00250 static int Usage; 00251 }; 00252 #endif
1.7.6.1