xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdCns
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
43
class
XrdCnsLogRec
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
)
127
{
Rec
.
Hdr
.
dataLen
=
FixDLen
+
Rec
.
Hdr
.
lfn1Len
+1;
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
Save = *
Rec
.
Data
.
SorT
;
153
Rec
.
Hdr
.
Mode
=
Mode
;
154
snprintf(
Rec
.
Data
.
Mode
,
155
sizeof
(
Rec
.
Data
.
Mode
),
"%03o"
,
156
511 & static_cast<int>(Mode));
157
*
Rec
.
Data
.
SorT
= Save;
158
}
159
160
inline
void
setMount
(
char
mCode) {
Rec
.
Data
.
Mount
= mCode;}
161
162
inline
void
setSize
(
long
long
Size
) {
char
Save =
Rec
.
Data
.
Mount
;
163
Rec
.
Hdr
.
Size
=
Size
;
164
snprintf(
Rec
.
Data
.
SorT
,
165
sizeof
(
Rec
.
Data
.
SorT
),
"%12lld"
,
166
(Size > 0 ? Size & 0x7fffffffffLL
167
: Size));
168
Rec
.
Data
.
Mount
= Save;
169
}
170
171
inline
void
setSpace
(
char
sCode) {
Rec
.
Data
.
Space
= sCode;}
172
173
inline
void
setTime
(
long
TOD=time(0)){
char
Save =
Rec
.
Data
.
Mount
;
174
snprintf(
Rec
.
Data
.
SorT
,
175
sizeof
(
Rec
.
Data
.
SorT
),
"%12ld"
,
176
TOD-
tBase
);
177
Rec
.
Data
.
Mount
= Save;
178
}
179
180
inline
void
setType
(
const
char
evt) {
Rec
.
Data
.
Type
= evt;}
181
182
int
setType
(
const
char
*evt);
183
184
inline
long
long
Size
() {
return
Rec
.
Hdr
.
Size
;}
185
186
inline
char
Space
(){
return
Rec
.
Data
.
Space
;}
187
188
inline
int
L1sz
() {
return
Rec
.
Hdr
.
lfn1Len
;}
189
190
inline
int
L2sz
() {
return
Rec
.
Hdr
.
lfn2Len
;}
191
192
char
Type
() {
return
Rec
.
Data
.
Type
;}
193
194
XrdCnsLogRec
(
const
char
rType=0) :
Next
(0)
195
{memset(&
Rec
, 0,
sizeof
(
Rec
.
Hdr
));
196
memset(&
Rec
.
Data
,
' '
,
FixDLen
);
197
Rec
.
Data
.
Type
= rType;
198
if
(rType ==
lrEOL
|| rType ==
lrTOD
)
199
{
setTime
();
200
Rec
.
Hdr
.
dataLen
=
FixDLen
;
201
if
(rType ==
lrTOD
)
202
{
Rec
.
Data
.
lfn
[0] =
' '
;
203
Rec
.
Data
.
lfn
[1] =
'\0'
;
204
Rec
.
Hdr
.
lfn1Len
= 1;
205
}
206
}
207
}
208
~XrdCnsLogRec
() {}
209
210
private
:
211
212
static
XrdSysSemaphore
qSem
;
213
static
XrdSysMutex
qMutex
;
214
static
XrdSysMutex
fMutex
;
215
static
XrdCnsLogRec
*
freeRec
;
216
static
XrdCnsLogRec
*
frstRec
;
217
static
XrdCnsLogRec
*
lastRec
;
218
static
int
Running
;
219
220
XrdCnsLogRec
*
Next
;
221
LogRec
Rec
;
222
};
223
#endif
Generated by
1.8.3.1