2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include "afs/param.h"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
15 #include "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h"
17 #include "rx/rx_globals.h"
18 #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
21 #include "h/hashing.h"
23 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN60_ENV)
24 #include "netinet/in_var.h"
26 #endif /* !defined(UKERNEL) */
27 #ifdef AFS_LINUX22_ENV
28 #include "h/smp_lock.h"
32 struct afs_icl_set *afs_iclSetp = (struct afs_icl_set *)0;
33 struct afs_icl_set *afs_iclLongTermSetp = (struct afs_icl_set *)0;
35 #if defined(AFS_OSF_ENV) || defined(AFS_SGI61_ENV)
36 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
37 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
38 int afs_icl_sizeofLong = 1;
40 int afs_icl_sizeofLong = 2;
43 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
44 int afs_icl_sizeofLong = 2;
46 int afs_icl_sizeofLong = 1;
50 int afs_icl_inited = 0;
52 /* init function, called once, under afs_icl_lock */
60 /* Function called at shutdown - zap everything */
64 struct afs_icl_log *logp;
65 struct afs_icl_set *setp;
67 setp = afs_icl_FindSet("cm");
69 /* Release the reference from Find, and the initial one */
70 afs_icl_SetFree(setp);
71 afs_icl_SetFree(setp);
73 setp = afs_icl_FindSet("cmlongterm");
75 /* Release the reference from Find, and the initial one */
76 afs_icl_SetFree(setp);
77 afs_icl_SetFree(setp);
79 logp = afs_icl_FindLog("cmfx");
81 /* Release the reference from Find, and the initial one */
82 afs_icl_LogFree(logp);
83 afs_icl_LogFree(logp);
89 afs_icl_InitLogs(void)
91 struct afs_icl_log *logp;
94 /* initialize the ICL system */
95 code = afs_icl_CreateLog("cmfx", 60 * 1024, &logp);
98 afs_icl_CreateSetWithFlags("cm", logp, NULL,
99 ICL_CRSET_FLAG_DEFAULT_OFF,
102 afs_icl_CreateSet("cmlongterm", logp, NULL,
103 &afs_iclLongTermSetp);
108 struct afs_icl_log *afs_icl_FindLog(char *);
109 struct afs_icl_set *afs_icl_FindSet(char *);
112 #ifdef AFS_DARWIN100_ENV
113 #define AFSKPTR(X) k ## X
115 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
117 return Afscall64_icl(opcode,
118 CAST_USER_ADDR_T((p1)),
119 CAST_USER_ADDR_T((p2)),
120 CAST_USER_ADDR_T((p3)),
121 CAST_USER_ADDR_T((p4)),
125 #define AFSKPTR(X) ((caddr_t)X)
129 #ifdef AFS_DARWIN100_ENV
130 Afscall64_icl(int opcode, user_addr_t kp1, user_addr_t kp2, user_addr_t kp3, user_addr_t kp4, int *retval)
132 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
135 afs_int32 *lp, elts, flags;
136 register afs_int32 code;
137 struct afs_icl_log *logp;
138 struct afs_icl_set *setp;
139 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
141 #else /* AFS_SGI61_ENV */
142 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
147 #endif /* AFS_SGI61_ENV */
149 afs_int32 startCookie;
151 struct afs_icl_log *tlp;
152 #ifdef AFS_DARWIN100_ENV
153 afs_uint32 p1 = (afs_uint32)kp1;
154 afs_uint32 p2 = (afs_uint32)kp2;
155 afs_uint32 p3 = (afs_uint32)kp3;
156 afs_uint32 p4 = (afs_uint32)kp4;
160 if (!afs_suser(CRED())) { /* only root can run this code */
164 if (!afs_suser(NULL)) { /* only root can run this code */
165 #if defined(KERNEL_HAVE_UERROR)
174 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
175 case ICL_OP_COPYOUT: /* copy ouy data */
176 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
177 * return flags<<24 + nwords.
178 * updates cookie to updated start (not end) if we had to
181 AFS_COPYINSTR(AFSKPTR(p1), tname, sizeof(tname), &temp, code);
184 AFS_COPYIN(AFSKPTR(p4), (char *)&startCookie, sizeof(afs_int32), code);
187 logp = afs_icl_FindLog(tname);
190 #define BUFFERSIZE AFS_LRALLOCSIZ
191 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
192 elts = BUFFERSIZE / sizeof(afs_int32);
195 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
197 afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) & startCookie,
200 osi_FreeLargeSpace((struct osi_buffer *)lp);
203 AFS_COPYOUT((char *)lp, AFSKPTR(p2), elts * sizeof(afs_int32), code);
206 AFS_COPYOUT((char *)&startCookie, AFSKPTR(p4), sizeof(afs_int32),
210 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
212 *retval = ((long)((flags << 24) | (elts & 0xffffff))) << 32;
215 *retval = (flags << 24) | (elts & 0xffffff);
217 afs_icl_LogRele(logp);
218 osi_FreeLargeSpace((struct osi_buffer *)lp);
221 case ICL_OP_ENUMLOGS: /* enumerate logs */
222 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
223 * return 0 for success, otherwise error.
225 for (tlp = afs_icl_allLogs; tlp; tlp = tlp->nextp) {
230 return ENOENT; /* past the end of file */
231 temp = strlen(tlp->name) + 1;
234 AFS_COPYOUT(tlp->name, AFSKPTR(p2), temp, code);
235 if (!code) /* copy out size of log */
236 AFS_COPYOUT((char *)&tlp->logSize, AFSKPTR(p4), sizeof(afs_int32),
240 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
241 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
242 * return 0 for success, otherwise error.
244 AFS_COPYINSTR(AFSKPTR(p1), tname, sizeof(tname), &temp, code);
247 setp = afs_icl_FindSet(tname);
250 if (p2 > ICL_LOGSPERSET)
252 if (!(tlp = setp->logs[p2]))
254 temp = strlen(tlp->name) + 1;
257 AFS_COPYOUT(tlp->name, AFSKPTR(p3), temp, code);
260 case ICL_OP_CLRLOG: /* clear specified log */
261 /* zero out the specified log: p1=logname */
262 AFS_COPYINSTR(AFSKPTR(p1), tname, sizeof(tname), &temp, code);
265 logp = afs_icl_FindLog(tname);
268 code = afs_icl_ZeroLog(logp);
269 afs_icl_LogRele(logp);
272 case ICL_OP_CLRSET: /* clear specified set */
273 /* zero out the specified set: p1=setname */
274 AFS_COPYINSTR(AFSKPTR(p1), tname, sizeof(tname), &temp, code);
277 setp = afs_icl_FindSet(tname);
280 code = afs_icl_ZeroSet(setp);
281 afs_icl_SetRele(setp);
284 case ICL_OP_CLRALL: /* clear all logs */
285 /* zero out all logs -- no args */
287 ObtainWriteLock(&afs_icl_lock, 178);
288 for (tlp = afs_icl_allLogs; tlp; tlp = tlp->nextp) {
289 tlp->refCount++; /* hold this guy */
290 ReleaseWriteLock(&afs_icl_lock);
291 /* don't clear persistent logs */
292 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
293 code = afs_icl_ZeroLog(tlp);
294 ObtainWriteLock(&afs_icl_lock, 179);
295 if (--tlp->refCount == 0)
300 ReleaseWriteLock(&afs_icl_lock);
303 case ICL_OP_ENUMSETS: /* enumerate all sets */
304 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
305 * return 0 for success, otherwise error.
307 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
312 return ENOENT; /* past the end of file */
313 temp = strlen(setp->name) + 1;
316 AFS_COPYOUT(setp->name, AFSKPTR(p2), temp, code);
317 if (!code) /* copy out size of log */
318 AFS_COPYOUT((char *)&setp->states, AFSKPTR(p4), sizeof(afs_int32),
322 case ICL_OP_SETSTAT: /* set status on a set */
323 /* activate the specified set: p1=setname, p2=op */
324 AFS_COPYINSTR(AFSKPTR(p1), tname, sizeof(tname), &temp, code);
327 setp = afs_icl_FindSet(tname);
330 code = afs_icl_SetSetStat(setp, p2);
331 afs_icl_SetRele(setp);
334 case ICL_OP_SETSTATALL: /* set status on all sets */
335 /* activate the specified set: p1=op */
337 ObtainWriteLock(&afs_icl_lock, 180);
338 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
339 setp->refCount++; /* hold this guy */
340 ReleaseWriteLock(&afs_icl_lock);
341 /* don't set states on persistent sets */
342 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
343 code = afs_icl_SetSetStat(setp, p1);
344 ObtainWriteLock(&afs_icl_lock, 181);
345 if (--setp->refCount == 0)
346 afs_icl_ZapSet(setp);
350 ReleaseWriteLock(&afs_icl_lock);
353 case ICL_OP_SETLOGSIZE: /* set size of log */
354 /* set the size of the specified log: p1=logname, p2=size (in words) */
355 AFS_COPYINSTR(AFSKPTR(p1), tname, sizeof(tname), &temp, code);
358 logp = afs_icl_FindLog(tname);
361 code = afs_icl_LogSetSize(logp, p2);
362 afs_icl_LogRele(logp);
365 case ICL_OP_GETLOGINFO: /* get size of log */
366 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
367 AFS_COPYINSTR(AFSKPTR(p1), tname, sizeof(tname), &temp, code);
370 logp = afs_icl_FindLog(tname);
373 allocated = !!logp->datap;
374 AFS_COPYOUT((char *)&logp->logSize, AFSKPTR(p2), sizeof(afs_int32),
377 AFS_COPYOUT((char *)&allocated, AFSKPTR(p3), sizeof(afs_int32),
379 afs_icl_LogRele(logp);
382 case ICL_OP_GETSETINFO: /* get state of set */
383 /* zero out the specified set: p1=setname, p2=&state */
384 AFS_COPYINSTR(AFSKPTR(p1), tname, sizeof(tname), &temp, code);
387 setp = afs_icl_FindSet(tname);
390 AFS_COPYOUT((char *)&setp->states, AFSKPTR(p2), sizeof(afs_int32),
392 afs_icl_SetRele(setp);
403 afs_lock_t afs_icl_lock;
405 /* exported routine: a 4 parameter event */
407 afs_icl_Event4(register struct afs_icl_set *setp, afs_int32 eventID,
408 afs_int32 lAndT, long p1, long p2, long p3, long p4)
412 register afs_int32 tmask;
415 /* If things aren't init'ed yet (or the set is inactive), don't panic */
416 if (!ICL_SETACTIVE(setp))
420 mask = lAndT >> 24 & 0xff; /* mask of which logs to log to */
421 ix = ICL_EVENTBYTE(eventID);
422 ObtainReadLock(&setp->lock);
423 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
424 for (i = 0, tmask = 1; i < ICL_LOGSPERSET; i++, tmask <<= 1) {
426 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
431 break; /* break early */
434 ReleaseReadLock(&setp->lock);
438 /* Next 4 routines should be implemented via var-args or something.
439 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
440 * Otherwise, could call afs_icl_Event4 directly.
443 afs_icl_Event3(register struct afs_icl_set *setp, afs_int32 eventID,
444 afs_int32 lAndT, long p1, long p2, long p3)
446 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
450 afs_icl_Event2(register struct afs_icl_set *setp, afs_int32 eventID,
451 afs_int32 lAndT, long p1, long p2)
453 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
457 afs_icl_Event1(register struct afs_icl_set *setp, afs_int32 eventID,
458 afs_int32 lAndT, long p1)
460 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0,
465 afs_icl_Event0(register struct afs_icl_set *setp, afs_int32 eventID,
468 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0,
472 struct afs_icl_log *afs_icl_allLogs = 0;
474 /* function to purge records from the start of the log, until there
475 * is at least minSpace long's worth of space available without
476 * making the head and the tail point to the same word.
478 * Log must be write-locked.
481 afs_icl_GetLogSpace(register struct afs_icl_log *logp, afs_int32 minSpace)
483 register unsigned int tsize;
485 while (logp->logSize - logp->logElements <= minSpace) {
487 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
488 logp->logElements -= tsize;
489 logp->firstUsed += tsize;
490 if (logp->firstUsed >= logp->logSize)
491 logp->firstUsed -= logp->logSize;
492 logp->baseCookie += tsize;
496 /* append string astr to buffer, including terminating null char.
498 * log must be write-locked.
500 #define ICL_CHARSPERLONG 4
502 afs_icl_AppendString(struct afs_icl_log *logp, char *astr)
504 char *op; /* ptr to char to write */
506 register int bib; /* bytes in buffer */
509 op = (char *)&(logp->datap[logp->firstFree]);
513 if (++bib >= ICL_CHARSPERLONG) {
516 if (++(logp->firstFree) >= logp->logSize) {
518 op = (char *)&(logp->datap[0]);
526 /* if we've used this word at all, allocate it */
527 if (++(logp->firstFree) >= logp->logSize) {
534 /* add a long to the log, ignoring overflow (checked already) */
535 #define ICL_APPENDINT32(lp, x) \
537 (lp)->datap[(lp)->firstFree] = (x); \
538 if (++((lp)->firstFree) >= (lp)->logSize) { \
539 (lp)->firstFree = 0; \
541 (lp)->logElements++; \
544 #if defined(AFS_OSF_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) || defined(AFS_DARWIN_ENV) && defined(__amd64__)
545 #define ICL_APPENDLONG(lp, x) \
547 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
548 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
551 #else /* AFS_OSF_ENV */
552 #define ICL_APPENDLONG(lp, x) ICL_APPENDINT32((lp), (x))
553 #endif /* AFS_OSF_ENV */
555 /* routine to tell whether we're dealing with the address or the
559 afs_icl_UseAddr(int type)
561 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
562 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
568 /* Function to append a record to the log. Written for speed
569 * since we know that we're going to have to make this work fast
570 * pretty soon, anyway. The log must be unlocked.
574 afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
575 afs_int32 types, long p1, long p2, long p3, long p4)
577 int rsize; /* record size in longs */
578 register int tsize; /* temp size */
582 t4 = types & 0x3f; /* decode types */
590 osi_GetTime(&tv); /* It panics for solaris if inside */
591 ObtainWriteLock(&logp->lock, 182);
593 ReleaseWriteLock(&logp->lock);
597 /* get timestamp as # of microseconds since some time that doesn't
598 * change that often. This algorithm ticks over every 20 minutes
599 * or so (1000 seconds). Write a timestamp record if it has.
601 if (tv.tv_sec - logp->lastTS > 1024) {
602 /* the timer has wrapped -- write a timestamp record */
603 if (logp->logSize - logp->logElements <= 5)
604 afs_icl_GetLogSpace(logp, 5);
606 ICL_APPENDINT32(logp,
607 (afs_int32) (5 << 24) + (ICL_TYPE_UNIXDATE << 18));
608 ICL_APPENDINT32(logp, (afs_int32) ICL_INFO_TIMESTAMP);
609 ICL_APPENDINT32(logp, (afs_int32) 0); /* use thread ID zero for clocks */
610 ICL_APPENDINT32(logp,
611 (afs_int32) (tv.tv_sec & 0x3ff) * 1000000 +
613 ICL_APPENDINT32(logp, (afs_int32) tv.tv_sec);
615 logp->lastTS = tv.tv_sec;
618 rsize = 4; /* base case */
620 /* compute size of parameter p1. Only tricky case is string.
621 * In that case, we have to call strlen to get the string length.
623 ICL_SIZEHACK(t1, p1);
626 /* compute size of parameter p2. Only tricky case is string.
627 * In that case, we have to call strlen to get the string length.
629 ICL_SIZEHACK(t2, p2);
632 /* compute size of parameter p3. Only tricky case is string.
633 * In that case, we have to call strlen to get the string length.
635 ICL_SIZEHACK(t3, p3);
638 /* compute size of parameter p4. Only tricky case is string.
639 * In that case, we have to call strlen to get the string length.
641 ICL_SIZEHACK(t4, p4);
644 /* At this point, we've computed all of the parameter sizes, and
645 * have in rsize the size of the entire record we want to append.
646 * Next, we check that we actually have room in the log to do this
647 * work, and then we do the append.
650 ReleaseWriteLock(&logp->lock);
651 return; /* log record too big to express */
654 if (logp->logSize - logp->logElements <= rsize)
655 afs_icl_GetLogSpace(logp, rsize);
657 ICL_APPENDINT32(logp,
658 (afs_int32) (rsize << 24) + (t1 << 18) + (t2 << 12) +
660 ICL_APPENDINT32(logp, (afs_int32) op);
661 ICL_APPENDINT32(logp, (afs_int32) osi_ThreadUnique());
662 ICL_APPENDINT32(logp,
663 (afs_int32) (tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
666 /* marshall parameter 1 now */
667 if (t1 == ICL_TYPE_STRING) {
668 afs_icl_AppendString(logp, (char *)p1);
669 } else if (t1 == ICL_TYPE_HYPER) {
670 ICL_APPENDINT32(logp,
671 (afs_int32) ((struct afs_hyper_t *)p1)->high);
672 ICL_APPENDINT32(logp,
673 (afs_int32) ((struct afs_hyper_t *)p1)->low);
674 } else if (t1 == ICL_TYPE_INT64) {
675 #ifndef WORDS_BIGENDIAN
676 #ifdef AFS_64BIT_CLIENT
677 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
678 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
679 #else /* AFS_64BIT_CLIENT */
680 ICL_APPENDINT32(logp, (afs_int32) p1);
681 ICL_APPENDINT32(logp, (afs_int32) 0);
682 #endif /* AFS_64BIT_CLIENT */
683 #else /* AFSLITTLE_ENDIAN */
684 #ifdef AFS_64BIT_CLIENT
685 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
686 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
687 #else /* AFS_64BIT_CLIENT */
688 ICL_APPENDINT32(logp, (afs_int32) 0);
689 ICL_APPENDINT32(logp, (afs_int32) p1);
690 #endif /* AFS_64BIT_CLIENT */
691 #endif /* AFSLITTLE_ENDIAN */
692 } else if (t1 == ICL_TYPE_FID) {
693 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
694 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
695 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[2]);
696 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[3]);
698 #if defined(AFS_OSF_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
699 else if (t1 == ICL_TYPE_INT32)
700 ICL_APPENDINT32(logp, (afs_int32) p1);
701 #endif /* AFS_OSF_ENV */
703 ICL_APPENDLONG(logp, p1);
706 /* marshall parameter 2 now */
707 if (t2 == ICL_TYPE_STRING)
708 afs_icl_AppendString(logp, (char *)p2);
709 else if (t2 == ICL_TYPE_HYPER) {
710 ICL_APPENDINT32(logp,
711 (afs_int32) ((struct afs_hyper_t *)p2)->high);
712 ICL_APPENDINT32(logp,
713 (afs_int32) ((struct afs_hyper_t *)p2)->low);
714 } else if (t2 == ICL_TYPE_INT64) {
715 #ifndef WORDS_BIGENDIAN
716 #ifdef AFS_64BIT_CLIENT
717 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
718 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
719 #else /* AFS_64BIT_CLIENT */
720 ICL_APPENDINT32(logp, (afs_int32) p2);
721 ICL_APPENDINT32(logp, (afs_int32) 0);
722 #endif /* AFS_64BIT_CLIENT */
723 #else /* AFSLITTLE_ENDIAN */
724 #ifdef AFS_64BIT_CLIENT
725 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
726 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
727 #else /* AFS_64BIT_CLIENT */
728 ICL_APPENDINT32(logp, (afs_int32) 0);
729 ICL_APPENDINT32(logp, (afs_int32) p2);
730 #endif /* AFS_64BIT_CLIENT */
731 #endif /* AFSLITTLE_ENDIAN */
732 } else if (t2 == ICL_TYPE_FID) {
733 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
734 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
735 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[2]);
736 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[3]);
738 #if defined(AFS_OSF_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
739 else if (t2 == ICL_TYPE_INT32)
740 ICL_APPENDINT32(logp, (afs_int32) p2);
741 #endif /* AFS_OSF_ENV */
743 ICL_APPENDLONG(logp, p2);
746 /* marshall parameter 3 now */
747 if (t3 == ICL_TYPE_STRING)
748 afs_icl_AppendString(logp, (char *)p3);
749 else if (t3 == ICL_TYPE_HYPER) {
750 ICL_APPENDINT32(logp,
751 (afs_int32) ((struct afs_hyper_t *)p3)->high);
752 ICL_APPENDINT32(logp,
753 (afs_int32) ((struct afs_hyper_t *)p3)->low);
754 } else if (t3 == ICL_TYPE_INT64) {
755 #ifndef WORDS_BIGENDIAN
756 #ifdef AFS_64BIT_CLIENT
757 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
758 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
759 #else /* AFS_64BIT_CLIENT */
760 ICL_APPENDINT32(logp, (afs_int32) p3);
761 ICL_APPENDINT32(logp, (afs_int32) 0);
762 #endif /* AFS_64BIT_CLIENT */
763 #else /* AFSLITTLE_ENDIAN */
764 #ifdef AFS_64BIT_CLIENT
765 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
766 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
767 #else /* AFS_64BIT_CLIENT */
768 ICL_APPENDINT32(logp, (afs_int32) 0);
769 ICL_APPENDINT32(logp, (afs_int32) p3);
770 #endif /* AFS_64BIT_CLIENT */
771 #endif /* AFSLITTLE_ENDIAN */
772 } else if (t3 == ICL_TYPE_FID) {
773 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
774 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
775 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[2]);
776 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[3]);
778 #if defined(AFS_OSF_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
779 else if (t3 == ICL_TYPE_INT32)
780 ICL_APPENDINT32(logp, (afs_int32) p3);
781 #endif /* AFS_OSF_ENV */
783 ICL_APPENDLONG(logp, p3);
786 /* marshall parameter 4 now */
787 if (t4 == ICL_TYPE_STRING)
788 afs_icl_AppendString(logp, (char *)p4);
789 else if (t4 == ICL_TYPE_HYPER) {
790 ICL_APPENDINT32(logp,
791 (afs_int32) ((struct afs_hyper_t *)p4)->high);
792 ICL_APPENDINT32(logp,
793 (afs_int32) ((struct afs_hyper_t *)p4)->low);
794 } else if (t4 == ICL_TYPE_INT64) {
795 #ifndef WORDS_BIGENDIAN
796 #ifdef AFS_64BIT_CLIENT
797 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
798 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
799 #else /* AFS_64BIT_CLIENT */
800 ICL_APPENDINT32(logp, (afs_int32) p4);
801 ICL_APPENDINT32(logp, (afs_int32) 0);
802 #endif /* AFS_64BIT_CLIENT */
803 #else /* AFSLITTLE_ENDIAN */
804 #ifdef AFS_64BIT_CLIENT
805 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
806 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
807 #else /* AFS_64BIT_CLIENT */
808 ICL_APPENDINT32(logp, (afs_int32) 0);
809 ICL_APPENDINT32(logp, (afs_int32) p4);
810 #endif /* AFS_64BIT_CLIENT */
811 #endif /* AFSLITTLE_ENDIAN */
812 } else if (t4 == ICL_TYPE_FID) {
813 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
814 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
815 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[2]);
816 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[3]);
818 #if defined(AFS_OSF_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
819 else if (t4 == ICL_TYPE_INT32)
820 ICL_APPENDINT32(logp, (afs_int32) p4);
821 #endif /* AFS_OSF_ENV */
823 ICL_APPENDLONG(logp, p4);
825 ReleaseWriteLock(&logp->lock);
828 /* create a log with size logSize; return it in *outLogpp and tag
829 * it with name "name."
832 afs_icl_CreateLog(char *name, afs_int32 logSize,
833 struct afs_icl_log **outLogpp)
835 return afs_icl_CreateLogWithFlags(name, logSize, /*flags */ 0, outLogpp);
838 /* create a log with size logSize; return it in *outLogpp and tag
839 * it with name "name." 'flags' can be set to make the log unclearable.
842 afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, afs_uint32 flags,
843 struct afs_icl_log **outLogpp)
845 register struct afs_icl_log *logp;
847 /* add into global list under lock */
848 ObtainWriteLock(&afs_icl_lock, 183);
852 for (logp = afs_icl_allLogs; logp; logp = logp->nextp) {
853 if (strcmp(logp->name, name) == 0) {
854 /* found it already created, just return it */
857 if (flags & ICL_CRLOG_FLAG_PERSISTENT) {
858 ObtainWriteLock(&logp->lock, 184);
859 logp->states |= ICL_LOGF_PERSISTENT;
860 ReleaseWriteLock(&logp->lock);
862 ReleaseWriteLock(&afs_icl_lock);
867 logp = (struct afs_icl_log *)
868 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
869 memset((caddr_t) logp, 0, sizeof(*logp));
872 logp->name = osi_AllocSmallSpace(strlen(name) + 1);
873 strcpy(logp->name, name);
874 LOCK_INIT(&logp->lock, "logp lock");
875 logp->logSize = logSize;
876 logp->datap = NULL; /* don't allocate it until we need it */
878 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
879 logp->states |= ICL_LOGF_PERSISTENT;
881 logp->nextp = afs_icl_allLogs;
882 afs_icl_allLogs = logp;
883 ReleaseWriteLock(&afs_icl_lock);
889 /* called with a log, a pointer to a buffer, the size of the buffer
890 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
891 * and returns data in the provided buffer, and returns output flags
892 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
893 * find the record with cookie value cookie.
896 afs_icl_CopyOut(register struct afs_icl_log *logp, afs_int32 * bufferp,
897 afs_int32 * bufSizep, afs_uint32 * cookiep,
900 afs_int32 nwords; /* number of words to copy out */
901 afs_uint32 startCookie; /* first cookie to use */
902 afs_int32 outWords; /* words we've copied out */
903 afs_int32 inWords; /* max words to copy out */
904 afs_int32 code; /* return code */
905 afs_int32 ix; /* index we're copying from */
906 afs_int32 outFlags; /* return flags */
907 afs_int32 inFlags; /* flags passed in */
910 inWords = *bufSizep; /* max to copy out */
911 outWords = 0; /* amount copied out */
912 startCookie = *cookiep;
917 ObtainWriteLock(&logp->lock, 185);
919 ReleaseWriteLock(&logp->lock);
923 /* first, compute the index of the start cookie we've been passed */
925 /* (re-)compute where we should start */
926 if (startCookie < logp->baseCookie) {
927 if (startCookie) /* missed some output */
928 outFlags |= ICL_COPYOUTF_MISSEDSOME;
929 /* skip to the first available record */
930 startCookie = logp->baseCookie;
931 *cookiep = startCookie;
934 /* compute where we find the first element to copy out */
935 ix = logp->firstUsed + startCookie - logp->baseCookie;
936 if (ix >= logp->logSize)
939 /* if have some data now, break out and process it */
940 if (startCookie - logp->baseCookie < logp->logElements)
943 /* At end of log, so clear it if we need to */
944 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD) {
945 logp->firstUsed = logp->firstFree = 0;
946 logp->logElements = 0;
948 /* otherwise, either wait for the data to arrive, or return */
949 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
950 ReleaseWriteLock(&logp->lock);
954 logp->states |= ICL_LOGF_WAITING;
955 ReleaseWriteLock(&logp->lock);
956 afs_osi_Sleep(&logp->lock);
957 ObtainWriteLock(&logp->lock, 186);
959 /* copy out data from ix to logSize or firstFree, depending
960 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
961 * be careful not to copy out more than nwords.
963 if (ix >= logp->firstUsed) {
964 if (logp->firstUsed <= logp->firstFree)
966 end = logp->firstFree; /* first element not to copy */
969 nwords = inWords; /* don't copy more than this */
970 if (end - ix < nwords)
973 memcpy((char *)bufferp, (char *)&logp->datap[ix],
974 sizeof(afs_int32) * nwords);
979 /* if we're going to copy more out below, we'll start here */
982 /* now, if active part of the log has wrapped, there's more stuff
983 * starting at the head of the log. Copy out more from there.
985 if (logp->firstUsed > logp->firstFree && ix < logp->firstFree
987 /* (more to) copy out from the wrapped section at the
988 * start of the log. May get here even if didn't copy any
989 * above, if the cookie points directly into the wrapped section.
992 if (logp->firstFree - ix < nwords)
993 nwords = logp->firstFree - ix;
994 memcpy((char *)bufferp, (char *)&logp->datap[ix],
995 sizeof(afs_int32) * nwords);
1001 ReleaseWriteLock(&logp->lock);
1005 *bufSizep = outWords;
1011 /* return basic parameter information about a log */
1013 afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 * maxSizep,
1014 afs_int32 * curSizep)
1016 ObtainReadLock(&logp->lock);
1017 *maxSizep = logp->logSize;
1018 *curSizep = logp->logElements;
1019 ReleaseReadLock(&logp->lock);
1024 /* hold and release logs */
1026 afs_icl_LogHold(register struct afs_icl_log *logp)
1028 ObtainWriteLock(&afs_icl_lock, 187);
1030 ReleaseWriteLock(&afs_icl_lock);
1034 /* hold and release logs, called with lock already held */
1036 afs_icl_LogHoldNL(register struct afs_icl_log *logp)
1042 /* keep track of how many sets believe the log itself is allocated */
1044 afs_icl_LogUse(register struct afs_icl_log *logp)
1046 ObtainWriteLock(&logp->lock, 188);
1047 if (logp->setCount == 0) {
1048 /* this is the first set actually using the log -- allocate it */
1049 if (logp->logSize == 0) {
1050 /* we weren't passed in a hint and it wasn't set */
1051 logp->logSize = ICL_DEFAULT_LOGSIZE;
1054 (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
1055 #ifdef KERNEL_HAVE_PIN
1056 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
1060 ReleaseWriteLock(&logp->lock);
1064 /* decrement the number of real users of the log, free if possible */
1066 afs_icl_LogFreeUse(register struct afs_icl_log *logp)
1068 ObtainWriteLock(&logp->lock, 189);
1069 if (--logp->setCount == 0) {
1070 /* no more users -- free it (but keep log structure around) */
1071 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
1072 #ifdef KERNEL_HAVE_PIN
1073 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
1075 logp->firstUsed = logp->firstFree = 0;
1076 logp->logElements = 0;
1079 ReleaseWriteLock(&logp->lock);
1083 /* set the size of the log to 'logSize' */
1085 afs_icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
1087 ObtainWriteLock(&logp->lock, 190);
1089 /* nothing to worry about since it's not allocated */
1090 logp->logSize = logSize;
1093 logp->firstUsed = logp->firstFree = 0;
1094 logp->logElements = 0;
1096 /* free and allocate a new one */
1097 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
1098 #ifdef KERNEL_HAVE_PIN
1099 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
1102 (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
1103 #ifdef KERNEL_HAVE_PIN
1104 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
1106 logp->logSize = logSize;
1108 ReleaseWriteLock(&logp->lock);
1113 /* free a log. Called with afs_icl_lock locked. */
1115 afs_icl_ZapLog(register struct afs_icl_log *logp)
1117 register struct afs_icl_log **lpp, *tp;
1119 for (lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
1121 /* found the dude we want to remove */
1123 osi_FreeSmallSpace(logp->name);
1124 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
1125 #ifdef KERNEL_HAVE_PIN
1126 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
1128 osi_FreeSmallSpace(logp);
1129 break; /* won't find it twice */
1135 /* do the release, watching for deleted entries */
1137 afs_icl_LogRele(register struct afs_icl_log *logp)
1139 ObtainWriteLock(&afs_icl_lock, 191);
1140 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
1141 afs_icl_ZapLog(logp); /* destroys logp's lock! */
1143 ReleaseWriteLock(&afs_icl_lock);
1147 /* do the release, watching for deleted entries, log already held */
1149 afs_icl_LogReleNL(register struct afs_icl_log *logp)
1151 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
1152 afs_icl_ZapLog(logp); /* destroys logp's lock! */
1157 /* zero out the log */
1159 afs_icl_ZeroLog(register struct afs_icl_log *logp)
1161 ObtainWriteLock(&logp->lock, 192);
1162 logp->firstUsed = logp->firstFree = 0;
1163 logp->logElements = 0;
1164 logp->baseCookie = 0;
1165 ReleaseWriteLock(&logp->lock);
1169 /* free a log entry, and drop its reference count */
1171 afs_icl_LogFree(register struct afs_icl_log *logp)
1173 ObtainWriteLock(&logp->lock, 193);
1174 logp->states |= ICL_LOGF_DELETED;
1175 ReleaseWriteLock(&logp->lock);
1176 afs_icl_LogRele(logp);
1180 /* find a log by name, returning it held */
1181 struct afs_icl_log *
1182 afs_icl_FindLog(char *name)
1184 register struct afs_icl_log *tp;
1185 ObtainWriteLock(&afs_icl_lock, 194);
1186 for (tp = afs_icl_allLogs; tp; tp = tp->nextp) {
1187 if (strcmp(tp->name, name) == 0) {
1188 /* this is the dude we want */
1193 ReleaseWriteLock(&afs_icl_lock);
1198 afs_icl_EnumerateLogs(int (*aproc)
1199 (char *name, char *arock, struct afs_icl_log * tp),
1202 register struct afs_icl_log *tp;
1203 register afs_int32 code;
1206 ObtainWriteLock(&afs_icl_lock, 195);
1207 for (tp = afs_icl_allLogs; tp; tp = tp->nextp) {
1208 tp->refCount++; /* hold this guy */
1209 ReleaseWriteLock(&afs_icl_lock);
1210 ObtainReadLock(&tp->lock);
1211 code = (*aproc) (tp->name, arock, tp);
1212 ReleaseReadLock(&tp->lock);
1213 ObtainWriteLock(&afs_icl_lock, 196);
1214 if (--tp->refCount == 0)
1219 ReleaseWriteLock(&afs_icl_lock);
1223 struct afs_icl_set *afs_icl_allSets = 0;
1226 afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
1227 struct afs_icl_log *fatalLogp,
1228 struct afs_icl_set **outSetpp)
1230 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
1231 /*flags */ 0, outSetpp);
1234 /* create a set, given pointers to base and fatal logs, if any.
1235 * Logs are unlocked, but referenced, and *outSetpp is returned
1236 * referenced. Function bumps reference count on logs, since it
1237 * addds references from the new afs_icl_set. When the set is destroyed,
1238 * those references will be released.
1241 afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
1242 struct afs_icl_log *fatalLogp, afs_uint32 flags,
1243 struct afs_icl_set **outSetpp)
1245 register struct afs_icl_set *setp;
1247 afs_int32 states = ICL_DEFAULT_SET_STATES;
1249 ObtainWriteLock(&afs_icl_lock, 197);
1250 if (!afs_icl_inited)
1253 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
1254 if (strcmp(setp->name, name) == 0) {
1257 if (flags & ICL_CRSET_FLAG_PERSISTENT) {
1258 ObtainWriteLock(&setp->lock, 198);
1259 setp->states |= ICL_SETF_PERSISTENT;
1260 ReleaseWriteLock(&setp->lock);
1262 ReleaseWriteLock(&afs_icl_lock);
1267 /* determine initial state */
1268 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
1269 states = ICL_SETF_ACTIVE;
1270 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
1271 states = ICL_SETF_FREED;
1272 if (flags & ICL_CRSET_FLAG_PERSISTENT)
1273 states |= ICL_SETF_PERSISTENT;
1275 setp = (struct afs_icl_set *)osi_AllocSmallSpace(sizeof(struct afs_icl_set));
1276 memset((caddr_t) setp, 0, sizeof(*setp));
1278 if (states & ICL_SETF_FREED)
1279 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
1280 setp->states = states;
1282 LOCK_INIT(&setp->lock, "setp lock");
1283 /* next lock is obtained in wrong order, hierarchy-wise, but
1284 * it doesn't matter, since no one can find this lock yet, since
1285 * the afs_icl_lock is still held, and thus the obtain can't block.
1287 ObtainWriteLock(&setp->lock, 199);
1288 setp->name = osi_AllocSmallSpace(strlen(name) + 1);
1289 strcpy(setp->name, name);
1290 setp->nevents = ICL_DEFAULTEVENTS;
1291 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
1292 #ifdef KERNEL_HAVE_PIN
1293 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
1295 for (i = 0; i < ICL_DEFAULTEVENTS; i++)
1296 setp->eventFlags[i] = 0xff; /* default to enabled */
1298 /* update this global info under the afs_icl_lock */
1299 setp->nextp = afs_icl_allSets;
1300 afs_icl_allSets = setp;
1301 ReleaseWriteLock(&afs_icl_lock);
1303 /* set's basic lock is still held, so we can finish init */
1305 setp->logs[0] = baseLogp;
1306 afs_icl_LogHold(baseLogp);
1307 if (!(setp->states & ICL_SETF_FREED))
1308 afs_icl_LogUse(baseLogp); /* log is actually being used */
1311 setp->logs[1] = fatalLogp;
1312 afs_icl_LogHold(fatalLogp);
1313 if (!(setp->states & ICL_SETF_FREED))
1314 afs_icl_LogUse(fatalLogp); /* log is actually being used */
1316 ReleaseWriteLock(&setp->lock);
1322 /* function to change event enabling information for a particular set */
1324 afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
1328 ObtainWriteLock(&setp->lock, 200);
1329 if (!ICL_EVENTOK(setp, eventID)) {
1330 ReleaseWriteLock(&setp->lock);
1333 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
1335 *tp |= ICL_EVENTMASK(eventID);
1337 *tp &= ~(ICL_EVENTMASK(eventID));
1338 ReleaseWriteLock(&setp->lock);
1342 /* return indication of whether a particular event ID is enabled
1343 * for tracing. If *getValuep is set to 0, the event is disabled,
1344 * otherwise it is enabled. All events start out enabled by default.
1347 afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID, int *getValuep)
1349 ObtainReadLock(&setp->lock);
1350 if (!ICL_EVENTOK(setp, eventID)) {
1351 ReleaseWriteLock(&setp->lock);
1354 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
1358 ReleaseReadLock(&setp->lock);
1362 /* hold and release event sets */
1364 afs_icl_SetHold(register struct afs_icl_set *setp)
1366 ObtainWriteLock(&afs_icl_lock, 201);
1368 ReleaseWriteLock(&afs_icl_lock);
1372 /* free a set. Called with afs_icl_lock locked */
1374 afs_icl_ZapSet(register struct afs_icl_set *setp)
1376 register struct afs_icl_set **lpp, *tp;
1378 register struct afs_icl_log *tlp;
1380 for (lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
1382 /* found the dude we want to remove */
1384 osi_FreeSmallSpace(setp->name);
1385 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
1386 #ifdef KERNEL_HAVE_PIN
1387 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
1389 for (i = 0; i < ICL_LOGSPERSET; i++) {
1390 if ((tlp = setp->logs[i]))
1391 afs_icl_LogReleNL(tlp);
1393 osi_FreeSmallSpace(setp);
1394 break; /* won't find it twice */
1400 /* do the release, watching for deleted entries */
1402 afs_icl_SetRele(register struct afs_icl_set *setp)
1404 ObtainWriteLock(&afs_icl_lock, 202);
1405 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
1406 afs_icl_ZapSet(setp); /* destroys setp's lock! */
1408 ReleaseWriteLock(&afs_icl_lock);
1412 /* free a set entry, dropping its reference count */
1414 afs_icl_SetFree(register struct afs_icl_set *setp)
1416 ObtainWriteLock(&setp->lock, 203);
1417 setp->states |= ICL_SETF_DELETED;
1418 ReleaseWriteLock(&setp->lock);
1419 afs_icl_SetRele(setp);
1423 /* find a set by name, returning it held */
1424 struct afs_icl_set *
1425 afs_icl_FindSet(char *name)
1427 register struct afs_icl_set *tp;
1428 ObtainWriteLock(&afs_icl_lock, 204);
1429 for (tp = afs_icl_allSets; tp; tp = tp->nextp) {
1430 if (strcmp(tp->name, name) == 0) {
1431 /* this is the dude we want */
1436 ReleaseWriteLock(&afs_icl_lock);
1440 /* zero out all the logs in the set */
1442 afs_icl_ZeroSet(struct afs_icl_set *setp)
1447 struct afs_icl_log *logp;
1449 ObtainReadLock(&setp->lock);
1450 for (i = 0; i < ICL_LOGSPERSET; i++) {
1451 logp = setp->logs[i];
1453 afs_icl_LogHold(logp);
1454 tcode = afs_icl_ZeroLog(logp);
1456 code = tcode; /* save the last bad one */
1457 afs_icl_LogRele(logp);
1460 ReleaseReadLock(&setp->lock);
1465 afs_icl_EnumerateSets(int (*aproc)
1466 (char *name, char *arock, struct afs_icl_log * tp),
1469 register struct afs_icl_set *tp, *np;
1470 register afs_int32 code;
1473 ObtainWriteLock(&afs_icl_lock, 205);
1474 for (tp = afs_icl_allSets; tp; tp = np) {
1475 tp->refCount++; /* hold this guy */
1476 ReleaseWriteLock(&afs_icl_lock);
1477 code = (*aproc) (tp->name, arock, (struct afs_icl_log *)tp);
1478 ObtainWriteLock(&afs_icl_lock, 206);
1479 np = tp->nextp; /* tp may disappear next, but not np */
1480 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
1485 ReleaseWriteLock(&afs_icl_lock);
1490 afs_icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
1495 ObtainWriteLock(&setp->lock, 207);
1496 for (i = 0; i < ICL_LOGSPERSET; i++) {
1497 if (!setp->logs[i]) {
1498 setp->logs[i] = newlogp;
1500 afs_icl_LogHold(newlogp);
1501 if (!(setp->states & ICL_SETF_FREED)) {
1502 /* bump up the number of sets using the log */
1503 afs_icl_LogUse(newlogp);
1508 ReleaseWriteLock(&setp->lock);
1513 afs_icl_SetSetStat(struct afs_icl_set *setp, int op)
1517 struct afs_icl_log *logp;
1519 ObtainWriteLock(&setp->lock, 208);
1521 case ICL_OP_SS_ACTIVATE: /* activate a log */
1523 * If we are not already active, see if we have released
1524 * our demand that the log be allocated (FREED set). If
1525 * we have, reassert our desire.
1527 if (!(setp->states & ICL_SETF_ACTIVE)) {
1528 if (setp->states & ICL_SETF_FREED) {
1529 /* have to reassert desire for logs */
1530 for (i = 0; i < ICL_LOGSPERSET; i++) {
1531 logp = setp->logs[i];
1533 afs_icl_LogHold(logp);
1534 afs_icl_LogUse(logp);
1535 afs_icl_LogRele(logp);
1538 setp->states &= ~ICL_SETF_FREED;
1540 setp->states |= ICL_SETF_ACTIVE;
1545 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
1546 /* this doesn't require anything beyond clearing the ACTIVE flag */
1547 setp->states &= ~ICL_SETF_ACTIVE;
1551 case ICL_OP_SS_FREE: /* deassert design for log */
1553 * if we are already in this state, do nothing; otherwise
1554 * deassert desire for log
1556 if (setp->states & ICL_SETF_ACTIVE)
1559 if (!(setp->states & ICL_SETF_FREED)) {
1560 for (i = 0; i < ICL_LOGSPERSET; i++) {
1561 logp = setp->logs[i];
1563 afs_icl_LogHold(logp);
1564 afs_icl_LogFreeUse(logp);
1565 afs_icl_LogRele(logp);
1568 setp->states |= ICL_SETF_FREED;
1577 ReleaseWriteLock(&setp->lock);