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_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN_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 #if defined(AFS_HPUX_ENV)
104 extern int afs_vfs_mount();
105 #endif /* defined(AFS_HPUX_ENV) */
107 /* This is code which needs to be called once when the first daemon enters
108 * the client. A non-zero return means an error and AFS should not start.
111 afs_InitSetup(int preallocs)
113 extern void afs_InitStats();
116 if (afs_InitSetup_done)
121 * Set up all the AFS statistics variables. This should be done
122 * exactly once, and it should be done here, the first resource-setting
123 * routine to be called by the CM/RX.
126 #endif /* AFS_NOSTATS */
128 memset(afs_zeros, 0, AFS_ZEROS);
131 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
132 code = rx_InitHost(rx_bindhost, htons(7001));
134 printf("AFS: RX failed to initialize %d).\n", code);
137 rx_SetRxDeadTime(afs_rx_deadtime);
138 /* resource init creates the services */
139 afs_ResourceInit(preallocs);
141 afs_InitSetup_done = 1;
142 afs_osi_Wakeup(&afs_InitSetup_done);
147 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)
148 struct afsd_thread_info {
150 struct completion *complete;
154 afsd_thread(void *rock)
156 struct afsd_thread_info *arg = rock;
157 unsigned long parm = arg->parm;
158 #ifdef SYS_SETPRIORITY_EXPORTED
159 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
161 #if defined(AFS_LINUX26_ENV)
166 /* doesn't do much, since we were forked from keventd, but
167 * does call mm_release, which wakes up our parent (since it
168 * used CLONE_VFORK) */
169 #if !defined(AFS_LINUX26_ENV)
172 afs_osi_MaskSignals();
174 case AFSOP_START_RXCALLBACK:
175 sprintf(current->comm, "afs_cbstart");
177 complete(arg->complete);
179 while (afs_RX_Running != 2)
180 afs_osi_Sleep(&afs_RX_Running);
181 sprintf(current->comm, "afs_callback");
182 afs_RXCallBackServer();
184 complete_and_exit(0, 0);
186 case AFSOP_START_AFS:
187 sprintf(current->comm, "afs_afsstart");
189 complete(arg->complete);
191 while (afs_initState < AFSOP_START_AFS)
192 afs_osi_Sleep(&afs_initState);
193 afs_initState = AFSOP_START_BKG;
194 afs_osi_Wakeup(&afs_initState);
195 sprintf(current->comm, "afsd");
198 complete_and_exit(0, 0);
200 case AFSOP_START_BKG:
201 sprintf(current->comm, "afs_bkgstart");
203 complete(arg->complete);
204 while (afs_initState < AFSOP_START_BKG)
205 afs_osi_Sleep(&afs_initState);
206 if (afs_initState < AFSOP_GO) {
207 afs_initState = AFSOP_GO;
208 afs_osi_Wakeup(&afs_initState);
210 sprintf(current->comm, "afs_background");
211 afs_BackgroundDaemon();
213 complete_and_exit(0, 0);
215 case AFSOP_START_TRUNCDAEMON:
216 sprintf(current->comm, "afs_trimstart");
218 complete(arg->complete);
219 while (afs_initState < AFSOP_GO)
220 afs_osi_Sleep(&afs_initState);
221 sprintf(current->comm, "afs_cachetrim");
222 afs_CacheTruncateDaemon();
224 complete_and_exit(0, 0);
227 sprintf(current->comm, "afs_checkserver");
229 complete(arg->complete);
230 afs_CheckServerDaemon();
232 complete_and_exit(0, 0);
234 case AFSOP_RXEVENT_DAEMON:
235 sprintf(current->comm, "afs_evtstart");
236 #ifdef SYS_SETPRIORITY_EXPORTED
237 sys_setpriority(PRIO_PROCESS, 0, -10);
239 #ifdef CURRENT_INCLUDES_NICE
244 complete(arg->complete);
245 while (afs_initState < AFSOP_START_BKG)
246 afs_osi_Sleep(&afs_initState);
247 sprintf(current->comm, "afs_rxevent");
248 afs_rxevent_daemon();
250 complete_and_exit(0, 0);
252 case AFSOP_RXLISTENER_DAEMON:
253 sprintf(current->comm, "afs_lsnstart");
254 #ifdef SYS_SETPRIORITY_EXPORTED
255 sys_setpriority(PRIO_PROCESS, 0, -10);
257 #ifdef CURRENT_INCLUDES_NICE
262 complete(arg->complete);
263 afs_initState = AFSOP_START_AFS;
264 afs_osi_Wakeup(&afs_initState);
266 afs_osi_Wakeup(&afs_RX_Running);
267 afs_osi_RxkRegister();
268 sprintf(current->comm, "afs_rxlistener");
271 complete_and_exit(0, 0);
274 printf("Unknown op %ld in StartDaemon()\n", (long)parm);
281 afsd_launcher(void *rock)
283 if (!kernel_thread(afsd_thread, rock, CLONE_VFORK | SIGCHLD))
284 printf("kernel_thread failed. afs startup will not complete\n");
288 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
292 DECLARE_COMPLETION(c);
293 #if defined(AFS_LINUX26_ENV)
294 struct work_struct tq;
298 struct afsd_thread_info info;
299 if (parm == AFSOP_START_RXCALLBACK) {
302 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
306 code = afs_InitSetup(parm2);
308 rx_enablePeerRPCStats();
311 rx_enableProcessRPCStats();
315 } else if (parm == AFSOP_START_AFS) {
318 } /* other functions don't need setup in the parent */
321 #if defined(AFS_LINUX26_ENV)
322 INIT_WORK(&tq, afsd_launcher, &info);
326 INIT_LIST_HEAD(&tq.list);
327 tq.routine = afsd_launcher;
332 /* we need to wait cause we passed stack pointers around.... */
333 wait_for_completion(&c);
338 /* leaving as is, probably will barf if we add prototypes here since it's likely being called
341 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
342 long parm, parm2, parm3, parm4, parm5, parm6;
345 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
347 #else /* AFS_SGI61_ENV */
349 #endif /* AFS_SGI61_ENV */
351 AFS_STATCNT(afs_syscall_call);
353 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
354 && (parm != AFSOP_GETMASK)) {
355 /* only root can run this code */
358 if (!afs_suser(NULL) && (parm != AFSOP_GETMTU)
359 && (parm != AFSOP_GETMASK)) {
360 /* only root can run this code */
361 #if defined(KERNEL_HAVE_UERROR)
365 #if defined(AFS_OSF_ENV)
367 #else /* AFS_OSF_ENV */
369 #endif /* AFS_OSF_ENV */
374 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS) && !defined(UKERNEL)
375 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
376 || parm == AFSOP_RXLISTENER_DAEMON) {
377 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
379 #else /* !(AFS_LINUX24_ENV && !UKERNEL) */
380 if (parm == AFSOP_START_RXCALLBACK) {
384 #ifndef RXK_LISTENER_ENV
385 code = afs_InitSetup(parm2);
387 #endif /* !RXK_LISTENER_ENV */
389 #ifdef RXK_LISTENER_ENV
390 while (afs_RX_Running != 2)
391 afs_osi_Sleep(&afs_RX_Running);
392 #else /* !RXK_LISTENER_ENV */
393 afs_initState = AFSOP_START_AFS;
394 afs_osi_Wakeup(&afs_initState);
395 #endif /* RXK_LISTENER_ENV */
397 afs_RXCallBackServer();
401 exit(CLD_EXITED, code);
402 #endif /* AFS_SGI_ENV */
404 #ifdef RXK_LISTENER_ENV
405 else if (parm == AFSOP_RXLISTENER_DAEMON) {
409 code = afs_InitSetup(parm2);
411 rx_enablePeerRPCStats();
414 rx_enableProcessRPCStats();
417 afs_initState = AFSOP_START_AFS;
418 afs_osi_Wakeup(&afs_initState);
421 afs_osi_Wakeup(&afs_RX_Running);
423 afs_osi_RxkRegister();
424 #endif /* !UKERNEL */
429 exit(CLD_EXITED, code);
430 #endif /* AFS_SGI_ENV */
432 #endif /* RXK_LISTENER_ENV */
433 else if (parm == AFSOP_START_AFS) {
438 while (afs_initState < AFSOP_START_AFS)
439 afs_osi_Sleep(&afs_initState);
441 afs_initState = AFSOP_START_BKG;
442 afs_osi_Wakeup(&afs_initState);
448 #endif /* AFS_SGI_ENV */
449 } else if (parm == AFSOP_START_CS) {
451 afs_CheckServerDaemon();
455 #endif /* AFS_SGI_ENV */
456 } else if (parm == AFSOP_START_BKG) {
457 while (afs_initState < AFSOP_START_BKG)
458 afs_osi_Sleep(&afs_initState);
459 if (afs_initState < AFSOP_GO) {
460 afs_initState = AFSOP_GO;
461 afs_osi_Wakeup(&afs_initState);
463 /* start the bkg daemon */
467 afs_BioDaemon(parm2);
469 #endif /* AFS_AIX32_ENV */
470 afs_BackgroundDaemon();
474 #endif /* AFS_SGI_ENV */
475 } else if (parm == AFSOP_START_TRUNCDAEMON) {
476 while (afs_initState < AFSOP_GO)
477 afs_osi_Sleep(&afs_initState);
478 /* start the bkg daemon */
480 afs_CacheTruncateDaemon();
484 #endif /* AFS_SGI_ENV */
486 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
487 else if (parm == AFSOP_RXEVENT_DAEMON) {
488 while (afs_initState < AFSOP_START_BKG)
489 afs_osi_Sleep(&afs_initState);
491 afs_rxevent_daemon();
495 #endif /* AFS_SGI_ENV */
497 #endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
498 #endif /* AFS_LINUX24_ENV && !UKERNEL */
499 else if (parm == AFSOP_BASIC_INIT) {
502 while (!afs_InitSetup_done)
503 afs_osi_Sleep(&afs_InitSetup_done);
505 #if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
506 temp = AFS_MINBUFFERS; /* Should fix this soon */
508 /* number of 2k buffers we could get from all of the buffer space */
509 temp = ((afs_bufferpages * NBPG) >> 11);
510 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
511 if (temp < AFS_MINBUFFERS)
512 temp = AFS_MINBUFFERS; /* though we really should have this many */
515 afs_rootFid.Fid.Volume = 0;
517 } else if (parm == AFSOP_ADDCELL) {
518 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
519 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
520 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
521 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
523 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts),
526 if (parm4 > sizeof(tcell->cellName))
529 AFS_COPYIN((char *)parm3, tcell->cellName, parm4, code);
531 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
535 afs_osi_Free(tcell, sizeof(struct afsop_cell));
536 } else if (parm == AFSOP_ADDCELL2) {
537 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
538 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
539 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
543 /* wait for basic init - XXX can't find any reason we need this? */
544 while (afs_initState < AFSOP_START_BKG)
545 afs_osi_Sleep(&afs_initState);
548 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts),
551 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ,
555 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ,
559 cflags |= CLinkedCell;
564 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
568 afs_osi_Free(tcell, sizeof(struct afsop_cell));
569 osi_FreeSmallSpace(tbuffer);
570 osi_FreeSmallSpace(tbuffer1);
571 } else if (parm == AFSOP_ADDCELLALIAS) {
574 * parm2 is the alias name
575 * parm3 is the real cell name
577 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
578 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
580 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize,
583 AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ,
586 afs_NewCellAlias(aliasName, cellName);
587 osi_FreeSmallSpace(aliasName);
588 osi_FreeSmallSpace(cellName);
589 } else if (parm == AFSOP_SET_THISCELL) {
592 * parm2 is the primary cell name
594 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
596 AFS_COPYINSTR((char *)parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code);
598 afs_SetPrimaryCell(cell);
599 osi_FreeSmallSpace(cell);
600 } else if (parm == AFSOP_CACHEINIT) {
601 struct afs_cacheParams cparms;
603 if (afs_CacheInit_Done)
606 AFS_COPYIN((char *)parm2, (caddr_t) & cparms, sizeof(cparms), code);
608 #if defined(KERNEL_HAVE_UERROR)
614 afs_CacheInit_Done = 1;
616 struct afs_icl_log *logp;
617 /* initialize the ICL system */
618 code = afs_icl_CreateLog("cmfx", 60 * 1024, &logp);
621 afs_icl_CreateSetWithFlags("cm", logp, NULL,
622 ICL_CRSET_FLAG_DEFAULT_OFF,
625 afs_icl_CreateSet("cmlongterm", logp, NULL,
626 &afs_iclLongTermSetp);
628 afs_setTime = cparms.setTimeFlag;
631 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
632 cparms.cacheBlocks, cparms.cacheDcaches,
633 cparms.cacheVolumes, cparms.chunkSize,
634 cparms.memCacheFlag, cparms.inodes, cparms.users);
636 } else if (parm == AFSOP_CACHEINODE) {
637 ino_t ainode = parm2;
638 /* wait for basic init */
639 while (afs_initState < AFSOP_START_BKG)
640 afs_osi_Sleep(&afs_initState);
644 ainode = (ainode << 32) | (parm3 & 0xffffffff);
646 code = afs_InitCacheFile(NULL, ainode);
647 } else if (parm == AFSOP_ROOTVOLUME) {
648 /* wait for basic init */
649 while (afs_initState < AFSOP_START_BKG)
650 afs_osi_Sleep(&afs_initState);
653 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName,
654 sizeof(afs_rootVolumeName), &bufferSize, code);
655 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
658 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
659 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG
660 || parm == AFSOP_CELLINFO) {
661 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
664 AFS_COPYINSTR((char *)parm2, tbuffer, AFS_SMALLOCSIZ, &bufferSize,
667 osi_FreeSmallSpace(tbuffer);
671 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
672 /* We have the cache dir copied in. Call the cache init routine */
673 if (parm == AFSOP_CACHEFILE)
674 code = afs_InitCacheFile(tbuffer, 0);
675 else if (parm == AFSOP_CACHEINFO)
676 code = afs_InitCacheInfo(tbuffer);
677 else if (parm == AFSOP_VOLUMEINFO)
678 code = afs_InitVolumeInfo(tbuffer);
679 else if (parm == AFSOP_CELLINFO)
680 code = afs_InitCellInfo(tbuffer);
682 osi_FreeSmallSpace(tbuffer);
683 } else if (parm == AFSOP_GO) {
684 /* the generic initialization calls come here. One parameter: should we do the
685 * set-time operation on this workstation */
689 while (afs_initState < AFSOP_GO)
690 afs_osi_Sleep(&afs_initState);
693 afs_osi_Wakeup(&afs_initState);
694 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
695 afs_nfsclient_init();
697 printf("found %d non-empty cache files (%d%%).\n",
698 afs_stats_cmperf.cacheFilesReused,
699 (100 * afs_stats_cmperf.cacheFilesReused) /
700 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
701 cacheNumEntries : 1));
702 } else if (parm == AFSOP_ADVISEADDR) {
703 /* pass in the host address to the rx package */
705 afs_int32 count = parm2;
707 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
708 afs_int32 *maskbuffer =
709 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
710 afs_int32 *mtubuffer =
711 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
714 /* Bind, but only if there's only one address configured */
715 if ( count & 0x80000000) {
716 count &= ~0x80000000;
721 if (count > AFS_MAX_INTERFACE_ADDR) {
723 count = AFS_MAX_INTERFACE_ADDR;
726 AFS_COPYIN((char *)parm3, (char *)buffer, count * sizeof(afs_int32),
729 AFS_COPYIN((char *)parm4, (char *)maskbuffer,
730 count * sizeof(afs_int32), code);
732 AFS_COPYIN((char *)parm5, (char *)mtubuffer,
733 count * sizeof(afs_int32), code);
735 afs_cb_interface.numberOfInterfaces = count;
736 for (i = 0; i < count; i++) {
737 afs_cb_interface.addr_in[i] = buffer[i];
738 #ifdef AFS_USERSPACE_IP_ADDR
739 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
740 * machines IP addresses when in the kernel (the in_ifaddr
741 * struct is not available), so we pass the info in at
742 * startup. We also pass in the subnetmask and mtu size. The
743 * subnetmask is used when setting the rank:
744 * afsi_SetServerIPRank(); and the mtu size is used when
745 * finding the best mtu size. rxi_FindIfnet() is replaced
746 * with rxi_Findcbi().
748 afs_cb_interface.subnetmask[i] =
749 (parm4 ? maskbuffer[i] : 0xffffffff);
750 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
753 afs_uuid_create(&afs_cb_interface.uuid);
754 rxi_setaddr(buffer[0]);
756 rx_bindhost = buffer[0];
758 rx_bindhost = htonl(INADDR_ANY);
760 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
761 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
762 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
765 else if (parm == AFSOP_NFSSTATICADDR) {
766 extern int (*nfs_rfsdisptab_v2) ();
767 nfs_rfsdisptab_v2 = (int (*)())parm2;
768 } else if (parm == AFSOP_NFSSTATICADDR2) {
769 extern int (*nfs_rfsdisptab_v2) ();
771 nfs_rfsdisptab_v2 = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
773 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
776 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
777 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
778 extern int (*afs_sblockp) ();
779 extern void (*afs_sbunlockp) ();
781 afs_sblockp = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
782 afs_sbunlockp = (void (*)())((parm4 << 32) | (parm5 & 0xffffffff));
784 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
785 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
788 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
789 #endif /* AFS_SGI53_ENV */
790 else if (parm == AFSOP_SHUTDOWN) {
791 afs_cold_shutdown = 0;
793 afs_cold_shutdown = 1;
794 #ifndef AFS_DARWIN_ENV
795 if (afs_globalVFS != 0) {
796 afs_warn("AFS isn't unmounted yet! Call aborted\n");
801 } else if (parm == AFSOP_AFS_VFSMOUNT) {
803 vfsmount(parm2, parm3, parm4, parm5);
804 #else /* defined(AFS_HPUX_ENV) */
805 #if defined(KERNEL_HAVE_UERROR)
810 #endif /* defined(AFS_HPUX_ENV) */
811 } else if (parm == AFSOP_CLOSEWAIT) {
812 afs_SynchronousCloses = 'S';
813 } else if (parm == AFSOP_GETMTU) {
815 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
816 #ifdef AFS_USERSPACE_IP_ADDR
818 i = rxi_Findcbi(parm2);
819 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
820 #else /* AFS_USERSPACE_IP_ADDR */
823 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
824 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
825 #endif /* else AFS_USERSPACE_IP_ADDR */
826 #endif /* !AFS_SUN5_ENV */
828 AFS_COPYOUT((caddr_t) & mtu, (caddr_t) parm3, sizeof(afs_int32),
831 /* this is disabled for now because I can't figure out how to get access
832 * to these kernel variables. It's only for supporting user-mode rx
833 * programs -- it makes a huge difference on the 220's in my testbed,
834 * though I don't know why. The bosserver does this with /etc/no, so it's
835 * being handled a different way for the servers right now. */
838 extern u_long sb_max_dflt;
841 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
842 if (sb_max < 131072) sb_max = 131072;
845 #endif /* AFS_AIX32_ENV */
846 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
848 #if !defined(AFS_SUN5_ENV)
849 #ifdef AFS_USERSPACE_IP_ADDR
851 i = rxi_Findcbi(parm2);
853 mask = afs_cb_interface.subnetmask[i];
857 #else /* AFS_USERSPACE_IP_ADDR */
860 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
863 #endif /* else AFS_USERSPACE_IP_ADDR */
864 #endif /* !AFS_SUN5_ENV */
866 AFS_COPYOUT((caddr_t) & mask, (caddr_t) parm3, sizeof(afs_int32),
870 else if (parm == AFSOP_AFSDB_HANDLER) {
871 int sizeArg = (int)parm4;
872 int kmsgLen = sizeArg & 0xffff;
873 int cellLen = (sizeArg & 0xffff0000) >> 16;
874 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
875 char *cellname = afs_osi_Alloc(cellLen);
878 afs_osi_MaskUserLoop();
880 AFS_COPYIN((afs_int32 *) parm2, cellname, cellLen, code);
881 AFS_COPYIN((afs_int32 *) parm3, kmsg, kmsgLen, code);
883 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
886 if (code == -2) { /* Shutting down? */
892 AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
893 afs_osi_Free(kmsg, kmsgLen);
894 afs_osi_Free(cellname, cellLen);
897 else if (parm == AFSOP_SET_DYNROOT) {
898 code = afs_SetDynrootEnable(parm2);
899 } else if (parm == AFSOP_SET_FAKESTAT) {
900 afs_fakestat_enable = parm2;
902 } else if (parm == AFSOP_SET_BACKUPTREE) {
903 afs_bkvolpref = parm2;
909 #ifdef AFS_LINUX20_ENV
918 #include "sys/lockl.h"
921 * syscall - this is the VRMIX system call entry point.
924 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
925 * all the user-level calls to `syscall' to change.
927 syscall(syscall, p1, p2, p3, p4, p5, p6)
929 register rval1 = 0, code;
932 #ifndef AFS_AIX41_ENV
933 extern lock_t kernel_lock;
934 monster = lockl(&kernel_lock, LOCK_SHORT);
935 #endif /* !AFS_AIX41_ENV */
937 AFS_STATCNT(syscall);
941 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
946 rval1 = afs_setpag();
952 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
956 case AFSCALL_ICREATE:
957 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
961 rval1 = afs_syscall_iopen(p1, p2, p3);
965 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
969 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
974 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
989 #ifndef AFS_AIX41_ENV
990 if (monster != LOCK_NEST)
991 unlockl(&kernel_lock);
992 #endif /* !AFS_AIX41_ENV */
993 return getuerror()? -1 : rval1;
997 * lsetpag - interface to afs_setpag().
1002 AFS_STATCNT(lsetpag);
1003 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
1007 * lpioctl - interface to pioctl()
1009 lpioctl(path, cmd, cmarg, follow)
1013 AFS_STATCNT(lpioctl);
1014 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
1017 #else /* !AFS_AIX32_ENV */
1019 #if defined(AFS_SGI_ENV)
1031 Afs_syscall(struct afsargs *uap, rval_t * rvp)
1036 AFS_STATCNT(afs_syscall);
1037 switch (uap->syscall) {
1042 Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1043 uap->parm5, &retval);
1045 rvp->r_val1 = retval;
1047 #ifdef AFS_SGI_XFS_IOPS_ENV
1048 case AFSCALL_IDEC64:
1050 afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1053 case AFSCALL_IINC64:
1055 afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1058 case AFSCALL_ILISTINODE64:
1060 afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
1061 uap->parm4, uap->parm5);
1063 case AFSCALL_ICREATENAME64:
1065 afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
1066 uap->parm4, uap->parm5);
1069 #ifdef AFS_SGI_VNODE_GLUE
1070 case AFSCALL_INIT_KERNEL_CONFIG:
1071 error = afs_init_kernel_config(uap->parm1);
1076 afs_syscall_call(uap->syscall, uap->parm1, uap->parm2, uap->parm3,
1077 uap->parm4, uap->parm5);
1082 #else /* AFS_SGI_ENV */
1099 #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))
1101 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
1103 dst->param1 = src->param1;
1104 dst->param2 = src->param2;
1105 dst->param3 = src->param3;
1106 dst->param4 = src->param4;
1111 * If you need to change copyin_iparam(), you may also need to change
1112 * copyin_afs_ioctl().
1116 copyin_iparam(caddr_t cmarg, struct iparam *dst)
1120 #if defined(AFS_HPUX_64BIT_ENV)
1121 struct iparam32 dst32;
1123 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
1124 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
1126 iparam32_to_iparam(&dst32, dst);
1129 #endif /* AFS_HPUX_64BIT_ENV */
1131 #if defined(AFS_SUN57_64BIT_ENV)
1132 struct iparam32 dst32;
1134 if (get_udatamodel() == DATAMODEL_ILP32) {
1135 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
1137 iparam32_to_iparam(&dst32, dst);
1140 #endif /* AFS_SUN57_64BIT_ENV */
1142 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
1143 struct iparam32 dst32;
1145 #ifdef AFS_SPARC64_LINUX24_ENV
1146 if (current->thread.flags & SPARC_FLAG_32BIT)
1147 #elif defined(AFS_SPARC64_LINUX20_ENV)
1148 if (current->tss.flags & SPARC_FLAG_32BIT)
1150 #elif defined(AFS_AMD64_LINUX26_ENV)
1151 if (test_thread_flag(TIF_IA32))
1152 #elif defined(AFS_AMD64_LINUX20_ENV)
1153 if (current->thread.flags & THREAD_IA32)
1155 #elif defined(AFS_PPC64_LINUX26_ENV)
1156 if (current->thread_info->flags & _TIF_32BIT)
1157 #elif defined(AFS_PPC64_LINUX20_ENV)
1158 if (current->thread.flags & PPC_FLAG_32BIT)
1160 #elif defined(AFS_S390X_LINUX26_ENV)
1161 if (test_thread_flag(TIF_31BIT))
1162 #elif defined(AFS_S390X_LINUX20_ENV)
1163 if (current->thread.flags & S390_FLAG_31BIT)
1166 #error iparam32 not done for this linux platform
1169 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
1171 iparam32_to_iparam(&dst32, dst);
1174 #endif /* AFS_LINUX_64BIT_KERNEL */
1176 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
1180 /* Main entry of all afs system calls */
1182 extern int afs_sinited;
1184 /** The 32 bit OS expects the members of this structure to be 32 bit
1185 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
1186 * to accomodate both, *long* is used instead of afs_int32
1189 #ifdef AFS_SUN57_ENV
1211 Afs_syscall(register struct afssysa *uap, rval_t * rvp)
1213 int *retval = &rvp->r_val1;
1214 #else /* AFS_SUN5_ENV */
1215 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1217 afs3_syscall(p, args, retval)
1218 #ifdef AFS_FBSD50_ENV
1234 } *uap = (struct a *)args;
1235 #else /* AFS_OSF_ENV */
1236 #ifdef AFS_LINUX20_ENV
1244 long parm6; /* not actually used - should be removed */
1246 /* Linux system calls only set up for 5 arguments. */
1248 afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4)
1250 struct afssysargs args, *uap = &args;
1252 long *retval = &linux_ret;
1253 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
1254 #ifdef AFS_SPARC64_LINUX24_ENV
1255 afs_int32 eparm32[4];
1257 /* eparm is also used by AFSCALL_CALL in afsd.c */
1259 #if defined(UKERNEL)
1270 } *uap = (struct a *)u.u_ap;
1273 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
1277 #endif /* SUN && !SUN5 */
1287 } *uap = (struct a *)u.u_ap;
1288 #endif /* UKERNEL */
1289 #if defined(AFS_DEC_ENV)
1290 int *retval = &u.u_r.r_val1;
1291 #elif defined(AFS_HPUX_ENV)
1292 long *retval = &u.u_rval1;
1294 int *retval = &u.u_rval1;
1296 #endif /* AFS_LINUX20_ENV */
1297 #endif /* AFS_OSF_ENV */
1298 #endif /* AFS_SUN5_ENV */
1299 register int code = 0;
1301 AFS_STATCNT(afs_syscall);
1308 #ifdef AFS_LINUX20_ENV
1310 /* setup uap for use below - pull out the magic decoder ring to know
1311 * which syscalls have folded argument lists.
1313 uap->syscall = syscall;
1317 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
1318 #ifdef AFS_SPARC64_LINUX24_ENV
1319 /* from arch/sparc64/kernel/sys_sparc32.c */
1321 ({ unsigned long __ret; \
1322 __asm__ ("srl %0, 0, %0" \
1329 if (current->thread.flags & SPARC_FLAG_32BIT) {
1330 AFS_COPYIN((char *)parm4, (char *)eparm32, sizeof(eparm32), code);
1331 eparm[0] = AA(eparm32[0]);
1332 eparm[1] = AA(eparm32[1]);
1333 eparm[2] = AA(eparm32[2]);
1337 AFS_COPYIN((char *)parm4, (char *)eparm, sizeof(eparm), code);
1338 uap->parm4 = eparm[0];
1339 uap->parm5 = eparm[1];
1340 uap->parm6 = eparm[2];
1348 #if defined(AFS_HPUX_ENV)
1350 * There used to be code here (duplicated from osi_Init()) for
1351 * initializing the semaphore used by AFS_GLOCK(). Was the
1352 * duplication to handle the case of a dynamically loaded kernel
1357 if (uap->syscall == AFSCALL_CALL) {
1360 afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1361 uap->parm5, uap->parm6, rvp, CRED());
1364 afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1365 uap->parm5, uap->parm6);
1367 } else if (uap->syscall == AFSCALL_SETPAG) {
1369 register proc_t *procp;
1371 procp = ttoproc(curthread);
1373 code = afs_setpag(&procp->p_cred);
1377 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1378 code = afs_setpag(p, args, retval);
1379 #else /* AFS_OSF_ENV */
1380 code = afs_setpag();
1384 } else if (uap->syscall == AFSCALL_PIOCTL) {
1386 #if defined(AFS_SUN5_ENV)
1388 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1390 #elif defined(AFS_FBSD50_ENV)
1392 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1394 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1396 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1397 p->p_cred->pc_ucred);
1400 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
1404 } else if (uap->syscall == AFSCALL_ICREATE) {
1405 struct iparam iparams;
1407 code = copyin_iparam((char *)uap->parm3, &iparams);
1409 #if defined(KERNEL_HAVE_UERROR)
1415 afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
1416 iparams.param2, iparams.param3,
1417 iparams.param4, rvp, CRED());
1420 afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
1422 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1423 iparams.param3, iparams.param4, retval);
1425 iparams.param3, iparams.param4);
1427 #endif /* AFS_SUN5_ENV */
1428 } else if (uap->syscall == AFSCALL_IOPEN) {
1431 afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp,
1434 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1435 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1437 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1439 #endif /* AFS_SUN5_ENV */
1440 } else if (uap->syscall == AFSCALL_IDEC) {
1443 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp,
1446 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1447 #endif /* AFS_SUN5_ENV */
1448 } else if (uap->syscall == AFSCALL_IINC) {
1451 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp,
1454 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1455 #endif /* AFS_SUN5_ENV */
1456 } else if (uap->syscall == AFSCALL_ICL) {
1459 Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
1460 uap->parm5, retval);
1462 #ifdef AFS_LINUX20_ENV
1464 /* ICL commands can return values. */
1465 code = -linux_ret; /* Gets negated again at exit below */
1469 #if defined(KERNEL_HAVE_UERROR)
1473 #endif /* !AFS_LINUX20_ENV */
1475 #if defined(KERNEL_HAVE_UERROR)
1482 #ifdef AFS_LINUX20_ENV
1488 #endif /* AFS_SGI_ENV */
1489 #endif /* !AFS_AIX32_ENV */
1492 * Initstate in the range 0 < x < 100 are early initialization states.
1493 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1494 * the cache may be initialized.
1495 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1496 * is done after all the cache initialization has been done.
1497 * Initstate of 200 means that the volume has been looked up once, possibly
1499 * Initstate of 300 means that the volume has been *successfully* looked up.
1504 register int code = 0;
1506 AFS_STATCNT(afs_CheckInit);
1507 if (afs_initState <= 100)
1508 code = ENXIO; /* never finished init phase */
1509 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1510 while (afs_initState < 200)
1511 afs_osi_Sleep(&afs_initState);
1512 } else if (afs_initState == 200)
1513 code = ETIMEDOUT; /* didn't find root volume */
1517 int afs_shuttingdown = 0;
1521 extern short afs_brsDaemons;
1522 extern afs_int32 afs_CheckServerDaemonStarted;
1523 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1524 extern struct osi_file *afs_cacheInodep;
1526 AFS_STATCNT(afs_shutdown);
1527 if (afs_initState == 0) {
1528 afs_warn("AFS not initialized - not shutting down\n");
1532 if (afs_shuttingdown)
1534 afs_shuttingdown = 1;
1535 if (afs_cold_shutdown)
1539 afs_warn("shutting down of: CB... ");
1541 afs_termState = AFSOP_STOP_RXCALLBACK;
1542 rx_WakeupServerProcs();
1543 #ifdef AFS_AIX51_ENV
1544 shutdown_rxkernel();
1546 /* shutdown_rxkernel(); */
1547 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1548 afs_osi_Sleep(&afs_termState);
1550 afs_warn("afs... ");
1551 while (afs_termState == AFSOP_STOP_AFS) {
1552 afs_osi_CancelWait(&AFS_WaitHandler);
1553 afs_osi_Sleep(&afs_termState);
1555 if (afs_CheckServerDaemonStarted) {
1556 while (afs_termState == AFSOP_STOP_CS) {
1557 afs_osi_CancelWait(&AFS_CSWaitHandler);
1558 afs_osi_Sleep(&afs_termState);
1561 afs_warn("BkG... ");
1562 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1563 while (afs_termState == AFSOP_STOP_BKG) {
1564 afs_osi_Wakeup(&afs_brsDaemons);
1565 afs_osi_Sleep(&afs_termState);
1567 afs_warn("CTrunc... ");
1568 /* Cancel cache truncate daemon. */
1569 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1570 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1571 afs_osi_Sleep(&afs_termState);
1573 #ifdef AFS_AFSDB_ENV
1574 afs_warn("AFSDB... ");
1576 while (afs_termState == AFSOP_STOP_AFSDB)
1577 afs_osi_Sleep(&afs_termState);
1579 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1580 afs_warn("RxEvent... ");
1581 /* cancel rx event daemon */
1582 while (afs_termState == AFSOP_STOP_RXEVENT)
1583 afs_osi_Sleep(&afs_termState);
1584 #if defined(RXK_LISTENER_ENV)
1586 afs_warn("UnmaskRxkSignals... ");
1587 afs_osi_UnmaskRxkSignals();
1589 /* cancel rx listener */
1590 afs_warn("RxListener... ");
1591 osi_StopListener(); /* This closes rx_socket. */
1592 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1593 afs_warn("Sleep... ");
1594 afs_osi_Sleep(&afs_termState);
1598 afs_termState = AFSOP_STOP_COMPLETE;
1602 /* Close file only after daemons which can write to it are stopped. */
1603 if (afs_cacheInodep) { /* memcache won't set this */
1604 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1605 afs_cacheInodep = 0;
1607 return; /* Just kill daemons for now */
1611 shutdown_rxkernel();
1615 shutdown_bufferpackage();
1617 #ifdef AFS_AIX51_ENV
1625 shutdown_vnodeops();
1627 shutdown_exporter();
1628 shutdown_memcache();
1629 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1630 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1631 /* this routine does not exist in Ultrix systems... 93.01.19 */
1633 #endif /* AFS_DEC_ENV */
1636 /* The following hold the cm stats */
1638 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1639 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1640 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1642 afs_warn(" ALL allocated tables\n");
1643 afs_shuttingdown = 0;
1648 shutdown_afstest(void)
1650 AFS_STATCNT(shutdown_afstest);
1651 afs_initState = afs_termState = afs_setTime = 0;
1652 AFS_Running = afs_CB_Running = 0;
1653 afs_CacheInit_Done = afs_Go_Done = 0;
1654 if (afs_cold_shutdown) {
1655 *afs_rootVolumeName = 0;
1660 /* In case there is a bunch of dynamically build bkg daemons to free */
1662 afs_shutdown_BKG(void)
1664 AFS_STATCNT(shutdown_BKG);
1668 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1669 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1670 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1671 int afs_icl_sizeofLong = 1;
1673 int afs_icl_sizeofLong = 2;
1676 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
1677 int afs_icl_sizeofLong = 2;
1679 int afs_icl_sizeofLong = 1;
1683 int afs_icl_inited = 0;
1685 /* init function, called once, under afs_icl_lock */
1693 extern struct afs_icl_log *afs_icl_FindLog();
1694 extern struct afs_icl_set *afs_icl_FindSet();
1698 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1700 afs_int32 *lp, elts, flags;
1701 register afs_int32 code;
1702 struct afs_icl_log *logp;
1703 struct afs_icl_set *setp;
1704 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1706 #else /* AFS_SGI61_ENV */
1707 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
1712 #endif /* AFS_SGI61_ENV */
1714 afs_int32 startCookie;
1715 afs_int32 allocated;
1716 struct afs_icl_log *tlp;
1719 if (!afs_suser(CRED())) { /* only root can run this code */
1723 if (!afs_suser(NULL)) { /* only root can run this code */
1724 #if defined(KERNEL_HAVE_UERROR)
1733 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1734 case ICL_OP_COPYOUT: /* copy ouy data */
1735 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1736 * return flags<<24 + nwords.
1737 * updates cookie to updated start (not end) if we had to
1738 * skip some records.
1740 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1743 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1746 logp = afs_icl_FindLog(tname);
1749 #define BUFFERSIZE AFS_LRALLOCSIZ
1750 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1751 elts = BUFFERSIZE / sizeof(afs_int32);
1754 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1756 afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) & startCookie,
1759 osi_FreeLargeSpace((struct osi_buffer *)lp);
1762 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1765 AFS_COPYOUT((char *)&startCookie, (char *)p4, sizeof(afs_int32),
1769 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
1771 *retval = ((long)((flags << 24) | (elts & 0xffffff))) << 32;
1774 *retval = (flags << 24) | (elts & 0xffffff);
1776 afs_icl_LogRele(logp);
1777 osi_FreeLargeSpace((struct osi_buffer *)lp);
1780 case ICL_OP_ENUMLOGS: /* enumerate logs */
1781 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1782 * return 0 for success, otherwise error.
1784 for (tlp = afs_icl_allLogs; tlp; tlp = tlp->nextp) {
1789 return ENOENT; /* past the end of file */
1790 temp = strlen(tlp->name) + 1;
1793 AFS_COPYOUT(tlp->name, (char *)p2, temp, code);
1794 if (!code) /* copy out size of log */
1795 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof(afs_int32),
1799 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1800 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1801 * return 0 for success, otherwise error.
1803 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1806 setp = afs_icl_FindSet(tname);
1809 if (p2 > ICL_LOGSPERSET)
1811 if (!(tlp = setp->logs[p2]))
1813 temp = strlen(tlp->name) + 1;
1816 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1819 case ICL_OP_CLRLOG: /* clear specified log */
1820 /* zero out the specified log: p1=logname */
1821 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1824 logp = afs_icl_FindLog(tname);
1827 code = afs_icl_ZeroLog(logp);
1828 afs_icl_LogRele(logp);
1831 case ICL_OP_CLRSET: /* clear specified set */
1832 /* zero out the specified set: p1=setname */
1833 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1836 setp = afs_icl_FindSet(tname);
1839 code = afs_icl_ZeroSet(setp);
1840 afs_icl_SetRele(setp);
1843 case ICL_OP_CLRALL: /* clear all logs */
1844 /* zero out all logs -- no args */
1846 ObtainWriteLock(&afs_icl_lock, 178);
1847 for (tlp = afs_icl_allLogs; tlp; tlp = tlp->nextp) {
1848 tlp->refCount++; /* hold this guy */
1849 ReleaseWriteLock(&afs_icl_lock);
1850 /* don't clear persistent logs */
1851 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1852 code = afs_icl_ZeroLog(tlp);
1853 ObtainWriteLock(&afs_icl_lock, 179);
1854 if (--tlp->refCount == 0)
1855 afs_icl_ZapLog(tlp);
1859 ReleaseWriteLock(&afs_icl_lock);
1862 case ICL_OP_ENUMSETS: /* enumerate all sets */
1863 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1864 * return 0 for success, otherwise error.
1866 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
1871 return ENOENT; /* past the end of file */
1872 temp = strlen(setp->name) + 1;
1875 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1876 if (!code) /* copy out size of log */
1877 AFS_COPYOUT((char *)&setp->states, (char *)p4, sizeof(afs_int32),
1881 case ICL_OP_SETSTAT: /* set status on a set */
1882 /* activate the specified set: p1=setname, p2=op */
1883 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1886 setp = afs_icl_FindSet(tname);
1889 code = afs_icl_SetSetStat(setp, p2);
1890 afs_icl_SetRele(setp);
1893 case ICL_OP_SETSTATALL: /* set status on all sets */
1894 /* activate the specified set: p1=op */
1896 ObtainWriteLock(&afs_icl_lock, 180);
1897 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
1898 setp->refCount++; /* hold this guy */
1899 ReleaseWriteLock(&afs_icl_lock);
1900 /* don't set states on persistent sets */
1901 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1902 code = afs_icl_SetSetStat(setp, p1);
1903 ObtainWriteLock(&afs_icl_lock, 181);
1904 if (--setp->refCount == 0)
1905 afs_icl_ZapSet(setp);
1909 ReleaseWriteLock(&afs_icl_lock);
1912 case ICL_OP_SETLOGSIZE: /* set size of log */
1913 /* set the size of the specified log: p1=logname, p2=size (in words) */
1914 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1917 logp = afs_icl_FindLog(tname);
1920 code = afs_icl_LogSetSize(logp, p2);
1921 afs_icl_LogRele(logp);
1924 case ICL_OP_GETLOGINFO: /* get size of log */
1925 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1926 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1929 logp = afs_icl_FindLog(tname);
1932 allocated = !!logp->datap;
1933 AFS_COPYOUT((char *)&logp->logSize, (char *)p2, sizeof(afs_int32),
1936 AFS_COPYOUT((char *)&allocated, (char *)p3, sizeof(afs_int32),
1938 afs_icl_LogRele(logp);
1941 case ICL_OP_GETSETINFO: /* get state of set */
1942 /* zero out the specified set: p1=setname, p2=&state */
1943 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1946 setp = afs_icl_FindSet(tname);
1949 AFS_COPYOUT((char *)&setp->states, (char *)p2, sizeof(afs_int32),
1951 afs_icl_SetRele(setp);
1962 afs_lock_t afs_icl_lock;
1964 /* exported routine: a 4 parameter event */
1966 afs_icl_Event4(register struct afs_icl_set *setp, afs_int32 eventID,
1967 afs_int32 lAndT, long p1, long p2, long p3, long p4)
1971 register afs_int32 tmask;
1974 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1975 if (!ICL_SETACTIVE(setp))
1979 mask = lAndT >> 24 & 0xff; /* mask of which logs to log to */
1980 ix = ICL_EVENTBYTE(eventID);
1981 ObtainReadLock(&setp->lock);
1982 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1983 for (i = 0, tmask = 1; i < ICL_LOGSPERSET; i++, tmask <<= 1) {
1985 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1990 break; /* break early */
1993 ReleaseReadLock(&setp->lock);
1997 /* Next 4 routines should be implemented via var-args or something.
1998 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1999 * Otherwise, could call afs_icl_Event4 directly.
2002 afs_icl_Event3(register struct afs_icl_set *setp, afs_int32 eventID,
2003 afs_int32 lAndT, long p1, long p2, long p3)
2005 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
2009 afs_icl_Event2(register struct afs_icl_set *setp, afs_int32 eventID,
2010 afs_int32 lAndT, long p1, long p2)
2012 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
2016 afs_icl_Event1(register struct afs_icl_set *setp, afs_int32 eventID,
2017 afs_int32 lAndT, long p1)
2019 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0,
2024 afs_icl_Event0(register struct afs_icl_set *setp, afs_int32 eventID,
2027 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0,
2031 struct afs_icl_log *afs_icl_allLogs = 0;
2033 /* function to purge records from the start of the log, until there
2034 * is at least minSpace long's worth of space available without
2035 * making the head and the tail point to the same word.
2037 * Log must be write-locked.
2040 afs_icl_GetLogSpace(register struct afs_icl_log *logp, afs_int32 minSpace)
2042 register unsigned int tsize;
2044 while (logp->logSize - logp->logElements <= minSpace) {
2046 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
2047 logp->logElements -= tsize;
2048 logp->firstUsed += tsize;
2049 if (logp->firstUsed >= logp->logSize)
2050 logp->firstUsed -= logp->logSize;
2051 logp->baseCookie += tsize;
2055 /* append string astr to buffer, including terminating null char.
2057 * log must be write-locked.
2059 #define ICL_CHARSPERLONG 4
2061 afs_icl_AppendString(struct afs_icl_log *logp, char *astr)
2063 char *op; /* ptr to char to write */
2065 register int bib; /* bytes in buffer */
2068 op = (char *)&(logp->datap[logp->firstFree]);
2072 if (++bib >= ICL_CHARSPERLONG) {
2075 if (++(logp->firstFree) >= logp->logSize) {
2076 logp->firstFree = 0;
2077 op = (char *)&(logp->datap[0]);
2079 logp->logElements++;
2085 /* if we've used this word at all, allocate it */
2086 if (++(logp->firstFree) >= logp->logSize) {
2087 logp->firstFree = 0;
2089 logp->logElements++;
2093 /* add a long to the log, ignoring overflow (checked already) */
2094 #define ICL_APPENDINT32(lp, x) \
2096 (lp)->datap[(lp)->firstFree] = (x); \
2097 if (++((lp)->firstFree) >= (lp)->logSize) { \
2098 (lp)->firstFree = 0; \
2100 (lp)->logElements++; \
2103 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
2104 #define ICL_APPENDLONG(lp, x) \
2106 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
2107 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
2110 #else /* AFS_ALPHA_ENV */
2111 #define ICL_APPENDLONG(lp, x) ICL_APPENDINT32((lp), (x))
2112 #endif /* AFS_ALPHA_ENV */
2114 /* routine to tell whether we're dealing with the address or the
2118 afs_icl_UseAddr(int type)
2120 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
2121 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
2127 /* Function to append a record to the log. Written for speed
2128 * since we know that we're going to have to make this work fast
2129 * pretty soon, anyway. The log must be unlocked.
2133 afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
2134 afs_int32 types, long p1, long p2, long p3, long p4)
2136 int rsize; /* record size in longs */
2137 register int tsize; /* temp size */
2141 t4 = types & 0x3f; /* decode types */
2149 osi_GetTime(&tv); /* It panics for solaris if inside */
2150 ObtainWriteLock(&logp->lock, 182);
2152 ReleaseWriteLock(&logp->lock);
2156 /* get timestamp as # of microseconds since some time that doesn't
2157 * change that often. This algorithm ticks over every 20 minutes
2158 * or so (1000 seconds). Write a timestamp record if it has.
2160 if (tv.tv_sec - logp->lastTS > 1024) {
2161 /* the timer has wrapped -- write a timestamp record */
2162 if (logp->logSize - logp->logElements <= 5)
2163 afs_icl_GetLogSpace(logp, 5);
2165 ICL_APPENDINT32(logp,
2166 (afs_int32) (5 << 24) + (ICL_TYPE_UNIXDATE << 18));
2167 ICL_APPENDINT32(logp, (afs_int32) ICL_INFO_TIMESTAMP);
2168 ICL_APPENDINT32(logp, (afs_int32) 0); /* use thread ID zero for clocks */
2169 ICL_APPENDINT32(logp,
2170 (afs_int32) (tv.tv_sec & 0x3ff) * 1000000 +
2172 ICL_APPENDINT32(logp, (afs_int32) tv.tv_sec);
2174 logp->lastTS = tv.tv_sec;
2177 rsize = 4; /* base case */
2179 /* compute size of parameter p1. Only tricky case is string.
2180 * In that case, we have to call strlen to get the string length.
2182 ICL_SIZEHACK(t1, p1);
2185 /* compute size of parameter p2. Only tricky case is string.
2186 * In that case, we have to call strlen to get the string length.
2188 ICL_SIZEHACK(t2, p2);
2191 /* compute size of parameter p3. Only tricky case is string.
2192 * In that case, we have to call strlen to get the string length.
2194 ICL_SIZEHACK(t3, p3);
2197 /* compute size of parameter p4. Only tricky case is string.
2198 * In that case, we have to call strlen to get the string length.
2200 ICL_SIZEHACK(t4, p4);
2203 /* At this point, we've computed all of the parameter sizes, and
2204 * have in rsize the size of the entire record we want to append.
2205 * Next, we check that we actually have room in the log to do this
2206 * work, and then we do the append.
2209 ReleaseWriteLock(&logp->lock);
2210 return; /* log record too big to express */
2213 if (logp->logSize - logp->logElements <= rsize)
2214 afs_icl_GetLogSpace(logp, rsize);
2216 ICL_APPENDINT32(logp,
2217 (afs_int32) (rsize << 24) + (t1 << 18) + (t2 << 12) +
2219 ICL_APPENDINT32(logp, (afs_int32) op);
2220 ICL_APPENDINT32(logp, (afs_int32) osi_ThreadUnique());
2221 ICL_APPENDINT32(logp,
2222 (afs_int32) (tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
2225 /* marshall parameter 1 now */
2226 if (t1 == ICL_TYPE_STRING) {
2227 afs_icl_AppendString(logp, (char *)p1);
2228 } else if (t1 == ICL_TYPE_HYPER) {
2229 ICL_APPENDINT32(logp,
2230 (afs_int32) ((struct afs_hyper_t *)p1)->high);
2231 ICL_APPENDINT32(logp,
2232 (afs_int32) ((struct afs_hyper_t *)p1)->low);
2233 } else if (t1 == ICL_TYPE_INT64) {
2234 #ifdef AFSLITTLE_ENDIAN
2235 #ifdef AFS_64BIT_CLIENT
2236 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
2237 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
2238 #else /* AFS_64BIT_CLIENT */
2239 ICL_APPENDINT32(logp, (afs_int32) p1);
2240 ICL_APPENDINT32(logp, (afs_int32) 0);
2241 #endif /* AFS_64BIT_CLIENT */
2242 #else /* AFSLITTLE_ENDIAN */
2243 #ifdef AFS_64BIT_CLIENT
2244 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
2245 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
2246 #else /* AFS_64BIT_CLIENT */
2247 ICL_APPENDINT32(logp, (afs_int32) 0);
2248 ICL_APPENDINT32(logp, (afs_int32) p1);
2249 #endif /* AFS_64BIT_CLIENT */
2250 #endif /* AFSLITTLE_ENDIAN */
2251 } else if (t1 == ICL_TYPE_FID) {
2252 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
2253 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
2254 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[2]);
2255 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[3]);
2257 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
2258 else if (t1 == ICL_TYPE_INT32)
2259 ICL_APPENDINT32(logp, (afs_int32) p1);
2260 #endif /* AFS_ALPHA_ENV */
2262 ICL_APPENDLONG(logp, p1);
2265 /* marshall parameter 2 now */
2266 if (t2 == ICL_TYPE_STRING)
2267 afs_icl_AppendString(logp, (char *)p2);
2268 else if (t2 == ICL_TYPE_HYPER) {
2269 ICL_APPENDINT32(logp,
2270 (afs_int32) ((struct afs_hyper_t *)p2)->high);
2271 ICL_APPENDINT32(logp,
2272 (afs_int32) ((struct afs_hyper_t *)p2)->low);
2273 } else if (t2 == ICL_TYPE_INT64) {
2274 #ifdef AFSLITTLE_ENDIAN
2275 #ifdef AFS_64BIT_CLIENT
2276 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
2277 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
2278 #else /* AFS_64BIT_CLIENT */
2279 ICL_APPENDINT32(logp, (afs_int32) p2);
2280 ICL_APPENDINT32(logp, (afs_int32) 0);
2281 #endif /* AFS_64BIT_CLIENT */
2282 #else /* AFSLITTLE_ENDIAN */
2283 #ifdef AFS_64BIT_CLIENT
2284 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
2285 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
2286 #else /* AFS_64BIT_CLIENT */
2287 ICL_APPENDINT32(logp, (afs_int32) 0);
2288 ICL_APPENDINT32(logp, (afs_int32) p2);
2289 #endif /* AFS_64BIT_CLIENT */
2290 #endif /* AFSLITTLE_ENDIAN */
2291 } else if (t2 == ICL_TYPE_FID) {
2292 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
2293 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
2294 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[2]);
2295 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[3]);
2297 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
2298 else if (t2 == ICL_TYPE_INT32)
2299 ICL_APPENDINT32(logp, (afs_int32) p2);
2300 #endif /* AFS_ALPHA_ENV */
2302 ICL_APPENDLONG(logp, p2);
2305 /* marshall parameter 3 now */
2306 if (t3 == ICL_TYPE_STRING)
2307 afs_icl_AppendString(logp, (char *)p3);
2308 else if (t3 == ICL_TYPE_HYPER) {
2309 ICL_APPENDINT32(logp,
2310 (afs_int32) ((struct afs_hyper_t *)p3)->high);
2311 ICL_APPENDINT32(logp,
2312 (afs_int32) ((struct afs_hyper_t *)p3)->low);
2313 } else if (t3 == ICL_TYPE_INT64) {
2314 #ifdef AFSLITTLE_ENDIAN
2315 #ifdef AFS_64BIT_CLIENT
2316 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
2317 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
2318 #else /* AFS_64BIT_CLIENT */
2319 ICL_APPENDINT32(logp, (afs_int32) p3);
2320 ICL_APPENDINT32(logp, (afs_int32) 0);
2321 #endif /* AFS_64BIT_CLIENT */
2322 #else /* AFSLITTLE_ENDIAN */
2323 #ifdef AFS_64BIT_CLIENT
2324 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
2325 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
2326 #else /* AFS_64BIT_CLIENT */
2327 ICL_APPENDINT32(logp, (afs_int32) 0);
2328 ICL_APPENDINT32(logp, (afs_int32) p3);
2329 #endif /* AFS_64BIT_CLIENT */
2330 #endif /* AFSLITTLE_ENDIAN */
2331 } else if (t3 == ICL_TYPE_FID) {
2332 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
2333 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
2334 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[2]);
2335 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[3]);
2337 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
2338 else if (t3 == ICL_TYPE_INT32)
2339 ICL_APPENDINT32(logp, (afs_int32) p3);
2340 #endif /* AFS_ALPHA_ENV */
2342 ICL_APPENDLONG(logp, p3);
2345 /* marshall parameter 4 now */
2346 if (t4 == ICL_TYPE_STRING)
2347 afs_icl_AppendString(logp, (char *)p4);
2348 else if (t4 == ICL_TYPE_HYPER) {
2349 ICL_APPENDINT32(logp,
2350 (afs_int32) ((struct afs_hyper_t *)p4)->high);
2351 ICL_APPENDINT32(logp,
2352 (afs_int32) ((struct afs_hyper_t *)p4)->low);
2353 } else if (t4 == ICL_TYPE_INT64) {
2354 #ifdef AFSLITTLE_ENDIAN
2355 #ifdef AFS_64BIT_CLIENT
2356 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
2357 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
2358 #else /* AFS_64BIT_CLIENT */
2359 ICL_APPENDINT32(logp, (afs_int32) p4);
2360 ICL_APPENDINT32(logp, (afs_int32) 0);
2361 #endif /* AFS_64BIT_CLIENT */
2362 #else /* AFSLITTLE_ENDIAN */
2363 #ifdef AFS_64BIT_CLIENT
2364 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
2365 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
2366 #else /* AFS_64BIT_CLIENT */
2367 ICL_APPENDINT32(logp, (afs_int32) 0);
2368 ICL_APPENDINT32(logp, (afs_int32) p4);
2369 #endif /* AFS_64BIT_CLIENT */
2370 #endif /* AFSLITTLE_ENDIAN */
2371 } else if (t4 == ICL_TYPE_FID) {
2372 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
2373 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
2374 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[2]);
2375 ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[3]);
2377 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
2378 else if (t4 == ICL_TYPE_INT32)
2379 ICL_APPENDINT32(logp, (afs_int32) p4);
2380 #endif /* AFS_ALPHA_ENV */
2382 ICL_APPENDLONG(logp, p4);
2384 ReleaseWriteLock(&logp->lock);
2387 /* create a log with size logSize; return it in *outLogpp and tag
2388 * it with name "name."
2391 afs_icl_CreateLog(char *name, afs_int32 logSize,
2392 struct afs_icl_log **outLogpp)
2394 return afs_icl_CreateLogWithFlags(name, logSize, /*flags */ 0, outLogpp);
2397 /* create a log with size logSize; return it in *outLogpp and tag
2398 * it with name "name." 'flags' can be set to make the log unclearable.
2401 afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, afs_uint32 flags,
2402 struct afs_icl_log **outLogpp)
2404 register struct afs_icl_log *logp;
2406 /* add into global list under lock */
2407 ObtainWriteLock(&afs_icl_lock, 183);
2408 if (!afs_icl_inited)
2411 for (logp = afs_icl_allLogs; logp; logp = logp->nextp) {
2412 if (strcmp(logp->name, name) == 0) {
2413 /* found it already created, just return it */
2416 if (flags & ICL_CRLOG_FLAG_PERSISTENT) {
2417 ObtainWriteLock(&logp->lock, 184);
2418 logp->states |= ICL_LOGF_PERSISTENT;
2419 ReleaseWriteLock(&logp->lock);
2421 ReleaseWriteLock(&afs_icl_lock);
2426 logp = (struct afs_icl_log *)
2427 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
2428 memset((caddr_t) logp, 0, sizeof(*logp));
2431 logp->name = osi_AllocSmallSpace(strlen(name) + 1);
2432 strcpy(logp->name, name);
2433 LOCK_INIT(&logp->lock, "logp lock");
2434 logp->logSize = logSize;
2435 logp->datap = NULL; /* don't allocate it until we need it */
2437 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2438 logp->states |= ICL_LOGF_PERSISTENT;
2440 logp->nextp = afs_icl_allLogs;
2441 afs_icl_allLogs = logp;
2442 ReleaseWriteLock(&afs_icl_lock);
2448 /* called with a log, a pointer to a buffer, the size of the buffer
2449 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
2450 * and returns data in the provided buffer, and returns output flags
2451 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
2452 * find the record with cookie value cookie.
2455 afs_icl_CopyOut(register struct afs_icl_log *logp, afs_int32 * bufferp,
2456 afs_int32 * bufSizep, afs_uint32 * cookiep,
2459 afs_int32 nwords; /* number of words to copy out */
2460 afs_uint32 startCookie; /* first cookie to use */
2461 afs_int32 outWords; /* words we've copied out */
2462 afs_int32 inWords; /* max words to copy out */
2463 afs_int32 code; /* return code */
2464 afs_int32 ix; /* index we're copying from */
2465 afs_int32 outFlags; /* return flags */
2466 afs_int32 inFlags; /* flags passed in */
2469 inWords = *bufSizep; /* max to copy out */
2470 outWords = 0; /* amount copied out */
2471 startCookie = *cookiep;
2476 ObtainWriteLock(&logp->lock, 185);
2478 ReleaseWriteLock(&logp->lock);
2482 /* first, compute the index of the start cookie we've been passed */
2484 /* (re-)compute where we should start */
2485 if (startCookie < logp->baseCookie) {
2486 if (startCookie) /* missed some output */
2487 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2488 /* skip to the first available record */
2489 startCookie = logp->baseCookie;
2490 *cookiep = startCookie;
2493 /* compute where we find the first element to copy out */
2494 ix = logp->firstUsed + startCookie - logp->baseCookie;
2495 if (ix >= logp->logSize)
2496 ix -= logp->logSize;
2498 /* if have some data now, break out and process it */
2499 if (startCookie - logp->baseCookie < logp->logElements)
2502 /* At end of log, so clear it if we need to */
2503 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD) {
2504 logp->firstUsed = logp->firstFree = 0;
2505 logp->logElements = 0;
2507 /* otherwise, either wait for the data to arrive, or return */
2508 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2509 ReleaseWriteLock(&logp->lock);
2513 logp->states |= ICL_LOGF_WAITING;
2514 ReleaseWriteLock(&logp->lock);
2515 afs_osi_Sleep(&logp->lock);
2516 ObtainWriteLock(&logp->lock, 186);
2518 /* copy out data from ix to logSize or firstFree, depending
2519 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2520 * be careful not to copy out more than nwords.
2522 if (ix >= logp->firstUsed) {
2523 if (logp->firstUsed <= logp->firstFree)
2525 end = logp->firstFree; /* first element not to copy */
2527 end = logp->logSize;
2528 nwords = inWords; /* don't copy more than this */
2529 if (end - ix < nwords)
2532 memcpy((char *)bufferp, (char *)&logp->datap[ix],
2533 sizeof(afs_int32) * nwords);
2538 /* if we're going to copy more out below, we'll start here */
2541 /* now, if active part of the log has wrapped, there's more stuff
2542 * starting at the head of the log. Copy out more from there.
2544 if (logp->firstUsed > logp->firstFree && ix < logp->firstFree
2546 /* (more to) copy out from the wrapped section at the
2547 * start of the log. May get here even if didn't copy any
2548 * above, if the cookie points directly into the wrapped section.
2551 if (logp->firstFree - ix < nwords)
2552 nwords = logp->firstFree - ix;
2553 memcpy((char *)bufferp, (char *)&logp->datap[ix],
2554 sizeof(afs_int32) * nwords);
2560 ReleaseWriteLock(&logp->lock);
2564 *bufSizep = outWords;
2570 /* return basic parameter information about a log */
2572 afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 * maxSizep,
2573 afs_int32 * curSizep)
2575 ObtainReadLock(&logp->lock);
2576 *maxSizep = logp->logSize;
2577 *curSizep = logp->logElements;
2578 ReleaseReadLock(&logp->lock);
2583 /* hold and release logs */
2585 afs_icl_LogHold(register struct afs_icl_log *logp)
2587 ObtainWriteLock(&afs_icl_lock, 187);
2589 ReleaseWriteLock(&afs_icl_lock);
2593 /* hold and release logs, called with lock already held */
2595 afs_icl_LogHoldNL(register struct afs_icl_log *logp)
2601 /* keep track of how many sets believe the log itself is allocated */
2603 afs_icl_LogUse(register struct afs_icl_log *logp)
2605 ObtainWriteLock(&logp->lock, 188);
2606 if (logp->setCount == 0) {
2607 /* this is the first set actually using the log -- allocate it */
2608 if (logp->logSize == 0) {
2609 /* we weren't passed in a hint and it wasn't set */
2610 logp->logSize = ICL_DEFAULT_LOGSIZE;
2613 (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2614 #ifdef KERNEL_HAVE_PIN
2615 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2619 ReleaseWriteLock(&logp->lock);
2623 /* decrement the number of real users of the log, free if possible */
2625 afs_icl_LogFreeUse(register struct afs_icl_log *logp)
2627 ObtainWriteLock(&logp->lock, 189);
2628 if (--logp->setCount == 0) {
2629 /* no more users -- free it (but keep log structure around) */
2630 #ifdef KERNEL_HAVE_PIN
2631 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2633 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2634 logp->firstUsed = logp->firstFree = 0;
2635 logp->logElements = 0;
2638 ReleaseWriteLock(&logp->lock);
2642 /* set the size of the log to 'logSize' */
2644 afs_icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
2646 ObtainWriteLock(&logp->lock, 190);
2648 /* nothing to worry about since it's not allocated */
2649 logp->logSize = logSize;
2652 logp->firstUsed = logp->firstFree = 0;
2653 logp->logElements = 0;
2655 /* free and allocate a new one */
2656 #ifdef KERNEL_HAVE_PIN
2657 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2659 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2661 (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2662 #ifdef KERNEL_HAVE_PIN
2663 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2665 logp->logSize = logSize;
2667 ReleaseWriteLock(&logp->lock);
2672 /* free a log. Called with afs_icl_lock locked. */
2674 afs_icl_ZapLog(register struct afs_icl_log *logp)
2676 register struct afs_icl_log **lpp, *tp;
2678 for (lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2680 /* found the dude we want to remove */
2682 osi_FreeSmallSpace(logp->name);
2683 #ifdef KERNEL_HAVE_PIN
2684 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2686 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2687 osi_FreeSmallSpace(logp);
2688 break; /* won't find it twice */
2694 /* do the release, watching for deleted entries */
2696 afs_icl_LogRele(register struct afs_icl_log *logp)
2698 ObtainWriteLock(&afs_icl_lock, 191);
2699 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2700 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2702 ReleaseWriteLock(&afs_icl_lock);
2706 /* do the release, watching for deleted entries, log already held */
2708 afs_icl_LogReleNL(register struct afs_icl_log *logp)
2710 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2711 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2716 /* zero out the log */
2718 afs_icl_ZeroLog(register struct afs_icl_log *logp)
2720 ObtainWriteLock(&logp->lock, 192);
2721 logp->firstUsed = logp->firstFree = 0;
2722 logp->logElements = 0;
2723 logp->baseCookie = 0;
2724 ReleaseWriteLock(&logp->lock);
2728 /* free a log entry, and drop its reference count */
2730 afs_icl_LogFree(register struct afs_icl_log *logp)
2732 ObtainWriteLock(&logp->lock, 193);
2733 logp->states |= ICL_LOGF_DELETED;
2734 ReleaseWriteLock(&logp->lock);
2735 afs_icl_LogRele(logp);
2739 /* find a log by name, returning it held */
2740 struct afs_icl_log *
2741 afs_icl_FindLog(char *name)
2743 register struct afs_icl_log *tp;
2744 ObtainWriteLock(&afs_icl_lock, 194);
2745 for (tp = afs_icl_allLogs; tp; tp = tp->nextp) {
2746 if (strcmp(tp->name, name) == 0) {
2747 /* this is the dude we want */
2752 ReleaseWriteLock(&afs_icl_lock);
2757 afs_icl_EnumerateLogs(int (*aproc)
2758 (char *name, char *arock, struct afs_icl_log * tp),
2761 register struct afs_icl_log *tp;
2762 register afs_int32 code;
2765 ObtainWriteLock(&afs_icl_lock, 195);
2766 for (tp = afs_icl_allLogs; tp; tp = tp->nextp) {
2767 tp->refCount++; /* hold this guy */
2768 ReleaseWriteLock(&afs_icl_lock);
2769 ObtainReadLock(&tp->lock);
2770 code = (*aproc) (tp->name, arock, tp);
2771 ReleaseReadLock(&tp->lock);
2772 ObtainWriteLock(&afs_icl_lock, 196);
2773 if (--tp->refCount == 0)
2778 ReleaseWriteLock(&afs_icl_lock);
2782 struct afs_icl_set *afs_icl_allSets = 0;
2785 afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
2786 struct afs_icl_log *fatalLogp,
2787 struct afs_icl_set **outSetpp)
2789 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2790 /*flags */ 0, outSetpp);
2793 /* create a set, given pointers to base and fatal logs, if any.
2794 * Logs are unlocked, but referenced, and *outSetpp is returned
2795 * referenced. Function bumps reference count on logs, since it
2796 * addds references from the new afs_icl_set. When the set is destroyed,
2797 * those references will be released.
2800 afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
2801 struct afs_icl_log *fatalLogp, afs_uint32 flags,
2802 struct afs_icl_set **outSetpp)
2804 register struct afs_icl_set *setp;
2806 afs_int32 states = ICL_DEFAULT_SET_STATES;
2808 ObtainWriteLock(&afs_icl_lock, 197);
2809 if (!afs_icl_inited)
2812 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2813 if (strcmp(setp->name, name) == 0) {
2816 if (flags & ICL_CRSET_FLAG_PERSISTENT) {
2817 ObtainWriteLock(&setp->lock, 198);
2818 setp->states |= ICL_SETF_PERSISTENT;
2819 ReleaseWriteLock(&setp->lock);
2821 ReleaseWriteLock(&afs_icl_lock);
2826 /* determine initial state */
2827 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2828 states = ICL_SETF_ACTIVE;
2829 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2830 states = ICL_SETF_FREED;
2831 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2832 states |= ICL_SETF_PERSISTENT;
2834 setp = (struct afs_icl_set *)afs_osi_Alloc(sizeof(struct afs_icl_set));
2835 memset((caddr_t) setp, 0, sizeof(*setp));
2837 if (states & ICL_SETF_FREED)
2838 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2839 setp->states = states;
2841 LOCK_INIT(&setp->lock, "setp lock");
2842 /* next lock is obtained in wrong order, hierarchy-wise, but
2843 * it doesn't matter, since no one can find this lock yet, since
2844 * the afs_icl_lock is still held, and thus the obtain can't block.
2846 ObtainWriteLock(&setp->lock, 199);
2847 setp->name = osi_AllocSmallSpace(strlen(name) + 1);
2848 strcpy(setp->name, name);
2849 setp->nevents = ICL_DEFAULTEVENTS;
2850 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2851 #ifdef KERNEL_HAVE_PIN
2852 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2854 for (i = 0; i < ICL_DEFAULTEVENTS; i++)
2855 setp->eventFlags[i] = 0xff; /* default to enabled */
2857 /* update this global info under the afs_icl_lock */
2858 setp->nextp = afs_icl_allSets;
2859 afs_icl_allSets = setp;
2860 ReleaseWriteLock(&afs_icl_lock);
2862 /* set's basic lock is still held, so we can finish init */
2864 setp->logs[0] = baseLogp;
2865 afs_icl_LogHold(baseLogp);
2866 if (!(setp->states & ICL_SETF_FREED))
2867 afs_icl_LogUse(baseLogp); /* log is actually being used */
2870 setp->logs[1] = fatalLogp;
2871 afs_icl_LogHold(fatalLogp);
2872 if (!(setp->states & ICL_SETF_FREED))
2873 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2875 ReleaseWriteLock(&setp->lock);
2881 /* function to change event enabling information for a particular set */
2883 afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
2887 ObtainWriteLock(&setp->lock, 200);
2888 if (!ICL_EVENTOK(setp, eventID)) {
2889 ReleaseWriteLock(&setp->lock);
2892 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2894 *tp |= ICL_EVENTMASK(eventID);
2896 *tp &= ~(ICL_EVENTMASK(eventID));
2897 ReleaseWriteLock(&setp->lock);
2901 /* return indication of whether a particular event ID is enabled
2902 * for tracing. If *getValuep is set to 0, the event is disabled,
2903 * otherwise it is enabled. All events start out enabled by default.
2906 afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID, int *getValuep)
2908 ObtainReadLock(&setp->lock);
2909 if (!ICL_EVENTOK(setp, eventID)) {
2910 ReleaseWriteLock(&setp->lock);
2913 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2917 ReleaseReadLock(&setp->lock);
2921 /* hold and release event sets */
2923 afs_icl_SetHold(register struct afs_icl_set *setp)
2925 ObtainWriteLock(&afs_icl_lock, 201);
2927 ReleaseWriteLock(&afs_icl_lock);
2931 /* free a set. Called with afs_icl_lock locked */
2933 afs_icl_ZapSet(register struct afs_icl_set *setp)
2935 register struct afs_icl_set **lpp, *tp;
2937 register struct afs_icl_log *tlp;
2939 for (lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2941 /* found the dude we want to remove */
2943 osi_FreeSmallSpace(setp->name);
2944 #ifdef KERNEL_HAVE_PIN
2945 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2947 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2948 for (i = 0; i < ICL_LOGSPERSET; i++) {
2949 if ((tlp = setp->logs[i]))
2950 afs_icl_LogReleNL(tlp);
2952 osi_FreeSmallSpace(setp);
2953 break; /* won't find it twice */
2959 /* do the release, watching for deleted entries */
2961 afs_icl_SetRele(register struct afs_icl_set *setp)
2963 ObtainWriteLock(&afs_icl_lock, 202);
2964 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2965 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2967 ReleaseWriteLock(&afs_icl_lock);
2971 /* free a set entry, dropping its reference count */
2973 afs_icl_SetFree(register struct afs_icl_set *setp)
2975 ObtainWriteLock(&setp->lock, 203);
2976 setp->states |= ICL_SETF_DELETED;
2977 ReleaseWriteLock(&setp->lock);
2978 afs_icl_SetRele(setp);
2982 /* find a set by name, returning it held */
2983 struct afs_icl_set *
2984 afs_icl_FindSet(char *name)
2986 register struct afs_icl_set *tp;
2987 ObtainWriteLock(&afs_icl_lock, 204);
2988 for (tp = afs_icl_allSets; tp; tp = tp->nextp) {
2989 if (strcmp(tp->name, name) == 0) {
2990 /* this is the dude we want */
2995 ReleaseWriteLock(&afs_icl_lock);
2999 /* zero out all the logs in the set */
3001 afs_icl_ZeroSet(struct afs_icl_set *setp)
3006 struct afs_icl_log *logp;
3008 ObtainReadLock(&setp->lock);
3009 for (i = 0; i < ICL_LOGSPERSET; i++) {
3010 logp = setp->logs[i];
3012 afs_icl_LogHold(logp);
3013 tcode = afs_icl_ZeroLog(logp);
3015 code = tcode; /* save the last bad one */
3016 afs_icl_LogRele(logp);
3019 ReleaseReadLock(&setp->lock);
3024 afs_icl_EnumerateSets(int (*aproc)
3025 (char *name, char *arock, struct afs_icl_log * tp),
3028 register struct afs_icl_set *tp, *np;
3029 register afs_int32 code;
3032 ObtainWriteLock(&afs_icl_lock, 205);
3033 for (tp = afs_icl_allSets; tp; tp = np) {
3034 tp->refCount++; /* hold this guy */
3035 ReleaseWriteLock(&afs_icl_lock);
3036 code = (*aproc) (tp->name, arock, (struct afs_icl_log *)tp);
3037 ObtainWriteLock(&afs_icl_lock, 206);
3038 np = tp->nextp; /* tp may disappear next, but not np */
3039 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
3044 ReleaseWriteLock(&afs_icl_lock);
3049 afs_icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
3054 ObtainWriteLock(&setp->lock, 207);
3055 for (i = 0; i < ICL_LOGSPERSET; i++) {
3056 if (!setp->logs[i]) {
3057 setp->logs[i] = newlogp;
3059 afs_icl_LogHold(newlogp);
3060 if (!(setp->states & ICL_SETF_FREED)) {
3061 /* bump up the number of sets using the log */
3062 afs_icl_LogUse(newlogp);
3067 ReleaseWriteLock(&setp->lock);
3072 afs_icl_SetSetStat(struct afs_icl_set *setp, int op)
3076 struct afs_icl_log *logp;
3078 ObtainWriteLock(&setp->lock, 208);
3080 case ICL_OP_SS_ACTIVATE: /* activate a log */
3082 * If we are not already active, see if we have released
3083 * our demand that the log be allocated (FREED set). If
3084 * we have, reassert our desire.
3086 if (!(setp->states & ICL_SETF_ACTIVE)) {
3087 if (setp->states & ICL_SETF_FREED) {
3088 /* have to reassert desire for logs */
3089 for (i = 0; i < ICL_LOGSPERSET; i++) {
3090 logp = setp->logs[i];
3092 afs_icl_LogHold(logp);
3093 afs_icl_LogUse(logp);
3094 afs_icl_LogRele(logp);
3097 setp->states &= ~ICL_SETF_FREED;
3099 setp->states |= ICL_SETF_ACTIVE;
3104 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
3105 /* this doesn't require anything beyond clearing the ACTIVE flag */
3106 setp->states &= ~ICL_SETF_ACTIVE;
3110 case ICL_OP_SS_FREE: /* deassert design for log */
3112 * if we are already in this state, do nothing; otherwise
3113 * deassert desire for log
3115 if (setp->states & ICL_SETF_ACTIVE)
3118 if (!(setp->states & ICL_SETF_FREED)) {
3119 for (i = 0; i < ICL_LOGSPERSET; i++) {
3120 logp = setp->logs[i];
3122 afs_icl_LogHold(logp);
3123 afs_icl_LogFreeUse(logp);
3124 afs_icl_LogRele(logp);
3127 setp->states |= ICL_SETF_FREED;
3136 ReleaseWriteLock(&setp->lock);