xrootd
XrdCnsLogRec.hh
Go to the documentation of this file.
1 #ifndef __XRDCnsLogRec_H_
2 #define __XRDCnsLogRec_H_
3 /******************************************************************************/
4 /* */
5 /* X r d C n s L o g R e c . h h */
6 /* */
7 /* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <stddef.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <time.h>
37 #include <sys/param.h>
38 #include <sys/types.h>
39 
40 #include "XrdSys/XrdSysPlatform.hh"
41 #include "XrdSys/XrdSysPthread.hh"
42 
44 {
45 public:
46 
47 static const int maxClients = 4;
48 
49 struct Ctl
50  {short dataLen; // Length of data in Arg (eof when 0)
51  short lfn1Len; // strlen(lfn1)
52  short lfn2Len; // strlen(lfn2)
53  short Mode; // File mode (create and mkdir)
54  char Done[maxClients]; // 1->Record processed
55  int Rsvd; // Reserved field
56  long long Size; // Valid when Closew
57  };
58 
59 struct Arg
60  {char Type; // Event code
61  char Mode[3]; // Mode (create, inv, mkdir)
62  char SorT[12]; // Size (closew, inv) | TOD (eol)
63  char Mount; // Mount Index
64  char Space; // Space Index
65  char Rsvd[6]; // Reserved (blank filled)
66  char lfn[MAXPATHLEN*2+3]; // lfn1 [lfn2] \n
67  };
68 
69 struct LogRec
70  {struct Ctl Hdr;
71  struct Arg Data;
72  };
73 
74 static const int OffDone = offsetof(LogRec, Hdr.Done);
75 static const int FixDLen = offsetof(Arg, lfn);
76 static const int MinSize = sizeof(Ctl); // Header
77 static const int MaxSize = sizeof(Arg); // Data
78 static const long tBase = 1248126834L;
79 
80 static const char lrClosew = 't';
81 static const char lrCreate = 'c';
82 static const char lrEOL = 'E'; // Internal
83 static const char lrInvD = 'I'; // Internal dir inventory
84 static const char lrInvF = 'i'; // Internal file inventory
85 static const char lrMkdir = 'd';
86 static const char lrMount = 'M'; // Internal Mount inventory
87 static const char lrMv = 'm';
88 static const char lrRm = 'r';
89 static const char lrRmdir = 'D';
90 static const char lrSpace = 'S'; // Internal Space inventory
91 static const char lrTOD = 'T'; // Internal TOD
92 
93 static const char *IArg;
94 static const char *iArg;
95 
96 static XrdCnsLogRec *Alloc();
97 
98 inline const char *Data() {return (const char *)&Rec.Data;}
99 
100 inline int DLen() {return Rec.Hdr.dataLen;}
101 
102 inline int Done(int iPos) {return Rec.Hdr.Done[iPos];}
103 
104 static XrdCnsLogRec *Get(char &lrType);
105 
106 inline const char *Lfn1() {return Rec.Data.lfn;}
107 
108 inline const char *Lfn1(int &Len) {Len=Rec.Hdr.lfn1Len; return Rec.Data.lfn;}
109 
110 inline const char *Lfn2() {return Rec.Data.lfn+Rec.Hdr.lfn1Len+1;}
111 
112 inline mode_t Mode() {return static_cast<mode_t>(Rec.Hdr.Mode);}
113 
114  void Queue();
115 
116  void Recycle();
117 
118 inline char *Record() {return (char *)&Rec;}
119 
120 // setLfn1() must be called prior to calling setLfn2() or setData()
121 //
122  int setData(const char *dP1, const char *dP2=0);
123 
124  void setDone(int iPos, char Val=1) {Rec.Hdr.Done[iPos] = Val;}
125 
126  int setLen() {if (Rec.Hdr.lfn1Len)
128  if (Rec.Hdr.lfn2Len)
129  Rec.Hdr.dataLen += Rec.Hdr.lfn2Len+1;
130  } else Rec.Hdr.dataLen = 0;
131  return static_cast<int>(Rec.Hdr.dataLen);
132  }
133 
134 inline int setLfn1(const char *lfn)
135  {int n;
136  n = strlcpy(Rec.Data.lfn, lfn, MAXPATHLEN+1);
137  if (n > MAXPATHLEN) return 0;
138  Rec.Hdr.lfn1Len = n;
139  return n;
140  }
141 
142 inline int setLfn2(const char *lfn)
143  {int n;
144  setSize(static_cast<long long>(Rec.Hdr.lfn1Len));
145  n = strlcpy(Rec.Data.lfn + Rec.Hdr.lfn1Len + 1,
146  lfn, MAXPATHLEN+1);
147  if (n > MAXPATHLEN) return 0;
148  Rec.Hdr.lfn2Len = n;
149  return n;
150  }
151 
152 inline void setMode(mode_t Mode) {char mBuff[8];
153  Rec.Hdr.Mode = Mode;
154  snprintf(mBuff,sizeof(mBuff),"%03o",
155  511 & static_cast<int>(Mode));
156  memcpy(Rec.Data.Mode, mBuff,
157  sizeof(Rec.Data.Mode));
158  }
159 
160 inline void setMount(char mCode) {Rec.Data.Mount = mCode;}
161 
162 inline void setSize(long long Size) {char tBuff[24];
163  Rec.Hdr.Size = Size;
164  snprintf(tBuff, sizeof(tBuff),
165  "%12lld",
166  (Size > 0 ? Size & 0x7fffffffffLL
167  : Size));
168  memcpy(Rec.Data.SorT, tBuff,
169  sizeof(Rec.Data.SorT));
170  }
171 
172 inline void setSpace(char sCode) {Rec.Data.Space = sCode;}
173 
174 inline void setTime(long TOD=time(0)){char tBuff[24];
175  snprintf(tBuff, sizeof(tBuff),
176  "%12ld", TOD-tBase);
177  memcpy(Rec.Data.SorT, tBuff,
178  sizeof(Rec.Data.SorT));
179  }
180 
181 inline void setType(const char evt) {Rec.Data.Type = evt;}
182 
183  int setType(const char *evt);
184 
185 inline long long Size() {return Rec.Hdr.Size;}
186 
187 inline char Space(){return Rec.Data.Space;}
188 
189 inline int L1sz() {return Rec.Hdr.lfn1Len;}
190 
191 inline int L2sz() {return Rec.Hdr.lfn2Len;}
192 
193  char Type() {return Rec.Data.Type;}
194 
195  XrdCnsLogRec(const char rType=0) : Next(0)
196  {memset(&Rec, 0, sizeof(Rec.Hdr));
197  memset(&Rec.Data,' ', FixDLen);
198  Rec.Data.Type = rType;
199  if (rType == lrEOL || rType == lrTOD)
200  {setTime();
202  if (rType == lrTOD)
203  {Rec.Data.lfn[0] = ' ';
204  Rec.Data.lfn[1] = '\0';
205  Rec.Hdr.lfn1Len = 1;
206  }
207  }
208  }
210 
211 private:
212 
219 static int Running;
220 
223 };
224 #endif
char Type
Definition: XrdCnsLogRec.hh:60
static const int OffDone
Definition: XrdCnsLogRec.hh:74
char * Record()
Definition: XrdCnsLogRec.hh:118
~XrdCnsLogRec()
Definition: XrdCnsLogRec.hh:209
LogRec Rec
Definition: XrdCnsLogRec.hh:222
static const char lrInvF
Definition: XrdCnsLogRec.hh:84
static int Running
Definition: XrdCnsLogRec.hh:219
static const char lrCreate
Definition: XrdCnsLogRec.hh:81
int setLen()
Definition: XrdCnsLogRec.hh:126
int DLen()
Definition: XrdCnsLogRec.hh:100
void setSpace(char sCode)
Definition: XrdCnsLogRec.hh:172
static const char lrMount
Definition: XrdCnsLogRec.hh:86
static const char lrMv
Definition: XrdCnsLogRec.hh:87
void Recycle()
const char * Lfn1(int &Len)
Definition: XrdCnsLogRec.hh:108
static const char lrEOL
Definition: XrdCnsLogRec.hh:82
static const int FixDLen
Definition: XrdCnsLogRec.hh:75
static const char * iArg
Definition: XrdCnsLogRec.hh:94
void setMount(char mCode)
Definition: XrdCnsLogRec.hh:160
static const long tBase
Definition: XrdCnsLogRec.hh:78
int setLfn1(const char *lfn)
Definition: XrdCnsLogRec.hh:134
Definition: XrdCnsLogRec.hh:49
char Mount
Definition: XrdCnsLogRec.hh:63
const char * Data()
Definition: XrdCnsLogRec.hh:98
struct Arg Data
Definition: XrdCnsLogRec.hh:71
int L2sz()
Definition: XrdCnsLogRec.hh:191
static XrdSysSemaphore qSem
Definition: XrdCnsLogRec.hh:213
char Done[maxClients]
Definition: XrdCnsLogRec.hh:54
const char * Lfn1()
Definition: XrdCnsLogRec.hh:106
int Done(int iPos)
Definition: XrdCnsLogRec.hh:102
static const char lrInvD
Definition: XrdCnsLogRec.hh:83
static XrdSysMutex qMutex
Definition: XrdCnsLogRec.hh:214
long long Size()
Definition: XrdCnsLogRec.hh:185
static XrdCnsLogRec * freeRec
Definition: XrdCnsLogRec.hh:216
static const char lrClosew
Definition: XrdCnsLogRec.hh:80
static const char lrMkdir
Definition: XrdCnsLogRec.hh:85
Definition: XrdSysPthread.hh:165
static const char lrRm
Definition: XrdCnsLogRec.hh:88
void setDone(int iPos, char Val=1)
Definition: XrdCnsLogRec.hh:124
struct Ctl Hdr
Definition: XrdCnsLogRec.hh:70
char Mode[3]
Definition: XrdCnsLogRec.hh:61
XrdCnsLogRec * Next
Definition: XrdCnsLogRec.hh:221
char lfn[MAXPATHLEN *2+3]
Definition: XrdCnsLogRec.hh:66
int L1sz()
Definition: XrdCnsLogRec.hh:189
Definition: XrdSysPthread.hh:403
short Mode
Definition: XrdCnsLogRec.hh:53
char Type()
Definition: XrdCnsLogRec.hh:193
void setTime(long TOD=time(0))
Definition: XrdCnsLogRec.hh:174
const char * Lfn2()
Definition: XrdCnsLogRec.hh:110
Definition: XrdCnsLogRec.hh:69
static XrdCnsLogRec * lastRec
Definition: XrdCnsLogRec.hh:218
mode_t Mode()
Definition: XrdCnsLogRec.hh:112
Definition: XrdCnsLogRec.hh:43
static XrdSysMutex fMutex
Definition: XrdCnsLogRec.hh:215
void setMode(mode_t Mode)
Definition: XrdCnsLogRec.hh:152
static XrdCnsLogRec * frstRec
Definition: XrdCnsLogRec.hh:217
static XrdCnsLogRec * Get(char &lrType)
static const int MaxSize
Definition: XrdCnsLogRec.hh:77
static XrdCnsLogRec * Alloc()
short dataLen
Definition: XrdCnsLogRec.hh:50
XrdCnsLogRec(const char rType=0)
Definition: XrdCnsLogRec.hh:195
static const int MinSize
Definition: XrdCnsLogRec.hh:76
long long Size
Definition: XrdCnsLogRec.hh:56
char Space
Definition: XrdCnsLogRec.hh:64
int Rsvd
Definition: XrdCnsLogRec.hh:55
char SorT[12]
Definition: XrdCnsLogRec.hh:62
static const char lrTOD
Definition: XrdCnsLogRec.hh:91
int setLfn2(const char *lfn)
Definition: XrdCnsLogRec.hh:142
void setType(const char evt)
Definition: XrdCnsLogRec.hh:181
short lfn2Len
Definition: XrdCnsLogRec.hh:52
Definition: XrdCnsLogRec.hh:59
static const char * IArg
Definition: XrdCnsLogRec.hh:93
void setSize(long long Size)
Definition: XrdCnsLogRec.hh:162
int setData(const char *dP1, const char *dP2=0)
short lfn1Len
Definition: XrdCnsLogRec.hh:51
char Rsvd[6]
Definition: XrdCnsLogRec.hh:65
char Space()
Definition: XrdCnsLogRec.hh:187
static const char lrSpace
Definition: XrdCnsLogRec.hh:90
static const char lrRmdir
Definition: XrdCnsLogRec.hh:89
size_t strlcpy(char *dst, const char *src, size_t size)
static const int maxClients
Definition: XrdCnsLogRec.hh:47