XRootD
XrdFrmAdminQuery.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d A d m i n Q u e r y . 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 <fcntl.h>
32 #include <cstdio>
33 #include <cstring>
34 #include <strings.h>
35 #include <sys/param.h>
36 #include <sys/stat.h>
37 #include <sys/types.h>
38 
39 #include "XrdFrc/XrdFrcProxy.hh"
40 #include "XrdFrc/XrdFrcRequest.hh"
41 #include "XrdFrc/XrdFrcTrace.hh"
42 #include "XrdFrc/XrdFrcUtils.hh"
43 #include "XrdFrm/XrdFrmAdmin.hh"
44 #include "XrdFrm/XrdFrmConfig.hh"
45 #include "XrdFrm/XrdFrmFiles.hh"
46 #include "XrdOss/XrdOssPath.hh"
47 #include "XrdOss/XrdOssSpace.hh"
48 #include "XrdOuc/XrdOucArgs.hh"
49 #include "XrdOuc/XrdOucNSWalk.hh"
50 #include "XrdOuc/XrdOucTList.hh"
51 
52 using namespace XrdFrc;
53 using namespace XrdFrm;
54 
55 /******************************************************************************/
56 /* Q u e r y P f n */
57 /******************************************************************************/
58 
59 int XrdFrmAdmin::QueryPfn(XrdOucArgs &Spec)
60 {
61  char *lfn, pfn[MAXPATHLEN];
62 
63 // Get the first lfn
64 //
65  if (!(lfn = Spec.getarg())) {Emsg("lfn not specified."); return 1;}
66 
67 // Process all of the files
68 //
69  do {if (Config.LocalPath(lfn, pfn, sizeof(pfn))) Msg(pfn);
70  else finalRC = 4;
71  } while((lfn = Spec.getarg()));
72  return 0;
73 }
74 
75 /******************************************************************************/
76 /* Q u e r y R f n */
77 /******************************************************************************/
78 
79 int XrdFrmAdmin::QueryRfn(XrdOucArgs &Spec)
80 {
81  char *lfn, rfn[MAXPATHLEN];
82 
83 // Get the first lfn
84 //
85  if (!(lfn = Spec.getarg())) {Emsg("lfn not specified."); return 1;}
86 
87 // Process all of the files
88 //
89  do {if (Config.RemotePath(lfn, rfn, sizeof(rfn))) Msg(rfn);
90  else finalRC = 4;
91  } while((lfn = Spec.getarg()));
92  return 0;
93 }
94 
95 /******************************************************************************/
96 /* Q u e r y S p a c e */
97 /******************************************************************************/
98 
99 int XrdFrmAdmin::QuerySpace(XrdOucArgs &Spec)
100 {
101  XrdFrmConfig::VPInfo *vP = Config.VPList;
102  XrdFrmFileset *sP;
103  XrdFrmFiles *fP;
104  XrdOucTList *tP;
105  struct stat Stat;
106  char buff[2048], pfn[MAXPATHLEN], *lfn;
107  int opts = 0, ec = 0;
108 
109 // If no cache configured say so
110 //
111  if (!vP) {Emsg("No outplace space has been configured."); return 0;}
112 
113 // Get the first lfn (optional)
114 //
115  lfn = Spec.getarg();
116 
117 // List the cache we have if no lfn exists
118 //
119  if (!lfn)
120  {while(vP)
121  {tP = vP->Dir;
122  while(tP)
123  {sprintf(buff, "%s %s", vP->Name, tP->text);
124  Msg(buff, (tP->val ? " xa" : 0));
125  tP = tP->next;
126  }
127  vP = vP->Next;
128  }
129  return 0;
130  }
131 
132 // Check if this is '-recursive'
133 //
134  if (!strncmp(lfn, "-recursive", strlen(lfn)))
136  if (!(lfn = Spec.getarg()))
137  {Emsg("lfn not specified."); return 0;}
138  }
139 
140 // Here we display thespace name of each lfn
141 //
142  do {Opt.All = VerifyAll(lfn);
143  if (!Config.LocalPath(lfn, pfn, sizeof(pfn))) finalRC = 4;
144  else if (stat(pfn, &Stat)) Emsg(errno, "query ", pfn);
145  else if ((Stat.st_mode & S_IFMT) != S_IFDIR)
146  {if (Opt.All) Emsg(ENOTDIR, "query ", lfn);
147  else QuerySpace(pfn);
148  }
149  else{fP = new XrdFrmFiles(pfn, opts | XrdFrmFiles::NoAutoDel);
150  while((sP = fP->Get(ec,1)))
151  {if (sP->baseFile())
152  QuerySpace(sP->basePath(),
153  sP->baseFile()->Link,
154  sP->baseFile()->Lksz);
155  delete sP;
156  }
157  if (ec) finalRC = 4;
158  delete fP;
159  }
160  } while((lfn = Spec.getarg()));
161 
162 // All done
163 //
164  return 0;
165 }
166 
167 /******************************************************************************/
168 
169 int XrdFrmAdmin::QuerySpace(const char *Pfn, char *Lnk, int Lsz)
170 {
171  char SName[XrdOssSpace::minSNbsz];
172 
173 // Get the space name
174 //
175  XrdOssPath::getCname(Pfn, SName, Lnk, Lsz);
176  Msg(SName, " ", Pfn);
177  return 0;
178 }
179 
180 /******************************************************************************/
181 /* Q u e r y U s a g e */
182 /******************************************************************************/
183 
184 int XrdFrmAdmin::QueryUsage(XrdOucArgs &Spec)
185 {
186  XrdOssSpace::uEnt myUsage;
187  XrdFrmConfig::VPInfo myVP((char *)""), *vP = Config.VPList;
188  long long Actual;
189  char buff[4096];
190 
191 // Check if usage has been configured
192 //
194  {Emsg("Usage is not being tracked."); return 0;}
195 
196 // Get the optional space name
197 //
198  if ((myVP.Name = Spec.getarg())) {myVP.Next = 0; vP = &myVP;}
199  else if (!vP) {Emsg("No outplace space has been configured."); return 0;}
200 
201 // Process all of the files
202 //
203  do {if (XrdOssSpace::Usage(vP->Name, myUsage, 1) < 0)
204  Emsg("Space ", vP->Name, " not found.");
205  else
206  {Actual = myUsage.Bytes[XrdOssSpace::Serv]
207  + myUsage.Bytes[XrdOssSpace::Pstg]
208  - myUsage.Bytes[XrdOssSpace::Purg]
209  + myUsage.Bytes[XrdOssSpace::Admin];
210  sprintf(buff,"Space %s\n%20lld Used\n%20lld Staged\n"
211  "%20lld Purged\n%20lld Adjust\n%20lld Effective",
212  vP->Name, myUsage.Bytes[XrdOssSpace::Serv],
213  myUsage.Bytes[XrdOssSpace::Pstg],
214  myUsage.Bytes[XrdOssSpace::Purg],
215  myUsage.Bytes[XrdOssSpace::Admin], Actual);
216  Msg(buff);
217  }
218  } while((vP = vP->Next));
219  return 0;
220 }
221 
222 /******************************************************************************/
223 /* Q u e r y X f r Q */
224 /******************************************************************************/
225 
226 int XrdFrmAdmin::QueryXfrQ(XrdOucArgs &Spec)
227 {
228  static struct {const char *qName; char qType;} qN2T[] =
229  {{"all", XrdFrcProxy::opAll},
230  {"get", XrdFrcProxy::opGet},
231  {"migr", XrdFrcProxy::opMig},
232  {"put", XrdFrcProxy::opPut},
233  {"migrate",XrdFrcProxy::opMig},
234  {"stage", XrdFrcProxy::opStg},
235  {0, 0}};
236 
238  XrdFrcProxy::Queues xfrQ(0);
239  char *qName;
240  int i, qPrty, QList = 0;
241 
242 // Check for proxy initialization
243 //
244  if (!frmProxy && !frmProxz) ConfigProxy();
245 
246 // Get the first q-type
247 //
248  while((qName = Spec.getarg()))
249  {i = 0;
250  while(qN2T[i].qName && strcmp(qN2T[i].qName, qName)) i++;
251  if (qN2T[i].qName) QList |= qN2T[i].qType;
252  else break;
253  }
254 
255 // Set queue if none specified
256 //
257  if (!QList) QList = XrdFrcProxy::opAll;
258 
259 // Check if priority
260 //
261  if (qName && strlen(qName) == 1 && *qName >= '0' && *qName <= '9')
262  {qPrty = *qName - '0';
263  if (qPrty > XrdFrcRequest::maxPrty)
264  {Emsg("Invalid xfrq priority - ", qName); return 1;}
265  qName = Spec.getarg();
266  } else qPrty = -1;
267 
268 // Process variable is we have an unmatched name
269 //
270  i = 0;
271  if (qName)
272  {do {if (XrdFrcUtils::MapV2I(qName, Items[i])) i++;
273  else {Emsg("Invalid xfrq variable - ", qName); return 1;}
274  } while((qName = Spec.getarg()) && i < XrdFrcRequest::getLast);
275  if (qName) {Emsg("Too many xfrq variables starting at ",qName);return 1;}
276  } else Items[i++] = XrdFrcRequest::getLFN;
277 
278 // Produce the listing
279 //
280  if (!frmProxy) {Emsg("Unable to list the xfrq."); return 1;}
281  if (!frmProxy->List(QList, qPrty, Items, i)) Msg("No entries found.");
282  return 0;
283 }
struct stat Stat
Definition: XrdCks.cc:49
int stat(const char *path, struct stat *buf)
struct myOpts opts
static const int opPut
Definition: XrdFrcProxy.hh:50
static const int opGet
Definition: XrdFrcProxy.hh:49
static const int opMig
Definition: XrdFrcProxy.hh:51
static const int opStg
Definition: XrdFrcProxy.hh:52
static const int opAll
Definition: XrdFrcProxy.hh:53
static const int maxPrty
static int MapV2I(const char *Opc, XrdFrcRequest::Item &ICode)
Definition: XrdFrcUtils.cc:211
static const int NoAutoDel
Definition: XrdFrmFiles.hh:123
XrdFrmFileset * Get(int &rc, int noBase=0)
Definition: XrdFrmFiles.cc:340
static const int Recursive
Definition: XrdFrmFiles.hh:121
XrdOucNSWalk::NSEnt * baseFile()
Definition: XrdFrmFiles.hh:60
const char * basePath()
Definition: XrdFrmFiles.hh:61
static int getCname(const char *path, char *Cache, char *lbuf=0, int lbsz=0)
Definition: XrdOssPath.cc:241
static long long Usage(int gent)
Definition: XrdOssSpace.cc:521
static int Init()
Definition: XrdOssSpace.cc:224
static const int minSNbsz
Definition: XrdOssSpace.hh:45
long long Bytes[Totn]
Definition: XrdOssSpace.hh:65
static const int haveUsage
Definition: XrdOssSpace.hh:51
char * getarg()
Definition: XrdOucArgs.cc:136
XrdOucTList * next
Definition: XrdOucTList.hh:45
char * text
Definition: XrdOucTList.hh:46
XrdCmsConfig Config