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"
15 #include "afs/sysincludes.h" /* Standard vendor system headers */
16 #include "afsincludes.h" /* Afs-based standard headers */
17 #include "afs/afs_stats.h"
18 #include "rx/rx_globals.h"
19 #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
22 #include "h/hashing.h"
24 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN60_ENV)
25 #include "netinet/in_var.h"
27 #endif /* !defined(UKERNEL) */
28 #ifdef AFS_LINUX22_ENV
29 #include "h/smp_lock.h"
33 #if defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
34 #define AFS_MINBUFFERS 100
36 #define AFS_MINBUFFERS 50
40 afs_int32 hosts[MAXCELLHOSTS];
44 char afs_zeros[AFS_ZEROS];
45 char afs_rootVolumeName[64]="";
46 struct afs_icl_set *afs_iclSetp = (struct afs_icl_set*)0;
47 struct afs_icl_set *afs_iclLongTermSetp = (struct afs_icl_set*)0;
49 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
50 kmutex_t afs_global_lock;
51 kmutex_t afs_rxglobal_lock;
54 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
55 long afs_global_owner;
58 #if defined(AFS_OSF_ENV)
59 simple_lock_data_t afs_global_lock;
62 #if defined(AFS_DARWIN_ENV)
63 struct lock__bsd__ afs_global_lock;
66 #if defined(AFS_XBSD_ENV)
67 struct lock afs_global_lock;
69 struct thread *afs_global_owner;
71 struct proc *afs_global_owner;
75 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
76 thread_t afs_global_owner;
77 #endif /* AFS_OSF_ENV */
79 #if defined(AFS_AIX41_ENV)
80 simple_lock_data afs_global_lock;
83 afs_int32 afs_initState = 0;
84 afs_int32 afs_termState = 0;
85 afs_int32 afs_setTime = 0;
86 int afs_cold_shutdown = 0;
87 char afs_SynchronousCloses = '\0';
88 static int afs_CB_Running = 0;
89 static int AFS_Running = 0;
90 static int afs_CacheInit_Done = 0;
91 static int afs_Go_Done = 0;
92 extern struct interfaceAddr afs_cb_interface;
93 static int afs_RX_Running = 0;
94 static int afs_InitSetup_done = 0;
96 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
97 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
100 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval);
102 #if defined(AFS_HPUX_ENV)
103 extern int afs_vfs_mount();
104 #endif /* defined(AFS_HPUX_ENV) */
106 /* This is code which needs to be called once when the first daemon enters
107 * the client. A non-zero return means an error and AFS should not start.
109 static int afs_InitSetup(int preallocs)
111 extern void afs_InitStats();
114 if (afs_InitSetup_done)
119 * Set up all the AFS statistics variables. This should be done
120 * exactly once, and it should be done here, the first resource-setting
121 * routine to be called by the CM/RX.
124 #endif /* AFS_NOSTATS */
126 memset(afs_zeros, 0, AFS_ZEROS);
129 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
130 code = rx_Init(htons(7001));
132 printf("AFS: RX failed to initialize.\n");
135 rx_SetRxDeadTime(afs_rx_deadtime);
136 /* resource init creates the services */
137 afs_ResourceInit(preallocs);
139 afs_InitSetup_done = 1;
140 afs_osi_Wakeup(&afs_InitSetup_done);
145 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)
146 struct afsd_thread_info {
148 struct completion *complete;
151 static int afsd_thread(void *rock) {
152 struct afsd_thread_info *arg=rock;
153 unsigned long parm=arg->parm;
154 #ifdef SYS_SETPRIORITY_EXPORTED
155 int (*sys_setpriority)(int,int,int) = sys_call_table[__NR_setpriority];
157 daemonize(); /* doesn't do much, since we were forked from keventd, but
158 does call mm_release, which wakes up our parent (since it
161 afs_osi_MaskSignals();
163 case AFSOP_START_RXCALLBACK:
164 sprintf(current->comm, "afs_cbstart");
166 complete(arg->complete);
168 while (afs_RX_Running != 2)
169 afs_osi_Sleep(&afs_RX_Running);
170 sprintf(current->comm, "afs_callback");
171 afs_RXCallBackServer();
173 complete_and_exit(0,0);
175 case AFSOP_START_AFS:
176 sprintf(current->comm, "afs_afsstart");
178 complete(arg->complete);
180 while (afs_initState < AFSOP_START_AFS)
181 afs_osi_Sleep(&afs_initState);
182 afs_initState = AFSOP_START_BKG;
183 afs_osi_Wakeup(&afs_initState);
184 sprintf(current->comm, "afsd");
187 complete_and_exit(0,0);
189 case AFSOP_START_BKG:
190 sprintf(current->comm, "afs_bkgstart");
192 complete(arg->complete);
193 while (afs_initState < AFSOP_START_BKG)
194 afs_osi_Sleep(&afs_initState);
195 if (afs_initState < AFSOP_GO) {
196 afs_initState = AFSOP_GO;
197 afs_osi_Wakeup(&afs_initState);
199 sprintf(current->comm, "afs_background");
200 afs_BackgroundDaemon();
202 complete_and_exit(0,0);
204 case AFSOP_START_TRUNCDAEMON:
205 sprintf(current->comm, "afs_trimstart");
207 complete(arg->complete);
208 while (afs_initState < AFSOP_GO)
209 afs_osi_Sleep(&afs_initState);
210 sprintf(current->comm, "afs_cachetrim");
211 afs_CacheTruncateDaemon();
213 complete_and_exit(0,0);
216 sprintf(current->comm, "afs_checkserver");
218 complete(arg->complete);
219 afs_CheckServerDaemon();
221 complete_and_exit(0,0);
223 case AFSOP_RXEVENT_DAEMON:
224 sprintf(current->comm, "afs_evtstart");
225 #ifdef SYS_SETPRIORITY_EXPORTED
226 sys_setpriority(PRIO_PROCESS,0,-10);
228 #ifdef CURRENT_INCLUDES_NICE
233 complete(arg->complete);
234 while (afs_initState < AFSOP_START_BKG)
235 afs_osi_Sleep(&afs_initState);
236 sprintf(current->comm, "afs_rxevent");
237 afs_rxevent_daemon();
239 complete_and_exit(0,0);
241 case AFSOP_RXLISTENER_DAEMON:
242 sprintf(current->comm, "afs_lsnstart");
243 #ifdef SYS_SETPRIORITY_EXPORTED
244 sys_setpriority(PRIO_PROCESS,0,-10);
246 #ifdef CURRENT_INCLUDES_NICE
251 complete(arg->complete);
252 afs_initState = AFSOP_START_AFS;
253 afs_osi_Wakeup(&afs_initState);
255 afs_osi_Wakeup(&afs_RX_Running);
256 afs_osi_RxkRegister();
257 sprintf(current->comm, "afs_rxlistener");
260 complete_and_exit(0,0);
263 printf("Unknown op %d in StartDaemon()\n");
269 void afsd_launcher(void *rock) {
270 if (!kernel_thread(afsd_thread,rock, CLONE_VFORK|SIGCHLD))
271 printf("kernel_thread failed. afs startup will not complete\n");
274 void afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
278 DECLARE_COMPLETION(c);
280 struct afsd_thread_info info;
281 if (parm == AFSOP_START_RXCALLBACK) {
282 if (afs_CB_Running) return;
283 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
284 if (afs_RX_Running) return;
286 code = afs_InitSetup(parm2);
288 rx_enablePeerRPCStats();
291 rx_enableProcessRPCStats();
295 } else if (parm == AFSOP_START_AFS) {
296 if (AFS_Running) return;
297 } /* other functions don't need setup in the parent */
301 INIT_LIST_HEAD(&tq.list);
302 tq.routine=afsd_launcher;
306 /* we need to wait cause we passed stack pointers around.... */
307 wait_for_completion(&c);
312 /* leaving as is, probably will barf if we add prototypes here since it's likely being called
315 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
316 long parm, parm2, parm3, parm4, parm5, parm6;
319 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
321 #else /* AFS_SGI61_ENV */
323 #endif /* AFS_SGI61_ENV */
325 AFS_STATCNT(afs_syscall_call);
327 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
328 && (parm != AFSOP_GETMASK)) {
329 /* only root can run this code */
332 if (!afs_suser() && (parm != AFSOP_GETMTU)
333 && (parm != AFSOP_GETMASK)) {
334 /* only root can run this code */
335 #if defined(KERNEL_HAVE_UERROR)
339 #if defined(AFS_OSF_ENV)
341 #else /* AFS_OSF_ENV */
343 #endif /* AFS_OSF_ENV */
348 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS) && !defined(UKERNEL)
349 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
350 || parm == AFSOP_RXLISTENER_DAEMON) {
351 afs_DaemonOp(parm,parm2,parm3,parm4,parm5,parm6);
353 #else /* !(AFS_LINUX24_ENV && !UKERNEL) */
354 if (parm == AFSOP_START_RXCALLBACK) {
355 if (afs_CB_Running) goto out;
357 #ifndef RXK_LISTENER_ENV
358 code = afs_InitSetup(parm2);
360 #endif /* !RXK_LISTENER_ENV */
362 #ifdef RXK_LISTENER_ENV
363 while (afs_RX_Running != 2)
364 afs_osi_Sleep(&afs_RX_Running);
365 #else /* !RXK_LISTENER_ENV */
366 afs_initState = AFSOP_START_AFS;
367 afs_osi_Wakeup(&afs_initState);
368 #endif /* RXK_LISTENER_ENV */
370 afs_RXCallBackServer();
374 exit(CLD_EXITED, code);
375 #endif /* AFS_SGI_ENV */
377 #ifdef RXK_LISTENER_ENV
378 else if (parm == AFSOP_RXLISTENER_DAEMON) {
379 if (afs_RX_Running) goto out;
381 code = afs_InitSetup(parm2);
383 rx_enablePeerRPCStats();
386 rx_enableProcessRPCStats();
389 afs_initState = AFSOP_START_AFS;
390 afs_osi_Wakeup(&afs_initState);
393 afs_osi_Wakeup(&afs_RX_Running);
395 afs_osi_RxkRegister();
396 #endif /* !UKERNEL */
401 exit(CLD_EXITED, code);
402 #endif /* AFS_SGI_ENV */
404 #endif /* RXK_LISTENER_ENV */
405 else if (parm == AFSOP_START_AFS) {
407 if (AFS_Running) goto out;
409 while (afs_initState < AFSOP_START_AFS)
410 afs_osi_Sleep(&afs_initState);
412 afs_initState = AFSOP_START_BKG;
413 afs_osi_Wakeup(&afs_initState);
419 #endif /* AFS_SGI_ENV */
421 else if (parm == AFSOP_START_CS) {
423 afs_CheckServerDaemon();
427 #endif /* AFS_SGI_ENV */
429 else if (parm == AFSOP_START_BKG) {
430 while (afs_initState < AFSOP_START_BKG)
431 afs_osi_Sleep(&afs_initState);
432 if (afs_initState < AFSOP_GO) {
433 afs_initState = AFSOP_GO;
434 afs_osi_Wakeup(&afs_initState);
436 /* start the bkg daemon */
440 afs_BioDaemon(parm2);
442 #endif /* AFS_AIX32_ENV */
443 afs_BackgroundDaemon();
447 #endif /* AFS_SGI_ENV */
449 else if (parm == AFSOP_START_TRUNCDAEMON) {
450 while (afs_initState < AFSOP_GO)
451 afs_osi_Sleep(&afs_initState);
452 /* start the bkg daemon */
454 afs_CacheTruncateDaemon();
458 #endif /* AFS_SGI_ENV */
460 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
461 else if (parm == AFSOP_RXEVENT_DAEMON) {
462 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
464 afs_rxevent_daemon();
468 #endif /* AFS_SGI_ENV */
470 #endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
471 #endif /* AFS_LINUX24_ENV && !UKERNEL */
472 else if (parm == AFSOP_BASIC_INIT) {
475 while (!afs_InitSetup_done)
476 afs_osi_Sleep(&afs_InitSetup_done);
478 #if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
479 temp = AFS_MINBUFFERS; /* Should fix this soon */
481 /* number of 2k buffers we could get from all of the buffer space */
482 temp = ((afs_bufferpages * NBPG)>>11);
483 temp = temp>>2; /* don't take more than 25% (our magic parameter) */
484 if (temp < AFS_MINBUFFERS)
485 temp = AFS_MINBUFFERS; /* though we really should have this many */
488 afs_rootFid.Fid.Volume = 0;
491 else if (parm == AFSOP_ADDCELL) {
492 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
493 name. Parameter 4 is the length of the name, including the null. Parm 5 is the
494 home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
495 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
497 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts), code);
499 if (parm4 > sizeof(tcell->cellName))
502 AFS_COPYIN((char *)parm3, tcell->cellName, parm4, code);
504 afs_NewCell(tcell->cellName, tcell->hosts, parm5,
508 afs_osi_Free(tcell, sizeof(struct afsop_cell));
509 } else if (parm == AFSOP_ADDCELL2) {
510 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
511 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
512 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
516 /* wait for basic init - XXX can't find any reason we need this? */
517 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
520 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts), code);
522 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, &bufferSize, code);
525 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
528 cflags |= CLinkedCell;
532 code = afs_NewCell(tbuffer1, tcell->hosts, cflags,
536 afs_osi_Free(tcell, sizeof(struct afsop_cell));
537 osi_FreeSmallSpace(tbuffer);
538 osi_FreeSmallSpace(tbuffer1);
540 else if (parm == AFSOP_ADDCELLALIAS) {
543 * parm2 is the alias name
544 * parm3 is the real cell name
546 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
547 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
549 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize, code);
550 if (!code) AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ, &bufferSize, code);
551 if (!code) afs_NewCellAlias(aliasName, cellName);
552 osi_FreeSmallSpace(aliasName);
553 osi_FreeSmallSpace(cellName);
555 else if (parm == AFSOP_SET_THISCELL) {
558 * parm2 is the primary cell name
560 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
562 AFS_COPYINSTR((char *) parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code);
564 afs_SetPrimaryCell(cell);
565 osi_FreeSmallSpace(cell);
567 else if (parm == AFSOP_CACHEINIT) {
568 struct afs_cacheParams cparms;
570 if (afs_CacheInit_Done) goto out;
572 AFS_COPYIN((char *)parm2, (caddr_t) &cparms, sizeof(cparms), code);
574 #if defined(KERNEL_HAVE_UERROR)
580 afs_CacheInit_Done = 1;
582 struct afs_icl_log *logp;
583 /* initialize the ICL system */
584 code = afs_icl_CreateLog("cmfx", 60*1024, &logp);
586 code = afs_icl_CreateSetWithFlags("cm", logp, NULL,
587 ICL_CRSET_FLAG_DEFAULT_OFF,
589 code = afs_icl_CreateSet("cmlongterm", logp, NULL,
590 &afs_iclLongTermSetp);
592 afs_setTime = cparms.setTimeFlag;
594 code = afs_CacheInit(cparms.cacheScaches,
605 else if (parm == AFSOP_CACHEINODE) {
606 ino_t ainode = parm2;
607 /* wait for basic init */
608 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
612 ainode = (ainode << 32) | (parm3 & 0xffffffff);
614 code = afs_InitCacheFile(NULL, ainode);
616 else if (parm == AFSOP_ROOTVOLUME) {
617 /* wait for basic init */
618 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
621 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code);
622 afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0;
626 else if (parm == AFSOP_CACHEFILE ||
627 parm == AFSOP_CACHEINFO ||
628 parm == AFSOP_VOLUMEINFO ||
629 parm == AFSOP_AFSLOG ||
630 parm == AFSOP_CELLINFO) {
631 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
634 AFS_COPYINSTR((char *) parm2, tbuffer, AFS_SMALLOCSIZ,
637 osi_FreeSmallSpace(tbuffer);
641 tbuffer[AFS_SMALLOCSIZ-1] = '\0'; /* null-terminate the name */
642 /* We have the cache dir copied in. Call the cache init routine */
643 if (parm == AFSOP_CACHEFILE)
644 code = afs_InitCacheFile(tbuffer, 0);
645 else if (parm == AFSOP_CACHEINFO)
646 code = afs_InitCacheInfo(tbuffer);
647 else if (parm == AFSOP_VOLUMEINFO)
648 code = afs_InitVolumeInfo(tbuffer);
649 else if (parm == AFSOP_CELLINFO)
650 code = afs_InitCellInfo(tbuffer);
652 osi_FreeSmallSpace(tbuffer);
654 else if (parm == AFSOP_GO) {
655 /* the generic initialization calls come here. One parameter: should we do the
656 set-time operation on this workstation */
657 if (afs_Go_Done) goto out;
659 while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState);
662 afs_osi_Wakeup(&afs_initState);
663 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
664 afs_nfsclient_init();
666 printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused,
667 (100*afs_stats_cmperf.cacheFilesReused) /
668 (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1));
670 else if (parm == AFSOP_ADVISEADDR) {
671 /* pass in the host address to the rx package */
672 afs_int32 count = parm2;
673 afs_int32 *buffer = afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
674 afs_int32 *maskbuffer = afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
675 afs_int32 *mtubuffer = afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
679 if ( count > AFS_MAX_INTERFACE_ADDR ) {
681 count = AFS_MAX_INTERFACE_ADDR;
684 AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code);
686 AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code);
688 AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code);
690 afs_cb_interface.numberOfInterfaces = count;
691 for (i=0; i < count ; i++) {
692 afs_cb_interface.addr_in[i] = buffer[i];
693 #ifdef AFS_USERSPACE_IP_ADDR
694 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
695 * machines IP addresses when in the kernel (the in_ifaddr
696 * struct is not available), so we pass the info in at
697 * startup. We also pass in the subnetmask and mtu size. The
698 * subnetmask is used when setting the rank:
699 * afsi_SetServerIPRank(); and the mtu size is used when
700 * finding the best mtu size. rxi_FindIfnet() is replaced
701 * with rxi_Findcbi().
703 afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff);
704 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
707 afs_uuid_create(&afs_cb_interface.uuid);
708 rxi_setaddr(buffer[0]);
709 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
710 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
711 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
715 else if (parm == AFSOP_NFSSTATICADDR) {
716 extern int (*nfs_rfsdisptab_v2)();
717 nfs_rfsdisptab_v2 = (int (*)())parm2;
719 else if (parm == AFSOP_NFSSTATICADDR2) {
720 extern int (*nfs_rfsdisptab_v2)();
722 nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
724 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
727 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
728 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
729 extern int (*afs_sblockp)();
730 extern void (*afs_sbunlockp)();
732 afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
733 afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff));
735 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
736 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
739 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
740 #endif /* AFS_SGI53_ENV */
741 else if (parm == AFSOP_SHUTDOWN) {
742 afs_cold_shutdown = 0;
743 if (parm == 1) afs_cold_shutdown = 1;
744 #ifndef AFS_DARWIN_ENV
745 if (afs_globalVFS != 0) {
746 afs_warn("AFS isn't unmounted yet! Call aborted\n");
752 else if (parm == AFSOP_AFS_VFSMOUNT) {
754 vfsmount(parm2, parm3, parm4, parm5);
755 #else /* defined(AFS_HPUX_ENV) */
756 #if defined(KERNEL_HAVE_UERROR)
761 #endif /* defined(AFS_HPUX_ENV) */
763 else if (parm == AFSOP_CLOSEWAIT) {
764 afs_SynchronousCloses = 'S';
766 else if (parm == AFSOP_GETMTU) {
768 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
769 #ifdef AFS_USERSPACE_IP_ADDR
771 i = rxi_Findcbi(parm2);
772 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
773 #else /* AFS_USERSPACE_IP_ADDR */
776 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
777 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
778 #endif /* else AFS_USERSPACE_IP_ADDR */
779 #endif /* !AFS_SUN5_ENV */
781 AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code);
783 /* this is disabled for now because I can't figure out how to get access
784 * to these kernel variables. It's only for supporting user-mode rx
785 * programs -- it makes a huge difference on the 220's in my testbed,
786 * though I don't know why. The bosserver does this with /etc/no, so it's
787 * being handled a different way for the servers right now. */
790 extern u_long sb_max_dflt;
793 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
794 if (sb_max < 131072) sb_max = 131072;
797 #endif /* AFS_AIX32_ENV */
799 else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
801 #if !defined(AFS_SUN5_ENV)
802 #ifdef AFS_USERSPACE_IP_ADDR
804 i = rxi_Findcbi(parm2);
806 mask = afs_cb_interface.subnetmask[i];
810 #else /* AFS_USERSPACE_IP_ADDR */
813 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
816 #endif /* else AFS_USERSPACE_IP_ADDR */
817 #endif /* !AFS_SUN5_ENV */
819 AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code);
822 else if (parm == AFSOP_AFSDB_HANDLER) {
823 int sizeArg = (int)parm4;
824 int kmsgLen = sizeArg & 0xffff;
825 int cellLen = (sizeArg & 0xffff0000) >> 16;
826 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
827 char *cellname = afs_osi_Alloc(cellLen);
830 afs_osi_MaskSignals();
832 AFS_COPYIN((afs_int32 *)parm2, cellname, cellLen, code);
833 AFS_COPYIN((afs_int32 *)parm3, kmsg, kmsgLen, code);
835 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
836 if (*cellname == 1) *cellname = 0;
837 if (code == -2) { /* Shutting down? */
842 if (!code) AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
843 afs_osi_Free(kmsg, kmsgLen);
844 afs_osi_Free(cellname, cellLen);
847 else if (parm == AFSOP_SET_DYNROOT) {
848 code = afs_SetDynrootEnable(parm2);
850 else if (parm == AFSOP_SET_FAKESTAT) {
851 afs_fakestat_enable = parm2;
859 #ifdef AFS_LINUX20_ENV
868 #include "sys/lockl.h"
871 * syscall - this is the VRMIX system call entry point.
874 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
875 * all the user-level calls to `syscall' to change.
877 syscall(syscall, p1, p2, p3, p4, p5, p6) {
878 register rval1=0, code;
881 #ifndef AFS_AIX41_ENV
882 extern lock_t kernel_lock;
883 monster = lockl(&kernel_lock, LOCK_SHORT);
884 #endif /* !AFS_AIX41_ENV */
886 AFS_STATCNT(syscall);
890 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
895 rval1 = afs_setpag();
901 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
905 case AFSCALL_ICREATE:
906 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
910 rval1 = afs_syscall_iopen(p1, p2, p3);
914 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
918 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
923 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
925 if (!code) rval1 = retval;
926 if (!rval1) rval1 = code;
936 #ifndef AFS_AIX41_ENV
937 if (monster != LOCK_NEST)
938 unlockl(&kernel_lock);
939 #endif /* !AFS_AIX41_ENV */
940 return getuerror() ? -1 : rval1;
944 * lsetpag - interface to afs_setpag().
948 AFS_STATCNT(lsetpag);
949 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
953 * lpioctl - interface to pioctl()
955 lpioctl(path, cmd, cmarg, follow)
956 char *path, *cmarg; {
958 AFS_STATCNT(lpioctl);
959 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
962 #else /* !AFS_AIX32_ENV */
964 #if defined(AFS_SGI_ENV)
977 Afs_syscall (struct afsargs *uap, rval_t *rvp)
982 AFS_STATCNT(afs_syscall);
983 switch(uap->syscall) {
987 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
989 rvp->r_val1 = retval;
991 #ifdef AFS_SGI_XFS_IOPS_ENV
993 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
994 uap->parm4, uap->parm5);
997 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
998 uap->parm4, uap->parm5);
1000 case AFSCALL_ILISTINODE64:
1001 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
1002 uap->parm4, uap->parm5);
1004 case AFSCALL_ICREATENAME64:
1005 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
1006 uap->parm4, uap->parm5);
1009 #ifdef AFS_SGI_VNODE_GLUE
1010 case AFSCALL_INIT_KERNEL_CONFIG:
1011 error = afs_init_kernel_config(uap->parm1);
1015 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
1016 uap->parm3, uap->parm4, uap->parm5);
1021 #else /* AFS_SGI_ENV */
1039 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
1041 dst->param1 = src->param1;
1042 dst->param2 = src->param2;
1043 dst->param3 = src->param3;
1044 dst->param4 = src->param4;
1048 * If you need to change copyin_iparam(), you may also need to change
1049 * copyin_afs_ioctl().
1053 copyin_iparam(caddr_t cmarg, struct iparam *dst)
1057 #if defined(AFS_HPUX_64BIT_ENV)
1058 struct iparam32 dst32;
1060 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
1062 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
1064 iparam32_to_iparam(&dst32, dst);
1067 #endif /* AFS_HPUX_64BIT_ENV */
1069 #if defined(AFS_SUN57_64BIT_ENV)
1070 struct iparam32 dst32;
1072 if (get_udatamodel() == DATAMODEL_ILP32) {
1073 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
1075 iparam32_to_iparam(&dst32, dst);
1078 #endif /* AFS_SUN57_64BIT_ENV */
1080 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
1081 struct iparam32 dst32;
1083 #ifdef AFS_SPARC64_LINUX24_ENV
1084 if (current->thread.flags & SPARC_FLAG_32BIT)
1085 #elif defined(AFS_SPARC64_LINUX20_ENV)
1086 if (current->tss.flags & SPARC_FLAG_32BIT)
1087 #elif defined(AFS_AMD64_LINUX20_ENV)
1088 if (current->thread.flags & THREAD_IA32)
1090 #error Not done for this linux version
1093 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
1095 iparam32_to_iparam(&dst32, dst);
1098 #endif /* AFS_LINUX_64BIT_KERNEL */
1100 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
1104 /* Main entry of all afs system calls */
1106 extern int afs_sinited;
1108 /** The 32 bit OS expects the members of this structure to be 32 bit
1109 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
1110 * to accomodate both, *long* is used instead of afs_int32
1113 #ifdef AFS_SUN57_ENV
1135 Afs_syscall(register struct afssysa *uap, rval_t *rvp)
1137 int *retval = &rvp->r_val1;
1138 #else /* AFS_SUN5_ENV */
1139 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1141 afs3_syscall(p, args, retval)
1142 #ifdef AFS_FBSD50_ENV
1158 } *uap = (struct a *)args;
1159 #else /* AFS_OSF_ENV */
1160 #ifdef AFS_LINUX20_ENV
1168 long parm6; /* not actually used - should be removed */
1170 /* Linux system calls only set up for 5 arguments. */
1171 asmlinkage long afs_syscall(long syscall, long parm1, long parm2, long parm3,
1174 struct afssysargs args, *uap = &args;
1176 long *retval = &linux_ret;
1177 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
1178 #ifdef AFS_SPARC64_LINUX24_ENV
1179 afs_int32 eparm32[4];
1181 /* eparm is also used by AFSCALL_CALL in afsd.c */
1183 #if defined(UKERNEL)
1194 } *uap = (struct a *)u.u_ap;
1197 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
1201 #endif /* SUN && !SUN5 */
1211 } *uap = (struct a *)u.u_ap;
1212 #endif /* UKERNEL */
1213 #if defined(AFS_DEC_ENV)
1214 int *retval = &u.u_r.r_val1;
1215 #elif defined(AFS_HPUX_ENV)
1216 long *retval = &u.u_rval1;
1218 int *retval = &u.u_rval1;
1220 #endif /* AFS_LINUX20_ENV */
1221 #endif /* AFS_OSF_ENV */
1222 #endif /* AFS_SUN5_ENV */
1223 register int code = 0;
1225 AFS_STATCNT(afs_syscall);
1232 #ifdef AFS_LINUX20_ENV
1234 /* setup uap for use below - pull out the magic decoder ring to know
1235 * which syscalls have folded argument lists.
1237 uap->syscall = syscall;
1241 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
1242 #ifdef AFS_SPARC64_LINUX24_ENV
1243 /* from arch/sparc64/kernel/sys_sparc32.c */
1245 ({ unsigned long __ret; \
1246 __asm__ ("srl %0, 0, %0" \
1253 if (current->thread.flags & SPARC_FLAG_32BIT) {
1254 AFS_COPYIN((char*)parm4, (char*)eparm32, sizeof(eparm32), code);
1255 eparm[0]=AA(eparm32[0]);
1256 eparm[1]=AA(eparm32[1]);
1257 eparm[2]=AA(eparm32[2]);
1261 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
1262 uap->parm4 = eparm[0];
1263 uap->parm5 = eparm[1];
1264 uap->parm6 = eparm[2];
1273 #if defined(AFS_HPUX_ENV)
1275 * There used to be code here (duplicated from osi_Init()) for
1276 * initializing the semaphore used by AFS_GLOCK(). Was the
1277 * duplication to handle the case of a dynamically loaded kernel
1282 if (uap->syscall == AFSCALL_CALL) {
1284 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1285 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1287 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1289 } else if (uap->syscall == AFSCALL_SETPAG) {
1291 register proc_t *procp;
1293 procp = ttoproc(curthread);
1295 code = afs_setpag(&procp->p_cred);
1299 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1300 code = afs_setpag(p, args, retval);
1301 #else /* AFS_OSF_ENV */
1302 code = afs_setpag();
1306 } else if (uap->syscall == AFSCALL_PIOCTL) {
1308 #if defined(AFS_SUN5_ENV)
1309 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1310 #elif defined(AFS_FBSD50_ENV)
1311 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->td_ucred);
1312 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1313 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1315 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1318 } else if (uap->syscall == AFSCALL_ICREATE) {
1319 struct iparam iparams;
1321 code = copyin_iparam((char *)uap->parm3, &iparams);
1323 #if defined(KERNEL_HAVE_UERROR)
1328 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1329 iparams.param3, iparams.param4, rvp, CRED());
1331 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1332 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1333 iparams.param3, iparams.param4, retval);
1335 iparams.param3, iparams.param4);
1337 #endif /* AFS_SUN5_ENV */
1338 } else if (uap->syscall == AFSCALL_IOPEN) {
1340 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1342 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1343 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1345 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1347 #endif /* AFS_SUN5_ENV */
1348 } else if (uap->syscall == AFSCALL_IDEC) {
1350 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1352 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1353 #endif /* AFS_SUN5_ENV */
1354 } else if (uap->syscall == AFSCALL_IINC) {
1356 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1358 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1359 #endif /* AFS_SUN5_ENV */
1360 } else if (uap->syscall == AFSCALL_ICL) {
1362 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1364 #ifdef AFS_LINUX20_ENV
1366 /* ICL commands can return values. */
1367 code = -linux_ret; /* Gets negated again at exit below */
1371 #if defined(KERNEL_HAVE_UERROR)
1375 #endif /* !AFS_LINUX20_ENV */
1377 #if defined(KERNEL_HAVE_UERROR)
1384 #ifdef AFS_LINUX20_ENV
1390 #endif /* AFS_SGI_ENV */
1391 #endif /* !AFS_AIX32_ENV */
1394 * Initstate in the range 0 < x < 100 are early initialization states.
1395 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1396 * the cache may be initialized.
1397 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1398 * is done after all the cache initialization has been done.
1399 * Initstate of 200 means that the volume has been looked up once, possibly
1401 * Initstate of 300 means that the volume has been *successfully* looked up.
1403 int afs_CheckInit(void)
1405 register int code = 0;
1407 AFS_STATCNT(afs_CheckInit);
1408 if (afs_initState <= 100)
1409 code = ENXIO; /* never finished init phase */
1410 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1411 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1412 } else if (afs_initState == 200)
1413 code = ETIMEDOUT; /* didn't find root volume */
1417 int afs_shuttingdown = 0;
1418 void afs_shutdown(void)
1420 extern short afs_brsDaemons;
1421 extern afs_int32 afs_CheckServerDaemonStarted;
1422 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1423 extern struct osi_file *afs_cacheInodep;
1425 AFS_STATCNT(afs_shutdown);
1426 if (afs_shuttingdown) return;
1427 afs_shuttingdown = 1;
1428 if (afs_cold_shutdown) afs_warn("COLD ");
1429 else afs_warn("WARM ");
1430 afs_warn("shutting down of: CB... ");
1432 afs_termState = AFSOP_STOP_RXCALLBACK;
1433 rx_WakeupServerProcs();
1434 /* shutdown_rxkernel(); */
1435 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1436 afs_osi_Sleep(&afs_termState);
1438 afs_warn("afs... ");
1439 while (afs_termState == AFSOP_STOP_AFS) {
1440 afs_osi_CancelWait(&AFS_WaitHandler);
1441 afs_osi_Sleep(&afs_termState);
1443 if (afs_CheckServerDaemonStarted) {
1444 while (afs_termState == AFSOP_STOP_CS) {
1445 afs_osi_CancelWait(&AFS_CSWaitHandler);
1446 afs_osi_Sleep(&afs_termState);
1449 afs_warn("BkG... ");
1450 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1451 while (afs_termState == AFSOP_STOP_BKG) {
1452 afs_osi_Wakeup(&afs_brsDaemons);
1453 afs_osi_Sleep(&afs_termState);
1455 afs_warn("CTrunc... ");
1456 /* Cancel cache truncate daemon. */
1457 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1458 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1459 afs_osi_Sleep(&afs_termState);
1461 #ifdef AFS_AFSDB_ENV
1462 afs_warn("AFSDB... ");
1464 while (afs_termState == AFSOP_STOP_AFSDB)
1465 afs_osi_Sleep(&afs_termState);
1467 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1468 afs_warn("RxEvent... ");
1469 /* cancel rx event daemon */
1470 while (afs_termState == AFSOP_STOP_RXEVENT)
1471 afs_osi_Sleep(&afs_termState);
1472 #if defined(RXK_LISTENER_ENV)
1474 afs_warn("UnmaskRxkSignals... ");
1475 afs_osi_UnmaskRxkSignals();
1477 /* cancel rx listener */
1478 afs_warn("RxListener... ");
1479 osi_StopListener(); /* This closes rx_socket. */
1480 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1481 afs_warn("Sleep... ");
1482 afs_osi_Sleep(&afs_termState);
1486 afs_termState = AFSOP_STOP_COMPLETE;
1490 /* Close file only after daemons which can write to it are stopped. */
1491 if (afs_cacheInodep) /* memcache won't set this */
1493 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1494 afs_cacheInodep = 0;
1496 return; /* Just kill daemons for now */
1500 shutdown_rxkernel();
1504 shutdown_bufferpackage();
1510 shutdown_vnodeops();
1512 shutdown_exporter();
1513 shutdown_memcache();
1514 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1515 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1516 /* this routine does not exist in Ultrix systems... 93.01.19 */
1518 #endif /* AFS_DEC_ENV */
1521 /* The following hold the cm stats */
1523 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1524 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1525 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1527 afs_warn(" ALL allocated tables\n");
1528 afs_shuttingdown = 0;
1532 void shutdown_afstest(void)
1534 AFS_STATCNT(shutdown_afstest);
1535 afs_initState = afs_termState = afs_setTime = 0;
1536 AFS_Running = afs_CB_Running = 0;
1537 afs_CacheInit_Done = afs_Go_Done = 0;
1538 if (afs_cold_shutdown) {
1539 *afs_rootVolumeName = 0;
1544 /* In case there is a bunch of dynamically build bkg daemons to free */
1545 void afs_shutdown_BKG(void)
1547 AFS_STATCNT(shutdown_BKG);
1551 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1552 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1553 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1554 int afs_icl_sizeofLong = 1;
1556 int afs_icl_sizeofLong = 2;
1559 int afs_icl_sizeofLong = 1;
1562 int afs_icl_inited = 0;
1564 /* init function, called once, under afs_icl_lock */
1565 int afs_icl_Init(void)
1571 extern struct afs_icl_log *afs_icl_FindLog();
1572 extern struct afs_icl_set *afs_icl_FindSet();
1576 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1578 afs_int32 *lp, elts, flags;
1579 register afs_int32 code;
1580 struct afs_icl_log *logp;
1581 struct afs_icl_set *setp;
1582 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1584 #else /* AFS_SGI61_ENV */
1586 #endif /* AFS_SGI61_ENV */
1588 afs_int32 startCookie;
1589 afs_int32 allocated;
1590 struct afs_icl_log *tlp;
1593 if (!afs_suser(CRED())) { /* only root can run this code */
1597 if (!afs_suser()) { /* only root can run this code */
1598 #if defined(KERNEL_HAVE_UERROR)
1607 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1608 case ICL_OP_COPYOUT: /* copy ouy data */
1609 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1610 * return flags<<24 + nwords.
1611 * updates cookie to updated start (not end) if we had to
1612 * skip some records.
1614 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1615 if (code) return code;
1616 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1617 if (code) return code;
1618 logp = afs_icl_FindLog(tname);
1619 if (!logp) return ENOENT;
1620 #define BUFFERSIZE AFS_LRALLOCSIZ
1621 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1622 elts = BUFFERSIZE / sizeof(afs_int32);
1623 if (p3 < elts) elts = p3;
1624 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1625 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1628 osi_FreeLargeSpace((struct osi_buffer *) lp);
1631 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1632 if (code) goto done;
1633 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1634 if (code) goto done;
1635 *retval = (flags<<24) | (elts & 0xffffff);
1637 afs_icl_LogRele(logp);
1638 osi_FreeLargeSpace((struct osi_buffer *) lp);
1641 case ICL_OP_ENUMLOGS: /* enumerate logs */
1642 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1643 * return 0 for success, otherwise error.
1645 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1646 if (p1-- == 0) break;
1648 if (!tlp) return ENOENT; /* past the end of file */
1649 temp = strlen(tlp->name)+1;
1650 if (temp > p3) return EINVAL;
1651 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1652 if (!code) /* copy out size of log */
1653 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1656 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1657 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1658 * return 0 for success, otherwise error.
1660 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1661 if (code) return code;
1662 setp = afs_icl_FindSet(tname);
1663 if (!setp) return ENOENT;
1664 if (p2 > ICL_LOGSPERSET)
1666 if (!(tlp = setp->logs[p2]))
1668 temp = strlen(tlp->name)+1;
1669 if (temp > p4) return EINVAL;
1670 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1673 case ICL_OP_CLRLOG: /* clear specified log */
1674 /* zero out the specified log: p1=logname */
1675 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1676 if (code) return code;
1677 logp = afs_icl_FindLog(tname);
1678 if (!logp) return ENOENT;
1679 code = afs_icl_ZeroLog(logp);
1680 afs_icl_LogRele(logp);
1683 case ICL_OP_CLRSET: /* clear specified set */
1684 /* zero out the specified set: p1=setname */
1685 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1686 if (code) return code;
1687 setp = afs_icl_FindSet(tname);
1688 if (!setp) return ENOENT;
1689 code = afs_icl_ZeroSet(setp);
1690 afs_icl_SetRele(setp);
1693 case ICL_OP_CLRALL: /* clear all logs */
1694 /* zero out all logs -- no args */
1696 ObtainWriteLock(&afs_icl_lock,178);
1697 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1698 tlp->refCount++; /* hold this guy */
1699 ReleaseWriteLock(&afs_icl_lock);
1700 /* don't clear persistent logs */
1701 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1702 code = afs_icl_ZeroLog(tlp);
1703 ObtainWriteLock(&afs_icl_lock,179);
1704 if (--tlp->refCount == 0)
1705 afs_icl_ZapLog(tlp);
1708 ReleaseWriteLock(&afs_icl_lock);
1711 case ICL_OP_ENUMSETS: /* enumerate all sets */
1712 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1713 * return 0 for success, otherwise error.
1715 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1716 if (p1-- == 0) break;
1718 if (!setp) return ENOENT; /* past the end of file */
1719 temp = strlen(setp->name)+1;
1720 if (temp > p3) return EINVAL;
1721 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1722 if (!code) /* copy out size of log */
1723 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1726 case ICL_OP_SETSTAT: /* set status on a set */
1727 /* activate the specified set: p1=setname, p2=op */
1728 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1729 if (code) return code;
1730 setp = afs_icl_FindSet(tname);
1731 if (!setp) return ENOENT;
1732 code = afs_icl_SetSetStat(setp, p2);
1733 afs_icl_SetRele(setp);
1736 case ICL_OP_SETSTATALL: /* set status on all sets */
1737 /* activate the specified set: p1=op */
1739 ObtainWriteLock(&afs_icl_lock,180);
1740 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1741 setp->refCount++; /* hold this guy */
1742 ReleaseWriteLock(&afs_icl_lock);
1743 /* don't set states on persistent sets */
1744 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1745 code = afs_icl_SetSetStat(setp, p1);
1746 ObtainWriteLock(&afs_icl_lock,181);
1747 if (--setp->refCount == 0)
1748 afs_icl_ZapSet(setp);
1751 ReleaseWriteLock(&afs_icl_lock);
1754 case ICL_OP_SETLOGSIZE: /* set size of log */
1755 /* set the size of the specified log: p1=logname, p2=size (in words) */
1756 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1757 if (code) return code;
1758 logp = afs_icl_FindLog(tname);
1759 if (!logp) return ENOENT;
1760 code = afs_icl_LogSetSize(logp, p2);
1761 afs_icl_LogRele(logp);
1764 case ICL_OP_GETLOGINFO: /* get size of log */
1765 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1766 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1767 if (code) return code;
1768 logp = afs_icl_FindLog(tname);
1769 if (!logp) return ENOENT;
1770 allocated = !!logp->datap;
1771 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1773 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1774 afs_icl_LogRele(logp);
1777 case ICL_OP_GETSETINFO: /* get state of set */
1778 /* zero out the specified set: p1=setname, p2=&state */
1779 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1780 if (code) return code;
1781 setp = afs_icl_FindSet(tname);
1782 if (!setp) return ENOENT;
1783 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1784 afs_icl_SetRele(setp);
1795 afs_lock_t afs_icl_lock;
1797 /* exported routine: a 4 parameter event */
1798 int afs_icl_Event4(register struct afs_icl_set *setp, afs_int32 eventID,
1799 afs_int32 lAndT, long p1, long p2, long p3, long p4)
1803 register afs_int32 tmask;
1806 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1807 if (!ICL_SETACTIVE(setp))
1811 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1812 ix = ICL_EVENTBYTE(eventID);
1813 ObtainReadLock(&setp->lock);
1814 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1815 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1817 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1821 if (mask == 0) break; /* break early */
1824 ReleaseReadLock(&setp->lock);
1828 /* Next 4 routines should be implemented via var-args or something.
1829 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1830 * Otherwise, could call afs_icl_Event4 directly.
1832 int afs_icl_Event3(register struct afs_icl_set *setp, afs_int32 eventID,
1833 afs_int32 lAndT, long p1, long p2, long p3)
1835 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1838 int afs_icl_Event2(register struct afs_icl_set *setp, afs_int32 eventID,
1839 afs_int32 lAndT, long p1, long p2)
1841 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1844 int afs_icl_Event1(register struct afs_icl_set *setp, afs_int32 eventID,
1845 afs_int32 lAndT, long p1)
1847 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1850 int afs_icl_Event0(register struct afs_icl_set *setp, afs_int32 eventID,
1853 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1856 struct afs_icl_log *afs_icl_allLogs = 0;
1858 /* function to purge records from the start of the log, until there
1859 * is at least minSpace long's worth of space available without
1860 * making the head and the tail point to the same word.
1862 * Log must be write-locked.
1864 static void afs_icl_GetLogSpace(register struct afs_icl_log *logp, afs_int32 minSpace)
1866 register unsigned int tsize;
1868 while (logp->logSize - logp->logElements <= minSpace) {
1870 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1871 logp->logElements -= tsize;
1872 logp->firstUsed += tsize;
1873 if (logp->firstUsed >= logp->logSize)
1874 logp->firstUsed -= logp->logSize;
1875 logp->baseCookie += tsize;
1879 /* append string astr to buffer, including terminating null char.
1881 * log must be write-locked.
1883 #define ICL_CHARSPERLONG 4
1884 static void afs_icl_AppendString(struct afs_icl_log *logp, char *astr)
1886 char *op; /* ptr to char to write */
1888 register int bib; /* bytes in buffer */
1891 op = (char *) &(logp->datap[logp->firstFree]);
1895 if (++bib >= ICL_CHARSPERLONG) {
1898 if (++(logp->firstFree) >= logp->logSize) {
1899 logp->firstFree = 0;
1900 op = (char *) &(logp->datap[0]);
1902 logp->logElements++;
1907 /* if we've used this word at all, allocate it */
1908 if (++(logp->firstFree) >= logp->logSize) {
1909 logp->firstFree = 0;
1911 logp->logElements++;
1915 /* add a long to the log, ignoring overflow (checked already) */
1916 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1917 #define ICL_APPENDINT32(lp, x) \
1919 (lp)->datap[(lp)->firstFree] = (x); \
1920 if (++((lp)->firstFree) >= (lp)->logSize) { \
1921 (lp)->firstFree = 0; \
1923 (lp)->logElements++; \
1926 #define ICL_APPENDLONG(lp, x) \
1928 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1929 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1932 #else /* AFS_ALPHA_ENV */
1933 #define ICL_APPENDLONG(lp, x) \
1935 (lp)->datap[(lp)->firstFree] = (x); \
1936 if (++((lp)->firstFree) >= (lp)->logSize) { \
1937 (lp)->firstFree = 0; \
1939 (lp)->logElements++; \
1941 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1942 #endif /* AFS_ALPHA_ENV */
1944 /* routine to tell whether we're dealing with the address or the
1947 int afs_icl_UseAddr(int type)
1949 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1950 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
1956 /* Function to append a record to the log. Written for speed
1957 * since we know that we're going to have to make this work fast
1958 * pretty soon, anyway. The log must be unlocked.
1961 void afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
1962 afs_int32 types, long p1, long p2, long p3, long p4)
1964 int rsize; /* record size in longs */
1965 register int tsize; /* temp size */
1969 t4 = types & 0x3f; /* decode types */
1977 osi_GetTime(&tv); /* It panics for solaris if inside */
1978 ObtainWriteLock(&logp->lock,182);
1980 ReleaseWriteLock(&logp->lock);
1984 /* get timestamp as # of microseconds since some time that doesn't
1985 * change that often. This algorithm ticks over every 20 minutes
1986 * or so (1000 seconds). Write a timestamp record if it has.
1988 if (tv.tv_sec - logp->lastTS > 1024)
1990 /* the timer has wrapped -- write a timestamp record */
1991 if (logp->logSize - logp->logElements <= 5)
1992 afs_icl_GetLogSpace(logp, 5);
1994 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1995 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1996 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1997 ICL_APPENDINT32(logp,
1998 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1999 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
2001 logp->lastTS = tv.tv_sec;
2004 rsize = 4; /* base case */
2006 /* compute size of parameter p1. Only tricky case is string.
2007 * In that case, we have to call strlen to get the string length.
2009 ICL_SIZEHACK(t1, p1);
2012 /* compute size of parameter p2. Only tricky case is string.
2013 * In that case, we have to call strlen to get the string length.
2015 ICL_SIZEHACK(t2, p2);
2018 /* compute size of parameter p3. Only tricky case is string.
2019 * In that case, we have to call strlen to get the string length.
2021 ICL_SIZEHACK(t3, p3);
2024 /* compute size of parameter p4. Only tricky case is string.
2025 * In that case, we have to call strlen to get the string length.
2027 ICL_SIZEHACK(t4, p4);
2030 /* At this point, we've computed all of the parameter sizes, and
2031 * have in rsize the size of the entire record we want to append.
2032 * Next, we check that we actually have room in the log to do this
2033 * work, and then we do the append.
2036 ReleaseWriteLock(&logp->lock);
2037 return; /* log record too big to express */
2040 if (logp->logSize - logp->logElements <= rsize)
2041 afs_icl_GetLogSpace(logp, rsize);
2043 ICL_APPENDINT32(logp,
2044 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
2045 ICL_APPENDINT32(logp, (afs_int32)op);
2046 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
2047 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
2050 /* marshall parameter 1 now */
2051 if (t1 == ICL_TYPE_STRING) {
2052 afs_icl_AppendString(logp, (char *) p1);
2054 else if (t1 == ICL_TYPE_HYPER) {
2055 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
2056 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
2058 else if (t1 == ICL_TYPE_INT64) {
2059 #ifdef AFSLITTLE_ENDIAN
2060 #ifdef AFS_64BIT_CLIENT
2061 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2062 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2063 #else /* AFS_64BIT_CLIENT */
2064 ICL_APPENDINT32(logp, (afs_int32) p1);
2065 ICL_APPENDINT32(logp, (afs_int32) 0);
2066 #endif /* AFS_64BIT_CLIENT */
2067 #else /* AFSLITTLE_ENDIAN */
2068 #ifdef AFS_64BIT_CLIENT
2069 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2070 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2071 #else /* AFS_64BIT_CLIENT */
2072 ICL_APPENDINT32(logp, (afs_int32) 0);
2073 ICL_APPENDINT32(logp, (afs_int32) p1);
2074 #endif /* AFS_64BIT_CLIENT */
2075 #endif /* AFSLITTLE_ENDIAN */
2077 else if (t1 == ICL_TYPE_FID) {
2078 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2079 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2080 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
2081 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
2083 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2084 else if (t1 == ICL_TYPE_INT32)
2085 ICL_APPENDINT32(logp, (afs_int32)p1);
2086 #endif /* AFS_ALPHA_ENV */
2087 else ICL_APPENDLONG(logp, p1);
2090 /* marshall parameter 2 now */
2091 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
2092 else if (t2 == ICL_TYPE_HYPER) {
2093 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
2094 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
2096 else if (t2 == ICL_TYPE_INT64) {
2097 #ifdef AFSLITTLE_ENDIAN
2098 #ifdef AFS_64BIT_CLIENT
2099 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2100 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2101 #else /* AFS_64BIT_CLIENT */
2102 ICL_APPENDINT32(logp, (afs_int32) p2);
2103 ICL_APPENDINT32(logp, (afs_int32) 0);
2104 #endif /* AFS_64BIT_CLIENT */
2105 #else /* AFSLITTLE_ENDIAN */
2106 #ifdef AFS_64BIT_CLIENT
2107 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2108 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2109 #else /* AFS_64BIT_CLIENT */
2110 ICL_APPENDINT32(logp, (afs_int32) 0);
2111 ICL_APPENDINT32(logp, (afs_int32) p2);
2112 #endif /* AFS_64BIT_CLIENT */
2113 #endif /* AFSLITTLE_ENDIAN */
2115 else if (t2 == ICL_TYPE_FID) {
2116 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2117 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2118 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
2119 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
2121 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2122 else if (t2 == ICL_TYPE_INT32)
2123 ICL_APPENDINT32(logp, (afs_int32)p2);
2124 #endif /* AFS_ALPHA_ENV */
2125 else ICL_APPENDLONG(logp, p2);
2128 /* marshall parameter 3 now */
2129 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
2130 else if (t3 == ICL_TYPE_HYPER) {
2131 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
2132 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
2134 else if (t3 == ICL_TYPE_INT64) {
2135 #ifdef AFSLITTLE_ENDIAN
2136 #ifdef AFS_64BIT_CLIENT
2137 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2138 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2139 #else /* AFS_64BIT_CLIENT */
2140 ICL_APPENDINT32(logp, (afs_int32) p3);
2141 ICL_APPENDINT32(logp, (afs_int32) 0);
2142 #endif /* AFS_64BIT_CLIENT */
2143 #else /* AFSLITTLE_ENDIAN */
2144 #ifdef AFS_64BIT_CLIENT
2145 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2146 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2147 #else /* AFS_64BIT_CLIENT */
2148 ICL_APPENDINT32(logp, (afs_int32) 0);
2149 ICL_APPENDINT32(logp, (afs_int32) p3);
2150 #endif /* AFS_64BIT_CLIENT */
2151 #endif /* AFSLITTLE_ENDIAN */
2153 else if (t3 == ICL_TYPE_FID) {
2154 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2155 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2156 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
2157 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
2159 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2160 else if (t3 == ICL_TYPE_INT32)
2161 ICL_APPENDINT32(logp, (afs_int32)p3);
2162 #endif /* AFS_ALPHA_ENV */
2163 else ICL_APPENDLONG(logp, p3);
2166 /* marshall parameter 4 now */
2167 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
2168 else if (t4 == ICL_TYPE_HYPER) {
2169 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
2170 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
2172 else if (t4 == ICL_TYPE_INT64) {
2173 #ifdef AFSLITTLE_ENDIAN
2174 #ifdef AFS_64BIT_CLIENT
2175 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2176 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2177 #else /* AFS_64BIT_CLIENT */
2178 ICL_APPENDINT32(logp, (afs_int32) p4);
2179 ICL_APPENDINT32(logp, (afs_int32) 0);
2180 #endif /* AFS_64BIT_CLIENT */
2181 #else /* AFSLITTLE_ENDIAN */
2182 #ifdef AFS_64BIT_CLIENT
2183 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2184 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2185 #else /* AFS_64BIT_CLIENT */
2186 ICL_APPENDINT32(logp, (afs_int32) 0);
2187 ICL_APPENDINT32(logp, (afs_int32) p4);
2188 #endif /* AFS_64BIT_CLIENT */
2189 #endif /* AFSLITTLE_ENDIAN */
2191 else if (t4 == ICL_TYPE_FID) {
2192 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2193 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2194 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
2195 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
2197 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2198 else if (t4 == ICL_TYPE_INT32)
2199 ICL_APPENDINT32(logp, (afs_int32)p4);
2200 #endif /* AFS_ALPHA_ENV */
2201 else ICL_APPENDLONG(logp, p4);
2203 ReleaseWriteLock(&logp->lock);
2206 /* create a log with size logSize; return it in *outLogpp and tag
2207 * it with name "name."
2209 int afs_icl_CreateLog(char *name, afs_int32 logSize, struct afs_icl_log **outLogpp)
2211 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
2214 /* create a log with size logSize; return it in *outLogpp and tag
2215 * it with name "name." 'flags' can be set to make the log unclearable.
2217 int afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, afs_uint32 flags,
2218 struct afs_icl_log **outLogpp)
2220 register struct afs_icl_log *logp;
2222 /* add into global list under lock */
2223 ObtainWriteLock(&afs_icl_lock,183);
2224 if (!afs_icl_inited) afs_icl_Init();
2226 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
2227 if (strcmp(logp->name, name) == 0) {
2228 /* found it already created, just return it */
2231 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2233 ObtainWriteLock(&logp->lock,184);
2234 logp->states |= ICL_LOGF_PERSISTENT;
2235 ReleaseWriteLock(&logp->lock);
2237 ReleaseWriteLock(&afs_icl_lock);
2242 logp = (struct afs_icl_log *)
2243 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
2244 memset((caddr_t)logp, 0, sizeof(*logp));
2247 logp->name = osi_AllocSmallSpace(strlen(name)+1);
2248 strcpy(logp->name, name);
2249 LOCK_INIT(&logp->lock, "logp lock");
2250 logp->logSize = logSize;
2251 logp->datap = NULL; /* don't allocate it until we need it */
2253 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2254 logp->states |= ICL_LOGF_PERSISTENT;
2256 logp->nextp = afs_icl_allLogs;
2257 afs_icl_allLogs = logp;
2258 ReleaseWriteLock(&afs_icl_lock);
2264 /* called with a log, a pointer to a buffer, the size of the buffer
2265 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
2266 * and returns data in the provided buffer, and returns output flags
2267 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
2268 * find the record with cookie value cookie.
2270 int afs_icl_CopyOut(register struct afs_icl_log *logp, afs_int32 *bufferp,
2271 afs_int32 *bufSizep, afs_uint32 *cookiep, afs_int32 *flagsp)
2273 afs_int32 nwords; /* number of words to copy out */
2274 afs_uint32 startCookie; /* first cookie to use */
2275 afs_int32 outWords; /* words we've copied out */
2276 afs_int32 inWords; /* max words to copy out */
2277 afs_int32 code; /* return code */
2278 afs_int32 ix; /* index we're copying from */
2279 afs_int32 outFlags; /* return flags */
2280 afs_int32 inFlags; /* flags passed in */
2283 inWords = *bufSizep; /* max to copy out */
2284 outWords = 0; /* amount copied out */
2285 startCookie = *cookiep;
2290 ObtainWriteLock(&logp->lock,185);
2292 ReleaseWriteLock(&logp->lock);
2296 /* first, compute the index of the start cookie we've been passed */
2298 /* (re-)compute where we should start */
2299 if (startCookie < logp->baseCookie) {
2300 if (startCookie) /* missed some output */
2301 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2302 /* skip to the first available record */
2303 startCookie = logp->baseCookie;
2304 *cookiep = startCookie;
2307 /* compute where we find the first element to copy out */
2308 ix = logp->firstUsed + startCookie - logp->baseCookie;
2309 if (ix >= logp->logSize) ix -= logp->logSize;
2311 /* if have some data now, break out and process it */
2312 if (startCookie - logp->baseCookie < logp->logElements) break;
2314 /* At end of log, so clear it if we need to */
2315 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
2317 logp->firstUsed = logp->firstFree = 0;
2318 logp->logElements = 0;
2320 /* otherwise, either wait for the data to arrive, or return */
2321 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2322 ReleaseWriteLock(&logp->lock);
2326 logp->states |= ICL_LOGF_WAITING;
2327 ReleaseWriteLock(&logp->lock);
2328 afs_osi_Sleep(&logp->lock);
2329 ObtainWriteLock(&logp->lock,186);
2331 /* copy out data from ix to logSize or firstFree, depending
2332 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2333 * be careful not to copy out more than nwords.
2335 if (ix >= logp->firstUsed) {
2336 if (logp->firstUsed <= logp->firstFree)
2338 end = logp->firstFree; /* first element not to copy */
2340 end = logp->logSize;
2341 nwords = inWords; /* don't copy more than this */
2342 if (end - ix < nwords)
2345 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2350 /* if we're going to copy more out below, we'll start here */
2353 /* now, if active part of the log has wrapped, there's more stuff
2354 * starting at the head of the log. Copy out more from there.
2356 if (logp->firstUsed > logp->firstFree
2357 && ix < logp->firstFree && inWords > 0) {
2358 /* (more to) copy out from the wrapped section at the
2359 * start of the log. May get here even if didn't copy any
2360 * above, if the cookie points directly into the wrapped section.
2363 if (logp->firstFree - ix < nwords)
2364 nwords = logp->firstFree - ix;
2365 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2371 ReleaseWriteLock(&logp->lock);
2375 *bufSizep = outWords;
2381 /* return basic parameter information about a log */
2382 int afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 *maxSizep,
2383 afs_int32 *curSizep)
2385 ObtainReadLock(&logp->lock);
2386 *maxSizep = logp->logSize;
2387 *curSizep = logp->logElements;
2388 ReleaseReadLock(&logp->lock);
2393 /* hold and release logs */
2394 int afs_icl_LogHold(register struct afs_icl_log *logp)
2396 ObtainWriteLock(&afs_icl_lock,187);
2398 ReleaseWriteLock(&afs_icl_lock);
2402 /* hold and release logs, called with lock already held */
2403 int afs_icl_LogHoldNL(register struct afs_icl_log *logp)
2409 /* keep track of how many sets believe the log itself is allocated */
2410 int afs_icl_LogUse(register struct afs_icl_log *logp)
2412 ObtainWriteLock(&logp->lock,188);
2413 if (logp->setCount == 0) {
2414 /* this is the first set actually using the log -- allocate it */
2415 if (logp->logSize == 0) {
2416 /* we weren't passed in a hint and it wasn't set */
2417 logp->logSize = ICL_DEFAULT_LOGSIZE;
2419 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2420 #ifdef KERNEL_HAVE_PIN
2421 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2425 ReleaseWriteLock(&logp->lock);
2429 /* decrement the number of real users of the log, free if possible */
2430 int afs_icl_LogFreeUse(register struct afs_icl_log *logp)
2432 ObtainWriteLock(&logp->lock,189);
2433 if (--logp->setCount == 0) {
2434 /* no more users -- free it (but keep log structure around)*/
2435 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2436 #ifdef KERNEL_HAVE_PIN
2437 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2439 logp->firstUsed = logp->firstFree = 0;
2440 logp->logElements = 0;
2443 ReleaseWriteLock(&logp->lock);
2447 /* set the size of the log to 'logSize' */
2448 int afs_icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
2450 ObtainWriteLock(&logp->lock,190);
2452 /* nothing to worry about since it's not allocated */
2453 logp->logSize = logSize;
2457 logp->firstUsed = logp->firstFree = 0;
2458 logp->logElements = 0;
2460 /* free and allocate a new one */
2461 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2462 #ifdef KERNEL_HAVE_PIN
2463 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2465 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2466 #ifdef KERNEL_HAVE_PIN
2467 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2469 logp->logSize = logSize;
2471 ReleaseWriteLock(&logp->lock);
2476 /* free a log. Called with afs_icl_lock locked. */
2477 int afs_icl_ZapLog(register struct afs_icl_log *logp)
2479 register struct afs_icl_log **lpp, *tp;
2481 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2483 /* found the dude we want to remove */
2485 osi_FreeSmallSpace(logp->name);
2486 osi_FreeSmallSpace(logp->datap);
2487 osi_FreeSmallSpace(logp);
2488 break; /* won't find it twice */
2494 /* do the release, watching for deleted entries */
2495 int afs_icl_LogRele(register struct afs_icl_log *logp)
2497 ObtainWriteLock(&afs_icl_lock,191);
2498 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2499 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2501 ReleaseWriteLock(&afs_icl_lock);
2505 /* do the release, watching for deleted entries, log already held */
2506 int afs_icl_LogReleNL(register struct afs_icl_log *logp)
2508 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2509 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2514 /* zero out the log */
2515 int afs_icl_ZeroLog(register struct afs_icl_log *logp)
2517 ObtainWriteLock(&logp->lock,192);
2518 logp->firstUsed = logp->firstFree = 0;
2519 logp->logElements = 0;
2520 logp->baseCookie = 0;
2521 ReleaseWriteLock(&logp->lock);
2525 /* free a log entry, and drop its reference count */
2526 int afs_icl_LogFree(register struct afs_icl_log *logp)
2528 ObtainWriteLock(&logp->lock,193);
2529 logp->states |= ICL_LOGF_DELETED;
2530 ReleaseWriteLock(&logp->lock);
2531 afs_icl_LogRele(logp);
2535 /* find a log by name, returning it held */
2536 struct afs_icl_log *afs_icl_FindLog(char *name)
2538 register struct afs_icl_log *tp;
2539 ObtainWriteLock(&afs_icl_lock,194);
2540 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2541 if (strcmp(tp->name, name) == 0) {
2542 /* this is the dude we want */
2547 ReleaseWriteLock(&afs_icl_lock);
2551 int afs_icl_EnumerateLogs(int (*aproc)(char *name,char *arock,struct afs_icl_log *tp), char *arock)
2553 register struct afs_icl_log *tp;
2554 register afs_int32 code;
2557 ObtainWriteLock(&afs_icl_lock,195);
2558 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2559 tp->refCount++; /* hold this guy */
2560 ReleaseWriteLock(&afs_icl_lock);
2561 ObtainReadLock(&tp->lock);
2562 code = (*aproc)(tp->name, arock, tp);
2563 ReleaseReadLock(&tp->lock);
2564 ObtainWriteLock(&afs_icl_lock,196);
2565 if (--tp->refCount == 0)
2569 ReleaseWriteLock(&afs_icl_lock);
2573 struct afs_icl_set *afs_icl_allSets = 0;
2575 int afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
2576 struct afs_icl_log *fatalLogp, struct afs_icl_set **outSetpp)
2578 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2579 /*flags*/0, outSetpp);
2582 /* create a set, given pointers to base and fatal logs, if any.
2583 * Logs are unlocked, but referenced, and *outSetpp is returned
2584 * referenced. Function bumps reference count on logs, since it
2585 * addds references from the new afs_icl_set. When the set is destroyed,
2586 * those references will be released.
2588 int afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
2589 struct afs_icl_log *fatalLogp, afs_uint32 flags, struct afs_icl_set **outSetpp)
2591 register struct afs_icl_set *setp;
2593 afs_int32 states = ICL_DEFAULT_SET_STATES;
2595 ObtainWriteLock(&afs_icl_lock,197);
2596 if (!afs_icl_inited) afs_icl_Init();
2598 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2599 if (strcmp(setp->name, name) == 0) {
2602 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2604 ObtainWriteLock(&setp->lock,198);
2605 setp->states |= ICL_SETF_PERSISTENT;
2606 ReleaseWriteLock(&setp->lock);
2608 ReleaseWriteLock(&afs_icl_lock);
2613 /* determine initial state */
2614 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2615 states = ICL_SETF_ACTIVE;
2616 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2617 states = ICL_SETF_FREED;
2618 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2619 states |= ICL_SETF_PERSISTENT;
2621 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2622 memset((caddr_t)setp, 0, sizeof(*setp));
2624 if (states & ICL_SETF_FREED)
2625 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2626 setp->states = states;
2628 LOCK_INIT(&setp->lock, "setp lock");
2629 /* next lock is obtained in wrong order, hierarchy-wise, but
2630 * it doesn't matter, since no one can find this lock yet, since
2631 * the afs_icl_lock is still held, and thus the obtain can't block.
2633 ObtainWriteLock(&setp->lock,199);
2634 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2635 strcpy(setp->name, name);
2636 setp->nevents = ICL_DEFAULTEVENTS;
2637 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2638 #ifdef KERNEL_HAVE_PIN
2639 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2641 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2642 setp->eventFlags[i] = 0xff; /* default to enabled */
2644 /* update this global info under the afs_icl_lock */
2645 setp->nextp = afs_icl_allSets;
2646 afs_icl_allSets = setp;
2647 ReleaseWriteLock(&afs_icl_lock);
2649 /* set's basic lock is still held, so we can finish init */
2651 setp->logs[0] = baseLogp;
2652 afs_icl_LogHold(baseLogp);
2653 if (!(setp->states & ICL_SETF_FREED))
2654 afs_icl_LogUse(baseLogp); /* log is actually being used */
2657 setp->logs[1] = fatalLogp;
2658 afs_icl_LogHold(fatalLogp);
2659 if (!(setp->states & ICL_SETF_FREED))
2660 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2662 ReleaseWriteLock(&setp->lock);
2668 /* function to change event enabling information for a particular set */
2669 int afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
2673 ObtainWriteLock(&setp->lock,200);
2674 if (!ICL_EVENTOK(setp, eventID)) {
2675 ReleaseWriteLock(&setp->lock);
2678 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2680 *tp |= ICL_EVENTMASK(eventID);
2682 *tp &= ~(ICL_EVENTMASK(eventID));
2683 ReleaseWriteLock(&setp->lock);
2687 /* return indication of whether a particular event ID is enabled
2688 * for tracing. If *getValuep is set to 0, the event is disabled,
2689 * otherwise it is enabled. All events start out enabled by default.
2691 int afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID,
2694 ObtainReadLock(&setp->lock);
2695 if (!ICL_EVENTOK(setp, eventID)) {
2696 ReleaseWriteLock(&setp->lock);
2699 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2703 ReleaseReadLock(&setp->lock);
2707 /* hold and release event sets */
2708 int afs_icl_SetHold(register struct afs_icl_set *setp)
2710 ObtainWriteLock(&afs_icl_lock,201);
2712 ReleaseWriteLock(&afs_icl_lock);
2716 /* free a set. Called with afs_icl_lock locked */
2717 int afs_icl_ZapSet(register struct afs_icl_set *setp)
2719 register struct afs_icl_set **lpp, *tp;
2721 register struct afs_icl_log *tlp;
2723 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2725 /* found the dude we want to remove */
2727 osi_FreeSmallSpace(setp->name);
2728 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2729 #ifdef KERNEL_HAVE_PIN
2730 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2732 for(i=0; i < ICL_LOGSPERSET; i++) {
2733 if ((tlp = setp->logs[i]))
2734 afs_icl_LogReleNL(tlp);
2736 osi_FreeSmallSpace(setp);
2737 break; /* won't find it twice */
2743 /* do the release, watching for deleted entries */
2744 int afs_icl_SetRele(register struct afs_icl_set *setp)
2746 ObtainWriteLock(&afs_icl_lock,202);
2747 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2748 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2750 ReleaseWriteLock(&afs_icl_lock);
2754 /* free a set entry, dropping its reference count */
2755 int afs_icl_SetFree(register struct afs_icl_set *setp)
2757 ObtainWriteLock(&setp->lock,203);
2758 setp->states |= ICL_SETF_DELETED;
2759 ReleaseWriteLock(&setp->lock);
2760 afs_icl_SetRele(setp);
2764 /* find a set by name, returning it held */
2765 struct afs_icl_set *afs_icl_FindSet(char *name)
2767 register struct afs_icl_set *tp;
2768 ObtainWriteLock(&afs_icl_lock,204);
2769 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2770 if (strcmp(tp->name, name) == 0) {
2771 /* this is the dude we want */
2776 ReleaseWriteLock(&afs_icl_lock);
2780 /* zero out all the logs in the set */
2781 int afs_icl_ZeroSet(struct afs_icl_set *setp)
2786 struct afs_icl_log *logp;
2788 ObtainReadLock(&setp->lock);
2789 for(i = 0; i < ICL_LOGSPERSET; i++) {
2790 logp = setp->logs[i];
2792 afs_icl_LogHold(logp);
2793 tcode = afs_icl_ZeroLog(logp);
2794 if (tcode != 0) code = tcode; /* save the last bad one */
2795 afs_icl_LogRele(logp);
2798 ReleaseReadLock(&setp->lock);
2802 int afs_icl_EnumerateSets(int (*aproc)(char *name,char *arock,struct afs_icl_log *tp), char *arock)
2804 register struct afs_icl_set *tp, *np;
2805 register afs_int32 code;
2808 ObtainWriteLock(&afs_icl_lock,205);
2809 for(tp = afs_icl_allSets; tp; tp=np) {
2810 tp->refCount++; /* hold this guy */
2811 ReleaseWriteLock(&afs_icl_lock);
2812 code = (*aproc)(tp->name, arock, tp);
2813 ObtainWriteLock(&afs_icl_lock,206);
2814 np = tp->nextp; /* tp may disappear next, but not np */
2815 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2819 ReleaseWriteLock(&afs_icl_lock);
2823 int afs_icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
2828 ObtainWriteLock(&setp->lock,207);
2829 for(i = 0; i < ICL_LOGSPERSET; i++) {
2830 if (!setp->logs[i]) {
2831 setp->logs[i] = newlogp;
2833 afs_icl_LogHold(newlogp);
2834 if (!(setp->states & ICL_SETF_FREED)) {
2835 /* bump up the number of sets using the log */
2836 afs_icl_LogUse(newlogp);
2841 ReleaseWriteLock(&setp->lock);
2845 int afs_icl_SetSetStat(struct afs_icl_set *setp, int op)
2849 struct afs_icl_log *logp;
2851 ObtainWriteLock(&setp->lock,208);
2853 case ICL_OP_SS_ACTIVATE: /* activate a log */
2855 * If we are not already active, see if we have released
2856 * our demand that the log be allocated (FREED set). If
2857 * we have, reassert our desire.
2859 if (!(setp->states & ICL_SETF_ACTIVE)) {
2860 if (setp->states & ICL_SETF_FREED) {
2861 /* have to reassert desire for logs */
2862 for(i = 0; i < ICL_LOGSPERSET; i++) {
2863 logp = setp->logs[i];
2865 afs_icl_LogHold(logp);
2866 afs_icl_LogUse(logp);
2867 afs_icl_LogRele(logp);
2870 setp->states &= ~ICL_SETF_FREED;
2872 setp->states |= ICL_SETF_ACTIVE;
2877 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2878 /* this doesn't require anything beyond clearing the ACTIVE flag */
2879 setp->states &= ~ICL_SETF_ACTIVE;
2883 case ICL_OP_SS_FREE: /* deassert design for log */
2885 * if we are already in this state, do nothing; otherwise
2886 * deassert desire for log
2888 if (setp->states & ICL_SETF_ACTIVE)
2891 if (!(setp->states & ICL_SETF_FREED)) {
2892 for(i = 0; i < ICL_LOGSPERSET; i++) {
2893 logp = setp->logs[i];
2895 afs_icl_LogHold(logp);
2896 afs_icl_LogFreeUse(logp);
2897 afs_icl_LogRele(logp);
2900 setp->states |= ICL_SETF_FREED;
2909 ReleaseWriteLock(&setp->lock);