xrootd
XrdOssCache.hh
Go to the documentation of this file.
1 #ifndef __XRDOSS_CACHE_H__
2 #define __XRDOSS_CACHE_H__
3 /******************************************************************************/
4 /* */
5 /* X r d O s s C a c h e . h h */
6 /* */
7 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <time.h>
34 #include <sys/stat.h>
35 #include "XrdOuc/XrdOucDLlist.hh"
36 #include "XrdSys/XrdSysError.hh"
37 #include "XrdSys/XrdSysPthread.hh"
38 
39 /******************************************************************************/
40 /* O S D e p e n d e n t D e f i n i t i o n s */
41 /******************************************************************************/
42 
43 #ifdef __solaris__
44 #include <sys/statvfs.h>
45 #define STATFS_t struct statvfs
46 #define FS_Stat(a,b) statvfs(a,b)
47 #define FS_BLKSZ f_frsize
48 #define FS_FFREE f_favail
49 #endif
50 #ifdef __linux__
51 #include <sys/vfs.h>
52 #define FS_Stat(a,b) statfs(a,b)
53 #define STATFS_t struct statfs
54 #define FS_BLKSZ f_bsize
55 #define FS_FFREE f_ffree
56 #endif
57 #ifdef AIX
58 #include <sys/statfs.h>
59 #define STATFS_t struct statfs
60 #define FS_Stat(a,b) statfs(a,b)
61 #define FS_BLKSZ f_bsize
62 #define FS_FFREE f_ffree
63 #endif
64 #if defined(__APPLE__) || defined(__FreeBSD__)
65 #include <sys/param.h>
66 #include <sys/mount.h>
67 #define STATFS_t struct statfs
68 #define FS_Stat(a,b) statfs(a,b)
69 #define FS_BLKSZ f_bsize
70 #define FS_FFREE f_ffree
71 #endif
72 
73 /******************************************************************************/
74 /* X r d O s s C a c h e _ S p a c e */
75 /******************************************************************************/
76 
78 {
79 public:
80 
81 long long Total;
82 long long Free;
83 long long Maxfree;
84 long long Largest;
85 long long Inodes;
86 long long Inleft;
87 long long Usage;
88 long long Quota;
89 
91  Inodes(0), Inleft(0), Usage(-1), Quota(-1) {}
93 };
94 
95 /******************************************************************************/
96 /* X r d O s s C a c h e _ F S D a t a */
97 /******************************************************************************/
98 
99 // Flags values for FSData
100 //
101 #define XrdOssFSData_OFFLINE 0x0001
102 #define XrdOssFSData_ADJUSTED 0x0002
103 #define XrdOssFSData_REFRESH 0x0004
104 
106 {
107 public:
108 
110 long long size;
111 long long frsz;
112 dev_t fsid;
113 const char *path;
114 time_t updt;
115 int stat;
116 unsigned int seen;
117 
118  XrdOssCache_FSData(const char *, STATFS_t &, dev_t);
119  ~XrdOssCache_FSData() {if (path) free((void *)path);}
120 };
121 
122 /******************************************************************************/
123 /* X r d O s s C a c h e _ F S */
124 /******************************************************************************/
125 
126 class XrdOssCache_Group;
127 
129 {
130 public:
131 
132 enum FSOpts {None = 0, isXA = 1};
133 
135 const char *group;
136 const char *path;
137 int plen;
139  char suffix[4]; // Corresponds to OssPath::sfxLen
142 
143 static int Add(const char *Path);
144 static long long freeSpace(long long &Size, const char *path=0);
145 static long long freeSpace(XrdOssCache_Space &Space, const char *path);
146 static int getSpace( XrdOssCache_Space &Space, const char *sname);
147 static int getSpace( XrdOssCache_Space &Space, XrdOssCache_Group *fsg);
148 
149  XrdOssCache_FS( int &retc,
150  const char *fsg,
151  const char *fsp,
152  FSOpts opt);
153  ~XrdOssCache_FS() {if (group) free((void *)group);
154  if (path) free((void *)path);
155  }
156 };
157 
158 /******************************************************************************/
159 /* X r d O s s C a c h e _ G r o u p */
160 /******************************************************************************/
161 
162 // Eventually we will have management information associated with cache groups
163 //
165 {
166 public:
167 
169 char *group;
171 long long Usage;
172 long long Quota;
173 int GRPid;
174 static long long PubQuota;
175 
177 
178  XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0)
179  : next(0), group(strdup(grp)), curr(fsp), Usage(0),
180  Quota(-1), GRPid(-1) {}
181  ~XrdOssCache_Group() {if (group) free((void *)group);}
182 };
183 
184 /******************************************************************************/
185 /* X r d O s s C a c h e */
186 /******************************************************************************/
187 
189 {
190 public:
191 
192 static void Adjust(dev_t devid, off_t size);
193 
194 static void Adjust(const char *Path, off_t size, struct stat *buf=0);
195 
196 static void Adjust(XrdOssCache_FS *fsp, off_t size);
197 
198 struct allocInfo
199  {const char *Path; // Req: Local file name
200  const char *cgName; // Req: Cache group name
201  long long cgSize; // Opt: Estimated size
202  const char *cgPath; // Opt: Specific partition path
203  int cgPlen; // Opt: Length of partition path
204  int cgPFsz; // Req: Size of buffer
205  char *cgPFbf; // Req: Buffer for cache pfn of size cgPFsz
206  char *cgPsfx; // Out: -> pfn suffix area. If 0, non-xa cache
207  XrdOssCache_FS *cgFSp; // Out: -> Cache file system definition
208  mode_t aMode; // Opt: Create mode; if 0, pfn file not created
209 
210  allocInfo(const char *pP, char *bP, int bL)
211  : Path(pP), cgName(0), cgSize(0), cgPath(0), cgPlen(0),
212  cgPFsz(bL), cgPFbf(bP), cgPsfx(0), cgFSp(0), aMode(0) {}
214  };
215 
216 static int Alloc(allocInfo &aInfo);
217 
218 static XrdOssCache_FS *Find(const char *Path, int lklen=0);
219 
220 static int Init(const char *UDir, const char *Qfile, int isSOL);
221 
222 static int Init(long long aMin, int ovhd, int aFuzz);
223 
224 static void List(const char *lname, XrdSysError &Eroute);
225 
226 static char *Parse(const char *token, char *cbuff, int cblen);
227 
228 static void *Scan(int cscanint);
229 
232 
233 static XrdSysMutex Mutex; // Cache context lock
234 
235 static long long fsTotal; // Total number of bytes known
236 static long long fsLarge; // Total number of bytes in largest fspart
237 static long long fsTotFr; // Total number of bytes free
238 static long long fsFree; // Maximum contiguous free space
239 static long long fsSize; // Size of partition with fsFree
240 static XrdOssCache_FS *fsfirst; // -> First filesystem
241 static XrdOssCache_FS *fslast; // -> Last filesystem
242 static XrdOssCache_FSData *fsdata; // -> Filesystem data
243 static int fsCount; // Number of file systems
244 
245 private:
246 
247 static long long minAlloc;
248 static double fuzAlloc;
249 static int ovhAlloc;
250 static int Quotas;
251 static int Usage;
252 };
253 #endif
static double fuzAlloc
Definition: XrdOssCache.hh:248
const char * cgName
Definition: XrdOssCache.hh:200
XrdOssCache_FS(int &retc, const char *fsg, const char *fsp, FSOpts opt)
XrdOssCache_Group * fsgroup
Definition: XrdOssCache.hh:141
int cgPlen
Definition: XrdOssCache.hh:203
static XrdSysMutex Mutex
Definition: XrdOssCache.hh:233
long long Quota
Definition: XrdOssCache.hh:172
static char * Parse(const char *token, char *cbuff, int cblen)
time_t updt
Definition: XrdOssCache.hh:114
XrdOssCache_Space()
Definition: XrdOssCache.hh:90
unsigned int seen
Definition: XrdOssCache.hh:116
static int Init(const char *UDir, const char *Qfile, int isSOL)
long long Quota
Definition: XrdOssCache.hh:88
Definition: XrdOssCache.hh:105
XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0)
Definition: XrdOssCache.hh:178
const char * group
Definition: XrdOssCache.hh:135
const char * cgPath
Definition: XrdOssCache.hh:202
XrdOssCache_FS * next
Definition: XrdOssCache.hh:134
int plen
Definition: XrdOssCache.hh:137
~XrdOssCache_FS()
Definition: XrdOssCache.hh:153
XrdOssCache_FS * curr
Definition: XrdOssCache.hh:170
allocInfo(const char *pP, char *bP, int bL)
Definition: XrdOssCache.hh:210
~allocInfo()
Definition: XrdOssCache.hh:213
dev_t fsid
Definition: XrdOssCache.hh:112
long long frsz
Definition: XrdOssCache.hh:111
static int Add(const char *Path)
static int ovhAlloc
Definition: XrdOssCache.hh:249
Definition: XrdOssCache.hh:132
long long Largest
Definition: XrdOssCache.hh:84
static XrdOssCache_FS * Find(const char *Path, int lklen=0)
static XrdOssCache_FS * fsfirst
Definition: XrdOssCache.hh:240
Definition: XrdSysError.hh:89
const char * Path
Definition: XrdOssCache.hh:199
Definition: XrdSysPthread.hh:165
static long long fsFree
Definition: XrdOssCache.hh:238
static int Usage
Definition: XrdOssCache.hh:251
long long Usage
Definition: XrdOssCache.hh:87
static XrdOssCache_FSData * fsdata
Definition: XrdOssCache.hh:242
static long long fsLarge
Definition: XrdOssCache.hh:236
static long long fsTotal
Definition: XrdOssCache.hh:235
long long cgSize
Definition: XrdOssCache.hh:201
static void List(const char *lname, XrdSysError &Eroute)
long long Usage
Definition: XrdOssCache.hh:171
static int getSpace(XrdOssCache_Space &Space, const char *sname)
Definition: XrdOssCache.hh:77
long long Total
Definition: XrdOssCache.hh:81
long long Maxfree
Definition: XrdOssCache.hh:83
static void * Scan(int cscanint)
long long size
Definition: XrdOssCache.hh:110
XrdOssCache_FSData * fsdata
Definition: XrdOssCache.hh:140
char suffix[4]
Definition: XrdOssCache.hh:139
XrdOssCache_Group * next
Definition: XrdOssCache.hh:168
long long Inodes
Definition: XrdOssCache.hh:85
char * cgPsfx
Definition: XrdOssCache.hh:206
static int Quotas
Definition: XrdOssCache.hh:250
~XrdOssCache_Space()
Definition: XrdOssCache.hh:92
char * cgPFbf
Definition: XrdOssCache.hh:205
Definition: XrdOssCache.hh:188
Definition: XrdOssCache.hh:164
XrdOssCache_FSData(const char *, STATFS_t &, dev_t)
static int Alloc(allocInfo &aInfo)
#define stat(a, b)
Definition: XrdPosix.hh:96
XrdOssCache_FSData * next
Definition: XrdOssCache.hh:109
const char * path
Definition: XrdOssCache.hh:113
static XrdOssCache_Group * fsgroups
Definition: XrdOssCache.hh:176
static long long freeSpace(long long &Size, const char *path=0)
static long long minAlloc
Definition: XrdOssCache.hh:247
const char * path
Definition: XrdOssCache.hh:136
int GRPid
Definition: XrdOssCache.hh:173
Definition: XrdOssCache.hh:198
static long long PubQuota
Definition: XrdOssCache.hh:174
XrdOssCache_FS * cgFSp
Definition: XrdOssCache.hh:207
Definition: XrdOssCache.hh:132
char * group
Definition: XrdOssCache.hh:169
~XrdOssCache()
Definition: XrdOssCache.hh:231
static void Adjust(dev_t devid, off_t size)
int cgPFsz
Definition: XrdOssCache.hh:204
FSOpts opts
Definition: XrdOssCache.hh:138
FSOpts
Definition: XrdOssCache.hh:132
Definition: XrdOssCache.hh:128
static long long fsTotFr
Definition: XrdOssCache.hh:237
long long Inleft
Definition: XrdOssCache.hh:86
~XrdOssCache_Group()
Definition: XrdOssCache.hh:181
long long Free
Definition: XrdOssCache.hh:82
XrdOssCache()
Definition: XrdOssCache.hh:230
static XrdOssCache_FS * fslast
Definition: XrdOssCache.hh:241
~XrdOssCache_FSData()
Definition: XrdOssCache.hh:119
static int fsCount
Definition: XrdOssCache.hh:243
static long long fsSize
Definition: XrdOssCache.hh:239
int stat
Definition: XrdOssCache.hh:115
mode_t aMode
Definition: XrdOssCache.hh:208