Loading...
Searching...
No Matches
XrdOssCache.hh
Go to the documentation of this file.
#ifndef __XRDOSS_CACHE_H__
#define __XRDOSS_CACHE_H__
/******************************************************************************/
/* */
/* X r d O s s C a c h e . h h */
/* */
/* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#include <ctime>
#include <sys/stat.h>
#include "XrdOuc/XrdOucDLlist.hh"
#include "XrdOss/XrdOssVS.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysPthread.hh"
/******************************************************************************/
/* O S D e p e n d e n t D e f i n i t i o n s */
/******************************************************************************/
#ifdef __solaris__
#include <sys/statvfs.h>
#define STATFS_t struct statvfs
#define FS_Stat(a,b) statvfs(a,b)
#define FS_BLKSZ f_frsize
#define FS_FFREE f_favail
#endif
#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
#include <sys/vfs.h>
#define FS_Stat(a,b) statfs(a,b)
#define STATFS_t struct statfs
#define FS_BLKSZ f_bsize
#define FS_FFREE f_ffree
#endif
#ifdef AIX
#include <sys/statfs.h>
#define STATFS_t struct statfs
#define FS_Stat(a,b) statfs(a,b)
#define FS_BLKSZ f_bsize
#define FS_FFREE f_ffree
#endif
#if defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/param.h>
#include <sys/mount.h>
#define STATFS_t struct statfs
#define FS_Stat(a,b) statfs(a,b)
#define FS_BLKSZ f_bsize
#define FS_FFREE f_ffree
#endif
/******************************************************************************/
/* X r d O s s C a c h e _ S p a c e */
/******************************************************************************/
class XrdOssCache_Space
{
public:
long long Total;
long long Free;
long long Maxfree;
long long Largest;
long long Inodes;
long long Inleft;
long long Usage;
long long Quota;
XrdOssCache_Space() : Total(0), Free(0), Maxfree(0), Largest(0),
Inodes(0), Inleft(0), Usage(-1), Quota(-1) {}
~XrdOssCache_Space() {}
};
/******************************************************************************/
/* X r d O s s C a c h e _ F S D a t a */
/******************************************************************************/
// Flags values for FSData
//
#define XrdOssFSData_OFFLINE 0x0001
#define XrdOssFSData_ADJUSTED 0x0002
#define XrdOssFSData_REFRESH 0x0004
class XrdOssCache_FSData
{
public:
XrdOssCache_FSData *next;
long long size;
long long frsz;
dev_t fsid;
const char *path;
const char *pact;
const char *devN;
time_t updt;
int stat;
unsigned short bdevID;
unsigned short partID;
XrdOssCache_FSData(const char *, STATFS_t &, dev_t);
~XrdOssCache_FSData() {if (path) free((void *)path);}
};
/******************************************************************************/
/* X r d O s s C a c h e _ F S */
/******************************************************************************/
class XrdOssCache_Group;
class XrdOssCache_FS
{
public:
enum FSOpts {None = 0, isXA = 1};
XrdOssCache_FS *next;
const char *group;
const char *path;
int plen;
FSOpts opts;
char suffix[4]; // Corresponds to OssPath::sfxLen
XrdOssCache_FSData *fsdata;
XrdOssCache_Group *fsgroup;
static int Add(const char *Path);
static long long freeSpace(long long &Size, const char *path=0);
static long long freeSpace(XrdOssCache_Space &Space, const char *path);
static int getSpace( XrdOssCache_Space &Space, const char *sname,
XrdOssVSPart **vsPart=0);
static int getSpace( XrdOssCache_Space &Space, XrdOssCache_Group *fsg,
XrdOssVSPart **vsPart=0);
XrdOssCache_FS( int &retc,
const char *fsg,
const char *fsp,
FSOpts opt);
~XrdOssCache_FS() {if (group) free((void *)group);
if (path) free((void *)path);
}
};
/******************************************************************************/
/* X r d O s s C a c h e _ F S A P */
/******************************************************************************/
struct XrdOssCache_FSAP
{
XrdOssCache_FSData *fsP; // Pointer to partition
const char **apVec; // Allocation root paths in this partition (nil end)
int apNum;
};
/******************************************************************************/
/* X r d O s s C a c h e _ G r o u p */
/******************************************************************************/
// Eventually we will have management information associated with cache groups
//
class XrdOssCache_Group
{
public:
XrdOssCache_Group *next;
char *group;
XrdOssCache_FS *curr;
XrdOssCache_FSAP *fsVec; // Partitions where space may be allocated
long long Usage;
long long Quota;
int GRPid;
short fsNum;
short rsvd;
static
XrdOssCache_Group *PubGroup;
static long long PubQuota;
static XrdOssCache_Group *fsgroups;
XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0)
: next(0), group(strdup(grp)), curr(fsp), fsVec(0),
Usage(0), Quota(-1), GRPid(-1), fsNum(0), rsvd(0)
{if (!strcmp("public", grp)) PubGroup = this;}
~XrdOssCache_Group() {if (group) free((void *)group);}
};
/******************************************************************************/
/* X r d O s s C a c h e */
/******************************************************************************/
class XrdOssCache
{
public:
static void Adjust(dev_t devid, off_t size);
static void Adjust(const char *Path, off_t size, struct stat *buf=0);
static void Adjust(XrdOssCache_FS *fsp, off_t size);
struct allocInfo
{const char *Path; // Req: Local file name
const char *cgName; // Req: Cache group name
long long cgSize; // Opt: Estimated size
const char *cgPath; // Opt: Specific partition path
int cgPlen; // Opt: Length of partition path
int cgPFsz; // Req: Size of buffer
char *cgPFbf; // Req: Buffer for cache pfn of size cgPFsz
char *cgPsfx; // Out: -> pfn suffix area. If 0, non-xa cache
XrdOssCache_FS *cgFSp; // Out: -> Cache file system definition
mode_t aMode; // Opt: Create mode; if 0, pfn file not created
allocInfo(const char *pP, char *bP, int bL)
: Path(pP), cgName(0), cgSize(0), cgPath(0), cgPlen(0),
cgPFsz(bL), cgPFbf(bP), cgPsfx(0), cgFSp(0), aMode(0) {}
~allocInfo() {}
};
static int Alloc(allocInfo &aInfo);
static void DevInfo(struct stat &buf, bool limits=false);
static XrdOssCache_FS *Find(const char *Path, int lklen=0);
static int Init(const char *UDir, const char *Qfile,
int isSOL, int usync=0);
static int Init(long long aMin, int ovhd, int aFuzz);
static void List(const char *lname, XrdSysError &Eroute);
static void MapDevs(bool dBug=false);
static char *Parse(const char *token, char *cbuff, int cblen);
static void *Scan(int cscanint);
XrdOssCache() {}
~XrdOssCache() {}
static XrdSysMutex Mutex; // Cache context lock
static long long fsTotal; // Total number of bytes known
static long long fsLarge; // Total number of bytes in largest fspart
static long long fsTotFr; // Total number of bytes free
static long long fsFree; // Maximum contiguous free space
static long long fsSize; // Size of partition with fsFree
static XrdOssCache_FS *fsfirst; // -> First filesystem
static XrdOssCache_FS *fslast; // -> Last filesystem
static XrdOssCache_FSData *fsdata; // -> Filesystem data
static int fsCount; // Number of file systems
private:
static bool MapDM(const char *ldm, char *buff, int blen);
static long long minAlloc;
static double fuzAlloc;
static int ovhAlloc;
static int Quotas;
static int Usage;
};
#endif
XrdOssCache_FSAP::apNum
int apNum
Definition XrdOssCache.hh:173
XrdOssCache_FSAP::apVec
const char ** apVec
Definition XrdOssCache.hh:172
XrdOssCache_FSAP::fsP
XrdOssCache_FSData * fsP
Definition XrdOssCache.hh:171
XrdOssCache_FSAP
Definition XrdOssCache.hh:170
XrdOssVS.hh
XrdOucDLlist.hh
stat
#define stat(a, b)
Definition XrdPosix.hh:101
Path
XrdOucString Path
Definition XrdSecpwdSrvAdmin.cc:160
XrdSysError.hh
XrdSysPthread.hh
XrdOssCache_FSData
Definition XrdOssCache.hh:107
XrdOssCache_FSData::updt
time_t updt
Definition XrdOssCache.hh:117
XrdOssCache_FSData::stat
int stat
Definition XrdOssCache.hh:118
XrdOssCache_FSData::path
const char * path
Definition XrdOssCache.hh:114
XrdOssCache_FSData::XrdOssCache_FSData
XrdOssCache_FSData(const char *, STATFS_t &, dev_t)
Definition XrdOssCache.cc:105
XrdOssCache_FSData::devN
const char * devN
Definition XrdOssCache.hh:116
XrdOssCache_FSData::pact
const char * pact
Definition XrdOssCache.hh:115
XrdOssCache_FSData::partID
unsigned short partID
Definition XrdOssCache.hh:120
XrdOssCache_FSData::fsid
dev_t fsid
Definition XrdOssCache.hh:113
XrdOssCache_FSData::~XrdOssCache_FSData
~XrdOssCache_FSData()
Definition XrdOssCache.hh:123
XrdOssCache_FSData::size
long long size
Definition XrdOssCache.hh:111
XrdOssCache_FSData::frsz
long long frsz
Definition XrdOssCache.hh:112
XrdOssCache_FSData::bdevID
unsigned short bdevID
Definition XrdOssCache.hh:119
XrdOssCache_FSData::next
XrdOssCache_FSData * next
Definition XrdOssCache.hh:110
XrdOssCache_FS
Definition XrdOssCache.hh:133
XrdOssCache_FS::group
const char * group
Definition XrdOssCache.hh:139
XrdOssCache_FS::getSpace
static int getSpace(XrdOssCache_Space &Space, const char *sname, XrdOssVSPart **vsPart=0)
Definition XrdOssCache.cc:327
XrdOssCache_FS::fsgroup
XrdOssCache_Group * fsgroup
Definition XrdOssCache.hh:145
XrdOssCache_FS::opts
FSOpts opts
Definition XrdOssCache.hh:142
XrdOssCache_FS::freeSpace
static long long freeSpace(long long &Size, const char *path=0)
Definition XrdOssCache.cc:279
XrdOssCache_FS::~XrdOssCache_FS
~XrdOssCache_FS()
Definition XrdOssCache.hh:160
XrdOssCache_FS::FSOpts
FSOpts
Definition XrdOssCache.hh:136
XrdOssCache_FS::None
@ None
Definition XrdOssCache.hh:136
XrdOssCache_FS::isXA
@ isXA
Definition XrdOssCache.hh:136
XrdOssCache_FS::plen
int plen
Definition XrdOssCache.hh:141
XrdOssCache_FS::suffix
char suffix[4]
Definition XrdOssCache.hh:143
XrdOssCache_FS::path
const char * path
Definition XrdOssCache.hh:140
XrdOssCache_FS::next
XrdOssCache_FS * next
Definition XrdOssCache.hh:138
XrdOssCache_FS::Add
static int Add(const char *Path)
Definition XrdOssCache.cc:250
XrdOssCache_FS::fsdata
XrdOssCache_FSData * fsdata
Definition XrdOssCache.hh:144
XrdOssCache_FS::XrdOssCache_FS
XrdOssCache_FS(int &retc, const char *fsg, const char *fsp, FSOpts opt)
Definition XrdOssCache.cc:146
XrdOssCache_Group
Definition XrdOssCache.hh:183
XrdOssCache_Group::PubQuota
static long long PubQuota
Definition XrdOssCache.hh:197
XrdOssCache_Group::fsNum
short fsNum
Definition XrdOssCache.hh:193
XrdOssCache_Group::~XrdOssCache_Group
~XrdOssCache_Group()
Definition XrdOssCache.hh:205
XrdOssCache_Group::fsgroups
static XrdOssCache_Group * fsgroups
Definition XrdOssCache.hh:199
XrdOssCache_Group::group
char * group
Definition XrdOssCache.hh:187
XrdOssCache_Group::XrdOssCache_Group
XrdOssCache_Group(const char *grp, XrdOssCache_FS *fsp=0)
Definition XrdOssCache.hh:201
XrdOssCache_Group::curr
XrdOssCache_FS * curr
Definition XrdOssCache.hh:188
XrdOssCache_Group::Usage
long long Usage
Definition XrdOssCache.hh:190
XrdOssCache_Group::fsVec
XrdOssCache_FSAP * fsVec
Definition XrdOssCache.hh:189
XrdOssCache_Group::GRPid
int GRPid
Definition XrdOssCache.hh:192
XrdOssCache_Group::next
XrdOssCache_Group * next
Definition XrdOssCache.hh:186
XrdOssCache_Group::Quota
long long Quota
Definition XrdOssCache.hh:191
XrdOssCache_Group::PubGroup
static XrdOssCache_Group * PubGroup
Definition XrdOssCache.hh:196
XrdOssCache_Group::rsvd
short rsvd
Definition XrdOssCache.hh:194
XrdOssCache_Space
Definition XrdOssCache.hh:79
XrdOssCache_Space::Usage
long long Usage
Definition XrdOssCache.hh:88
XrdOssCache_Space::~XrdOssCache_Space
~XrdOssCache_Space()
Definition XrdOssCache.hh:93
XrdOssCache_Space::Total
long long Total
Definition XrdOssCache.hh:82
XrdOssCache_Space::Inodes
long long Inodes
Definition XrdOssCache.hh:86
XrdOssCache_Space::XrdOssCache_Space
XrdOssCache_Space()
Definition XrdOssCache.hh:91
XrdOssCache_Space::Largest
long long Largest
Definition XrdOssCache.hh:85
XrdOssCache_Space::Inleft
long long Inleft
Definition XrdOssCache.hh:87
XrdOssCache_Space::Free
long long Free
Definition XrdOssCache.hh:83
XrdOssCache_Space::Maxfree
long long Maxfree
Definition XrdOssCache.hh:84
XrdOssCache_Space::Quota
long long Quota
Definition XrdOssCache.hh:89
XrdOssCache::Init
static int Init(const char *UDir, const char *Qfile, int isSOL, int usync=0)
Definition XrdOssCache.cc:644
XrdOssCache::fsdata
static XrdOssCache_FSData * fsdata
Definition XrdOssCache.hh:271
XrdOssCache::Scan
static void * Scan(int cscanint)
Definition XrdOssCache.cc:843
XrdOssCache::fsSize
static long long fsSize
Definition XrdOssCache.hh:268
XrdOssCache::~XrdOssCache
~XrdOssCache()
Definition XrdOssCache.hh:260
XrdOssCache::fsLarge
static long long fsLarge
Definition XrdOssCache.hh:265
XrdOssCache::fsTotal
static long long fsTotal
Definition XrdOssCache.hh:264
XrdOssCache::Alloc
static int Alloc(allocInfo &aInfo)
Definition XrdOssCache.cc:492
XrdOssCache::DevInfo
static void DevInfo(struct stat &buf, bool limits=false)
Definition XrdOssCache.cc:583
XrdOssCache::fsTotFr
static long long fsTotFr
Definition XrdOssCache.hh:266
XrdOssCache::Parse
static char * Parse(const char *token, char *cbuff, int cblen)
Definition XrdOssCache.cc:814
XrdOssCache::XrdOssCache
XrdOssCache()
Definition XrdOssCache.hh:259
XrdOssCache::fsCount
static int fsCount
Definition XrdOssCache.hh:272
XrdOssCache::fsfirst
static XrdOssCache_FS * fsfirst
Definition XrdOssCache.hh:269
XrdOssCache::List
static void List(const char *lname, XrdSysError &Eroute)
Definition XrdOssCache.cc:682
XrdOssCache::fsFree
static long long fsFree
Definition XrdOssCache.hh:267
XrdOssCache::fslast
static XrdOssCache_FS * fslast
Definition XrdOssCache.hh:270
XrdOssCache::MapDevs
static void MapDevs(bool dBug=false)
Definition XrdOssCache.cc:709
XrdOssCache::Find
static XrdOssCache_FS * Find(const char *Path, int lklen=0)
Definition XrdOssCache.cc:611
XrdOssCache::Adjust
static void Adjust(dev_t devid, off_t size)
Definition XrdOssCache.cc:397
XrdOssCache::Mutex
static XrdSysMutex Mutex
Definition XrdOssCache.hh:262
XrdOssVSPart
Definition XrdOssVS.hh:64
XrdSysError
Definition XrdSysError.hh:90
XrdSysMutex
Definition XrdSysPthread.hh:165
XrdOssCache::allocInfo::cgSize
long long cgSize
Definition XrdOssCache.hh:225
XrdOssCache::allocInfo::cgFSp
XrdOssCache_FS * cgFSp
Definition XrdOssCache.hh:231
XrdOssCache::allocInfo::cgPlen
int cgPlen
Definition XrdOssCache.hh:227
XrdOssCache::allocInfo::cgPsfx
char * cgPsfx
Definition XrdOssCache.hh:230
XrdOssCache::allocInfo::allocInfo
allocInfo(const char *pP, char *bP, int bL)
Definition XrdOssCache.hh:234
XrdOssCache::allocInfo::cgPFsz
int cgPFsz
Definition XrdOssCache.hh:228
XrdOssCache::allocInfo::aMode
mode_t aMode
Definition XrdOssCache.hh:232
XrdOssCache::allocInfo::cgName
const char * cgName
Definition XrdOssCache.hh:224
XrdOssCache::allocInfo::Path
const char * Path
Definition XrdOssCache.hh:223
XrdOssCache::allocInfo::cgPath
const char * cgPath
Definition XrdOssCache.hh:226
XrdOssCache::allocInfo::~allocInfo
~allocInfo()
Definition XrdOssCache.hh:237
XrdOssCache::allocInfo::cgPFbf
char * cgPFbf
Definition XrdOssCache.hh:229