xrootd
Loading...
Searching...
No Matches
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>
36#include "XrdOss/XrdOssVS.hh"
37#include "XrdSys/XrdSysError.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{
80public:
81
82long long Total;
83long long Free;
84long long Maxfree;
85long long Largest;
86long long Inodes;
87long long Inleft;
88long long Usage;
89long 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{
108public:
109
111long long size;
112long long frsz;
113dev_t fsid;
114const char *path;
115const char *pact;
116const char *devN;
117time_t updt;
119unsigned short bdevID;
120unsigned 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
131
133{
134public:
135
136enum FSOpts {None = 0, isXA = 1};
137
139const char *group;
140const char *path;
143 char suffix[4]; // Corresponds to OssPath::sfxLen
146
147static int Add(const char *Path);
148static long long freeSpace(long long &Size, const char *path=0);
149static long long freeSpace(XrdOssCache_Space &Space, const char *path);
150
151static int getSpace( XrdOssCache_Space &Space, const char *sname,
152 XrdOssVSPart **vsPart=0);
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{
171XrdOssCache_FSData *fsP; // Pointer to partition
172const char **apVec; // Allocation root paths in this partition (nil end)
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{
184public:
185
187char *group;
189XrdOssCache_FSAP *fsVec; // Partitions where space may be allocated
190long long Usage;
191long long Quota;
193short fsNum;
194short rsvd;
195static
197static 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{
214public:
215
216static void Adjust(dev_t devid, off_t size);
217
218static void Adjust(const char *Path, off_t size, struct stat *buf=0);
219
220static void Adjust(XrdOssCache_FS *fsp, off_t size);
221
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
240static int Alloc(allocInfo &aInfo);
241
242static void DevInfo(struct stat &buf, bool limits=false);
243
244static XrdOssCache_FS *Find(const char *Path, int lklen=0);
245
246static int Init(const char *UDir, const char *Qfile,
247 int isSOL, int usync=0);
248
249static int Init(long long aMin, int ovhd, int aFuzz);
250
251static void List(const char *lname, XrdSysError &Eroute);
252
253static void MapDevs(bool dBug=false);
254
255static char *Parse(const char *token, char *cbuff, int cblen);
256
257static void *Scan(int cscanint);
258
261
262static XrdSysMutex Mutex; // Cache context lock
263
264static long long fsTotal; // Total number of bytes known
265static long long fsLarge; // Total number of bytes in largest fspart
266static long long fsTotFr; // Total number of bytes free
267static long long fsFree; // Maximum contiguous free space
268static long long fsSize; // Size of partition with fsFree
269static XrdOssCache_FS *fsfirst; // -> First filesystem
270static XrdOssCache_FS *fslast; // -> Last filesystem
271static XrdOssCache_FSData *fsdata; // -> Filesystem data
272static int fsCount; // Number of file systems
273
274private:
275static bool MapDM(const char *ldm, char *buff, int blen);
276
277static long long minAlloc;
278static double fuzAlloc;
279static int ovhAlloc;
280static int Quotas;
281static int Usage;
282};
283#endif
#define stat(a, b)
Definition XrdPosix.hh:96
Definition XrdOssCache.hh:107
time_t updt
Definition XrdOssCache.hh:117
int stat
Definition XrdOssCache.hh:118
const char * path
Definition XrdOssCache.hh:114
XrdOssCache_FSData(const char *, STATFS_t &, dev_t)
const char * devN
Definition XrdOssCache.hh:116
const char * pact
Definition XrdOssCache.hh:115
unsigned short partID
Definition XrdOssCache.hh:120
dev_t fsid
Definition XrdOssCache.hh:113
~XrdOssCache_FSData()
Definition XrdOssCache.hh:123
long long size
Definition XrdOssCache.hh:111
long long frsz
Definition XrdOssCache.hh:112
unsigned short bdevID
Definition XrdOssCache.hh:119
XrdOssCache_FSData * next
Definition XrdOssCache.hh:110
Definition XrdOssCache.hh:133
const char * group
Definition XrdOssCache.hh:139
static int getSpace(XrdOssCache_Space &Space, const char *sname, XrdOssVSPart **vsPart=0)
XrdOssCache_Group * fsgroup
Definition XrdOssCache.hh:145
static long long freeSpace(long long &Size, const char *path=0)
FSOpts opts
Definition XrdOssCache.hh:142
~XrdOssCache_FS()
Definition XrdOssCache.hh:160
FSOpts
Definition XrdOssCache.hh:136
@ None
Definition XrdOssCache.hh:136
@ isXA
Definition XrdOssCache.hh:136
int plen
Definition XrdOssCache.hh:141
char suffix[4]
Definition XrdOssCache.hh:143
static int getSpace(XrdOssCache_Space &Space, XrdOssCache_Group *fsg, XrdOssVSPart **vsPart=0)
static int Add(const char *Path)
const char * path
Definition XrdOssCache.hh:140
XrdOssCache_FS * next
Definition XrdOssCache.hh:138
XrdOssCache_FSData * fsdata
Definition XrdOssCache.hh:144
static long long freeSpace(XrdOssCache_Space &Space, const char *path)
XrdOssCache_FS(int &retc, const char *fsg, const char *fsp, FSOpts opt)
Definition XrdOssCache.hh:183
static XrdOssCache_Group * fsgroups
Definition XrdOssCache.hh:199
static long long PubQuota
Definition XrdOssCache.hh:197
short fsNum
Definition XrdOssCache.hh:193
~XrdOssCache_Group()
Definition XrdOssCache.hh:205
static XrdOssCache_Group * PubGroup
Definition XrdOssCache.hh:196
char * group
Definition XrdOssCache.hh:187
XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0)
Definition XrdOssCache.hh:201
XrdOssCache_FS * curr
Definition XrdOssCache.hh:188
long long Usage
Definition XrdOssCache.hh:190
XrdOssCache_FSAP * fsVec
Definition XrdOssCache.hh:189
int GRPid
Definition XrdOssCache.hh:192
XrdOssCache_Group * next
Definition XrdOssCache.hh:186
long long Quota
Definition XrdOssCache.hh:191
short rsvd
Definition XrdOssCache.hh:194
Definition XrdOssCache.hh:79
long long Usage
Definition XrdOssCache.hh:88
~XrdOssCache_Space()
Definition XrdOssCache.hh:93
long long Total
Definition XrdOssCache.hh:82
long long Inodes
Definition XrdOssCache.hh:86
XrdOssCache_Space()
Definition XrdOssCache.hh:91
long long Largest
Definition XrdOssCache.hh:85
long long Inleft
Definition XrdOssCache.hh:87
long long Free
Definition XrdOssCache.hh:83
long long Maxfree
Definition XrdOssCache.hh:84
long long Quota
Definition XrdOssCache.hh:89
Definition XrdOssCache.hh:213
static void Adjust(const char *Path, off_t size, struct stat *buf=0)
static void * Scan(int cscanint)
static long long fsSize
Definition XrdOssCache.hh:268
static bool MapDM(const char *ldm, char *buff, int blen)
static char * Parse(const char *token, char *cbuff, int cblen)
static void MapDevs(bool dBug=false)
~XrdOssCache()
Definition XrdOssCache.hh:260
static long long fsLarge
Definition XrdOssCache.hh:265
static long long fsTotal
Definition XrdOssCache.hh:264
static void Adjust(XrdOssCache_FS *fsp, off_t size)
static void DevInfo(struct stat &buf, bool limits=false)
static XrdOssCache_FS * fslast
Definition XrdOssCache.hh:270
static int Quotas
Definition XrdOssCache.hh:280
static void Adjust(dev_t devid, off_t size)
static XrdOssCache_FS * fsfirst
Definition XrdOssCache.hh:269
static long long fsTotFr
Definition XrdOssCache.hh:266
static void List(const char *lname, XrdSysError &Eroute)
XrdOssCache()
Definition XrdOssCache.hh:259
static int Init(const char *UDir, const char *Qfile, int isSOL, int usync=0)
static long long minAlloc
Definition XrdOssCache.hh:277
static int fsCount
Definition XrdOssCache.hh:272
static int Usage
Definition XrdOssCache.hh:281
static XrdOssCache_FS * Find(const char *Path, int lklen=0)
static long long fsFree
Definition XrdOssCache.hh:267
static int Alloc(allocInfo &aInfo)
static int ovhAlloc
Definition XrdOssCache.hh:279
static XrdOssCache_FSData * fsdata
Definition XrdOssCache.hh:271
static double fuzAlloc
Definition XrdOssCache.hh:278
static int Init(long long aMin, int ovhd, int aFuzz)
static XrdSysMutex Mutex
Definition XrdOssCache.hh:262
Definition XrdOssVS.hh:64
Definition XrdSysError.hh:90
Definition XrdSysPthread.hh:165
Definition XrdOssCache.hh:223
long long cgSize
Definition XrdOssCache.hh:225
XrdOssCache_FS * cgFSp
Definition XrdOssCache.hh:231
int cgPlen
Definition XrdOssCache.hh:227
char * cgPsfx
Definition XrdOssCache.hh:230
allocInfo(const char *pP, char *bP, int bL)
Definition XrdOssCache.hh:234
int cgPFsz
Definition XrdOssCache.hh:228
mode_t aMode
Definition XrdOssCache.hh:232
const char * cgName
Definition XrdOssCache.hh:224
const char * Path
Definition XrdOssCache.hh:223
const char * cgPath
Definition XrdOssCache.hh:226
~allocInfo()
Definition XrdOssCache.hh:237
char * cgPFbf
Definition XrdOssCache.hh:229
Definition XrdOssCache.hh:170
int apNum
Definition XrdOssCache.hh:173
const char ** apVec
Definition XrdOssCache.hh:172
XrdOssCache_FSData * fsP
Definition XrdOssCache.hh:171