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 <ctime>
34 #include <sys/stat.h>
35 #include "XrdOuc/XrdOucDLlist.hh"
36 #include "XrdOss/XrdOssVS.hh"
37 #include "XrdSys/XrdSysError.hh"
38 #include "XrdSys/XrdSysPthread.hh"
39 
40 /******************************************************************************/
41 /* O S D e p e n d e n t D e f i n i t i o n s */
42 /******************************************************************************/
43 
44 #ifdef __solaris__
45 #include <sys/statvfs.h>
46 #define STATFS_t struct statvfs
47 #define FS_Stat(a,b) statvfs(a,b)
48 #define FS_BLKSZ f_frsize
49 #define FS_FFREE f_favail
50 #endif
51 #if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
52 #include <sys/vfs.h>
53 #define FS_Stat(a,b) statfs(a,b)
54 #define STATFS_t struct statfs
55 #define FS_BLKSZ f_bsize
56 #define FS_FFREE f_ffree
57 #endif
58 #ifdef AIX
59 #include <sys/statfs.h>
60 #define STATFS_t struct statfs
61 #define FS_Stat(a,b) statfs(a,b)
62 #define FS_BLKSZ f_bsize
63 #define FS_FFREE f_ffree
64 #endif
65 #if defined(__APPLE__) || defined(__FreeBSD__)
66 #include <sys/param.h>
67 #include <sys/mount.h>
68 #define STATFS_t struct statfs
69 #define FS_Stat(a,b) statfs(a,b)
70 #define FS_BLKSZ f_bsize
71 #define FS_FFREE f_ffree
72 #endif
73 
74 /******************************************************************************/
75 /* X r d O s s C a c h e _ S p a c e */
76 /******************************************************************************/
77 
79 {
80 public:
81 
82 long long Total;
83 long long Free;
84 long long Maxfree;
85 long long Largest;
86 long long Inodes;
87 long long Inleft;
88 long long Usage;
89 long long Quota;
90 
92  Inodes(0), Inleft(0), Usage(-1), Quota(-1) {}
94 };
95 
96 /******************************************************************************/
97 /* X r d O s s C a c h e _ F S D a t a */
98 /******************************************************************************/
99 
100 // Flags values for FSData
101 //
102 #define XrdOssFSData_OFFLINE 0x0001
103 #define XrdOssFSData_ADJUSTED 0x0002
104 #define XrdOssFSData_REFRESH 0x0004
105 
107 {
108 public:
109 
111 long long size;
112 long long frsz;
113 dev_t fsid;
114 const char *path;
115 const char *pact;
116 const char *devN;
117 time_t updt;
118 int stat;
119 unsigned short bdevID;
120 unsigned short partID;
121 
122  XrdOssCache_FSData(const char *, STATFS_t &, dev_t);
123  ~XrdOssCache_FSData() {if (path) free((void *)path);}
124 };
125 
126 /******************************************************************************/
127 /* X r d O s s C a c h e _ F S */
128 /******************************************************************************/
129 
130 class XrdOssCache_Group;
131 
133 {
134 public:
135 
136 enum FSOpts {None = 0, isXA = 1};
137 
139 const char *group;
140 const char *path;
141 int plen;
143  char suffix[4]; // Corresponds to OssPath::sfxLen
146 
147 static int Add(const char *Path);
148 static long long freeSpace(long long &Size, const char *path=0);
149 static long long freeSpace(XrdOssCache_Space &Space, const char *path);
150 
151 static int getSpace( XrdOssCache_Space &Space, const char *sname,
152  XrdOssVSPart **vsPart=0);
153 static int getSpace( XrdOssCache_Space &Space, XrdOssCache_Group *fsg,
154  XrdOssVSPart **vsPart=0);
155 
156  XrdOssCache_FS( int &retc,
157  const char *fsg,
158  const char *fsp,
159  FSOpts opt);
160  ~XrdOssCache_FS() {if (group) free((void *)group);
161  if (path) free((void *)path);
162  }
163 };
164 
165 /******************************************************************************/
166 /* X r d O s s C a c h e _ F S A P */
167 /******************************************************************************/
168 
170 {
171 XrdOssCache_FSData *fsP; // Pointer to partition
172 const char **apVec; // Allocation root paths in this partition (nil end)
173 int apNum;
174 };
175 
176 /******************************************************************************/
177 /* X r d O s s C a c h e _ G r o u p */
178 /******************************************************************************/
179 
180 // Eventually we will have management information associated with cache groups
181 //
183 {
184 public:
185 
187 char *group;
189 XrdOssCache_FSAP *fsVec; // Partitions where space may be allocated
190 long long Usage;
191 long long Quota;
192 int GRPid;
193 short fsNum;
194 short rsvd;
195 static
197 static long long PubQuota;
198 
200 
201  XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0)
202  : next(0), group(strdup(grp)), curr(fsp), fsVec(0),
203  Usage(0), Quota(-1), GRPid(-1), fsNum(0), rsvd(0)
204  {if (!strcmp("public", grp)) PubGroup = this;}
205  ~XrdOssCache_Group() {if (group) free((void *)group);}
206 };
207 
208 /******************************************************************************/
209 /* X r d O s s C a c h e */
210 /******************************************************************************/
211 
213 {
214 public:
215 
216 static void Adjust(dev_t devid, off_t size);
217 
218 static void Adjust(const char *Path, off_t size, struct stat *buf=0);
219 
220 static void Adjust(XrdOssCache_FS *fsp, off_t size);
221 
222 struct allocInfo
223  {const char *Path; // Req: Local file name
224  const char *cgName; // Req: Cache group name
225  long long cgSize; // Opt: Estimated size
226  const char *cgPath; // Opt: Specific partition path
227  int cgPlen; // Opt: Length of partition path
228  int cgPFsz; // Req: Size of buffer
229  char *cgPFbf; // Req: Buffer for cache pfn of size cgPFsz
230  char *cgPsfx; // Out: -> pfn suffix area. If 0, non-xa cache
231  XrdOssCache_FS *cgFSp; // Out: -> Cache file system definition
232  mode_t aMode; // Opt: Create mode; if 0, pfn file not created
233 
234  allocInfo(const char *pP, char *bP, int bL)
235  : Path(pP), cgName(0), cgSize(0), cgPath(0), cgPlen(0),
236  cgPFsz(bL), cgPFbf(bP), cgPsfx(0), cgFSp(0), aMode(0) {}
238  };
239 
240 static int Alloc(allocInfo &aInfo);
241 
242 static void DevInfo(struct stat &buf, bool limits=false);
243 
244 static XrdOssCache_FS *Find(const char *Path, int lklen=0);
245 
246 static int Init(const char *UDir, const char *Qfile,
247  int isSOL, int usync=0);
248 
249 static int Init(long long aMin, int ovhd, int aFuzz);
250 
251 static void List(const char *lname, XrdSysError &Eroute);
252 
253 static void MapDevs(bool dBug=false);
254 
255 static char *Parse(const char *token, char *cbuff, int cblen);
256 
257 static void *Scan(int cscanint);
258 
261 
262 static XrdSysMutex Mutex; // Cache context lock
263 
264 static long long fsTotal; // Total number of bytes known
265 static long long fsLarge; // Total number of bytes in largest fspart
266 static long long fsTotFr; // Total number of bytes free
267 static long long fsFree; // Maximum contiguous free space
268 static long long fsSize; // Size of partition with fsFree
269 static XrdOssCache_FS *fsfirst; // -> First filesystem
270 static XrdOssCache_FS *fslast; // -> Last filesystem
271 static XrdOssCache_FSData *fsdata; // -> Filesystem data
272 static int fsCount; // Number of file systems
273 
274 private:
275 static bool MapDM(const char *ldm, char *buff, int blen);
276 
277 static long long minAlloc;
278 static double fuzAlloc;
279 static int ovhAlloc;
280 static int Quotas;
281 static int Usage;
282 };
283 #endif
const char ** apVec
Definition: XrdOssCache.hh:172
XrdOssCache_FSData * fsP
Definition: XrdOssCache.hh:171
int stat(const char *path, struct stat *buf)
XrdOucString Path
const char * path
Definition: XrdOssCache.hh:114
XrdOssCache_FSData(const char *, STATFS_t &, dev_t)
Definition: XrdOssCache.cc:105
const char * devN
Definition: XrdOssCache.hh:116
const char * pact
Definition: XrdOssCache.hh:115
unsigned short partID
Definition: XrdOssCache.hh:120
unsigned short bdevID
Definition: XrdOssCache.hh:119
XrdOssCache_FSData * next
Definition: XrdOssCache.hh:110
const char * group
Definition: XrdOssCache.hh:139
static int getSpace(XrdOssCache_Space &Space, const char *sname, XrdOssVSPart **vsPart=0)
Definition: XrdOssCache.cc:327
XrdOssCache_Group * fsgroup
Definition: XrdOssCache.hh:145
static long long freeSpace(long long &Size, const char *path=0)
Definition: XrdOssCache.cc:279
const char * path
Definition: XrdOssCache.hh:140
XrdOssCache_FS * next
Definition: XrdOssCache.hh:138
static int Add(const char *Path)
Definition: XrdOssCache.cc:250
XrdOssCache_FSData * fsdata
Definition: XrdOssCache.hh:144
XrdOssCache_FS(int &retc, const char *fsg, const char *fsp, FSOpts opt)
Definition: XrdOssCache.cc:146
static long long PubQuota
Definition: XrdOssCache.hh:197
static XrdOssCache_Group * fsgroups
Definition: XrdOssCache.hh:199
XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0)
Definition: XrdOssCache.hh:201
XrdOssCache_FS * curr
Definition: XrdOssCache.hh:188
XrdOssCache_FSAP * fsVec
Definition: XrdOssCache.hh:189
XrdOssCache_Group * next
Definition: XrdOssCache.hh:186
static XrdOssCache_Group * PubGroup
Definition: XrdOssCache.hh:196
long long Inodes
Definition: XrdOssCache.hh:86
long long Largest
Definition: XrdOssCache.hh:85
long long Inleft
Definition: XrdOssCache.hh:87
long long Maxfree
Definition: XrdOssCache.hh:84
static int Init(const char *UDir, const char *Qfile, int isSOL, int usync=0)
Definition: XrdOssCache.cc:644
static XrdOssCache_FSData * fsdata
Definition: XrdOssCache.hh:271
static void * Scan(int cscanint)
Definition: XrdOssCache.cc:843
static long long fsSize
Definition: XrdOssCache.hh:268
static long long fsLarge
Definition: XrdOssCache.hh:265
static long long fsTotal
Definition: XrdOssCache.hh:264
static int Alloc(allocInfo &aInfo)
Definition: XrdOssCache.cc:492
static void DevInfo(struct stat &buf, bool limits=false)
Definition: XrdOssCache.cc:583
static long long fsTotFr
Definition: XrdOssCache.hh:266
static char * Parse(const char *token, char *cbuff, int cblen)
Definition: XrdOssCache.cc:814
static int fsCount
Definition: XrdOssCache.hh:272
static XrdOssCache_FS * fsfirst
Definition: XrdOssCache.hh:269
static void List(const char *lname, XrdSysError &Eroute)
Definition: XrdOssCache.cc:682
static long long fsFree
Definition: XrdOssCache.hh:267
static XrdOssCache_FS * fslast
Definition: XrdOssCache.hh:270
static void MapDevs(bool dBug=false)
Definition: XrdOssCache.cc:709
static XrdOssCache_FS * Find(const char *Path, int lklen=0)
Definition: XrdOssCache.cc:611
static void Adjust(dev_t devid, off_t size)
Definition: XrdOssCache.cc:397
static XrdSysMutex Mutex
Definition: XrdOssCache.hh:262
XrdOssCache_FS * cgFSp
Definition: XrdOssCache.hh:231
allocInfo(const char *pP, char *bP, int bL)
Definition: XrdOssCache.hh:234