33 #include <sys/param.h>
60 {num++; Msg(
"Orphaned lock file: ", sP->
lockPath());}
62 {num++; Msg(
"Orphaned pfn file: ", sP->
pfnPath());
66 {num++; Msg(
"Orphaned pin file: ", sP->
pinPath());}
71 if (!Opt.Fix || !num)
return 1;
74 if (Resp !=
'y')
return Resp !=
'a';
79 rem = AuditRemove(sP);
84 sprintf(buff,
"%d of %d orphaned files removed.", rem, num);
99 Msg(
"Dangling link: ", sP->
basePath());
105 if (!Opt.Fix)
return 1;
108 if (Resp !=
'y')
return Resp !=
'a';
114 Emsg(errno,
"remove symlink", sP->
basePath());
115 else if (AuditRemove(sP))
116 {Msg(
"Symlink removed.");
129 static const char *noCPT =
"No copy time for: ";
130 static const char *mkCPT =
"Set copy time?";
140 if (!Opt.Fix)
return -1;
143 if (Resp !=
'y')
return Resp !=
'a';
150 Msg(
"Copy time set.");
159 int XrdFrmAdmin::AuditNames()
164 char pDir[MAXPATHLEN], *lDir = Opt.Args[1];
170 numProb = 0; numFix = 0;
171 if (VerifyMP(
"audit", lDir) !=
'y')
return 0;
175 if (!
Config.LocalPath(lDir, pDir,
sizeof(pDir))) {finalRC = 4;
return 1;}
177 while(Act && (sP = fP->
Get(
ec,1)))
178 {
if (!(sP->
baseFile())) Act = AuditNameNB(sP);
180 Act = AuditNameNF(sP);
182 Act = AuditNameNL(sP);
184 Act = AuditNameXA(sP);
193 if (!Act) Msg(
"Audit names aborted!");
194 sprintf(pDir,
"%d problem%s found; %d fixed.", numProb,
195 (numProb == 1 ?
"" :
"s"), numFix);
207 const char *doWhat =
"Recreate pfn xref?";
208 char Resp, dfltAns =
'n';
214 {
if (!strcmp(pfnInfo.
Attr.Pfn,sP->
basePath()))
return 1;
215 Msg(
"Incorrect pfn xref to ", sP->
basePath());
216 Msg(
"Data file refers to ", pfnInfo.
Attr.Pfn);
218 if (rc) Emsg(-rc,
"get pfn xattr for ",sP->
basePath());
219 else {Msg(
"Missing pfn xref to ", sP->
basePath());
220 doWhat =
"Create pfn xref?"; dfltAns =
'y';
226 if (!Opt.Fix || rc < 0)
return 1;
229 if (Resp !=
'y')
return Resp !=
'a';
236 {Msg(
"pfn xref set."); numFix++;}
237 else Emsg(-rc,
"set pfn xref to ", sP->
basePath());
260 {
if (
unlink(sP-> pinPath())) Emsg(errno,
"remove pin file.");
264 {
if (
unlink(sP-> pfnPath())) Emsg(errno,
"remove pfn file.");
275 int XrdFrmAdmin::AuditSpace()
278 char buff[256], *
Path = 0, *Space = Opt.Args[1];
283 if (!(pP = ParseSpace(Space, &
Path)))
return 4;
287 numBytes = 0; numFiles = 0; numProb = 0; numFix = 0;
291 do {Act = (pP->val ? AuditSpaceXA(Space, pP->
text) : AuditSpaceAX(pP->text));
293 }
while(pP && !
Path && Act);
297 sprintf(buff,
"%d problem%s found; %d fixed.", numProb,
298 (numProb == 1 ?
"" :
"s"), numFix);
300 if (!Act) Msg(
"Audit space aborted!");
302 sprintf(buff,
"Space %s has %d file%s with %lld byte%s in use "
303 "(%lld unreachable).",
305 numFiles, (numFiles == 1 ?
"" :
"s"),
306 numBytes, (numBytes == 1 ?
"" :
"s"),
310 return (Act ? 0 : 4);
317 int XrdFrmAdmin::AuditSpaceAX(
const char *
Path)
328 if (!(nP = nsWalk.Index(
ec))) {
if (
ec) finalRC = 4;
return 1;}
335 ? AuditSpaceAXDC(buff, nP) : AuditSpaceAXDB(nP->
Path));
341 while(pP) {nP = pP; pP = pP->
Next;
delete nP;}
349 int XrdFrmAdmin::AuditSpaceAXDB(
const char *
Path)
355 Msg(
"Invalid name for data file ",
Path);
363 if (Resp !=
'y')
return Resp !=
'a';
378 char lkbuff[1032], *Dest = nP->
Path;
388 {
if (errno != ENOENT) {Emsg(errno,
"stat ",
Path);
return -1;}
389 Msg(
"Missing pfn data link ",
Path);
390 return AuditSpaceAXDL(0,
Path, Dest);
395 if ((buf.st_mode & S_IFMT) != S_IFLNK)
396 {Msg(
"Invalid pfn data link ",
Path);
397 return AuditSpaceAXDL(1,
Path, Dest);
402 if ((n = readlink(
Path, lkbuff,
sizeof(lkbuff)-1)) < 0)
403 {Emsg(errno,
"read link from ",
Path);
return -1;}
405 if (strcmp(Dest, lkbuff))
406 {Msg(
"Incorrect pfn data link ",
Path);
407 return AuditSpaceAXDL(1,
Path, Dest);
412 numProb--; numFiles++; numBytes += nP->
Stat.st_size;
420 int XrdFrmAdmin::AuditSpaceAXDL(
int dorm,
const char *
Path,
const char *Dest)
426 if (!Opt.Fix)
return -1;
432 if (Resp !=
'y')
return Resp !=
'a';
438 if (symlink(Dest,
Path))
439 {Emsg(errno,
"create symlink ",
Path);
return -1;}
440 Msg(
"pfn symlink created.");
449 int XrdFrmAdmin::AuditSpaceXA(
const char *Space,
const char *
Path)
463 while(Act && (sP = fP->
Get(
ec,1)))
464 {
if (!sP->
baseFile()) Act = AuditNameNB(sP);
466 if ((Act = AuditSpaceXA(sP)))
467 {
if (Act < 0) numFiles--;
489 char Resp = 0, tempPath[1032], lkbuff[1032], *Pfn = pfnInfo.
Attr.Pfn;
495 {Msg(
"Missing pfn xref for data file ", sP->
basePath());
504 if (errno != ENOENT) {Emsg(errno,
"stat ", Pfn);
return 1;}
505 Msg(
"Data file xrefs missing pfn ", Pfn);
507 {
if (Opt.Force) Resp =
'y';
511 {Msg(
"pfn symlink created."); numFix++;
return 1;}
512 Emsg(errno,
"create symlink ", Pfn);
521 if ((buf.st_mode & S_IFMT) != S_IFLNK)
523 Msg(
"Data file xrefs non-symlink pfn ", Pfn);
525 {
if (Opt.Force) Resp =
'n';
529 else {Msg(
"Data file removed."); numFix++;
return -1;}
538 if ((n = readlink(Pfn, lkbuff,
sizeof(lkbuff)-1)) < 0)
539 {Emsg(errno,
"read link from ", Pfn); numProb++;
return 1;}
541 if (!strcmp(sP->
basePath(), lkbuff))
return 1;
545 Msg(
"Inconsistent data file: ", sP->
basePath());
550 if (!
stat(lkbuff, &buf)) Plug =
"exists.";
551 else if (errno == ENOENT) Plug =
"is missing.";
552 else {Emsg(errno,
"stat ", lkbuff);
return 1;}
553 Msg(
"Data file xrefs pfn ", Pfn);
554 Msg(
"Pfn points to a different data file that ", Plug);
555 if (!Opt.Fix)
return 1;
561 {
if (Opt.Force) Resp =
'n';
565 else {Msg(
"Data file removed."); numFix++;
return -1;}
568 if (Opt.Force) Resp =
'n';
571 {*tempPath =
' '; strcpy(tempPath+1, Pfn);
unlink(tempPath);
573 {Emsg(errno,
"create symlink ", Pfn);
unlink(tempPath);}
574 else {Msg(
"pfn symlink changed."); numFix++;
return 1;}
588 int XrdFrmAdmin::AuditUsage()
596 if (Opt.Args[1])
return AuditUsage(Opt.Args[1]);
600 if (!vP) {Emsg(
"No outplace space has been configured.");
return -1;}
606 {strcpy(Sbuff, vP->
Name);
607 if (!(rc = AuditUsage(Sbuff)))
return 0;
608 if (rc < 0) retval = rc;
616 int XrdFrmAdmin::AuditUsage(
char *Space)
620 char Resp, buff[256], *
Path = 0;
621 long long theClaim, theDiff;
622 int haveUsage, Probs = 0;
626 if (!(pP = ParseSpace(Space, &
Path)))
return -1;
627 if (
Path) {Emsg(
"Path not allowed for audit usage.");
return -1;}
631 numBytes = 0; numFiles = 0; numProb = 0;
636 do {Probs |= (pP->val ? AuditUsageXA(pP->
text, Space)
637 : AuditUsageAX(pP->text));
643 sprintf(buff,
"Audit of %d file%s in %s space completed with %serrors.",
644 numFiles, (numFiles == 1 ?
"" :
"s"), Space,
645 (Probs ?
"" :
"no "));
657 sprintf(buff,
"%12lld", theClaim);
658 Msg(
"Claimed: ", buff);
659 }
else theClaim = numBytes;
663 sprintf(buff,
"%12lld", numBytes);
664 Msg(
"Actual: ", buff);
668 if (numBytes == theClaim || !Opt.Fix)
return 1;
670 {Emsg(0,
"No usage file present to fix!");
return -1;}
674 if (theClaim < numBytes) theDiff = numBytes - theClaim;
675 else theDiff = theClaim - numBytes;
680 {
if (theDiff < 500000) Sfx =
"byte";
681 {theDiff = (theDiff+512)/1024; Sfx =
"KB";}
682 sprintf(buff,
"Fix %lld %s difference?", theDiff, Sfx);
684 if (Resp !=
'y')
return Resp !=
'a';
697 int XrdFrmAdmin::AuditUsageAX(
const char *
Path)
707 if (!(nP = nsWalk.Index(
ec))) {
if (
ec) finalRC = 4;
return 1;}
712 {numBytes += nP->
Stat.st_size;
728 int XrdFrmAdmin::AuditUsageXA(
const char *
Path,
const char *Space)
742 while((sP = fP->
Get(
ec)))
763 if (!(nP->
Link))
return 0;
int stat(const char *path, struct stat *buf)
int lstat(const char *path, struct stat *buf)
int unlink(const char *path)
int rename(const char *oldpath, const char *newpath)
static char Ask(char dflt, const char *Msg1, const char *Msg2="", const char *Msg3="")
static int updtCpy(const char *Pfn, int Adj)
static const int NoAutoDel
static const int GetCpyTim
XrdFrmFileset * Get(int &rc, int noBase=0)
static const int Recursive
XrdOucXAttr< XrdFrcXAttrCpy > cpyInfo
XrdOucNSWalk::NSEnt * pfnFile()
XrdOucNSWalk::NSEnt * pinFile()
XrdOucNSWalk::NSEnt * baseFile()
XrdOucNSWalk::NSEnt * lockFile()
static char * genPFN(fnInfo &Info, char *buff, int blen, const char *Path=0)
static char * genPath(const char *inPath, const char *cgrp, char *sfx)
static long long Usage(int gent)
static void Adjust(int Gent, off_t Space, sType=Serv)
int Get(const char *Path, int fd=-1)
int Set(const char *Path, int fd=-1)