XrdCnsInventory.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                    X r d C n s I n v e n t o r y . c c                     */
00004 /*                                                                            */
00005 /* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010   
00011 //         $Id: XrdCnsInventory.cc 30949 2009-11-02 16:37:58Z ganis $
00012 
00013 const char *XrdCnsInventoryCVSID = "$Id: XrdCnsInventory.cc 30949 2009-11-02 16:37:58Z ganis $";
00014 
00015 #include "XrdCns/XrdCnsConfig.hh"
00016 #include "XrdCns/XrdCnsInventory.hh"
00017 #include "XrdOss/XrdOssPath.hh"
00018 #include "XrdSys/XrdSysError.hh"
00019 
00020 /******************************************************************************/
00021 /*                        G l o b a l   O b j e c t s                         */
00022 /******************************************************************************/
00023   
00024 namespace XrdCns
00025 {
00026 extern XrdSysError  MLog;
00027 
00028 extern XrdCnsConfig Config;
00029 }
00030 
00031 using namespace XrdCns;
00032 
00033 /******************************************************************************/
00034 /*                           C o n s t r u c t o r                            */
00035 /******************************************************************************/
00036 
00037 XrdCnsInventory::XrdCnsInventory()
00038                : dRec(XrdCnsLogRec::lrInvD),
00039                  fRec(XrdCnsLogRec::lrInvF),
00040                  mRec(XrdCnsLogRec::lrMount),
00041                  sRec(XrdCnsLogRec::lrSpace),
00042                  Mount(Config.LCLRoot ? Config.LCLRoot : "/",0),
00043                  Space("public",0), lfP(0)
00044 {
00045 // Do some initialization
00046 //
00047    dRec.setMode(0755);
00048    dRec.setSize(-1);
00049    mDflt = Mount.Default();
00050    sDflt = Space.Default();
00051 }
00052   
00053 /******************************************************************************/
00054 /*                               C o n d u c t                                */
00055 /******************************************************************************/
00056   
00057 int XrdCnsInventory::Conduct(const char *dPath)
00058 {
00059    static const int nsOpts = XrdOucNSWalk::Recurse | XrdOucNSWalk::retFile
00060                            | XrdOucNSWalk::retStat | XrdOucNSWalk::skpErrs
00061                            | XrdOucNSWalk::noPath  | XrdOucNSWalk::retLink;
00062    XrdOucNSWalk nsObj(&MLog, dPath, 0, nsOpts);
00063    XrdOucNSWalk::NSEnt *nP, *fP;
00064    int n, aOK = 1, rc;
00065 
00066 // Index all directories here
00067 //
00068    do {if (!(nP = nsObj.Index(rc, &cwdP))) return 1;
00069        if (!Config.LogicPath(cwdP, lfnBuff, sizeof(lfnBuff))) break;
00070        if ((n = strlen(lfnBuff)) && lfnBuff[n-1] == '/') lfnBuff[n-1] = '\0';
00071        dRec.setLfn1(lfnBuff);
00072        if (!(aOK = lfP->Add(&dRec, 0))) break;
00073        do {if (XrdOssPath::pathType(nP->Path) == XrdOssPath::isBase)
00074               {fRec.setMode(nP->Stat.st_mode);
00075                fRec.setSize(nP->Stat.st_size);
00076                fRec.setLfn1(nP->Path);
00077                if (!(aOK = Xref(nP) && lfP->Add(&fRec, 0))) break;
00078               }
00079             fP = nP; nP = nP->Next; delete fP;
00080           } while(nP);
00081       } while(aOK);
00082 
00083 // Determine how we ended
00084 //
00085    rc = (nP || rc ? 0 : 1);
00086 
00087 // Clean up and return
00088 //
00089    while((fP = nP)) {nP = nP->Next; delete fP;}
00090    return rc;
00091 }
00092 
00093 /******************************************************************************/
00094 /*                                  I n i t                                   */
00095 /******************************************************************************/
00096   
00097 int XrdCnsInventory::Init(XrdCnsLogFile *theLF)
00098 {
00099    XrdCnsLogRec tRec(XrdCnsLogRec::lrTOD);
00100 
00101 // Establish the log file we will be using
00102 //
00103    lfP = theLF;
00104 
00105 // Insert time stamp
00106 //
00107    lfP->Add(&tRec, 0);
00108 
00109 // Add default Mount record
00110 //
00111    mRec.setLfn1(Mount.Key(mDflt));
00112    mRec.setMount(mDflt);
00113    if (!(lfP->Add(&mRec, 0))) return 0;
00114 
00115 // Add default space record
00116 //
00117    sRec.setLfn1(Space.Key(sDflt));
00118    sRec.setSpace(sDflt);
00119    if (!(lfP->Add(&sRec, 0))) return 0;
00120 
00121 // All done
00122 //
00123    return 1;
00124 }
00125 
00126 /******************************************************************************/
00127 /* Private:                         X r e f                                   */
00128 /******************************************************************************/
00129   
00130 int XrdCnsInventory::Xref(XrdOucNSWalk::NSEnt *nP)
00131 {
00132    const char *cP;
00133    char pBuff[MAXPATHLEN+1], xCode;
00134    int n;
00135 
00136 // Add actual space information
00137 //
00138    if (nP->Link && (n = nP->Lksz))
00139       {cP = XrdOssPath::Extract(0, nP->Link, n);
00140        if (!(xCode = Mount.Find(nP->Link)))
00141           {xCode = Mount.Add(nP->Link); mRec.setMount(xCode);
00142            mRec.setLfn1(nP->Link);
00143            if (!(lfP->Add(&mRec, 0))) return 0;
00144           }
00145        fRec.setMount(xCode);
00146        if (!(xCode = Space.Find(cP)))
00147           {xCode = Space.Add(cP); sRec.setSpace(xCode);
00148            sRec.setLfn1(cP);
00149            if (!(lfP->Add(&sRec, 0))) return 0;
00150           }
00151         fRec.setSpace(xCode);
00152         return 1;
00153        }
00154 
00155 // Add constructed space information
00156 //
00157    if (!Config.MountPath(lfnBuff, pBuff, sizeof(pBuff))) xCode = mDflt;
00158       else if (!(xCode = Mount.Find(pBuff)))
00159               {xCode = Mount.Add(pBuff);
00160                mRec.setMount(xCode);
00161                mRec.setLfn1(pBuff);
00162                if (!(lfP->Add(&mRec, 0))) return 0;
00163               }
00164    fRec.setMount(xCode);
00165    fRec.setSpace(sDflt);
00166    return 1;
00167 }

Generated on Tue Jul 5 14:46:32 2011 for ROOT_528-00b_version by  doxygen 1.5.1