Commit | Line | Data |
---|---|---|
805e021f CE |
1 | /* |
2 | * Copyright 2000, International Business Machines Corporation and others. | |
3 | * All Rights Reserved. | |
4 | * | |
5 | * This software has been released under the terms of the IBM Public | |
6 | * License. For details, see the LICENSE file in the top-level source | |
7 | * directory or online at http://www.openafs.org/dl/license10.html | |
8 | */ | |
9 | ||
10 | /* | |
11 | * All Rights Reserved | |
12 | */ | |
13 | #ifndef _ICL_H__ENV_ | |
14 | #define _ICL_H__ENV_ 1 | |
15 | ||
16 | #ifdef KERNEL | |
17 | #include "afs/param.h" | |
18 | #include "afs_osi.h" | |
19 | #include "lock.h" | |
20 | #include "afs_trace.h" | |
21 | #else | |
22 | #include <lock.h> | |
23 | typedef struct Lock afs_lock_t; | |
24 | #endif | |
25 | ||
26 | #define ICL_LOGSPERSET 8 /* max logs per set */ | |
27 | #define ICL_DEFAULTEVENTS 1024 /* default events per event set */ | |
28 | #define ICL_DEFAULT_LOGSIZE 60*1024 /* number of words in default log size */ | |
29 | ||
30 | #define osi_dlock_t afs_lock_t | |
31 | extern osi_dlock_t afs_icl_lock; /* lock for log and set refcounts */ | |
32 | extern int afs_icl_inited; | |
33 | extern struct afs_icl_log *afs_icl_allLogs; | |
34 | extern struct afs_icl_set *afs_icl_allSets; | |
35 | ||
36 | /* define an in-core logging package */ | |
37 | struct afs_icl_set { | |
38 | afs_int32 refCount; /* reference count */ | |
39 | afs_int32 states; /* state flags */ | |
40 | osi_dlock_t lock; /* lock */ | |
41 | struct afs_icl_set *nextp; /* next dude in all known tables */ | |
42 | char *name; /* name of set */ | |
43 | struct afs_icl_log *logs[ICL_LOGSPERSET]; /* logs */ | |
44 | afs_int32 nevents; /* count of events */ | |
45 | char *eventFlags; /* pointer to event flags */ | |
46 | }; | |
47 | ||
48 | /* set flags */ | |
49 | #define ICL_SETF_DELETED 1 | |
50 | #define ICL_SETF_ACTIVE 2 | |
51 | #define ICL_SETF_FREED 4 | |
52 | #define ICL_SETF_PERSISTENT 8 | |
53 | ||
54 | #ifdef ICL_DEFAULT_ENABLED | |
55 | #define ICL_DEFAULT_SET_STATES 0 /* was ICL_SETF_ACTIVE */ | |
56 | #else /* ICL_DEFAULT_ENABLED */ | |
57 | ||
58 | #ifdef ICL_DEFAULT_DISABLED | |
59 | #define ICL_DEFAULT_SET_STATES ICL_SETF_FREED | |
60 | #endif /* ICL_DEFAULT_DISABLED */ | |
61 | ||
62 | #endif /* ICL_DEFAULT_ENABLED */ | |
63 | ||
64 | #ifndef ICL_DEFAULT_SET_STATES | |
65 | /* if not changed already, default to ACTIVE on created sets */ | |
66 | #define ICL_DEFAULT_SET_STATES 0 /* was ICL_SETF_ACTIVE */ | |
67 | #endif /* ICL_DEFAULT_SET_STATES */ | |
68 | ||
69 | /* bytes required by eventFlags array, for x events */ | |
70 | #define ICL_EVENTBYTES(x) ((((x) - 1) | 7) + 1) | |
71 | ||
72 | /* functions for finding a particular event */ | |
73 | #define ICL_EVENTBYTE(x) (((x) & 0x3ff) >> 3) | |
74 | #define ICL_EVENTMASK(x) (1 << ((x) & 0x7)) | |
75 | #define ICL_EVENTOK(setp, x) ((x&0x3ff) >= 0 && (x&0x3ff) < (setp)->nevents) | |
76 | ||
77 | /* define ICL syscalls by name!! */ | |
78 | #define ICL_OP_COPYOUT 1 | |
79 | #define ICL_OP_ENUMLOGS 2 | |
80 | #define ICL_OP_CLRLOG 3 | |
81 | #define ICL_OP_CLRSET 4 | |
82 | #define ICL_OP_CLRALL 5 | |
83 | #define ICL_OP_ENUMSETS 6 | |
84 | #define ICL_OP_SETSTAT 7 | |
85 | #define ICL_OP_SETSTATALL 8 | |
86 | #define ICL_OP_SETLOGSIZE 9 | |
87 | #define ICL_OP_ENUMLOGSBYSET 10 | |
88 | #define ICL_OP_GETSETINFO 11 | |
89 | #define ICL_OP_GETLOGINFO 12 | |
90 | #define ICL_OP_COPYOUTCLR 13 | |
91 | /* Determine version number and type size info from icl package. */ | |
92 | #define ICL_OP_VERSION 14 | |
93 | ||
94 | /* define setstat commands */ | |
95 | #define ICL_OP_SS_ACTIVATE 1 | |
96 | #define ICL_OP_SS_DEACTIVATE 2 | |
97 | #define ICL_OP_SS_FREE 3 | |
98 | ||
99 | /* define set status flags */ | |
100 | #define ICL_FLAG_ACTIVE 1 | |
101 | #define ICL_FLAG_FREED 2 | |
102 | ||
103 | /* The format of the circular log is: | |
104 | * 1'st word: | |
105 | * <8 bits: size of record in longs> <6 bits: p1 type> <6 bits: p2 type> | |
106 | * <6 bits: p3 type> <6 bits: p4 type> | |
107 | * <32 bits: opcode> | |
108 | * <32 bits: pid> | |
109 | * <32 bits: timestamp in microseconds> | |
110 | * <p1 rep> | |
111 | * <p2 rep> | |
112 | * <p3 rep> | |
113 | * <p4 rep> | |
114 | * | |
115 | * Note that the representation for each parm starts at a new 32 bit | |
116 | * offset, and only the represented parameters are marshalled. | |
117 | * You can tell if a particular parameter exists by looking at its | |
118 | * type; type 0 means the parameter does not exist. | |
119 | */ | |
120 | ||
121 | /* descriptor of the circular log. Note that it can never be 100% full | |
122 | * since we break the ambiguity of head == tail by calling that | |
123 | * state empty. | |
124 | */ | |
125 | struct afs_icl_log { | |
126 | int refCount; /* reference count */ | |
127 | int setCount; /* number of non-FREED sets pointing to this guy */ | |
128 | osi_dlock_t lock; /* lock */ | |
129 | char *name; /* log name */ | |
130 | struct afs_icl_log *nextp; /* next log in system */ | |
131 | afs_int32 logSize; /* allocated # of elements in log */ | |
132 | afs_int32 logElements; /* # of elements in log right now */ | |
133 | afs_int32 *datap; /* pointer to the data */ | |
134 | afs_int32 firstUsed; /* first element used */ | |
135 | afs_int32 firstFree; /* index of first free dude */ | |
136 | long baseCookie; /* cookie value of first entry */ | |
137 | afs_int32 states; /* state bits */ | |
138 | afs_uint32 lastTS; /* last timestamp written to this log */ | |
139 | }; | |
140 | ||
141 | /* macro used to compute size of parameter when in log, used by | |
142 | * afs_icl_AppendRecord below. | |
143 | * | |
144 | * Note that "tsize" and "rsize" are free variables! | |
145 | * I use rsize to determine correct alignment (and hence size). | |
146 | * The #ifdef's start to get unwieldly when the 32 bit kernels for SGI 6.2 are | |
147 | * factored in. So, I'm going to a single macro with a variable for sizeof long. | |
148 | * User space programs need to set this based on the size of the kernel long. | |
149 | * Defined in afs_call.c and venus/fstrace.c | |
150 | */ | |
151 | extern int afs_icl_sizeofLong; | |
152 | ||
153 | #define ICL_SIZEHACK(t1, p1, ts1, rs1) \ | |
154 | MACRO_BEGIN \ | |
155 | if ((t1) == ICL_TYPE_STRING) { \ | |
156 | ts1 = (int)((unsigned)(strlen((char *)(p1)) + 4) >> 2); \ | |
157 | } else if ((t1) == ICL_TYPE_HYPER || (t1) == ICL_TYPE_INT64) \ | |
158 | ts1 = 2; \ | |
159 | else if ((t1) == ICL_TYPE_FID) \ | |
160 | ts1 = 4; \ | |
161 | else if ((t1) == ICL_TYPE_INT32) \ | |
162 | ts1 = 1; \ | |
163 | else \ | |
164 | ts1 = afs_icl_sizeofLong; \ | |
165 | /* now add in the parameter */ \ | |
166 | rs1 += ts1; \ | |
167 | MACRO_END | |
168 | ||
169 | /* log flags */ | |
170 | #define ICL_LOGF_DELETED 1 /* freed */ | |
171 | #define ICL_LOGF_WAITING 2 /* waiting for output to appear */ | |
172 | #define ICL_LOGF_PERSISTENT 4 /* persistent */ | |
173 | ||
174 | /* macros for calling these things easily */ | |
175 | #define ICL_SETACTIVE(setp) ((setp) && (setp->states & ICL_SETF_ACTIVE)) | |
176 | #define afs_Trace0(set, id) \ | |
177 | (ICL_SETACTIVE(set) ? afs_icl_Event0(set, id, 1<<24) : 0) | |
178 | #define afs_Trace1(set, id, t1, p1) \ | |
179 | (ICL_SETACTIVE(set) ? afs_icl_Event1(set, id, (1<<24)+((t1)<<18), (long)(p1)) : 0) | |
180 | #define afs_Trace2(set, id, t1, p1, t2, p2) \ | |
181 | (ICL_SETACTIVE(set) ? afs_icl_Event2(set, id, (1<<24)+((t1)<<18)+((t2)<<12), \ | |
182 | (long)(p1), (long)(p2)) : 0) | |
183 | #define afs_Trace3(set, id, t1, p1, t2, p2, t3, p3) \ | |
184 | (ICL_SETACTIVE(set) ? afs_icl_Event3(set, id, (1<<24)+((t1)<<18)+((t2)<<12)+((t3)<<6), \ | |
185 | (long)(p1), (long)(p2), (long)(p3)) : 0) | |
186 | #define afs_Trace4(set, id, t1, p1, t2, p2, t3, p3, t4, p4) \ | |
187 | (ICL_SETACTIVE(set) ? afs_icl_Event4(set, id, (1<<24)+((t1)<<18)+((t2)<<12)+((t3)<<6)+(t4), \ | |
188 | (long)(p1), (long)(p2), (long)(p3), (long)(p4)) : 0) | |
189 | ||
190 | /* types for icl_trace macros; values must be less than 64. If | |
191 | * you add a new type here, don't forget to check for ICL_MAXEXPANSION | |
192 | * changing. | |
193 | */ | |
194 | #define ICL_TYPE_NONE 0 /* parameter doesn't exist */ | |
195 | #define ICL_TYPE_LONG 1 | |
196 | #define ICL_TYPE_INT32 7 | |
197 | #define ICL_TYPE_POINTER 2 | |
198 | #define ICL_TYPE_HYPER 3 | |
199 | #define ICL_TYPE_STRING 4 | |
200 | #define ICL_TYPE_FID 5 | |
201 | #define ICL_TYPE_UNIXDATE 6 | |
202 | #define ICL_TYPE_INT64 8 | |
203 | ||
204 | #ifdef AFS_64BIT_CLIENT | |
205 | #define ICL_TYPE_OFFSET ICL_TYPE_INT64 | |
206 | #define ICL_HANDLE_OFFSET(x) (&x) | |
207 | #else /* AFS_64BIT_CLIENT */ | |
208 | #define ICL_TYPE_OFFSET ICL_TYPE_INT64 | |
209 | #define ICL_HANDLE_OFFSET(x) (x) | |
210 | #endif /* AFS_64BIT_CLIENT */ | |
211 | ||
212 | /* max # of words put in the printf buffer per parameter */ | |
213 | #define ICL_MAXEXPANSION 4 | |
214 | ||
215 | /* define flags to be used by afs_icl_CreateSetWithFlags */ | |
216 | #define ICL_CRSET_FLAG_DEFAULT_ON 1 | |
217 | #define ICL_CRSET_FLAG_DEFAULT_OFF 2 | |
218 | #define ICL_CRSET_FLAG_PERSISTENT 4 | |
219 | ||
220 | /* define flags to be used by afs_icl_CreateLogWithFlags */ | |
221 | #define ICL_CRLOG_FLAG_PERSISTENT 1 | |
222 | ||
223 | /* input flags */ | |
224 | #define ICL_COPYOUTF_WAITIO 1 /* block for output */ | |
225 | #define ICL_COPYOUTF_CLRAFTERREAD 2 /* clear log after reading */ | |
226 | /* output flags */ | |
227 | #define ICL_COPYOUTF_MISSEDSOME 1 /* missed some output */ | |
228 | ||
229 | #define lock_ObtainWrite ObtainWriteLock | |
230 | #define lock_ReleaseWrite ReleaseWriteLock | |
231 | ||
232 | #ifdef KERNEL | |
233 | extern struct afs_icl_set *afs_iclSetp; /* standard icl trace */ | |
234 | /* A separate icl set to collect long term debugging info. */ | |
235 | extern struct afs_icl_set *afs_iclLongTermSetp; | |
236 | #else | |
237 | #define osi_Alloc malloc | |
238 | #define osi_Free(a,b) free(a) | |
239 | ||
240 | #define ICL_RPC_MAX_SETS (64) | |
241 | #define ICL_RPC_MAX_LOGS (64) | |
242 | ||
243 | typedef struct afs_icl_setinfo { | |
244 | u_char setName[32]; | |
245 | afs_uint32 states; | |
246 | } afs_icl_setinfo_t; | |
247 | ||
248 | typedef struct afs_icl_loginfo { | |
249 | u_char logName[32]; | |
250 | afs_uint32 logSize; | |
251 | afs_uint32 logElements; | |
252 | afs_uint32 states; | |
253 | } afs_icl_loginfo_t; | |
254 | ||
255 | typedef struct afs_icl_bulkSetinfo { | |
256 | afs_uint32 count; | |
257 | afs_icl_setinfo_t setinfo[1]; | |
258 | } afs_icl_bulkSetinfo_t; | |
259 | ||
260 | typedef struct afs_icl_bulkLoginfo { | |
261 | afs_uint32 count; | |
262 | afs_icl_loginfo_t loginfo[1]; | |
263 | } afs_icl_bulkLoginfo_t; | |
264 | ||
265 | #endif | |
266 | ||
267 | ||
268 | #define ICL_ERROR_NOSET 9001 | |
269 | #define ICL_ERROR_NOLOG 9002 | |
270 | #define ICL_ERROR_CANTOPEN 9003 | |
271 | #define ICL_INFO_TIMESTAMP 9004 | |
272 | ||
273 | #endif /* _ICL_H__ENV_ */ |