|
xrootd
|
00001 #ifndef __XRDCnsLogRec_H_ 00002 #define __XRDCnsLogRec_H_ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C n s L o g R e c . h h */ 00006 /* */ 00007 /* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <stddef.h> 00034 #include <stdio.h> 00035 #include <string.h> 00036 #include <time.h> 00037 #include <sys/param.h> 00038 #include <sys/types.h> 00039 00040 #include "XrdSys/XrdSysPlatform.hh" 00041 #include "XrdSys/XrdSysPthread.hh" 00042 00043 class XrdCnsLogRec 00044 { 00045 public: 00046 00047 static const int maxClients = 4; 00048 00049 struct Ctl 00050 {short dataLen; // Length of data in Arg (eof when 0) 00051 short lfn1Len; // strlen(lfn1) 00052 short lfn2Len; // strlen(lfn2) 00053 short Mode; // File mode (create and mkdir) 00054 char Done[maxClients]; // 1->Record processed 00055 int Rsvd; // Reserved field 00056 long long Size; // Valid when Closew 00057 }; 00058 00059 struct Arg 00060 {char Type; // Event code 00061 char Mode[3]; // Mode (create, inv, mkdir) 00062 char SorT[12]; // Size (closew, inv) | TOD (eol) 00063 char Mount; // Mount Index 00064 char Space; // Space Index 00065 char Rsvd[6]; // Reserved (blank filled) 00066 char lfn[MAXPATHLEN*2+3]; // lfn1 [lfn2] \n 00067 }; 00068 00069 struct LogRec 00070 {struct Ctl Hdr; 00071 struct Arg Data; 00072 }; 00073 00074 static const int OffDone = offsetof(LogRec, Hdr.Done); 00075 static const int FixDLen = offsetof(Arg, lfn); 00076 static const int MinSize = sizeof(Ctl); // Header 00077 static const int MaxSize = sizeof(Arg); // Data 00078 static const long tBase = 1248126834L; 00079 00080 static const char lrClosew = 't'; 00081 static const char lrCreate = 'c'; 00082 static const char lrEOL = 'E'; // Internal 00083 static const char lrInvD = 'I'; // Internal dir inventory 00084 static const char lrInvF = 'i'; // Internal file inventory 00085 static const char lrMkdir = 'd'; 00086 static const char lrMount = 'M'; // Internal Mount inventory 00087 static const char lrMv = 'm'; 00088 static const char lrRm = 'r'; 00089 static const char lrRmdir = 'D'; 00090 static const char lrSpace = 'S'; // Internal Space inventory 00091 static const char lrTOD = 'T'; // Internal TOD 00092 00093 static const char *IArg; 00094 static const char *iArg; 00095 00096 static XrdCnsLogRec *Alloc(); 00097 00098 inline const char *Data() {return (const char *)&Rec.Data;} 00099 00100 inline int DLen() {return Rec.Hdr.dataLen;} 00101 00102 inline int Done(int iPos) {return Rec.Hdr.Done[iPos];} 00103 00104 static XrdCnsLogRec *Get(char &lrType); 00105 00106 inline const char *Lfn1() {return Rec.Data.lfn;} 00107 00108 inline const char *Lfn1(int &Len) {Len=Rec.Hdr.lfn1Len; return Rec.Data.lfn;} 00109 00110 inline const char *Lfn2() {return Rec.Data.lfn+Rec.Hdr.lfn1Len+1;} 00111 00112 inline mode_t Mode() {return static_cast<mode_t>(Rec.Hdr.Mode);} 00113 00114 void Queue(); 00115 00116 void Recycle(); 00117 00118 inline char *Record() {return (char *)&Rec;} 00119 00120 // setLfn1() must be called prior to calling setLfn2() or setData() 00121 // 00122 int setData(const char *dP1, const char *dP2=0); 00123 00124 void setDone(int iPos, char Val=1) {Rec.Hdr.Done[iPos] = Val;} 00125 00126 int setLen() {if (Rec.Hdr.lfn1Len) 00127 {Rec.Hdr.dataLen = FixDLen+Rec.Hdr.lfn1Len+1; 00128 if (Rec.Hdr.lfn2Len) 00129 Rec.Hdr.dataLen += Rec.Hdr.lfn2Len+1; 00130 } else Rec.Hdr.dataLen = 0; 00131 return static_cast<int>(Rec.Hdr.dataLen); 00132 } 00133 00134 inline int setLfn1(const char *lfn) 00135 {int n; 00136 n = strlcpy(Rec.Data.lfn, lfn, MAXPATHLEN+1); 00137 if (n > MAXPATHLEN) return 0; 00138 Rec.Hdr.lfn1Len = n; 00139 return n; 00140 } 00141 00142 inline int setLfn2(const char *lfn) 00143 {int n; 00144 setSize(static_cast<long long>(Rec.Hdr.lfn1Len)); 00145 n = strlcpy(Rec.Data.lfn + Rec.Hdr.lfn1Len + 1, 00146 lfn, MAXPATHLEN+1); 00147 if (n > MAXPATHLEN) return 0; 00148 Rec.Hdr.lfn2Len = n; 00149 return n; 00150 } 00151 00152 inline void setMode(mode_t Mode) {char Save = *Rec.Data.SorT; 00153 Rec.Hdr.Mode = Mode; 00154 snprintf(Rec.Data.Mode, 00155 sizeof(Rec.Data.Mode), "%03o", 00156 511 & static_cast<int>(Mode)); 00157 *Rec.Data.SorT = Save; 00158 } 00159 00160 inline void setMount(char mCode) {Rec.Data.Mount = mCode;} 00161 00162 inline void setSize(long long Size) {char Save = Rec.Data.Mount; 00163 Rec.Hdr.Size = Size; 00164 snprintf(Rec.Data.SorT, 00165 sizeof(Rec.Data.SorT), "%12lld", 00166 (Size > 0 ? Size & 0x7fffffffffLL 00167 : Size)); 00168 Rec.Data.Mount = Save; 00169 } 00170 00171 inline void setSpace(char sCode) {Rec.Data.Space = sCode;} 00172 00173 inline void setTime(long TOD=time(0)){char Save = Rec.Data.Mount; 00174 snprintf(Rec.Data.SorT, 00175 sizeof(Rec.Data.SorT), "%12ld", 00176 TOD-tBase); 00177 Rec.Data.Mount = Save; 00178 } 00179 00180 inline void setType(const char evt) {Rec.Data.Type = evt;} 00181 00182 int setType(const char *evt); 00183 00184 inline long long Size() {return Rec.Hdr.Size;} 00185 00186 inline char Space(){return Rec.Data.Space;} 00187 00188 inline int L1sz() {return Rec.Hdr.lfn1Len;} 00189 00190 inline int L2sz() {return Rec.Hdr.lfn2Len;} 00191 00192 char Type() {return Rec.Data.Type;} 00193 00194 XrdCnsLogRec(const char rType=0) : Next(0) 00195 {memset(&Rec, 0, sizeof(Rec.Hdr)); 00196 memset(&Rec.Data,' ', FixDLen); 00197 Rec.Data.Type = rType; 00198 if (rType == lrEOL || rType == lrTOD) 00199 {setTime(); 00200 Rec.Hdr.dataLen=FixDLen; 00201 if (rType == lrTOD) 00202 {Rec.Data.lfn[0] = ' '; 00203 Rec.Data.lfn[1] = '\0'; 00204 Rec.Hdr.lfn1Len = 1; 00205 } 00206 } 00207 } 00208 ~XrdCnsLogRec() {} 00209 00210 private: 00211 00212 static XrdSysSemaphore qSem; 00213 static XrdSysMutex qMutex; 00214 static XrdSysMutex fMutex; 00215 static XrdCnsLogRec *freeRec; 00216 static XrdCnsLogRec *frstRec; 00217 static XrdCnsLogRec *lastRec; 00218 static int Running; 00219 00220 XrdCnsLogRec *Next; 00221 LogRec Rec; 00222 }; 00223 #endif
1.7.6.1