XRootD
XrdOssArcFSMon Class Reference

#include <XrdOssArcFSMon.hh>

+ Inheritance diagram for XrdOssArcFSMon:
+ Collaboration diagram for XrdOssArcFSMon:

Public Member Functions

 XrdOssArcFSMon ()
 
 ~XrdOssArcFSMon ()
 
void DoIt () override
 
bool Init (const char *path, long long fVal, int fsupdt)
 
bool Permit (XrdOssArcBackupTask *btP)
 
void Release (size_t bytes)
 
- Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 

Additional Inherited Members

- Public Attributes inherited from XrdJob
const char * Comment
 
XrdJobNextJob
 

Detailed Description

Definition at line 41 of file XrdOssArcFSMon.hh.

Constructor & Destructor Documentation

◆ XrdOssArcFSMon()

XrdOssArcFSMon::XrdOssArcFSMon ( )
inline

Definition at line 53 of file XrdOssArcFSMon.hh.

53 : fs_inBkp(0) {}

◆ ~XrdOssArcFSMon()

XrdOssArcFSMon::~XrdOssArcFSMon ( )
inline

Definition at line 54 of file XrdOssArcFSMon.hh.

54 {}

Member Function Documentation

◆ DoIt()

void XrdOssArcFSMon::DoIt ( )
overridevirtual

Implements XrdJob.

Definition at line 93 of file XrdOssArcFSMon.cc.

94 {
95  TraceInfo("FSMon", 0);
96  XrdSysMutexHelper rmHelp(rmMutex);
97  size_t tmpSize, tmpFree;
98 
99 // Update file system statistics
100 //
101  if (!(tmpSize = getFSpace(tmpFree, fs_Path)))
102  Elog.Emsg("FSMon", errno, "filesystem info for", fs_Path);
103  else {fs_Size = tmpSize;
104  fs_Free = tmpFree;
105  fs_MaxUsed = fs_Size - fs_MinFree;
106  fs_inUse = fs_Size - fs_Free;
107  }
108 
109 // Perform some debugging
110 //
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));
114 
115 // reschedule ourselves
116 //
117  schedP->Schedule(this, time(0)+fs_Updt);
118 }
#define DEBUG(x)
Definition: XrdBwmTrace.hh:54
#define TraceInfo(x, y)
void Schedule(XrdJob *jp)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:116
XrdScheduler * schedP
XrdSysError Elog(0, "OssArc_")

References DEBUG, XrdOssArcGlobals::Elog, XrdSysError::Emsg(), XrdOssArcGlobals::schedP, XrdScheduler::Schedule(), and TraceInfo.

+ Here is the call graph for this function:

◆ Init()

bool XrdOssArcFSMon::Init ( const char *  path,
long long  fVal,
int  fsupdt 
)

Definition at line 141 of file XrdOssArcFSMon.cc.

142 {
143  char buff[1024], HSb1[16], HSb2[16], HSb3[16];
144 
145 // Save the update frequescy
146 //
147  fs_Updt = fsupdt;
148 
149 // The first step is to get the relevant filesystem statistics we need
150 //
151  if (!(fs_Size = getFSpace(fs_Free, path)))
152  {Elog.Emsg("FSMon", errno, "filesystem info for", path);
153  return false;
154  }
155 
156 // Calculate the minimum free space allowed (if fval < 0 -> percentage)
157 //
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));
164  Elog.Emsg("FSMon", buff, path);
165  return false;
166  }
167  }
168 
169 // Calculate the maximum amount of usage and set the filesystem path
170 //
171  fs_MaxUsed = fs_Size - fs_MinFree;
172  fs_inUse = fs_Size - fs_Free;
173  fs_Path = path;
174 
175 // Check if we don't have enough free space at startup time
176 //
177  if (fs_Free < fs_MinFree)
178  {snprintf(buff, sizeof(buff), "Filesystme free space (%s) < minimum "
179  "allowed (%s) at ",
180  HSZ(fs_Free, HSb1), HSZ(fs_MinFree, HSb2));
181  Elog.Say("Config warning: ", buff, path);
182  } else {
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);
188  }
189 
190 // Start automatic filesystem updates
191 //
192  schedP->Schedule(this, time(0)+fs_Updt);
193 
194 // All done
195 //
196  return true;
197 }
#define HSZ(x, y)
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)
Definition: XrdSysError.cc:162

References XrdOssArcGlobals::Elog, XrdSysError::Emsg(), HSZ, XrdSysError::Say(), XrdOssArcGlobals::schedP, and XrdScheduler::Schedule().

Referenced by XrdOssArcConfig::Configure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Permit()

bool XrdOssArcFSMon::Permit ( XrdOssArcBackupTask btP)

Definition at line 203 of file XrdOssArcFSMon.cc.

204 {
205 // Check if we can permit this request or the caller will need to wait
206 //
207  rmMutex.Lock();
208  if ((fs_inUse + fs_inBkp + btP->numBytes) <= fs_MaxUsed)
209  {fs_inBkp += btP->numBytes;
210  btP->relSpace = true;
211  rmMutex.UnLock();
212  return true;
213  }
214 
215 // There is not enough space to permit the request. Place it on the re-drive
216 // queue and tell the call to wait.
217 //
218  btWaitQ.push_back(btP);
219  rmMutex.UnLock();
220  return false;
221 }

References XrdOssArcBackupTask::numBytes, and XrdOssArcBackupTask::relSpace.

Referenced by XrdOssArcBackupTask::BkpXeq().

+ Here is the caller graph for this function:

◆ Release()

void XrdOssArcFSMon::Release ( size_t  bytes)

Definition at line 227 of file XrdOssArcFSMon.cc.

228 {
229  XrdSysMutexHelper mHelp(rmMutex);
230  size_t tmpSize, tmpFree;
231  int n;
232 
233 // Release the number of bytes previously reserved
234 //
235  if (bytes >= fs_inBkp) fs_inBkp = 0;
236  else fs_inBkp -= bytes;
237 
238 // Update file system statistics
239 //
240  if (!(tmpSize = getFSpace(tmpFree, fs_Path)))
241  Elog.Emsg("FSMon", errno, "filesystem info for", fs_Path);
242  else {fs_Size = tmpSize;
243  fs_Free = tmpFree;
244  fs_MaxUsed = fs_Size - fs_MinFree;
245  fs_inUse = fs_Size - fs_Free;
246  }
247 
248 // If a backup is waiting for space, see if it can proceed
249 //
250  size_t nTot = 0;
251  while(!btWaitQ.empty())
252  {XrdOssArcBackupTask* btP = btWaitQ.front();
253  if ((fs_inUse + fs_inBkp + btP->numBytes + nTot) <= fs_MaxUsed)
254  {nTot += btP->numBytes;
255  btP->btSem.Post();
256  btWaitQ.pop_front();
257  } else break;
258  }
259 
260 // Issue message if there are still queued backups
261 //
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);
268  Elog.Emsg("FSMon", buff);
269  }
270 }
XrdSysSemaphore btSem

References XrdOssArcBackupTask::btSem, XrdOssArcGlobals::Elog, XrdSysError::Emsg(), HSZ, XrdOssArcBackupTask::numBytes, and XrdSysSemaphore::Post().

Referenced by XrdOssArcBackupTask::~XrdOssArcBackupTask().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: