00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <fcntl.h>
00014 #include <stdio.h>
00015 #include <string.h>
00016 #include <strings.h>
00017 #include <sys/param.h>
00018 #include <sys/stat.h>
00019 #include <sys/types.h>
00020
00021 #include "XrdFrm/XrdFrmAdmin.hh"
00022 #include "XrdFrm/XrdFrmConfig.hh"
00023 #include "XrdFrm/XrdFrmFiles.hh"
00024 #include "XrdFrm/XrdFrmProxy.hh"
00025 #include "XrdFrm/XrdFrmRequest.hh"
00026 #include "XrdFrm/XrdFrmTrace.hh"
00027 #include "XrdFrm/XrdFrmUtils.hh"
00028 #include "XrdOss/XrdOssPath.hh"
00029 #include "XrdOss/XrdOssSpace.hh"
00030 #include "XrdOuc/XrdOucArgs.hh"
00031 #include "XrdOuc/XrdOucNSWalk.hh"
00032 #include "XrdOuc/XrdOucTList.hh"
00033
00034 const char *XrdFrmAdminQueryCVSID = "$Id: XrdFrmAdminQuery.cc 35287 2010-09-14 21:19:35Z ganis $";
00035
00036 using namespace XrdFrm;
00037
00038
00039
00040
00041
00042 int XrdFrmAdmin::QueryPfn(XrdOucArgs &Spec)
00043 {
00044 char *lfn, pfn[MAXPATHLEN];
00045
00046
00047
00048 if (!(lfn = Spec.getarg())) {Emsg("lfn not specified."); return 1;}
00049
00050
00051
00052 do {if (Config.LocalPath(lfn, pfn, sizeof(pfn))) Msg(pfn);
00053 else finalRC = 4;
00054 } while((lfn = Spec.getarg()));
00055 return 0;
00056 }
00057
00058
00059
00060
00061
00062 int XrdFrmAdmin::QueryRfn(XrdOucArgs &Spec)
00063 {
00064 char *lfn, rfn[MAXPATHLEN];
00065
00066
00067
00068 if (!(lfn = Spec.getarg())) {Emsg("lfn not specified."); return 1;}
00069
00070
00071
00072 do {if (Config.RemotePath(lfn, rfn, sizeof(rfn))) Msg(rfn);
00073 else finalRC = 4;
00074 } while((lfn = Spec.getarg()));
00075 return 0;
00076 }
00077
00078
00079
00080
00081
00082 int XrdFrmAdmin::QuerySpace(XrdOucArgs &Spec)
00083 {
00084 XrdFrmConfig::VPInfo *vP = Config.VPList;
00085 XrdFrmFileset *sP;
00086 XrdFrmFiles *fP;
00087 XrdOucTList *tP;
00088 struct stat Stat;
00089 char buff[2048], pfn[MAXPATHLEN], *lfn;
00090 int opts = 0, ec = 0;
00091
00092
00093
00094 if (!vP) {Emsg("No outplace space has been configured."); return 0;}
00095
00096
00097
00098 lfn = Spec.getarg();
00099
00100
00101
00102 if (!lfn)
00103 {while(vP)
00104 {tP = vP->Dir;
00105 while(tP)
00106 {sprintf(buff, "%s %s", vP->Name, tP->text);
00107 Msg(buff, (tP->val ? " xa" : 0));
00108 tP = tP->next;
00109 }
00110 vP = vP->Next;
00111 }
00112 return 0;
00113 }
00114
00115
00116
00117 if (!strncmp(lfn, "-recursive", strlen(lfn)))
00118 {opts = XrdFrmFiles::Recursive;
00119 if (!(lfn = Spec.getarg()))
00120 {Emsg("lfn not specified."); return 0;}
00121 }
00122
00123
00124
00125 do {Opt.All = VerifyAll(lfn);
00126 if (!Config.LocalPath(lfn, pfn, sizeof(pfn))) finalRC = 4;
00127 else if (stat(pfn, &Stat)) Emsg(errno, "query ", pfn);
00128 else if ((Stat.st_mode & S_IFMT) != S_IFDIR)
00129 {if (Opt.All) Emsg(ENOTDIR, "query ", lfn);
00130 else QuerySpace(pfn);
00131 }
00132 else{fP = new XrdFrmFiles(pfn, opts);
00133 while((sP = fP->Get(ec,1)))
00134 {if (sP->baseFile())
00135 QuerySpace(sP->basePath(),
00136 sP->baseFile()->Link,
00137 sP->baseFile()->Lksz);
00138 }
00139 if (ec) finalRC = 4;
00140 delete fP;
00141 }
00142 } while((lfn = Spec.getarg()));
00143
00144
00145
00146 return 0;
00147 }
00148
00149
00150
00151 int XrdFrmAdmin::QuerySpace(const char *Pfn, char *Lnk, int Lsz)
00152 {
00153 char SName[XrdOssSpace::minSNbsz];
00154
00155
00156
00157 XrdOssPath::getCname(Pfn, SName, Lnk, Lsz);
00158 Msg(SName, " ", Pfn);
00159 return 0;
00160 }
00161
00162
00163
00164
00165
00166 int XrdFrmAdmin::QueryUsage(XrdOucArgs &Spec)
00167 {
00168 XrdOssSpace::uEnt myUsage;
00169 XrdFrmConfig::VPInfo myVP((char *)""), *vP = Config.VPList;
00170 long long Actual;
00171 char buff[4096];
00172
00173
00174
00175 if (!(XrdOssSpace::Init() & XrdOssSpace::haveUsage))
00176 {Emsg("Usage is not being tracked."); return 0;}
00177
00178
00179
00180 if ((myVP.Name = Spec.getarg())) {myVP.Next = 0; vP = &myVP;}
00181 else if (!vP) {Emsg("No outplace space has been configured."); return 0;}
00182
00183
00184
00185 do {if (XrdOssSpace::Usage(vP->Name, myUsage, 1) < 0)
00186 Emsg("Space ", vP->Name, " not found.");
00187 else
00188 {Actual = myUsage.Bytes[XrdOssSpace::Serv]
00189 + myUsage.Bytes[XrdOssSpace::Pstg]
00190 - myUsage.Bytes[XrdOssSpace::Purg]
00191 + myUsage.Bytes[XrdOssSpace::Admin];
00192 sprintf(buff,"Space %s\n%20lld Used\n%20lld Staged\n"
00193 "%20lld Purged\n%20lld Adjust\n%20lld Effective",
00194 vP->Name, myUsage.Bytes[XrdOssSpace::Serv],
00195 myUsage.Bytes[XrdOssSpace::Pstg],
00196 myUsage.Bytes[XrdOssSpace::Purg],
00197 myUsage.Bytes[XrdOssSpace::Admin], Actual);
00198 Msg(buff);
00199 }
00200 } while((vP = vP->Next));
00201 return 0;
00202 }
00203
00204
00205
00206
00207
00208 int XrdFrmAdmin::QueryXfrQ(XrdOucArgs &Spec)
00209 {
00210 static struct {const char *qName; char qType;} qN2T[] =
00211 {{"all", XrdFrmProxy::opAll},
00212 {"get", XrdFrmProxy::opGet},
00213 {"migr", XrdFrmProxy::opMig},
00214 {"put", XrdFrmProxy::opPut},
00215 {"migrate",XrdFrmProxy::opMig},
00216 {"stage", XrdFrmProxy::opStg},
00217 {0, 0}};
00218
00219 XrdFrmRequest::Item Items[XrdFrmRequest::getLast];
00220 XrdFrmProxy::Queues xfrQ(0);
00221 char *qName;
00222 int i, qPrty, QList = 0;
00223
00224
00225
00226 if (!frmProxy && !frmProxz) ConfigProxy();
00227
00228
00229
00230 while((qName = Spec.getarg()))
00231 {i = 0;
00232 while(qN2T[i].qName && strcmp(qN2T[i].qName, qName)) i++;
00233 if (qN2T[i].qName) QList |= qN2T[i].qType;
00234 else break;
00235 }
00236
00237
00238
00239 if (!QList) QList = XrdFrmProxy::opAll;
00240
00241
00242
00243 if (qName && strlen(qName) == 1 && *qName >= '0' && *qName <= '9')
00244 {qPrty = *qName - '0';
00245 if (qPrty > XrdFrmRequest::maxPrty)
00246 {Emsg("Invalid xfrq priority - ", qName); return 1;}
00247 qName = Spec.getarg();
00248 } else qPrty = -1;
00249
00250
00251
00252 i = 0;
00253 if (qName)
00254 {do {if (XrdFrmUtils::MapV2I(qName, Items[i])) i++;
00255 else {Emsg("Invalid xfrq variable - ", qName); return 1;}
00256 } while((qName = Spec.getarg()) && i < XrdFrmRequest::getLast);
00257 if (qName) {Emsg("Too many xfrq variables starting at ",qName);return 1;}
00258 } else Items[i++] = XrdFrmRequest::getLFN;
00259
00260
00261
00262 if (!frmProxy) {Emsg("Unable to list the xfrq."); return 1;}
00263 if (!frmProxy->List(QList, qPrty, Items, i)) Msg("No entries found.");
00264 return 0;
00265 }