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
157 afs_osi_MaskSignals();
159 case AFSOP_START_RXCALLBACK:
160 sprintf(current->comm, "afs_cbstart");
162 complete(arg->complete);
164 while (afs_RX_Running != 2)
165 afs_osi_Sleep(&afs_RX_Running);
166 sprintf(current->comm, "afs_callback");
167 afs_RXCallBackServer();
169 complete_and_exit(0,0);
171 case AFSOP_START_AFS:
172 sprintf(current->comm, "afs_afsstart");
174 complete(arg->complete);
176 while (afs_initState < AFSOP_START_AFS)
177 afs_osi_Sleep(&afs_initState);
178 afs_initState = AFSOP_START_BKG;
179 afs_osi_Wakeup(&afs_initState);
180 sprintf(current->comm, "afsd");
183 complete_and_exit(0,0);
185 case AFSOP_START_BKG:
186 sprintf(current->comm, "afs_bkgstart");
188 complete(arg->complete);
189 while (afs_initState < AFSOP_START_BKG)
190 afs_osi_Sleep(&afs_initState);
191 if (afs_initState < AFSOP_GO) {
192 afs_initState = AFSOP_GO;
193 afs_osi_Wakeup(&afs_initState);
195 sprintf(current->comm, "afs_background");
196 afs_BackgroundDaemon();
198 complete_and_exit(0,0);
200 case AFSOP_START_TRUNCDAEMON:
201 sprintf(current->comm, "afs_trimstart");
203 complete(arg->complete);
204 while (afs_initState < AFSOP_GO)
205 afs_osi_Sleep(&afs_initState);
206 sprintf(current->comm, "afs_cachetrim");
207 afs_CacheTruncateDaemon();
209 complete_and_exit(0,0);
212 sprintf(current->comm, "afs_checkserver");
214 complete(arg->complete);
215 afs_CheckServerDaemon();
217 complete_and_exit(0,0);
219 case AFSOP_RXEVENT_DAEMON:
220 sprintf(current->comm, "afs_evtstart");
221 #ifdef SYS_SETPRIORITY_EXPORTED
222 sys_setpriority(PRIO_PROCESS,0,-10);
224 #ifdef CURRENT_INCLUDES_NICE
229 complete(arg->complete);
230 while (afs_initState < AFSOP_START_BKG)
231 afs_osi_Sleep(&afs_initState);
232 sprintf(current->comm, "afs_rxevent");
233 afs_rxevent_daemon();
235 complete_and_exit(0,0);
237 case AFSOP_RXLISTENER_DAEMON:
238 sprintf(current->comm, "afs_lsnstart");
239 #ifdef SYS_SETPRIORITY_EXPORTED
240 sys_setpriority(PRIO_PROCESS,0,-10);
242 #ifdef CURRENT_INCLUDES_NICE
247 complete(arg->complete);
248 afs_initState = AFSOP_START_AFS;
249 afs_osi_Wakeup(&afs_initState);
251 afs_osi_Wakeup(&afs_RX_Running);
252 afs_osi_RxkRegister();
253 sprintf(current->comm, "afs_rxlistener");
256 complete_and_exit(0,0);
259 printf("Unknown op %d in StartDaemon()\n");
265 void afsd_launcher(void *rock) {
266 if (!kernel_thread(afsd_thread,rock, CLONE_VFORK|SIGCHLD))
267 printf("kernel_thread failed. afs startup will not complete\n");
270 void afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
274 DECLARE_COMPLETION(c);
276 struct afsd_thread_info info;
277 if (parm == AFSOP_START_RXCALLBACK) {
278 if (afs_CB_Running) return;
279 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
280 if (afs_RX_Running) return;
282 code = afs_InitSetup(parm2);
284 rx_enablePeerRPCStats();
287 rx_enableProcessRPCStats();
291 } else if (parm == AFSOP_START_AFS) {
292 if (AFS_Running) return;
293 } /* other functions don't need setup in the parent */
297 INIT_LIST_HEAD(&tq.list);
298 tq.routine=afsd_launcher;
302 /* we need to wait cause we passed stack pointers around.... */
303 wait_for_completion(&c);
308 /* leaving as is, probably will barf if we add prototypes here since it's likely being called
311 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
312 long parm, parm2, parm3, parm4, parm5, parm6;
315 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
317 #else /* AFS_SGI61_ENV */
319 #endif /* AFS_SGI61_ENV */
321 AFS_STATCNT(afs_syscall_call);
323 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
324 && (parm != AFSOP_GETMASK)) {
325 /* only root can run this code */
328 if (!afs_suser() && (parm != AFSOP_GETMTU)
329 && (parm != AFSOP_GETMASK)) {
330 /* only root can run this code */
331 #if defined(KERNEL_HAVE_UERROR)
335 #if defined(AFS_OSF_ENV)
337 #else /* AFS_OSF_ENV */
339 #endif /* AFS_OSF_ENV */
344 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS) && !defined(UKERNEL)
345 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
346 || parm == AFSOP_RXLISTENER_DAEMON) {
347 afs_DaemonOp(parm,parm2,parm3,parm4,parm5,parm6);
349 #else /* !(AFS_LINUX24_ENV && !UKERNEL) */
350 if (parm == AFSOP_START_RXCALLBACK) {
351 if (afs_CB_Running) goto out;
353 #ifndef RXK_LISTENER_ENV
354 code = afs_InitSetup(parm2);
356 #endif /* !RXK_LISTENER_ENV */
358 #ifdef RXK_LISTENER_ENV
359 while (afs_RX_Running != 2)
360 afs_osi_Sleep(&afs_RX_Running);
361 #else /* !RXK_LISTENER_ENV */
362 afs_initState = AFSOP_START_AFS;
363 afs_osi_Wakeup(&afs_initState);
364 #endif /* RXK_LISTENER_ENV */
366 afs_RXCallBackServer();
370 exit(CLD_EXITED, code);
371 #endif /* AFS_SGI_ENV */
373 #ifdef RXK_LISTENER_ENV
374 else if (parm == AFSOP_RXLISTENER_DAEMON) {
375 if (afs_RX_Running) goto out;
377 code = afs_InitSetup(parm2);
379 rx_enablePeerRPCStats();
382 rx_enableProcessRPCStats();
385 afs_initState = AFSOP_START_AFS;
386 afs_osi_Wakeup(&afs_initState);
389 afs_osi_Wakeup(&afs_RX_Running);
391 afs_osi_RxkRegister();
392 #endif /* !UKERNEL */
397 exit(CLD_EXITED, code);
398 #endif /* AFS_SGI_ENV */
400 #endif /* RXK_LISTENER_ENV */
401 else if (parm == AFSOP_START_AFS) {
403 if (AFS_Running) goto out;
405 while (afs_initState < AFSOP_START_AFS)
406 afs_osi_Sleep(&afs_initState);
408 afs_initState = AFSOP_START_BKG;
409 afs_osi_Wakeup(&afs_initState);
415 #endif /* AFS_SGI_ENV */
417 else if (parm == AFSOP_START_CS) {
419 afs_CheckServerDaemon();
423 #endif /* AFS_SGI_ENV */
425 else if (parm == AFSOP_START_BKG) {
426 while (afs_initState < AFSOP_START_BKG)
427 afs_osi_Sleep(&afs_initState);
428 if (afs_initState < AFSOP_GO) {
429 afs_initState = AFSOP_GO;
430 afs_osi_Wakeup(&afs_initState);
432 /* start the bkg daemon */
436 afs_BioDaemon(parm2);
438 #endif /* AFS_AIX32_ENV */
439 afs_BackgroundDaemon();
443 #endif /* AFS_SGI_ENV */
445 else if (parm == AFSOP_START_TRUNCDAEMON) {
446 while (afs_initState < AFSOP_GO)
447 afs_osi_Sleep(&afs_initState);
448 /* start the bkg daemon */
450 afs_CacheTruncateDaemon();
454 #endif /* AFS_SGI_ENV */
456 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
457 else if (parm == AFSOP_RXEVENT_DAEMON) {
458 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
460 afs_rxevent_daemon();
464 #endif /* AFS_SGI_ENV */
466 #endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
467 #endif /* AFS_LINUX24_ENV && !UKERNEL */
468 else if (parm == AFSOP_BASIC_INIT) {
471 while (!afs_InitSetup_done)
472 afs_osi_Sleep(&afs_InitSetup_done);
474 #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)
475 temp = AFS_MINBUFFERS; /* Should fix this soon */
477 /* number of 2k buffers we could get from all of the buffer space */
478 temp = ((afs_bufferpages * NBPG)>>11);
479 temp = temp>>2; /* don't take more than 25% (our magic parameter) */
480 if (temp < AFS_MINBUFFERS)
481 temp = AFS_MINBUFFERS; /* though we really should have this many */
484 afs_rootFid.Fid.Volume = 0;
487 else if (parm == AFSOP_ADDCELL) {
488 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
489 name. Parameter 4 is the length of the name, including the null. Parm 5 is the
490 home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
491 struct afsop_cell tcell;
493 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
495 if (parm4 > sizeof(tcell.cellName))
498 AFS_COPYIN((char *)parm3, tcell.cellName, parm4, code);
500 afs_NewCell(tcell.cellName, tcell.hosts, parm5,
504 } else if (parm == AFSOP_ADDCELL2) {
505 struct afsop_cell tcell;
506 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
507 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
510 /* wait for basic init */
511 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
513 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
515 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, &bufferSize, code);
518 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
521 cflags |= CLinkedCell;
525 code = afs_NewCell(tbuffer1, tcell.hosts, cflags,
529 osi_FreeSmallSpace(tbuffer);
530 osi_FreeSmallSpace(tbuffer1);
532 else if (parm == AFSOP_ADDCELLALIAS) {
535 * parm2 is the alias name
536 * parm3 is the real cell name
538 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
539 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
541 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize, code);
542 if (!code) AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ, &bufferSize, code);
543 if (!code) afs_NewCellAlias(aliasName, cellName);
544 osi_FreeSmallSpace(aliasName);
545 osi_FreeSmallSpace(cellName);
547 else if (parm == AFSOP_SET_THISCELL) {
550 * parm2 is the primary cell name
552 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
554 AFS_COPYINSTR((char *) parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code);
556 afs_SetPrimaryCell(cell);
557 osi_FreeSmallSpace(cell);
559 else if (parm == AFSOP_CACHEINIT) {
560 struct afs_cacheParams cparms;
562 if (afs_CacheInit_Done) goto out;
564 AFS_COPYIN((char *)parm2, (caddr_t) &cparms, sizeof(cparms), code);
566 #if defined(KERNEL_HAVE_UERROR)
572 afs_CacheInit_Done = 1;
574 struct afs_icl_log *logp;
575 /* initialize the ICL system */
576 code = afs_icl_CreateLog("cmfx", 60*1024, &logp);
578 code = afs_icl_CreateSetWithFlags("cm", logp,
579 (struct icl_log *) 0,
580 ICL_CRSET_FLAG_DEFAULT_OFF,
582 code = afs_icl_CreateSet("cmlongterm", logp, (struct icl_log*) 0,
583 &afs_iclLongTermSetp);
585 afs_setTime = cparms.setTimeFlag;
587 code = afs_CacheInit(cparms.cacheScaches,
598 else if (parm == AFSOP_CACHEINODE) {
599 ino_t ainode = parm2;
600 /* wait for basic init */
601 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
605 ainode = (ainode << 32) | (parm3 & 0xffffffff);
607 code = afs_InitCacheFile(NULL, ainode);
609 else if (parm == AFSOP_ROOTVOLUME) {
610 /* wait for basic init */
611 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
614 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code);
615 afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0;
619 else if (parm == AFSOP_CACHEFILE ||
620 parm == AFSOP_CACHEINFO ||
621 parm == AFSOP_VOLUMEINFO ||
622 parm == AFSOP_AFSLOG ||
623 parm == AFSOP_CELLINFO) {
624 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
627 AFS_COPYINSTR((char *) parm2, tbuffer, AFS_SMALLOCSIZ,
630 osi_FreeSmallSpace(tbuffer);
634 tbuffer[AFS_SMALLOCSIZ-1] = '\0'; /* null-terminate the name */
635 /* We have the cache dir copied in. Call the cache init routine */
636 if (parm == AFSOP_CACHEFILE)
637 code = afs_InitCacheFile(tbuffer, 0);
638 else if (parm == AFSOP_CACHEINFO)
639 code = afs_InitCacheInfo(tbuffer);
640 else if (parm == AFSOP_VOLUMEINFO)
641 code = afs_InitVolumeInfo(tbuffer);
642 else if (parm == AFSOP_CELLINFO)
643 code = afs_InitCellInfo(tbuffer);
645 osi_FreeSmallSpace(tbuffer);
647 else if (parm == AFSOP_GO) {
648 /* the generic initialization calls come here. One parameter: should we do the
649 set-time operation on this workstation */
650 if (afs_Go_Done) goto out;
652 while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState);
655 afs_osi_Wakeup(&afs_initState);
656 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
657 afs_nfsclient_init();
659 printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused,
660 (100*afs_stats_cmperf.cacheFilesReused) /
661 (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1));
663 else if (parm == AFSOP_ADVISEADDR) {
664 /* pass in the host address to the rx package */
665 afs_int32 count = parm2;
666 afs_int32 buffer[AFS_MAX_INTERFACE_ADDR];
667 afs_int32 maskbuffer[AFS_MAX_INTERFACE_ADDR];
668 afs_int32 mtubuffer[AFS_MAX_INTERFACE_ADDR];
672 if ( count > AFS_MAX_INTERFACE_ADDR ) {
674 count = AFS_MAX_INTERFACE_ADDR;
677 AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code);
679 AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code);
681 AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code);
683 afs_cb_interface.numberOfInterfaces = count;
684 for (i=0; i < count ; i++) {
685 afs_cb_interface.addr_in[i] = buffer[i];
686 #ifdef AFS_USERSPACE_IP_ADDR
687 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
688 * machines IP addresses when in the kernel (the in_ifaddr
689 * struct is not available), so we pass the info in at
690 * startup. We also pass in the subnetmask and mtu size. The
691 * subnetmask is used when setting the rank:
692 * afsi_SetServerIPRank(); and the mtu size is used when
693 * finding the best mtu size. rxi_FindIfnet() is replaced
694 * with rxi_Findcbi().
696 afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff);
697 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
700 afs_uuid_create(&afs_cb_interface.uuid);
701 rxi_setaddr(buffer[0]);
705 else if (parm == AFSOP_NFSSTATICADDR) {
706 extern int (*nfs_rfsdisptab_v2)();
707 nfs_rfsdisptab_v2 = (int (*)())parm2;
709 else if (parm == AFSOP_NFSSTATICADDR2) {
710 extern int (*nfs_rfsdisptab_v2)();
712 nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
714 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
717 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
718 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
719 extern int (*afs_sblockp)();
720 extern void (*afs_sbunlockp)();
722 afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
723 afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff));
725 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
726 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
729 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
730 #endif /* AFS_SGI53_ENV */
731 else if (parm == AFSOP_SHUTDOWN) {
732 afs_cold_shutdown = 0;
733 if (parm == 1) afs_cold_shutdown = 1;
734 if (afs_globalVFS != 0) {
735 afs_warn("AFS isn't unmounted yet! Call aborted\n");
740 else if (parm == AFSOP_AFS_VFSMOUNT) {
742 vfsmount(parm2, parm3, parm4, parm5);
743 #else /* defined(AFS_HPUX_ENV) */
744 #if defined(KERNEL_HAVE_UERROR)
749 #endif /* defined(AFS_HPUX_ENV) */
751 else if (parm == AFSOP_CLOSEWAIT) {
752 afs_SynchronousCloses = 'S';
754 else if (parm == AFSOP_GETMTU) {
756 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
757 #ifdef AFS_USERSPACE_IP_ADDR
759 i = rxi_Findcbi(parm2);
760 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
761 #else /* AFS_USERSPACE_IP_ADDR */
764 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
765 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
766 #endif /* else AFS_USERSPACE_IP_ADDR */
767 #endif /* !AFS_SUN5_ENV */
769 AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code);
771 /* this is disabled for now because I can't figure out how to get access
772 * to these kernel variables. It's only for supporting user-mode rx
773 * programs -- it makes a huge difference on the 220's in my testbed,
774 * though I don't know why. The bosserver does this with /etc/no, so it's
775 * being handled a different way for the servers right now. */
778 extern u_long sb_max_dflt;
781 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
782 if (sb_max < 131072) sb_max = 131072;
785 #endif /* AFS_AIX32_ENV */
787 else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
789 #if !defined(AFS_SUN5_ENV)
790 #ifdef AFS_USERSPACE_IP_ADDR
792 i = rxi_Findcbi(parm2);
794 mask = afs_cb_interface.subnetmask[i];
798 #else /* AFS_USERSPACE_IP_ADDR */
801 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
804 #endif /* else AFS_USERSPACE_IP_ADDR */
805 #endif /* !AFS_SUN5_ENV */
807 AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code);
810 else if (parm == AFSOP_AFSDB_HANDLER) {
811 int sizeArg = (int)parm4;
812 int kmsgLen = sizeArg & 0xffff;
813 int cellLen = (sizeArg & 0xffff0000) >> 16;
814 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
815 char *cellname = afs_osi_Alloc(cellLen);
818 afs_osi_MaskSignals();
820 AFS_COPYIN((afs_int32 *)parm2, cellname, cellLen, code);
821 AFS_COPYIN((afs_int32 *)parm3, kmsg, kmsgLen, code);
823 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
824 if (*cellname == 1) *cellname = 0;
825 if (code == -2) { /* Shutting down? */
830 if (!code) AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
831 afs_osi_Free(kmsg, kmsgLen);
832 afs_osi_Free(cellname, cellLen);
835 else if (parm == AFSOP_SET_DYNROOT) {
836 code = afs_SetDynrootEnable(parm2);
838 else if (parm == AFSOP_SET_FAKESTAT) {
839 afs_fakestat_enable = parm2;
847 #ifdef AFS_LINUX20_ENV
856 #include "sys/lockl.h"
859 * syscall - this is the VRMIX system call entry point.
862 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
863 * all the user-level calls to `syscall' to change.
865 syscall(syscall, p1, p2, p3, p4, p5, p6) {
866 register rval1=0, code;
869 #ifndef AFS_AIX41_ENV
870 extern lock_t kernel_lock;
871 monster = lockl(&kernel_lock, LOCK_SHORT);
872 #endif /* !AFS_AIX41_ENV */
874 AFS_STATCNT(syscall);
878 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
883 rval1 = afs_setpag();
889 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
893 case AFSCALL_ICREATE:
894 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
898 rval1 = afs_syscall_iopen(p1, p2, p3);
902 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
906 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
911 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
913 if (!code) rval1 = retval;
914 if (!rval1) rval1 = code;
924 #ifndef AFS_AIX41_ENV
925 if (monster != LOCK_NEST)
926 unlockl(&kernel_lock);
927 #endif /* !AFS_AIX41_ENV */
928 return getuerror() ? -1 : rval1;
932 * lsetpag - interface to afs_setpag().
936 AFS_STATCNT(lsetpag);
937 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
941 * lpioctl - interface to pioctl()
943 lpioctl(path, cmd, cmarg, follow)
944 char *path, *cmarg; {
946 AFS_STATCNT(lpioctl);
947 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
950 #else /* !AFS_AIX32_ENV */
952 #if defined(AFS_SGI_ENV)
965 Afs_syscall (struct afsargs *uap, rval_t *rvp)
970 AFS_STATCNT(afs_syscall);
971 switch(uap->syscall) {
975 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
977 rvp->r_val1 = retval;
979 #ifdef AFS_SGI_XFS_IOPS_ENV
981 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
982 uap->parm4, uap->parm5);
985 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
986 uap->parm4, uap->parm5);
988 case AFSCALL_ILISTINODE64:
989 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
990 uap->parm4, uap->parm5);
992 case AFSCALL_ICREATENAME64:
993 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
994 uap->parm4, uap->parm5);
997 #ifdef AFS_SGI_VNODE_GLUE
998 case AFSCALL_INIT_KERNEL_CONFIG:
999 error = afs_init_kernel_config(uap->parm1);
1003 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
1004 uap->parm3, uap->parm4, uap->parm5);
1009 #else /* AFS_SGI_ENV */
1027 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
1029 dst->param1 = src->param1;
1030 dst->param2 = src->param2;
1031 dst->param3 = src->param3;
1032 dst->param4 = src->param4;
1036 * If you need to change copyin_iparam(), you may also need to change
1037 * copyin_afs_ioctl().
1041 copyin_iparam(caddr_t cmarg, struct iparam *dst)
1045 #if defined(AFS_HPUX_64BIT_ENV)
1046 struct iparam32 dst32;
1048 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
1050 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
1052 iparam32_to_iparam(&dst32, dst);
1055 #endif /* AFS_HPUX_64BIT_ENV */
1057 #if defined(AFS_SUN57_64BIT_ENV)
1058 struct iparam32 dst32;
1060 if (get_udatamodel() == DATAMODEL_ILP32) {
1061 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
1063 iparam32_to_iparam(&dst32, dst);
1066 #endif /* AFS_SUN57_64BIT_ENV */
1068 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
1069 struct iparam32 dst32;
1071 #ifdef AFS_SPARC64_LINUX24_ENV
1072 if (current->thread.flags & SPARC_FLAG_32BIT)
1073 #elif AFS_SPARC64_LINUX20_ENV
1074 if (current->tss.flags & SPARC_FLAG_32BIT)
1076 #error Not done for this linux version
1077 #endif /* AFS_SPARC64_LINUX20_ENV */
1079 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
1081 iparam32_to_iparam(&dst32, dst);
1084 #endif /* AFS_LINUX_64BIT_KERNEL */
1086 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
1090 /* Main entry of all afs system calls */
1092 extern int afs_sinited;
1094 /** The 32 bit OS expects the members of this structure to be 32 bit
1095 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
1096 * to accomodate both, *long* is used instead of afs_int32
1099 #ifdef AFS_SUN57_ENV
1121 Afs_syscall(register struct afssysa *uap, rval_t *rvp)
1123 int *retval = &rvp->r_val1;
1124 #else /* AFS_SUN5_ENV */
1125 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1127 afs3_syscall(p, args, retval)
1140 } *uap = (struct a *)args;
1141 #else /* AFS_OSF_ENV */
1142 #ifdef AFS_LINUX20_ENV
1150 long parm6; /* not actually used - should be removed */
1152 /* Linux system calls only set up for 5 arguments. */
1153 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
1156 struct afssysargs args, *uap = &args;
1158 long *retval = &linux_ret;
1159 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
1160 #ifdef AFS_SPARC64_LINUX24_ENV
1161 afs_int32 eparm32[4];
1163 /* eparm is also used by AFSCALL_CALL in afsd.c */
1165 #if defined(UKERNEL)
1176 } *uap = (struct a *)u.u_ap;
1179 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
1183 #endif /* SUN && !SUN5 */
1193 } *uap = (struct a *)u.u_ap;
1194 #endif /* UKERNEL */
1195 #if defined(AFS_DEC_ENV)
1196 int *retval = &u.u_r.r_val1;
1197 #elif defined(AFS_HPUX_ENV)
1198 long *retval = &u.u_rval1;
1200 int *retval = &u.u_rval1;
1202 #endif /* AFS_LINUX20_ENV */
1203 #endif /* AFS_OSF_ENV */
1204 #endif /* AFS_SUN5_ENV */
1205 register int code = 0;
1207 AFS_STATCNT(afs_syscall);
1214 #ifdef AFS_LINUX20_ENV
1216 /* setup uap for use below - pull out the magic decoder ring to know
1217 * which syscalls have folded argument lists.
1219 uap->syscall = syscall;
1223 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
1224 #ifdef AFS_SPARC64_LINUX24_ENV
1225 /* from arch/sparc64/kernel/sys_sparc32.c */
1227 ({ unsigned long __ret; \
1228 __asm__ ("srl %0, 0, %0" \
1235 if (current->thread.flags & SPARC_FLAG_32BIT) {
1236 AFS_COPYIN((char*)parm4, (char*)eparm32, sizeof(eparm32), code);
1237 eparm[0]=AA(eparm32[0]);
1238 eparm[1]=AA(eparm32[1]);
1239 eparm[2]=AA(eparm32[2]);
1243 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
1244 uap->parm4 = eparm[0];
1245 uap->parm5 = eparm[1];
1246 uap->parm6 = eparm[2];
1255 #if defined(AFS_HPUX_ENV)
1257 * There used to be code here (duplicated from osi_Init()) for
1258 * initializing the semaphore used by AFS_GLOCK(). Was the
1259 * duplication to handle the case of a dynamically loaded kernel
1264 if (uap->syscall == AFSCALL_CALL) {
1266 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1267 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1269 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1271 } else if (uap->syscall == AFSCALL_SETPAG) {
1273 register proc_t *procp;
1275 procp = ttoproc(curthread);
1277 code = afs_setpag(&procp->p_cred);
1281 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1282 code = afs_setpag(p, args, retval);
1283 #else /* AFS_OSF_ENV */
1284 code = afs_setpag();
1288 } else if (uap->syscall == AFSCALL_PIOCTL) {
1291 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1293 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1294 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1296 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1300 } else if (uap->syscall == AFSCALL_ICREATE) {
1301 struct iparam iparams;
1303 code = copyin_iparam((char *)uap->parm3, &iparams);
1305 #if defined(KERNEL_HAVE_UERROR)
1310 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1311 iparams.param3, iparams.param4, rvp, CRED());
1313 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1314 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1315 iparams.param3, iparams.param4, retval);
1317 iparams.param3, iparams.param4);
1319 #endif /* AFS_SUN5_ENV */
1320 } else if (uap->syscall == AFSCALL_IOPEN) {
1322 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1324 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1325 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1327 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1329 #endif /* AFS_SUN5_ENV */
1330 } else if (uap->syscall == AFSCALL_IDEC) {
1332 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1334 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1335 #endif /* AFS_SUN5_ENV */
1336 } else if (uap->syscall == AFSCALL_IINC) {
1338 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1340 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1341 #endif /* AFS_SUN5_ENV */
1342 } else if (uap->syscall == AFSCALL_ICL) {
1344 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1346 #ifdef AFS_LINUX20_ENV
1348 /* ICL commands can return values. */
1349 code = -linux_ret; /* Gets negated again at exit below */
1353 #if defined(KERNEL_HAVE_UERROR)
1357 #endif /* !AFS_LINUX20_ENV */
1359 #if defined(KERNEL_HAVE_UERROR)
1366 #ifdef AFS_LINUX20_ENV
1372 #endif /* AFS_SGI_ENV */
1373 #endif /* !AFS_AIX32_ENV */
1376 * Initstate in the range 0 < x < 100 are early initialization states.
1377 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1378 * the cache may be initialized.
1379 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1380 * is done after all the cache initialization has been done.
1381 * Initstate of 200 means that the volume has been looked up once, possibly
1383 * Initstate of 300 means that the volume has been *successfully* looked up.
1385 int afs_CheckInit(void)
1387 register int code = 0;
1389 AFS_STATCNT(afs_CheckInit);
1390 if (afs_initState <= 100)
1391 code = ENXIO; /* never finished init phase */
1392 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1393 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1394 } else if (afs_initState == 200)
1395 code = ETIMEDOUT; /* didn't find root volume */
1399 int afs_shuttingdown = 0;
1400 void afs_shutdown(void)
1402 extern short afs_brsDaemons;
1403 extern afs_int32 afs_CheckServerDaemonStarted;
1404 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1405 extern struct osi_file *afs_cacheInodep;
1407 AFS_STATCNT(afs_shutdown);
1408 if (afs_shuttingdown) return;
1409 afs_shuttingdown = 1;
1410 if (afs_cold_shutdown) afs_warn("COLD ");
1411 else afs_warn("WARM ");
1412 afs_warn("shutting down of: CB... ");
1414 afs_termState = AFSOP_STOP_RXCALLBACK;
1415 rx_WakeupServerProcs();
1416 /* shutdown_rxkernel(); */
1417 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1418 afs_osi_Sleep(&afs_termState);
1420 afs_warn("afs... ");
1421 while (afs_termState == AFSOP_STOP_AFS) {
1422 afs_osi_CancelWait(&AFS_WaitHandler);
1423 afs_osi_Sleep(&afs_termState);
1425 if (afs_CheckServerDaemonStarted) {
1426 while (afs_termState == AFSOP_STOP_CS) {
1427 afs_osi_CancelWait(&AFS_CSWaitHandler);
1428 afs_osi_Sleep(&afs_termState);
1431 afs_warn("BkG... ");
1432 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1433 while (afs_termState == AFSOP_STOP_BKG) {
1434 afs_osi_Wakeup(&afs_brsDaemons);
1435 afs_osi_Sleep(&afs_termState);
1437 afs_warn("CTrunc... ");
1438 /* Cancel cache truncate daemon. */
1439 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1440 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1441 afs_osi_Sleep(&afs_termState);
1443 #ifdef AFS_AFSDB_ENV
1444 afs_warn("AFSDB... ");
1446 while (afs_termState == AFSOP_STOP_AFSDB)
1447 afs_osi_Sleep(&afs_termState);
1449 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1450 afs_warn("RxEvent... ");
1451 /* cancel rx event daemon */
1452 while (afs_termState == AFSOP_STOP_RXEVENT)
1453 afs_osi_Sleep(&afs_termState);
1454 #if defined(RXK_LISTENER_ENV)
1456 afs_warn("UnmaskRxkSignals... ");
1457 afs_osi_UnmaskRxkSignals();
1459 /* cancel rx listener */
1460 afs_warn("RxListener... ");
1461 osi_StopListener(); /* This closes rx_socket. */
1462 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1463 afs_warn("Sleep... ");
1464 afs_osi_Sleep(&afs_termState);
1468 afs_termState = AFSOP_STOP_COMPLETE;
1472 /* Close file only after daemons which can write to it are stopped. */
1473 if (afs_cacheInodep) /* memcache won't set this */
1475 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1476 afs_cacheInodep = 0;
1478 return; /* Just kill daemons for now */
1482 shutdown_rxkernel();
1486 shutdown_bufferpackage();
1492 shutdown_vnodeops();
1494 shutdown_exporter();
1495 shutdown_memcache();
1496 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1497 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1498 /* this routine does not exist in Ultrix systems... 93.01.19 */
1500 #endif /* AFS_DEC_ENV */
1503 /* The following hold the cm stats */
1505 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1506 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1507 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1509 afs_warn(" ALL allocated tables\n");
1510 afs_shuttingdown = 0;
1514 void shutdown_afstest(void)
1516 AFS_STATCNT(shutdown_afstest);
1517 afs_initState = afs_termState = afs_setTime = 0;
1518 AFS_Running = afs_CB_Running = 0;
1519 afs_CacheInit_Done = afs_Go_Done = 0;
1520 if (afs_cold_shutdown) {
1521 *afs_rootVolumeName = 0;
1526 /* In case there is a bunch of dynamically build bkg daemons to free */
1527 void afs_shutdown_BKG(void)
1529 AFS_STATCNT(shutdown_BKG);
1533 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1534 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1535 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1536 int afs_icl_sizeofLong = 1;
1538 int afs_icl_sizeofLong = 2;
1541 int afs_icl_sizeofLong = 1;
1544 int afs_icl_inited = 0;
1546 /* init function, called once, under afs_icl_lock */
1547 int afs_icl_Init(void)
1553 extern struct afs_icl_log *afs_icl_FindLog();
1554 extern struct afs_icl_set *afs_icl_FindSet();
1558 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1560 afs_int32 *lp, elts, flags;
1561 register afs_int32 code;
1562 struct afs_icl_log *logp;
1563 struct afs_icl_set *setp;
1564 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1566 #else /* AFS_SGI61_ENV */
1568 #endif /* AFS_SGI61_ENV */
1570 afs_int32 startCookie;
1571 afs_int32 allocated;
1572 struct afs_icl_log *tlp;
1575 if (!afs_suser(CRED())) { /* only root can run this code */
1579 if (!afs_suser()) { /* only root can run this code */
1580 #if defined(KERNEL_HAVE_UERROR)
1589 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1590 case ICL_OP_COPYOUT: /* copy ouy data */
1591 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1592 * return flags<<24 + nwords.
1593 * updates cookie to updated start (not end) if we had to
1594 * skip some records.
1596 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1597 if (code) return code;
1598 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1599 if (code) return code;
1600 logp = afs_icl_FindLog(tname);
1601 if (!logp) return ENOENT;
1602 #define BUFFERSIZE AFS_LRALLOCSIZ
1603 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1604 elts = BUFFERSIZE / sizeof(afs_int32);
1605 if (p3 < elts) elts = p3;
1606 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1607 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1610 osi_FreeLargeSpace((struct osi_buffer *) lp);
1613 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1614 if (code) goto done;
1615 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1616 if (code) goto done;
1617 *retval = (flags<<24) | (elts & 0xffffff);
1619 afs_icl_LogRele(logp);
1620 osi_FreeLargeSpace((struct osi_buffer *) lp);
1623 case ICL_OP_ENUMLOGS: /* enumerate logs */
1624 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1625 * return 0 for success, otherwise error.
1627 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1628 if (p1-- == 0) break;
1630 if (!tlp) return ENOENT; /* past the end of file */
1631 temp = strlen(tlp->name)+1;
1632 if (temp > p3) return EINVAL;
1633 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1634 if (!code) /* copy out size of log */
1635 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1638 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1639 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1640 * return 0 for success, otherwise error.
1642 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1643 if (code) return code;
1644 setp = afs_icl_FindSet(tname);
1645 if (!setp) return ENOENT;
1646 if (p2 > ICL_LOGSPERSET)
1648 if (!(tlp = setp->logs[p2]))
1650 temp = strlen(tlp->name)+1;
1651 if (temp > p4) return EINVAL;
1652 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1655 case ICL_OP_CLRLOG: /* clear specified log */
1656 /* zero out the specified log: p1=logname */
1657 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1658 if (code) return code;
1659 logp = afs_icl_FindLog(tname);
1660 if (!logp) return ENOENT;
1661 code = afs_icl_ZeroLog(logp);
1662 afs_icl_LogRele(logp);
1665 case ICL_OP_CLRSET: /* clear specified set */
1666 /* zero out the specified set: p1=setname */
1667 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1668 if (code) return code;
1669 setp = afs_icl_FindSet(tname);
1670 if (!setp) return ENOENT;
1671 code = afs_icl_ZeroSet(setp);
1672 afs_icl_SetRele(setp);
1675 case ICL_OP_CLRALL: /* clear all logs */
1676 /* zero out all logs -- no args */
1678 ObtainWriteLock(&afs_icl_lock,178);
1679 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1680 tlp->refCount++; /* hold this guy */
1681 ReleaseWriteLock(&afs_icl_lock);
1682 /* don't clear persistent logs */
1683 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1684 code = afs_icl_ZeroLog(tlp);
1685 ObtainWriteLock(&afs_icl_lock,179);
1686 if (--tlp->refCount == 0)
1687 afs_icl_ZapLog(tlp);
1690 ReleaseWriteLock(&afs_icl_lock);
1693 case ICL_OP_ENUMSETS: /* enumerate all sets */
1694 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1695 * return 0 for success, otherwise error.
1697 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1698 if (p1-- == 0) break;
1700 if (!setp) return ENOENT; /* past the end of file */
1701 temp = strlen(setp->name)+1;
1702 if (temp > p3) return EINVAL;
1703 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1704 if (!code) /* copy out size of log */
1705 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1708 case ICL_OP_SETSTAT: /* set status on a set */
1709 /* activate the specified set: p1=setname, p2=op */
1710 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1711 if (code) return code;
1712 setp = afs_icl_FindSet(tname);
1713 if (!setp) return ENOENT;
1714 code = afs_icl_SetSetStat(setp, p2);
1715 afs_icl_SetRele(setp);
1718 case ICL_OP_SETSTATALL: /* set status on all sets */
1719 /* activate the specified set: p1=op */
1721 ObtainWriteLock(&afs_icl_lock,180);
1722 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1723 setp->refCount++; /* hold this guy */
1724 ReleaseWriteLock(&afs_icl_lock);
1725 /* don't set states on persistent sets */
1726 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1727 code = afs_icl_SetSetStat(setp, p1);
1728 ObtainWriteLock(&afs_icl_lock,181);
1729 if (--setp->refCount == 0)
1730 afs_icl_ZapSet(setp);
1733 ReleaseWriteLock(&afs_icl_lock);
1736 case ICL_OP_SETLOGSIZE: /* set size of log */
1737 /* set the size of the specified log: p1=logname, p2=size (in words) */
1738 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1739 if (code) return code;
1740 logp = afs_icl_FindLog(tname);
1741 if (!logp) return ENOENT;
1742 code = afs_icl_LogSetSize(logp, p2);
1743 afs_icl_LogRele(logp);
1746 case ICL_OP_GETLOGINFO: /* get size of log */
1747 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1748 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1749 if (code) return code;
1750 logp = afs_icl_FindLog(tname);
1751 if (!logp) return ENOENT;
1752 allocated = !!logp->datap;
1753 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1755 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1756 afs_icl_LogRele(logp);
1759 case ICL_OP_GETSETINFO: /* get state of set */
1760 /* zero out the specified set: p1=setname, p2=&state */
1761 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1762 if (code) return code;
1763 setp = afs_icl_FindSet(tname);
1764 if (!setp) return ENOENT;
1765 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1766 afs_icl_SetRele(setp);
1777 afs_lock_t afs_icl_lock;
1779 /* exported routine: a 4 parameter event */
1780 int afs_icl_Event4(register struct afs_icl_set *setp, afs_int32 eventID,
1781 afs_int32 lAndT, long p1, long p2, long p3, long p4)
1785 register afs_int32 tmask;
1788 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1789 if (!ICL_SETACTIVE(setp))
1793 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1794 ix = ICL_EVENTBYTE(eventID);
1795 ObtainReadLock(&setp->lock);
1796 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1797 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1799 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1803 if (mask == 0) break; /* break early */
1806 ReleaseReadLock(&setp->lock);
1810 /* Next 4 routines should be implemented via var-args or something.
1811 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1812 * Otherwise, could call afs_icl_Event4 directly.
1814 int afs_icl_Event3(register struct afs_icl_set *setp, afs_int32 eventID,
1815 afs_int32 lAndT, long p1, long p2, long p3)
1817 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1820 int afs_icl_Event2(register struct afs_icl_set *setp, afs_int32 eventID,
1821 afs_int32 lAndT, long p1, long p2)
1823 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1826 int afs_icl_Event1(register struct afs_icl_set *setp, afs_int32 eventID,
1827 afs_int32 lAndT, long p1)
1829 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1832 int afs_icl_Event0(register struct afs_icl_set *setp, afs_int32 eventID,
1835 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1838 struct afs_icl_log *afs_icl_allLogs = 0;
1840 /* function to purge records from the start of the log, until there
1841 * is at least minSpace long's worth of space available without
1842 * making the head and the tail point to the same word.
1844 * Log must be write-locked.
1846 static void afs_icl_GetLogSpace(register struct afs_icl_log *logp, afs_int32 minSpace)
1848 register unsigned int tsize;
1850 while (logp->logSize - logp->logElements <= minSpace) {
1852 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1853 logp->logElements -= tsize;
1854 logp->firstUsed += tsize;
1855 if (logp->firstUsed >= logp->logSize)
1856 logp->firstUsed -= logp->logSize;
1857 logp->baseCookie += tsize;
1861 /* append string astr to buffer, including terminating null char.
1863 * log must be write-locked.
1865 #define ICL_CHARSPERLONG 4
1866 static void afs_icl_AppendString(struct afs_icl_log *logp, char *astr)
1868 char *op; /* ptr to char to write */
1870 register int bib; /* bytes in buffer */
1873 op = (char *) &(logp->datap[logp->firstFree]);
1877 if (++bib >= ICL_CHARSPERLONG) {
1880 if (++(logp->firstFree) >= logp->logSize) {
1881 logp->firstFree = 0;
1882 op = (char *) &(logp->datap[0]);
1884 logp->logElements++;
1889 /* if we've used this word at all, allocate it */
1890 if (++(logp->firstFree) >= logp->logSize) {
1891 logp->firstFree = 0;
1893 logp->logElements++;
1897 /* add a long to the log, ignoring overflow (checked already) */
1898 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1899 #define ICL_APPENDINT32(lp, x) \
1901 (lp)->datap[(lp)->firstFree] = (x); \
1902 if (++((lp)->firstFree) >= (lp)->logSize) { \
1903 (lp)->firstFree = 0; \
1905 (lp)->logElements++; \
1908 #define ICL_APPENDLONG(lp, x) \
1910 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1911 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1914 #else /* AFS_ALPHA_ENV */
1915 #define ICL_APPENDLONG(lp, x) \
1917 (lp)->datap[(lp)->firstFree] = (x); \
1918 if (++((lp)->firstFree) >= (lp)->logSize) { \
1919 (lp)->firstFree = 0; \
1921 (lp)->logElements++; \
1923 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1924 #endif /* AFS_ALPHA_ENV */
1926 /* routine to tell whether we're dealing with the address or the
1929 int afs_icl_UseAddr(int type)
1931 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1932 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
1938 /* Function to append a record to the log. Written for speed
1939 * since we know that we're going to have to make this work fast
1940 * pretty soon, anyway. The log must be unlocked.
1943 void afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
1944 afs_int32 types, long p1, long p2, long p3, long p4)
1946 int rsize; /* record size in longs */
1947 register int tsize; /* temp size */
1951 t4 = types & 0x3f; /* decode types */
1959 osi_GetTime(&tv); /* It panics for solaris if inside */
1960 ObtainWriteLock(&logp->lock,182);
1962 ReleaseWriteLock(&logp->lock);
1966 /* get timestamp as # of microseconds since some time that doesn't
1967 * change that often. This algorithm ticks over every 20 minutes
1968 * or so (1000 seconds). Write a timestamp record if it has.
1970 if (tv.tv_sec - logp->lastTS > 1024)
1972 /* the timer has wrapped -- write a timestamp record */
1973 if (logp->logSize - logp->logElements <= 5)
1974 afs_icl_GetLogSpace(logp, 5);
1976 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1977 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1978 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1979 ICL_APPENDINT32(logp,
1980 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1981 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1983 logp->lastTS = tv.tv_sec;
1986 rsize = 4; /* base case */
1988 /* compute size of parameter p1. Only tricky case is string.
1989 * In that case, we have to call strlen to get the string length.
1991 ICL_SIZEHACK(t1, p1);
1994 /* compute size of parameter p2. Only tricky case is string.
1995 * In that case, we have to call strlen to get the string length.
1997 ICL_SIZEHACK(t2, p2);
2000 /* compute size of parameter p3. Only tricky case is string.
2001 * In that case, we have to call strlen to get the string length.
2003 ICL_SIZEHACK(t3, p3);
2006 /* compute size of parameter p4. Only tricky case is string.
2007 * In that case, we have to call strlen to get the string length.
2009 ICL_SIZEHACK(t4, p4);
2012 /* At this point, we've computed all of the parameter sizes, and
2013 * have in rsize the size of the entire record we want to append.
2014 * Next, we check that we actually have room in the log to do this
2015 * work, and then we do the append.
2018 ReleaseWriteLock(&logp->lock);
2019 return; /* log record too big to express */
2022 if (logp->logSize - logp->logElements <= rsize)
2023 afs_icl_GetLogSpace(logp, rsize);
2025 ICL_APPENDINT32(logp,
2026 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
2027 ICL_APPENDINT32(logp, (afs_int32)op);
2028 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
2029 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
2032 /* marshall parameter 1 now */
2033 if (t1 == ICL_TYPE_STRING) {
2034 afs_icl_AppendString(logp, (char *) p1);
2036 else if (t1 == ICL_TYPE_HYPER) {
2037 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
2038 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
2040 else if (t1 == ICL_TYPE_INT64) {
2041 #ifdef AFSLITTLE_ENDIAN
2042 #ifdef AFS_64BIT_CLIENT
2043 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2044 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2045 #else /* AFS_64BIT_CLIENT */
2046 ICL_APPENDINT32(logp, (afs_int32) p1);
2047 ICL_APPENDINT32(logp, (afs_int32) 0);
2048 #endif /* AFS_64BIT_CLIENT */
2049 #else /* AFSLITTLE_ENDIAN */
2050 #ifdef AFS_64BIT_CLIENT
2051 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2052 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2053 #else /* AFS_64BIT_CLIENT */
2054 ICL_APPENDINT32(logp, (afs_int32) 0);
2055 ICL_APPENDINT32(logp, (afs_int32) p1);
2056 #endif /* AFS_64BIT_CLIENT */
2057 #endif /* AFSLITTLE_ENDIAN */
2059 else if (t1 == ICL_TYPE_FID) {
2060 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
2061 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
2062 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
2063 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
2065 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2066 else if (t1 == ICL_TYPE_INT32)
2067 ICL_APPENDINT32(logp, (afs_int32)p1);
2068 #endif /* AFS_ALPHA_ENV */
2069 else ICL_APPENDLONG(logp, p1);
2072 /* marshall parameter 2 now */
2073 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
2074 else if (t2 == ICL_TYPE_HYPER) {
2075 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
2076 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
2078 else if (t2 == ICL_TYPE_INT64) {
2079 #ifdef AFSLITTLE_ENDIAN
2080 #ifdef AFS_64BIT_CLIENT
2081 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2082 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2083 #else /* AFS_64BIT_CLIENT */
2084 ICL_APPENDINT32(logp, (afs_int32) p2);
2085 ICL_APPENDINT32(logp, (afs_int32) 0);
2086 #endif /* AFS_64BIT_CLIENT */
2087 #else /* AFSLITTLE_ENDIAN */
2088 #ifdef AFS_64BIT_CLIENT
2089 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2090 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2091 #else /* AFS_64BIT_CLIENT */
2092 ICL_APPENDINT32(logp, (afs_int32) 0);
2093 ICL_APPENDINT32(logp, (afs_int32) p2);
2094 #endif /* AFS_64BIT_CLIENT */
2095 #endif /* AFSLITTLE_ENDIAN */
2097 else if (t2 == ICL_TYPE_FID) {
2098 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
2099 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
2100 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
2101 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
2103 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2104 else if (t2 == ICL_TYPE_INT32)
2105 ICL_APPENDINT32(logp, (afs_int32)p2);
2106 #endif /* AFS_ALPHA_ENV */
2107 else ICL_APPENDLONG(logp, p2);
2110 /* marshall parameter 3 now */
2111 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
2112 else if (t3 == ICL_TYPE_HYPER) {
2113 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
2114 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
2116 else if (t3 == ICL_TYPE_INT64) {
2117 #ifdef AFSLITTLE_ENDIAN
2118 #ifdef AFS_64BIT_CLIENT
2119 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2120 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2121 #else /* AFS_64BIT_CLIENT */
2122 ICL_APPENDINT32(logp, (afs_int32) p3);
2123 ICL_APPENDINT32(logp, (afs_int32) 0);
2124 #endif /* AFS_64BIT_CLIENT */
2125 #else /* AFSLITTLE_ENDIAN */
2126 #ifdef AFS_64BIT_CLIENT
2127 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2128 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2129 #else /* AFS_64BIT_CLIENT */
2130 ICL_APPENDINT32(logp, (afs_int32) 0);
2131 ICL_APPENDINT32(logp, (afs_int32) p3);
2132 #endif /* AFS_64BIT_CLIENT */
2133 #endif /* AFSLITTLE_ENDIAN */
2135 else if (t3 == ICL_TYPE_FID) {
2136 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
2137 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
2138 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
2139 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
2141 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2142 else if (t3 == ICL_TYPE_INT32)
2143 ICL_APPENDINT32(logp, (afs_int32)p3);
2144 #endif /* AFS_ALPHA_ENV */
2145 else ICL_APPENDLONG(logp, p3);
2148 /* marshall parameter 4 now */
2149 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
2150 else if (t4 == ICL_TYPE_HYPER) {
2151 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
2152 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
2154 else if (t4 == ICL_TYPE_INT64) {
2155 #ifdef AFSLITTLE_ENDIAN
2156 #ifdef AFS_64BIT_CLIENT
2157 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2158 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2159 #else /* AFS_64BIT_CLIENT */
2160 ICL_APPENDINT32(logp, (afs_int32) p4);
2161 ICL_APPENDINT32(logp, (afs_int32) 0);
2162 #endif /* AFS_64BIT_CLIENT */
2163 #else /* AFSLITTLE_ENDIAN */
2164 #ifdef AFS_64BIT_CLIENT
2165 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2166 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2167 #else /* AFS_64BIT_CLIENT */
2168 ICL_APPENDINT32(logp, (afs_int32) 0);
2169 ICL_APPENDINT32(logp, (afs_int32) p4);
2170 #endif /* AFS_64BIT_CLIENT */
2171 #endif /* AFSLITTLE_ENDIAN */
2173 else if (t4 == ICL_TYPE_FID) {
2174 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2175 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2176 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
2177 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
2179 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2180 else if (t4 == ICL_TYPE_INT32)
2181 ICL_APPENDINT32(logp, (afs_int32)p4);
2182 #endif /* AFS_ALPHA_ENV */
2183 else ICL_APPENDLONG(logp, p4);
2185 ReleaseWriteLock(&logp->lock);
2188 /* create a log with size logSize; return it in *outLogpp and tag
2189 * it with name "name."
2191 int afs_icl_CreateLog(char *name, afs_int32 logSize, struct afs_icl_log **outLogpp)
2193 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
2196 /* create a log with size logSize; return it in *outLogpp and tag
2197 * it with name "name." 'flags' can be set to make the log unclearable.
2199 int afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, afs_uint32 flags,
2200 struct afs_icl_log **outLogpp)
2202 register struct afs_icl_log *logp;
2204 /* add into global list under lock */
2205 ObtainWriteLock(&afs_icl_lock,183);
2206 if (!afs_icl_inited) afs_icl_Init();
2208 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
2209 if (strcmp(logp->name, name) == 0) {
2210 /* found it already created, just return it */
2213 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2215 ObtainWriteLock(&logp->lock,184);
2216 logp->states |= ICL_LOGF_PERSISTENT;
2217 ReleaseWriteLock(&logp->lock);
2219 ReleaseWriteLock(&afs_icl_lock);
2224 logp = (struct afs_icl_log *)
2225 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
2226 memset((caddr_t)logp, 0, sizeof(*logp));
2229 logp->name = osi_AllocSmallSpace(strlen(name)+1);
2230 strcpy(logp->name, name);
2231 LOCK_INIT(&logp->lock, "logp lock");
2232 logp->logSize = logSize;
2233 logp->datap = NULL; /* don't allocate it until we need it */
2235 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2236 logp->states |= ICL_LOGF_PERSISTENT;
2238 logp->nextp = afs_icl_allLogs;
2239 afs_icl_allLogs = logp;
2240 ReleaseWriteLock(&afs_icl_lock);
2246 /* called with a log, a pointer to a buffer, the size of the buffer
2247 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
2248 * and returns data in the provided buffer, and returns output flags
2249 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
2250 * find the record with cookie value cookie.
2252 int afs_icl_CopyOut(register struct afs_icl_log *logp, afs_int32 *bufferp,
2253 afs_int32 *bufSizep, afs_uint32 *cookiep, afs_int32 *flagsp)
2255 afs_int32 nwords; /* number of words to copy out */
2256 afs_uint32 startCookie; /* first cookie to use */
2257 afs_int32 outWords; /* words we've copied out */
2258 afs_int32 inWords; /* max words to copy out */
2259 afs_int32 code; /* return code */
2260 afs_int32 ix; /* index we're copying from */
2261 afs_int32 outFlags; /* return flags */
2262 afs_int32 inFlags; /* flags passed in */
2265 inWords = *bufSizep; /* max to copy out */
2266 outWords = 0; /* amount copied out */
2267 startCookie = *cookiep;
2272 ObtainWriteLock(&logp->lock,185);
2274 ReleaseWriteLock(&logp->lock);
2278 /* first, compute the index of the start cookie we've been passed */
2280 /* (re-)compute where we should start */
2281 if (startCookie < logp->baseCookie) {
2282 if (startCookie) /* missed some output */
2283 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2284 /* skip to the first available record */
2285 startCookie = logp->baseCookie;
2286 *cookiep = startCookie;
2289 /* compute where we find the first element to copy out */
2290 ix = logp->firstUsed + startCookie - logp->baseCookie;
2291 if (ix >= logp->logSize) ix -= logp->logSize;
2293 /* if have some data now, break out and process it */
2294 if (startCookie - logp->baseCookie < logp->logElements) break;
2296 /* At end of log, so clear it if we need to */
2297 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
2299 logp->firstUsed = logp->firstFree = 0;
2300 logp->logElements = 0;
2302 /* otherwise, either wait for the data to arrive, or return */
2303 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2304 ReleaseWriteLock(&logp->lock);
2308 logp->states |= ICL_LOGF_WAITING;
2309 ReleaseWriteLock(&logp->lock);
2310 afs_osi_Sleep(&logp->lock);
2311 ObtainWriteLock(&logp->lock,186);
2313 /* copy out data from ix to logSize or firstFree, depending
2314 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2315 * be careful not to copy out more than nwords.
2317 if (ix >= logp->firstUsed) {
2318 if (logp->firstUsed <= logp->firstFree)
2320 end = logp->firstFree; /* first element not to copy */
2322 end = logp->logSize;
2323 nwords = inWords; /* don't copy more than this */
2324 if (end - ix < nwords)
2327 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2332 /* if we're going to copy more out below, we'll start here */
2335 /* now, if active part of the log has wrapped, there's more stuff
2336 * starting at the head of the log. Copy out more from there.
2338 if (logp->firstUsed > logp->firstFree
2339 && ix < logp->firstFree && inWords > 0) {
2340 /* (more to) copy out from the wrapped section at the
2341 * start of the log. May get here even if didn't copy any
2342 * above, if the cookie points directly into the wrapped section.
2345 if (logp->firstFree - ix < nwords)
2346 nwords = logp->firstFree - ix;
2347 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2353 ReleaseWriteLock(&logp->lock);
2357 *bufSizep = outWords;
2363 /* return basic parameter information about a log */
2364 int afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 *maxSizep,
2365 afs_int32 *curSizep)
2367 ObtainReadLock(&logp->lock);
2368 *maxSizep = logp->logSize;
2369 *curSizep = logp->logElements;
2370 ReleaseReadLock(&logp->lock);
2375 /* hold and release logs */
2376 int afs_icl_LogHold(register struct afs_icl_log *logp)
2378 ObtainWriteLock(&afs_icl_lock,187);
2380 ReleaseWriteLock(&afs_icl_lock);
2384 /* hold and release logs, called with lock already held */
2385 int afs_icl_LogHoldNL(register struct afs_icl_log *logp)
2391 /* keep track of how many sets believe the log itself is allocated */
2392 int afs_icl_LogUse(register struct afs_icl_log *logp)
2394 ObtainWriteLock(&logp->lock,188);
2395 if (logp->setCount == 0) {
2396 /* this is the first set actually using the log -- allocate it */
2397 if (logp->logSize == 0) {
2398 /* we weren't passed in a hint and it wasn't set */
2399 logp->logSize = ICL_DEFAULT_LOGSIZE;
2401 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2402 #ifdef KERNEL_HAVE_PIN
2403 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2407 ReleaseWriteLock(&logp->lock);
2411 /* decrement the number of real users of the log, free if possible */
2412 int afs_icl_LogFreeUse(register struct afs_icl_log *logp)
2414 ObtainWriteLock(&logp->lock,189);
2415 if (--logp->setCount == 0) {
2416 /* no more users -- free it (but keep log structure around)*/
2417 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2418 #ifdef KERNEL_HAVE_PIN
2419 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2421 logp->firstUsed = logp->firstFree = 0;
2422 logp->logElements = 0;
2425 ReleaseWriteLock(&logp->lock);
2429 /* set the size of the log to 'logSize' */
2430 int afs_icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
2432 ObtainWriteLock(&logp->lock,190);
2434 /* nothing to worry about since it's not allocated */
2435 logp->logSize = logSize;
2439 logp->firstUsed = logp->firstFree = 0;
2440 logp->logElements = 0;
2442 /* free and allocate a new one */
2443 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2444 #ifdef KERNEL_HAVE_PIN
2445 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2447 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2448 #ifdef KERNEL_HAVE_PIN
2449 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2451 logp->logSize = logSize;
2453 ReleaseWriteLock(&logp->lock);
2458 /* free a log. Called with afs_icl_lock locked. */
2459 int afs_icl_ZapLog(register struct afs_icl_log *logp)
2461 register struct afs_icl_log **lpp, *tp;
2463 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2465 /* found the dude we want to remove */
2467 osi_FreeSmallSpace(logp->name);
2468 osi_FreeSmallSpace(logp->datap);
2469 osi_FreeSmallSpace(logp);
2470 break; /* won't find it twice */
2476 /* do the release, watching for deleted entries */
2477 int afs_icl_LogRele(register struct afs_icl_log *logp)
2479 ObtainWriteLock(&afs_icl_lock,191);
2480 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2481 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2483 ReleaseWriteLock(&afs_icl_lock);
2487 /* do the release, watching for deleted entries, log already held */
2488 int afs_icl_LogReleNL(register struct afs_icl_log *logp)
2490 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2491 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2496 /* zero out the log */
2497 int afs_icl_ZeroLog(register struct afs_icl_log *logp)
2499 ObtainWriteLock(&logp->lock,192);
2500 logp->firstUsed = logp->firstFree = 0;
2501 logp->logElements = 0;
2502 logp->baseCookie = 0;
2503 ReleaseWriteLock(&logp->lock);
2507 /* free a log entry, and drop its reference count */
2508 int afs_icl_LogFree(register struct afs_icl_log *logp)
2510 ObtainWriteLock(&logp->lock,193);
2511 logp->states |= ICL_LOGF_DELETED;
2512 ReleaseWriteLock(&logp->lock);
2513 afs_icl_LogRele(logp);
2517 /* find a log by name, returning it held */
2518 struct afs_icl_log *afs_icl_FindLog(char *name)
2520 register struct afs_icl_log *tp;
2521 ObtainWriteLock(&afs_icl_lock,194);
2522 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2523 if (strcmp(tp->name, name) == 0) {
2524 /* this is the dude we want */
2529 ReleaseWriteLock(&afs_icl_lock);
2533 int afs_icl_EnumerateLogs(int (*aproc)(), char *arock)
2535 register struct afs_icl_log *tp;
2536 register afs_int32 code;
2539 ObtainWriteLock(&afs_icl_lock,195);
2540 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2541 tp->refCount++; /* hold this guy */
2542 ReleaseWriteLock(&afs_icl_lock);
2543 ObtainReadLock(&tp->lock);
2544 code = (*aproc)(tp->name, arock, tp);
2545 ReleaseReadLock(&tp->lock);
2546 ObtainWriteLock(&afs_icl_lock,196);
2547 if (--tp->refCount == 0)
2551 ReleaseWriteLock(&afs_icl_lock);
2555 struct afs_icl_set *afs_icl_allSets = 0;
2557 int afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
2558 struct afs_icl_log *fatalLogp, struct afs_icl_set **outSetpp)
2560 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2561 /*flags*/0, outSetpp);
2564 /* create a set, given pointers to base and fatal logs, if any.
2565 * Logs are unlocked, but referenced, and *outSetpp is returned
2566 * referenced. Function bumps reference count on logs, since it
2567 * addds references from the new afs_icl_set. When the set is destroyed,
2568 * those references will be released.
2570 int afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
2571 struct afs_icl_log *fatalLogp, afs_uint32 flags, struct afs_icl_set **outSetpp)
2573 register struct afs_icl_set *setp;
2575 afs_int32 states = ICL_DEFAULT_SET_STATES;
2577 ObtainWriteLock(&afs_icl_lock,197);
2578 if (!afs_icl_inited) afs_icl_Init();
2580 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2581 if (strcmp(setp->name, name) == 0) {
2584 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2586 ObtainWriteLock(&setp->lock,198);
2587 setp->states |= ICL_SETF_PERSISTENT;
2588 ReleaseWriteLock(&setp->lock);
2590 ReleaseWriteLock(&afs_icl_lock);
2595 /* determine initial state */
2596 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2597 states = ICL_SETF_ACTIVE;
2598 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2599 states = ICL_SETF_FREED;
2600 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2601 states |= ICL_SETF_PERSISTENT;
2603 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2604 memset((caddr_t)setp, 0, sizeof(*setp));
2606 if (states & ICL_SETF_FREED)
2607 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2608 setp->states = states;
2610 LOCK_INIT(&setp->lock, "setp lock");
2611 /* next lock is obtained in wrong order, hierarchy-wise, but
2612 * it doesn't matter, since no one can find this lock yet, since
2613 * the afs_icl_lock is still held, and thus the obtain can't block.
2615 ObtainWriteLock(&setp->lock,199);
2616 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2617 strcpy(setp->name, name);
2618 setp->nevents = ICL_DEFAULTEVENTS;
2619 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2620 #ifdef KERNEL_HAVE_PIN
2621 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2623 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2624 setp->eventFlags[i] = 0xff; /* default to enabled */
2626 /* update this global info under the afs_icl_lock */
2627 setp->nextp = afs_icl_allSets;
2628 afs_icl_allSets = setp;
2629 ReleaseWriteLock(&afs_icl_lock);
2631 /* set's basic lock is still held, so we can finish init */
2633 setp->logs[0] = baseLogp;
2634 afs_icl_LogHold(baseLogp);
2635 if (!(setp->states & ICL_SETF_FREED))
2636 afs_icl_LogUse(baseLogp); /* log is actually being used */
2639 setp->logs[1] = fatalLogp;
2640 afs_icl_LogHold(fatalLogp);
2641 if (!(setp->states & ICL_SETF_FREED))
2642 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2644 ReleaseWriteLock(&setp->lock);
2650 /* function to change event enabling information for a particular set */
2651 int afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
2655 ObtainWriteLock(&setp->lock,200);
2656 if (!ICL_EVENTOK(setp, eventID)) {
2657 ReleaseWriteLock(&setp->lock);
2660 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2662 *tp |= ICL_EVENTMASK(eventID);
2664 *tp &= ~(ICL_EVENTMASK(eventID));
2665 ReleaseWriteLock(&setp->lock);
2669 /* return indication of whether a particular event ID is enabled
2670 * for tracing. If *getValuep is set to 0, the event is disabled,
2671 * otherwise it is enabled. All events start out enabled by default.
2673 int afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID,
2676 ObtainReadLock(&setp->lock);
2677 if (!ICL_EVENTOK(setp, eventID)) {
2678 ReleaseWriteLock(&setp->lock);
2681 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2685 ReleaseReadLock(&setp->lock);
2689 /* hold and release event sets */
2690 int afs_icl_SetHold(register struct afs_icl_set *setp)
2692 ObtainWriteLock(&afs_icl_lock,201);
2694 ReleaseWriteLock(&afs_icl_lock);
2698 /* free a set. Called with afs_icl_lock locked */
2699 int afs_icl_ZapSet(register struct afs_icl_set *setp)
2701 register struct afs_icl_set **lpp, *tp;
2703 register struct afs_icl_log *tlp;
2705 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2707 /* found the dude we want to remove */
2709 osi_FreeSmallSpace(setp->name);
2710 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2711 #ifdef KERNEL_HAVE_PIN
2712 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2714 for(i=0; i < ICL_LOGSPERSET; i++) {
2715 if ((tlp = setp->logs[i]))
2716 afs_icl_LogReleNL(tlp);
2718 osi_FreeSmallSpace(setp);
2719 break; /* won't find it twice */
2725 /* do the release, watching for deleted entries */
2726 int afs_icl_SetRele(register struct afs_icl_set *setp)
2728 ObtainWriteLock(&afs_icl_lock,202);
2729 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2730 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2732 ReleaseWriteLock(&afs_icl_lock);
2736 /* free a set entry, dropping its reference count */
2737 int afs_icl_SetFree(register struct afs_icl_set *setp)
2739 ObtainWriteLock(&setp->lock,203);
2740 setp->states |= ICL_SETF_DELETED;
2741 ReleaseWriteLock(&setp->lock);
2742 afs_icl_SetRele(setp);
2746 /* find a set by name, returning it held */
2747 struct afs_icl_set *afs_icl_FindSet(char *name)
2749 register struct afs_icl_set *tp;
2750 ObtainWriteLock(&afs_icl_lock,204);
2751 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2752 if (strcmp(tp->name, name) == 0) {
2753 /* this is the dude we want */
2758 ReleaseWriteLock(&afs_icl_lock);
2762 /* zero out all the logs in the set */
2763 int afs_icl_ZeroSet(struct afs_icl_set *setp)
2768 struct afs_icl_log *logp;
2770 ObtainReadLock(&setp->lock);
2771 for(i = 0; i < ICL_LOGSPERSET; i++) {
2772 logp = setp->logs[i];
2774 afs_icl_LogHold(logp);
2775 tcode = afs_icl_ZeroLog(logp);
2776 if (tcode != 0) code = tcode; /* save the last bad one */
2777 afs_icl_LogRele(logp);
2780 ReleaseReadLock(&setp->lock);
2784 int afs_icl_EnumerateSets(int (*aproc)(), char *arock)
2786 register struct afs_icl_set *tp, *np;
2787 register afs_int32 code;
2790 ObtainWriteLock(&afs_icl_lock,205);
2791 for(tp = afs_icl_allSets; tp; tp=np) {
2792 tp->refCount++; /* hold this guy */
2793 ReleaseWriteLock(&afs_icl_lock);
2794 code = (*aproc)(tp->name, arock, tp);
2795 ObtainWriteLock(&afs_icl_lock,206);
2796 np = tp->nextp; /* tp may disappear next, but not np */
2797 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2801 ReleaseWriteLock(&afs_icl_lock);
2805 int afs_icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
2810 ObtainWriteLock(&setp->lock,207);
2811 for(i = 0; i < ICL_LOGSPERSET; i++) {
2812 if (!setp->logs[i]) {
2813 setp->logs[i] = newlogp;
2815 afs_icl_LogHold(newlogp);
2816 if (!(setp->states & ICL_SETF_FREED)) {
2817 /* bump up the number of sets using the log */
2818 afs_icl_LogUse(newlogp);
2823 ReleaseWriteLock(&setp->lock);
2827 int afs_icl_SetSetStat(struct afs_icl_set *setp, int op)
2831 struct afs_icl_log *logp;
2833 ObtainWriteLock(&setp->lock,208);
2835 case ICL_OP_SS_ACTIVATE: /* activate a log */
2837 * If we are not already active, see if we have released
2838 * our demand that the log be allocated (FREED set). If
2839 * we have, reassert our desire.
2841 if (!(setp->states & ICL_SETF_ACTIVE)) {
2842 if (setp->states & ICL_SETF_FREED) {
2843 /* have to reassert desire for logs */
2844 for(i = 0; i < ICL_LOGSPERSET; i++) {
2845 logp = setp->logs[i];
2847 afs_icl_LogHold(logp);
2848 afs_icl_LogUse(logp);
2849 afs_icl_LogRele(logp);
2852 setp->states &= ~ICL_SETF_FREED;
2854 setp->states |= ICL_SETF_ACTIVE;
2859 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2860 /* this doesn't require anything beyond clearing the ACTIVE flag */
2861 setp->states &= ~ICL_SETF_ACTIVE;
2865 case ICL_OP_SS_FREE: /* deassert design for log */
2867 * if we are already in this state, do nothing; otherwise
2868 * deassert desire for log
2870 if (setp->states & ICL_SETF_ACTIVE)
2873 if (!(setp->states & ICL_SETF_FREED)) {
2874 for(i = 0; i < ICL_LOGSPERSET; i++) {
2875 logp = setp->logs[i];
2877 afs_icl_LogHold(logp);
2878 afs_icl_LogFreeUse(logp);
2879 afs_icl_LogRele(logp);
2882 setp->states |= ICL_SETF_FREED;
2891 ReleaseWriteLock(&setp->lock);