2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "afs/param.h"
15 #include "afs/sysincludes.h" /* Standard vendor system headers */
16 #include "afsincludes.h" /* Afs-based standard headers */
17 #include "afs/afs_stats.h"
18 #include "rx/rx_globals.h"
19 #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
22 #include "h/hashing.h"
24 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN60_ENV)
25 #include "netinet/in_var.h"
27 #endif /* !defined(UKERNEL) */
28 #ifdef AFS_LINUX22_ENV
29 #include "h/smp_lock.h"
33 #if defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
34 #define AFS_MINBUFFERS 100
36 #define AFS_MINBUFFERS 50
40 afs_int32 hosts[MAXCELLHOSTS];
44 char afs_zeros[AFS_ZEROS];
45 char afs_rootVolumeName[64]="";
46 struct afs_icl_set *afs_iclSetp = (struct afs_icl_set*)0;
47 struct afs_icl_set *afs_iclLongTermSetp = (struct afs_icl_set*)0;
49 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
50 kmutex_t afs_global_lock;
51 kmutex_t afs_rxglobal_lock;
54 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
55 long afs_global_owner;
58 #if defined(AFS_OSF_ENV)
59 simple_lock_data_t afs_global_lock;
62 #if defined(AFS_DARWIN_ENV)
63 struct lock__bsd__ afs_global_lock;
66 #if defined(AFS_XBSD_ENV)
67 struct lock afs_global_lock;
68 struct proc *afs_global_owner;
71 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
72 thread_t afs_global_owner;
73 #endif /* AFS_OSF_ENV */
75 #if defined(AFS_AIX41_ENV)
76 simple_lock_data afs_global_lock;
79 afs_int32 afs_initState = 0;
80 afs_int32 afs_termState = 0;
81 afs_int32 afs_setTime = 0;
82 int afs_cold_shutdown = 0;
83 char afs_SynchronousCloses = '\0';
84 static int afs_CB_Running = 0;
85 static int AFS_Running = 0;
86 static int afs_CacheInit_Done = 0;
87 static int afs_Go_Done = 0;
88 extern struct interfaceAddr afs_cb_interface;
89 static int afs_RX_Running = 0;
90 static int afs_InitSetup_done = 0;
92 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
93 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
96 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval);
98 #if defined(AFS_HPUX_ENV)
99 extern int afs_vfs_mount();
100 #endif /* defined(AFS_HPUX_ENV) */
102 /* This is code which needs to be called once when the first daemon enters
103 * the client. A non-zero return means an error and AFS should not start.
105 static int afs_InitSetup(int preallocs)
107 extern void afs_InitStats();
110 if (afs_InitSetup_done)
115 * Set up all the AFS statistics variables. This should be done
116 * exactly once, and it should be done here, the first resource-setting
117 * routine to be called by the CM/RX.
120 #endif /* AFS_NOSTATS */
122 memset(afs_zeros, 0, AFS_ZEROS);
125 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
126 code = rx_Init(htons(7001));
128 printf("AFS: RX failed to initialize.\n");
131 rx_SetRxDeadTime(afs_rx_deadtime);
132 /* resource init creates the services */
133 afs_ResourceInit(preallocs);
135 afs_InitSetup_done = 1;
136 afs_osi_Wakeup(&afs_InitSetup_done);
141 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)
142 struct afsd_thread_info {
144 struct completion *complete;
147 static int afsd_thread(void *rock) {
148 struct afsd_thread_info *arg=rock;
149 unsigned long parm=arg->parm;
150 #ifdef SYS_SETPRIORITY_EXPORTED
151 int (*sys_setpriority)(int,int,int) = sys_call_table[__NR_setpriority];
153 daemonize(); /* doesn't do much, since we were forked from keventd, but
154 does call mm_release, which wakes up our parent (since it
156 afs_osi_MaskSignals();
158 case AFSOP_START_RXCALLBACK:
159 sprintf(current->comm, "afs_cbstart");
161 complete(arg->complete);
163 while (afs_RX_Running != 2)
164 afs_osi_Sleep(&afs_RX_Running);
165 sprintf(current->comm, "afs_callback");
166 afs_RXCallBackServer();
168 complete_and_exit(0,0);
170 case AFSOP_START_AFS:
171 sprintf(current->comm, "afs_afsstart");
173 complete(arg->complete);
175 while (afs_initState < AFSOP_START_AFS)
176 afs_osi_Sleep(&afs_initState);
177 afs_initState = AFSOP_START_BKG;
178 afs_osi_Wakeup(&afs_initState);
179 sprintf(current->comm, "afsd");
182 complete_and_exit(0,0);
184 case AFSOP_START_BKG:
185 sprintf(current->comm, "afs_bkgstart");
187 complete(arg->complete);
188 while (afs_initState < AFSOP_START_BKG)
189 afs_osi_Sleep(&afs_initState);
190 if (afs_initState < AFSOP_GO) {
191 afs_initState = AFSOP_GO;
192 afs_osi_Wakeup(&afs_initState);
194 sprintf(current->comm, "afs_background");
195 afs_BackgroundDaemon();
197 complete_and_exit(0,0);
199 case AFSOP_START_TRUNCDAEMON:
200 sprintf(current->comm, "afs_trimstart");
202 complete(arg->complete);
203 while (afs_initState < AFSOP_GO)
204 afs_osi_Sleep(&afs_initState);
205 sprintf(current->comm, "afs_cachetrim");
206 afs_CacheTruncateDaemon();
208 complete_and_exit(0,0);
211 sprintf(current->comm, "afs_checkserver");
213 complete(arg->complete);
214 afs_CheckServerDaemon();
216 complete_and_exit(0,0);
218 case AFSOP_RXEVENT_DAEMON:
219 sprintf(current->comm, "afs_evtstart");
220 #ifdef SYS_SETPRIORITY_EXPORTED
221 sys_setpriority(PRIO_PROCESS,0,-10);
223 #ifdef CURRENT_INCLUDES_NICE
228 complete(arg->complete);
229 while (afs_initState < AFSOP_START_BKG)
230 afs_osi_Sleep(&afs_initState);
231 sprintf(current->comm, "afs_rxevent");
232 afs_rxevent_daemon();
234 complete_and_exit(0,0);
236 case AFSOP_RXLISTENER_DAEMON:
237 sprintf(current->comm, "afs_lsnstart");
238 #ifdef SYS_SETPRIORITY_EXPORTED
239 sys_setpriority(PRIO_PROCESS,0,-10);
241 #ifdef CURRENT_INCLUDES_NICE
246 complete(arg->complete);
247 afs_initState = AFSOP_START_AFS;
248 afs_osi_Wakeup(&afs_initState);
250 afs_osi_Wakeup(&afs_RX_Running);
251 afs_osi_RxkRegister();
252 sprintf(current->comm, "afs_rxlistener");
255 complete_and_exit(0,0);
258 printf("Unknown op %d in StartDaemon()\n");
264 void afsd_launcher(void *rock) {
265 if (!kernel_thread(afsd_thread,rock, CLONE_VFORK|SIGCHLD))
266 printf("kernel_thread failed. afs startup will not complete\n");
269 void afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
273 DECLARE_COMPLETION(c);
275 struct afsd_thread_info info;
276 if (parm == AFSOP_START_RXCALLBACK) {
277 if (afs_CB_Running) return;
278 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
279 if (afs_RX_Running) return;
281 code = afs_InitSetup(parm2);
283 rx_enablePeerRPCStats();
286 rx_enableProcessRPCStats();
290 } else if (parm == AFSOP_START_AFS) {
291 if (AFS_Running) return;
292 } /* other functions don't need setup in the parent */
296 INIT_LIST_HEAD(&tq.list);
297 tq.routine=afsd_launcher;
301 /* we need to wait cause we passed stack pointers around.... */
302 wait_for_completion(&c);
307 /* leaving as is, probably will barf if we add prototypes here since it's likely being called
310 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
311 long parm, parm2, parm3, parm4, parm5, parm6;
314 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
316 #else /* AFS_SGI61_ENV */
318 #endif /* AFS_SGI61_ENV */
320 AFS_STATCNT(afs_syscall_call);
322 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
323 && (parm != AFSOP_GETMASK)) {
324 /* only root can run this code */
327 if (!afs_suser() && (parm != AFSOP_GETMTU)
328 && (parm != AFSOP_GETMASK)) {
329 /* only root can run this code */
330 #if defined(KERNEL_HAVE_UERROR)
334 #if defined(AFS_OSF_ENV)
336 #else /* AFS_OSF_ENV */
338 #endif /* AFS_OSF_ENV */
343 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS) && !defined(UKERNEL)
344 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
345 || parm == AFSOP_RXLISTENER_DAEMON) {
346 afs_DaemonOp(parm,parm2,parm3,parm4,parm5,parm6);
348 #else /* !(AFS_LINUX24_ENV && !UKERNEL) */
349 if (parm == AFSOP_START_RXCALLBACK) {
350 if (afs_CB_Running) goto out;
352 #ifndef RXK_LISTENER_ENV
353 code = afs_InitSetup(parm2);
355 #endif /* !RXK_LISTENER_ENV */
357 #ifdef RXK_LISTENER_ENV
358 while (afs_RX_Running != 2)
359 afs_osi_Sleep(&afs_RX_Running);
360 #else /* !RXK_LISTENER_ENV */
361 afs_initState = AFSOP_START_AFS;
362 afs_osi_Wakeup(&afs_initState);
363 #endif /* RXK_LISTENER_ENV */
365 afs_RXCallBackServer();
369 exit(CLD_EXITED, code);
370 #endif /* AFS_SGI_ENV */
372 #ifdef RXK_LISTENER_ENV
373 else if (parm == AFSOP_RXLISTENER_DAEMON) {
374 if (afs_RX_Running) goto out;
376 code = afs_InitSetup(parm2);
378 rx_enablePeerRPCStats();
381 rx_enableProcessRPCStats();
384 afs_initState = AFSOP_START_AFS;
385 afs_osi_Wakeup(&afs_initState);
388 afs_osi_Wakeup(&afs_RX_Running);
390 afs_osi_RxkRegister();
391 #endif /* !UKERNEL */
396 exit(CLD_EXITED, code);
397 #endif /* AFS_SGI_ENV */
399 #endif /* RXK_LISTENER_ENV */
400 else if (parm == AFSOP_START_AFS) {
402 if (AFS_Running) goto out;
404 while (afs_initState < AFSOP_START_AFS)
405 afs_osi_Sleep(&afs_initState);
407 afs_initState = AFSOP_START_BKG;
408 afs_osi_Wakeup(&afs_initState);
414 #endif /* AFS_SGI_ENV */
416 else if (parm == AFSOP_START_CS) {
418 afs_CheckServerDaemon();
422 #endif /* AFS_SGI_ENV */
424 else if (parm == AFSOP_START_BKG) {
425 while (afs_initState < AFSOP_START_BKG)
426 afs_osi_Sleep(&afs_initState);
427 if (afs_initState < AFSOP_GO) {
428 afs_initState = AFSOP_GO;
429 afs_osi_Wakeup(&afs_initState);
431 /* start the bkg daemon */
435 afs_BioDaemon(parm2);
437 #endif /* AFS_AIX32_ENV */
438 afs_BackgroundDaemon();
442 #endif /* AFS_SGI_ENV */
444 else if (parm == AFSOP_START_TRUNCDAEMON) {
445 while (afs_initState < AFSOP_GO)
446 afs_osi_Sleep(&afs_initState);
447 /* start the bkg daemon */
449 afs_CacheTruncateDaemon();
453 #endif /* AFS_SGI_ENV */
455 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
456 else if (parm == AFSOP_RXEVENT_DAEMON) {
457 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
459 afs_rxevent_daemon();
463 #endif /* AFS_SGI_ENV */
465 #endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
466 #endif /* AFS_LINUX24_ENV && !UKERNEL */
467 else if (parm == AFSOP_BASIC_INIT) {
470 while (!afs_InitSetup_done)
471 afs_osi_Sleep(&afs_InitSetup_done);
473 #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)
474 temp = AFS_MINBUFFERS; /* Should fix this soon */
476 /* number of 2k buffers we could get from all of the buffer space */
477 temp = ((afs_bufferpages * NBPG)>>11);
478 temp = temp>>2; /* don't take more than 25% (our magic parameter) */
479 if (temp < AFS_MINBUFFERS)
480 temp = AFS_MINBUFFERS; /* though we really should have this many */
483 afs_rootFid.Fid.Volume = 0;
486 else if (parm == AFSOP_ADDCELL) {
487 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
488 name. Parameter 4 is the length of the name, including the null. Parm 5 is the
489 home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
490 struct afsop_cell tcell;
492 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
494 if (parm4 > sizeof(tcell.cellName))
497 AFS_COPYIN((char *)parm3, tcell.cellName, parm4, code);
499 afs_NewCell(tcell.cellName, tcell.hosts, parm5,
503 } else if (parm == AFSOP_ADDCELL2) {
504 struct afsop_cell tcell;
505 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
506 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
509 /* wait for basic init */
510 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
512 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
514 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, &bufferSize, code);
517 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
520 cflags |= CLinkedCell;
524 code = afs_NewCell(tbuffer1, tcell.hosts, cflags,
528 osi_FreeSmallSpace(tbuffer);
529 osi_FreeSmallSpace(tbuffer1);
531 else if (parm == AFSOP_ADDCELLALIAS) {
534 * parm2 is the alias name
535 * parm3 is the real cell name
537 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
538 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
540 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize, code);
541 if (!code) AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ, &bufferSize, code);
542 if (!code) afs_NewCellAlias(aliasName, cellName);
543 osi_FreeSmallSpace(aliasName);
544 osi_FreeSmallSpace(cellName);
546 else if (parm == AFSOP_SET_THISCELL) {
549 * parm2 is the primary cell name
551 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
553 AFS_COPYINSTR((char *) parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code);
555 afs_SetPrimaryCell(cell);
556 osi_FreeSmallSpace(cell);
558 else if (parm == AFSOP_CACHEINIT) {
559 struct afs_cacheParams cparms;
561 if (afs_CacheInit_Done) goto out;
563 AFS_COPYIN((char *)parm2, (caddr_t) &cparms, sizeof(cparms), code);
565 #if defined(KERNEL_HAVE_UERROR)
571 afs_CacheInit_Done = 1;
573 struct afs_icl_log *logp;
574 /* initialize the ICL system */
575 code = afs_icl_CreateLog("cmfx", 60*1024, &logp);
577 code = afs_icl_CreateSetWithFlags("cm", logp,
578 (struct icl_log *) 0,
579 ICL_CRSET_FLAG_DEFAULT_OFF,
581 code = afs_icl_CreateSet("cmlongterm", logp, (struct icl_log*) 0,
582 &afs_iclLongTermSetp);
584 afs_setTime = cparms.setTimeFlag;
586 code = afs_CacheInit(cparms.cacheScaches,
597 else if (parm == AFSOP_CACHEINODE) {
598 ino_t ainode = parm2;
599 /* wait for basic init */
600 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
604 ainode = (ainode << 32) | (parm3 & 0xffffffff);
606 code = afs_InitCacheFile(NULL, ainode);
608 else if (parm == AFSOP_ROOTVOLUME) {
609 /* wait for basic init */
610 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
613 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code);
614 afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0;
618 else if (parm == AFSOP_CACHEFILE ||
619 parm == AFSOP_CACHEINFO ||
620 parm == AFSOP_VOLUMEINFO ||
621 parm == AFSOP_AFSLOG ||
622 parm == AFSOP_CELLINFO) {
623 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
626 AFS_COPYINSTR((char *) parm2, tbuffer, AFS_SMALLOCSIZ,
629 osi_FreeSmallSpace(tbuffer);
633 tbuffer[AFS_SMALLOCSIZ-1] = '\0'; /* null-terminate the name */
634 /* We have the cache dir copied in. Call the cache init routine */
635 if (parm == AFSOP_CACHEFILE)
636 code = afs_InitCacheFile(tbuffer, 0);
637 else if (parm == AFSOP_CACHEINFO)
638 code = afs_InitCacheInfo(tbuffer);
639 else if (parm == AFSOP_VOLUMEINFO)
640 code = afs_InitVolumeInfo(tbuffer);
641 else if (parm == AFSOP_CELLINFO)
642 code = afs_InitCellInfo(tbuffer);
644 osi_FreeSmallSpace(tbuffer);
646 else if (parm == AFSOP_GO) {
647 /* the generic initialization calls come here. One parameter: should we do the
648 set-time operation on this workstation */
649 if (afs_Go_Done) goto out;
651 while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState);
654 afs_osi_Wakeup(&afs_initState);
655 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
656 afs_nfsclient_init();
658 printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused,
659 (100*afs_stats_cmperf.cacheFilesReused) /
660 (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1));
662 else if (parm == AFSOP_ADVISEADDR) {
663 /* pass in the host address to the rx package */
664 afs_int32 count = parm2;
665 afs_int32 buffer[AFS_MAX_INTERFACE_ADDR];
666 afs_int32 maskbuffer[AFS_MAX_INTERFACE_ADDR];
667 afs_int32 mtubuffer[AFS_MAX_INTERFACE_ADDR];
671 if ( count > AFS_MAX_INTERFACE_ADDR ) {
673 count = AFS_MAX_INTERFACE_ADDR;
676 AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code);
678 AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code);
680 AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code);
682 afs_cb_interface.numberOfInterfaces = count;
683 for (i=0; i < count ; i++) {
684 afs_cb_interface.addr_in[i] = buffer[i];
685 #ifdef AFS_USERSPACE_IP_ADDR
686 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
687 * machines IP addresses when in the kernel (the in_ifaddr
688 * struct is not available), so we pass the info in at
689 * startup. We also pass in the subnetmask and mtu size. The
690 * subnetmask is used when setting the rank:
691 * afsi_SetServerIPRank(); and the mtu size is used when
692 * finding the best mtu size. rxi_FindIfnet() is replaced
693 * with rxi_Findcbi().
695 afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff);
696 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
699 afs_uuid_create(&afs_cb_interface.uuid);
700 rxi_setaddr(buffer[0]);
704 else if (parm == AFSOP_NFSSTATICADDR) {
705 extern int (*nfs_rfsdisptab_v2)();
706 nfs_rfsdisptab_v2 = (int (*)())parm2;
708 else if (parm == AFSOP_NFSSTATICADDR2) {
709 extern int (*nfs_rfsdisptab_v2)();
711 nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
713 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
716 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
717 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
718 extern int (*afs_sblockp)();
719 extern void (*afs_sbunlockp)();
721 afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
722 afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff));
724 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
725 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
728 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
729 #endif /* AFS_SGI53_ENV */
730 else if (parm == AFSOP_SHUTDOWN) {
731 afs_cold_shutdown = 0;
732 if (parm == 1) afs_cold_shutdown = 1;
733 if (afs_globalVFS != 0) {
734 afs_warn("AFS isn't unmounted yet! Call aborted\n");
739 else if (parm == AFSOP_AFS_VFSMOUNT) {
741 vfsmount(parm2, parm3, parm4, parm5);
742 #else /* defined(AFS_HPUX_ENV) */
743 #if defined(KERNEL_HAVE_UERROR)
748 #endif /* defined(AFS_HPUX_ENV) */
750 else if (parm == AFSOP_CLOSEWAIT) {
751 afs_SynchronousCloses = 'S';
753 else if (parm == AFSOP_GETMTU) {
755 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
756 #ifdef AFS_USERSPACE_IP_ADDR
758 i = rxi_Findcbi(parm2);
759 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
760 #else /* AFS_USERSPACE_IP_ADDR */
763 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
764 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
765 #endif /* else AFS_USERSPACE_IP_ADDR */
766 #endif /* !AFS_SUN5_ENV */
768 AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code);
770 /* this is disabled for now because I can't figure out how to get access
771 * to these kernel variables. It's only for supporting user-mode rx
772 * programs -- it makes a huge difference on the 220's in my testbed,
773 * though I don't know why. The bosserver does this with /etc/no, so it's
774 * being handled a different way for the servers right now. */
777 extern u_long sb_max_dflt;
780 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
781 if (sb_max < 131072) sb_max = 131072;
784 #endif /* AFS_AIX32_ENV */
786 else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
788 #if !defined(AFS_SUN5_ENV)
789 #ifdef AFS_USERSPACE_IP_ADDR
791 i = rxi_Findcbi(parm2);
793 mask = afs_cb_interface.subnetmask[i];
797 #else /* AFS_USERSPACE_IP_ADDR */
800 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
803 #endif /* else AFS_USERSPACE_IP_ADDR */
804 #endif /* !AFS_SUN5_ENV */
806 AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code);
809 else if (parm == AFSOP_AFSDB_HANDLER) {
810 int sizeArg = (int)parm4;
811 int kmsgLen = sizeArg & 0xffff;
812 int cellLen = (sizeArg & 0xffff0000) >> 16;
813 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
814 char *cellname = afs_osi_Alloc(cellLen);
817 afs_osi_MaskSignals();
819 AFS_COPYIN((afs_int32 *)parm2, cellname, cellLen, code);
820 AFS_COPYIN((afs_int32 *)parm3, kmsg, kmsgLen, code);
822 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
823 if (*cellname == 1) *cellname = 0;
824 if (code == -2) { /* Shutting down? */
829 if (!code) AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
830 afs_osi_Free(kmsg, kmsgLen);
831 afs_osi_Free(cellname, cellLen);
834 else if (parm == AFSOP_SET_DYNROOT) {
835 code = afs_SetDynrootEnable(parm2);
837 else if (parm == AFSOP_SET_FAKESTAT) {
838 afs_fakestat_enable = parm2;
846 #ifdef AFS_LINUX20_ENV
855 #include "sys/lockl.h"
858 * syscall - this is the VRMIX system call entry point.
861 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
862 * all the user-level calls to `syscall' to change.
864 syscall(syscall, p1, p2, p3, p4, p5, p6) {
865 register rval1=0, code;
868 #ifndef AFS_AIX41_ENV
869 extern lock_t kernel_lock;
870 monster = lockl(&kernel_lock, LOCK_SHORT);
871 #endif /* !AFS_AIX41_ENV */
873 AFS_STATCNT(syscall);
877 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
882 rval1 = afs_setpag();
888 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
892 case AFSCALL_ICREATE:
893 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
897 rval1 = afs_syscall_iopen(p1, p2, p3);
901 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
905 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
910 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
912 if (!code) rval1 = retval;
913 if (!rval1) rval1 = code;
923 #ifndef AFS_AIX41_ENV
924 if (monster != LOCK_NEST)
925 unlockl(&kernel_lock);
926 #endif /* !AFS_AIX41_ENV */
927 return getuerror() ? -1 : rval1;
931 * lsetpag - interface to afs_setpag().
935 AFS_STATCNT(lsetpag);
936 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
940 * lpioctl - interface to pioctl()
942 lpioctl(path, cmd, cmarg, follow)
943 char *path, *cmarg; {
945 AFS_STATCNT(lpioctl);
946 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
949 #else /* !AFS_AIX32_ENV */
951 #if defined(AFS_SGI_ENV)
964 Afs_syscall (struct afsargs *uap, rval_t *rvp)
969 AFS_STATCNT(afs_syscall);
970 switch(uap->syscall) {
974 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
976 rvp->r_val1 = retval;
978 #ifdef AFS_SGI_XFS_IOPS_ENV
980 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
981 uap->parm4, uap->parm5);
984 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
985 uap->parm4, uap->parm5);
987 case AFSCALL_ILISTINODE64:
988 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
989 uap->parm4, uap->parm5);
991 case AFSCALL_ICREATENAME64:
992 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
993 uap->parm4, uap->parm5);
996 #ifdef AFS_SGI_VNODE_GLUE
997 case AFSCALL_INIT_KERNEL_CONFIG:
998 error = afs_init_kernel_config(uap->parm1);
1002 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
1003 uap->parm3, uap->parm4, uap->parm5);
1008 #else /* AFS_SGI_ENV */
1026 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
1028 dst->param1 = src->param1;
1029 dst->param2 = src->param2;
1030 dst->param3 = src->param3;
1031 dst->param4 = src->param4;
1035 * If you need to change copyin_iparam(), you may also need to change
1036 * copyin_afs_ioctl().
1040 copyin_iparam(caddr_t cmarg, struct iparam *dst)
1044 #if defined(AFS_HPUX_64BIT_ENV)
1045 struct iparam32 dst32;
1047 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
1049 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
1051 iparam32_to_iparam(&dst32, dst);
1054 #endif /* AFS_HPUX_64BIT_ENV */
1056 #if defined(AFS_SUN57_64BIT_ENV)
1057 struct iparam32 dst32;
1059 if (get_udatamodel() == DATAMODEL_ILP32) {
1060 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
1062 iparam32_to_iparam(&dst32, dst);
1065 #endif /* AFS_SUN57_64BIT_ENV */
1067 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
1068 struct iparam32 dst32;
1070 #ifdef AFS_SPARC64_LINUX24_ENV
1071 if (current->thread.flags & SPARC_FLAG_32BIT)
1072 #elif AFS_SPARC64_LINUX20_ENV
1073 if (current->tss.flags & SPARC_FLAG_32BIT)
1075 #error Not done for this linux version
1076 #endif /* AFS_SPARC64_LINUX20_ENV */
1078 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
1080 iparam32_to_iparam(&dst32, dst);
1083 #endif /* AFS_LINUX_64BIT_KERNEL */
1085 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
1089 /* Main entry of all afs system calls */
1091 extern int afs_sinited;
1093 /** The 32 bit OS expects the members of this structure to be 32 bit
1094 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
1095 * to accomodate both, *long* is used instead of afs_int32
1098 #ifdef AFS_SUN57_ENV
1120 Afs_syscall(register struct afssysa *uap, rval_t *rvp)
1122 int *retval = &rvp->r_val1;
1123 #else /* AFS_SUN5_ENV */
1124 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1126 afs3_syscall(p, args, retval)
1139 } *uap = (struct a *)args;
1140 #else /* AFS_OSF_ENV */
1141 #ifdef AFS_LINUX20_ENV
1149 long parm6; /* not actually used - should be removed */
1151 /* Linux system calls only set up for 5 arguments. */
1152 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
1155 struct afssysargs args, *uap = &args;
1157 long *retval = &linux_ret;
1158 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
1159 #ifdef AFS_SPARC64_LINUX24_ENV
1160 afs_int32 eparm32[4];
1162 /* eparm is also used by AFSCALL_CALL in afsd.c */
1164 #if defined(UKERNEL)
1175 } *uap = (struct a *)u.u_ap;
1178 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
1182 #endif /* SUN && !SUN5 */
1192 } *uap = (struct a *)u.u_ap;
1193 #endif /* UKERNEL */
1194 #if defined(AFS_DEC_ENV)
1195 int *retval = &u.u_r.r_val1;
1196 #elif defined(AFS_HPUX_ENV)
1197 long *retval = &u.u_rval1;
1199 int *retval = &u.u_rval1;
1201 #endif /* AFS_LINUX20_ENV */
1202 #endif /* AFS_OSF_ENV */
1203 #endif /* AFS_SUN5_ENV */
1204 register int code = 0;
1206 AFS_STATCNT(afs_syscall);
1213 #ifdef AFS_LINUX20_ENV
1215 /* setup uap for use below - pull out the magic decoder ring to know
1216 * which syscalls have folded argument lists.
1218 uap->syscall = syscall;
1222 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
1223 #ifdef AFS_SPARC64_LINUX24_ENV
1224 /* from arch/sparc64/kernel/sys_sparc32.c */
1226 ({ unsigned long __ret; \
1227 __asm__ ("srl %0, 0, %0" \
1234 if (current->thread.flags & SPARC_FLAG_32BIT) {
1235 AFS_COPYIN((char*)parm4, (char*)eparm32, sizeof(eparm32), code);
1236 eparm[0]=AA(eparm32[0]);
1237 eparm[1]=AA(eparm32[1]);
1238 eparm[2]=AA(eparm32[2]);
1242 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
1243 uap->parm4 = eparm[0];
1244 uap->parm5 = eparm[1];
1245 uap->parm6 = eparm[2];
1254 #if defined(AFS_HPUX_ENV)
1256 * There used to be code here (duplicated from osi_Init()) for
1257 * initializing the semaphore used by AFS_GLOCK(). Was the
1258 * duplication to handle the case of a dynamically loaded kernel
1263 if (uap->syscall == AFSCALL_CALL) {
1265 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1266 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1268 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1270 } else if (uap->syscall == AFSCALL_SETPAG) {
1272 register proc_t *procp;
1274 procp = ttoproc(curthread);
1276 code = afs_setpag(&procp->p_cred);
1280 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1281 code = afs_setpag(p, args, retval);
1282 #else /* AFS_OSF_ENV */
1283 code = afs_setpag();
1287 } else if (uap->syscall == AFSCALL_PIOCTL) {
1290 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1292 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1293 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1295 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1299 } else if (uap->syscall == AFSCALL_ICREATE) {
1300 struct iparam iparams;
1302 code = copyin_iparam((char *)uap->parm3, &iparams);
1304 #if defined(KERNEL_HAVE_UERROR)
1309 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1310 iparams.param3, iparams.param4, rvp, CRED());
1312 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1313 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1314 iparams.param3, iparams.param4, retval);
1316 iparams.param3, iparams.param4);
1318 #endif /* AFS_SUN5_ENV */
1319 } else if (uap->syscall == AFSCALL_IOPEN) {
1321 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1323 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1324 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1326 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1328 #endif /* AFS_SUN5_ENV */
1329 } else if (uap->syscall == AFSCALL_IDEC) {
1331 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1333 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1334 #endif /* AFS_SUN5_ENV */
1335 } else if (uap->syscall == AFSCALL_IINC) {
1337 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1339 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1340 #endif /* AFS_SUN5_ENV */
1341 } else if (uap->syscall == AFSCALL_ICL) {
1343 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1345 #ifdef AFS_LINUX20_ENV
1347 /* ICL commands can return values. */
1348 code = -linux_ret; /* Gets negated again at exit below */
1352 #if defined(KERNEL_HAVE_UERROR)
1356 #endif /* !AFS_LINUX20_ENV */
1358 #if defined(KERNEL_HAVE_UERROR)
1365 #ifdef AFS_LINUX20_ENV
1371 #endif /* AFS_SGI_ENV */
1372 #endif /* !AFS_AIX32_ENV */
1375 * Initstate in the range 0 < x < 100 are early initialization states.
1376 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1377 * the cache may be initialized.
1378 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1379 * is done after all the cache initialization has been done.
1380 * Initstate of 200 means that the volume has been looked up once, possibly
1382 * Initstate of 300 means that the volume has been *successfully* looked up.
1384 int afs_CheckInit(void)
1386 register int code = 0;
1388 AFS_STATCNT(afs_CheckInit);
1389 if (afs_initState <= 100)
1390 code = ENXIO; /* never finished init phase */
1391 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1392 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1393 } else if (afs_initState == 200)
1394 code = ETIMEDOUT; /* didn't find root volume */
1398 int afs_shuttingdown = 0;
1399 void afs_shutdown(void)
1401 extern short afs_brsDaemons;
1402 extern afs_int32 afs_CheckServerDaemonStarted;
1403 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1404 extern struct osi_file *afs_cacheInodep;
1406 AFS_STATCNT(afs_shutdown);
1407 if (afs_shuttingdown) return;
1408 afs_shuttingdown = 1;
1409 if (afs_cold_shutdown) afs_warn("COLD ");
1410 else afs_warn("WARM ");
1411 afs_warn("shutting down of: CB... ");
1413 afs_termState = AFSOP_STOP_RXCALLBACK;
1414 rx_WakeupServerProcs();
1415 /* shutdown_rxkernel(); */
1416 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1417 afs_osi_Sleep(&afs_termState);
1419 afs_warn("afs... ");
1420 while (afs_termState == AFSOP_STOP_AFS) {
1421 afs_osi_CancelWait(&AFS_WaitHandler);
1422 afs_osi_Sleep(&afs_termState);
1424 if (afs_CheckServerDaemonStarted) {
1425 while (afs_termState == AFSOP_STOP_CS) {
1426 afs_osi_CancelWait(&AFS_CSWaitHandler);
1427 afs_osi_Sleep(&afs_termState);
1430 afs_warn("BkG... ");
1431 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1432 while (afs_termState == AFSOP_STOP_BKG) {
1433 afs_osi_Wakeup(&afs_brsDaemons);
1434 afs_osi_Sleep(&afs_termState);
1436 afs_warn("CTrunc... ");
1437 /* Cancel cache truncate daemon. */
1438 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1439 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1440 afs_osi_Sleep(&afs_termState);
1442 #ifdef AFS_AFSDB_ENV
1443 afs_warn("AFSDB... ");
1445 while (afs_termState == AFSOP_STOP_AFSDB)
1446 afs_osi_Sleep(&afs_termState);
1448 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1449 afs_warn("RxEvent... ");
1450 /* cancel rx event daemon */
1451 while (afs_termState == AFSOP_STOP_RXEVENT)
1452 afs_osi_Sleep(&afs_termState);
1453 #if defined(RXK_LISTENER_ENV)
1455 afs_warn("UnmaskRxkSignals... ");
1456 afs_osi_UnmaskRxkSignals();
1458 /* cancel rx listener */
1459 afs_warn("RxListener... ");
1460 osi_StopListener(); /* This closes rx_socket. */
1461 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1462 afs_warn("Sleep... ");
1463 afs_osi_Sleep(&afs_termState);
1467 afs_termState = AFSOP_STOP_COMPLETE;
1471 /* Close file only after daemons which can write to it are stopped. */
1472 if (afs_cacheInodep) /* memcache won't set this */
1474 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1475 afs_cacheInodep = 0;
1477 return; /* Just kill daemons for now */
1481 shutdown_rxkernel();
1485 shutdown_bufferpackage();
1491 shutdown_vnodeops();
1493 shutdown_exporter();
1494 shutdown_memcache();
1495 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1496 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1497 /* this routine does not exist in Ultrix systems... 93.01.19 */
1499 #endif /* AFS_DEC_ENV */
1502 /* The following hold the cm stats */
1504 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1505 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1506 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1508 afs_warn(" ALL allocated tables\n");
1509 afs_shuttingdown = 0;
1513 void shutdown_afstest(void)
1515 AFS_STATCNT(shutdown_afstest);
1516 afs_initState = afs_termState = afs_setTime = 0;
1517 AFS_Running = afs_CB_Running = 0;
1518 afs_CacheInit_Done = afs_Go_Done = 0;
1519 if (afs_cold_shutdown) {
1520 *afs_rootVolumeName = 0;
1525 /* In case there is a bunch of dynamically build bkg daemons to free */
1526 void afs_shutdown_BKG(void)
1528 AFS_STATCNT(shutdown_BKG);
1532 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1533 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1534 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1535 int afs_icl_sizeofLong = 1;
1537 int afs_icl_sizeofLong = 2;
1540 int afs_icl_sizeofLong = 1;
1543 int afs_icl_inited = 0;
1545 /* init function, called once, under afs_icl_lock */
1546 int afs_icl_Init(void)
1552 extern struct afs_icl_log *afs_icl_FindLog();
1553 extern struct afs_icl_set *afs_icl_FindSet();
1557 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1559 afs_int32 *lp, elts, flags;
1560 register afs_int32 code;
1561 struct afs_icl_log *logp;
1562 struct afs_icl_set *setp;
1563 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1565 #else /* AFS_SGI61_ENV */
1567 #endif /* AFS_SGI61_ENV */
1569 afs_int32 startCookie;
1570 afs_int32 allocated;
1571 struct afs_icl_log *tlp;
1574 if (!afs_suser(CRED())) { /* only root can run this code */
1578 if (!afs_suser()) { /* only root can run this code */
1579 #if defined(KERNEL_HAVE_UERROR)
1588 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1589 case ICL_OP_COPYOUT: /* copy ouy data */
1590 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1591 * return flags<<24 + nwords.
1592 * updates cookie to updated start (not end) if we had to
1593 * skip some records.
1595 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1596 if (code) return code;
1597 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1598 if (code) return code;
1599 logp = afs_icl_FindLog(tname);
1600 if (!logp) return ENOENT;
1601 #define BUFFERSIZE AFS_LRALLOCSIZ
1602 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1603 elts = BUFFERSIZE / sizeof(afs_int32);
1604 if (p3 < elts) elts = p3;
1605 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1606 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1609 osi_FreeLargeSpace((struct osi_buffer *) lp);
1612 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1613 if (code) goto done;
1614 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1615 if (code) goto done;
1616 *retval = (flags<<24) | (elts & 0xffffff);
1618 afs_icl_LogRele(logp);
1619 osi_FreeLargeSpace((struct osi_buffer *) lp);
1622 case ICL_OP_ENUMLOGS: /* enumerate logs */
1623 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1624 * return 0 for success, otherwise error.
1626 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1627 if (p1-- == 0) break;
1629 if (!tlp) return ENOENT; /* past the end of file */
1630 temp = strlen(tlp->name)+1;
1631 if (temp > p3) return EINVAL;
1632 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1633 if (!code) /* copy out size of log */
1634 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1637 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1638 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1639 * return 0 for success, otherwise error.
1641 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1642 if (code) return code;
1643 setp = afs_icl_FindSet(tname);
1644 if (!setp) return ENOENT;
1645 if (p2 > ICL_LOGSPERSET)
1647 if (!(tlp = setp->logs[p2]))
1649 temp = strlen(tlp->name)+1;
1650 if (temp > p4) return EINVAL;
1651 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1654 case ICL_OP_CLRLOG: /* clear specified log */
1655 /* zero out the specified log: p1=logname */
1656 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1657 if (code) return code;
1658 logp = afs_icl_FindLog(tname);
1659 if (!logp) return ENOENT;
1660 code = afs_icl_ZeroLog(logp);
1661 afs_icl_LogRele(logp);
1664 case ICL_OP_CLRSET: /* clear specified set */
1665 /* zero out the specified set: p1=setname */
1666 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1667 if (code) return code;
1668 setp = afs_icl_FindSet(tname);
1669 if (!setp) return ENOENT;
1670 code = afs_icl_ZeroSet(setp);
1671 afs_icl_SetRele(setp);
1674 case ICL_OP_CLRALL: /* clear all logs */
1675 /* zero out all logs -- no args */
1677 ObtainWriteLock(&afs_icl_lock,178);
1678 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1679 tlp->refCount++; /* hold this guy */
1680 ReleaseWriteLock(&afs_icl_lock);
1681 /* don't clear persistent logs */
1682 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1683 code = afs_icl_ZeroLog(tlp);
1684 ObtainWriteLock(&afs_icl_lock,179);
1685 if (--tlp->refCount == 0)
1686 afs_icl_ZapLog(tlp);
1689 ReleaseWriteLock(&afs_icl_lock);
1692 case ICL_OP_ENUMSETS: /* enumerate all sets */
1693 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1694 * return 0 for success, otherwise error.
1696 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1697 if (p1-- == 0) break;
1699 if (!setp) return ENOENT; /* past the end of file */
1700 temp = strlen(setp->name)+1;
1701 if (temp > p3) return EINVAL;
1702 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1703 if (!code) /* copy out size of log */
1704 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1707 case ICL_OP_SETSTAT: /* set status on a set */
1708 /* activate the specified set: p1=setname, p2=op */
1709 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1710 if (code) return code;
1711 setp = afs_icl_FindSet(tname);
1712 if (!setp) return ENOENT;
1713 code = afs_icl_SetSetStat(setp, p2);
1714 afs_icl_SetRele(setp);
1717 case ICL_OP_SETSTATALL: /* set status on all sets */
1718 /* activate the specified set: p1=op */
1720 ObtainWriteLock(&afs_icl_lock,180);
1721 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1722 setp->refCount++; /* hold this guy */
1723 ReleaseWriteLock(&afs_icl_lock);
1724 /* don't set states on persistent sets */
1725 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1726 code = afs_icl_SetSetStat(setp, p1);
1727 ObtainWriteLock(&afs_icl_lock,181);
1728 if (--setp->refCount == 0)
1729 afs_icl_ZapSet(setp);
1732 ReleaseWriteLock(&afs_icl_lock);
1735 case ICL_OP_SETLOGSIZE: /* set size of log */
1736 /* set the size of the specified log: p1=logname, p2=size (in words) */
1737 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1738 if (code) return code;
1739 logp = afs_icl_FindLog(tname);
1740 if (!logp) return ENOENT;
1741 code = afs_icl_LogSetSize(logp, p2);
1742 afs_icl_LogRele(logp);
1745 case ICL_OP_GETLOGINFO: /* get size of log */
1746 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1747 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1748 if (code) return code;
1749 logp = afs_icl_FindLog(tname);
1750 if (!logp) return ENOENT;
1751 allocated = !!logp->datap;
1752 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1754 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1755 afs_icl_LogRele(logp);
1758 case ICL_OP_GETSETINFO: /* get state of set */
1759 /* zero out the specified set: p1=setname, p2=&state */
1760 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1761 if (code) return code;
1762 setp = afs_icl_FindSet(tname);
1763 if (!setp) return ENOENT;
1764 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1765 afs_icl_SetRele(setp);
1776 afs_lock_t afs_icl_lock;
1778 /* exported routine: a 4 parameter event */
1779 int afs_icl_Event4(register struct afs_icl_set *setp, afs_int32 eventID,
1780 afs_int32 lAndT, long p1, long p2, long p3, long p4)
1784 register afs_int32 tmask;
1787 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1788 if (!ICL_SETACTIVE(setp))
1792 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1793 ix = ICL_EVENTBYTE(eventID);
1794 ObtainReadLock(&setp->lock);
1795 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1796 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1798 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1802 if (mask == 0) break; /* break early */
1805 ReleaseReadLock(&setp->lock);
1809 /* Next 4 routines should be implemented via var-args or something.
1810 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1811 * Otherwise, could call afs_icl_Event4 directly.
1813 int afs_icl_Event3(register struct afs_icl_set *setp, afs_int32 eventID,
1814 afs_int32 lAndT, long p1, long p2, long p3)
1816 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1819 int afs_icl_Event2(register struct afs_icl_set *setp, afs_int32 eventID,
1820 afs_int32 lAndT, long p1, long p2)
1822 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1825 int afs_icl_Event1(register struct afs_icl_set *setp, afs_int32 eventID,
1826 afs_int32 lAndT, long p1)
1828 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1831 int afs_icl_Event0(register struct afs_icl_set *setp, afs_int32 eventID,
1834 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1837 struct afs_icl_log *afs_icl_allLogs = 0;
1839 /* function to purge records from the start of the log, until there
1840 * is at least minSpace long's worth of space available without
1841 * making the head and the tail point to the same word.
1843 * Log must be write-locked.
1845 static void afs_icl_GetLogSpace(register struct afs_icl_log *logp, afs_int32 minSpace)
1847 register unsigned int tsize;
1849 while (logp->logSize - logp->logElements <= minSpace) {
1851 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1852 logp->logElements -= tsize;
1853 logp->firstUsed += tsize;
1854 if (logp->firstUsed >= logp->logSize)
1855 logp->firstUsed -= logp->logSize;
1856 logp->baseCookie += tsize;
1860 /* append string astr to buffer, including terminating null char.
1862 * log must be write-locked.
1864 #define ICL_CHARSPERLONG 4
1865 static void afs_icl_AppendString(struct afs_icl_log *logp, char *astr)
1867 char *op; /* ptr to char to write */
1869 register int bib; /* bytes in buffer */
1872 op = (char *) &(logp->datap[logp->firstFree]);
1876 if (++bib >= ICL_CHARSPERLONG) {
1879 if (++(logp->firstFree) >= logp->logSize) {
1880 logp->firstFree = 0;
1881 op = (char *) &(logp->datap[0]);
1883 logp->logElements++;
1888 /* if we've used this word at all, allocate it */
1889 if (++(logp->firstFree) >= logp->logSize) {
1890 logp->firstFree = 0;
1892 logp->logElements++;
1896 /* add a long to the log, ignoring overflow (checked already) */
1897 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1898 #define ICL_APPENDINT32(lp, x) \
1900 (lp)->datap[(lp)->firstFree] = (x); \
1901 if (++((lp)->firstFree) >= (lp)->logSize) { \
1902 (lp)->firstFree = 0; \
1904 (lp)->logElements++; \
1907 #define ICL_APPENDLONG(lp, x) \
1909 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1910 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1913 #else /* AFS_ALPHA_ENV */
1914 #define ICL_APPENDLONG(lp, x) \
1916 (lp)->datap[(lp)->firstFree] = (x); \
1917 if (++((lp)->firstFree) >= (lp)->logSize) { \
1918 (lp)->firstFree = 0; \
1920 (lp)->logElements++; \
1922 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1923 #endif /* AFS_ALPHA_ENV */
1925 /* routine to tell whether we're dealing with the address or the
1928 int afs_icl_UseAddr(int type)
1930 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1931 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
1937 /* Function to append a record to the log. Written for speed
1938 * since we know that we're going to have to make this work fast
1939 * pretty soon, anyway. The log must be unlocked.
1942 void afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
1943 afs_int32 types, long p1, long p2, long p3, long p4)
1945 int rsize; /* record size in longs */
1946 register int tsize; /* temp size */
1950 t4 = types & 0x3f; /* decode types */
1958 osi_GetTime(&tv); /* It panics for solaris if inside */
1959 ObtainWriteLock(&logp->lock,182);
1961 ReleaseWriteLock(&logp->lock);
1965 /* get timestamp as # of microseconds since some time that doesn't
1966 * change that often. This algorithm ticks over every 20 minutes
1967 * or so (1000 seconds). Write a timestamp record if it has.
1969 if (tv.tv_sec - logp->lastTS > 1024)
1971 /* the timer has wrapped -- write a timestamp record */
1972 if (logp->logSize - logp->logElements <= 5)
1973 afs_icl_GetLogSpace(logp, 5);
1975 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1976 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1977 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1978 ICL_APPENDINT32(logp,
1979 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1980 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1982 logp->lastTS = tv.tv_sec;
1985 rsize = 4; /* base case */
1987 /* compute size of parameter p1. Only tricky case is string.
1988 * In that case, we have to call strlen to get the string length.
1990 ICL_SIZEHACK(t1, p1);
1993 /* compute size of parameter p2. Only tricky case is string.
1994 * In that case, we have to call strlen to get the string length.
1996 ICL_SIZEHACK(t2, p2);
1999 /* compute size of parameter p3. Only tricky case is string.
2000 * In that case, we have to call strlen to get the string length.
2002 ICL_SIZEHACK(t3, p3);
2005 /* compute size of parameter p4. Only tricky case is string.
2006 * In that case, we have to call strlen to get the string length.
2008 ICL_SIZEHACK(t4, p4);
2011 /* At this point, we've computed all of the parameter sizes, and
2012 * have in rsize the size of the entire record we want to append.
2013 * Next, we check that we actually have room in the log to do this
2014 * work, and then we do the append.
2017 ReleaseWriteLock(&logp->lock);
2018 return; /* log record too big to express */
2021 if (logp->logSize - logp->logElements <= rsize)
2022 afs_icl_GetLogSpace(logp, rsize);
2024 ICL_APPENDINT32(logp,
2025 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
2026 ICL_APPENDINT32(logp, (afs_int32)op);
2027 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
2028 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
2031 /* marshall parameter 1 now */
2032 if (t1 == ICL_TYPE_STRING) {
2033 afs_icl_AppendString(logp, (char *) p1);
2035 else if (t1 == ICL_TYPE_HYPER) {
2036 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
2037 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
2039 else if (t1 == ICL_TYPE_INT64) {
2040 #ifdef AFSLITTLE_ENDIAN
2041 #ifdef AFS_64BIT_CLIENT
2042 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2043 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2044 #else /* AFS_64BIT_CLIENT */
2045 ICL_APPENDINT32(logp, (afs_int32) p1);
2046 ICL_APPENDINT32(logp, (afs_int32) 0);
2047 #endif /* AFS_64BIT_CLIENT */
2048 #else /* AFSLITTLE_ENDIAN */
2049 #ifdef AFS_64BIT_CLIENT
2050 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2051 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2052 #else /* AFS_64BIT_CLIENT */
2053 ICL_APPENDINT32(logp, (afs_int32) 0);
2054 ICL_APPENDINT32(logp, (afs_int32) p1);
2055 #endif /* AFS_64BIT_CLIENT */
2056 #endif /* AFSLITTLE_ENDIAN */
2058 else if (t1 == ICL_TYPE_FID) {
2059 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2060 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2061 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
2062 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
2064 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2065 else if (t1 == ICL_TYPE_INT32)
2066 ICL_APPENDINT32(logp, (afs_int32)p1);
2067 #endif /* AFS_ALPHA_ENV */
2068 else ICL_APPENDLONG(logp, p1);
2071 /* marshall parameter 2 now */
2072 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
2073 else if (t2 == ICL_TYPE_HYPER) {
2074 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
2075 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
2077 else if (t2 == ICL_TYPE_INT64) {
2078 #ifdef AFSLITTLE_ENDIAN
2079 #ifdef AFS_64BIT_CLIENT
2080 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2081 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2082 #else /* AFS_64BIT_CLIENT */
2083 ICL_APPENDINT32(logp, (afs_int32) p2);
2084 ICL_APPENDINT32(logp, (afs_int32) 0);
2085 #endif /* AFS_64BIT_CLIENT */
2086 #else /* AFSLITTLE_ENDIAN */
2087 #ifdef AFS_64BIT_CLIENT
2088 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2089 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2090 #else /* AFS_64BIT_CLIENT */
2091 ICL_APPENDINT32(logp, (afs_int32) 0);
2092 ICL_APPENDINT32(logp, (afs_int32) p2);
2093 #endif /* AFS_64BIT_CLIENT */
2094 #endif /* AFSLITTLE_ENDIAN */
2096 else if (t2 == ICL_TYPE_FID) {
2097 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2098 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2099 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
2100 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
2102 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2103 else if (t2 == ICL_TYPE_INT32)
2104 ICL_APPENDINT32(logp, (afs_int32)p2);
2105 #endif /* AFS_ALPHA_ENV */
2106 else ICL_APPENDLONG(logp, p2);
2109 /* marshall parameter 3 now */
2110 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
2111 else if (t3 == ICL_TYPE_HYPER) {
2112 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
2113 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
2115 else if (t3 == ICL_TYPE_INT64) {
2116 #ifdef AFSLITTLE_ENDIAN
2117 #ifdef AFS_64BIT_CLIENT
2118 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2119 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2120 #else /* AFS_64BIT_CLIENT */
2121 ICL_APPENDINT32(logp, (afs_int32) p3);
2122 ICL_APPENDINT32(logp, (afs_int32) 0);
2123 #endif /* AFS_64BIT_CLIENT */
2124 #else /* AFSLITTLE_ENDIAN */
2125 #ifdef AFS_64BIT_CLIENT
2126 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2127 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2128 #else /* AFS_64BIT_CLIENT */
2129 ICL_APPENDINT32(logp, (afs_int32) 0);
2130 ICL_APPENDINT32(logp, (afs_int32) p3);
2131 #endif /* AFS_64BIT_CLIENT */
2132 #endif /* AFSLITTLE_ENDIAN */
2134 else if (t3 == ICL_TYPE_FID) {
2135 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2136 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2137 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
2138 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
2140 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2141 else if (t3 == ICL_TYPE_INT32)
2142 ICL_APPENDINT32(logp, (afs_int32)p3);
2143 #endif /* AFS_ALPHA_ENV */
2144 else ICL_APPENDLONG(logp, p3);
2147 /* marshall parameter 4 now */
2148 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
2149 else if (t4 == ICL_TYPE_HYPER) {
2150 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
2151 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
2153 else if (t4 == ICL_TYPE_INT64) {
2154 #ifdef AFSLITTLE_ENDIAN
2155 #ifdef AFS_64BIT_CLIENT
2156 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2157 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2158 #else /* AFS_64BIT_CLIENT */
2159 ICL_APPENDINT32(logp, (afs_int32) p4);
2160 ICL_APPENDINT32(logp, (afs_int32) 0);
2161 #endif /* AFS_64BIT_CLIENT */
2162 #else /* AFSLITTLE_ENDIAN */
2163 #ifdef AFS_64BIT_CLIENT
2164 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2165 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2166 #else /* AFS_64BIT_CLIENT */
2167 ICL_APPENDINT32(logp, (afs_int32) 0);
2168 ICL_APPENDINT32(logp, (afs_int32) p4);
2169 #endif /* AFS_64BIT_CLIENT */
2170 #endif /* AFSLITTLE_ENDIAN */
2172 else if (t4 == ICL_TYPE_FID) {
2173 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2174 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2175 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
2176 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
2178 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2179 else if (t4 == ICL_TYPE_INT32)
2180 ICL_APPENDINT32(logp, (afs_int32)p4);
2181 #endif /* AFS_ALPHA_ENV */
2182 else ICL_APPENDLONG(logp, p4);
2184 ReleaseWriteLock(&logp->lock);
2187 /* create a log with size logSize; return it in *outLogpp and tag
2188 * it with name "name."
2190 int afs_icl_CreateLog(char *name, afs_int32 logSize, struct afs_icl_log **outLogpp)
2192 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
2195 /* create a log with size logSize; return it in *outLogpp and tag
2196 * it with name "name." 'flags' can be set to make the log unclearable.
2198 int afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, afs_uint32 flags,
2199 struct afs_icl_log **outLogpp)
2201 register struct afs_icl_log *logp;
2203 /* add into global list under lock */
2204 ObtainWriteLock(&afs_icl_lock,183);
2205 if (!afs_icl_inited) afs_icl_Init();
2207 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
2208 if (strcmp(logp->name, name) == 0) {
2209 /* found it already created, just return it */
2212 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2214 ObtainWriteLock(&logp->lock,184);
2215 logp->states |= ICL_LOGF_PERSISTENT;
2216 ReleaseWriteLock(&logp->lock);
2218 ReleaseWriteLock(&afs_icl_lock);
2223 logp = (struct afs_icl_log *)
2224 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
2225 memset((caddr_t)logp, 0, sizeof(*logp));
2228 logp->name = osi_AllocSmallSpace(strlen(name)+1);
2229 strcpy(logp->name, name);
2230 LOCK_INIT(&logp->lock, "logp lock");
2231 logp->logSize = logSize;
2232 logp->datap = NULL; /* don't allocate it until we need it */
2234 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2235 logp->states |= ICL_LOGF_PERSISTENT;
2237 logp->nextp = afs_icl_allLogs;
2238 afs_icl_allLogs = logp;
2239 ReleaseWriteLock(&afs_icl_lock);
2245 /* called with a log, a pointer to a buffer, the size of the buffer
2246 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
2247 * and returns data in the provided buffer, and returns output flags
2248 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
2249 * find the record with cookie value cookie.
2251 int afs_icl_CopyOut(register struct afs_icl_log *logp, afs_int32 *bufferp,
2252 afs_int32 *bufSizep, afs_uint32 *cookiep, afs_int32 *flagsp)
2254 afs_int32 nwords; /* number of words to copy out */
2255 afs_uint32 startCookie; /* first cookie to use */
2256 afs_int32 outWords; /* words we've copied out */
2257 afs_int32 inWords; /* max words to copy out */
2258 afs_int32 code; /* return code */
2259 afs_int32 ix; /* index we're copying from */
2260 afs_int32 outFlags; /* return flags */
2261 afs_int32 inFlags; /* flags passed in */
2264 inWords = *bufSizep; /* max to copy out */
2265 outWords = 0; /* amount copied out */
2266 startCookie = *cookiep;
2271 ObtainWriteLock(&logp->lock,185);
2273 ReleaseWriteLock(&logp->lock);
2277 /* first, compute the index of the start cookie we've been passed */
2279 /* (re-)compute where we should start */
2280 if (startCookie < logp->baseCookie) {
2281 if (startCookie) /* missed some output */
2282 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2283 /* skip to the first available record */
2284 startCookie = logp->baseCookie;
2285 *cookiep = startCookie;
2288 /* compute where we find the first element to copy out */
2289 ix = logp->firstUsed + startCookie - logp->baseCookie;
2290 if (ix >= logp->logSize) ix -= logp->logSize;
2292 /* if have some data now, break out and process it */
2293 if (startCookie - logp->baseCookie < logp->logElements) break;
2295 /* At end of log, so clear it if we need to */
2296 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
2298 logp->firstUsed = logp->firstFree = 0;
2299 logp->logElements = 0;
2301 /* otherwise, either wait for the data to arrive, or return */
2302 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2303 ReleaseWriteLock(&logp->lock);
2307 logp->states |= ICL_LOGF_WAITING;
2308 ReleaseWriteLock(&logp->lock);
2309 afs_osi_Sleep(&logp->lock);
2310 ObtainWriteLock(&logp->lock,186);
2312 /* copy out data from ix to logSize or firstFree, depending
2313 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2314 * be careful not to copy out more than nwords.
2316 if (ix >= logp->firstUsed) {
2317 if (logp->firstUsed <= logp->firstFree)
2319 end = logp->firstFree; /* first element not to copy */
2321 end = logp->logSize;
2322 nwords = inWords; /* don't copy more than this */
2323 if (end - ix < nwords)
2326 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2331 /* if we're going to copy more out below, we'll start here */
2334 /* now, if active part of the log has wrapped, there's more stuff
2335 * starting at the head of the log. Copy out more from there.
2337 if (logp->firstUsed > logp->firstFree
2338 && ix < logp->firstFree && inWords > 0) {
2339 /* (more to) copy out from the wrapped section at the
2340 * start of the log. May get here even if didn't copy any
2341 * above, if the cookie points directly into the wrapped section.
2344 if (logp->firstFree - ix < nwords)
2345 nwords = logp->firstFree - ix;
2346 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2352 ReleaseWriteLock(&logp->lock);
2356 *bufSizep = outWords;
2362 /* return basic parameter information about a log */
2363 int afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 *maxSizep,
2364 afs_int32 *curSizep)
2366 ObtainReadLock(&logp->lock);
2367 *maxSizep = logp->logSize;
2368 *curSizep = logp->logElements;
2369 ReleaseReadLock(&logp->lock);
2374 /* hold and release logs */
2375 int afs_icl_LogHold(register struct afs_icl_log *logp)
2377 ObtainWriteLock(&afs_icl_lock,187);
2379 ReleaseWriteLock(&afs_icl_lock);
2383 /* hold and release logs, called with lock already held */
2384 int afs_icl_LogHoldNL(register struct afs_icl_log *logp)
2390 /* keep track of how many sets believe the log itself is allocated */
2391 int afs_icl_LogUse(register struct afs_icl_log *logp)
2393 ObtainWriteLock(&logp->lock,188);
2394 if (logp->setCount == 0) {
2395 /* this is the first set actually using the log -- allocate it */
2396 if (logp->logSize == 0) {
2397 /* we weren't passed in a hint and it wasn't set */
2398 logp->logSize = ICL_DEFAULT_LOGSIZE;
2400 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2401 #ifdef KERNEL_HAVE_PIN
2402 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2406 ReleaseWriteLock(&logp->lock);
2410 /* decrement the number of real users of the log, free if possible */
2411 int afs_icl_LogFreeUse(register struct afs_icl_log *logp)
2413 ObtainWriteLock(&logp->lock,189);
2414 if (--logp->setCount == 0) {
2415 /* no more users -- free it (but keep log structure around)*/
2416 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2417 #ifdef KERNEL_HAVE_PIN
2418 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2420 logp->firstUsed = logp->firstFree = 0;
2421 logp->logElements = 0;
2424 ReleaseWriteLock(&logp->lock);
2428 /* set the size of the log to 'logSize' */
2429 int afs_icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
2431 ObtainWriteLock(&logp->lock,190);
2433 /* nothing to worry about since it's not allocated */
2434 logp->logSize = logSize;
2438 logp->firstUsed = logp->firstFree = 0;
2439 logp->logElements = 0;
2441 /* free and allocate a new one */
2442 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2443 #ifdef KERNEL_HAVE_PIN
2444 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2446 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2447 #ifdef KERNEL_HAVE_PIN
2448 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2450 logp->logSize = logSize;
2452 ReleaseWriteLock(&logp->lock);
2457 /* free a log. Called with afs_icl_lock locked. */
2458 int afs_icl_ZapLog(register struct afs_icl_log *logp)
2460 register struct afs_icl_log **lpp, *tp;
2462 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2464 /* found the dude we want to remove */
2466 osi_FreeSmallSpace(logp->name);
2467 osi_FreeSmallSpace(logp->datap);
2468 osi_FreeSmallSpace(logp);
2469 break; /* won't find it twice */
2475 /* do the release, watching for deleted entries */
2476 int afs_icl_LogRele(register struct afs_icl_log *logp)
2478 ObtainWriteLock(&afs_icl_lock,191);
2479 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2480 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2482 ReleaseWriteLock(&afs_icl_lock);
2486 /* do the release, watching for deleted entries, log already held */
2487 int afs_icl_LogReleNL(register struct afs_icl_log *logp)
2489 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2490 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2495 /* zero out the log */
2496 int afs_icl_ZeroLog(register struct afs_icl_log *logp)
2498 ObtainWriteLock(&logp->lock,192);
2499 logp->firstUsed = logp->firstFree = 0;
2500 logp->logElements = 0;
2501 logp->baseCookie = 0;
2502 ReleaseWriteLock(&logp->lock);
2506 /* free a log entry, and drop its reference count */
2507 int afs_icl_LogFree(register struct afs_icl_log *logp)
2509 ObtainWriteLock(&logp->lock,193);
2510 logp->states |= ICL_LOGF_DELETED;
2511 ReleaseWriteLock(&logp->lock);
2512 afs_icl_LogRele(logp);
2516 /* find a log by name, returning it held */
2517 struct afs_icl_log *afs_icl_FindLog(char *name)
2519 register struct afs_icl_log *tp;
2520 ObtainWriteLock(&afs_icl_lock,194);
2521 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2522 if (strcmp(tp->name, name) == 0) {
2523 /* this is the dude we want */
2528 ReleaseWriteLock(&afs_icl_lock);
2532 int afs_icl_EnumerateLogs(int (*aproc)(), char *arock)
2534 register struct afs_icl_log *tp;
2535 register afs_int32 code;
2538 ObtainWriteLock(&afs_icl_lock,195);
2539 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2540 tp->refCount++; /* hold this guy */
2541 ReleaseWriteLock(&afs_icl_lock);
2542 ObtainReadLock(&tp->lock);
2543 code = (*aproc)(tp->name, arock, tp);
2544 ReleaseReadLock(&tp->lock);
2545 ObtainWriteLock(&afs_icl_lock,196);
2546 if (--tp->refCount == 0)
2550 ReleaseWriteLock(&afs_icl_lock);
2554 struct afs_icl_set *afs_icl_allSets = 0;
2556 int afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
2557 struct afs_icl_log *fatalLogp, struct afs_icl_set **outSetpp)
2559 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2560 /*flags*/0, outSetpp);
2563 /* create a set, given pointers to base and fatal logs, if any.
2564 * Logs are unlocked, but referenced, and *outSetpp is returned
2565 * referenced. Function bumps reference count on logs, since it
2566 * addds references from the new afs_icl_set. When the set is destroyed,
2567 * those references will be released.
2569 int afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
2570 struct afs_icl_log *fatalLogp, afs_uint32 flags, struct afs_icl_set **outSetpp)
2572 register struct afs_icl_set *setp;
2574 afs_int32 states = ICL_DEFAULT_SET_STATES;
2576 ObtainWriteLock(&afs_icl_lock,197);
2577 if (!afs_icl_inited) afs_icl_Init();
2579 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2580 if (strcmp(setp->name, name) == 0) {
2583 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2585 ObtainWriteLock(&setp->lock,198);
2586 setp->states |= ICL_SETF_PERSISTENT;
2587 ReleaseWriteLock(&setp->lock);
2589 ReleaseWriteLock(&afs_icl_lock);
2594 /* determine initial state */
2595 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2596 states = ICL_SETF_ACTIVE;
2597 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2598 states = ICL_SETF_FREED;
2599 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2600 states |= ICL_SETF_PERSISTENT;
2602 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2603 memset((caddr_t)setp, 0, sizeof(*setp));
2605 if (states & ICL_SETF_FREED)
2606 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2607 setp->states = states;
2609 LOCK_INIT(&setp->lock, "setp lock");
2610 /* next lock is obtained in wrong order, hierarchy-wise, but
2611 * it doesn't matter, since no one can find this lock yet, since
2612 * the afs_icl_lock is still held, and thus the obtain can't block.
2614 ObtainWriteLock(&setp->lock,199);
2615 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2616 strcpy(setp->name, name);
2617 setp->nevents = ICL_DEFAULTEVENTS;
2618 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2619 #ifdef KERNEL_HAVE_PIN
2620 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2622 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2623 setp->eventFlags[i] = 0xff; /* default to enabled */
2625 /* update this global info under the afs_icl_lock */
2626 setp->nextp = afs_icl_allSets;
2627 afs_icl_allSets = setp;
2628 ReleaseWriteLock(&afs_icl_lock);
2630 /* set's basic lock is still held, so we can finish init */
2632 setp->logs[0] = baseLogp;
2633 afs_icl_LogHold(baseLogp);
2634 if (!(setp->states & ICL_SETF_FREED))
2635 afs_icl_LogUse(baseLogp); /* log is actually being used */
2638 setp->logs[1] = fatalLogp;
2639 afs_icl_LogHold(fatalLogp);
2640 if (!(setp->states & ICL_SETF_FREED))
2641 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2643 ReleaseWriteLock(&setp->lock);
2649 /* function to change event enabling information for a particular set */
2650 int afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
2654 ObtainWriteLock(&setp->lock,200);
2655 if (!ICL_EVENTOK(setp, eventID)) {
2656 ReleaseWriteLock(&setp->lock);
2659 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2661 *tp |= ICL_EVENTMASK(eventID);
2663 *tp &= ~(ICL_EVENTMASK(eventID));
2664 ReleaseWriteLock(&setp->lock);
2668 /* return indication of whether a particular event ID is enabled
2669 * for tracing. If *getValuep is set to 0, the event is disabled,
2670 * otherwise it is enabled. All events start out enabled by default.
2672 int afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID,
2675 ObtainReadLock(&setp->lock);
2676 if (!ICL_EVENTOK(setp, eventID)) {
2677 ReleaseWriteLock(&setp->lock);
2680 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2684 ReleaseReadLock(&setp->lock);
2688 /* hold and release event sets */
2689 int afs_icl_SetHold(register struct afs_icl_set *setp)
2691 ObtainWriteLock(&afs_icl_lock,201);
2693 ReleaseWriteLock(&afs_icl_lock);
2697 /* free a set. Called with afs_icl_lock locked */
2698 int afs_icl_ZapSet(register struct afs_icl_set *setp)
2700 register struct afs_icl_set **lpp, *tp;
2702 register struct afs_icl_log *tlp;
2704 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2706 /* found the dude we want to remove */
2708 osi_FreeSmallSpace(setp->name);
2709 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2710 #ifdef KERNEL_HAVE_PIN
2711 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2713 for(i=0; i < ICL_LOGSPERSET; i++) {
2714 if ((tlp = setp->logs[i]))
2715 afs_icl_LogReleNL(tlp);
2717 osi_FreeSmallSpace(setp);
2718 break; /* won't find it twice */
2724 /* do the release, watching for deleted entries */
2725 int afs_icl_SetRele(register struct afs_icl_set *setp)
2727 ObtainWriteLock(&afs_icl_lock,202);
2728 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2729 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2731 ReleaseWriteLock(&afs_icl_lock);
2735 /* free a set entry, dropping its reference count */
2736 int afs_icl_SetFree(register struct afs_icl_set *setp)
2738 ObtainWriteLock(&setp->lock,203);
2739 setp->states |= ICL_SETF_DELETED;
2740 ReleaseWriteLock(&setp->lock);
2741 afs_icl_SetRele(setp);
2745 /* find a set by name, returning it held */
2746 struct afs_icl_set *afs_icl_FindSet(char *name)
2748 register struct afs_icl_set *tp;
2749 ObtainWriteLock(&afs_icl_lock,204);
2750 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2751 if (strcmp(tp->name, name) == 0) {
2752 /* this is the dude we want */
2757 ReleaseWriteLock(&afs_icl_lock);
2761 /* zero out all the logs in the set */
2762 int afs_icl_ZeroSet(struct afs_icl_set *setp)
2767 struct afs_icl_log *logp;
2769 ObtainReadLock(&setp->lock);
2770 for(i = 0; i < ICL_LOGSPERSET; i++) {
2771 logp = setp->logs[i];
2773 afs_icl_LogHold(logp);
2774 tcode = afs_icl_ZeroLog(logp);
2775 if (tcode != 0) code = tcode; /* save the last bad one */
2776 afs_icl_LogRele(logp);
2779 ReleaseReadLock(&setp->lock);
2783 int afs_icl_EnumerateSets(int (*aproc)(), char *arock)
2785 register struct afs_icl_set *tp, *np;
2786 register afs_int32 code;
2789 ObtainWriteLock(&afs_icl_lock,205);
2790 for(tp = afs_icl_allSets; tp; tp=np) {
2791 tp->refCount++; /* hold this guy */
2792 ReleaseWriteLock(&afs_icl_lock);
2793 code = (*aproc)(tp->name, arock, tp);
2794 ObtainWriteLock(&afs_icl_lock,206);
2795 np = tp->nextp; /* tp may disappear next, but not np */
2796 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2800 ReleaseWriteLock(&afs_icl_lock);
2804 int afs_icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
2809 ObtainWriteLock(&setp->lock,207);
2810 for(i = 0; i < ICL_LOGSPERSET; i++) {
2811 if (!setp->logs[i]) {
2812 setp->logs[i] = newlogp;
2814 afs_icl_LogHold(newlogp);
2815 if (!(setp->states & ICL_SETF_FREED)) {
2816 /* bump up the number of sets using the log */
2817 afs_icl_LogUse(newlogp);
2822 ReleaseWriteLock(&setp->lock);
2826 int afs_icl_SetSetStat(struct afs_icl_set *setp, int op)
2830 struct afs_icl_log *logp;
2832 ObtainWriteLock(&setp->lock,208);
2834 case ICL_OP_SS_ACTIVATE: /* activate a log */
2836 * If we are not already active, see if we have released
2837 * our demand that the log be allocated (FREED set). If
2838 * we have, reassert our desire.
2840 if (!(setp->states & ICL_SETF_ACTIVE)) {
2841 if (setp->states & ICL_SETF_FREED) {
2842 /* have to reassert desire for logs */
2843 for(i = 0; i < ICL_LOGSPERSET; i++) {
2844 logp = setp->logs[i];
2846 afs_icl_LogHold(logp);
2847 afs_icl_LogUse(logp);
2848 afs_icl_LogRele(logp);
2851 setp->states &= ~ICL_SETF_FREED;
2853 setp->states |= ICL_SETF_ACTIVE;
2858 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2859 /* this doesn't require anything beyond clearing the ACTIVE flag */
2860 setp->states &= ~ICL_SETF_ACTIVE;
2864 case ICL_OP_SS_FREE: /* deassert design for log */
2866 * if we are already in this state, do nothing; otherwise
2867 * deassert desire for log
2869 if (setp->states & ICL_SETF_ACTIVE)
2872 if (!(setp->states & ICL_SETF_FREED)) {
2873 for(i = 0; i < ICL_LOGSPERSET; i++) {
2874 logp = setp->logs[i];
2876 afs_icl_LogHold(logp);
2877 afs_icl_LogFreeUse(logp);
2878 afs_icl_LogRele(logp);
2881 setp->states |= ICL_SETF_FREED;
2890 ReleaseWriteLock(&setp->lock);