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 "../afs/param.h" /* Should be always first */
11 #include "../afs/sysincludes.h" /* Standard vendor system headers */
12 #include "../afs/afsincludes.h" /* Afs-based standard headers */
13 #include "../afs/afs_stats.h"
14 #include "../rx/rx_globals.h"
15 #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
18 #include "../h/hashing.h"
20 #if !defined(AFS_HPUX110_ENV)
21 #include "netinet/in_var.h"
23 #endif /* !defined(UKERNEL) */
24 #ifdef AFS_LINUX22_ENV
25 #include "../h/smp_lock.h"
29 #if defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
30 #define AFS_MINBUFFERS 100
32 #define AFS_MINBUFFERS 50
36 afs_int32 hosts[MAXCELLHOSTS];
40 char afs_zeros[AFS_ZEROS];
41 char afs_rootVolumeName[64]="";
42 struct afs_icl_set *afs_iclSetp = (struct afs_icl_set*)0;
43 struct afs_icl_set *afs_iclLongTermSetp = (struct afs_icl_set*)0;
45 #if defined(AFS_GLOBAL_SUNLOCK) && !defined(AFS_HPUX_ENV) && !defined(AFS_AIX41_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
47 kmutex_t afs_global_lock;
48 kmutex_t afs_rxglobal_lock;
50 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
51 long afs_global_owner;
55 #if defined(AFS_OSF_ENV)
56 simple_lock_data_t afs_global_lock;
57 #elif defined(AFS_DARWIN_ENV)
58 struct lock__bsd__ afs_global_lock;
60 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
61 thread_t afs_global_owner;
62 #endif /* AFS_OSF_ENV */
64 #if defined(AFS_AIX41_ENV)
65 simple_lock_data afs_global_lock;
68 afs_int32 afs_initState = 0;
69 afs_int32 afs_termState = 0;
70 afs_int32 afs_setTime = 0;
71 int afs_cold_shutdown = 0;
72 char afs_SynchronousCloses = '\0';
73 static int afs_CB_Running = 0;
74 static int AFS_Running = 0;
75 static int afs_CacheInit_Done = 0;
76 static int afs_Go_Done = 0;
77 extern struct interfaceAddr afs_cb_interface;
78 static int afs_RX_Running = 0;
81 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval);
83 #if defined(AFS_HPUX_ENV)
84 extern int afs_vfs_mount();
85 #endif /* defined(AFS_HPUX_ENV) */
87 /* This is code which needs to be called once when the first daemon enters
88 * the client. A non-zero return means an error and AFS should not start.
90 static int afs_InitSetup(int preallocs)
92 extern void afs_InitStats();
97 * Set up all the AFS statistics variables. This should be done
98 * exactly once, and it should be done here, the first resource-setting
99 * routine to be called by the CM/RX.
102 #endif /* AFS_NOSTATS */
104 bzero(afs_zeros, AFS_ZEROS);
107 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
108 code = rx_Init(htons(7001));
110 printf("AFS: RX failed to initialize.\n");
113 rx_SetRxDeadTime(AFS_RXDEADTIME);
114 /* resource init creates the services */
115 afs_ResourceInit(preallocs);
120 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
121 long parm, parm2, parm3, parm4, parm5, parm6;
125 AFS_STATCNT(afs_syscall_call);
127 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
128 && (parm != AFSOP_GETMASK)) {
129 /* only root can run this code */
132 if (!afs_suser() && (parm != AFSOP_GETMTU)
133 && (parm != AFSOP_GETMASK)) {
134 /* only root can run this code */
135 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
139 #if defined(AFS_OSF_ENV)
141 #else /* AFS_OSF_ENV */
148 if (parm == AFSOP_START_RXCALLBACK) {
149 if (afs_CB_Running) goto out;
151 #ifndef RXK_LISTENER_ENV
152 code = afs_InitSetup(parm2);
154 #endif /* RXK_LISTENER_ENV */
156 #ifdef RXK_LISTENER_ENV
157 while (afs_RX_Running != 2)
158 afs_osi_Sleep(&afs_RX_Running);
160 afs_initState = AFSOP_START_AFS;
161 afs_osi_Wakeup(&afs_initState);
162 #endif /* RXK_LISTENER_ENV */
164 afs_RXCallBackServer();
168 exit(CLD_EXITED, code);
171 #ifdef RXK_LISTENER_ENV
172 else if (parm == AFSOP_RXLISTENER_DAEMON) {
173 if (afs_RX_Running) goto out;
175 code = afs_InitSetup(parm2);
177 rx_enablePeerRPCStats();
180 rx_enableProcessRPCStats();
183 afs_initState = AFSOP_START_AFS;
184 afs_osi_Wakeup(&afs_initState);
187 afs_osi_Wakeup(&afs_RX_Running);
192 exit(CLD_EXITED, code);
196 else if (parm == AFSOP_START_AFS) {
200 if (AFS_Running) goto out;
202 while (afs_initState < AFSOP_START_AFS)
203 afs_osi_Sleep(&afs_initState);
205 #if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV)
206 temp = AFS_MINBUFFERS; /* Should fix this soon */
208 temp = ((afs_bufferpages * NBPG)>>11); /* number of 2k buffers we could get from all of the buffer space */
209 temp = temp>>2; /* don't take more than 25% (our magic parameter) */
210 if (temp < AFS_MINBUFFERS) temp = AFS_MINBUFFERS; /* although we really should have this many */
213 afs_initState = AFSOP_START_BKG;
214 afs_osi_Wakeup(&afs_initState);
222 else if (parm == AFSOP_START_CS) {
224 afs_CheckServerDaemon();
230 else if (parm == AFSOP_START_BKG) {
231 while (afs_initState < AFSOP_START_BKG)
232 afs_osi_Sleep(&afs_initState);
233 if (afs_initState < AFSOP_GO) {
234 afs_initState = AFSOP_GO;
235 afs_osi_Wakeup(&afs_initState);
237 /* start the bkg daemon */
241 afs_BioDaemon(parm2);
244 afs_BackgroundDaemon();
250 else if (parm == AFSOP_START_TRUNCDAEMON) {
251 while (afs_initState < AFSOP_GO)
252 afs_osi_Sleep(&afs_initState);
253 /* start the bkg daemon */
255 afs_CacheTruncateDaemon();
261 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
262 else if (parm == AFSOP_RXEVENT_DAEMON) {
263 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
265 afs_rxevent_daemon();
272 else if (parm == AFSOP_ADDCELL) {
273 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
274 name. Parameter 4 is the length of the name, including the null. Parm 5 is the
275 home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
276 struct afsop_cell tcell;
278 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
279 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
281 if (parm4 > sizeof(tcell.cellName))
284 AFS_COPYIN((char *)parm3, tcell.cellName, parm4, code);
286 afs_NewCell(tcell.cellName, tcell.hosts, parm5,
287 (char *)0, (u_short)0, (u_short)0);
290 } else if (parm == AFSOP_ADDCELL2) {
291 struct afsop_cell tcell;
292 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
293 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *cnamep = 0;
294 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV)
296 #else /* AFS_SGI61_ENV */
298 #endif /* AFS_SGI61_ENV */
301 /* wait for basic init */
302 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
304 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
306 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, &bufferSize, code);
309 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
312 cflags |= CLinkedCell;
316 afs_NewCell(tbuffer1, tcell.hosts, cflags,
317 lcnamep, (u_short)0, (u_short)0);
320 osi_FreeSmallSpace(tbuffer);
321 osi_FreeSmallSpace(tbuffer1);
323 else if (parm == AFSOP_CACHEINIT) {
324 struct afs_cacheParams cparms;
326 if (afs_CacheInit_Done) goto out;
328 /* wait for basic init */
329 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
330 AFS_COPYIN((char *)parm2, (caddr_t) &cparms, sizeof(cparms), code);
332 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined (AFS_SGI64_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV)
340 afs_CacheInit_Done = 1;
342 struct afs_icl_log *logp;
343 /* initialize the ICL system */
344 code = afs_icl_CreateLog("cmfx", 60*1024, &logp);
346 code = afs_icl_CreateSetWithFlags("cm", logp,
347 (struct icl_log *) 0,
348 ICL_CRSET_FLAG_DEFAULT_OFF,
350 code = afs_icl_CreateSet("cmlongterm", logp, (struct icl_log*) 0,
351 &afs_iclLongTermSetp);
353 afs_setTime = cparms.setTimeFlag;
355 code = afs_CacheInit(cparms.cacheScaches,
366 else if (parm == AFSOP_CACHEINODE) {
367 ino_t ainode = parm2;
368 /* wait for basic init */
369 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
373 ainode = (ainode << 32) | (parm3 & 0xffffffff);
375 code = afs_InitCacheFile((char *) 0, ainode);
377 else if (parm == AFSOP_ROOTVOLUME) {
378 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV)
380 #else /* AFS_SGI61_ENV */
382 #endif /* AFS_SGI61_ENV */
384 /* wait for basic init */
385 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
388 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code);
389 afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0;
393 else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO ||
394 parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG) {
395 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
396 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV)
398 #else /* AFS_SGI61_ENV */
400 #endif /* AFS_SGI61_ENV */
402 /* wait for basic init */
403 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
405 AFS_COPYINSTR((char *)parm2, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
407 osi_FreeSmallSpace(tbuffer);
411 tbuffer[AFS_SMALLOCSIZ-1] = 0; /* null-terminate the name */
412 /* we now have the cache dir copied in. Call the cache init routines */
413 if (parm == AFSOP_CACHEFILE) code = afs_InitCacheFile(tbuffer, 0);
414 else if (parm == AFSOP_CACHEINFO) code = afs_InitCacheInfo(tbuffer);
415 else if (parm == AFSOP_VOLUMEINFO) code = afs_InitVolumeInfo(tbuffer);
417 osi_FreeSmallSpace(tbuffer);
419 else if (parm == AFSOP_GO) {
420 /* the generic initialization calls come here. One parameter: should we do the
421 set-time operation on this workstation */
422 if (afs_Go_Done) goto out;
424 while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState);
427 afs_osi_Wakeup(&afs_initState);
428 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
429 afs_nfsclient_init();
431 printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused,
432 (100*afs_stats_cmperf.cacheFilesReused) /
433 (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1));
435 else if (parm == AFSOP_ADVISEADDR) {
436 /* pass in the host address to the rx package */
437 afs_int32 count = parm2;
438 afs_int32 buffer[AFS_MAX_INTERFACE_ADDR];
439 afs_int32 maskbuffer[AFS_MAX_INTERFACE_ADDR];
440 afs_int32 mtubuffer[AFS_MAX_INTERFACE_ADDR];
444 if ( count > AFS_MAX_INTERFACE_ADDR ) {
446 count = AFS_MAX_INTERFACE_ADDR;
449 AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code);
451 AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code);
453 AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code);
455 afs_cb_interface.numberOfInterfaces = count;
456 for (i=0; i < count ; i++) {
457 afs_cb_interface.addr_in[i] = buffer[i];
458 #ifdef AFS_USERSPACE_IP_ADDR
459 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
460 * machines IP addresses when in the kernel (the in_ifaddr
461 * struct is not available), so we pass the info in at
462 * startup. We also pass in the subnetmask and mtu size. The
463 * subnetmask is used when setting the rank:
464 * afsi_SetServerIPRank(); and the mtu size is used when
465 * finding the best mtu size. rxi_FindIfnet() is replaced
466 * with rxi_Findcbi().
468 afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff);
469 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
472 afs_uuid_create(&afs_cb_interface.uuid);
473 rxi_setaddr(buffer[0]);
477 else if (parm == AFSOP_NFSSTATICADDR) {
478 extern int (*nfs_rfsdisptab_v2)();
479 nfs_rfsdisptab_v2 = (int (*)())parm2;
481 else if (parm == AFSOP_NFSSTATICADDR2) {
482 extern int (*nfs_rfsdisptab_v2)();
484 nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
486 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
489 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
490 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
491 extern int (*afs_sblockp)();
492 extern void (*afs_sbunlockp)();
494 afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
495 afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff));
497 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
498 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
501 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
502 #endif /* AFS_SGI53_ENV */
503 else if (parm == AFSOP_SHUTDOWN) {
504 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
505 extern struct mount *afs_globalVFS;
506 #else /* AFS_OSF_ENV */
507 extern struct vfs *afs_globalVFS;
509 afs_cold_shutdown = 0;
510 if (parm == 1) afs_cold_shutdown = 1;
511 if (afs_globalVFS != 0) {
512 afs_warn("AFS isn't unmounted yet! Call aborted\n");
518 #if ! defined(AFS_HPUX90_ENV) || defined(AFS_HPUX100_ENV)
519 else if (parm == AFSOP_AFS_VFSMOUNT) {
521 #if defined(AFS_HPUX100_ENV)
522 vfsmount(parm2, parm3, parm4, parm5);
524 afs_vfs_mount(parm2, parm3, parm4, parm5);
525 #endif /* AFS_HPUX100_ENV */
526 #else /* defined(AFS_HPUX_ENV) */
527 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV)
532 #endif /* defined(AFS_HPUX_ENV) */
535 else if (parm == AFSOP_CLOSEWAIT) {
536 afs_SynchronousCloses = 'S';
538 else if (parm == AFSOP_GETMTU) {
540 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
541 #ifdef AFS_USERSPACE_IP_ADDR
543 i = rxi_Findcbi(parm2);
544 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
545 #else /* AFS_USERSPACE_IP_ADDR */
547 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
548 extern struct ifnet *rxi_FindIfnet();
550 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
551 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
552 #endif /* else AFS_USERSPACE_IP_ADDR */
553 #endif /* !AFS_SUN5_ENV */
555 AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code);
557 /* this is disabled for now because I can't figure out how to get access
558 * to these kernel variables. It's only for supporting user-mode rx
559 * programs -- it makes a huge difference on the 220's in my testbed,
560 * though I don't know why. The bosserver does this with /etc/no, so it's
561 * being handled a different way for the servers right now. */
564 extern u_long sb_max_dflt;
567 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
568 if (sb_max < 131072) sb_max = 131072;
571 #endif /* AFS_AIX32_ENV */
573 else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
575 #if !defined(AFS_SUN5_ENV)
576 #ifdef AFS_USERSPACE_IP_ADDR
578 i = rxi_Findcbi(parm2);
580 mask = afs_cb_interface.subnetmask[i];
584 #else /* AFS_USERSPACE_IP_ADDR */
586 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
587 extern struct ifnet *rxi_FindIfnet();
588 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
589 if (tifnp && tifadp) {
590 mask = tifadp->ia_subnetmask;
594 #endif /* else AFS_USERSPACE_IP_ADDR */
595 #endif /* !AFS_SUN5_ENV */
597 AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code);
603 #ifdef AFS_LINUX20_ENV
612 #include "sys/lockl.h"
615 * syscall - this is the VRMIX system call entry point.
618 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
619 * all the user-level calls to `syscall' to change.
621 syscall(syscall, p1, p2, p3, p4, p5, p6) {
622 register rval1=0, code;
625 #ifndef AFS_AIX41_ENV
626 extern lock_t kernel_lock;
627 monster = lockl(&kernel_lock, LOCK_SHORT);
628 #endif /* !AFS_AIX41_ENV */
630 AFS_STATCNT(syscall);
634 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
639 rval1 = afs_setpag();
645 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
649 case AFSCALL_ICREATE:
650 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
654 rval1 = afs_syscall_iopen(p1, p2, p3);
658 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
662 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
667 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
669 if (!code) rval1 = retval;
670 if (!rval1) rval1 = code;
680 #ifndef AFS_AIX41_ENV
681 if (monster != LOCK_NEST)
682 unlockl(&kernel_lock);
683 #endif /* !AFS_AIX41_ENV */
684 return getuerror() ? -1 : rval1;
688 * lsetpag - interface to afs_setpag().
692 AFS_STATCNT(lsetpag);
693 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
697 * lpioctl - interface to pioctl()
699 lpioctl(path, cmd, cmarg, follow)
700 char *path, *cmarg; {
702 AFS_STATCNT(lpioctl);
703 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
706 #else /* !AFS_AIX32_ENV */
708 #if defined(AFS_SGI_ENV)
721 Afs_syscall (struct afsargs *uap, rval_t *rvp)
726 AFS_STATCNT(afs_syscall);
727 switch(uap->syscall) {
731 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
733 rvp->r_val1 = retval;
735 #ifdef AFS_SGI_XFS_IOPS_ENV
737 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
738 uap->parm4, uap->parm5);
741 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
742 uap->parm4, uap->parm5);
744 case AFSCALL_ILISTINODE64:
745 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
746 uap->parm4, uap->parm5);
748 case AFSCALL_ICREATENAME64:
749 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
750 uap->parm4, uap->parm5);
753 #ifdef AFS_SGI_VNODE_GLUE
754 case AFSCALL_INIT_KERNEL_CONFIG:
755 error = afs_init_kernel_config(uap->parm1);
759 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
760 uap->parm3, uap->parm4, uap->parm5);
765 #else /* AFS_SGI_ENV */
783 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
785 dst->param1 = src->param1;
786 dst->param2 = src->param2;
787 dst->param3 = src->param3;
788 dst->param4 = src->param4;
792 * If you need to change copyin_iparam(), you may also need to change
793 * copyin_afs_ioctl().
797 copyin_iparam(caddr_t cmarg, struct iparam *dst)
801 #if defined(AFS_HPUX_64BIT_ENV)
802 struct iparam32 dst32;
804 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
806 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
808 iparam32_to_iparam(&dst32, dst);
811 #endif /* AFS_HPUX_64BIT_ENV */
813 #if defined(AFS_SUN57_64BIT_ENV)
814 struct iparam32 dst32;
816 if (get_udatamodel() == DATAMODEL_ILP32) {
817 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
819 iparam32_to_iparam(&dst32, dst);
822 #endif /* AFS_SUN57_64BIT_ENV */
824 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV)
825 struct iparam32 dst32;
827 #ifdef AFS_SPARC64_LINUX20_ENV
828 if (current->tss.flags & SPARC_FLAG_32BIT)
830 #error Not done for this linux version
831 #endif /* AFS_SPARC64_LINUX20_ENV */
833 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
835 iparam32_to_iparam(&dst32, dst);
838 #endif /* AFS_LINUX_64BIT_KERNEL */
840 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
844 /* Main entry of all afs system calls */
846 extern int afs_sinited;
848 /** The 32 bit OS expects the members of this structure to be 32 bit
849 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
850 * to accomodate both, *long* is used instead of afs_int32
875 Afs_syscall (uap, rvp)
876 register struct afssysa *uap;
879 int *retval = &rvp->r_val1;
880 #else /* AFS_SUN5_ENV */
881 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
882 afs3_syscall(p, args, retval)
895 } *uap = (struct a *)args;
896 #else /* AFS_OSF_ENV */
897 #ifdef AFS_LINUX20_ENV
905 long parm6; /* not actually used - should be removed */
907 /* Linux system calls only set up for 5 arguments. */
908 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
911 struct afssysargs args, *uap = &args;
913 long *retval = &linux_ret;
914 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
927 } *uap = (struct a *)u.u_ap;
929 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
933 #endif /* SUN && !SUN5 */
943 } *uap = (struct a *)u.u_ap;
945 #if defined(AFS_DEC_ENV)
946 int *retval = &u.u_r.r_val1;
948 #if defined(AFS_HPUX_ENV)
949 long *retval = &u.u_rval1;
951 int *retval = &u.u_rval1;
954 #endif /* AFS_LINUX20_ENV */
955 #endif /* AFS_OSF_ENV */
956 #endif /* AFS_SUN5_ENV */
957 register int code = 0;
959 AFS_STATCNT(afs_syscall);
966 #ifdef AFS_LINUX20_ENV
968 /* setup uap for use below - pull out the magic decoder ring to know
969 * which syscalls have folded argument lists.
971 uap->syscall = syscall;
975 if (syscall == AFSCALL_ICL) {
976 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
977 uap->parm4 = eparm[0];
978 uap->parm5 = eparm[1];
979 uap->parm6 = eparm[2];
988 #if defined(AFS_HPUX_ENV)
990 * There used to be code here (duplicated from osi_Init()) for
991 * initializing the semaphore used by AFS_GLOCK(). Was the
992 * duplication to handle the case of a dynamically loaded kernel
997 if (uap->syscall == AFSCALL_CALL) {
999 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1000 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1002 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1004 } else if (uap->syscall == AFSCALL_SETPAG) {
1007 register proc_t *procp;
1009 procp = ttoproc(curthread);
1010 mutex_enter(&procp->p_crlock);
1011 cred = procp->p_cred;
1013 code = afs_setpag(&cred);
1015 procp->p_cred = cred;
1016 mutex_exit(&procp->p_crlock);
1019 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
1020 code = afs_setpag(p, args, retval);
1021 #else /* AFS_OSF_ENV */
1022 code = afs_setpag();
1026 } else if (uap->syscall == AFSCALL_PIOCTL) {
1029 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1031 #ifdef AFS_DARWIN_ENV
1032 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1034 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1038 } else if (uap->syscall == AFSCALL_ICREATE) {
1039 struct iparam iparams;
1041 code = copyin_iparam((char *)uap->parm3, &iparams);
1043 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
1048 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1049 iparams.param3, iparams.param4, rvp, CRED());
1051 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1052 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
1053 iparams.param3, iparams.param4, retval);
1055 iparams.param3, iparams.param4);
1057 #endif /* AFS_SUN5_ENV */
1058 } else if (uap->syscall == AFSCALL_IOPEN) {
1060 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1062 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
1063 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1065 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1067 #endif /* AFS_SUN5_ENV */
1068 } else if (uap->syscall == AFSCALL_IDEC) {
1070 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1072 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1073 #endif /* AFS_SUN5_ENV */
1074 } else if (uap->syscall == AFSCALL_IINC) {
1076 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1078 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1079 #endif /* AFS_SUN5_ENV */
1080 } else if (uap->syscall == AFSCALL_ICL) {
1082 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1084 #ifdef AFS_LINUX20_ENV
1086 /* ICL commands can return values. */
1087 code = -linux_ret; /* Gets negated again at exit below */
1091 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV)
1095 #endif /* !AFS_LINUX20_ENV */
1097 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV)
1101 #endif /* AFS_SUN5_ENV */
1104 #ifdef AFS_LINUX20_ENV
1110 #endif /* AFS_SGI_ENV */
1111 #endif /* !AFS_AIX32_ENV */
1114 * Initstate in the range 0 < x < 100 are early initialization states.
1115 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1116 * the cache may be initialized.
1117 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1118 * is done after all the cache initialization has been done.
1119 * Initstate of 200 means that the volume has been looked up once, possibly
1121 * Initstate of 300 means that the volume has been *successfully* looked up.
1124 register int code = 0;
1126 AFS_STATCNT(afs_CheckInit);
1127 if (afs_initState <= 100)
1128 code = ENXIO; /* never finished init phase */
1129 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1130 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1131 } else if (afs_initState == 200)
1132 code = ETIMEDOUT; /* didn't find root volume */
1136 int afs_shuttingdown = 0;
1140 extern short afs_brsDaemons;
1141 extern afs_int32 afs_CheckServerDaemonStarted;
1142 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1143 extern struct osi_file *afs_cacheInodep;
1145 AFS_STATCNT(afs_shutdown);
1146 if (afs_shuttingdown) return;
1147 afs_shuttingdown = 1;
1148 if (afs_cold_shutdown) afs_warn("COLD ");
1149 else afs_warn("WARM ");
1150 afs_warn("shutting down of: CB... ");
1152 afs_termState = AFSOP_STOP_RXCALLBACK;
1153 rx_WakeupServerProcs();
1154 /* shutdown_rxkernel(); */
1155 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1156 afs_osi_Sleep(&afs_termState);
1158 afs_warn("afs... ");
1159 while (afs_termState == AFSOP_STOP_AFS) {
1160 afs_osi_CancelWait(&AFS_WaitHandler);
1161 afs_osi_Sleep(&afs_termState);
1163 if (afs_CheckServerDaemonStarted) {
1164 while (afs_termState == AFSOP_STOP_CS) {
1165 afs_osi_CancelWait(&AFS_CSWaitHandler);
1166 afs_osi_Sleep(&afs_termState);
1169 afs_warn("BkG... ");
1170 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1171 while (afs_termState == AFSOP_STOP_BKG) {
1172 afs_osi_Wakeup(&afs_brsDaemons);
1173 afs_osi_Sleep(&afs_termState);
1175 afs_warn("CTrunc... ");
1176 /* Cancel cache truncate daemon. */
1177 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1178 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1179 afs_osi_Sleep(&afs_termState);
1181 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1182 afs_warn("RxEvent... ");
1183 /* cancel rx event deamon */
1184 while (afs_termState == AFSOP_STOP_RXEVENT)
1185 afs_osi_Sleep(&afs_termState);
1186 #if defined(RXK_LISTENER_ENV)
1187 afs_warn("RxListener... ");
1188 /* cancel rx listener */
1189 osi_StopListener(); /* This closes rx_socket. */
1190 while (afs_termState == AFSOP_STOP_RXK_LISTENER)
1191 afs_osi_Sleep(&afs_termState);
1194 afs_termState = AFSOP_STOP_COMPLETE;
1198 /* Close file only after daemons which can write to it are stopped. */
1199 if (afs_cacheInodep) /* memcache won't set this */
1201 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1202 afs_cacheInodep = 0;
1204 return; /* Just kill daemons for now */
1208 shutdown_rxkernel();
1212 shutdown_bufferpackage();
1218 shutdown_vnodeops();
1220 shutdown_exporter();
1221 shutdown_memcache();
1222 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1223 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1224 /* this routine does not exist in Ultrix systems... 93.01.19 */
1226 #endif /* AFS_DEC_ENV */
1229 /* The following hold the cm stats */
1231 bzero(&afs_cmstats, sizeof(struct afs_CMStats));
1232 bzero(&afs_stats_cmperf, sizeof(struct afs_stats_CMPerf));
1233 bzero(&afs_stats_cmfullperf, sizeof(struct afs_stats_CMFullPerf));
1235 afs_warn(" ALL allocated tables\n");
1236 afs_shuttingdown = 0;
1242 AFS_STATCNT(shutdown_afstest);
1243 afs_initState = afs_termState = afs_setTime = 0;
1244 AFS_Running = afs_CB_Running = 0;
1245 afs_CacheInit_Done = afs_Go_Done = 0;
1246 if (afs_cold_shutdown) {
1247 *afs_rootVolumeName = 0;
1252 /* In case there is a bunch of dynamically build bkg daemons to free */
1254 { AFS_STATCNT(shutdown_BKG); }
1257 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1258 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1259 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1260 int afs_icl_sizeofLong = 1;
1262 int afs_icl_sizeofLong = 2;
1265 int afs_icl_sizeofLong = 1;
1268 int afs_icl_inited = 0;
1270 /* init function, called once, under afs_icl_lock */
1277 extern struct afs_icl_log *afs_icl_FindLog();
1278 extern struct afs_icl_set *afs_icl_FindSet();
1282 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1285 afs_int32 *lp, elts, flags;
1286 register afs_int32 code;
1287 struct afs_icl_log *logp;
1288 struct afs_icl_set *setp;
1289 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV)
1291 #else /* AFS_SGI61_ENV */
1293 #endif /* AFS_SGI61_ENV */
1295 afs_int32 startCookie;
1296 afs_int32 allocated;
1297 struct afs_icl_log *tlp;
1300 if (!afs_suser(CRED())) { /* only root can run this code */
1304 if (!afs_suser()) { /* only root can run this code */
1305 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
1314 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1315 case ICL_OP_COPYOUT: /* copy ouy data */
1316 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1317 * return flags<<24 + nwords.
1318 * updates cookie to updated start (not end) if we had to
1319 * skip some records.
1321 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1322 if (code) return code;
1323 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1324 if (code) return code;
1325 logp = afs_icl_FindLog(tname);
1326 if (!logp) return ENOENT;
1327 #define BUFFERSIZE AFS_LRALLOCSIZ
1328 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1329 elts = BUFFERSIZE / sizeof(afs_int32);
1330 if (p3 < elts) elts = p3;
1331 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1332 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1335 osi_FreeLargeSpace((struct osi_buffer *) lp);
1338 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1339 if (code) goto done;
1340 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1341 if (code) goto done;
1342 *retval = (flags<<24) | (elts & 0xffffff);
1344 afs_icl_LogRele(logp);
1345 osi_FreeLargeSpace((struct osi_buffer *) lp);
1348 case ICL_OP_ENUMLOGS: /* enumerate logs */
1349 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1350 * return 0 for success, otherwise error.
1352 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1353 if (p1-- == 0) break;
1355 if (!tlp) return ENOENT; /* past the end of file */
1356 temp = strlen(tlp->name)+1;
1357 if (temp > p3) return EINVAL;
1358 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1359 if (!code) /* copy out size of log */
1360 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1363 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1364 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1365 * return 0 for success, otherwise error.
1367 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1368 if (code) return code;
1369 setp = afs_icl_FindSet(tname);
1370 if (!setp) return ENOENT;
1371 if (p2 > ICL_LOGSPERSET)
1373 if (!(tlp = setp->logs[p2]))
1375 temp = strlen(tlp->name)+1;
1376 if (temp > p4) return EINVAL;
1377 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1380 case ICL_OP_CLRLOG: /* clear specified log */
1381 /* zero out the specified log: p1=logname */
1382 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1383 if (code) return code;
1384 logp = afs_icl_FindLog(tname);
1385 if (!logp) return ENOENT;
1386 code = afs_icl_ZeroLog(logp);
1387 afs_icl_LogRele(logp);
1390 case ICL_OP_CLRSET: /* clear specified set */
1391 /* zero out the specified set: p1=setname */
1392 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1393 if (code) return code;
1394 setp = afs_icl_FindSet(tname);
1395 if (!setp) return ENOENT;
1396 code = afs_icl_ZeroSet(setp);
1397 afs_icl_SetRele(setp);
1400 case ICL_OP_CLRALL: /* clear all logs */
1401 /* zero out all logs -- no args */
1403 ObtainWriteLock(&afs_icl_lock,178);
1404 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1405 tlp->refCount++; /* hold this guy */
1406 ReleaseWriteLock(&afs_icl_lock);
1407 /* don't clear persistent logs */
1408 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1409 code = afs_icl_ZeroLog(tlp);
1410 ObtainWriteLock(&afs_icl_lock,179);
1411 if (--tlp->refCount == 0)
1412 afs_icl_ZapLog(tlp);
1415 ReleaseWriteLock(&afs_icl_lock);
1418 case ICL_OP_ENUMSETS: /* enumerate all sets */
1419 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1420 * return 0 for success, otherwise error.
1422 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1423 if (p1-- == 0) break;
1425 if (!setp) return ENOENT; /* past the end of file */
1426 temp = strlen(setp->name)+1;
1427 if (temp > p3) return EINVAL;
1428 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1429 if (!code) /* copy out size of log */
1430 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1433 case ICL_OP_SETSTAT: /* set status on a set */
1434 /* activate the specified set: p1=setname, p2=op */
1435 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1436 if (code) return code;
1437 setp = afs_icl_FindSet(tname);
1438 if (!setp) return ENOENT;
1439 code = afs_icl_SetSetStat(setp, p2);
1440 afs_icl_SetRele(setp);
1443 case ICL_OP_SETSTATALL: /* set status on all sets */
1444 /* activate the specified set: p1=op */
1446 ObtainWriteLock(&afs_icl_lock,180);
1447 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1448 setp->refCount++; /* hold this guy */
1449 ReleaseWriteLock(&afs_icl_lock);
1450 /* don't set states on persistent sets */
1451 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1452 code = afs_icl_SetSetStat(setp, p1);
1453 ObtainWriteLock(&afs_icl_lock,181);
1454 if (--setp->refCount == 0)
1455 afs_icl_ZapSet(setp);
1458 ReleaseWriteLock(&afs_icl_lock);
1461 case ICL_OP_SETLOGSIZE: /* set size of log */
1462 /* set the size of the specified log: p1=logname, p2=size (in words) */
1463 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1464 if (code) return code;
1465 logp = afs_icl_FindLog(tname);
1466 if (!logp) return ENOENT;
1467 code = afs_icl_LogSetSize(logp, p2);
1468 afs_icl_LogRele(logp);
1471 case ICL_OP_GETLOGINFO: /* get size of log */
1472 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1473 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1474 if (code) return code;
1475 logp = afs_icl_FindLog(tname);
1476 if (!logp) return ENOENT;
1477 allocated = !!logp->datap;
1478 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1480 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1481 afs_icl_LogRele(logp);
1484 case ICL_OP_GETSETINFO: /* get state of set */
1485 /* zero out the specified set: p1=setname, p2=&state */
1486 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1487 if (code) return code;
1488 setp = afs_icl_FindSet(tname);
1489 if (!setp) return ENOENT;
1490 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1491 afs_icl_SetRele(setp);
1502 afs_lock_t afs_icl_lock;
1504 /* exported routine: a 4 parameter event */
1505 afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, p4)
1506 register struct afs_icl_set *setp;
1509 long p1, p2, p3, p4;
1511 register struct afs_icl_log *logp;
1514 register afs_int32 tmask;
1517 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1518 if (!ICL_SETACTIVE(setp)) return;
1521 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1522 ix = ICL_EVENTBYTE(eventID);
1523 ObtainReadLock(&setp->lock);
1524 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1525 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1527 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1531 if (mask == 0) break; /* break early */
1534 ReleaseReadLock(&setp->lock);
1537 /* Next 4 routines should be implemented via var-args or something.
1538 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1539 * Otherwise, could call afs_icl_Event4 directly.
1541 afs_icl_Event3(setp, eventID, lAndT, p1, p2, p3)
1542 register struct afs_icl_set *setp;
1547 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1550 afs_icl_Event2(setp, eventID, lAndT, p1, p2)
1551 register struct afs_icl_set *setp;
1556 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1559 afs_icl_Event1(setp, eventID, lAndT, p1)
1560 register struct afs_icl_set *setp;
1565 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1568 afs_icl_Event0(setp, eventID, lAndT)
1569 register struct afs_icl_set *setp;
1573 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1576 struct afs_icl_log *afs_icl_allLogs = 0;
1578 /* function to purge records from the start of the log, until there
1579 * is at least minSpace long's worth of space available without
1580 * making the head and the tail point to the same word.
1582 * Log must be write-locked.
1584 static afs_icl_GetLogSpace(logp, minSpace)
1585 register struct afs_icl_log *logp;
1588 register unsigned int tsize;
1590 while (logp->logSize - logp->logElements <= minSpace) {
1592 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1593 logp->logElements -= tsize;
1594 logp->firstUsed += tsize;
1595 if (logp->firstUsed >= logp->logSize)
1596 logp->firstUsed -= logp->logSize;
1597 logp->baseCookie += tsize;
1601 /* append string astr to buffer, including terminating null char.
1603 * log must be write-locked.
1605 #define ICL_CHARSPERLONG 4
1606 static afs_int32 afs_icl_AppendString(logp, astr)
1607 struct afs_icl_log *logp;
1610 char *op; /* ptr to char to write */
1612 register int bib; /* bytes in buffer */
1615 op = (char *) &(logp->datap[logp->firstFree]);
1619 if (++bib >= ICL_CHARSPERLONG) {
1622 if (++(logp->firstFree) >= logp->logSize) {
1623 logp->firstFree = 0;
1624 op = (char *) &(logp->datap[0]);
1626 logp->logElements++;
1631 /* if we've used this word at all, allocate it */
1632 if (++(logp->firstFree) >= logp->logSize) {
1633 logp->firstFree = 0;
1635 logp->logElements++;
1639 /* add a long to the log, ignoring overflow (checked already) */
1640 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1641 #define ICL_APPENDINT32(lp, x) \
1643 (lp)->datap[(lp)->firstFree] = (x); \
1644 if (++((lp)->firstFree) >= (lp)->logSize) { \
1645 (lp)->firstFree = 0; \
1647 (lp)->logElements++; \
1650 #define ICL_APPENDLONG(lp, x) \
1652 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1653 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1656 #else /* AFS_ALPHA_ENV */
1657 #define ICL_APPENDLONG(lp, x) \
1659 (lp)->datap[(lp)->firstFree] = (x); \
1660 if (++((lp)->firstFree) >= (lp)->logSize) { \
1661 (lp)->firstFree = 0; \
1663 (lp)->logElements++; \
1665 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1666 #endif /* AFS_ALPHA_ENV */
1668 /* routine to tell whether we're dealing with the address or the
1671 afs_icl_UseAddr(type)
1674 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1675 || type == ICL_TYPE_FID)
1681 /* Function to append a record to the log. Written for speed
1682 * since we know that we're going to have to make this work fast
1683 * pretty soon, anyway. The log must be unlocked.
1686 afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4)
1687 register struct afs_icl_log *logp;
1690 long p1, p2, p3, p4;
1692 int rsize; /* record size in longs */
1693 register int tsize; /* temp size */
1697 t4 = types & 0x3f; /* decode types */
1705 osi_GetTime(&tv); /* It panics for solaris if inside */
1706 ObtainWriteLock(&logp->lock,182);
1708 ReleaseWriteLock(&logp->lock);
1712 /* get timestamp as # of microseconds since some time that doesn't
1713 * change that often. This algorithm ticks over every 20 minutes
1714 * or so (1000 seconds). Write a timestamp record if it has.
1716 if (tv.tv_sec - logp->lastTS > 1024)
1718 /* the timer has wrapped -- write a timestamp record */
1719 if (logp->logSize - logp->logElements <= 5)
1720 afs_icl_GetLogSpace(logp, 5);
1722 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1723 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1724 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1725 ICL_APPENDINT32(logp,
1726 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1727 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1729 logp->lastTS = tv.tv_sec;
1732 rsize = 4; /* base case */
1734 /* compute size of parameter p1. Only tricky case is string.
1735 * In that case, we have to call strlen to get the string length.
1737 ICL_SIZEHACK(t1, p1);
1740 /* compute size of parameter p2. Only tricky case is string.
1741 * In that case, we have to call strlen to get the string length.
1743 ICL_SIZEHACK(t2, p2);
1746 /* compute size of parameter p3. Only tricky case is string.
1747 * In that case, we have to call strlen to get the string length.
1749 ICL_SIZEHACK(t3, p3);
1752 /* compute size of parameter p4. Only tricky case is string.
1753 * In that case, we have to call strlen to get the string length.
1755 ICL_SIZEHACK(t4, p4);
1758 /* At this point, we've computed all of the parameter sizes, and
1759 * have in rsize the size of the entire record we want to append.
1760 * Next, we check that we actually have room in the log to do this
1761 * work, and then we do the append.
1764 ReleaseWriteLock(&logp->lock);
1765 return; /* log record too big to express */
1768 if (logp->logSize - logp->logElements <= rsize)
1769 afs_icl_GetLogSpace(logp, rsize);
1771 ICL_APPENDINT32(logp,
1772 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
1773 ICL_APPENDINT32(logp, (afs_int32)op);
1774 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
1775 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1778 /* marshall parameter 1 now */
1779 if (t1 == ICL_TYPE_STRING) {
1780 afs_icl_AppendString(logp, (char *) p1);
1782 else if (t1 == ICL_TYPE_HYPER) {
1783 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
1784 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
1786 else if (t1 == ICL_TYPE_FID) {
1787 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1788 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1789 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
1790 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
1792 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1793 else if (t1 == ICL_TYPE_INT32)
1794 ICL_APPENDINT32(logp, (afs_int32)p1);
1795 #endif /* AFS_ALPHA_ENV */
1796 else ICL_APPENDLONG(logp, p1);
1799 /* marshall parameter 2 now */
1800 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
1801 else if (t2 == ICL_TYPE_HYPER) {
1802 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
1803 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
1805 else if (t2 == ICL_TYPE_FID) {
1806 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1807 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1808 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
1809 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
1811 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1812 else if (t2 == ICL_TYPE_INT32)
1813 ICL_APPENDINT32(logp, (afs_int32)p2);
1814 #endif /* AFS_ALPHA_ENV */
1815 else ICL_APPENDLONG(logp, p2);
1818 /* marshall parameter 3 now */
1819 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
1820 else if (t3 == ICL_TYPE_HYPER) {
1821 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
1822 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
1824 else if (t3 == ICL_TYPE_FID) {
1825 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1826 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1827 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
1828 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
1830 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1831 else if (t3 == ICL_TYPE_INT32)
1832 ICL_APPENDINT32(logp, (afs_int32)p3);
1833 #endif /* AFS_ALPHA_ENV */
1834 else ICL_APPENDLONG(logp, p3);
1837 /* marshall parameter 4 now */
1838 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
1839 else if (t4 == ICL_TYPE_HYPER) {
1840 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
1841 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
1843 else if (t4 == ICL_TYPE_FID) {
1844 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
1845 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
1846 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
1847 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
1849 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1850 else if (t4 == ICL_TYPE_INT32)
1851 ICL_APPENDINT32(logp, (afs_int32)p4);
1852 #endif /* AFS_ALPHA_ENV */
1853 else ICL_APPENDLONG(logp, p4);
1855 ReleaseWriteLock(&logp->lock);
1858 /* create a log with size logSize; return it in *outLogpp and tag
1859 * it with name "name."
1861 afs_icl_CreateLog(name, logSize, outLogpp)
1864 struct afs_icl_log **outLogpp;
1866 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
1869 /* create a log with size logSize; return it in *outLogpp and tag
1870 * it with name "name." 'flags' can be set to make the log unclearable.
1872 afs_icl_CreateLogWithFlags(name, logSize, flags, outLogpp)
1876 struct afs_icl_log **outLogpp;
1878 register struct afs_icl_log *logp;
1880 /* add into global list under lock */
1881 ObtainWriteLock(&afs_icl_lock,183);
1882 if (!afs_icl_inited) afs_icl_Init();
1884 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
1885 if (strcmp(logp->name, name) == 0) {
1886 /* found it already created, just return it */
1889 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
1891 ObtainWriteLock(&logp->lock,184);
1892 logp->states |= ICL_LOGF_PERSISTENT;
1893 ReleaseWriteLock(&logp->lock);
1895 ReleaseWriteLock(&afs_icl_lock);
1900 logp = (struct afs_icl_log *)
1901 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
1902 bzero((caddr_t)logp, sizeof(*logp));
1905 logp->name = osi_AllocSmallSpace(strlen(name)+1);
1906 strcpy(logp->name, name);
1907 LOCK_INIT(&logp->lock, "logp lock");
1908 logp->logSize = logSize;
1909 logp->datap = (afs_int32 *)0; /* don't allocate it until we need it */
1911 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
1912 logp->states |= ICL_LOGF_PERSISTENT;
1914 logp->nextp = afs_icl_allLogs;
1915 afs_icl_allLogs = logp;
1916 ReleaseWriteLock(&afs_icl_lock);
1922 /* called with a log, a pointer to a buffer, the size of the buffer
1923 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
1924 * and returns data in the provided buffer, and returns output flags
1925 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
1926 * find the record with cookie value cookie.
1928 afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp)
1929 register struct afs_icl_log *logp;
1931 afs_int32 *bufSizep;
1932 afs_uint32 *cookiep;
1935 afs_int32 nwords; /* number of words to copy out */
1936 afs_uint32 startCookie; /* first cookie to use */
1937 register afs_int32 i;
1938 afs_int32 outWords; /* words we've copied out */
1939 afs_int32 inWords; /* max words to copy out */
1940 afs_int32 code; /* return code */
1941 afs_int32 ix; /* index we're copying from */
1942 afs_int32 outFlags; /* return flags */
1943 afs_int32 inFlags; /* flags passed in */
1946 inWords = *bufSizep; /* max to copy out */
1947 outWords = 0; /* amount copied out */
1948 startCookie = *cookiep;
1953 ObtainWriteLock(&logp->lock,185);
1955 ReleaseWriteLock(&logp->lock);
1959 /* first, compute the index of the start cookie we've been passed */
1961 /* (re-)compute where we should start */
1962 if (startCookie < logp->baseCookie) {
1963 if (startCookie) /* missed some output */
1964 outFlags |= ICL_COPYOUTF_MISSEDSOME;
1965 /* skip to the first available record */
1966 startCookie = logp->baseCookie;
1967 *cookiep = startCookie;
1970 /* compute where we find the first element to copy out */
1971 ix = logp->firstUsed + startCookie - logp->baseCookie;
1972 if (ix >= logp->logSize) ix -= logp->logSize;
1974 /* if have some data now, break out and process it */
1975 if (startCookie - logp->baseCookie < logp->logElements) break;
1977 /* At end of log, so clear it if we need to */
1978 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
1980 logp->firstUsed = logp->firstFree = 0;
1981 logp->logElements = 0;
1983 /* otherwise, either wait for the data to arrive, or return */
1984 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
1985 ReleaseWriteLock(&logp->lock);
1989 logp->states |= ICL_LOGF_WAITING;
1990 ReleaseWriteLock(&logp->lock);
1991 afs_osi_Sleep(&logp->lock);
1992 ObtainWriteLock(&logp->lock,186);
1994 /* copy out data from ix to logSize or firstFree, depending
1995 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
1996 * be careful not to copy out more than nwords.
1998 if (ix >= logp->firstUsed) {
1999 if (logp->firstUsed <= logp->firstFree)
2001 end = logp->firstFree; /* first element not to copy */
2003 end = logp->logSize;
2004 nwords = inWords; /* don't copy more than this */
2005 if (end - ix < nwords)
2008 bcopy((char *) &logp->datap[ix], (char *) bufferp,
2009 sizeof(afs_int32) * nwords);
2014 /* if we're going to copy more out below, we'll start here */
2017 /* now, if active part of the log has wrapped, there's more stuff
2018 * starting at the head of the log. Copy out more from there.
2020 if (logp->firstUsed > logp->firstFree
2021 && ix < logp->firstFree && inWords > 0) {
2022 /* (more to) copy out from the wrapped section at the
2023 * start of the log. May get here even if didn't copy any
2024 * above, if the cookie points directly into the wrapped section.
2027 if (logp->firstFree - ix < nwords)
2028 nwords = logp->firstFree - ix;
2029 bcopy((char *) &logp->datap[ix], (char *) bufferp,
2030 sizeof(afs_int32) * nwords);
2036 ReleaseWriteLock(&logp->lock);
2040 *bufSizep = outWords;
2046 /* return basic parameter information about a log */
2047 afs_icl_GetLogParms(logp, maxSizep, curSizep)
2048 struct afs_icl_log *logp;
2049 afs_int32 *maxSizep;
2050 afs_int32 *curSizep;
2052 ObtainReadLock(&logp->lock);
2053 *maxSizep = logp->logSize;
2054 *curSizep = logp->logElements;
2055 ReleaseReadLock(&logp->lock);
2060 /* hold and release logs */
2061 afs_icl_LogHold(logp)
2062 register struct afs_icl_log *logp;
2064 ObtainWriteLock(&afs_icl_lock,187);
2066 ReleaseWriteLock(&afs_icl_lock);
2070 /* hold and release logs, called with lock already held */
2071 afs_icl_LogHoldNL(logp)
2072 register struct afs_icl_log *logp;
2078 /* keep track of how many sets believe the log itself is allocated */
2079 afs_icl_LogUse(logp)
2080 register struct afs_icl_log *logp;
2082 ObtainWriteLock(&logp->lock,188);
2083 if (logp->setCount == 0) {
2084 /* this is the first set actually using the log -- allocate it */
2085 if (logp->logSize == 0) {
2086 /* we weren't passed in a hint and it wasn't set */
2087 logp->logSize = ICL_DEFAULT_LOGSIZE;
2089 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2090 #ifdef AFS_AIX32_ENV
2091 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2095 ReleaseWriteLock(&logp->lock);
2099 /* decrement the number of real users of the log, free if possible */
2100 afs_icl_LogFreeUse(logp)
2101 register struct afs_icl_log *logp;
2103 ObtainWriteLock(&logp->lock,189);
2104 if (--logp->setCount == 0) {
2105 /* no more users -- free it (but keep log structure around)*/
2106 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2107 #ifdef AFS_AIX32_ENV
2108 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2110 logp->firstUsed = logp->firstFree = 0;
2111 logp->logElements = 0;
2112 logp->datap = (afs_int32 *)0;
2114 ReleaseWriteLock(&logp->lock);
2118 /* set the size of the log to 'logSize' */
2119 afs_icl_LogSetSize(logp, logSize)
2120 register struct afs_icl_log *logp;
2123 ObtainWriteLock(&logp->lock,190);
2125 /* nothing to worry about since it's not allocated */
2126 logp->logSize = logSize;
2130 logp->firstUsed = logp->firstFree = 0;
2131 logp->logElements = 0;
2133 /* free and allocate a new one */
2134 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2135 #ifdef AFS_AIX32_ENV
2136 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2138 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2139 #ifdef AFS_AIX32_ENV
2140 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2142 logp->logSize = logSize;
2144 ReleaseWriteLock(&logp->lock);
2149 /* free a log. Called with afs_icl_lock locked. */
2150 afs_icl_ZapLog(logp)
2151 register struct afs_icl_log *logp;
2153 register struct afs_icl_log **lpp, *tp;
2155 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2157 /* found the dude we want to remove */
2159 osi_FreeSmallSpace(logp->name);
2160 osi_FreeSmallSpace(logp->datap);
2161 osi_FreeSmallSpace(logp);
2162 break; /* won't find it twice */
2168 /* do the release, watching for deleted entries */
2169 afs_icl_LogRele(logp)
2170 register struct afs_icl_log *logp;
2172 ObtainWriteLock(&afs_icl_lock,191);
2173 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2174 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2176 ReleaseWriteLock(&afs_icl_lock);
2180 /* do the release, watching for deleted entries, log already held */
2181 afs_icl_LogReleNL(logp)
2182 register struct afs_icl_log *logp;
2184 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2185 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2190 /* zero out the log */
2191 afs_icl_ZeroLog(logp)
2192 register struct afs_icl_log *logp;
2194 ObtainWriteLock(&logp->lock,192);
2195 logp->firstUsed = logp->firstFree = 0;
2196 logp->logElements = 0;
2197 logp->baseCookie = 0;
2198 ReleaseWriteLock(&logp->lock);
2202 /* free a log entry, and drop its reference count */
2203 afs_icl_LogFree(logp)
2204 register struct afs_icl_log *logp;
2206 ObtainWriteLock(&logp->lock,193);
2207 logp->states |= ICL_LOGF_DELETED;
2208 ReleaseWriteLock(&logp->lock);
2209 afs_icl_LogRele(logp);
2213 /* find a log by name, returning it held */
2214 struct afs_icl_log *afs_icl_FindLog(name)
2217 register struct afs_icl_log *tp;
2218 ObtainWriteLock(&afs_icl_lock,194);
2219 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2220 if (strcmp(tp->name, name) == 0) {
2221 /* this is the dude we want */
2226 ReleaseWriteLock(&afs_icl_lock);
2230 afs_icl_EnumerateLogs(aproc, arock)
2234 register struct afs_icl_log *tp;
2235 register afs_int32 code;
2238 ObtainWriteLock(&afs_icl_lock,195);
2239 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2240 tp->refCount++; /* hold this guy */
2241 ReleaseWriteLock(&afs_icl_lock);
2242 ObtainReadLock(&tp->lock);
2243 code = (*aproc)(tp->name, arock, tp);
2244 ReleaseReadLock(&tp->lock);
2245 ObtainWriteLock(&afs_icl_lock,196);
2246 if (--tp->refCount == 0)
2250 ReleaseWriteLock(&afs_icl_lock);
2254 struct afs_icl_set *afs_icl_allSets = 0;
2256 afs_icl_CreateSet(name, baseLogp, fatalLogp, outSetpp)
2258 struct afs_icl_log *baseLogp;
2259 struct afs_icl_log *fatalLogp;
2260 struct afs_icl_set **outSetpp;
2262 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2263 /*flags*/0, outSetpp);
2266 /* create a set, given pointers to base and fatal logs, if any.
2267 * Logs are unlocked, but referenced, and *outSetpp is returned
2268 * referenced. Function bumps reference count on logs, since it
2269 * addds references from the new afs_icl_set. When the set is destroyed,
2270 * those references will be released.
2272 afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp)
2274 struct afs_icl_log *baseLogp;
2275 struct afs_icl_log *fatalLogp;
2277 struct afs_icl_set **outSetpp;
2279 register struct afs_icl_set *setp;
2281 afs_int32 states = ICL_DEFAULT_SET_STATES;
2283 ObtainWriteLock(&afs_icl_lock,197);
2284 if (!afs_icl_inited) afs_icl_Init();
2286 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2287 if (strcmp(setp->name, name) == 0) {
2290 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2292 ObtainWriteLock(&setp->lock,198);
2293 setp->states |= ICL_SETF_PERSISTENT;
2294 ReleaseWriteLock(&setp->lock);
2296 ReleaseWriteLock(&afs_icl_lock);
2301 /* determine initial state */
2302 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2303 states = ICL_SETF_ACTIVE;
2304 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2305 states = ICL_SETF_FREED;
2306 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2307 states |= ICL_SETF_PERSISTENT;
2309 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2310 bzero((caddr_t)setp, sizeof(*setp));
2312 if (states & ICL_SETF_FREED)
2313 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2314 setp->states = states;
2316 LOCK_INIT(&setp->lock, "setp lock");
2317 /* next lock is obtained in wrong order, hierarchy-wise, but
2318 * it doesn't matter, since no one can find this lock yet, since
2319 * the afs_icl_lock is still held, and thus the obtain can't block.
2321 ObtainWriteLock(&setp->lock,199);
2322 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2323 strcpy(setp->name, name);
2324 setp->nevents = ICL_DEFAULTEVENTS;
2325 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2326 #ifdef AFS_AIX32_ENV
2327 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2329 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2330 setp->eventFlags[i] = 0xff; /* default to enabled */
2332 /* update this global info under the afs_icl_lock */
2333 setp->nextp = afs_icl_allSets;
2334 afs_icl_allSets = setp;
2335 ReleaseWriteLock(&afs_icl_lock);
2337 /* set's basic lock is still held, so we can finish init */
2339 setp->logs[0] = baseLogp;
2340 afs_icl_LogHold(baseLogp);
2341 if (!(setp->states & ICL_SETF_FREED))
2342 afs_icl_LogUse(baseLogp); /* log is actually being used */
2345 setp->logs[1] = fatalLogp;
2346 afs_icl_LogHold(fatalLogp);
2347 if (!(setp->states & ICL_SETF_FREED))
2348 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2350 ReleaseWriteLock(&setp->lock);
2356 /* function to change event enabling information for a particular set */
2357 afs_icl_SetEnable(setp, eventID, setValue)
2358 struct afs_icl_set *setp;
2364 ObtainWriteLock(&setp->lock,200);
2365 if (!ICL_EVENTOK(setp, eventID)) {
2366 ReleaseWriteLock(&setp->lock);
2369 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2371 *tp |= ICL_EVENTMASK(eventID);
2373 *tp &= ~(ICL_EVENTMASK(eventID));
2374 ReleaseWriteLock(&setp->lock);
2378 /* return indication of whether a particular event ID is enabled
2379 * for tracing. If *getValuep is set to 0, the event is disabled,
2380 * otherwise it is enabled. All events start out enabled by default.
2382 afs_icl_GetEnable(setp, eventID, getValuep)
2383 struct afs_icl_set *setp;
2387 ObtainReadLock(&setp->lock);
2388 if (!ICL_EVENTOK(setp, eventID)) {
2389 ReleaseWriteLock(&setp->lock);
2392 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2396 ReleaseReadLock(&setp->lock);
2400 /* hold and release event sets */
2401 afs_icl_SetHold(setp)
2402 register struct afs_icl_set *setp;
2404 ObtainWriteLock(&afs_icl_lock,201);
2406 ReleaseWriteLock(&afs_icl_lock);
2410 /* free a set. Called with afs_icl_lock locked */
2411 afs_icl_ZapSet(setp)
2412 register struct afs_icl_set *setp;
2414 register struct afs_icl_set **lpp, *tp;
2416 register struct afs_icl_log *tlp;
2418 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2420 /* found the dude we want to remove */
2422 osi_FreeSmallSpace(setp->name);
2423 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2424 #ifdef AFS_AIX32_ENV
2425 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2427 for(i=0; i < ICL_LOGSPERSET; i++) {
2428 if (tlp = setp->logs[i])
2429 afs_icl_LogReleNL(tlp);
2431 osi_FreeSmallSpace(setp);
2432 break; /* won't find it twice */
2438 /* do the release, watching for deleted entries */
2439 afs_icl_SetRele(setp)
2440 register struct afs_icl_set *setp;
2442 ObtainWriteLock(&afs_icl_lock,202);
2443 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2444 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2446 ReleaseWriteLock(&afs_icl_lock);
2450 /* free a set entry, dropping its reference count */
2451 afs_icl_SetFree(setp)
2452 register struct afs_icl_set *setp;
2454 ObtainWriteLock(&setp->lock,203);
2455 setp->states |= ICL_SETF_DELETED;
2456 ReleaseWriteLock(&setp->lock);
2457 afs_icl_SetRele(setp);
2461 /* find a set by name, returning it held */
2462 struct afs_icl_set *afs_icl_FindSet(name)
2465 register struct afs_icl_set *tp;
2466 ObtainWriteLock(&afs_icl_lock,204);
2467 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2468 if (strcmp(tp->name, name) == 0) {
2469 /* this is the dude we want */
2474 ReleaseWriteLock(&afs_icl_lock);
2478 /* zero out all the logs in the set */
2479 afs_icl_ZeroSet(setp)
2480 struct afs_icl_set *setp;
2485 struct afs_icl_log *logp;
2487 ObtainReadLock(&setp->lock);
2488 for(i = 0; i < ICL_LOGSPERSET; i++) {
2489 logp = setp->logs[i];
2491 afs_icl_LogHold(logp);
2492 tcode = afs_icl_ZeroLog(logp);
2493 if (tcode != 0) code = tcode; /* save the last bad one */
2494 afs_icl_LogRele(logp);
2497 ReleaseReadLock(&setp->lock);
2501 afs_icl_EnumerateSets(aproc, arock)
2505 register struct afs_icl_set *tp, *np;
2506 register afs_int32 code;
2509 ObtainWriteLock(&afs_icl_lock,205);
2510 for(tp = afs_icl_allSets; tp; tp=np) {
2511 tp->refCount++; /* hold this guy */
2512 ReleaseWriteLock(&afs_icl_lock);
2513 code = (*aproc)(tp->name, arock, tp);
2514 ObtainWriteLock(&afs_icl_lock,206);
2515 np = tp->nextp; /* tp may disappear next, but not np */
2516 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2520 ReleaseWriteLock(&afs_icl_lock);
2524 afs_icl_AddLogToSet(setp, newlogp)
2525 struct afs_icl_set *setp;
2526 struct afs_icl_log *newlogp;
2530 struct afs_icl_log *logp;
2532 ObtainWriteLock(&setp->lock,207);
2533 for(i = 0; i < ICL_LOGSPERSET; i++) {
2534 if (!setp->logs[i]) {
2535 setp->logs[i] = newlogp;
2537 afs_icl_LogHold(newlogp);
2538 if (!(setp->states & ICL_SETF_FREED)) {
2539 /* bump up the number of sets using the log */
2540 afs_icl_LogUse(newlogp);
2545 ReleaseWriteLock(&setp->lock);
2549 afs_icl_SetSetStat(setp, op)
2550 struct afs_icl_set *setp;
2555 struct afs_icl_log *logp;
2557 ObtainWriteLock(&setp->lock,208);
2559 case ICL_OP_SS_ACTIVATE: /* activate a log */
2561 * If we are not already active, see if we have released
2562 * our demand that the log be allocated (FREED set). If
2563 * we have, reassert our desire.
2565 if (!(setp->states & ICL_SETF_ACTIVE)) {
2566 if (setp->states & ICL_SETF_FREED) {
2567 /* have to reassert desire for logs */
2568 for(i = 0; i < ICL_LOGSPERSET; i++) {
2569 logp = setp->logs[i];
2571 afs_icl_LogHold(logp);
2572 afs_icl_LogUse(logp);
2573 afs_icl_LogRele(logp);
2576 setp->states &= ~ICL_SETF_FREED;
2578 setp->states |= ICL_SETF_ACTIVE;
2583 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2584 /* this doesn't require anything beyond clearing the ACTIVE flag */
2585 setp->states &= ~ICL_SETF_ACTIVE;
2589 case ICL_OP_SS_FREE: /* deassert design for log */
2591 * if we are already in this state, do nothing; otherwise
2592 * deassert desire for log
2594 if (setp->states & ICL_SETF_ACTIVE)
2597 if (!(setp->states & ICL_SETF_FREED)) {
2598 for(i = 0; i < ICL_LOGSPERSET; i++) {
2599 logp = setp->logs[i];
2601 afs_icl_LogHold(logp);
2602 afs_icl_LogFreeUse(logp);
2603 afs_icl_LogRele(logp);
2606 setp->states |= ICL_SETF_FREED;
2615 ReleaseWriteLock(&setp->lock);