00001 #ifndef __XRDOSS_CACHE_H__
00002 #define __XRDOSS_CACHE_H__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
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(__APPLE__) || 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
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
00097
00098
00099
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 unsigned int seen;
00117
00118 XrdOssCache_FSData(const char *, STATFS_t &, dev_t);
00119 ~XrdOssCache_FSData() {if (path) free((void *)path);}
00120 };
00121
00122
00123
00124
00125
00126 class XrdOssCache_Group;
00127
00128 class XrdOssCache_FS
00129 {
00130 public:
00131
00132 enum FSOpts {None = 0, isXA = 1};
00133
00134 XrdOssCache_FS *next;
00135 const char *group;
00136 const char *path;
00137 int plen;
00138 FSOpts opts;
00139 char suffix[4];
00140 XrdOssCache_FSData *fsdata;
00141 XrdOssCache_Group *fsgroup;
00142
00143 static int Add(const char *Path);
00144 static long long freeSpace(long long &Size, const char *path=0);
00145 static long long freeSpace(XrdOssCache_Space &Space, const char *path);
00146 static int getSpace( XrdOssCache_Space &Space, const char *sname);
00147 static int getSpace( XrdOssCache_Space &Space, XrdOssCache_Group *fsg);
00148
00149 XrdOssCache_FS( int &retc,
00150 const char *fsg,
00151 const char *fsp,
00152 FSOpts opt);
00153 ~XrdOssCache_FS() {if (group) free((void *)group);
00154 if (path) free((void *)path);
00155 }
00156 };
00157
00158
00159
00160
00161
00162
00163
00164 class XrdOssCache_Group
00165 {
00166 public:
00167
00168 XrdOssCache_Group *next;
00169 char *group;
00170 XrdOssCache_FS *curr;
00171 long long Usage;
00172 long long Quota;
00173 int GRPid;
00174 static long long PubQuota;
00175
00176 static XrdOssCache_Group *fsgroups;
00177
00178 XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0)
00179 : next(0), group(strdup(grp)), curr(fsp), Usage(0),
00180 Quota(-1), GRPid(-1) {}
00181 ~XrdOssCache_Group() {if (group) free((void *)group);}
00182 };
00183
00184
00185
00186
00187
00188 class XrdOssCache
00189 {
00190 public:
00191
00192 static void Adjust(dev_t devid, off_t size);
00193
00194 static void Adjust(const char *Path, off_t size, struct stat *buf=0);
00195
00196 static void Adjust(XrdOssCache_FS *fsp, off_t size);
00197
00198 struct allocInfo
00199 {const char *Path;
00200 const char *cgName;
00201 long long cgSize;
00202 const char *cgPath;
00203 int cgPlen;
00204 int cgPFsz;
00205 char *cgPFbf;
00206 char *cgPsfx;
00207 XrdOssCache_FS *cgFSp;
00208 mode_t aMode;
00209
00210 allocInfo(const char *pP, char *bP, int bL)
00211 : Path(pP), cgName(0), cgSize(0), cgPath(0), cgPlen(0),
00212 cgPFsz(bL), cgPFbf(bP), cgPsfx(0), cgFSp(0), aMode(0) {}
00213 ~allocInfo() {}
00214 };
00215
00216 static int Alloc(allocInfo &aInfo);
00217
00218 static XrdOssCache_FS *Find(const char *Path, int lklen=0);
00219
00220 static int Init(const char *UDir, const char *Qfile, int isSOL);
00221
00222 static int Init(long long aMin, int ovhd, int aFuzz);
00223
00224 static void List(const char *lname, XrdSysError &Eroute);
00225
00226 static char *Parse(const char *token, char *cbuff, int cblen);
00227
00228 static void *Scan(int cscanint);
00229
00230 XrdOssCache() {}
00231 ~XrdOssCache() {}
00232
00233 static XrdSysMutex Mutex;
00234
00235 static long long fsTotal;
00236 static long long fsLarge;
00237 static long long fsTotFr;
00238 static long long fsFree;
00239 static long long fsSize;
00240 static XrdOssCache_FS *fsfirst;
00241 static XrdOssCache_FS *fslast;
00242 static XrdOssCache_FSData *fsdata;
00243 static int fsCount;
00244
00245 private:
00246
00247 static long long minAlloc;
00248 static double fuzAlloc;
00249 static int ovhAlloc;
00250 static int Quotas;
00251 static int Usage;
00252 };
00253 #endif