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"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
17 #include "afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h"
19 #include "rx/rx_globals.h"
20 #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
23 #include "h/hashing.h"
25 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN60_ENV)
26 #include "netinet/in_var.h"
28 #endif /* !defined(UKERNEL) */
29 #ifdef AFS_LINUX22_ENV
30 #include "h/smp_lock.h"
34 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV)
35 #define AFS_MINBUFFERS 100
37 #define AFS_MINBUFFERS 50
41 afs_int32 hosts[MAXCELLHOSTS];
45 char afs_zeros[AFS_ZEROS];
46 char afs_rootVolumeName[64] = "";
47 struct afs_icl_set *afs_iclSetp = (struct afs_icl_set *)0;
48 struct afs_icl_set *afs_iclLongTermSetp = (struct afs_icl_set *)0;
49 afs_uint32 rx_bindhost;
51 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
52 kmutex_t afs_global_lock;
53 kmutex_t afs_rxglobal_lock;
56 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
57 long afs_global_owner;
60 #if defined(AFS_OSF_ENV)
61 simple_lock_data_t afs_global_lock;
64 #if defined(AFS_DARWIN_ENV)
65 struct lock__bsd__ afs_global_lock;
68 #if defined(AFS_XBSD_ENV) && !defined(AFS_FBSD50_ENV)
69 struct lock afs_global_lock;
70 struct proc *afs_global_owner;
73 struct mtx afs_global_mtx;
76 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
77 thread_t afs_global_owner;
78 #endif /* AFS_OSF_ENV */
80 #if defined(AFS_AIX41_ENV)
81 simple_lock_data afs_global_lock;
84 afs_int32 afs_initState = 0;
85 afs_int32 afs_termState = 0;
86 afs_int32 afs_setTime = 0;
87 int afs_cold_shutdown = 0;
88 char afs_SynchronousCloses = '\0';
89 static int afs_CB_Running = 0;
90 static int AFS_Running = 0;
91 static int afs_CacheInit_Done = 0;
92 static int afs_Go_Done = 0;
93 extern struct interfaceAddr afs_cb_interface;
94 static int afs_RX_Running = 0;
95 static int afs_InitSetup_done = 0;
97 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
98 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
101 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval);
103 static int afscall_set_rxpck_received = 0;
105 #if defined(AFS_HPUX_ENV)
106 extern int afs_vfs_mount();
107 #endif /* defined(AFS_HPUX_ENV) */
109 /* This is code which needs to be called once when the first daemon enters
110 * the client. A non-zero return means an error and AFS should not start.
113 afs_InitSetup(int preallocs)
115 extern void afs_InitStats();
118 if (afs_InitSetup_done)
123 * Set up all the AFS statistics variables. This should be done
124 * exactly once, and it should be done here, the first resource-setting
125 * routine to be called by the CM/RX.
128 #endif /* AFS_NOSTATS */
130 memset(afs_zeros, 0, AFS_ZEROS);
133 if(!afscall_set_rxpck_received)
134 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
135 code = rx_InitHost(rx_bindhost, htons(7001));
137 printf("AFS: RX failed to initialize %d).\n", code);
140 rx_SetRxDeadTime(afs_rx_deadtime);
141 /* resource init creates the services */
142 afs_ResourceInit(preallocs);
144 afs_InitSetup_done = 1;
145 afs_osi_Wakeup(&afs_InitSetup_done);
150 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)
151 struct afsd_thread_info {
153 struct completion *complete;
157 afsd_thread(void *rock)
159 struct afsd_thread_info *arg = rock;
160 unsigned long parm = arg->parm;
161 #ifdef SYS_SETPRIORITY_EXPORTED
162 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
164 #if defined(AFS_LINUX26_ENV)
169 /* doesn't do much, since we were forked from keventd, but
170 * does call mm_release, which wakes up our parent (since it
171 * used CLONE_VFORK) */
172 #if !defined(AFS_LINUX26_ENV)
175 afs_osi_MaskSignals();
177 case AFSOP_START_RXCALLBACK:
178 sprintf(current->comm, "afs_cbstart");
180 complete(arg->complete);
182 while (afs_RX_Running != 2)
183 afs_osi_Sleep(&afs_RX_Running);
184 sprintf(current->comm, "afs_callback");
185 afs_RXCallBackServer();
187 complete_and_exit(0, 0);
189 case AFSOP_START_AFS:
190 sprintf(current->comm, "afs_afsstart");
192 complete(arg->complete);
194 while (afs_initState < AFSOP_START_AFS)
195 afs_osi_Sleep(&afs_initState);
196 afs_initState = AFSOP_START_BKG;
197 afs_osi_Wakeup(&afs_initState);
198 sprintf(current->comm, "afsd");
201 complete_and_exit(0, 0);
203 case AFSOP_START_BKG:
204 sprintf(current->comm, "afs_bkgstart");
206 complete(arg->complete);
207 while (afs_initState < AFSOP_START_BKG)
208 afs_osi_Sleep(&afs_initState);
209 if (afs_initState < AFSOP_GO) {
210 afs_initState = AFSOP_GO;
211 afs_osi_Wakeup(&afs_initState);
213 sprintf(current->comm, "afs_background");
214 afs_BackgroundDaemon();
216 complete_and_exit(0, 0);
218 case AFSOP_START_TRUNCDAEMON:
219 sprintf(current->comm, "afs_trimstart");
221 complete(arg->complete);
222 while (afs_initState < AFSOP_GO)
223 afs_osi_Sleep(&afs_initState);
224 sprintf(current->comm, "afs_cachetrim");
225 afs_CacheTruncateDaemon();
227 complete_and_exit(0, 0);
230 sprintf(current->comm, "afs_checkserver");
232 complete(arg->complete);
233 afs_CheckServerDaemon();
235 complete_and_exit(0, 0);
237 case AFSOP_RXEVENT_DAEMON:
238 sprintf(current->comm, "afs_evtstart");
239 #ifdef SYS_SETPRIORITY_EXPORTED
240 sys_setpriority(PRIO_PROCESS, 0, -10);
242 #ifdef CURRENT_INCLUDES_NICE
247 complete(arg->complete);
248 while (afs_initState < AFSOP_START_BKG)
249 afs_osi_Sleep(&afs_initState);
250 sprintf(current->comm, "afs_rxevent");
251 afs_rxevent_daemon();
253 complete_and_exit(0, 0);
255 case AFSOP_RXLISTENER_DAEMON:
256 sprintf(current->comm, "afs_lsnstart");
257 #ifdef SYS_SETPRIORITY_EXPORTED
258 sys_setpriority(PRIO_PROCESS, 0, -10);
260 #ifdef CURRENT_INCLUDES_NICE
265 complete(arg->complete);
266 afs_initState = AFSOP_START_AFS;
267 afs_osi_Wakeup(&afs_initState);
269 afs_osi_Wakeup(&afs_RX_Running);
270 afs_osi_RxkRegister();
271 sprintf(current->comm, "afs_rxlistener");
274 complete_and_exit(0, 0);
277 printf("Unknown op %ld in StartDaemon()\n", (long)parm);
284 afsd_launcher(void *rock)
286 if (!kernel_thread(afsd_thread, rock, CLONE_VFORK | SIGCHLD))
287 printf("kernel_thread failed. afs startup will not complete\n");
291 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
295 DECLARE_COMPLETION(c);
296 #if defined(AFS_LINUX26_ENV)
297 struct work_struct tq;
301 struct afsd_thread_info info;
302 if (parm == AFSOP_START_RXCALLBACK) {
305 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
309 code = afs_InitSetup(parm2);
311 rx_enablePeerRPCStats();
314 rx_enableProcessRPCStats();
318 } else if (parm == AFSOP_START_AFS) {
321 } /* other functions don't need setup in the parent */
324 #if defined(AFS_LINUX26_ENV)
325 INIT_WORK(&tq, afsd_launcher, &info);
329 INIT_LIST_HEAD(&tq.list);
330 tq.routine = afsd_launcher;
335 /* we need to wait cause we passed stack pointers around.... */
336 wait_for_completion(&c);
341 /* leaving as is, probably will barf if we add prototypes here since it's likely being called
344 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
345 long parm, parm2, parm3, parm4, parm5, parm6;
348 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
350 #else /* AFS_SGI61_ENV */
352 #endif /* AFS_SGI61_ENV */
354 AFS_STATCNT(afs_syscall_call);
356 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
357 && (parm != AFSOP_GETMASK)) {
358 /* only root can run this code */
361 if (!afs_suser(NULL) && (parm != AFSOP_GETMTU)
362 && (parm != AFSOP_GETMASK)) {
363 /* only root can run this code */
364 #if defined(KERNEL_HAVE_UERROR)
368 #if defined(AFS_OSF_ENV)
370 #else /* AFS_OSF_ENV */
372 #endif /* AFS_OSF_ENV */
377 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS) && !defined(UKERNEL)
378 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
379 || parm == AFSOP_RXLISTENER_DAEMON) {
380 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
382 #else /* !(AFS_LINUX24_ENV && !UKERNEL) */
383 if (parm == AFSOP_START_RXCALLBACK) {
387 #ifndef RXK_LISTENER_ENV
388 code = afs_InitSetup(parm2);
390 #endif /* !RXK_LISTENER_ENV */
392 #ifdef RXK_LISTENER_ENV
393 while (afs_RX_Running != 2)
394 afs_osi_Sleep(&afs_RX_Running);
395 #else /* !RXK_LISTENER_ENV */
396 afs_initState = AFSOP_START_AFS;
397 afs_osi_Wakeup(&afs_initState);
398 #endif /* RXK_LISTENER_ENV */
400 afs_RXCallBackServer();
404 exit(CLD_EXITED, code);
405 #endif /* AFS_SGI_ENV */
407 #ifdef RXK_LISTENER_ENV
408 else if (parm == AFSOP_RXLISTENER_DAEMON) {
412 code = afs_InitSetup(parm2);
414 rx_enablePeerRPCStats();
417 rx_enableProcessRPCStats();
420 afs_initState = AFSOP_START_AFS;
421 afs_osi_Wakeup(&afs_initState);
424 afs_osi_Wakeup(&afs_RX_Running);
426 afs_osi_RxkRegister();
427 #endif /* !UKERNEL */
432 exit(CLD_EXITED, code);
433 #endif /* AFS_SGI_ENV */
435 #endif /* RXK_LISTENER_ENV */
436 else if (parm == AFSOP_START_AFS) {
441 while (afs_initState < AFSOP_START_AFS)
442 afs_osi_Sleep(&afs_initState);
444 afs_initState = AFSOP_START_BKG;
445 afs_osi_Wakeup(&afs_initState);
451 #endif /* AFS_SGI_ENV */
452 } else if (parm == AFSOP_START_CS) {
454 afs_CheckServerDaemon();
458 #endif /* AFS_SGI_ENV */
459 } else if (parm == AFSOP_START_BKG) {
460 while (afs_initState < AFSOP_START_BKG)
461 afs_osi_Sleep(&afs_initState);
462 if (afs_initState < AFSOP_GO) {
463 afs_initState = AFSOP_GO;
464 afs_osi_Wakeup(&afs_initState);
466 /* start the bkg daemon */
470 afs_BioDaemon(parm2);
472 #endif /* AFS_AIX32_ENV */
473 afs_BackgroundDaemon();
477 #endif /* AFS_SGI_ENV */
478 } else if (parm == AFSOP_START_TRUNCDAEMON) {
479 while (afs_initState < AFSOP_GO)
480 afs_osi_Sleep(&afs_initState);
481 /* start the bkg daemon */
483 afs_CacheTruncateDaemon();
487 #endif /* AFS_SGI_ENV */
489 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
490 else if (parm == AFSOP_RXEVENT_DAEMON) {
491 while (afs_initState < AFSOP_START_BKG)
492 afs_osi_Sleep(&afs_initState);
494 afs_rxevent_daemon();
498 #endif /* AFS_SGI_ENV */
500 #endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
501 #endif /* AFS_LINUX24_ENV && !UKERNEL */
502 else if (parm == AFSOP_BASIC_INIT) {
505 while (!afs_InitSetup_done)
506 afs_osi_Sleep(&afs_InitSetup_done);
508 #if defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_SUN5_ENV)
509 temp = AFS_MINBUFFERS; /* Should fix this soon */
511 /* number of 2k buffers we could get from all of the buffer space */
512 temp = ((afs_bufferpages * NBPG) >> 11);
513 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
514 if (temp < AFS_MINBUFFERS)
515 temp = AFS_MINBUFFERS; /* though we really should have this many */
518 afs_rootFid.Fid.Volume = 0;
520 } else if (parm == AFSOP_BUCKETPCT) {
521 /* need to enable this now, will disable again before GO
522 if we don't have 100% */
532 } else if (parm == AFSOP_ADDCELL) {
533 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
534 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
535 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
536 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
538 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts),
541 if (parm4 > sizeof(tcell->cellName))
544 AFS_COPYIN((char *)parm3, tcell->cellName, parm4, code);
546 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
550 afs_osi_Free(tcell, sizeof(struct afsop_cell));
551 } else if (parm == AFSOP_ADDCELL2) {
552 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
553 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
554 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
558 /* wait for basic init - XXX can't find any reason we need this? */
559 while (afs_initState < AFSOP_START_BKG)
560 afs_osi_Sleep(&afs_initState);
563 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts),
566 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ,
570 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ,
574 cflags |= CLinkedCell;
579 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
583 afs_osi_Free(tcell, sizeof(struct afsop_cell));
584 osi_FreeSmallSpace(tbuffer);
585 osi_FreeSmallSpace(tbuffer1);
586 } else if (parm == AFSOP_ADDCELLALIAS) {
589 * parm2 is the alias name
590 * parm3 is the real cell name
592 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
593 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
595 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize,
598 AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ,
601 afs_NewCellAlias(aliasName, cellName);
602 osi_FreeSmallSpace(aliasName);
603 osi_FreeSmallSpace(cellName);
604 } else if (parm == AFSOP_SET_THISCELL) {
607 * parm2 is the primary cell name
609 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
611 AFS_COPYINSTR((char *)parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code);
613 afs_SetPrimaryCell(cell);
614 osi_FreeSmallSpace(cell);
615 } else if (parm == AFSOP_CACHEINIT) {
616 struct afs_cacheParams cparms;
618 if (afs_CacheInit_Done)
621 AFS_COPYIN((char *)parm2, (caddr_t) & cparms, sizeof(cparms), code);
623 #if defined(KERNEL_HAVE_UERROR)
629 afs_CacheInit_Done = 1;
631 struct afs_icl_log *logp;
632 /* initialize the ICL system */
633 code = afs_icl_CreateLog("cmfx", 60 * 1024, &logp);
636 afs_icl_CreateSetWithFlags("cm", logp, NULL,
637 ICL_CRSET_FLAG_DEFAULT_OFF,
640 afs_icl_CreateSet("cmlongterm", logp, NULL,
641 &afs_iclLongTermSetp);
643 afs_setTime = cparms.setTimeFlag;
646 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
647 cparms.cacheBlocks, cparms.cacheDcaches,
648 cparms.cacheVolumes, cparms.chunkSize,
649 cparms.memCacheFlag, cparms.inodes, cparms.users);
651 } else if (parm == AFSOP_CACHEINODE) {
652 ino_t ainode = parm2;
653 /* wait for basic init */
654 while (afs_initState < AFSOP_START_BKG)
655 afs_osi_Sleep(&afs_initState);
659 ainode = (ainode << 32) | (parm3 & 0xffffffff);
661 code = afs_InitCacheFile(NULL, ainode);
662 } else if (parm == AFSOP_ROOTVOLUME) {
663 /* wait for basic init */
664 while (afs_initState < AFSOP_START_BKG)
665 afs_osi_Sleep(&afs_initState);
668 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName,
669 sizeof(afs_rootVolumeName), &bufferSize, code);
670 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
673 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
674 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG
675 || parm == AFSOP_CELLINFO) {
676 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
679 AFS_COPYINSTR((char *)parm2, tbuffer, AFS_SMALLOCSIZ, &bufferSize,
682 osi_FreeSmallSpace(tbuffer);
686 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
687 /* We have the cache dir copied in. Call the cache init routine */
688 if (parm == AFSOP_CACHEFILE)
689 code = afs_InitCacheFile(tbuffer, 0);
690 else if (parm == AFSOP_CACHEINFO)
691 code = afs_InitCacheInfo(tbuffer);
692 else if (parm == AFSOP_VOLUMEINFO)
693 code = afs_InitVolumeInfo(tbuffer);
694 else if (parm == AFSOP_CELLINFO)
695 code = afs_InitCellInfo(tbuffer);
697 osi_FreeSmallSpace(tbuffer);
698 } else if (parm == AFSOP_GO) {
699 /* the generic initialization calls come here. One parameter: should we do the
700 * set-time operation on this workstation */
704 while (afs_initState < AFSOP_GO)
705 afs_osi_Sleep(&afs_initState);
708 if (afs_tpct1 + afs_tpct2 != 100) {
715 afs_osi_Wakeup(&afs_initState);
716 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
717 afs_nfsclient_init();
719 printf("found %d non-empty cache files (%d%%).\n",
720 afs_stats_cmperf.cacheFilesReused,
721 (100 * afs_stats_cmperf.cacheFilesReused) /
722 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
723 cacheNumEntries : 1));
724 } else if (parm == AFSOP_ADVISEADDR) {
725 /* pass in the host address to the rx package */
727 afs_int32 count = parm2;
729 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
730 afs_int32 *maskbuffer =
731 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
732 afs_int32 *mtubuffer =
733 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
736 /* Bind, but only if there's only one address configured */
737 if ( count & 0x80000000) {
738 count &= ~0x80000000;
743 if (count > AFS_MAX_INTERFACE_ADDR) {
745 count = AFS_MAX_INTERFACE_ADDR;
748 AFS_COPYIN((char *)parm3, (char *)buffer, count * sizeof(afs_int32),
751 AFS_COPYIN((char *)parm4, (char *)maskbuffer,
752 count * sizeof(afs_int32), code);
754 AFS_COPYIN((char *)parm5, (char *)mtubuffer,
755 count * sizeof(afs_int32), code);
757 afs_cb_interface.numberOfInterfaces = count;
758 for (i = 0; i < count; i++) {
759 afs_cb_interface.addr_in[i] = buffer[i];
760 #ifdef AFS_USERSPACE_IP_ADDR
761 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
762 * machines IP addresses when in the kernel (the in_ifaddr
763 * struct is not available), so we pass the info in at
764 * startup. We also pass in the subnetmask and mtu size. The
765 * subnetmask is used when setting the rank:
766 * afsi_SetServerIPRank(); and the mtu size is used when
767 * finding the best mtu size. rxi_FindIfnet() is replaced
768 * with rxi_Findcbi().
770 afs_cb_interface.subnetmask[i] =
771 (parm4 ? maskbuffer[i] : 0xffffffff);
772 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
775 afs_uuid_create(&afs_cb_interface.uuid);
776 rxi_setaddr(buffer[0]);
778 rx_bindhost = buffer[0];
780 rx_bindhost = htonl(INADDR_ANY);
782 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
783 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
784 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
787 else if (parm == AFSOP_NFSSTATICADDR) {
788 extern int (*nfs_rfsdisptab_v2) ();
789 nfs_rfsdisptab_v2 = (int (*)())parm2;
790 } else if (parm == AFSOP_NFSSTATICADDR2) {
791 extern int (*nfs_rfsdisptab_v2) ();
793 nfs_rfsdisptab_v2 = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
795 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
798 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
799 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
800 extern int (*afs_sblockp) ();
801 extern void (*afs_sbunlockp) ();
803 afs_sblockp = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
804 afs_sbunlockp = (void (*)())((parm4 << 32) | (parm5 & 0xffffffff));
806 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
807 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
810 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
811 #endif /* AFS_SGI53_ENV */
812 else if (parm == AFSOP_SHUTDOWN) {
813 afs_cold_shutdown = 0;
815 afs_cold_shutdown = 1;
816 #ifndef AFS_DARWIN_ENV
817 if (afs_globalVFS != 0) {
818 afs_warn("AFS isn't unmounted yet! Call aborted\n");
823 } else if (parm == AFSOP_AFS_VFSMOUNT) {
825 vfsmount(parm2, parm3, parm4, parm5);
826 #else /* defined(AFS_HPUX_ENV) */
827 #if defined(KERNEL_HAVE_UERROR)
832 #endif /* defined(AFS_HPUX_ENV) */
833 } else if (parm == AFSOP_CLOSEWAIT) {
834 afs_SynchronousCloses = 'S';
835 } else if (parm == AFSOP_GETMTU) {
837 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
838 #ifdef AFS_USERSPACE_IP_ADDR
840 i = rxi_Findcbi(parm2);
841 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
842 #else /* AFS_USERSPACE_IP_ADDR */
845 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
846 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
847 #endif /* else AFS_USERSPACE_IP_ADDR */
848 #endif /* !AFS_SUN5_ENV */
850 AFS_COPYOUT((caddr_t) & mtu, (caddr_t) parm3, sizeof(afs_int32),
853 /* this is disabled for now because I can't figure out how to get access
854 * to these kernel variables. It's only for supporting user-mode rx
855 * programs -- it makes a huge difference on the 220's in my testbed,
856 * though I don't know why. The bosserver does this with /etc/no, so it's
857 * being handled a different way for the servers right now. */
860 extern u_long sb_max_dflt;
863 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
864 if (sb_max < 131072) sb_max = 131072;
867 #endif /* AFS_AIX32_ENV */
868 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
870 #if !defined(AFS_SUN5_ENV)
871 #ifdef AFS_USERSPACE_IP_ADDR
873 i = rxi_Findcbi(parm2);
875 mask = afs_cb_interface.subnetmask[i];
879 #else /* AFS_USERSPACE_IP_ADDR */
882 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
885 #endif /* else AFS_USERSPACE_IP_ADDR */
886 #endif /* !AFS_SUN5_ENV */
888 AFS_COPYOUT((caddr_t) & mask, (caddr_t) parm3, sizeof(afs_int32),
892 else if (parm == AFSOP_AFSDB_HANDLER) {
893 int sizeArg = (int)parm4;
894 int kmsgLen = sizeArg & 0xffff;
895 int cellLen = (sizeArg & 0xffff0000) >> 16;
896 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
897 char *cellname = afs_osi_Alloc(cellLen);
900 afs_osi_MaskUserLoop();
902 AFS_COPYIN((afs_int32 *) parm2, cellname, cellLen, code);
903 AFS_COPYIN((afs_int32 *) parm3, kmsg, kmsgLen, code);
905 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
908 if (code == -2) { /* Shutting down? */
914 AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
915 afs_osi_Free(kmsg, kmsgLen);
916 afs_osi_Free(cellname, cellLen);
919 else if (parm == AFSOP_SET_DYNROOT) {
920 code = afs_SetDynrootEnable(parm2);
921 } else if (parm == AFSOP_SET_FAKESTAT) {
922 afs_fakestat_enable = parm2;
924 } else if (parm == AFSOP_SET_BACKUPTREE) {
925 afs_bkvolpref = parm2;
926 } else if (parm == AFSOP_SET_RXPCK) {
927 rx_extraPackets = parm2;
928 afscall_set_rxpck_received = 1;
934 #ifdef AFS_LINUX20_ENV
943 #include "sys/lockl.h"
946 * syscall - this is the VRMIX system call entry point.
949 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
950 * all the user-level calls to `syscall' to change.
952 syscall(syscall, p1, p2, p3, p4, p5, p6)
954 register rval1 = 0, code;
957 #ifndef AFS_AIX41_ENV
958 extern lock_t kernel_lock;
959 monster = lockl(&kernel_lock, LOCK_SHORT);
960 #endif /* !AFS_AIX41_ENV */
962 AFS_STATCNT(syscall);
966 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
971 rval1 = afs_setpag();
977 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
981 case AFSCALL_ICREATE:
982 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
986 rval1 = afs_syscall_iopen(p1, p2, p3);
990 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
994 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
999 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
1014 #ifndef AFS_AIX41_ENV
1015 if (monster != LOCK_NEST)
1016 unlockl(&kernel_lock);
1017 #endif /* !AFS_AIX41_ENV */
1018 return getuerror()? -1 : rval1;
1022 * lsetpag - interface to afs_setpag().
1027 AFS_STATCNT(lsetpag);
1028 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
1032 * lpioctl - interface to pioctl()
1034 lpioctl(path, cmd, cmarg, follow)
1038 AFS_STATCNT(lpioctl);
1039 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
1042 #else /* !AFS_AIX32_ENV */
1044 #if defined(AFS_SGI_ENV)
1056 Afs_syscall(struct afsargs *uap, rval_t * rvp)
1061 AFS_STATCNT(afs_syscall);
1062 switch (uap->syscall) {
1067 Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1068 uap->parm5, &retval);
1070 rvp->r_val1 = retval;
1072 #ifdef AFS_SGI_XFS_IOPS_ENV
1073 case AFSCALL_IDEC64:
1075 afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1078 case AFSCALL_IINC64:
1080 afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1083 case AFSCALL_ILISTINODE64:
1085 afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
1086 uap->parm4, uap->parm5);
1088 case AFSCALL_ICREATENAME64:
1090 afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
1091 uap->parm4, uap->parm5);
1094 #ifdef AFS_SGI_VNODE_GLUE
1095 case AFSCALL_INIT_KERNEL_CONFIG:
1096 error = afs_init_kernel_config(uap->parm1);
1101 afs_syscall_call(uap->syscall, uap->parm1, uap->parm2, uap->parm3,
1102 uap->parm4, uap->parm5);
1107 #else /* AFS_SGI_ENV */
1124 #if defined(AFS_HPUX_64BIT_ENV) || defined(AFS_SUN57_64BIT_ENV) || (defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV))
1126 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
1128 dst->param1 = src->param1;
1129 dst->param2 = src->param2;
1130 dst->param3 = src->param3;
1131 dst->param4 = src->param4;
1136 * If you need to change copyin_iparam(), you may also need to change
1137 * copyin_afs_ioctl().
1141 copyin_iparam(caddr_t cmarg, struct iparam *dst)
1145 #if defined(AFS_HPUX_64BIT_ENV)
1146 struct iparam32 dst32;
1148 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
1149 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
1151 iparam32_to_iparam(&dst32, dst);
1154 #endif /* AFS_HPUX_64BIT_ENV */
1156 #if defined(AFS_SUN57_64BIT_ENV)
1157 struct iparam32 dst32;
1159 if (get_udatamodel() == DATAMODEL_ILP32) {
1160 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
1162 iparam32_to_iparam(&dst32, dst);
1165 #endif /* AFS_SUN57_64BIT_ENV */
1167 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
1168 struct iparam32 dst32;
1170 #ifdef AFS_SPARC64_LINUX24_ENV
1171 if (current->thread.flags & SPARC_FLAG_32BIT)
1172 #elif defined(AFS_SPARC64_LINUX20_ENV)
1173 if (current->tss.flags & SPARC_FLAG_32BIT)
1175 #elif defined(AFS_AMD64_LINUX26_ENV)
1176 if (test_thread_flag(TIF_IA32))
1177 #elif defined(AFS_AMD64_LINUX20_ENV)
1178 if (current->thread.flags & THREAD_IA32)
1180 #elif defined(AFS_PPC64_LINUX26_ENV)
1181 if (current->thread_info->flags & _TIF_32BIT)
1182 #elif defined(AFS_PPC64_LINUX20_ENV)
1183 if (current->thread.flags & PPC_FLAG_32BIT)
1185 #elif defined(AFS_S390X_LINUX26_ENV)
1186 if (test_thread_flag(TIF_31BIT))
1187 #elif defined(AFS_S390X_LINUX20_ENV)
1188 if (current->thread.flags & S390_FLAG_31BIT)
1191 #error iparam32 not done for this linux platform
1194 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
1196 iparam32_to_iparam(&dst32, dst);
1199 #endif /* AFS_LINUX_64BIT_KERNEL */
1201 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
1205 /* Main entry of all afs system calls */
1207 extern int afs_sinited;
1209 /** The 32 bit OS expects the members of this structure to be 32 bit
1210 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
1211 * to accomodate both, *long* is used instead of afs_int32
1214 #ifdef AFS_SUN57_ENV
1236 Afs_syscall(register struct afssysa *uap, rval_t * rvp)
1238 int *retval = &rvp->r_val1;
1239 #else /* AFS_SUN5_ENV */
1240 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1242 afs3_syscall(p, args, retval)
1243 #ifdef AFS_FBSD50_ENV
1259 } *uap = (struct a *)args;
1260 #else /* AFS_OSF_ENV */
1261 #ifdef AFS_LINUX20_ENV
1269 long parm6; /* not actually used - should be removed */
1271 /* Linux system calls only set up for 5 arguments. */
1273 afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4)
1275 struct afssysargs args, *uap = &args;
1277 long *retval = &linux_ret;
1278 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
1279 #ifdef AFS_SPARC64_LINUX24_ENV
1280 afs_int32 eparm32[4];
1282 /* eparm is also used by AFSCALL_CALL in afsd.c */
1284 #if defined(UKERNEL)
1295 } *uap = (struct a *)u.u_ap;
1308 } *uap = (struct a *)u.u_ap;
1309 #endif /* UKERNEL */
1310 #if defined(AFS_HPUX_ENV)
1311 long *retval = &u.u_rval1;
1313 int *retval = &u.u_rval1;
1315 #endif /* AFS_LINUX20_ENV */
1316 #endif /* AFS_OSF_ENV */
1317 #endif /* AFS_SUN5_ENV */
1318 register int code = 0;
1320 AFS_STATCNT(afs_syscall);
1327 #ifdef AFS_LINUX20_ENV
1329 /* setup uap for use below - pull out the magic decoder ring to know
1330 * which syscalls have folded argument lists.
1332 uap->syscall = syscall;
1336 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
1337 #ifdef AFS_SPARC64_LINUX24_ENV
1338 /* from arch/sparc64/kernel/sys_sparc32.c */
1340 ({ unsigned long __ret; \
1341 __asm__ ("srl %0, 0, %0" \
1348 if (current->thread.flags & SPARC_FLAG_32BIT) {
1349 AFS_COPYIN((char *)parm4, (char *)eparm32, sizeof(eparm32), code);
1350 eparm[0] = AA(eparm32[0]);
1351 eparm[1] = AA(eparm32[1]);
1352 eparm[2] = AA(eparm32[2]);
1356 AFS_COPYIN((char *)parm4, (char *)eparm, sizeof(eparm), code);
1357 uap->parm4 = eparm[0];
1358 uap->parm5 = eparm[1];
1359 uap->parm6 = eparm[2];
1367 #if defined(AFS_HPUX_ENV)
1369 * There used to be code here (duplicated from osi_Init()) for
1370 * initializing the semaphore used by AFS_GLOCK(). Was the
1371 * duplication to handle the case of a dynamically loaded kernel
1376 if (uap->syscall == AFSCALL_CALL) {
1379 afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1380 uap->parm5, uap->parm6, rvp, CRED());
1383 afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1384 uap->parm5, uap->parm6);
1386 } else if (uap->syscall == AFSCALL_SETPAG) {
1388 register proc_t *procp;
1390 procp = ttoproc(curthread);
1392 code = afs_setpag(&procp->p_cred);
1396 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1397 code = afs_setpag(p, args, retval);
1398 #else /* AFS_OSF_ENV */
1399 code = afs_setpag();
1403 } else if (uap->syscall == AFSCALL_PIOCTL) {
1405 #if defined(AFS_SUN5_ENV)
1407 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1409 #elif defined(AFS_FBSD50_ENV)
1411 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1413 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1415 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1416 p->p_cred->pc_ucred);
1419 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
1423 } else if (uap->syscall == AFSCALL_ICREATE) {
1424 struct iparam iparams;
1426 code = copyin_iparam((char *)uap->parm3, &iparams);
1428 #if defined(KERNEL_HAVE_UERROR)
1434 afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
1435 iparams.param2, iparams.param3,
1436 iparams.param4, rvp, CRED());
1439 afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
1441 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1442 iparams.param3, iparams.param4, retval);
1444 iparams.param3, iparams.param4);
1446 #endif /* AFS_SUN5_ENV */
1447 } else if (uap->syscall == AFSCALL_IOPEN) {
1450 afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp,
1453 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1454 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1456 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1458 #endif /* AFS_SUN5_ENV */
1459 } else if (uap->syscall == AFSCALL_IDEC) {
1462 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp,
1465 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1466 #endif /* AFS_SUN5_ENV */
1467 } else if (uap->syscall == AFSCALL_IINC) {
1470 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp,
1473 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1474 #endif /* AFS_SUN5_ENV */
1475 } else if (uap->syscall == AFSCALL_ICL) {
1478 Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1479 uap->parm5, retval);
1481 #ifdef AFS_LINUX20_ENV
1483 /* ICL commands can return values. */
1484 code = -linux_ret; /* Gets negated again at exit below */
1488 #if defined(KERNEL_HAVE_UERROR)
1492 #endif /* !AFS_LINUX20_ENV */
1494 #if defined(KERNEL_HAVE_UERROR)
1501 #ifdef AFS_LINUX20_ENV
1507 #endif /* AFS_SGI_ENV */
1508 #endif /* !AFS_AIX32_ENV */
1511 * Initstate in the range 0 < x < 100 are early initialization states.
1512 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1513 * the cache may be initialized.
1514 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1515 * is done after all the cache initialization has been done.
1516 * Initstate of 200 means that the volume has been looked up once, possibly
1518 * Initstate of 300 means that the volume has been *successfully* looked up.
1523 register int code = 0;
1525 AFS_STATCNT(afs_CheckInit);
1526 if (afs_initState <= 100)
1527 code = ENXIO; /* never finished init phase */
1528 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1529 while (afs_initState < 200)
1530 afs_osi_Sleep(&afs_initState);
1531 } else if (afs_initState == 200)
1532 code = ETIMEDOUT; /* didn't find root volume */
1536 int afs_shuttingdown = 0;
1540 extern short afs_brsDaemons;
1541 extern afs_int32 afs_CheckServerDaemonStarted;
1542 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1543 extern struct osi_file *afs_cacheInodep;
1545 AFS_STATCNT(afs_shutdown);
1546 if (afs_initState == 0) {
1547 afs_warn("AFS not initialized - not shutting down\n");
1551 if (afs_shuttingdown)
1553 afs_shuttingdown = 1;
1554 if (afs_cold_shutdown)
1558 afs_warn("shutting down of: CB... ");
1560 afs_termState = AFSOP_STOP_RXCALLBACK;
1561 rx_WakeupServerProcs();
1562 #ifdef AFS_AIX51_ENV
1563 shutdown_rxkernel();
1565 /* shutdown_rxkernel(); */
1566 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1567 afs_osi_Sleep(&afs_termState);
1569 afs_warn("afs... ");
1570 while (afs_termState == AFSOP_STOP_AFS) {
1571 afs_osi_CancelWait(&AFS_WaitHandler);
1572 afs_osi_Sleep(&afs_termState);
1574 if (afs_CheckServerDaemonStarted) {
1575 while (afs_termState == AFSOP_STOP_CS) {
1576 afs_osi_CancelWait(&AFS_CSWaitHandler);
1577 afs_osi_Sleep(&afs_termState);
1580 afs_warn("BkG... ");
1581 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1582 while (afs_termState == AFSOP_STOP_BKG) {
1583 afs_osi_Wakeup(&afs_brsDaemons);
1584 afs_osi_Sleep(&afs_termState);
1586 afs_warn("CTrunc... ");
1587 /* Cancel cache truncate daemon. */
1588 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1589 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1590 afs_osi_Sleep(&afs_termState);
1592 #ifdef AFS_AFSDB_ENV
1593 afs_warn("AFSDB... ");
1595 while (afs_termState == AFSOP_STOP_AFSDB)
1596 afs_osi_Sleep(&afs_termState);
1598 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1599 afs_warn("RxEvent... ");
1600 /* cancel rx event daemon */
1601 while (afs_termState == AFSOP_STOP_RXEVENT)
1602 afs_osi_Sleep(&afs_termState);
1603 #if defined(RXK_LISTENER_ENV)
1605 afs_warn("UnmaskRxkSignals... ");
1606 afs_osi_UnmaskRxkSignals();
1608 /* cancel rx listener */
1609 afs_warn("RxListener... ");
1610 osi_StopListener(); /* This closes rx_socket. */
1611 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1612 afs_warn("Sleep... ");
1613 afs_osi_Sleep(&afs_termState);
1617 afs_termState = AFSOP_STOP_COMPLETE;
1621 /* Close file only after daemons which can write to it are stopped. */
1622 if (afs_cacheInodep) { /* memcache won't set this */
1623 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1624 afs_cacheInodep = 0;
1626 return; /* Just kill daemons for now */
1630 shutdown_rxkernel();
1634 shutdown_bufferpackage();
1636 #ifdef AFS_AIX51_ENV
1644 shutdown_vnodeops();
1646 shutdown_exporter();
1647 shutdown_memcache();
1648 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)) && !defined(AFS_OSF_ENV)
1652 /* The following hold the cm stats */
1654 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1655 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1656 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1658 afs_warn(" ALL allocated tables\n");
1659 afs_shuttingdown = 0;
1664 shutdown_afstest(void)
1666 AFS_STATCNT(shutdown_afstest);
1667 afs_initState = afs_termState = afs_setTime = 0;
1668 AFS_Running = afs_CB_Running = 0;
1669 afs_CacheInit_Done = afs_Go_Done = 0;
1670 if (afs_cold_shutdown) {
1671 *afs_rootVolumeName = 0;
1676 /* In case there is a bunch of dynamically build bkg daemons to free */
1678 afs_shutdown_BKG(void)
1680 AFS_STATCNT(shutdown_BKG);
1684 #if defined(AFS_OSF_ENV) || defined(AFS_SGI61_ENV)
1685 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1686 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1687 int afs_icl_sizeofLong = 1;
1689 int afs_icl_sizeofLong = 2;
1692 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
1693 int afs_icl_sizeofLong = 2;
1695 int afs_icl_sizeofLong = 1;
1699 int afs_icl_inited = 0;
1701 /* init function, called once, under afs_icl_lock */
1709 extern struct afs_icl_log *afs_icl_FindLog();
1710 extern struct afs_icl_set *afs_icl_FindSet();
1714 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1716 afs_int32 *lp, elts, flags;
1717 register afs_int32 code;
1718 struct afs_icl_log *logp;
1719 struct afs_icl_set *setp;
1720 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1722 #else /* AFS_SGI61_ENV */
1723 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
1728 #endif /* AFS_SGI61_ENV */
1730 afs_int32 startCookie;
1731 afs_int32 allocated;
1732 struct afs_icl_log *tlp;
1735 if (!afs_suser(CRED())) { /* only root can run this code */
1739 if (!afs_suser(NULL)) { /* only root can run this code */
1740 #if defined(KERNEL_HAVE_UERROR)
1749 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1750 case ICL_OP_COPYOUT: /* copy ouy data */
1751 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1752 * return flags<<24 + nwords.
1753 * updates cookie to updated start (not end) if we had to
1754 * skip some records.
1756 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1759 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1762 logp = afs_icl_FindLog(tname);
1765 #define BUFFERSIZE AFS_LRALLOCSIZ
1766 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1767 elts = BUFFERSIZE / sizeof(afs_int32);
1770 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1772 afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) & startCookie,
1775 osi_FreeLargeSpace((struct osi_buffer *)lp);
1778 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1781 AFS_COPYOUT((char *)&startCookie, (char *)p4, sizeof(afs_int32),
1785 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
1787 *retval = ((long)((flags << 24) | (elts & 0xffffff))) << 32;
1790 *retval = (flags << 24) | (elts & 0xffffff);
1792 afs_icl_LogRele(logp);
1793 osi_FreeLargeSpace((struct osi_buffer *)lp);
1796 case ICL_OP_ENUMLOGS: /* enumerate logs */
1797 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1798 * return 0 for success, otherwise error.
1800 for (tlp = afs_icl_allLogs; tlp; tlp = tlp->nextp) {
1805 return ENOENT; /* past the end of file */
1806 temp = strlen(tlp->name) + 1;
1809 AFS_COPYOUT(tlp->name, (char *)p2, temp, code);
1810 if (!code) /* copy out size of log */
1811 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof(afs_int32),
1815 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1816 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1817 * return 0 for success, otherwise error.
1819 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1822 setp = afs_icl_FindSet(tname);
1825 if (p2 > ICL_LOGSPERSET)
1827 if (!(tlp = setp->logs[p2]))
1829 temp = strlen(tlp->name) + 1;
1832 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1835 case ICL_OP_CLRLOG: /* clear specified log */
1836 /* zero out the specified log: p1=logname */
1837 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1840 logp = afs_icl_FindLog(tname);
1843 code = afs_icl_ZeroLog(logp);
1844 afs_icl_LogRele(logp);
1847 case ICL_OP_CLRSET: /* clear specified set */
1848 /* zero out the specified set: p1=setname */
1849 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1852 setp = afs_icl_FindSet(tname);
1855 code = afs_icl_ZeroSet(setp);
1856 afs_icl_SetRele(setp);
1859 case ICL_OP_CLRALL: /* clear all logs */
1860 /* zero out all logs -- no args */
1862 ObtainWriteLock(&afs_icl_lock, 178);
1863 for (tlp = afs_icl_allLogs; tlp; tlp = tlp->nextp) {
1864 tlp->refCount++; /* hold this guy */
1865 ReleaseWriteLock(&afs_icl_lock);
1866 /* don't clear persistent logs */
1867 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1868 code = afs_icl_ZeroLog(tlp);
1869 ObtainWriteLock(&afs_icl_lock, 179);
1870 if (--tlp->refCount == 0)
1871 afs_icl_ZapLog(tlp);
1875 ReleaseWriteLock(&afs_icl_lock);
1878 case ICL_OP_ENUMSETS: /* enumerate all sets */
1879 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1880 * return 0 for success, otherwise error.
1882 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
1887 return ENOENT; /* past the end of file */
1888 temp = strlen(setp->name) + 1;
1891 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1892 if (!code) /* copy out size of log */
1893 AFS_COPYOUT((char *)&setp->states, (char *)p4, sizeof(afs_int32),
1897 case ICL_OP_SETSTAT: /* set status on a set */
1898 /* activate the specified set: p1=setname, p2=op */
1899 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1902 setp = afs_icl_FindSet(tname);
1905 code = afs_icl_SetSetStat(setp, p2);
1906 afs_icl_SetRele(setp);
1909 case ICL_OP_SETSTATALL: /* set status on all sets */
1910 /* activate the specified set: p1=op */
1912 ObtainWriteLock(&afs_icl_lock, 180);
1913 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
1914 setp->refCount++; /* hold this guy */
1915 ReleaseWriteLock(&afs_icl_lock);
1916 /* don't set states on persistent sets */
1917 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1918 code = afs_icl_SetSetStat(setp, p1);
1919 ObtainWriteLock(&afs_icl_lock, 181);
1920 if (--setp->refCount == 0)
1921 afs_icl_ZapSet(setp);
1925 ReleaseWriteLock(&afs_icl_lock);
1928 case ICL_OP_SETLOGSIZE: /* set size of log */
1929 /* set the size of the specified log: p1=logname, p2=size (in words) */
1930 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1933 logp = afs_icl_FindLog(tname);
1936 code = afs_icl_LogSetSize(logp, p2);
1937 afs_icl_LogRele(logp);
1940 case ICL_OP_GETLOGINFO: /* get size of log */
1941 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1942 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1945 logp = afs_icl_FindLog(tname);
1948 allocated = !!logp->datap;
1949 AFS_COPYOUT((char *)&logp->logSize, (char *)p2, sizeof(afs_int32),
1952 AFS_COPYOUT((char *)&allocated, (char *)p3, sizeof(afs_int32),
1954 afs_icl_LogRele(logp);
1957 case ICL_OP_GETSETINFO: /* get state of set */
1958 /* zero out the specified set: p1=setname, p2=&state */
1959 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1962 setp = afs_icl_FindSet(tname);
1965 AFS_COPYOUT((char *)&setp->states, (char *)p2, sizeof(afs_int32),
1967 afs_icl_SetRele(setp);
1978 afs_lock_t afs_icl_lock;
1980 /* exported routine: a 4 parameter event */
1982 afs_icl_Event4(register struct afs_icl_set *setp, afs_int32 eventID,
1983 afs_int32 lAndT, long p1, long p2, long p3, long p4)
1987 register afs_int32 tmask;
1990 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1991 if (!ICL_SETACTIVE(setp))
1995 mask = lAndT >> 24 & 0xff; /* mask of which logs to log to */
1996 ix = ICL_EVENTBYTE(eventID);
1997 ObtainReadLock(&setp->lock);
1998 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1999 for (i = 0, tmask = 1; i < ICL_LOGSPERSET; i++, tmask <<= 1) {
2001 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
2006 break; /* break early */
2009 ReleaseReadLock(&setp->lock);
2013 /* Next 4 routines should be implemented via var-args or something.
2014 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
2015 * Otherwise, could call afs_icl_Event4 directly.
2018 afs_icl_Event3(register struct afs_icl_set *setp, afs_int32 eventID,
2019 afs_int32 lAndT, long p1, long p2, long p3)
2021 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
2025 afs_icl_Event2(register struct afs_icl_set *setp, afs_int32 eventID,
2026 afs_int32 lAndT, long p1, long p2)
2028 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
2032 afs_icl_Event1(register struct afs_icl_set *setp, afs_int32 eventID,
2033 afs_int32 lAndT, long p1)
2035 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0,
2040 afs_icl_Event0(register struct afs_icl_set *setp, afs_int32 eventID,
2043 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0,
2047 struct afs_icl_log *afs_icl_allLogs = 0;
2049 /* function to purge records from the start of the log, until there
2050 * is at least minSpace long's worth of space available without
2051 * making the head and the tail point to the same word.
2053 * Log must be write-locked.
2056 afs_icl_GetLogSpace(register struct afs_icl_log *logp, afs_int32 minSpace)
2058 register unsigned int tsize;
2060 while (logp->logSize - logp->logElements <= minSpace) {
2062 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
2063 logp->logElements -= tsize;
2064 logp->firstUsed += tsize;
2065 if (logp->firstUsed >= logp->logSize)
2066 logp->firstUsed -= logp->logSize;
2067 logp->baseCookie += tsize;
2071 /* append string astr to buffer, including terminating null char.
2073 * log must be write-locked.
2075 #define ICL_CHARSPERLONG 4
2077 afs_icl_AppendString(struct afs_icl_log *logp, char *astr)
2079 char *op; /* ptr to char to write */
2081 register int bib; /* bytes in buffer */
2084 op = (char *)&(logp->datap[logp->firstFree]);
2088 if (++bib >= ICL_CHARSPERLONG) {
2091 if (++(logp->firstFree) >= logp->logSize) {
2092 logp->firstFree = 0;
2093 op = (char *)&(logp->datap[0]);
2095 logp->logElements++;
2101 /* if we've used this word at all, allocate it */
2102 if (++(logp->firstFree) >= logp->logSize) {
2103 logp->firstFree = 0;
2105 logp->logElements++;
2109 /* add a long to the log, ignoring overflow (checked already) */
2110 #define ICL_APPENDINT32(lp, x) \
2112 (lp)->datap[(lp)->firstFree] = (x); \
2113 if (++((lp)->firstFree) >= (lp)->logSize) { \
2114 (lp)->firstFree = 0; \
2116 (lp)->logElements++; \
2119 #if defined(AFS_OSF_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
2120 #define ICL_APPENDLONG(lp, x) \
2122 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
2123 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
2126 #else /* AFS_OSF_ENV */
2127 #define ICL_APPENDLONG(lp, x) ICL_APPENDINT32((lp), (x))
2128 #endif /* AFS_OSF_ENV */
2130 /* routine to tell whether we're dealing with the address or the
2134 afs_icl_UseAddr(int type)
2136 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
2137 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
2143 /* Function to append a record to the log. Written for speed
2144 * since we know that we're going to have to make this work fast
2145 * pretty soon, anyway. The log must be unlocked.
2149 afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
2150 afs_int32 types, long p1, long p2, long p3, long p4)
2152 int rsize; /* record size in longs */
2153 register int tsize; /* temp size */
2157 t4 = types & 0x3f; /* decode types */
2165 osi_GetTime(&tv); /* It panics for solaris if inside */
2166 ObtainWriteLock(&logp->lock, 182);
2168 ReleaseWriteLock(&logp->lock);
2172 /* get timestamp as # of microseconds since some time that doesn't
2173 * change that often. This algorithm ticks over every 20 minutes
2174 * or so (1000 seconds). Write a timestamp record if it has.
2176 if (tv.tv_sec - logp->lastTS > 1024) {
2177 /* the timer has wrapped -- write a timestamp record */
2178 if (logp->logSize - logp->logElements <= 5)
2179 afs_icl_GetLogSpace(logp, 5);
2181 ICL_APPENDINT32(logp,
2182 (afs_int32) (5 << 24) + (ICL_TYPE_UNIXDATE << 18));
2183 ICL_APPENDINT32(logp, (afs_int32) ICL_INFO_TIMESTAMP);
2184 ICL_APPENDINT32(logp, (afs_int32) 0); /* use thread ID zero for clocks */
2185 ICL_APPENDINT32(logp,
2186 (afs_int32) (tv.tv_sec & 0x3ff) * 1000000 +
2188 ICL_APPENDINT32(logp, (afs_int32) tv.tv_sec);
2190 logp->lastTS = tv.tv_sec;
2193 rsize = 4; /* base case */
2195 /* compute size of parameter p1. Only tricky case is string.
2196 * In that case, we have to call strlen to get the string length.
2198 ICL_SIZEHACK(t1, p1);
2201 /* compute size of parameter p2. Only tricky case is string.
2202 * In that case, we have to call strlen to get the string length.
2204 ICL_SIZEHACK(t2, p2);
2207 /* compute size of parameter p3. Only tricky case is string.
2208 * In that case, we have to call strlen to get the string length.
2210 ICL_SIZEHACK(t3, p3);
2213 /* compute size of parameter p4. Only tricky case is string.
2214 * In that case, we have to call strlen to get the string length.
2216 ICL_SIZEHACK(t4, p4);
2219 /* At this point, we've computed all of the parameter sizes, and
2220 * have in rsize the size of the entire record we want to append.
2221 * Next, we check that we actually have room in the log to do this
2222 * work, and then we do the append.
2225 ReleaseWriteLock(&logp->lock);
2226 return; /* log record too big to express */
2229 if (logp->logSize - logp->logElements <= rsize)
2230 afs_icl_GetLogSpace(logp, rsize);
2232 ICL_APPENDINT32(logp,
2233 (afs_int32) (rsize << 24) + (t1 << 18) + (t2 << 12) +
2235 ICL_APPENDINT32(logp, (afs_int32) op);
2236 ICL_APPENDINT32(logp, (afs_int32) osi_ThreadUnique());
2237 ICL_APPENDINT32(logp,
2238 (afs_int32) (tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
2241 /* marshall parameter 1 now */
2242 if (t1 == ICL_TYPE_STRING) {
2243 afs_icl_AppendString(logp, (char *)p1);
2244 } else if (t1 == ICL_TYPE_HYPER) {
2245 ICL_APPENDINT32(logp,
2246 (afs_int32) ((struct afs_hyper_t *)p1)->high);
2247 ICL_APPENDINT32(logp,
2248 (afs_int32) ((struct afs_hyper_t *)p1)->low);
2249 } else if (t1 == ICL_TYPE_INT64) {
2250 #ifdef AFSLITTLE_ENDIAN
2251 #ifdef AFS_64BIT_CLIENT
2252 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
2253 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
2254 #else /* AFS_64BIT_CLIENT */
2255 ICL_APPENDINT32(logp, (afs_int32) p1);
2256 ICL_APPENDINT32(logp, (afs_int32) 0);
2257 #endif /* AFS_64BIT_CLIENT */
2258 #else /* AFSLITTLE_ENDIAN */
2259 #ifdef AFS_64BIT_CLIENT
2260 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
2261 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
2262 #else /* AFS_64BIT_CLIENT */
2263 ICL_APPENDINT32(logp, (afs_int32) 0);
2264 ICL_APPENDINT32(logp, (afs_int32) p1);
2265 #endif /* AFS_64BIT_CLIENT */
2266 #endif /* AFSLITTLE_ENDIAN */
2267 } else if (t1 == ICL_TYPE_FID) {
2268 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
2269 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
2270 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[2]);
2271 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[3]);
2273 #if defined(AFS_OSF_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
2274 else if (t1 == ICL_TYPE_INT32)
2275 ICL_APPENDINT32(logp, (afs_int32) p1);
2276 #endif /* AFS_OSF_ENV */
2278 ICL_APPENDLONG(logp, p1);
2281 /* marshall parameter 2 now */
2282 if (t2 == ICL_TYPE_STRING)
2283 afs_icl_AppendString(logp, (char *)p2);
2284 else if (t2 == ICL_TYPE_HYPER) {
2285 ICL_APPENDINT32(logp,
2286 (afs_int32) ((struct afs_hyper_t *)p2)->high);
2287 ICL_APPENDINT32(logp,
2288 (afs_int32) ((struct afs_hyper_t *)p2)->low);
2289 } else if (t2 == ICL_TYPE_INT64) {
2290 #ifdef AFSLITTLE_ENDIAN
2291 #ifdef AFS_64BIT_CLIENT
2292 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
2293 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
2294 #else /* AFS_64BIT_CLIENT */
2295 ICL_APPENDINT32(logp, (afs_int32) p2);
2296 ICL_APPENDINT32(logp, (afs_int32) 0);
2297 #endif /* AFS_64BIT_CLIENT */
2298 #else /* AFSLITTLE_ENDIAN */
2299 #ifdef AFS_64BIT_CLIENT
2300 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
2301 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
2302 #else /* AFS_64BIT_CLIENT */
2303 ICL_APPENDINT32(logp, (afs_int32) 0);
2304 ICL_APPENDINT32(logp, (afs_int32) p2);
2305 #endif /* AFS_64BIT_CLIENT */
2306 #endif /* AFSLITTLE_ENDIAN */
2307 } else if (t2 == ICL_TYPE_FID) {
2308 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
2309 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
2310 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[2]);
2311 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[3]);
2313 #if defined(AFS_OSF_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
2314 else if (t2 == ICL_TYPE_INT32)
2315 ICL_APPENDINT32(logp, (afs_int32) p2);
2316 #endif /* AFS_OSF_ENV */
2318 ICL_APPENDLONG(logp, p2);
2321 /* marshall parameter 3 now */
2322 if (t3 == ICL_TYPE_STRING)
2323 afs_icl_AppendString(logp, (char *)p3);
2324 else if (t3 == ICL_TYPE_HYPER) {
2325 ICL_APPENDINT32(logp,
2326 (afs_int32) ((struct afs_hyper_t *)p3)->high);
2327 ICL_APPENDINT32(logp,
2328 (afs_int32) ((struct afs_hyper_t *)p3)->low);
2329 } else if (t3 == ICL_TYPE_INT64) {
2330 #ifdef AFSLITTLE_ENDIAN
2331 #ifdef AFS_64BIT_CLIENT
2332 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
2333 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
2334 #else /* AFS_64BIT_CLIENT */
2335 ICL_APPENDINT32(logp, (afs_int32) p3);
2336 ICL_APPENDINT32(logp, (afs_int32) 0);
2337 #endif /* AFS_64BIT_CLIENT */
2338 #else /* AFSLITTLE_ENDIAN */
2339 #ifdef AFS_64BIT_CLIENT
2340 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
2341 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
2342 #else /* AFS_64BIT_CLIENT */
2343 ICL_APPENDINT32(logp, (afs_int32) 0);
2344 ICL_APPENDINT32(logp, (afs_int32) p3);
2345 #endif /* AFS_64BIT_CLIENT */
2346 #endif /* AFSLITTLE_ENDIAN */
2347 } else if (t3 == ICL_TYPE_FID) {
2348 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
2349 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
2350 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[2]);
2351 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[3]);
2353 #if defined(AFS_OSF_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
2354 else if (t3 == ICL_TYPE_INT32)
2355 ICL_APPENDINT32(logp, (afs_int32) p3);
2356 #endif /* AFS_OSF_ENV */
2358 ICL_APPENDLONG(logp, p3);
2361 /* marshall parameter 4 now */
2362 if (t4 == ICL_TYPE_STRING)
2363 afs_icl_AppendString(logp, (char *)p4);
2364 else if (t4 == ICL_TYPE_HYPER) {
2365 ICL_APPENDINT32(logp,
2366 (afs_int32) ((struct afs_hyper_t *)p4)->high);
2367 ICL_APPENDINT32(logp,
2368 (afs_int32) ((struct afs_hyper_t *)p4)->low);
2369 } else if (t4 == ICL_TYPE_INT64) {
2370 #ifdef AFSLITTLE_ENDIAN
2371 #ifdef AFS_64BIT_CLIENT
2372 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
2373 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
2374 #else /* AFS_64BIT_CLIENT */
2375 ICL_APPENDINT32(logp, (afs_int32) p4);
2376 ICL_APPENDINT32(logp, (afs_int32) 0);
2377 #endif /* AFS_64BIT_CLIENT */
2378 #else /* AFSLITTLE_ENDIAN */
2379 #ifdef AFS_64BIT_CLIENT
2380 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
2381 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
2382 #else /* AFS_64BIT_CLIENT */
2383 ICL_APPENDINT32(logp, (afs_int32) 0);
2384 ICL_APPENDINT32(logp, (afs_int32) p4);
2385 #endif /* AFS_64BIT_CLIENT */
2386 #endif /* AFSLITTLE_ENDIAN */
2387 } else if (t4 == ICL_TYPE_FID) {
2388 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
2389 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
2390 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[2]);
2391 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[3]);
2393 #if defined(AFS_OSF_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
2394 else if (t4 == ICL_TYPE_INT32)
2395 ICL_APPENDINT32(logp, (afs_int32) p4);
2396 #endif /* AFS_OSF_ENV */
2398 ICL_APPENDLONG(logp, p4);
2400 ReleaseWriteLock(&logp->lock);
2403 /* create a log with size logSize; return it in *outLogpp and tag
2404 * it with name "name."
2407 afs_icl_CreateLog(char *name, afs_int32 logSize,
2408 struct afs_icl_log **outLogpp)
2410 return afs_icl_CreateLogWithFlags(name, logSize, /*flags */ 0, outLogpp);
2413 /* create a log with size logSize; return it in *outLogpp and tag
2414 * it with name "name." 'flags' can be set to make the log unclearable.
2417 afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, afs_uint32 flags,
2418 struct afs_icl_log **outLogpp)
2420 register struct afs_icl_log *logp;
2422 /* add into global list under lock */
2423 ObtainWriteLock(&afs_icl_lock, 183);
2424 if (!afs_icl_inited)
2427 for (logp = afs_icl_allLogs; logp; logp = logp->nextp) {
2428 if (strcmp(logp->name, name) == 0) {
2429 /* found it already created, just return it */
2432 if (flags & ICL_CRLOG_FLAG_PERSISTENT) {
2433 ObtainWriteLock(&logp->lock, 184);
2434 logp->states |= ICL_LOGF_PERSISTENT;
2435 ReleaseWriteLock(&logp->lock);
2437 ReleaseWriteLock(&afs_icl_lock);
2442 logp = (struct afs_icl_log *)
2443 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
2444 memset((caddr_t) logp, 0, sizeof(*logp));
2447 logp->name = osi_AllocSmallSpace(strlen(name) + 1);
2448 strcpy(logp->name, name);
2449 LOCK_INIT(&logp->lock, "logp lock");
2450 logp->logSize = logSize;
2451 logp->datap = NULL; /* don't allocate it until we need it */
2453 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2454 logp->states |= ICL_LOGF_PERSISTENT;
2456 logp->nextp = afs_icl_allLogs;
2457 afs_icl_allLogs = logp;
2458 ReleaseWriteLock(&afs_icl_lock);
2464 /* called with a log, a pointer to a buffer, the size of the buffer
2465 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
2466 * and returns data in the provided buffer, and returns output flags
2467 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
2468 * find the record with cookie value cookie.
2471 afs_icl_CopyOut(register struct afs_icl_log *logp, afs_int32 * bufferp,
2472 afs_int32 * bufSizep, afs_uint32 * cookiep,
2475 afs_int32 nwords; /* number of words to copy out */
2476 afs_uint32 startCookie; /* first cookie to use */
2477 afs_int32 outWords; /* words we've copied out */
2478 afs_int32 inWords; /* max words to copy out */
2479 afs_int32 code; /* return code */
2480 afs_int32 ix; /* index we're copying from */
2481 afs_int32 outFlags; /* return flags */
2482 afs_int32 inFlags; /* flags passed in */
2485 inWords = *bufSizep; /* max to copy out */
2486 outWords = 0; /* amount copied out */
2487 startCookie = *cookiep;
2492 ObtainWriteLock(&logp->lock, 185);
2494 ReleaseWriteLock(&logp->lock);
2498 /* first, compute the index of the start cookie we've been passed */
2500 /* (re-)compute where we should start */
2501 if (startCookie < logp->baseCookie) {
2502 if (startCookie) /* missed some output */
2503 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2504 /* skip to the first available record */
2505 startCookie = logp->baseCookie;
2506 *cookiep = startCookie;
2509 /* compute where we find the first element to copy out */
2510 ix = logp->firstUsed + startCookie - logp->baseCookie;
2511 if (ix >= logp->logSize)
2512 ix -= logp->logSize;
2514 /* if have some data now, break out and process it */
2515 if (startCookie - logp->baseCookie < logp->logElements)
2518 /* At end of log, so clear it if we need to */
2519 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD) {
2520 logp->firstUsed = logp->firstFree = 0;
2521 logp->logElements = 0;
2523 /* otherwise, either wait for the data to arrive, or return */
2524 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2525 ReleaseWriteLock(&logp->lock);
2529 logp->states |= ICL_LOGF_WAITING;
2530 ReleaseWriteLock(&logp->lock);
2531 afs_osi_Sleep(&logp->lock);
2532 ObtainWriteLock(&logp->lock, 186);
2534 /* copy out data from ix to logSize or firstFree, depending
2535 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2536 * be careful not to copy out more than nwords.
2538 if (ix >= logp->firstUsed) {
2539 if (logp->firstUsed <= logp->firstFree)
2541 end = logp->firstFree; /* first element not to copy */
2543 end = logp->logSize;
2544 nwords = inWords; /* don't copy more than this */
2545 if (end - ix < nwords)
2548 memcpy((char *)bufferp, (char *)&logp->datap[ix],
2549 sizeof(afs_int32) * nwords);
2554 /* if we're going to copy more out below, we'll start here */
2557 /* now, if active part of the log has wrapped, there's more stuff
2558 * starting at the head of the log. Copy out more from there.
2560 if (logp->firstUsed > logp->firstFree && ix < logp->firstFree
2562 /* (more to) copy out from the wrapped section at the
2563 * start of the log. May get here even if didn't copy any
2564 * above, if the cookie points directly into the wrapped section.
2567 if (logp->firstFree - ix < nwords)
2568 nwords = logp->firstFree - ix;
2569 memcpy((char *)bufferp, (char *)&logp->datap[ix],
2570 sizeof(afs_int32) * nwords);
2576 ReleaseWriteLock(&logp->lock);
2580 *bufSizep = outWords;
2586 /* return basic parameter information about a log */
2588 afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 * maxSizep,
2589 afs_int32 * curSizep)
2591 ObtainReadLock(&logp->lock);
2592 *maxSizep = logp->logSize;
2593 *curSizep = logp->logElements;
2594 ReleaseReadLock(&logp->lock);
2599 /* hold and release logs */
2601 afs_icl_LogHold(register struct afs_icl_log *logp)
2603 ObtainWriteLock(&afs_icl_lock, 187);
2605 ReleaseWriteLock(&afs_icl_lock);
2609 /* hold and release logs, called with lock already held */
2611 afs_icl_LogHoldNL(register struct afs_icl_log *logp)
2617 /* keep track of how many sets believe the log itself is allocated */
2619 afs_icl_LogUse(register struct afs_icl_log *logp)
2621 ObtainWriteLock(&logp->lock, 188);
2622 if (logp->setCount == 0) {
2623 /* this is the first set actually using the log -- allocate it */
2624 if (logp->logSize == 0) {
2625 /* we weren't passed in a hint and it wasn't set */
2626 logp->logSize = ICL_DEFAULT_LOGSIZE;
2629 (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2630 #ifdef KERNEL_HAVE_PIN
2631 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2635 ReleaseWriteLock(&logp->lock);
2639 /* decrement the number of real users of the log, free if possible */
2641 afs_icl_LogFreeUse(register struct afs_icl_log *logp)
2643 ObtainWriteLock(&logp->lock, 189);
2644 if (--logp->setCount == 0) {
2645 /* no more users -- free it (but keep log structure around) */
2646 #ifdef KERNEL_HAVE_PIN
2647 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2649 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2650 logp->firstUsed = logp->firstFree = 0;
2651 logp->logElements = 0;
2654 ReleaseWriteLock(&logp->lock);
2658 /* set the size of the log to 'logSize' */
2660 afs_icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
2662 ObtainWriteLock(&logp->lock, 190);
2664 /* nothing to worry about since it's not allocated */
2665 logp->logSize = logSize;
2668 logp->firstUsed = logp->firstFree = 0;
2669 logp->logElements = 0;
2671 /* free and allocate a new one */
2672 #ifdef KERNEL_HAVE_PIN
2673 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2675 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2677 (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2678 #ifdef KERNEL_HAVE_PIN
2679 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2681 logp->logSize = logSize;
2683 ReleaseWriteLock(&logp->lock);
2688 /* free a log. Called with afs_icl_lock locked. */
2690 afs_icl_ZapLog(register struct afs_icl_log *logp)
2692 register struct afs_icl_log **lpp, *tp;
2694 for (lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2696 /* found the dude we want to remove */
2698 osi_FreeSmallSpace(logp->name);
2699 #ifdef KERNEL_HAVE_PIN
2700 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2702 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2703 osi_FreeSmallSpace(logp);
2704 break; /* won't find it twice */
2710 /* do the release, watching for deleted entries */
2712 afs_icl_LogRele(register struct afs_icl_log *logp)
2714 ObtainWriteLock(&afs_icl_lock, 191);
2715 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2716 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2718 ReleaseWriteLock(&afs_icl_lock);
2722 /* do the release, watching for deleted entries, log already held */
2724 afs_icl_LogReleNL(register struct afs_icl_log *logp)
2726 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2727 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2732 /* zero out the log */
2734 afs_icl_ZeroLog(register struct afs_icl_log *logp)
2736 ObtainWriteLock(&logp->lock, 192);
2737 logp->firstUsed = logp->firstFree = 0;
2738 logp->logElements = 0;
2739 logp->baseCookie = 0;
2740 ReleaseWriteLock(&logp->lock);
2744 /* free a log entry, and drop its reference count */
2746 afs_icl_LogFree(register struct afs_icl_log *logp)
2748 ObtainWriteLock(&logp->lock, 193);
2749 logp->states |= ICL_LOGF_DELETED;
2750 ReleaseWriteLock(&logp->lock);
2751 afs_icl_LogRele(logp);
2755 /* find a log by name, returning it held */
2756 struct afs_icl_log *
2757 afs_icl_FindLog(char *name)
2759 register struct afs_icl_log *tp;
2760 ObtainWriteLock(&afs_icl_lock, 194);
2761 for (tp = afs_icl_allLogs; tp; tp = tp->nextp) {
2762 if (strcmp(tp->name, name) == 0) {
2763 /* this is the dude we want */
2768 ReleaseWriteLock(&afs_icl_lock);
2773 afs_icl_EnumerateLogs(int (*aproc)
2774 (char *name, char *arock, struct afs_icl_log * tp),
2777 register struct afs_icl_log *tp;
2778 register afs_int32 code;
2781 ObtainWriteLock(&afs_icl_lock, 195);
2782 for (tp = afs_icl_allLogs; tp; tp = tp->nextp) {
2783 tp->refCount++; /* hold this guy */
2784 ReleaseWriteLock(&afs_icl_lock);
2785 ObtainReadLock(&tp->lock);
2786 code = (*aproc) (tp->name, arock, tp);
2787 ReleaseReadLock(&tp->lock);
2788 ObtainWriteLock(&afs_icl_lock, 196);
2789 if (--tp->refCount == 0)
2794 ReleaseWriteLock(&afs_icl_lock);
2798 struct afs_icl_set *afs_icl_allSets = 0;
2801 afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
2802 struct afs_icl_log *fatalLogp,
2803 struct afs_icl_set **outSetpp)
2805 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2806 /*flags */ 0, outSetpp);
2809 /* create a set, given pointers to base and fatal logs, if any.
2810 * Logs are unlocked, but referenced, and *outSetpp is returned
2811 * referenced. Function bumps reference count on logs, since it
2812 * addds references from the new afs_icl_set. When the set is destroyed,
2813 * those references will be released.
2816 afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
2817 struct afs_icl_log *fatalLogp, afs_uint32 flags,
2818 struct afs_icl_set **outSetpp)
2820 register struct afs_icl_set *setp;
2822 afs_int32 states = ICL_DEFAULT_SET_STATES;
2824 ObtainWriteLock(&afs_icl_lock, 197);
2825 if (!afs_icl_inited)
2828 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2829 if (strcmp(setp->name, name) == 0) {
2832 if (flags & ICL_CRSET_FLAG_PERSISTENT) {
2833 ObtainWriteLock(&setp->lock, 198);
2834 setp->states |= ICL_SETF_PERSISTENT;
2835 ReleaseWriteLock(&setp->lock);
2837 ReleaseWriteLock(&afs_icl_lock);
2842 /* determine initial state */
2843 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2844 states = ICL_SETF_ACTIVE;
2845 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2846 states = ICL_SETF_FREED;
2847 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2848 states |= ICL_SETF_PERSISTENT;
2850 setp = (struct afs_icl_set *)afs_osi_Alloc(sizeof(struct afs_icl_set));
2851 memset((caddr_t) setp, 0, sizeof(*setp));
2853 if (states & ICL_SETF_FREED)
2854 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2855 setp->states = states;
2857 LOCK_INIT(&setp->lock, "setp lock");
2858 /* next lock is obtained in wrong order, hierarchy-wise, but
2859 * it doesn't matter, since no one can find this lock yet, since
2860 * the afs_icl_lock is still held, and thus the obtain can't block.
2862 ObtainWriteLock(&setp->lock, 199);
2863 setp->name = osi_AllocSmallSpace(strlen(name) + 1);
2864 strcpy(setp->name, name);
2865 setp->nevents = ICL_DEFAULTEVENTS;
2866 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2867 #ifdef KERNEL_HAVE_PIN
2868 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2870 for (i = 0; i < ICL_DEFAULTEVENTS; i++)
2871 setp->eventFlags[i] = 0xff; /* default to enabled */
2873 /* update this global info under the afs_icl_lock */
2874 setp->nextp = afs_icl_allSets;
2875 afs_icl_allSets = setp;
2876 ReleaseWriteLock(&afs_icl_lock);
2878 /* set's basic lock is still held, so we can finish init */
2880 setp->logs[0] = baseLogp;
2881 afs_icl_LogHold(baseLogp);
2882 if (!(setp->states & ICL_SETF_FREED))
2883 afs_icl_LogUse(baseLogp); /* log is actually being used */
2886 setp->logs[1] = fatalLogp;
2887 afs_icl_LogHold(fatalLogp);
2888 if (!(setp->states & ICL_SETF_FREED))
2889 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2891 ReleaseWriteLock(&setp->lock);
2897 /* function to change event enabling information for a particular set */
2899 afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
2903 ObtainWriteLock(&setp->lock, 200);
2904 if (!ICL_EVENTOK(setp, eventID)) {
2905 ReleaseWriteLock(&setp->lock);
2908 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2910 *tp |= ICL_EVENTMASK(eventID);
2912 *tp &= ~(ICL_EVENTMASK(eventID));
2913 ReleaseWriteLock(&setp->lock);
2917 /* return indication of whether a particular event ID is enabled
2918 * for tracing. If *getValuep is set to 0, the event is disabled,
2919 * otherwise it is enabled. All events start out enabled by default.
2922 afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID, int *getValuep)
2924 ObtainReadLock(&setp->lock);
2925 if (!ICL_EVENTOK(setp, eventID)) {
2926 ReleaseWriteLock(&setp->lock);
2929 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2933 ReleaseReadLock(&setp->lock);
2937 /* hold and release event sets */
2939 afs_icl_SetHold(register struct afs_icl_set *setp)
2941 ObtainWriteLock(&afs_icl_lock, 201);
2943 ReleaseWriteLock(&afs_icl_lock);
2947 /* free a set. Called with afs_icl_lock locked */
2949 afs_icl_ZapSet(register struct afs_icl_set *setp)
2951 register struct afs_icl_set **lpp, *tp;
2953 register struct afs_icl_log *tlp;
2955 for (lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2957 /* found the dude we want to remove */
2959 osi_FreeSmallSpace(setp->name);
2960 #ifdef KERNEL_HAVE_PIN
2961 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2963 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2964 for (i = 0; i < ICL_LOGSPERSET; i++) {
2965 if ((tlp = setp->logs[i]))
2966 afs_icl_LogReleNL(tlp);
2968 osi_FreeSmallSpace(setp);
2969 break; /* won't find it twice */
2975 /* do the release, watching for deleted entries */
2977 afs_icl_SetRele(register struct afs_icl_set *setp)
2979 ObtainWriteLock(&afs_icl_lock, 202);
2980 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2981 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2983 ReleaseWriteLock(&afs_icl_lock);
2987 /* free a set entry, dropping its reference count */
2989 afs_icl_SetFree(register struct afs_icl_set *setp)
2991 ObtainWriteLock(&setp->lock, 203);
2992 setp->states |= ICL_SETF_DELETED;
2993 ReleaseWriteLock(&setp->lock);
2994 afs_icl_SetRele(setp);
2998 /* find a set by name, returning it held */
2999 struct afs_icl_set *
3000 afs_icl_FindSet(char *name)
3002 register struct afs_icl_set *tp;
3003 ObtainWriteLock(&afs_icl_lock, 204);
3004 for (tp = afs_icl_allSets; tp; tp = tp->nextp) {
3005 if (strcmp(tp->name, name) == 0) {
3006 /* this is the dude we want */
3011 ReleaseWriteLock(&afs_icl_lock);
3015 /* zero out all the logs in the set */
3017 afs_icl_ZeroSet(struct afs_icl_set *setp)
3022 struct afs_icl_log *logp;
3024 ObtainReadLock(&setp->lock);
3025 for (i = 0; i < ICL_LOGSPERSET; i++) {
3026 logp = setp->logs[i];
3028 afs_icl_LogHold(logp);
3029 tcode = afs_icl_ZeroLog(logp);
3031 code = tcode; /* save the last bad one */
3032 afs_icl_LogRele(logp);
3035 ReleaseReadLock(&setp->lock);
3040 afs_icl_EnumerateSets(int (*aproc)
3041 (char *name, char *arock, struct afs_icl_log * tp),
3044 register struct afs_icl_set *tp, *np;
3045 register afs_int32 code;
3048 ObtainWriteLock(&afs_icl_lock, 205);
3049 for (tp = afs_icl_allSets; tp; tp = np) {
3050 tp->refCount++; /* hold this guy */
3051 ReleaseWriteLock(&afs_icl_lock);
3052 code = (*aproc) (tp->name, arock, (struct afs_icl_log *)tp);
3053 ObtainWriteLock(&afs_icl_lock, 206);
3054 np = tp->nextp; /* tp may disappear next, but not np */
3055 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
3060 ReleaseWriteLock(&afs_icl_lock);
3065 afs_icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
3070 ObtainWriteLock(&setp->lock, 207);
3071 for (i = 0; i < ICL_LOGSPERSET; i++) {
3072 if (!setp->logs[i]) {
3073 setp->logs[i] = newlogp;
3075 afs_icl_LogHold(newlogp);
3076 if (!(setp->states & ICL_SETF_FREED)) {
3077 /* bump up the number of sets using the log */
3078 afs_icl_LogUse(newlogp);
3083 ReleaseWriteLock(&setp->lock);
3088 afs_icl_SetSetStat(struct afs_icl_set *setp, int op)
3092 struct afs_icl_log *logp;
3094 ObtainWriteLock(&setp->lock, 208);
3096 case ICL_OP_SS_ACTIVATE: /* activate a log */
3098 * If we are not already active, see if we have released
3099 * our demand that the log be allocated (FREED set). If
3100 * we have, reassert our desire.
3102 if (!(setp->states & ICL_SETF_ACTIVE)) {
3103 if (setp->states & ICL_SETF_FREED) {
3104 /* have to reassert desire for logs */
3105 for (i = 0; i < ICL_LOGSPERSET; i++) {
3106 logp = setp->logs[i];
3108 afs_icl_LogHold(logp);
3109 afs_icl_LogUse(logp);
3110 afs_icl_LogRele(logp);
3113 setp->states &= ~ICL_SETF_FREED;
3115 setp->states |= ICL_SETF_ACTIVE;
3120 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
3121 /* this doesn't require anything beyond clearing the ACTIVE flag */
3122 setp->states &= ~ICL_SETF_ACTIVE;
3126 case ICL_OP_SS_FREE: /* deassert design for log */
3128 * if we are already in this state, do nothing; otherwise
3129 * deassert desire for log
3131 if (setp->states & ICL_SETF_ACTIVE)
3134 if (!(setp->states & ICL_SETF_FREED)) {
3135 for (i = 0; i < ICL_LOGSPERSET; i++) {
3136 logp = setp->logs[i];
3138 afs_icl_LogHold(logp);
3139 afs_icl_LogFreeUse(logp);
3140 afs_icl_LogRele(logp);
3143 setp->states |= ICL_SETF_FREED;
3152 ReleaseWriteLock(&setp->lock);