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(__macos__) || 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 
117  XrdOssCache_FSData(const char *, STATFS_t &, dev_t);
118  ~XrdOssCache_FSData() {if (path) free((void *)path);}
119 };
120 
121 /******************************************************************************/
122 /* X r d O s s C a c h e _ F S */
123 /******************************************************************************/
124 
125 class XrdOssCache_Group;
126 
128 {
129 public:
130 
131 enum FSOpts {None = 0, isXA = 1};
132 
134 const char *group;
135 const char *path;
136 int plen;
138  char suffix[4]; // Corresponds to OssPath::sfxLen
141 
142 static int Add(const char *Path);
143 static long long freeSpace(long long &Size, const char *path=0);
144 static long long freeSpace(XrdOssCache_Space &Space, const char *path);
145 static int getSpace( XrdOssCache_Space &Space, const char *sname);
146 static int getSpace( XrdOssCache_Space &Space, XrdOssCache_Group *fsg);
147 
148  XrdOssCache_FS( int &retc,
149  const char *fsg,
150  const char *fsp,
151  FSOpts opt);
152  ~XrdOssCache_FS() {if (group) free((void *)group);
153  if (path) free((void *)path);
154  }
155 };
156 
157 /******************************************************************************/
158 /* X r d O s s C a c h e _ G r o u p */
159 /******************************************************************************/
160 
161 // Eventually we will have management information associated with cache groups
162 //
164 {
165 public:
166 
168 char *group;
170 long long Usage;
171 long long Quota;
172 int GRPid;
173 static long long PubQuota;
174 
176 
177  XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0)
178  : next(0), group(strdup(grp)), curr(fsp), Usage(0),
179  Quota(-1), GRPid(-1) {}
180  ~XrdOssCache_Group() {if (group) free((void *)group);}
181 };
182 
183 /******************************************************************************/
184 /* X r d O s s C a c h e */
185 /******************************************************************************/
186 
188 {
189 public:
190 
191 static void Adjust(dev_t devid, off_t size);
192 
193 static void Adjust(const char *Path, off_t size, struct stat *buf=0);
194 
195 static void Adjust(XrdOssCache_FS *fsp, off_t size);
196 
197 struct allocInfo
198  {const char *Path; // Req: Local file name
199  const char *cgName; // Req: Cache group name
200  long long cgSize; // Opt: Estimated size
201  const char *cgPath; // Opt: Specific partition path
202  int cgPlen; // Opt: Length of partition path
203  int cgPFsz; // Req: Size of buffer
204  char *cgPFbf; // Req: Buffer for cache pfn of size cgPFsz
205  char *cgPsfx; // Out: -> pfn suffix area. If 0, non-xa cache
206  XrdOssCache_FS *cgFSp; // Out: -> Cache file system definition
207  mode_t aMode; // Opt: Create mode; if 0, pfn file not created
208 
209  allocInfo(const char *pP, char *bP, int bL)
210  : Path(pP), cgName(0), cgSize(0), cgPath(0), cgPlen(0),
211  cgPFsz(bL), cgPFbf(bP), cgPsfx(0), cgFSp(0), aMode(0) {}
213  };
214 
215 static int Alloc(allocInfo &aInfo);
216 
217 static XrdOssCache_FS *Find(const char *Path, int lklen=0);
218 
219 static int Init(const char *UDir, const char *Qfile, int isSOL);
220 
221 static int Init(long long aMin, int ovhd, int aFuzz);
222 
223 static void List(const char *lname, XrdSysError &Eroute);
224 
225 static char *Parse(const char *token, char *cbuff, int cblen);
226 
227 static void *Scan(int cscanint);
228 
231 
232 static XrdSysMutex Mutex; // Cache context lock
233 
234 static long long fsTotal; // Total number of bytes known
235 static long long fsLarge; // Total number of bytes in largest fspart
236 static long long fsTotFr; // Total number of bytes free
237 static long long fsFree; // Maximum contiguous free space
238 static long long fsSize; // Size of partition with fsFree
239 static XrdOssCache_FS *fsfirst; // -> First filesystem
240 static XrdOssCache_FS *fslast; // -> Last filesystem
241 static XrdOssCache_FSData *fsdata; // -> Filesystem data
242 static int fsCount; // Number of file systems
243 
244 private:
245 
246 static long long minAlloc;
247 static double fuzAlloc;
248 static int ovhAlloc;
249 static int Quotas;
250 static int Usage;
251 };
252 #endif