XrdCnsLogRec.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                       X r d C n s L o g R e c . 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: XrdCnsLogRec.cc 35287 2010-09-14 21:19:35Z ganis $
00012 
00013 const char *XrdCnsLogRecCVSID = "$Id: XrdCnsLogRec.cc 35287 2010-09-14 21:19:35Z ganis $";
00014 
00015 #include <stdlib.h>
00016 #include <stdio.h>
00017 #include <string.h>
00018 #include <sys/types.h>
00019 #include <time.h>
00020 
00021 #include "XrdCns/XrdCnsLogRec.hh"
00022 #include "XrdSys/XrdSysTimer.hh"
00023  
00024 /******************************************************************************/
00025 /*                               G l o b a l s                                */
00026 /******************************************************************************/
00027   
00028 extern XrdSysError                  XrdLog;
00029 
00030 XrdSysMutex            XrdCnsLogRec::fMutex;
00031 XrdCnsLogRec          *XrdCnsLogRec::freeRec = 0;
00032 
00033 XrdSysSemaphore        XrdCnsLogRec::qSem(0);
00034 XrdSysMutex            XrdCnsLogRec::qMutex;
00035 XrdCnsLogRec          *XrdCnsLogRec::frstRec = 0;
00036 XrdCnsLogRec          *XrdCnsLogRec::lastRec = 0;
00037 
00038 int                    XrdCnsLogRec::Running = 0;
00039 
00040 const char            *XrdCnsLogRec::IArg = "I755          -1        ";
00041 const char            *XrdCnsLogRec::iArg = "i644           0        ";
00042 
00043 /******************************************************************************/
00044 /*                                  A l l o c                                  */
00045 /******************************************************************************/
00046   
00047 XrdCnsLogRec *XrdCnsLogRec::Alloc()
00048 {
00049    XrdCnsLogRec *rP;
00050 
00051 // Allocate a request object. Develop a serial sequence if init wanted
00052 //
00053    fMutex.Lock();
00054    if ((rP = freeRec)) freeRec = rP->Next;
00055       else rP = new XrdCnsLogRec();
00056    fMutex.UnLock();
00057 
00058 // Pre-initialize the record
00059 //
00060    rP->Next = 0;
00061    memset(&rP->Rec.Hdr, 0, sizeof(struct Ctl));
00062    memset(&rP->Rec.Data, ' ', FixDLen);
00063    rP->Rec.Data.Mode[2]  = '0';
00064    rP->Rec.Data.SorT[11] = '0';
00065    rP->Rec.Data.Type = '?';
00066    return rP;
00067 }
00068 
00069 /******************************************************************************/
00070 /*                                   G e t                                    */
00071 /******************************************************************************/
00072   
00073 XrdCnsLogRec *XrdCnsLogRec::Get(char &lrType)
00074 {
00075    XrdCnsLogRec *lrP;
00076 
00077 // Find the request in the slot table
00078 //
00079    qMutex.Lock();
00080    while(!(lrP = frstRec))
00081         {Running = 0;
00082          qMutex.UnLock();
00083          qSem.Wait();
00084          qMutex.Lock();
00085         }
00086    if (!(frstRec = lrP->Next)) lastRec = 0;
00087    qMutex.UnLock();
00088 
00089 // Get the type and if its an eol marker recycle now
00090 //
00091    if (!(lrType = lrP->Rec.Data.Type)) {lrP->Recycle(); lrP = 0;}
00092    return lrP;
00093 }
00094 
00095 
00096 /******************************************************************************/
00097 /*                                 Q u e u e                                  */
00098 /******************************************************************************/
00099   
00100 void XrdCnsLogRec::Queue()
00101 {
00102 
00103 // Put request on the queue
00104 //
00105    qMutex.Lock();
00106    if (frstRec) lastRec->Next = this;
00107       else      frstRec       = this;
00108    lastRec = this;
00109 
00110 // Tell dequeue thread we have something if it's not already running
00111 //
00112    if (!Running) {qSem.Post(); Running = 1;}
00113    qMutex.UnLock();
00114 }
00115 
00116 /******************************************************************************/
00117 /*                               R e c y c l e                                */
00118 /******************************************************************************/
00119   
00120 void XrdCnsLogRec::Recycle()
00121 {
00122 
00123 // Put this object on the free queue
00124 //
00125    fMutex.Lock();
00126    Next = freeRec;
00127    freeRec = this;
00128    fMutex.UnLock();
00129 }
00130 
00131 /******************************************************************************/
00132 /*                               s e t D a t a                                */
00133 /******************************************************************************/
00134 
00135 int XrdCnsLogRec::setData(const char *dP1, const char *dP2)
00136 {
00137   int n1 = strlen(dP1), n2 = strlen(dP2);
00138   char *dP;
00139 
00140 // Make sure we have room "'lfn' + 'data1' + ' ' + data2"
00141 //
00142    if (n1+n2+2 > MAXPATHLEN) return 0;
00143 
00144 // Add the data in the fields
00145 //
00146    setSize(static_cast<long long>(Rec.Hdr.lfn1Len));
00147    dP = Rec.Data.lfn + Rec.Hdr.lfn1Len+1;
00148    strcpy(dP, dP1);
00149    dP += n1; *dP++ = ' ';
00150    strcpy(dP, dP2);
00151    Rec.Hdr.lfn2Len = n1+n2+1;
00152    return Rec.Hdr.lfn2Len;
00153 }
00154   
00155 /******************************************************************************/
00156 /*                               s e t T y p e                                */
00157 /******************************************************************************/
00158 
00159 int XrdCnsLogRec::setType(const char *lrName)
00160 {
00161         if (!strcmp(lrName, "closew")) setType(lrClosew);
00162    else if (!strcmp(lrName, "create")) setType(lrCreate);
00163    else if (!strcmp(lrName, "mkdir"))  setType(lrMkdir);
00164    else if (!strcmp(lrName, "mv"))     setType(lrMv);
00165    else if (!strcmp(lrName, "rm"))     setType(lrRm);
00166    else if (!strcmp(lrName, "rmdir"))  setType(lrRmdir);
00167    else return 0;
00168 
00169    return 1;
00170 }

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