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 "../afs/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_FBSD_ENV)
67 struct lock afs_global_lock;
68 struct proc *afs_global_owner;
71 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
72 thread_t afs_global_owner;
73 #endif /* AFS_OSF_ENV */
75 #if defined(AFS_AIX41_ENV)
76 simple_lock_data afs_global_lock;
79 afs_int32 afs_initState = 0;
80 afs_int32 afs_termState = 0;
81 afs_int32 afs_setTime = 0;
82 int afs_cold_shutdown = 0;
83 char afs_SynchronousCloses = '\0';
84 static int afs_CB_Running = 0;
85 static int AFS_Running = 0;
86 static int afs_CacheInit_Done = 0;
87 static int afs_Go_Done = 0;
88 extern struct interfaceAddr afs_cb_interface;
89 static int afs_RX_Running = 0;
90 static int afs_InitSetup_done = 0;
93 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval);
95 #if defined(AFS_HPUX_ENV)
96 extern int afs_vfs_mount();
97 #endif /* defined(AFS_HPUX_ENV) */
99 /* This is code which needs to be called once when the first daemon enters
100 * the client. A non-zero return means an error and AFS should not start.
102 static int afs_InitSetup(int preallocs)
104 extern void afs_InitStats();
107 if (afs_InitSetup_done)
112 * Set up all the AFS statistics variables. This should be done
113 * exactly once, and it should be done here, the first resource-setting
114 * routine to be called by the CM/RX.
117 #endif /* AFS_NOSTATS */
119 memset(afs_zeros, 0, AFS_ZEROS);
122 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
123 code = rx_Init(htons(7001));
125 printf("AFS: RX failed to initialize.\n");
128 rx_SetRxDeadTime(AFS_RXDEADTIME);
129 /* resource init creates the services */
130 afs_ResourceInit(preallocs);
132 afs_InitSetup_done = 1;
133 afs_osi_Wakeup(&afs_InitSetup_done);
138 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)
139 struct afsd_thread_info {
141 struct completion *complete;
144 static int afsd_thread(void *rock) {
145 struct afsd_thread_info *arg=rock;
146 unsigned long parm=arg->parm;
147 #ifdef SYS_SETPRIORITY_EXPORTED
148 int (*sys_setpriority)(int,int,int) = sys_call_table[__NR_setpriority];
150 daemonize(); /* doesn't do much, since we were forked from keventd, but
151 does call mm_release, which wakes up our parent (since it
153 afs_osi_MaskSignals();
155 case AFSOP_START_RXCALLBACK:
156 sprintf(current->comm, "afs_cbstart");
158 complete(arg->complete);
160 while (afs_RX_Running != 2)
161 afs_osi_Sleep(&afs_RX_Running);
162 sprintf(current->comm, "afs_callback");
163 afs_RXCallBackServer();
165 complete_and_exit(0,0);
167 case AFSOP_START_AFS:
168 sprintf(current->comm, "afs_afsstart");
170 complete(arg->complete);
172 while (afs_initState < AFSOP_START_AFS)
173 afs_osi_Sleep(&afs_initState);
174 afs_initState = AFSOP_START_BKG;
175 afs_osi_Wakeup(&afs_initState);
176 sprintf(current->comm, "afsd");
179 complete_and_exit(0,0);
181 case AFSOP_START_BKG:
182 sprintf(current->comm, "afs_bkgstart");
184 complete(arg->complete);
185 while (afs_initState < AFSOP_START_BKG)
186 afs_osi_Sleep(&afs_initState);
187 if (afs_initState < AFSOP_GO) {
188 afs_initState = AFSOP_GO;
189 afs_osi_Wakeup(&afs_initState);
191 sprintf(current->comm, "afs_background");
192 afs_BackgroundDaemon();
194 complete_and_exit(0,0);
196 case AFSOP_START_TRUNCDAEMON:
197 sprintf(current->comm, "afs_trimstart");
199 complete(arg->complete);
200 while (afs_initState < AFSOP_GO)
201 afs_osi_Sleep(&afs_initState);
202 sprintf(current->comm, "afs_cachetrim");
203 afs_CacheTruncateDaemon();
205 complete_and_exit(0,0);
208 sprintf(current->comm, "afs_checkserver");
210 complete(arg->complete);
211 afs_CheckServerDaemon();
213 complete_and_exit(0,0);
215 case AFSOP_RXEVENT_DAEMON:
216 sprintf(current->comm, "afs_evtstart");
217 #ifdef SYS_SETPRIORITY_EXPORTED
218 sys_setpriority(PRIO_PROCESS,0,-10);
220 #ifdef CURRENT_INCLUDES_NICE
225 complete(arg->complete);
226 while (afs_initState < AFSOP_START_BKG)
227 afs_osi_Sleep(&afs_initState);
228 sprintf(current->comm, "afs_rxevent");
229 afs_rxevent_daemon();
231 complete_and_exit(0,0);
233 case AFSOP_RXLISTENER_DAEMON:
234 sprintf(current->comm, "afs_lsnstart");
235 #ifdef SYS_SETPRIORITY_EXPORTED
236 sys_setpriority(PRIO_PROCESS,0,-10);
238 #ifdef CURRENT_INCLUDES_NICE
243 complete(arg->complete);
244 afs_initState = AFSOP_START_AFS;
245 afs_osi_Wakeup(&afs_initState);
247 afs_osi_Wakeup(&afs_RX_Running);
248 afs_osi_RxkRegister();
249 sprintf(current->comm, "afs_rxlistener");
252 complete_and_exit(0,0);
255 printf("Unknown op %d in StartDaemon()\n");
261 void afsd_launcher(void *rock) {
262 if (!kernel_thread(afsd_thread,rock, CLONE_VFORK|SIGCHLD))
263 printf("kernel_thread failed. afs startup will not complete\n");
266 void afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
270 DECLARE_COMPLETION(c);
272 struct afsd_thread_info info;
273 if (parm == AFSOP_START_RXCALLBACK) {
274 if (afs_CB_Running) return;
275 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
276 if (afs_RX_Running) return;
278 code = afs_InitSetup(parm2);
280 rx_enablePeerRPCStats();
283 rx_enableProcessRPCStats();
287 } else if (parm == AFSOP_START_AFS) {
288 if (AFS_Running) return;
289 } /* other functions don't need setup in the parent */
293 INIT_LIST_HEAD(&tq.list);
294 tq.routine=afsd_launcher;
298 /* we need to wait cause we passed stack pointers around.... */
299 wait_for_completion(&c);
304 /* leaving as is, probably will barf if we add prototypes here since it's likely being called
306 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
307 long parm, parm2, parm3, parm4, parm5, parm6;
310 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
312 #else /* AFS_SGI61_ENV */
314 #endif /* AFS_SGI61_ENV */
316 AFS_STATCNT(afs_syscall_call);
318 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
319 && (parm != AFSOP_GETMASK)) {
320 /* only root can run this code */
323 if (!afs_suser() && (parm != AFSOP_GETMTU)
324 && (parm != AFSOP_GETMASK)) {
325 /* only root can run this code */
326 #if defined(KERNEL_HAVE_UERROR)
330 #if defined(AFS_OSF_ENV)
332 #else /* AFS_OSF_ENV */
334 #endif /* AFS_OSF_ENV */
339 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS) && !defined(UKERNEL)
340 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
341 || parm == AFSOP_RXLISTENER_DAEMON) {
342 afs_DaemonOp(parm,parm2,parm3,parm4,parm5,parm6);
344 #else /* !(AFS_LINUX24_ENV && !UKERNEL) */
345 if (parm == AFSOP_START_RXCALLBACK) {
346 if (afs_CB_Running) goto out;
348 #ifndef RXK_LISTENER_ENV
349 code = afs_InitSetup(parm2);
351 #endif /* !RXK_LISTENER_ENV */
353 #ifdef RXK_LISTENER_ENV
354 while (afs_RX_Running != 2)
355 afs_osi_Sleep(&afs_RX_Running);
356 #else /* !RXK_LISTENER_ENV */
357 afs_initState = AFSOP_START_AFS;
358 afs_osi_Wakeup(&afs_initState);
359 #endif /* RXK_LISTENER_ENV */
361 afs_RXCallBackServer();
365 exit(CLD_EXITED, code);
366 #endif /* AFS_SGI_ENV */
368 #ifdef RXK_LISTENER_ENV
369 else if (parm == AFSOP_RXLISTENER_DAEMON) {
370 if (afs_RX_Running) goto out;
372 code = afs_InitSetup(parm2);
374 rx_enablePeerRPCStats();
377 rx_enableProcessRPCStats();
380 afs_initState = AFSOP_START_AFS;
381 afs_osi_Wakeup(&afs_initState);
384 afs_osi_Wakeup(&afs_RX_Running);
386 afs_osi_RxkRegister();
387 #endif /* !UKERNEL */
392 exit(CLD_EXITED, code);
393 #endif /* AFS_SGI_ENV */
395 #endif /* RXK_LISTENER_ENV */
396 else if (parm == AFSOP_START_AFS) {
398 if (AFS_Running) goto out;
400 while (afs_initState < AFSOP_START_AFS)
401 afs_osi_Sleep(&afs_initState);
403 afs_initState = AFSOP_START_BKG;
404 afs_osi_Wakeup(&afs_initState);
410 #endif /* AFS_SGI_ENV */
412 else if (parm == AFSOP_START_CS) {
414 afs_CheckServerDaemon();
418 #endif /* AFS_SGI_ENV */
420 else if (parm == AFSOP_START_BKG) {
421 while (afs_initState < AFSOP_START_BKG)
422 afs_osi_Sleep(&afs_initState);
423 if (afs_initState < AFSOP_GO) {
424 afs_initState = AFSOP_GO;
425 afs_osi_Wakeup(&afs_initState);
427 /* start the bkg daemon */
431 afs_BioDaemon(parm2);
433 #endif /* AFS_AIX32_ENV */
434 afs_BackgroundDaemon();
438 #endif /* AFS_SGI_ENV */
440 else if (parm == AFSOP_START_TRUNCDAEMON) {
441 while (afs_initState < AFSOP_GO)
442 afs_osi_Sleep(&afs_initState);
443 /* start the bkg daemon */
445 afs_CacheTruncateDaemon();
449 #endif /* AFS_SGI_ENV */
451 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
452 else if (parm == AFSOP_RXEVENT_DAEMON) {
453 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
455 afs_rxevent_daemon();
459 #endif /* AFS_SGI_ENV */
461 #endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
462 #endif /* AFS_LINUX24_ENV && !UKERNEL */
463 else if (parm == AFSOP_BASIC_INIT) {
466 while (!afs_InitSetup_done)
467 afs_osi_Sleep(&afs_InitSetup_done);
469 #if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
470 temp = AFS_MINBUFFERS; /* Should fix this soon */
472 /* number of 2k buffers we could get from all of the buffer space */
473 temp = ((afs_bufferpages * NBPG)>>11);
474 temp = temp>>2; /* don't take more than 25% (our magic parameter) */
475 if (temp < AFS_MINBUFFERS)
476 temp = AFS_MINBUFFERS; /* though we really should have this many */
479 afs_rootFid.Fid.Volume = 0;
482 else if (parm == AFSOP_ADDCELL) {
483 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
484 name. Parameter 4 is the length of the name, including the null. Parm 5 is the
485 home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
486 struct afsop_cell tcell;
488 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
490 if (parm4 > sizeof(tcell.cellName))
493 AFS_COPYIN((char *)parm3, tcell.cellName, parm4, code);
495 afs_NewCell(tcell.cellName, tcell.hosts, parm5,
499 } else if (parm == AFSOP_ADDCELL2) {
500 struct afsop_cell tcell;
501 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
502 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *cnamep = 0;
505 /* wait for basic init */
506 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
508 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
510 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, &bufferSize, code);
513 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
516 cflags |= CLinkedCell;
520 code = afs_NewCell(tbuffer1, tcell.hosts, cflags,
524 osi_FreeSmallSpace(tbuffer);
525 osi_FreeSmallSpace(tbuffer1);
527 else if (parm == AFSOP_ADDCELLALIAS) {
530 * parm2 is the alias name
531 * parm3 is the real cell name
533 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
534 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
536 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize, code);
537 if (!code) AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ, &bufferSize, code);
538 if (!code) afs_NewCellAlias(aliasName, cellName);
539 osi_FreeSmallSpace(aliasName);
540 osi_FreeSmallSpace(cellName);
542 else if (parm == AFSOP_SET_THISCELL) {
545 * parm2 is the primary cell name
547 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
549 AFS_COPYINSTR((char *) parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code);
551 afs_SetPrimaryCell(cell);
552 osi_FreeSmallSpace(cell);
554 else if (parm == AFSOP_CACHEINIT) {
555 struct afs_cacheParams cparms;
557 if (afs_CacheInit_Done) goto out;
559 AFS_COPYIN((char *)parm2, (caddr_t) &cparms, sizeof(cparms), code);
561 #if defined(KERNEL_HAVE_UERROR)
567 afs_CacheInit_Done = 1;
569 struct afs_icl_log *logp;
570 /* initialize the ICL system */
571 code = afs_icl_CreateLog("cmfx", 60*1024, &logp);
573 code = afs_icl_CreateSetWithFlags("cm", logp,
574 (struct icl_log *) 0,
575 ICL_CRSET_FLAG_DEFAULT_OFF,
577 code = afs_icl_CreateSet("cmlongterm", logp, (struct icl_log*) 0,
578 &afs_iclLongTermSetp);
580 afs_setTime = cparms.setTimeFlag;
582 code = afs_CacheInit(cparms.cacheScaches,
593 else if (parm == AFSOP_CACHEINODE) {
594 ino_t ainode = parm2;
595 /* wait for basic init */
596 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
600 ainode = (ainode << 32) | (parm3 & 0xffffffff);
602 code = afs_InitCacheFile(NULL, ainode);
604 else if (parm == AFSOP_ROOTVOLUME) {
605 /* wait for basic init */
606 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
609 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code);
610 afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0;
614 else if (parm == AFSOP_CACHEFILE ||
615 parm == AFSOP_CACHEINFO ||
616 parm == AFSOP_VOLUMEINFO ||
617 parm == AFSOP_AFSLOG ||
618 parm == AFSOP_CELLINFO) {
619 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
622 AFS_COPYINSTR((char *) parm2, tbuffer, AFS_SMALLOCSIZ,
625 osi_FreeSmallSpace(tbuffer);
629 tbuffer[AFS_SMALLOCSIZ-1] = '\0'; /* null-terminate the name */
630 /* We have the cache dir copied in. Call the cache init routine */
631 if (parm == AFSOP_CACHEFILE)
632 code = afs_InitCacheFile(tbuffer, 0);
633 else if (parm == AFSOP_CACHEINFO)
634 code = afs_InitCacheInfo(tbuffer);
635 else if (parm == AFSOP_VOLUMEINFO)
636 code = afs_InitVolumeInfo(tbuffer);
637 else if (parm == AFSOP_CELLINFO)
638 code = afs_InitCellInfo(tbuffer);
640 osi_FreeSmallSpace(tbuffer);
642 else if (parm == AFSOP_GO) {
643 /* the generic initialization calls come here. One parameter: should we do the
644 set-time operation on this workstation */
645 if (afs_Go_Done) goto out;
647 while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState);
650 afs_osi_Wakeup(&afs_initState);
651 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
652 afs_nfsclient_init();
654 printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused,
655 (100*afs_stats_cmperf.cacheFilesReused) /
656 (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1));
658 else if (parm == AFSOP_ADVISEADDR) {
659 /* pass in the host address to the rx package */
660 afs_int32 count = parm2;
661 afs_int32 buffer[AFS_MAX_INTERFACE_ADDR];
662 afs_int32 maskbuffer[AFS_MAX_INTERFACE_ADDR];
663 afs_int32 mtubuffer[AFS_MAX_INTERFACE_ADDR];
667 if ( count > AFS_MAX_INTERFACE_ADDR ) {
669 count = AFS_MAX_INTERFACE_ADDR;
672 AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code);
674 AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code);
676 AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code);
678 afs_cb_interface.numberOfInterfaces = count;
679 for (i=0; i < count ; i++) {
680 afs_cb_interface.addr_in[i] = buffer[i];
681 #ifdef AFS_USERSPACE_IP_ADDR
682 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
683 * machines IP addresses when in the kernel (the in_ifaddr
684 * struct is not available), so we pass the info in at
685 * startup. We also pass in the subnetmask and mtu size. The
686 * subnetmask is used when setting the rank:
687 * afsi_SetServerIPRank(); and the mtu size is used when
688 * finding the best mtu size. rxi_FindIfnet() is replaced
689 * with rxi_Findcbi().
691 afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff);
692 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
695 afs_uuid_create(&afs_cb_interface.uuid);
696 rxi_setaddr(buffer[0]);
700 else if (parm == AFSOP_NFSSTATICADDR) {
701 extern int (*nfs_rfsdisptab_v2)();
702 nfs_rfsdisptab_v2 = (int (*)())parm2;
704 else if (parm == AFSOP_NFSSTATICADDR2) {
705 extern int (*nfs_rfsdisptab_v2)();
707 nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
709 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
712 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
713 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
714 extern int (*afs_sblockp)();
715 extern void (*afs_sbunlockp)();
717 afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
718 afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff));
720 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
721 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
724 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
725 #endif /* AFS_SGI53_ENV */
726 else if (parm == AFSOP_SHUTDOWN) {
727 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
728 extern struct mount *afs_globalVFS;
729 #else /* AFS_OSF_ENV */
730 extern struct vfs *afs_globalVFS;
732 afs_cold_shutdown = 0;
733 if (parm == 1) afs_cold_shutdown = 1;
734 if (afs_globalVFS != 0) {
735 afs_warn("AFS isn't unmounted yet! Call aborted\n");
740 else if (parm == AFSOP_AFS_VFSMOUNT) {
742 vfsmount(parm2, parm3, parm4, parm5);
743 #else /* defined(AFS_HPUX_ENV) */
744 #if defined(KERNEL_HAVE_UERROR)
749 #endif /* defined(AFS_HPUX_ENV) */
751 else if (parm == AFSOP_CLOSEWAIT) {
752 afs_SynchronousCloses = 'S';
754 else if (parm == AFSOP_GETMTU) {
756 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
757 #ifdef AFS_USERSPACE_IP_ADDR
759 i = rxi_Findcbi(parm2);
760 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
761 #else /* AFS_USERSPACE_IP_ADDR */
763 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
764 extern struct ifnet *rxi_FindIfnet();
766 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
767 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
768 #endif /* else AFS_USERSPACE_IP_ADDR */
769 #endif /* !AFS_SUN5_ENV */
771 AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code);
773 /* this is disabled for now because I can't figure out how to get access
774 * to these kernel variables. It's only for supporting user-mode rx
775 * programs -- it makes a huge difference on the 220's in my testbed,
776 * though I don't know why. The bosserver does this with /etc/no, so it's
777 * being handled a different way for the servers right now. */
780 extern u_long sb_max_dflt;
783 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
784 if (sb_max < 131072) sb_max = 131072;
787 #endif /* AFS_AIX32_ENV */
789 else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
791 #if !defined(AFS_SUN5_ENV)
792 #ifdef AFS_USERSPACE_IP_ADDR
794 i = rxi_Findcbi(parm2);
796 mask = afs_cb_interface.subnetmask[i];
800 #else /* AFS_USERSPACE_IP_ADDR */
802 #ifdef AFS_DARWIN60_ENV
803 struct ifaddr *tifadp = (struct ifaddr *) 0;
805 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
807 extern struct ifnet *rxi_FindIfnet();
808 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
809 if (tifnp && tifadp) {
810 #ifdef AFS_DARWIN60_ENV
811 mask = ((struct sockaddr_in *)tifadp->ifa_netmask)->sin_addr.s_addr;
813 mask = tifadp->ia_subnetmask;
818 #endif /* else AFS_USERSPACE_IP_ADDR */
819 #endif /* !AFS_SUN5_ENV */
821 AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code);
824 else if (parm == AFSOP_AFSDB_HANDLER) {
825 int sizeArg = (int)parm4;
826 int kmsgLen = sizeArg & 0xffff;
827 int cellLen = (sizeArg & 0xffff0000) >> 16;
828 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
829 char *cellname = afs_osi_Alloc(cellLen);
832 afs_osi_MaskSignals();
834 AFS_COPYIN((afs_int32 *)parm2, cellname, cellLen, code);
835 AFS_COPYIN((afs_int32 *)parm3, kmsg, kmsgLen, code);
837 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
838 if (*cellname == 1) *cellname = 0;
839 if (code == -2) { /* Shutting down? */
844 if (!code) AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
845 afs_osi_Free(kmsg, kmsgLen);
846 afs_osi_Free(cellname, cellLen);
849 else if (parm == AFSOP_SET_DYNROOT) {
850 code = afs_SetDynrootEnable(parm2);
852 else if (parm == AFSOP_SET_FAKESTAT) {
853 afs_fakestat_enable = parm2;
861 #ifdef AFS_LINUX20_ENV
870 #include "sys/lockl.h"
873 * syscall - this is the VRMIX system call entry point.
876 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
877 * all the user-level calls to `syscall' to change.
879 syscall(syscall, p1, p2, p3, p4, p5, p6) {
880 register rval1=0, code;
883 #ifndef AFS_AIX41_ENV
884 extern lock_t kernel_lock;
885 monster = lockl(&kernel_lock, LOCK_SHORT);
886 #endif /* !AFS_AIX41_ENV */
888 AFS_STATCNT(syscall);
892 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
897 rval1 = afs_setpag();
903 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
907 case AFSCALL_ICREATE:
908 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
912 rval1 = afs_syscall_iopen(p1, p2, p3);
916 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
920 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
925 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
927 if (!code) rval1 = retval;
928 if (!rval1) rval1 = code;
938 #ifndef AFS_AIX41_ENV
939 if (monster != LOCK_NEST)
940 unlockl(&kernel_lock);
941 #endif /* !AFS_AIX41_ENV */
942 return getuerror() ? -1 : rval1;
946 * lsetpag - interface to afs_setpag().
950 AFS_STATCNT(lsetpag);
951 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
955 * lpioctl - interface to pioctl()
957 lpioctl(path, cmd, cmarg, follow)
958 char *path, *cmarg; {
960 AFS_STATCNT(lpioctl);
961 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
964 #else /* !AFS_AIX32_ENV */
966 #if defined(AFS_SGI_ENV)
979 Afs_syscall (struct afsargs *uap, rval_t *rvp)
984 AFS_STATCNT(afs_syscall);
985 switch(uap->syscall) {
989 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
991 rvp->r_val1 = retval;
993 #ifdef AFS_SGI_XFS_IOPS_ENV
995 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
996 uap->parm4, uap->parm5);
999 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
1000 uap->parm4, uap->parm5);
1002 case AFSCALL_ILISTINODE64:
1003 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
1004 uap->parm4, uap->parm5);
1006 case AFSCALL_ICREATENAME64:
1007 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
1008 uap->parm4, uap->parm5);
1011 #ifdef AFS_SGI_VNODE_GLUE
1012 case AFSCALL_INIT_KERNEL_CONFIG:
1013 error = afs_init_kernel_config(uap->parm1);
1017 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
1018 uap->parm3, uap->parm4, uap->parm5);
1023 #else /* AFS_SGI_ENV */
1041 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
1043 dst->param1 = src->param1;
1044 dst->param2 = src->param2;
1045 dst->param3 = src->param3;
1046 dst->param4 = src->param4;
1050 * If you need to change copyin_iparam(), you may also need to change
1051 * copyin_afs_ioctl().
1055 copyin_iparam(caddr_t cmarg, struct iparam *dst)
1059 #if defined(AFS_HPUX_64BIT_ENV)
1060 struct iparam32 dst32;
1062 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
1064 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
1066 iparam32_to_iparam(&dst32, dst);
1069 #endif /* AFS_HPUX_64BIT_ENV */
1071 #if defined(AFS_SUN57_64BIT_ENV)
1072 struct iparam32 dst32;
1074 if (get_udatamodel() == DATAMODEL_ILP32) {
1075 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
1077 iparam32_to_iparam(&dst32, dst);
1080 #endif /* AFS_SUN57_64BIT_ENV */
1082 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
1083 struct iparam32 dst32;
1085 #ifdef AFS_SPARC64_LINUX24_ENV
1086 if (current->thread.flags & SPARC_FLAG_32BIT)
1087 #elif AFS_SPARC64_LINUX20_ENV
1088 if (current->tss.flags & SPARC_FLAG_32BIT)
1090 #error Not done for this linux version
1091 #endif /* AFS_SPARC64_LINUX20_ENV */
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_FBSD_ENV)
1140 afs3_syscall(p, args, retval)
1153 } *uap = (struct a *)args;
1154 #else /* AFS_OSF_ENV */
1155 #ifdef AFS_LINUX20_ENV
1163 long parm6; /* not actually used - should be removed */
1165 /* Linux system calls only set up for 5 arguments. */
1166 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
1169 struct afssysargs args, *uap = &args;
1171 long *retval = &linux_ret;
1172 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
1173 #ifdef AFS_SPARC64_LINUX24_ENV
1174 afs_int32 eparm32[4];
1176 /* eparm is also used by AFSCALL_CALL in afsd.c */
1178 #if defined(UKERNEL)
1189 } *uap = (struct a *)u.u_ap;
1191 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
1195 #endif /* SUN && !SUN5 */
1205 } *uap = (struct a *)u.u_ap;
1206 #endif /* UKERNEL */
1207 #if defined(AFS_DEC_ENV)
1208 int *retval = &u.u_r.r_val1;
1210 #if defined(AFS_HPUX_ENV)
1211 long *retval = &u.u_rval1;
1213 int *retval = &u.u_rval1;
1216 #endif /* AFS_LINUX20_ENV */
1217 #endif /* AFS_OSF_ENV */
1218 #endif /* AFS_SUN5_ENV */
1219 register int code = 0;
1221 AFS_STATCNT(afs_syscall);
1228 #ifdef AFS_LINUX20_ENV
1230 /* setup uap for use below - pull out the magic decoder ring to know
1231 * which syscalls have folded argument lists.
1233 uap->syscall = syscall;
1237 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
1238 #ifdef AFS_SPARC64_LINUX24_ENV
1239 /* from arch/sparc64/kernel/sys_sparc32.c */
1241 ({ unsigned long __ret; \
1242 __asm__ ("srl %0, 0, %0" \
1249 if (current->thread.flags & SPARC_FLAG_32BIT) {
1250 AFS_COPYIN((char*)parm4, (char*)eparm32, sizeof(eparm32), code);
1251 eparm[0]=AA(eparm32[0]);
1252 eparm[1]=AA(eparm32[1]);
1253 eparm[2]=AA(eparm32[2]);
1257 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
1258 uap->parm4 = eparm[0];
1259 uap->parm5 = eparm[1];
1260 uap->parm6 = eparm[2];
1269 #if defined(AFS_HPUX_ENV)
1271 * There used to be code here (duplicated from osi_Init()) for
1272 * initializing the semaphore used by AFS_GLOCK(). Was the
1273 * duplication to handle the case of a dynamically loaded kernel
1278 if (uap->syscall == AFSCALL_CALL) {
1280 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1281 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1283 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1285 } else if (uap->syscall == AFSCALL_SETPAG) {
1287 register proc_t *procp;
1289 procp = ttoproc(curthread);
1291 code = afs_setpag(&procp->p_cred);
1295 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1296 code = afs_setpag(p, args, retval);
1297 #else /* AFS_OSF_ENV */
1298 code = afs_setpag();
1302 } else if (uap->syscall == AFSCALL_PIOCTL) {
1305 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1307 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1308 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1310 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1314 } else if (uap->syscall == AFSCALL_ICREATE) {
1315 struct iparam iparams;
1317 code = copyin_iparam((char *)uap->parm3, &iparams);
1319 #if defined(KERNEL_HAVE_UERROR)
1324 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1325 iparams.param3, iparams.param4, rvp, CRED());
1327 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1328 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1329 iparams.param3, iparams.param4, retval);
1331 iparams.param3, iparams.param4);
1333 #endif /* AFS_SUN5_ENV */
1334 } else if (uap->syscall == AFSCALL_IOPEN) {
1336 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1338 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1339 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1341 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1343 #endif /* AFS_SUN5_ENV */
1344 } else if (uap->syscall == AFSCALL_IDEC) {
1346 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1348 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1349 #endif /* AFS_SUN5_ENV */
1350 } else if (uap->syscall == AFSCALL_IINC) {
1352 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1354 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1355 #endif /* AFS_SUN5_ENV */
1356 } else if (uap->syscall == AFSCALL_ICL) {
1358 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1360 #ifdef AFS_LINUX20_ENV
1362 /* ICL commands can return values. */
1363 code = -linux_ret; /* Gets negated again at exit below */
1367 #if defined(KERNEL_HAVE_UERROR)
1371 #endif /* !AFS_LINUX20_ENV */
1373 #if defined(KERNEL_HAVE_UERROR)
1380 #ifdef AFS_LINUX20_ENV
1386 #endif /* AFS_SGI_ENV */
1387 #endif /* !AFS_AIX32_ENV */
1390 * Initstate in the range 0 < x < 100 are early initialization states.
1391 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1392 * the cache may be initialized.
1393 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1394 * is done after all the cache initialization has been done.
1395 * Initstate of 200 means that the volume has been looked up once, possibly
1397 * Initstate of 300 means that the volume has been *successfully* looked up.
1399 int afs_CheckInit(void)
1401 register int code = 0;
1403 AFS_STATCNT(afs_CheckInit);
1404 if (afs_initState <= 100)
1405 code = ENXIO; /* never finished init phase */
1406 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1407 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1408 } else if (afs_initState == 200)
1409 code = ETIMEDOUT; /* didn't find root volume */
1413 int afs_shuttingdown = 0;
1414 void afs_shutdown(void)
1416 extern short afs_brsDaemons;
1417 extern afs_int32 afs_CheckServerDaemonStarted;
1418 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1419 extern struct osi_file *afs_cacheInodep;
1421 AFS_STATCNT(afs_shutdown);
1422 if (afs_shuttingdown) return;
1423 afs_shuttingdown = 1;
1424 if (afs_cold_shutdown) afs_warn("COLD ");
1425 else afs_warn("WARM ");
1426 afs_warn("shutting down of: CB... ");
1428 afs_termState = AFSOP_STOP_RXCALLBACK;
1429 rx_WakeupServerProcs();
1430 /* shutdown_rxkernel(); */
1431 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1432 afs_osi_Sleep(&afs_termState);
1434 afs_warn("afs... ");
1435 while (afs_termState == AFSOP_STOP_AFS) {
1436 afs_osi_CancelWait(&AFS_WaitHandler);
1437 afs_osi_Sleep(&afs_termState);
1439 if (afs_CheckServerDaemonStarted) {
1440 while (afs_termState == AFSOP_STOP_CS) {
1441 afs_osi_CancelWait(&AFS_CSWaitHandler);
1442 afs_osi_Sleep(&afs_termState);
1445 afs_warn("BkG... ");
1446 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1447 while (afs_termState == AFSOP_STOP_BKG) {
1448 afs_osi_Wakeup(&afs_brsDaemons);
1449 afs_osi_Sleep(&afs_termState);
1451 afs_warn("CTrunc... ");
1452 /* Cancel cache truncate daemon. */
1453 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1454 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1455 afs_osi_Sleep(&afs_termState);
1457 #ifdef AFS_AFSDB_ENV
1458 afs_warn("AFSDB... ");
1460 while (afs_termState == AFSOP_STOP_AFSDB)
1461 afs_osi_Sleep(&afs_termState);
1463 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1464 afs_warn("RxEvent... ");
1465 /* cancel rx event deamon */
1466 while (afs_termState == AFSOP_STOP_RXEVENT)
1467 afs_osi_Sleep(&afs_termState);
1468 #if defined(RXK_LISTENER_ENV)
1470 afs_warn("UnmaskRxkSignals... ");
1471 afs_osi_UnmaskRxkSignals();
1473 /* cancel rx listener */
1474 afs_warn("RxListener... ");
1475 osi_StopListener(); /* This closes rx_socket. */
1476 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1477 afs_warn("Sleep... ");
1478 afs_osi_Sleep(&afs_termState);
1482 afs_termState = AFSOP_STOP_COMPLETE;
1486 /* Close file only after daemons which can write to it are stopped. */
1487 if (afs_cacheInodep) /* memcache won't set this */
1489 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1490 afs_cacheInodep = 0;
1492 return; /* Just kill daemons for now */
1496 shutdown_rxkernel();
1500 shutdown_bufferpackage();
1506 shutdown_vnodeops();
1508 shutdown_exporter();
1509 shutdown_memcache();
1510 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1511 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1512 /* this routine does not exist in Ultrix systems... 93.01.19 */
1514 #endif /* AFS_DEC_ENV */
1517 /* The following hold the cm stats */
1519 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1520 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1521 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1523 afs_warn(" ALL allocated tables\n");
1524 afs_shuttingdown = 0;
1528 void shutdown_afstest(void)
1530 AFS_STATCNT(shutdown_afstest);
1531 afs_initState = afs_termState = afs_setTime = 0;
1532 AFS_Running = afs_CB_Running = 0;
1533 afs_CacheInit_Done = afs_Go_Done = 0;
1534 if (afs_cold_shutdown) {
1535 *afs_rootVolumeName = 0;
1540 /* In case there is a bunch of dynamically build bkg daemons to free */
1541 void afs_shutdown_BKG(void)
1543 AFS_STATCNT(shutdown_BKG);
1547 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1548 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1549 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1550 int afs_icl_sizeofLong = 1;
1552 int afs_icl_sizeofLong = 2;
1555 int afs_icl_sizeofLong = 1;
1558 int afs_icl_inited = 0;
1560 /* init function, called once, under afs_icl_lock */
1561 int afs_icl_Init(void)
1567 extern struct afs_icl_log *afs_icl_FindLog();
1568 extern struct afs_icl_set *afs_icl_FindSet();
1572 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1575 afs_int32 *lp, elts, flags;
1576 register afs_int32 code;
1577 struct afs_icl_log *logp;
1578 struct afs_icl_set *setp;
1579 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1581 #else /* AFS_SGI61_ENV */
1583 #endif /* AFS_SGI61_ENV */
1585 afs_int32 startCookie;
1586 afs_int32 allocated;
1587 struct afs_icl_log *tlp;
1590 if (!afs_suser(CRED())) { /* only root can run this code */
1594 if (!afs_suser()) { /* only root can run this code */
1595 #if defined(KERNEL_HAVE_UERROR)
1604 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1605 case ICL_OP_COPYOUT: /* copy ouy data */
1606 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1607 * return flags<<24 + nwords.
1608 * updates cookie to updated start (not end) if we had to
1609 * skip some records.
1611 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1612 if (code) return code;
1613 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1614 if (code) return code;
1615 logp = afs_icl_FindLog(tname);
1616 if (!logp) return ENOENT;
1617 #define BUFFERSIZE AFS_LRALLOCSIZ
1618 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1619 elts = BUFFERSIZE / sizeof(afs_int32);
1620 if (p3 < elts) elts = p3;
1621 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1622 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1625 osi_FreeLargeSpace((struct osi_buffer *) lp);
1628 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1629 if (code) goto done;
1630 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1631 if (code) goto done;
1632 *retval = (flags<<24) | (elts & 0xffffff);
1634 afs_icl_LogRele(logp);
1635 osi_FreeLargeSpace((struct osi_buffer *) lp);
1638 case ICL_OP_ENUMLOGS: /* enumerate logs */
1639 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1640 * return 0 for success, otherwise error.
1642 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1643 if (p1-- == 0) break;
1645 if (!tlp) return ENOENT; /* past the end of file */
1646 temp = strlen(tlp->name)+1;
1647 if (temp > p3) return EINVAL;
1648 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1649 if (!code) /* copy out size of log */
1650 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1653 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1654 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1655 * return 0 for success, otherwise error.
1657 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1658 if (code) return code;
1659 setp = afs_icl_FindSet(tname);
1660 if (!setp) return ENOENT;
1661 if (p2 > ICL_LOGSPERSET)
1663 if (!(tlp = setp->logs[p2]))
1665 temp = strlen(tlp->name)+1;
1666 if (temp > p4) return EINVAL;
1667 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1670 case ICL_OP_CLRLOG: /* clear specified log */
1671 /* zero out the specified log: p1=logname */
1672 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1673 if (code) return code;
1674 logp = afs_icl_FindLog(tname);
1675 if (!logp) return ENOENT;
1676 code = afs_icl_ZeroLog(logp);
1677 afs_icl_LogRele(logp);
1680 case ICL_OP_CLRSET: /* clear specified set */
1681 /* zero out the specified set: p1=setname */
1682 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1683 if (code) return code;
1684 setp = afs_icl_FindSet(tname);
1685 if (!setp) return ENOENT;
1686 code = afs_icl_ZeroSet(setp);
1687 afs_icl_SetRele(setp);
1690 case ICL_OP_CLRALL: /* clear all logs */
1691 /* zero out all logs -- no args */
1693 ObtainWriteLock(&afs_icl_lock,178);
1694 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1695 tlp->refCount++; /* hold this guy */
1696 ReleaseWriteLock(&afs_icl_lock);
1697 /* don't clear persistent logs */
1698 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1699 code = afs_icl_ZeroLog(tlp);
1700 ObtainWriteLock(&afs_icl_lock,179);
1701 if (--tlp->refCount == 0)
1702 afs_icl_ZapLog(tlp);
1705 ReleaseWriteLock(&afs_icl_lock);
1708 case ICL_OP_ENUMSETS: /* enumerate all sets */
1709 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1710 * return 0 for success, otherwise error.
1712 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1713 if (p1-- == 0) break;
1715 if (!setp) return ENOENT; /* past the end of file */
1716 temp = strlen(setp->name)+1;
1717 if (temp > p3) return EINVAL;
1718 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1719 if (!code) /* copy out size of log */
1720 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1723 case ICL_OP_SETSTAT: /* set status on a set */
1724 /* activate the specified set: p1=setname, p2=op */
1725 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1726 if (code) return code;
1727 setp = afs_icl_FindSet(tname);
1728 if (!setp) return ENOENT;
1729 code = afs_icl_SetSetStat(setp, p2);
1730 afs_icl_SetRele(setp);
1733 case ICL_OP_SETSTATALL: /* set status on all sets */
1734 /* activate the specified set: p1=op */
1736 ObtainWriteLock(&afs_icl_lock,180);
1737 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1738 setp->refCount++; /* hold this guy */
1739 ReleaseWriteLock(&afs_icl_lock);
1740 /* don't set states on persistent sets */
1741 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1742 code = afs_icl_SetSetStat(setp, p1);
1743 ObtainWriteLock(&afs_icl_lock,181);
1744 if (--setp->refCount == 0)
1745 afs_icl_ZapSet(setp);
1748 ReleaseWriteLock(&afs_icl_lock);
1751 case ICL_OP_SETLOGSIZE: /* set size of log */
1752 /* set the size of the specified log: p1=logname, p2=size (in words) */
1753 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1754 if (code) return code;
1755 logp = afs_icl_FindLog(tname);
1756 if (!logp) return ENOENT;
1757 code = afs_icl_LogSetSize(logp, p2);
1758 afs_icl_LogRele(logp);
1761 case ICL_OP_GETLOGINFO: /* get size of log */
1762 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1763 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1764 if (code) return code;
1765 logp = afs_icl_FindLog(tname);
1766 if (!logp) return ENOENT;
1767 allocated = !!logp->datap;
1768 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1770 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1771 afs_icl_LogRele(logp);
1774 case ICL_OP_GETSETINFO: /* get state of set */
1775 /* zero out the specified set: p1=setname, p2=&state */
1776 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1777 if (code) return code;
1778 setp = afs_icl_FindSet(tname);
1779 if (!setp) return ENOENT;
1780 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1781 afs_icl_SetRele(setp);
1792 afs_lock_t afs_icl_lock;
1794 /* exported routine: a 4 parameter event */
1795 int afs_icl_Event4(register struct afs_icl_set *setp, afs_int32 eventID,
1796 afs_int32 lAndT, long p1, long p2, long p3, long p4)
1798 register struct afs_icl_log *logp;
1801 register afs_int32 tmask;
1804 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1805 if (!ICL_SETACTIVE(setp)) return;
1808 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1809 ix = ICL_EVENTBYTE(eventID);
1810 ObtainReadLock(&setp->lock);
1811 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1812 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1814 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1818 if (mask == 0) break; /* break early */
1821 ReleaseReadLock(&setp->lock);
1824 /* Next 4 routines should be implemented via var-args or something.
1825 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1826 * Otherwise, could call afs_icl_Event4 directly.
1828 int afs_icl_Event3(register struct afs_icl_set *setp, afs_int32 eventID,
1829 afs_int32 lAndT, long p1, long p2, long p3)
1831 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1834 int afs_icl_Event2(register struct afs_icl_set *setp, afs_int32 eventID,
1835 afs_int32 lAndT, long p1, long p2)
1837 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1840 int afs_icl_Event1(register struct afs_icl_set *setp, afs_int32 eventID,
1841 afs_int32 lAndT, long p1)
1843 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1846 int afs_icl_Event0(register struct afs_icl_set *setp, afs_int32 eventID,
1849 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1852 struct afs_icl_log *afs_icl_allLogs = 0;
1854 /* function to purge records from the start of the log, until there
1855 * is at least minSpace long's worth of space available without
1856 * making the head and the tail point to the same word.
1858 * Log must be write-locked.
1860 static afs_icl_GetLogSpace(register struct afs_icl_log *logp, afs_int32 minSpace)
1862 register unsigned int tsize;
1864 while (logp->logSize - logp->logElements <= minSpace) {
1866 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1867 logp->logElements -= tsize;
1868 logp->firstUsed += tsize;
1869 if (logp->firstUsed >= logp->logSize)
1870 logp->firstUsed -= logp->logSize;
1871 logp->baseCookie += tsize;
1875 /* append string astr to buffer, including terminating null char.
1877 * log must be write-locked.
1879 #define ICL_CHARSPERLONG 4
1880 static afs_int32 afs_icl_AppendString(struct afs_icl_log *logp, char *astr)
1882 char *op; /* ptr to char to write */
1884 register int bib; /* bytes in buffer */
1887 op = (char *) &(logp->datap[logp->firstFree]);
1891 if (++bib >= ICL_CHARSPERLONG) {
1894 if (++(logp->firstFree) >= logp->logSize) {
1895 logp->firstFree = 0;
1896 op = (char *) &(logp->datap[0]);
1898 logp->logElements++;
1903 /* if we've used this word at all, allocate it */
1904 if (++(logp->firstFree) >= logp->logSize) {
1905 logp->firstFree = 0;
1907 logp->logElements++;
1911 /* add a long to the log, ignoring overflow (checked already) */
1912 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1913 #define ICL_APPENDINT32(lp, x) \
1915 (lp)->datap[(lp)->firstFree] = (x); \
1916 if (++((lp)->firstFree) >= (lp)->logSize) { \
1917 (lp)->firstFree = 0; \
1919 (lp)->logElements++; \
1922 #define ICL_APPENDLONG(lp, x) \
1924 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1925 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1928 #else /* AFS_ALPHA_ENV */
1929 #define ICL_APPENDLONG(lp, x) \
1931 (lp)->datap[(lp)->firstFree] = (x); \
1932 if (++((lp)->firstFree) >= (lp)->logSize) { \
1933 (lp)->firstFree = 0; \
1935 (lp)->logElements++; \
1937 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1938 #endif /* AFS_ALPHA_ENV */
1940 /* routine to tell whether we're dealing with the address or the
1943 int afs_icl_UseAddr(int type)
1945 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1946 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
1952 /* Function to append a record to the log. Written for speed
1953 * since we know that we're going to have to make this work fast
1954 * pretty soon, anyway. The log must be unlocked.
1957 int afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
1958 afs_int32 types, long p1, long p2, long p3, long p4)
1960 int rsize; /* record size in longs */
1961 register int tsize; /* temp size */
1965 t4 = types & 0x3f; /* decode types */
1973 osi_GetTime(&tv); /* It panics for solaris if inside */
1974 ObtainWriteLock(&logp->lock,182);
1976 ReleaseWriteLock(&logp->lock);
1980 /* get timestamp as # of microseconds since some time that doesn't
1981 * change that often. This algorithm ticks over every 20 minutes
1982 * or so (1000 seconds). Write a timestamp record if it has.
1984 if (tv.tv_sec - logp->lastTS > 1024)
1986 /* the timer has wrapped -- write a timestamp record */
1987 if (logp->logSize - logp->logElements <= 5)
1988 afs_icl_GetLogSpace(logp, 5);
1990 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1991 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1992 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1993 ICL_APPENDINT32(logp,
1994 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1995 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1997 logp->lastTS = tv.tv_sec;
2000 rsize = 4; /* base case */
2002 /* compute size of parameter p1. Only tricky case is string.
2003 * In that case, we have to call strlen to get the string length.
2005 ICL_SIZEHACK(t1, p1);
2008 /* compute size of parameter p2. Only tricky case is string.
2009 * In that case, we have to call strlen to get the string length.
2011 ICL_SIZEHACK(t2, p2);
2014 /* compute size of parameter p3. Only tricky case is string.
2015 * In that case, we have to call strlen to get the string length.
2017 ICL_SIZEHACK(t3, p3);
2020 /* compute size of parameter p4. Only tricky case is string.
2021 * In that case, we have to call strlen to get the string length.
2023 ICL_SIZEHACK(t4, p4);
2026 /* At this point, we've computed all of the parameter sizes, and
2027 * have in rsize the size of the entire record we want to append.
2028 * Next, we check that we actually have room in the log to do this
2029 * work, and then we do the append.
2032 ReleaseWriteLock(&logp->lock);
2033 return; /* log record too big to express */
2036 if (logp->logSize - logp->logElements <= rsize)
2037 afs_icl_GetLogSpace(logp, rsize);
2039 ICL_APPENDINT32(logp,
2040 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
2041 ICL_APPENDINT32(logp, (afs_int32)op);
2042 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
2043 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
2046 /* marshall parameter 1 now */
2047 if (t1 == ICL_TYPE_STRING) {
2048 afs_icl_AppendString(logp, (char *) p1);
2050 else if (t1 == ICL_TYPE_HYPER) {
2051 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
2052 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
2054 else if (t1 == ICL_TYPE_INT64) {
2055 #ifdef AFSLITTLE_ENDIAN
2056 #ifdef AFS_64BIT_CLIENT
2057 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2058 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2059 #else /* AFS_64BIT_CLIENT */
2060 ICL_APPENDINT32(logp, (afs_int32) p1);
2061 ICL_APPENDINT32(logp, (afs_int32) 0);
2062 #endif /* AFS_64BIT_CLIENT */
2063 #else /* AFSLITTLE_ENDIAN */
2064 #ifdef AFS_64BIT_CLIENT
2065 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2066 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2067 #else /* AFS_64BIT_CLIENT */
2068 ICL_APPENDINT32(logp, (afs_int32) 0);
2069 ICL_APPENDINT32(logp, (afs_int32) p1);
2070 #endif /* AFS_64BIT_CLIENT */
2071 #endif /* AFSLITTLE_ENDIAN */
2073 else if (t1 == ICL_TYPE_FID) {
2074 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2075 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2076 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
2077 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
2079 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2080 else if (t1 == ICL_TYPE_INT32)
2081 ICL_APPENDINT32(logp, (afs_int32)p1);
2082 #endif /* AFS_ALPHA_ENV */
2083 else ICL_APPENDLONG(logp, p1);
2086 /* marshall parameter 2 now */
2087 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
2088 else if (t2 == ICL_TYPE_HYPER) {
2089 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
2090 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
2092 else if (t2 == ICL_TYPE_INT64) {
2093 #ifdef AFSLITTLE_ENDIAN
2094 #ifdef AFS_64BIT_CLIENT
2095 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2096 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2097 #else /* AFS_64BIT_CLIENT */
2098 ICL_APPENDINT32(logp, (afs_int32) p2);
2099 ICL_APPENDINT32(logp, (afs_int32) 0);
2100 #endif /* AFS_64BIT_CLIENT */
2101 #else /* AFSLITTLE_ENDIAN */
2102 #ifdef AFS_64BIT_CLIENT
2103 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2104 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2105 #else /* AFS_64BIT_CLIENT */
2106 ICL_APPENDINT32(logp, (afs_int32) 0);
2107 ICL_APPENDINT32(logp, (afs_int32) p2);
2108 #endif /* AFS_64BIT_CLIENT */
2109 #endif /* AFSLITTLE_ENDIAN */
2111 else if (t2 == ICL_TYPE_FID) {
2112 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2113 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2114 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
2115 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
2117 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2118 else if (t2 == ICL_TYPE_INT32)
2119 ICL_APPENDINT32(logp, (afs_int32)p2);
2120 #endif /* AFS_ALPHA_ENV */
2121 else ICL_APPENDLONG(logp, p2);
2124 /* marshall parameter 3 now */
2125 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
2126 else if (t3 == ICL_TYPE_HYPER) {
2127 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
2128 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
2130 else if (t3 == ICL_TYPE_INT64) {
2131 #ifdef AFSLITTLE_ENDIAN
2132 #ifdef AFS_64BIT_CLIENT
2133 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2134 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2135 #else /* AFS_64BIT_CLIENT */
2136 ICL_APPENDINT32(logp, (afs_int32) p3);
2137 ICL_APPENDINT32(logp, (afs_int32) 0);
2138 #endif /* AFS_64BIT_CLIENT */
2139 #else /* AFSLITTLE_ENDIAN */
2140 #ifdef AFS_64BIT_CLIENT
2141 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2142 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2143 #else /* AFS_64BIT_CLIENT */
2144 ICL_APPENDINT32(logp, (afs_int32) 0);
2145 ICL_APPENDINT32(logp, (afs_int32) p3);
2146 #endif /* AFS_64BIT_CLIENT */
2147 #endif /* AFSLITTLE_ENDIAN */
2149 else if (t3 == ICL_TYPE_FID) {
2150 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2151 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2152 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
2153 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
2155 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2156 else if (t3 == ICL_TYPE_INT32)
2157 ICL_APPENDINT32(logp, (afs_int32)p3);
2158 #endif /* AFS_ALPHA_ENV */
2159 else ICL_APPENDLONG(logp, p3);
2162 /* marshall parameter 4 now */
2163 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
2164 else if (t4 == ICL_TYPE_HYPER) {
2165 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
2166 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
2168 else if (t4 == ICL_TYPE_INT64) {
2169 #ifdef AFSLITTLE_ENDIAN
2170 #ifdef AFS_64BIT_CLIENT
2171 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2172 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2173 #else /* AFS_64BIT_CLIENT */
2174 ICL_APPENDINT32(logp, (afs_int32) p4);
2175 ICL_APPENDINT32(logp, (afs_int32) 0);
2176 #endif /* AFS_64BIT_CLIENT */
2177 #else /* AFSLITTLE_ENDIAN */
2178 #ifdef AFS_64BIT_CLIENT
2179 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2180 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2181 #else /* AFS_64BIT_CLIENT */
2182 ICL_APPENDINT32(logp, (afs_int32) 0);
2183 ICL_APPENDINT32(logp, (afs_int32) p4);
2184 #endif /* AFS_64BIT_CLIENT */
2185 #endif /* AFSLITTLE_ENDIAN */
2187 else if (t4 == ICL_TYPE_FID) {
2188 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2189 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2190 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
2191 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
2193 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2194 else if (t4 == ICL_TYPE_INT32)
2195 ICL_APPENDINT32(logp, (afs_int32)p4);
2196 #endif /* AFS_ALPHA_ENV */
2197 else ICL_APPENDLONG(logp, p4);
2199 ReleaseWriteLock(&logp->lock);
2202 /* create a log with size logSize; return it in *outLogpp and tag
2203 * it with name "name."
2205 int afs_icl_CreateLog(char *name, afs_int32 logSize, struct afs_icl_log **outLogpp)
2207 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
2210 /* create a log with size logSize; return it in *outLogpp and tag
2211 * it with name "name." 'flags' can be set to make the log unclearable.
2213 int afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, afs_uint32 flags,
2214 struct afs_icl_log **outLogpp)
2216 register struct afs_icl_log *logp;
2218 /* add into global list under lock */
2219 ObtainWriteLock(&afs_icl_lock,183);
2220 if (!afs_icl_inited) afs_icl_Init();
2222 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
2223 if (strcmp(logp->name, name) == 0) {
2224 /* found it already created, just return it */
2227 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2229 ObtainWriteLock(&logp->lock,184);
2230 logp->states |= ICL_LOGF_PERSISTENT;
2231 ReleaseWriteLock(&logp->lock);
2233 ReleaseWriteLock(&afs_icl_lock);
2238 logp = (struct afs_icl_log *)
2239 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
2240 memset((caddr_t)logp, 0, sizeof(*logp));
2243 logp->name = osi_AllocSmallSpace(strlen(name)+1);
2244 strcpy(logp->name, name);
2245 LOCK_INIT(&logp->lock, "logp lock");
2246 logp->logSize = logSize;
2247 logp->datap = NULL; /* don't allocate it until we need it */
2249 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2250 logp->states |= ICL_LOGF_PERSISTENT;
2252 logp->nextp = afs_icl_allLogs;
2253 afs_icl_allLogs = logp;
2254 ReleaseWriteLock(&afs_icl_lock);
2260 /* called with a log, a pointer to a buffer, the size of the buffer
2261 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
2262 * and returns data in the provided buffer, and returns output flags
2263 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
2264 * find the record with cookie value cookie.
2266 int afs_icl_CopyOut(register struct afs_icl_log *logp, afs_int32 *bufferp,
2267 afs_int32 *bufSizep, afs_uint32 *cookiep, afs_int32 *flagsp)
2269 afs_int32 nwords; /* number of words to copy out */
2270 afs_uint32 startCookie; /* first cookie to use */
2271 register afs_int32 i;
2272 afs_int32 outWords; /* words we've copied out */
2273 afs_int32 inWords; /* max words to copy out */
2274 afs_int32 code; /* return code */
2275 afs_int32 ix; /* index we're copying from */
2276 afs_int32 outFlags; /* return flags */
2277 afs_int32 inFlags; /* flags passed in */
2280 inWords = *bufSizep; /* max to copy out */
2281 outWords = 0; /* amount copied out */
2282 startCookie = *cookiep;
2287 ObtainWriteLock(&logp->lock,185);
2289 ReleaseWriteLock(&logp->lock);
2293 /* first, compute the index of the start cookie we've been passed */
2295 /* (re-)compute where we should start */
2296 if (startCookie < logp->baseCookie) {
2297 if (startCookie) /* missed some output */
2298 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2299 /* skip to the first available record */
2300 startCookie = logp->baseCookie;
2301 *cookiep = startCookie;
2304 /* compute where we find the first element to copy out */
2305 ix = logp->firstUsed + startCookie - logp->baseCookie;
2306 if (ix >= logp->logSize) ix -= logp->logSize;
2308 /* if have some data now, break out and process it */
2309 if (startCookie - logp->baseCookie < logp->logElements) break;
2311 /* At end of log, so clear it if we need to */
2312 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
2314 logp->firstUsed = logp->firstFree = 0;
2315 logp->logElements = 0;
2317 /* otherwise, either wait for the data to arrive, or return */
2318 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2319 ReleaseWriteLock(&logp->lock);
2323 logp->states |= ICL_LOGF_WAITING;
2324 ReleaseWriteLock(&logp->lock);
2325 afs_osi_Sleep(&logp->lock);
2326 ObtainWriteLock(&logp->lock,186);
2328 /* copy out data from ix to logSize or firstFree, depending
2329 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2330 * be careful not to copy out more than nwords.
2332 if (ix >= logp->firstUsed) {
2333 if (logp->firstUsed <= logp->firstFree)
2335 end = logp->firstFree; /* first element not to copy */
2337 end = logp->logSize;
2338 nwords = inWords; /* don't copy more than this */
2339 if (end - ix < nwords)
2342 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2347 /* if we're going to copy more out below, we'll start here */
2350 /* now, if active part of the log has wrapped, there's more stuff
2351 * starting at the head of the log. Copy out more from there.
2353 if (logp->firstUsed > logp->firstFree
2354 && ix < logp->firstFree && inWords > 0) {
2355 /* (more to) copy out from the wrapped section at the
2356 * start of the log. May get here even if didn't copy any
2357 * above, if the cookie points directly into the wrapped section.
2360 if (logp->firstFree - ix < nwords)
2361 nwords = logp->firstFree - ix;
2362 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2368 ReleaseWriteLock(&logp->lock);
2372 *bufSizep = outWords;
2378 /* return basic parameter information about a log */
2379 int afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 *maxSizep,
2380 afs_int32 *curSizep)
2382 ObtainReadLock(&logp->lock);
2383 *maxSizep = logp->logSize;
2384 *curSizep = logp->logElements;
2385 ReleaseReadLock(&logp->lock);
2390 /* hold and release logs */
2391 int afs_icl_LogHold(register struct afs_icl_log *logp)
2393 ObtainWriteLock(&afs_icl_lock,187);
2395 ReleaseWriteLock(&afs_icl_lock);
2399 /* hold and release logs, called with lock already held */
2400 int afs_icl_LogHoldNL(register struct afs_icl_log *logp)
2406 /* keep track of how many sets believe the log itself is allocated */
2407 int afs_icl_LogUse(register struct afs_icl_log *logp)
2409 ObtainWriteLock(&logp->lock,188);
2410 if (logp->setCount == 0) {
2411 /* this is the first set actually using the log -- allocate it */
2412 if (logp->logSize == 0) {
2413 /* we weren't passed in a hint and it wasn't set */
2414 logp->logSize = ICL_DEFAULT_LOGSIZE;
2416 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2417 #ifdef KERNEL_HAVE_PIN
2418 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2422 ReleaseWriteLock(&logp->lock);
2426 /* decrement the number of real users of the log, free if possible */
2427 int afs_icl_LogFreeUse(register struct afs_icl_log *logp)
2429 ObtainWriteLock(&logp->lock,189);
2430 if (--logp->setCount == 0) {
2431 /* no more users -- free it (but keep log structure around)*/
2432 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2433 #ifdef KERNEL_HAVE_PIN
2434 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2436 logp->firstUsed = logp->firstFree = 0;
2437 logp->logElements = 0;
2440 ReleaseWriteLock(&logp->lock);
2444 /* set the size of the log to 'logSize' */
2445 int afs_icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
2447 ObtainWriteLock(&logp->lock,190);
2449 /* nothing to worry about since it's not allocated */
2450 logp->logSize = logSize;
2454 logp->firstUsed = logp->firstFree = 0;
2455 logp->logElements = 0;
2457 /* free and allocate a new one */
2458 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2459 #ifdef KERNEL_HAVE_PIN
2460 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2462 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2463 #ifdef KERNEL_HAVE_PIN
2464 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2466 logp->logSize = logSize;
2468 ReleaseWriteLock(&logp->lock);
2473 /* free a log. Called with afs_icl_lock locked. */
2474 int afs_icl_ZapLog(register struct afs_icl_log *logp)
2476 register struct afs_icl_log **lpp, *tp;
2478 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2480 /* found the dude we want to remove */
2482 osi_FreeSmallSpace(logp->name);
2483 osi_FreeSmallSpace(logp->datap);
2484 osi_FreeSmallSpace(logp);
2485 break; /* won't find it twice */
2491 /* do the release, watching for deleted entries */
2492 int afs_icl_LogRele(register struct afs_icl_log *logp)
2494 ObtainWriteLock(&afs_icl_lock,191);
2495 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2496 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2498 ReleaseWriteLock(&afs_icl_lock);
2502 /* do the release, watching for deleted entries, log already held */
2503 int afs_icl_LogReleNL(register struct afs_icl_log *logp)
2505 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2506 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2511 /* zero out the log */
2512 int afs_icl_ZeroLog(register struct afs_icl_log *logp)
2514 ObtainWriteLock(&logp->lock,192);
2515 logp->firstUsed = logp->firstFree = 0;
2516 logp->logElements = 0;
2517 logp->baseCookie = 0;
2518 ReleaseWriteLock(&logp->lock);
2522 /* free a log entry, and drop its reference count */
2523 int afs_icl_LogFree(register struct afs_icl_log *logp)
2525 ObtainWriteLock(&logp->lock,193);
2526 logp->states |= ICL_LOGF_DELETED;
2527 ReleaseWriteLock(&logp->lock);
2528 afs_icl_LogRele(logp);
2532 /* find a log by name, returning it held */
2533 struct afs_icl_log *afs_icl_FindLog(char *name)
2535 register struct afs_icl_log *tp;
2536 ObtainWriteLock(&afs_icl_lock,194);
2537 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2538 if (strcmp(tp->name, name) == 0) {
2539 /* this is the dude we want */
2544 ReleaseWriteLock(&afs_icl_lock);
2548 int afs_icl_EnumerateLogs(int (*aproc)(), char *arock)
2550 register struct afs_icl_log *tp;
2551 register afs_int32 code;
2554 ObtainWriteLock(&afs_icl_lock,195);
2555 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2556 tp->refCount++; /* hold this guy */
2557 ReleaseWriteLock(&afs_icl_lock);
2558 ObtainReadLock(&tp->lock);
2559 code = (*aproc)(tp->name, arock, tp);
2560 ReleaseReadLock(&tp->lock);
2561 ObtainWriteLock(&afs_icl_lock,196);
2562 if (--tp->refCount == 0)
2566 ReleaseWriteLock(&afs_icl_lock);
2570 struct afs_icl_set *afs_icl_allSets = 0;
2572 int afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
2573 struct afs_icl_log *fatalLogp, struct afs_icl_set **outSetpp)
2575 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2576 /*flags*/0, outSetpp);
2579 /* create a set, given pointers to base and fatal logs, if any.
2580 * Logs are unlocked, but referenced, and *outSetpp is returned
2581 * referenced. Function bumps reference count on logs, since it
2582 * addds references from the new afs_icl_set. When the set is destroyed,
2583 * those references will be released.
2585 int afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
2586 struct afs_icl_log *fatalLogp, afs_uint32 flags, struct afs_icl_set **outSetpp)
2588 register struct afs_icl_set *setp;
2590 afs_int32 states = ICL_DEFAULT_SET_STATES;
2592 ObtainWriteLock(&afs_icl_lock,197);
2593 if (!afs_icl_inited) afs_icl_Init();
2595 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2596 if (strcmp(setp->name, name) == 0) {
2599 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2601 ObtainWriteLock(&setp->lock,198);
2602 setp->states |= ICL_SETF_PERSISTENT;
2603 ReleaseWriteLock(&setp->lock);
2605 ReleaseWriteLock(&afs_icl_lock);
2610 /* determine initial state */
2611 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2612 states = ICL_SETF_ACTIVE;
2613 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2614 states = ICL_SETF_FREED;
2615 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2616 states |= ICL_SETF_PERSISTENT;
2618 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2619 memset((caddr_t)setp, 0, sizeof(*setp));
2621 if (states & ICL_SETF_FREED)
2622 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2623 setp->states = states;
2625 LOCK_INIT(&setp->lock, "setp lock");
2626 /* next lock is obtained in wrong order, hierarchy-wise, but
2627 * it doesn't matter, since no one can find this lock yet, since
2628 * the afs_icl_lock is still held, and thus the obtain can't block.
2630 ObtainWriteLock(&setp->lock,199);
2631 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2632 strcpy(setp->name, name);
2633 setp->nevents = ICL_DEFAULTEVENTS;
2634 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2635 #ifdef KERNEL_HAVE_PIN
2636 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2638 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2639 setp->eventFlags[i] = 0xff; /* default to enabled */
2641 /* update this global info under the afs_icl_lock */
2642 setp->nextp = afs_icl_allSets;
2643 afs_icl_allSets = setp;
2644 ReleaseWriteLock(&afs_icl_lock);
2646 /* set's basic lock is still held, so we can finish init */
2648 setp->logs[0] = baseLogp;
2649 afs_icl_LogHold(baseLogp);
2650 if (!(setp->states & ICL_SETF_FREED))
2651 afs_icl_LogUse(baseLogp); /* log is actually being used */
2654 setp->logs[1] = fatalLogp;
2655 afs_icl_LogHold(fatalLogp);
2656 if (!(setp->states & ICL_SETF_FREED))
2657 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2659 ReleaseWriteLock(&setp->lock);
2665 /* function to change event enabling information for a particular set */
2666 int afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
2670 ObtainWriteLock(&setp->lock,200);
2671 if (!ICL_EVENTOK(setp, eventID)) {
2672 ReleaseWriteLock(&setp->lock);
2675 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2677 *tp |= ICL_EVENTMASK(eventID);
2679 *tp &= ~(ICL_EVENTMASK(eventID));
2680 ReleaseWriteLock(&setp->lock);
2684 /* return indication of whether a particular event ID is enabled
2685 * for tracing. If *getValuep is set to 0, the event is disabled,
2686 * otherwise it is enabled. All events start out enabled by default.
2688 int afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID,
2691 ObtainReadLock(&setp->lock);
2692 if (!ICL_EVENTOK(setp, eventID)) {
2693 ReleaseWriteLock(&setp->lock);
2696 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2700 ReleaseReadLock(&setp->lock);
2704 /* hold and release event sets */
2705 int afs_icl_SetHold(register struct afs_icl_set *setp)
2707 ObtainWriteLock(&afs_icl_lock,201);
2709 ReleaseWriteLock(&afs_icl_lock);
2713 /* free a set. Called with afs_icl_lock locked */
2714 int afs_icl_ZapSet(register struct afs_icl_set *setp)
2716 register struct afs_icl_set **lpp, *tp;
2718 register struct afs_icl_log *tlp;
2720 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2722 /* found the dude we want to remove */
2724 osi_FreeSmallSpace(setp->name);
2725 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2726 #ifdef KERNEL_HAVE_PIN
2727 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2729 for(i=0; i < ICL_LOGSPERSET; i++) {
2730 if ((tlp = setp->logs[i]))
2731 afs_icl_LogReleNL(tlp);
2733 osi_FreeSmallSpace(setp);
2734 break; /* won't find it twice */
2740 /* do the release, watching for deleted entries */
2741 int afs_icl_SetRele(register struct afs_icl_set *setp)
2743 ObtainWriteLock(&afs_icl_lock,202);
2744 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2745 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2747 ReleaseWriteLock(&afs_icl_lock);
2751 /* free a set entry, dropping its reference count */
2752 int afs_icl_SetFree(register struct afs_icl_set *setp)
2754 ObtainWriteLock(&setp->lock,203);
2755 setp->states |= ICL_SETF_DELETED;
2756 ReleaseWriteLock(&setp->lock);
2757 afs_icl_SetRele(setp);
2761 /* find a set by name, returning it held */
2762 struct afs_icl_set *afs_icl_FindSet(char *name)
2764 register struct afs_icl_set *tp;
2765 ObtainWriteLock(&afs_icl_lock,204);
2766 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2767 if (strcmp(tp->name, name) == 0) {
2768 /* this is the dude we want */
2773 ReleaseWriteLock(&afs_icl_lock);
2777 /* zero out all the logs in the set */
2778 int afs_icl_ZeroSet(struct afs_icl_set *setp)
2783 struct afs_icl_log *logp;
2785 ObtainReadLock(&setp->lock);
2786 for(i = 0; i < ICL_LOGSPERSET; i++) {
2787 logp = setp->logs[i];
2789 afs_icl_LogHold(logp);
2790 tcode = afs_icl_ZeroLog(logp);
2791 if (tcode != 0) code = tcode; /* save the last bad one */
2792 afs_icl_LogRele(logp);
2795 ReleaseReadLock(&setp->lock);
2799 int afs_icl_EnumerateSets(int (*aproc)(), char *arock)
2801 register struct afs_icl_set *tp, *np;
2802 register afs_int32 code;
2805 ObtainWriteLock(&afs_icl_lock,205);
2806 for(tp = afs_icl_allSets; tp; tp=np) {
2807 tp->refCount++; /* hold this guy */
2808 ReleaseWriteLock(&afs_icl_lock);
2809 code = (*aproc)(tp->name, arock, tp);
2810 ObtainWriteLock(&afs_icl_lock,206);
2811 np = tp->nextp; /* tp may disappear next, but not np */
2812 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2816 ReleaseWriteLock(&afs_icl_lock);
2820 int afs_icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
2824 struct afs_icl_log *logp;
2826 ObtainWriteLock(&setp->lock,207);
2827 for(i = 0; i < ICL_LOGSPERSET; i++) {
2828 if (!setp->logs[i]) {
2829 setp->logs[i] = newlogp;
2831 afs_icl_LogHold(newlogp);
2832 if (!(setp->states & ICL_SETF_FREED)) {
2833 /* bump up the number of sets using the log */
2834 afs_icl_LogUse(newlogp);
2839 ReleaseWriteLock(&setp->lock);
2843 int afs_icl_SetSetStat(struct afs_icl_set *setp, int op)
2847 struct afs_icl_log *logp;
2849 ObtainWriteLock(&setp->lock,208);
2851 case ICL_OP_SS_ACTIVATE: /* activate a log */
2853 * If we are not already active, see if we have released
2854 * our demand that the log be allocated (FREED set). If
2855 * we have, reassert our desire.
2857 if (!(setp->states & ICL_SETF_ACTIVE)) {
2858 if (setp->states & ICL_SETF_FREED) {
2859 /* have to reassert desire for logs */
2860 for(i = 0; i < ICL_LOGSPERSET; i++) {
2861 logp = setp->logs[i];
2863 afs_icl_LogHold(logp);
2864 afs_icl_LogUse(logp);
2865 afs_icl_LogRele(logp);
2868 setp->states &= ~ICL_SETF_FREED;
2870 setp->states |= ICL_SETF_ACTIVE;
2875 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2876 /* this doesn't require anything beyond clearing the ACTIVE flag */
2877 setp->states &= ~ICL_SETF_ACTIVE;
2881 case ICL_OP_SS_FREE: /* deassert design for log */
2883 * if we are already in this state, do nothing; otherwise
2884 * deassert desire for log
2886 if (setp->states & ICL_SETF_ACTIVE)
2889 if (!(setp->states & ICL_SETF_FREED)) {
2890 for(i = 0; i < ICL_LOGSPERSET; i++) {
2891 logp = setp->logs[i];
2893 afs_icl_LogHold(logp);
2894 afs_icl_LogFreeUse(logp);
2895 afs_icl_LogRele(logp);
2898 setp->states |= ICL_SETF_FREED;
2907 ReleaseWriteLock(&setp->lock);