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>
36#include "XrdSys/XrdSysError.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{
79public:
80
81long long Total;
82long long Free;
83long long Maxfree;
84long long Largest;
85long long Inodes;
86long long Inleft;
87long long Usage;
88long 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{
107public:
108
110long long size;
111long long frsz;
112dev_t fsid;
113const char *path;
114time_t updt;
116unsigned 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
127
129{
130public:
131
132enum FSOpts {None = 0, isXA = 1};
133
135const char *group;
136const char *path;
139 char suffix[4]; // Corresponds to OssPath::sfxLen
142
143static int Add(const char *Path);
144static long long freeSpace(long long &Size, const char *path=0);
145static long long freeSpace(XrdOssCache_Space &Space, const char *path);
146static int getSpace( XrdOssCache_Space &Space, const char *sname);
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{
166public:
167
169char *group;
171long long Usage;
172long long Quota;
174static 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{
190public:
191
192static void Adjust(dev_t devid, off_t size);
193
194static void Adjust(const char *Path, off_t size, struct stat *buf=0);
195
196static void Adjust(XrdOssCache_FS *fsp, off_t size);
197
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
216static int Alloc(allocInfo &aInfo);
217
218static XrdOssCache_FS *Find(const char *Path, int lklen=0);
219
220static int Init(const char *UDir, const char *Qfile, int isSOL);
221
222static int Init(long long aMin, int ovhd, int aFuzz);
223
224static void List(const char *lname, XrdSysError &Eroute);
225
226static char *Parse(const char *token, char *cbuff, int cblen);
227
228static void *Scan(int cscanint);
229
232
233static XrdSysMutex Mutex; // Cache context lock
234
235static long long fsTotal; // Total number of bytes known
236static long long fsLarge; // Total number of bytes in largest fspart
237static long long fsTotFr; // Total number of bytes free
238static long long fsFree; // Maximum contiguous free space
239static long long fsSize; // Size of partition with fsFree
240static XrdOssCache_FS *fsfirst; // -> First filesystem
241static XrdOssCache_FS *fslast; // -> Last filesystem
242static XrdOssCache_FSData *fsdata; // -> Filesystem data
243static int fsCount; // Number of file systems
244
245private:
246
247static long long minAlloc;
248static double fuzAlloc;
249static int ovhAlloc;
250static int Quotas;
251static int Usage;
252};
253#endif
#define stat(a, b)
Definition: XrdPosix.hh:96
Definition: XrdOssCache.hh:106
time_t updt
Definition: XrdOssCache.hh:114
int stat
Definition: XrdOssCache.hh:115
const char * path
Definition: XrdOssCache.hh:113
XrdOssCache_FSData(const char *, STATFS_t &, dev_t)
dev_t fsid
Definition: XrdOssCache.hh:112
~XrdOssCache_FSData()
Definition: XrdOssCache.hh:119
unsigned int seen
Definition: XrdOssCache.hh:116
long long size
Definition: XrdOssCache.hh:110
long long frsz
Definition: XrdOssCache.hh:111
XrdOssCache_FSData * next
Definition: XrdOssCache.hh:109
Definition: XrdOssCache.hh:129
const char * group
Definition: XrdOssCache.hh:135
XrdOssCache_Group * fsgroup
Definition: XrdOssCache.hh:141
static long long freeSpace(long long &Size, const char *path=0)
FSOpts opts
Definition: XrdOssCache.hh:138
~XrdOssCache_FS()
Definition: XrdOssCache.hh:153
FSOpts
Definition: XrdOssCache.hh:132
@ None
Definition: XrdOssCache.hh:132
@ isXA
Definition: XrdOssCache.hh:132
int plen
Definition: XrdOssCache.hh:137
static int getSpace(XrdOssCache_Space &Space, XrdOssCache_Group *fsg)
char suffix[4]
Definition: XrdOssCache.hh:139
static int Add(const char *Path)
const char * path
Definition: XrdOssCache.hh:136
XrdOssCache_FS * next
Definition: XrdOssCache.hh:134
static int getSpace(XrdOssCache_Space &Space, const char *sname)
XrdOssCache_FSData * fsdata
Definition: XrdOssCache.hh:140
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:165
static XrdOssCache_Group * fsgroups
Definition: XrdOssCache.hh:176
static long long PubQuota
Definition: XrdOssCache.hh:174
~XrdOssCache_Group()
Definition: XrdOssCache.hh:181
char * group
Definition: XrdOssCache.hh:169
XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0)
Definition: XrdOssCache.hh:178
XrdOssCache_FS * curr
Definition: XrdOssCache.hh:170
long long Usage
Definition: XrdOssCache.hh:171
int GRPid
Definition: XrdOssCache.hh:173
XrdOssCache_Group * next
Definition: XrdOssCache.hh:168
long long Quota
Definition: XrdOssCache.hh:172
Definition: XrdOssCache.hh:78
long long Usage
Definition: XrdOssCache.hh:87
~XrdOssCache_Space()
Definition: XrdOssCache.hh:92
long long Total
Definition: XrdOssCache.hh:81
long long Inodes
Definition: XrdOssCache.hh:85
XrdOssCache_Space()
Definition: XrdOssCache.hh:90
long long Largest
Definition: XrdOssCache.hh:84
long long Inleft
Definition: XrdOssCache.hh:86
long long Free
Definition: XrdOssCache.hh:82
long long Maxfree
Definition: XrdOssCache.hh:83
long long Quota
Definition: XrdOssCache.hh:88
Definition: XrdOssCache.hh:189
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:239
static char * Parse(const char *token, char *cbuff, int cblen)
~XrdOssCache()
Definition: XrdOssCache.hh:231
static long long fsLarge
Definition: XrdOssCache.hh:236
static long long fsTotal
Definition: XrdOssCache.hh:235
static int Init(const char *UDir, const char *Qfile, int isSOL)
static void Adjust(XrdOssCache_FS *fsp, off_t size)
static XrdOssCache_FS * fslast
Definition: XrdOssCache.hh:241
static int Quotas
Definition: XrdOssCache.hh:250
static void Adjust(dev_t devid, off_t size)
static XrdOssCache_FS * fsfirst
Definition: XrdOssCache.hh:240
static long long fsTotFr
Definition: XrdOssCache.hh:237
static void List(const char *lname, XrdSysError &Eroute)
XrdOssCache()
Definition: XrdOssCache.hh:230
static long long minAlloc
Definition: XrdOssCache.hh:247
static int fsCount
Definition: XrdOssCache.hh:243
static int Usage
Definition: XrdOssCache.hh:251
static XrdOssCache_FS * Find(const char *Path, int lklen=0)
static long long fsFree
Definition: XrdOssCache.hh:238
static int Alloc(allocInfo &aInfo)
static int ovhAlloc
Definition: XrdOssCache.hh:249
static XrdOssCache_FSData * fsdata
Definition: XrdOssCache.hh:242
static double fuzAlloc
Definition: XrdOssCache.hh:248
static int Init(long long aMin, int ovhd, int aFuzz)
static XrdSysMutex Mutex
Definition: XrdOssCache.hh:233
Definition: XrdSysError.hh:90
Definition: XrdSysPthread.hh:166
Definition: XrdOssCache.hh:199
long long cgSize
Definition: XrdOssCache.hh:201
XrdOssCache_FS * cgFSp
Definition: XrdOssCache.hh:207
int cgPlen
Definition: XrdOssCache.hh:203
char * cgPsfx
Definition: XrdOssCache.hh:206
allocInfo(const char *pP, char *bP, int bL)
Definition: XrdOssCache.hh:210
int cgPFsz
Definition: XrdOssCache.hh:204
mode_t aMode
Definition: XrdOssCache.hh:208
const char * cgName
Definition: XrdOssCache.hh:200
const char * Path
Definition: XrdOssCache.hh:199
const char * cgPath
Definition: XrdOssCache.hh:202
~allocInfo()
Definition: XrdOssCache.hh:213
char * cgPFbf
Definition: XrdOssCache.hh:205