XRootD
Loading...
Searching...
No Matches
XrdFrmAdminFind.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d A d m i n F i n d . c c */
4/* */
5/* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31#include <cstdio>
32#include <cstring>
33#include <strings.h>
34#include <ctime>
35#include <sys/param.h>
36
38#include "XrdFrc/XrdFrcTrace.hh"
39#include "XrdFrm/XrdFrmAdmin.hh"
41#include "XrdFrm/XrdFrmFiles.hh"
42#include "XrdOuc/XrdOucArgs.hh"
44
45using namespace XrdFrc;
46using namespace XrdFrm;
47
48/******************************************************************************/
49/* F i n d F a i l */
50/******************************************************************************/
51
52int XrdFrmAdmin::FindFail(XrdOucArgs &Spec)
53{
54 XrdOucNSWalk::NSEnt *nP, *fP;
55 XrdOucNSWalk *nsP;
56 char pDir[MAXPATHLEN], *dotP, *dirFN, *lDir = Opt.Args[1];
57 char *dirP = pDir + Config.xfrFdln;
58 int dirL = sizeof(pDir) - Config.xfrFdln;
59 int opts = XrdOucNSWalk::retFile | (Opt.Recurse ? XrdOucNSWalk::Recurse : 0);
60 int ec, rc = 0, num = 0;
61
62// Check if fail files are being relocated
63//
64 if (Config.xfrFdir) strcpy(pDir, Config.xfrFdir);
65
66// Process each directory
67//
68 do {if (!Config.LocalPath(lDir, dirP, dirL)) continue;
69 nsP = new XrdOucNSWalk(&Say, pDir, 0, opts);
70 while((nP = nsP->Index(ec)) || ec)
71 {while((fP = nP))
72 {if ((dotP = rindex(fP->File,'.')) && !strcmp(dotP,".fail"))
73 {Msg(fP->Path); num++;}
74 nP = fP->Next; delete fP;
75 }
76 if (ec) rc = 4;
77 }
78 delete nsP;
79 } while((dirFN = Spec.getarg()));
80
81// All done
82//
83 sprintf(pDir, "%d fail file%s found.", num, (num == 1 ? "" : "s"));
84 Msg(pDir);
85 return rc;
86}
87
88/******************************************************************************/
89/* F i n d M m a p */
90/******************************************************************************/
91
92int XrdFrmAdmin::FindMmap(XrdOucArgs &Spec)
93{
94 XrdOucXAttr<XrdFrcXAttrMem> memInfo;
95 XrdFrmFileset *sP;
96 XrdFrmFiles *fP;
97 char buff[128], pDir[MAXPATHLEN], *lDir = Opt.Args[1];
98 int opts = (Opt.Recurse ? XrdFrmFiles::Recursive : 0);
99 int mFlag, ec = 0, rc = 0, num = 0;
100
101// Process each directory
102//
103 do {if (!Config.LocalPath(lDir, pDir, sizeof(pDir))) continue;
104 fP = new XrdFrmFiles(pDir, opts | XrdFrmFiles::NoAutoDel);
105 while((sP = fP->Get(ec)))
106 {if (memInfo.Get(sP->basePath()) >= 0
107 && (mFlag = memInfo.Attr.Flags))
108 {const char *Kp = (mFlag&XrdFrcXAttrMem::memKeep ? "-keep ":0);
109 const char *Lk = (mFlag&XrdFrcXAttrMem::memLock ? "-lock ":0);
110 Msg("mmap ", Kp, Lk, sP->basePath()); num++;
111 }
112 delete sP;
113 }
114 if (ec) rc = 4;
115 delete fP;
116 } while((lDir = Spec.getarg()));
117
118// All done
119//
120 sprintf(buff,"%d mmapped file%s found.",num,(num == 1 ? "" : "s"));
121 Msg(buff);
122 return rc;
123}
124
125/******************************************************************************/
126/* F i n d N o c s */
127/******************************************************************************/
128
129int XrdFrmAdmin::FindNocs(XrdOucArgs &Spec)
130{
131 XrdFrmFileset *sP;
132 XrdFrmFiles *fP;
133 char buff[128], pDir[MAXPATHLEN], *lDir = Opt.Args[1];
134 int opts = (Opt.Recurse ? XrdFrmFiles::Recursive : 0);
135 int ec = 0, rc = 0, num = 0;
136
137// Check if this is even supported
138//
139 if (!Config.CksMan)
140 {Emsg("Checksum support has not been configured!"); return 8;}
141
142
143// First get the checksum type
144//
145 if (!(CksData.Length = Config.CksMan->Size(Opt.Args[1]))
146 || !CksData.Set(Opt.Args[1]))
147 {Emsg(Opt.Args[1], " checksum is not supported."); return 4;}
148
149// Now get the actual target
150//
151 if (!(lDir = Spec.getarg()))
152 {Emsg("Find target not specified."); return 4;}
153
154// Process each directory
155//
156 do {if (!Config.LocalPath(lDir, pDir, sizeof(pDir))) continue;
157 fP = new XrdFrmFiles(pDir, opts | XrdFrmFiles::NoAutoDel);
158 while((sP = fP->Get(ec)))
159 {if ((rc = Config.CksMan->Get(sP->basePath(), CksData)) <= 0)
160 {num++;
161 Msg((rc == -ESTALE ? "Invalid " : "Missing "), CksData.Name,
162 " ",sP->basePath());
163 }
164 delete sP;
165 }
166 if (ec) rc = 4;
167 delete fP;
168 } while((lDir = Spec.getarg()));
169
170// All done
171//
172 sprintf(buff,"%d file%s found with no chksum.",num,(num == 1 ? "" : "s"));
173 Msg(buff);
174 return rc;
175}
176
177/******************************************************************************/
178/* F i n d P i n s */
179/******************************************************************************/
180
181int XrdFrmAdmin::FindPins(XrdOucArgs &Spec)
182{
183 XrdFrmFileset *sP;
184 XrdFrmFiles *fP;
185 char buff[128], pDir[MAXPATHLEN], *lDir = Opt.Args[1];
186 int opts = (Opt.Recurse ? XrdFrmFiles::Recursive : 0);
187 int ec = 0, rc = 0, num = 0;
188
189// Process each directory
190//
191 do {if (!Config.LocalPath(lDir, pDir, sizeof(pDir))) continue;
192 fP = new XrdFrmFiles(pDir, opts | XrdFrmFiles::NoAutoDel);
193 while((sP = fP->Get(ec)))
194 {if (sP->pinInfo.Get(sP->basePath()) >= 0 && FindPins(sP)) num++;
195 delete sP;
196 }
197 if (ec) rc = 4;
198 delete fP;
199 } while((lDir = Spec.getarg()));
200
201// All done
202//
203 sprintf(buff,"%d pinned file%s found.",num,(num == 1 ? "" : "s"));
204 Msg(buff);
205 return rc;
206}
207
208/******************************************************************************/
209
210int XrdFrmAdmin::FindPins(XrdFrmFileset *sP)
211{
212 static const int Week = 7*24*60*60;
213 time_t pinVal;
214 const char *Pfx = "+";
215 char How[256], Scale;
216 int pinFlag;
217
218// If no pif flags are set then no pin value exists
219//
220 if (!(pinFlag = sP->pinInfo.Attr.Flags)) return 0;
221
222// If it's pinned forever, we can blither the message right away
223//
224 if (pinFlag & XrdFrcXAttrPin::pinPerm)
225 {Msg("pin -k forever ", sP->basePath()); return 1;}
226
227// Be optimistic and get the pin time value
228//
229 pinVal = static_cast<time_t>(sP->pinInfo.Attr.pinTime);
230 *How = 0;
231
232// If it's a keep then decide how to format it. If the keep has been exceeed
233// then just delete the attribute, since it isn't pinned anymore.
234//
235 if (pinFlag & XrdFrcXAttrPin::pinKeep)
236 {time_t nowT = time(0);
237 if (pinVal <= nowT) {sP->pinInfo.Del(sP->basePath()); return 0;}
238 if ((pinVal - nowT) <= Week)
239 {pinFlag = XrdFrcXAttrPin::pinIdle;
240 pinVal = pinVal - nowT;
241 Pfx = "";
242 } else {
243 struct tm *lclTime = localtime(&pinVal);
244 sprintf(How, "-k %02d/%02d/%04d", lclTime->tm_mon+1,
245 lclTime->tm_mday, lclTime->tm_year+1900);
246 }
247 }
248
249// Check for idle pin or convert keep pin to suedo-idle formatting
250//
251 if (pinFlag & XrdFrcXAttrPin::pinIdle)
252 { if ( pinVal <= 180) Scale = 's';
253 else if ((pinVal /= 60) <= 90) Scale = 'm';
254 else if ((pinVal /= 60) <= 45) Scale = 'h';
255 else { pinVal /= 24; Scale = 'd';}
256 sprintf(How, "-k %s%d%c", Pfx, static_cast<int>(pinVal), Scale);
257 } else if (!*How) return 0;
258
259// Print the result
260//
261 Msg("pin ", How, " ", sP->basePath());
262 return 1;
263}
264
265/******************************************************************************/
266/* F i n d U n m i */
267/******************************************************************************/
268
269int XrdFrmAdmin::FindUnmi(XrdOucArgs &Spec)
270{
271 static const char *noCPT = "Unmigrated; no copy time: ";
272 XrdFrmFileset *sP;
273 XrdFrmFiles *fP;
274 const char *Why;
275 char buff[128], pDir[MAXPATHLEN], *lDir = Opt.Args[1];
276 int opts = (Opt.Recurse ? XrdFrmFiles::Recursive : 0)|XrdFrmFiles::GetCpyTim;
277 int ec = 0, rc = 0, num = 0;
278
279// Process each directory
280//
281 do {if (!Config.LocalPath(lDir, pDir, sizeof(pDir))) continue;
282 fP = new XrdFrmFiles(pDir, opts | XrdFrmFiles::NoAutoDel);
283 while((sP = fP->Get(ec)))
284 { if (!(sP->cpyInfo.Attr.cpyTime))
285 Why = noCPT;
286 else if (static_cast<long long>(sP->baseFile()->Stat.st_mtime) >
287 sP->cpyInfo.Attr.cpyTime)
288 Why="Unmigrated; modified: ";
289 else Why = 0;
290 if (Why) {Msg(Why, sP->basePath()); num++;}
291 delete sP;
292 }
293 if (ec) rc = 4;
294 delete fP;
295 } while((lDir = Spec.getarg()));
296
297// All done
298//
299 sprintf(buff,"%d unmigrated file%s found.",num,(num == 1 ? "" : "s"));
300 Msg(buff);
301 return rc;
302}
XrdOucPup XrdCmsParser::Pup & Say
struct myOpts opts
virtual int Get(const char *Xfn, XrdCksData &Cks)=0
virtual int Size(const char *Name=0)=0
long long cpyTime
static const char memKeep
static const char memLock
static const char pinKeep
static const char pinPerm
static const char pinIdle
long long pinTime
XrdCks * CksMan
int LocalPath(const char *oldp, char *newp, int newpsz)
static const int NoAutoDel
static const int GetCpyTim
XrdFrmFileset * Get(int &rc, int noBase=0)
static const int Recursive
const char * basePath()
XrdOucNSWalk::NSEnt * baseFile()
XrdOucXAttr< XrdFrcXAttrCpy > cpyInfo
XrdOucXAttr< XrdFrcXAttrPin > pinInfo
char * getarg()
static const int retFile
static const int Recurse
int Get(const char *Path, int fd=-1)
int Del(const char *Path, int fd=-1)
XrdFrmConfig Config