XRootD
XrdOssCache_FS Class Reference

#include <XrdOssCache.hh>

+ Collaboration diagram for XrdOssCache_FS:

Public Types

enum  FSOpts {
  None = 0 ,
  isXA = 1
}
 

Public Member Functions

 XrdOssCache_FS (int &retc, const char *fsg, const char *fsp, FSOpts opt)
 
 ~XrdOssCache_FS ()
 

Static Public Member Functions

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)
 

Public Attributes

XrdOssCache_FSDatafsdata
 
XrdOssCache_Groupfsgroup
 
const char * group
 
XrdOssCache_FSnext
 
FSOpts opts
 
const char * path
 
int plen
 
char suffix [4]
 

Detailed Description

Definition at line 132 of file XrdOssCache.hh.

Member Enumeration Documentation

◆ FSOpts

Enumerator
None 
isXA 

Definition at line 136 of file XrdOssCache.hh.

136 {None = 0, isXA = 1};

Constructor & Destructor Documentation

◆ XrdOssCache_FS()

XrdOssCache_FS::XrdOssCache_FS ( int &  retc,
const char *  fsg,
const char *  fsp,
FSOpts  opt 
)

Definition at line 146 of file XrdOssCache.cc.

150 {
151  static const mode_t theMode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
152  STATFS_t fsbuff;
153  struct stat sfbuff;
154  XrdOssCache_FSData *fdp;
155  XrdOssCache_FS *fsp;
156  int n;
157 
158 // Prefill in case of failure
159 //
160  path = group = 0;
161 
162 // Verify that this is not a duplicate
163 //
164  fsp = XrdOssCache::fsfirst;
165  while(fsp && (strcmp(fsp->path,fsPath)||strcmp(fsp->fsgroup->group,fsGrp)))
166  if ((fsp = fsp->next) == XrdOssCache::fsfirst) {fsp = 0; break;}
167  if (fsp) {retc = EEXIST; return;}
168 
169 // Set the groupname and the path which is the supplied path/group name
170 //
171  if (!(fsOpts & isXA)) path = strdup(fsPath);
172  else {path = XrdOssPath::genPath(fsPath, fsGrp, suffix);
173  if (mkdir(path, theMode) && errno != EEXIST) {retc=errno; return;}
174  }
175  plen = strlen(path);
176  group = strdup(fsGrp);
177  fsgroup= 0;
178  opts = fsOpts;
179  retc = ENOMEM;
180 
181 // Find the filesystem for this object
182 //
183  if (FS_Stat(fsPath, &fsbuff) || stat(fsPath, &sfbuff)) {retc=errno; return;}
184 
185 // Find the matching filesystem data
186 //
187  fdp = XrdOssCache::fsdata;
188  while(fdp) {if (fdp->fsid == sfbuff.st_dev) break; fdp = fdp->next;}
189 
190 // If we didn't find the filesystem, then create one
191 //
192  if (!fdp)
193  {if (!(fdp = new XrdOssCache_FSData(fsPath,fsbuff,sfbuff.st_dev))) return;
194  else {fdp->next = XrdOssCache::fsdata; XrdOssCache::fsdata = fdp;}
195  }
196 
197 // Complete the filesystem block (failure now is not an option)
198 //
199  fsdata = fdp;
200  retc = 0;
201 
202 // Link this filesystem into the filesystem chain
203 //
204  if (!XrdOssCache::fsfirst) {next = this;
205  XrdOssCache::fsfirst = this;
206  XrdOssCache::fslast = this;
207  }
208  else {next = XrdOssCache::fslast->next;
209  XrdOssCache::fslast->next = this;
210  XrdOssCache::fslast = this;
211  }
212 
213 // Check if this is the first group allocation
214 //
216  while(fsgroup && strcmp(group, fsgroup->group)) fsgroup = fsgroup->next;
217  if (!fsgroup && (fsgroup = new XrdOssCache_Group(group, this)))
220  }
221 
222 // Add a filesystem to this group but only if it is a new one
223 //
224  XrdOssCache_FSAP *fsAP;
225  for (n = 0; n < fsgroup->fsNum && fdp != fsgroup->fsVec[n].fsP; n++);
226  if (n >= fsgroup->fsNum)
227  {n= (fsgroup->fsNum + 1) * sizeof(XrdOssCache_FSAP);
228  fsgroup->fsVec = (XrdOssCache_FSAP *)realloc((void *)fsgroup->fsVec,n);
229  fsAP = &(fsgroup->fsVec[fsgroup->fsNum++]);
230  fsAP->fsP = fdp;
231  fsAP->apVec = 0;
232  fsAP->apNum = 0;
233  } else fsAP = &(fsgroup->fsVec[n]);
234 
235 // Add the allocation path to this partition
236 //
237  n = (fsAP->apNum + 2) * sizeof(char *);
238  fsAP->apVec = (const char **)realloc((void *)fsAP->apVec, n);
239  fsAP->apVec[fsAP->apNum++] = path;
240  fsAP->apVec[fsAP->apNum] = 0;
241 }
const char ** apVec
Definition: XrdOssCache.hh:172
XrdOssCache_FSData * fsP
Definition: XrdOssCache.hh:171
int stat(const char *path, struct stat *buf)
int mkdir(const char *path, mode_t mode)
XrdOssCache_FSData * next
Definition: XrdOssCache.hh:110
const char * group
Definition: XrdOssCache.hh:139
XrdOssCache_Group * fsgroup
Definition: XrdOssCache.hh:145
const char * path
Definition: XrdOssCache.hh:140
XrdOssCache_FS * next
Definition: XrdOssCache.hh:138
XrdOssCache_FSData * fsdata
Definition: XrdOssCache.hh:144
static XrdOssCache_Group * fsgroups
Definition: XrdOssCache.hh:199
XrdOssCache_FSAP * fsVec
Definition: XrdOssCache.hh:189
XrdOssCache_Group * next
Definition: XrdOssCache.hh:186
static XrdOssCache_FSData * fsdata
Definition: XrdOssCache.hh:271
static XrdOssCache_FS * fsfirst
Definition: XrdOssCache.hh:269
static XrdOssCache_FS * fslast
Definition: XrdOssCache.hh:270
static char * genPath(const char *inPath, const char *cgrp, char *sfx)
Definition: XrdOssPath.cc:134

References XrdOssCache_FSAP::apNum, XrdOssCache_FSAP::apVec, XrdOssCache::fsdata, XrdOssCache::fsfirst, fsgroup, XrdOssCache_Group::fsgroups, XrdOssCache::fslast, XrdOssCache_FSAP::fsP, XrdOssPath::genPath(), XrdOssCache_Group::group, mkdir(), XrdOssCache_FSData::next, next, XrdOssCache_Group::next, opts, path, and stat().

+ Here is the call graph for this function:

◆ ~XrdOssCache_FS()

XrdOssCache_FS::~XrdOssCache_FS ( )
inline

Definition at line 160 of file XrdOssCache.hh.

160  {if (group) free((void *)group);
161  if (path) free((void *)path);
162  }

References group, and path.

Member Function Documentation

◆ Add()

int XrdOssCache_FS::Add ( const char *  Path)
static

Definition at line 250 of file XrdOssCache.cc.

251 {
252  STATFS_t fsbuff;
253  struct stat sfbuff;
254  XrdOssCache_FSData *fdp;
255 
256 // Find the filesystem for this object
257 //
258  if (FS_Stat(fsPath, &fsbuff) || stat(fsPath, &sfbuff)) return -errno;
259 
260 // Find the matching filesystem data
261 //
262  fdp = XrdOssCache::fsdata;
263  while(fdp) {if (fdp->fsid == sfbuff.st_dev) break; fdp = fdp->next;}
264  if (fdp) return 0;
265 
266 // Create new filesystem data that will not be linked to any filesystem
267 //
268  if (!(fdp = new XrdOssCache_FSData(fsPath,fsbuff,sfbuff.st_dev)))
269  return -ENOMEM;
270  fdp->next = XrdOssCache::fsdata;
271  XrdOssCache::fsdata = fdp;
272  return 0;
273 }

References XrdOssCache::fsdata, XrdOssCache_FSData::next, and stat().

Referenced by XrdOssSys::ConfigSpace().

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

◆ freeSpace() [1/2]

long long XrdOssCache_FS::freeSpace ( long long &  Size,
const char *  path = 0 
)
static

Definition at line 279 of file XrdOssCache.cc.

280 {
281  STATFS_t fsbuff;
282  long long fSpace;
283 
284 // Free space for a specific path
285 //
286  if (path)
287  {if (FS_Stat(path, &fsbuff)) return -1;
288  Size = static_cast<long long>(fsbuff.f_blocks)
289  * static_cast<long long>(fsbuff.FS_BLKSZ);
290  return static_cast<long long>(fsbuff.f_bavail)
291  * static_cast<long long>(fsbuff.FS_BLKSZ);
292  }
293 
294 // Free space for the whole system
295 //
297  fSpace = XrdOssCache::fsFree;
298  Size = XrdOssCache::fsSize;
300  return fSpace;
301 }
static long long fsSize
Definition: XrdOssCache.hh:268
static long long fsFree
Definition: XrdOssCache.hh:267
static XrdSysMutex Mutex
Definition: XrdOssCache.hh:262

References XrdOssCache::fsFree, XrdOssCache::fsSize, XrdSysMutex::Lock(), XrdOssCache::Mutex, and XrdSysMutex::UnLock().

Referenced by XrdOssSys::getStats(), XrdOssCache::Scan(), and XrdOssSys::StatFS().

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

◆ freeSpace() [2/2]

long long XrdOssCache_FS::freeSpace ( XrdOssCache_Space Space,
const char *  path 
)
static

Definition at line 305 of file XrdOssCache.cc.

306 {
307  STATFS_t fsbuff;
308 
309 // Free space for a specific path
310 //
311  if (!path || FS_Stat(path, &fsbuff)) return -1;
312 
313  Space.Total = static_cast<long long>(fsbuff.f_blocks)
314  * static_cast<long long>(fsbuff.FS_BLKSZ);
315  Space.Free = static_cast<long long>(fsbuff.f_bavail)
316  * static_cast<long long>(fsbuff.FS_BLKSZ);
317  Space.Inodes= static_cast<long long>(fsbuff.f_files);
318  Space.Inleft= static_cast<long long>(fsbuff.FS_FFREE);
319 
320  return Space.Free;
321 }
long long Inodes
Definition: XrdOssCache.hh:86
long long Inleft
Definition: XrdOssCache.hh:87

References XrdOssCache_Space::Free, XrdOssCache_Space::Inleft, XrdOssCache_Space::Inodes, and XrdOssCache_Space::Total.

◆ getSpace() [1/2]

int XrdOssCache_FS::getSpace ( XrdOssCache_Space Space,
const char *  sname,
XrdOssVSPart **  vsPart = 0 
)
static

Definition at line 327 of file XrdOssCache.cc.

329 {
331 
332 // Try to find the space group name
333 //
334  while(fsg && strcmp(sname, fsg->group)) fsg = fsg->next;
335  if (!fsg) return 0;
336 
337 // Return the accumulated result
338 //
339  return getSpace(Space, fsg, vsPart);
340 }
static int getSpace(XrdOssCache_Space &Space, const char *sname, XrdOssVSPart **vsPart=0)
Definition: XrdOssCache.cc:327

References XrdOssCache_Group::fsgroups, XrdOssCache_Group::group, and XrdOssCache_Group::next.

Referenced by XrdOssSys::getStats(), XrdOssSys::StatLS(), and XrdOssSys::StatVS().

+ Here is the caller graph for this function:

◆ getSpace() [2/2]

int XrdOssCache_FS::getSpace ( XrdOssCache_Space Space,
XrdOssCache_Group fsg,
XrdOssVSPart **  vsPart = 0 
)
static

Definition at line 344 of file XrdOssCache.cc.

346 {
347  XrdOssVSPart *pVec;
348  XrdOssCache_FSData *fsd;
349 
350 // If there is no partition table then we really have no space to report
351 //
352  if (fsg->fsNum < 1 || !fsg->fsVec) return 0;
353 
354 // If partion information is wanted, allocate a partition table
355 //
356  if (vsPart) *vsPart = pVec = new XrdOssVSPart[fsg->fsNum];
357  else pVec = 0;
358 
359 // Prevent any changes
360 //
362 
363 // Get overall values
364 //
365  Space.Quota = fsg->Quota;
366  Space.Usage = fsg->Usage;
367 
368 // Accumulate the stats.
369 //
370  for (int i = 0; i < fsg->fsNum; i++)
371  {fsd = fsg->fsVec[i].fsP;
372  Space.Total += fsd->size;
373  Space.Free += fsd->frsz;
374  if (fsd->frsz > Space.Maxfree) Space.Maxfree = fsd->frsz;
375  if (fsd->size > Space.Largest) Space.Largest = fsd->size;
376 
377  if (pVec)
378  {pVec[i].pPath = fsd->path;
379  pVec[i].aPath = fsg->fsVec[i].apVec;
380  pVec[i].Total = fsd->size;
381  pVec[i].Free = fsd->frsz;
382  pVec[i].bdevID= fsd->bdevID;
383  pVec[i].partID= fsd->partID;
384  }
385  }
387 
388 // All done
389 //
390  return fsg->fsNum;
391 }
const char * path
Definition: XrdOssCache.hh:114
unsigned short partID
Definition: XrdOssCache.hh:120
unsigned short bdevID
Definition: XrdOssCache.hh:119
long long Largest
Definition: XrdOssCache.hh:85
long long Maxfree
Definition: XrdOssCache.hh:84
unsigned short partID
Definition: XrdOssVS.hh:71
long long Total
Definition: XrdOssVS.hh:68
const char * pPath
Definition: XrdOssVS.hh:66
const char ** aPath
Definition: XrdOssVS.hh:67
long long Free
Definition: XrdOssVS.hh:69
unsigned short bdevID
Definition: XrdOssVS.hh:70

References XrdOssVSPart::aPath, XrdOssCache_FSAP::apVec, XrdOssCache_FSData::bdevID, XrdOssVSPart::bdevID, XrdOssCache_Space::Free, XrdOssVSPart::Free, XrdOssCache_FSData::frsz, XrdOssCache_Group::fsNum, XrdOssCache_FSAP::fsP, XrdOssCache_Group::fsVec, XrdOssCache_Space::Largest, XrdSysMutex::Lock(), XrdOssCache_Space::Maxfree, XrdOssCache::Mutex, XrdOssCache_FSData::partID, XrdOssVSPart::partID, XrdOssCache_FSData::path, XrdOssVSPart::pPath, XrdOssCache_Space::Quota, XrdOssCache_Group::Quota, XrdOssCache_FSData::size, XrdOssCache_Space::Total, XrdOssVSPart::Total, XrdSysMutex::UnLock(), XrdOssCache_Space::Usage, and XrdOssCache_Group::Usage.

+ Here is the call graph for this function:

Member Data Documentation

◆ fsdata

XrdOssCache_FSData* XrdOssCache_FS::fsdata

Definition at line 144 of file XrdOssCache.hh.

Referenced by XrdOssCache::Adjust(), XrdOssCache::Alloc(), and XrdOssCache::List().

◆ fsgroup

XrdOssCache_Group* XrdOssCache_FS::fsgroup

Definition at line 145 of file XrdOssCache.hh.

Referenced by XrdOssCache_FS(), and XrdOssCache::Adjust().

◆ group

const char* XrdOssCache_FS::group

Definition at line 139 of file XrdOssCache.hh.

Referenced by ~XrdOssCache_FS(), XrdOssCache::Alloc(), and XrdOssCache::List().

◆ next

◆ opts

FSOpts XrdOssCache_FS::opts

Definition at line 142 of file XrdOssCache.hh.

Referenced by XrdOssCache::Alloc(), and XrdOssCache::List().

◆ path

const char* XrdOssCache_FS::path

◆ plen

int XrdOssCache_FS::plen

Definition at line 141 of file XrdOssCache.hh.

Referenced by XrdOssCache::Alloc(), and XrdOssCache::List().

◆ suffix

char XrdOssCache_FS::suffix[4]

Definition at line 143 of file XrdOssCache.hh.

Referenced by XrdOssCache::Alloc().


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