37 #if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
39 #define FS_Stat(a,b) statfs(a,b)
40 #define STATFS_t struct statfs
41 #define FS_BLKSZ f_bsize
42 #define FS_FFREE f_ffree
44 #if defined(__APPLE__) || defined(__FreeBSD__)
45 #include <sys/param.h>
46 #include <sys/mount.h>
47 #define STATFS_t struct statfs
48 #define FS_Stat(a,b) statfs(a,b)
49 #define FS_BLKSZ f_bsize
50 #define FS_FFREE f_ffree
87 #define HSZ(x,y) XrdOucUtils::HSize(x, y, (int)sizeof(y))
97 size_t tmpSize, tmpFree;
101 if (!(tmpSize = getFSpace(tmpFree, fs_Path)))
102 Elog.
Emsg(
"FSMon", errno,
"filesystem info for", fs_Path);
103 else {fs_Size = tmpSize;
105 fs_MaxUsed = fs_Size - fs_MinFree;
106 fs_inUse = fs_Size - fs_Free;
111 DEBUG(
"FS info: Size="<<fs_Size<<
" Free="<<fs_Free<<
" Used="<<fs_inUse<<
112 " Commit="<<fs_inBkp<<
" Avail="<<
113 (fs_Free <= fs_inBkp ? 0 : fs_Free - fs_inBkp));
124 size_t XrdOssArcFSMon::getFSpace(
size_t &Free,
const char *path)
130 if (FS_Stat(path, &fsbuff))
return 0;
131 Free =
static_cast<size_t>(fsbuff.f_bavail)
132 *
static_cast<size_t>(fsbuff.FS_BLKSZ);
133 return static_cast<size_t>(fsbuff.f_blocks)
134 *
static_cast<size_t>(fsbuff.FS_BLKSZ);
143 char buff[1024], HSb1[16], HSb2[16], HSb3[16];
151 if (!(fs_Size = getFSpace(fs_Free, path)))
152 {
Elog.
Emsg(
"FSMon", errno,
"filesystem info for", path);
158 if (fVal < 0) fs_MinFree = fs_Size*(
static_cast<size_t>(-fVal))/100;
159 else {fs_MinFree =
static_cast<size_t>(fVal);
160 if (fs_MinFree >= fs_Size)
161 {snprintf(buff,
sizeof(buff),
"Minimum free space allowed (%s) "
162 ">= size of filesystem (%s) at",
163 HSZ(fs_MinFree, HSb1),
HSZ(fs_Size, HSb2));
171 fs_MaxUsed = fs_Size - fs_MinFree;
172 fs_inUse = fs_Size - fs_Free;
177 if (fs_Free < fs_MinFree)
178 {snprintf(buff,
sizeof(buff),
"Filesystme free space (%s) < minimum "
180 HSZ(fs_Free, HSb1),
HSZ(fs_MinFree, HSb2));
181 Elog.
Say(
"Config warning: ", buff, path);
183 snprintf(buff,
sizeof(buff),
"Filesystme free space: %s; "
184 "minimum allowed: %s; remaining: %s at ",
185 HSZ(fs_Free, HSb1),
HSZ(fs_MinFree,HSb2),
186 HSZ(fs_Free-fs_MinFree, HSb3));
187 Elog.
Say(
"Config outcome: ", buff, path);
208 if ((fs_inUse + fs_inBkp + btP->
numBytes) <= fs_MaxUsed)
218 btWaitQ.push_back(btP);
230 size_t tmpSize, tmpFree;
235 if (bytes >= fs_inBkp) fs_inBkp = 0;
236 else fs_inBkp -= bytes;
240 if (!(tmpSize = getFSpace(tmpFree, fs_Path)))
241 Elog.
Emsg(
"FSMon", errno,
"filesystem info for", fs_Path);
242 else {fs_Size = tmpSize;
244 fs_MaxUsed = fs_Size - fs_MinFree;
245 fs_inUse = fs_Size - fs_Free;
251 while(!btWaitQ.empty())
253 if ((fs_inUse + fs_inBkp + btP->
numBytes + nTot) <= fs_MaxUsed)
262 if ((n = btWaitQ.size()))
263 {
char buff[1024], HSb1[16], HSb2[16];
264 size_t free = (fs_Free <= fs_inBkp ? 0 : fs_Free - fs_inBkp);
265 snprintf(buff,
sizeof(buff),
"Insufficient free space (%s < %s); "
266 "%d backup(s) still pending!",
267 HSZ(free, HSb1),
HSZ(fs_MinFree, HSb2), n);
void Release(size_t bytes)
bool Permit(XrdOssArcBackupTask *btP)
bool Init(const char *path, long long fVal, int fsupdt)
void Schedule(XrdJob *jp)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
XrdSysTrace ArcTrace("OssArc")
XrdSysError Elog(0, "OssArc_")