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
42
44{
45public:
46
47static const int maxClients = 4;
48
49struct 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
59struct 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
69struct LogRec
70 {struct Ctl Hdr;
71 struct Arg Data;
72 };
73
74static const int OffDone = offsetof(LogRec, Hdr.Done);
75static const int FixDLen = offsetof(Arg, lfn);
76static const int MinSize = sizeof(Ctl); // Header
77static const int MaxSize = sizeof(Arg); // Data
78static const long tBase = 1248126834L;
79
80static const char lrClosew = 't';
81static const char lrCreate = 'c';
82static const char lrEOL = 'E'; // Internal
83static const char lrInvD = 'I'; // Internal dir inventory
84static const char lrInvF = 'i'; // Internal file inventory
85static const char lrMkdir = 'd';
86static const char lrMount = 'M'; // Internal Mount inventory
87static const char lrMv = 'm';
88static const char lrRm = 'r';
89static const char lrRmdir = 'D';
90static const char lrSpace = 'S'; // Internal Space inventory
91static const char lrTOD = 'T'; // Internal TOD
92
93static const char *IArg;
94static const char *iArg;
95
97
98inline const char *Data() {return (const char *)&Rec.Data;}
99
100inline int DLen() {return Rec.Hdr.dataLen;}
101
102inline int Done(int iPos) {return Rec.Hdr.Done[iPos];}
103
104static XrdCnsLogRec *Get(char &lrType);
105
106inline const char *Lfn1() {return Rec.Data.lfn;}
107
108inline const char *Lfn1(int &Len) {Len=Rec.Hdr.lfn1Len; return Rec.Data.lfn;}
109
110inline const char *Lfn2() {return Rec.Data.lfn+Rec.Hdr.lfn1Len+1;}
111
112inline mode_t Mode() {return static_cast<mode_t>(Rec.Hdr.Mode);}
113
114 void Queue();
115
116 void Recycle();
117
118inline 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)
130 } else Rec.Hdr.dataLen = 0;
131 return static_cast<int>(Rec.Hdr.dataLen);
132 }
133
134inline 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
142inline 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
152inline 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
160inline void setMount(char mCode) {Rec.Data.Mount = mCode;}
161
162inline 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
172inline void setSpace(char sCode) {Rec.Data.Space = sCode;}
173
174inline 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
181inline void setType(const char evt) {Rec.Data.Type = evt;}
182
183 int setType(const char *evt);
184
185inline long long Size() {return Rec.Hdr.Size;}
186
187inline char Space(){return Rec.Data.Space;}
188
189inline int L1sz() {return Rec.Hdr.lfn1Len;}
190
191inline 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
211private:
212
219static int Running;
220
223};
224#endif
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: XrdCnsLogRec.hh:44
static const char lrTOD
Definition: XrdCnsLogRec.hh:91
static XrdCnsLogRec * Get(char &lrType)
static const long tBase
Definition: XrdCnsLogRec.hh:78
static const char lrCreate
Definition: XrdCnsLogRec.hh:81
void setType(const char evt)
Definition: XrdCnsLogRec.hh:181
const char * Lfn1(int &Len)
Definition: XrdCnsLogRec.hh:108
static const char * iArg
Definition: XrdCnsLogRec.hh:94
static const int maxClients
Definition: XrdCnsLogRec.hh:47
static XrdSysMutex qMutex
Definition: XrdCnsLogRec.hh:214
long long Size()
Definition: XrdCnsLogRec.hh:185
static const char lrEOL
Definition: XrdCnsLogRec.hh:82
XrdCnsLogRec(const char rType=0)
Definition: XrdCnsLogRec.hh:195
void setMode(mode_t Mode)
Definition: XrdCnsLogRec.hh:152
static XrdCnsLogRec * frstRec
Definition: XrdCnsLogRec.hh:217
LogRec Rec
Definition: XrdCnsLogRec.hh:222
const char * Lfn1()
Definition: XrdCnsLogRec.hh:106
static const int FixDLen
Definition: XrdCnsLogRec.hh:75
static const int MaxSize
Definition: XrdCnsLogRec.hh:77
int setLen()
Definition: XrdCnsLogRec.hh:126
int setLfn1(const char *lfn)
Definition: XrdCnsLogRec.hh:134
static const int MinSize
Definition: XrdCnsLogRec.hh:76
const char * Lfn2()
Definition: XrdCnsLogRec.hh:110
void setTime(long TOD=time(0))
Definition: XrdCnsLogRec.hh:174
static const char lrClosew
Definition: XrdCnsLogRec.hh:80
static XrdCnsLogRec * lastRec
Definition: XrdCnsLogRec.hh:218
void setDone(int iPos, char Val=1)
Definition: XrdCnsLogRec.hh:124
char * Record()
Definition: XrdCnsLogRec.hh:118
static const char lrSpace
Definition: XrdCnsLogRec.hh:90
static const char lrInvD
Definition: XrdCnsLogRec.hh:83
static const char lrMkdir
Definition: XrdCnsLogRec.hh:85
void Recycle()
void setMount(char mCode)
Definition: XrdCnsLogRec.hh:160
static const int OffDone
Definition: XrdCnsLogRec.hh:74
static XrdSysSemaphore qSem
Definition: XrdCnsLogRec.hh:213
static XrdSysMutex fMutex
Definition: XrdCnsLogRec.hh:215
const char * Data()
Definition: XrdCnsLogRec.hh:98
static const char lrRmdir
Definition: XrdCnsLogRec.hh:89
int L2sz()
Definition: XrdCnsLogRec.hh:191
void setSpace(char sCode)
Definition: XrdCnsLogRec.hh:172
static XrdCnsLogRec * freeRec
Definition: XrdCnsLogRec.hh:216
int DLen()
Definition: XrdCnsLogRec.hh:100
static const char lrMv
Definition: XrdCnsLogRec.hh:87
static const char lrInvF
Definition: XrdCnsLogRec.hh:84
char Type()
Definition: XrdCnsLogRec.hh:193
static const char lrRm
Definition: XrdCnsLogRec.hh:88
int Done(int iPos)
Definition: XrdCnsLogRec.hh:102
int setType(const char *evt)
mode_t Mode()
Definition: XrdCnsLogRec.hh:112
static const char * IArg
Definition: XrdCnsLogRec.hh:93
XrdCnsLogRec * Next
Definition: XrdCnsLogRec.hh:221
static int Running
Definition: XrdCnsLogRec.hh:219
int setData(const char *dP1, const char *dP2=0)
char Space()
Definition: XrdCnsLogRec.hh:187
int setLfn2(const char *lfn)
Definition: XrdCnsLogRec.hh:142
static const char lrMount
Definition: XrdCnsLogRec.hh:86
int L1sz()
Definition: XrdCnsLogRec.hh:189
~XrdCnsLogRec()
Definition: XrdCnsLogRec.hh:209
static XrdCnsLogRec * Alloc()
void setSize(long long Size)
Definition: XrdCnsLogRec.hh:162
Definition: XrdSysPthread.hh:166
Definition: XrdSysPthread.hh:404
Definition: XrdCnsLogRec.hh:60
char lfn[MAXPATHLEN *2+3]
Definition: XrdCnsLogRec.hh:66
char Type
Definition: XrdCnsLogRec.hh:60
char Mode[3]
Definition: XrdCnsLogRec.hh:61
char Space
Definition: XrdCnsLogRec.hh:64
char Rsvd[6]
Definition: XrdCnsLogRec.hh:65
char Mount
Definition: XrdCnsLogRec.hh:63
char SorT[12]
Definition: XrdCnsLogRec.hh:62
Definition: XrdCnsLogRec.hh:50
char Done[maxClients]
Definition: XrdCnsLogRec.hh:54
short lfn1Len
Definition: XrdCnsLogRec.hh:51
short Mode
Definition: XrdCnsLogRec.hh:53
long long Size
Definition: XrdCnsLogRec.hh:56
short lfn2Len
Definition: XrdCnsLogRec.hh:52
int Rsvd
Definition: XrdCnsLogRec.hh:55
short dataLen
Definition: XrdCnsLogRec.hh:50
Definition: XrdCnsLogRec.hh:70
struct Arg Data
Definition: XrdCnsLogRec.hh:71
struct Ctl Hdr
Definition: XrdCnsLogRec.hh:70