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 "XrdOss/XrdOssVS.hh"
00037 #include "XrdSys/XrdSysError.hh"
00038 #include "XrdSys/XrdSysPthread.hh"
00039
00040
00041
00042
00043
00044 #ifdef __solaris__
00045 #include <sys/statvfs.h>
00046 #define STATFS_t struct statvfs
00047 #define FS_Stat(a,b) statvfs(a,b)
00048 #define FS_BLKSZ f_frsize
00049 #define FS_FFREE f_favail
00050 #endif
00051 #ifdef __linux__
00052 #include <sys/vfs.h>
00053 #define FS_Stat(a,b) statfs(a,b)
00054 #define STATFS_t struct statfs
00055 #define FS_BLKSZ f_bsize
00056 #define FS_FFREE f_ffree
00057 #endif
00058 #ifdef AIX
00059 #include <sys/statfs.h>
00060 #define STATFS_t struct statfs
00061 #define FS_Stat(a,b) statfs(a,b)
00062 #define FS_BLKSZ f_bsize
00063 #define FS_FFREE f_ffree
00064 #endif
00065 #if defined(__APPLE__) || defined(__FreeBSD__)
00066 #include <sys/param.h>
00067 #include <sys/mount.h>
00068 #define STATFS_t struct statfs
00069 #define FS_Stat(a,b) statfs(a,b)
00070 #define FS_BLKSZ f_bsize
00071 #define FS_FFREE f_ffree
00072 #endif
00073
00074
00075
00076
00077
00078 class XrdOssCache_Space
00079 {
00080 public:
00081
00082 long long Total;
00083 long long Free;
00084 long long Maxfree;
00085 long long Largest;
00086 long long Inodes;
00087 long long Inleft;
00088 long long Usage;
00089 long long Quota;
00090
00091 XrdOssCache_Space() : Total(0), Free(0), Maxfree(0), Largest(0),
00092 Inodes(0), Inleft(0), Usage(-1), Quota(-1) {}
00093 ~XrdOssCache_Space() {}
00094 };
00095
00096
00097
00098
00099
00100
00101
00102 #define XrdOssFSData_OFFLINE 0x0001
00103 #define XrdOssFSData_ADJUSTED 0x0002
00104 #define XrdOssFSData_REFRESH 0x0004
00105
00106 class XrdOssCache_FSData
00107 {
00108 public:
00109
00110 XrdOssCache_FSData *next;
00111 long long size;
00112 long long frsz;
00113 dev_t fsid;
00114 const char *path;
00115 const char *pact;
00116 const char *devN;
00117 time_t updt;
00118 int stat;
00119 unsigned short bdevID;
00120 unsigned short partID;
00121
00122 XrdOssCache_FSData(const char *, STATFS_t &, dev_t);
00123 ~XrdOssCache_FSData() {if (path) free((void *)path);}
00124 };
00125
00126
00127
00128
00129
00130 class XrdOssCache_Group;
00131
00132 class XrdOssCache_FS
00133 {
00134 public:
00135
00136 enum FSOpts {None = 0, isXA = 1};
00137
00138 XrdOssCache_FS *next;
00139 const char *group;
00140 const char *path;
00141 int plen;
00142 FSOpts opts;
00143 char suffix[4];
00144 XrdOssCache_FSData *fsdata;
00145 XrdOssCache_Group *fsgroup;
00146
00147 static int Add(const char *Path);
00148 static long long freeSpace(long long &Size, const char *path=0);
00149 static long long freeSpace(XrdOssCache_Space &Space, const char *path);
00150
00151 static int getSpace( XrdOssCache_Space &Space, const char *sname,
00152 XrdOssVSPart **vsPart=0);
00153 static int getSpace( XrdOssCache_Space &Space, XrdOssCache_Group *fsg,
00154 XrdOssVSPart **vsPart=0);
00155
00156 XrdOssCache_FS( int &retc,
00157 const char *fsg,
00158 const char *fsp,
00159 FSOpts opt);
00160 ~XrdOssCache_FS() {if (group) free((void *)group);
00161 if (path) free((void *)path);
00162 }
00163 };
00164
00165
00166
00167
00168
00169 struct XrdOssCache_FSAP
00170 {
00171 XrdOssCache_FSData *fsP;
00172 const char **apVec;
00173 int apNum;
00174 };
00175
00176
00177
00178
00179
00180
00181
00182 class XrdOssCache_Group
00183 {
00184 public:
00185
00186 XrdOssCache_Group *next;
00187 char *group;
00188 XrdOssCache_FS *curr;
00189 XrdOssCache_FSAP *fsVec;
00190 long long Usage;
00191 long long Quota;
00192 int GRPid;
00193 short fsNum;
00194 short rsvd;
00195 static
00196 XrdOssCache_Group *PubGroup;
00197 static long long PubQuota;
00198
00199 static XrdOssCache_Group *fsgroups;
00200
00201 XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0)
00202 : next(0), group(strdup(grp)), curr(fsp), fsVec(0),
00203 Usage(0), Quota(-1), GRPid(-1), fsNum(0), rsvd(0)
00204 {if (!strcmp("public", grp)) PubGroup = this;}
00205 ~XrdOssCache_Group() {if (group) free((void *)group);}
00206 };
00207
00208
00209
00210
00211
00212 class XrdOssCache
00213 {
00214 public:
00215
00216 static void Adjust(dev_t devid, off_t size);
00217
00218 static void Adjust(const char *Path, off_t size, struct stat *buf=0);
00219
00220 static void Adjust(XrdOssCache_FS *fsp, off_t size);
00221
00222 struct allocInfo
00223 {const char *Path;
00224 const char *cgName;
00225 long long cgSize;
00226 const char *cgPath;
00227 int cgPlen;
00228 int cgPFsz;
00229 char *cgPFbf;
00230 char *cgPsfx;
00231 XrdOssCache_FS *cgFSp;
00232 mode_t aMode;
00233
00234 allocInfo(const char *pP, char *bP, int bL)
00235 : Path(pP), cgName(0), cgSize(0), cgPath(0), cgPlen(0),
00236 cgPFsz(bL), cgPFbf(bP), cgPsfx(0), cgFSp(0), aMode(0) {}
00237 ~allocInfo() {}
00238 };
00239
00240 static int Alloc(allocInfo &aInfo);
00241
00242 static void DevInfo(struct stat &buf, bool limits=false);
00243
00244 static XrdOssCache_FS *Find(const char *Path, int lklen=0);
00245
00246 static int Init(const char *UDir, const char *Qfile,
00247 int isSOL, int usync=0);
00248
00249 static int Init(long long aMin, int ovhd, int aFuzz);
00250
00251 static void List(const char *lname, XrdSysError &Eroute);
00252
00253 static void MapDevs(bool dBug=false);
00254
00255 static char *Parse(const char *token, char *cbuff, int cblen);
00256
00257 static void *Scan(int cscanint);
00258
00259 XrdOssCache() {}
00260 ~XrdOssCache() {}
00261
00262 static XrdSysMutex Mutex;
00263
00264 static long long fsTotal;
00265 static long long fsLarge;
00266 static long long fsTotFr;
00267 static long long fsFree;
00268 static long long fsSize;
00269 static XrdOssCache_FS *fsfirst;
00270 static XrdOssCache_FS *fslast;
00271 static XrdOssCache_FSData *fsdata;
00272 static int fsCount;
00273
00274 private:
00275 static bool MapDM(const char *ldm, char *buff, int blen);
00276
00277 static long long minAlloc;
00278 static double fuzAlloc;
00279 static int ovhAlloc;
00280 static int Quotas;
00281 static int Usage;
00282 };
00283 #endif