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, (int)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, (int)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);
600 else if (parm == AFSOP_AFSDB_HANDLER) {
601 int sizeArg = (int)parm4;
602 int kmsgLen = sizeArg & 0xffff;
603 int cellLen = (sizeArg & 0xffff0000) >> 16;
604 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
605 char *cellname = afs_osi_Alloc(cellLen);
606 AFS_COPYIN((afs_int32 *)parm3, kmsg, kmsgLen, code);
607 if (!code) code = afs_AfsdbHandler(cellname, cellLen, kmsg);
608 if (!code) AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
609 afs_osi_Free(kmsg, kmsgLen);
610 afs_osi_Free(cellname, cellLen);
618 #ifdef AFS_LINUX20_ENV
627 #include "sys/lockl.h"
630 * syscall - this is the VRMIX system call entry point.
633 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
634 * all the user-level calls to `syscall' to change.
636 syscall(syscall, p1, p2, p3, p4, p5, p6) {
637 register rval1=0, code;
640 #ifndef AFS_AIX41_ENV
641 extern lock_t kernel_lock;
642 monster = lockl(&kernel_lock, LOCK_SHORT);
643 #endif /* !AFS_AIX41_ENV */
645 AFS_STATCNT(syscall);
649 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
654 rval1 = afs_setpag();
660 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
664 case AFSCALL_ICREATE:
665 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
669 rval1 = afs_syscall_iopen(p1, p2, p3);
673 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
677 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
682 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
684 if (!code) rval1 = retval;
685 if (!rval1) rval1 = code;
695 #ifndef AFS_AIX41_ENV
696 if (monster != LOCK_NEST)
697 unlockl(&kernel_lock);
698 #endif /* !AFS_AIX41_ENV */
699 return getuerror() ? -1 : rval1;
703 * lsetpag - interface to afs_setpag().
707 AFS_STATCNT(lsetpag);
708 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
712 * lpioctl - interface to pioctl()
714 lpioctl(path, cmd, cmarg, follow)
715 char *path, *cmarg; {
717 AFS_STATCNT(lpioctl);
718 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
721 #else /* !AFS_AIX32_ENV */
723 #if defined(AFS_SGI_ENV)
736 Afs_syscall (struct afsargs *uap, rval_t *rvp)
741 AFS_STATCNT(afs_syscall);
742 switch(uap->syscall) {
746 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
748 rvp->r_val1 = retval;
750 #ifdef AFS_SGI_XFS_IOPS_ENV
752 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
753 uap->parm4, uap->parm5);
756 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
757 uap->parm4, uap->parm5);
759 case AFSCALL_ILISTINODE64:
760 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
761 uap->parm4, uap->parm5);
763 case AFSCALL_ICREATENAME64:
764 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
765 uap->parm4, uap->parm5);
768 #ifdef AFS_SGI_VNODE_GLUE
769 case AFSCALL_INIT_KERNEL_CONFIG:
770 error = afs_init_kernel_config(uap->parm1);
774 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
775 uap->parm3, uap->parm4, uap->parm5);
780 #else /* AFS_SGI_ENV */
798 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
800 dst->param1 = src->param1;
801 dst->param2 = src->param2;
802 dst->param3 = src->param3;
803 dst->param4 = src->param4;
807 * If you need to change copyin_iparam(), you may also need to change
808 * copyin_afs_ioctl().
812 copyin_iparam(caddr_t cmarg, struct iparam *dst)
816 #if defined(AFS_HPUX_64BIT_ENV)
817 struct iparam32 dst32;
819 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
821 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
823 iparam32_to_iparam(&dst32, dst);
826 #endif /* AFS_HPUX_64BIT_ENV */
828 #if defined(AFS_SUN57_64BIT_ENV)
829 struct iparam32 dst32;
831 if (get_udatamodel() == DATAMODEL_ILP32) {
832 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
834 iparam32_to_iparam(&dst32, dst);
837 #endif /* AFS_SUN57_64BIT_ENV */
839 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV)
840 struct iparam32 dst32;
842 #ifdef AFS_SPARC64_LINUX20_ENV
843 if (current->tss.flags & SPARC_FLAG_32BIT)
845 #error Not done for this linux version
846 #endif /* AFS_SPARC64_LINUX20_ENV */
848 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
850 iparam32_to_iparam(&dst32, dst);
853 #endif /* AFS_LINUX_64BIT_KERNEL */
855 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
859 /* Main entry of all afs system calls */
861 extern int afs_sinited;
863 /** The 32 bit OS expects the members of this structure to be 32 bit
864 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
865 * to accomodate both, *long* is used instead of afs_int32
890 Afs_syscall (uap, rvp)
891 register struct afssysa *uap;
894 int *retval = &rvp->r_val1;
895 #else /* AFS_SUN5_ENV */
896 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
897 afs3_syscall(p, args, retval)
910 } *uap = (struct a *)args;
911 #else /* AFS_OSF_ENV */
912 #ifdef AFS_LINUX20_ENV
920 long parm6; /* not actually used - should be removed */
922 /* Linux system calls only set up for 5 arguments. */
923 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
926 struct afssysargs args, *uap = &args;
928 long *retval = &linux_ret;
929 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
942 } *uap = (struct a *)u.u_ap;
944 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
948 #endif /* SUN && !SUN5 */
958 } *uap = (struct a *)u.u_ap;
960 #if defined(AFS_DEC_ENV)
961 int *retval = &u.u_r.r_val1;
963 #if defined(AFS_HPUX_ENV)
964 long *retval = &u.u_rval1;
966 int *retval = &u.u_rval1;
969 #endif /* AFS_LINUX20_ENV */
970 #endif /* AFS_OSF_ENV */
971 #endif /* AFS_SUN5_ENV */
972 register int code = 0;
974 AFS_STATCNT(afs_syscall);
981 #ifdef AFS_LINUX20_ENV
983 /* setup uap for use below - pull out the magic decoder ring to know
984 * which syscalls have folded argument lists.
986 uap->syscall = syscall;
990 if (syscall == AFSCALL_ICL) {
991 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
992 uap->parm4 = eparm[0];
993 uap->parm5 = eparm[1];
994 uap->parm6 = eparm[2];
1003 #if defined(AFS_HPUX_ENV)
1005 * There used to be code here (duplicated from osi_Init()) for
1006 * initializing the semaphore used by AFS_GLOCK(). Was the
1007 * duplication to handle the case of a dynamically loaded kernel
1012 if (uap->syscall == AFSCALL_CALL) {
1014 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1015 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1017 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1019 } else if (uap->syscall == AFSCALL_SETPAG) {
1022 register proc_t *procp;
1024 procp = ttoproc(curthread);
1025 mutex_enter(&procp->p_crlock);
1026 cred = procp->p_cred;
1028 code = afs_setpag(&cred);
1030 procp->p_cred = cred;
1031 mutex_exit(&procp->p_crlock);
1034 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
1035 code = afs_setpag(p, args, retval);
1036 #else /* AFS_OSF_ENV */
1037 code = afs_setpag();
1041 } else if (uap->syscall == AFSCALL_PIOCTL) {
1044 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1046 #ifdef AFS_DARWIN_ENV
1047 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1049 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1053 } else if (uap->syscall == AFSCALL_ICREATE) {
1054 struct iparam iparams;
1056 code = copyin_iparam((char *)uap->parm3, &iparams);
1058 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
1063 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1064 iparams.param3, iparams.param4, rvp, CRED());
1066 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1067 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
1068 iparams.param3, iparams.param4, retval);
1070 iparams.param3, iparams.param4);
1072 #endif /* AFS_SUN5_ENV */
1073 } else if (uap->syscall == AFSCALL_IOPEN) {
1075 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1077 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
1078 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1080 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1082 #endif /* AFS_SUN5_ENV */
1083 } else if (uap->syscall == AFSCALL_IDEC) {
1085 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1087 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1088 #endif /* AFS_SUN5_ENV */
1089 } else if (uap->syscall == AFSCALL_IINC) {
1091 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1093 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1094 #endif /* AFS_SUN5_ENV */
1095 } else if (uap->syscall == AFSCALL_ICL) {
1097 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1099 #ifdef AFS_LINUX20_ENV
1101 /* ICL commands can return values. */
1102 code = -linux_ret; /* Gets negated again at exit below */
1106 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV)
1110 #endif /* !AFS_LINUX20_ENV */
1112 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV)
1116 #endif /* AFS_SUN5_ENV */
1119 #ifdef AFS_LINUX20_ENV
1125 #endif /* AFS_SGI_ENV */
1126 #endif /* !AFS_AIX32_ENV */
1129 * Initstate in the range 0 < x < 100 are early initialization states.
1130 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1131 * the cache may be initialized.
1132 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1133 * is done after all the cache initialization has been done.
1134 * Initstate of 200 means that the volume has been looked up once, possibly
1136 * Initstate of 300 means that the volume has been *successfully* looked up.
1139 register int code = 0;
1141 AFS_STATCNT(afs_CheckInit);
1142 if (afs_initState <= 100)
1143 code = ENXIO; /* never finished init phase */
1144 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1145 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1146 } else if (afs_initState == 200)
1147 code = ETIMEDOUT; /* didn't find root volume */
1151 int afs_shuttingdown = 0;
1155 extern short afs_brsDaemons;
1156 extern afs_int32 afs_CheckServerDaemonStarted;
1157 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1158 extern struct osi_file *afs_cacheInodep;
1160 AFS_STATCNT(afs_shutdown);
1161 if (afs_shuttingdown) return;
1162 afs_shuttingdown = 1;
1163 if (afs_cold_shutdown) afs_warn("COLD ");
1164 else afs_warn("WARM ");
1165 afs_warn("shutting down of: CB... ");
1167 afs_termState = AFSOP_STOP_RXCALLBACK;
1168 rx_WakeupServerProcs();
1169 /* shutdown_rxkernel(); */
1170 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1171 afs_osi_Sleep(&afs_termState);
1173 afs_warn("afs... ");
1174 while (afs_termState == AFSOP_STOP_AFS) {
1175 afs_osi_CancelWait(&AFS_WaitHandler);
1176 afs_osi_Sleep(&afs_termState);
1178 if (afs_CheckServerDaemonStarted) {
1179 while (afs_termState == AFSOP_STOP_CS) {
1180 afs_osi_CancelWait(&AFS_CSWaitHandler);
1181 afs_osi_Sleep(&afs_termState);
1184 afs_warn("BkG... ");
1185 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1186 while (afs_termState == AFSOP_STOP_BKG) {
1187 afs_osi_Wakeup(&afs_brsDaemons);
1188 afs_osi_Sleep(&afs_termState);
1190 afs_warn("CTrunc... ");
1191 /* Cancel cache truncate daemon. */
1192 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1193 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1194 afs_osi_Sleep(&afs_termState);
1196 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1197 afs_warn("RxEvent... ");
1198 /* cancel rx event deamon */
1199 while (afs_termState == AFSOP_STOP_RXEVENT)
1200 afs_osi_Sleep(&afs_termState);
1201 #if defined(RXK_LISTENER_ENV)
1202 afs_warn("RxListener... ");
1203 /* cancel rx listener */
1204 osi_StopListener(); /* This closes rx_socket. */
1205 while (afs_termState == AFSOP_STOP_RXK_LISTENER)
1206 afs_osi_Sleep(&afs_termState);
1209 afs_termState = AFSOP_STOP_COMPLETE;
1213 /* Close file only after daemons which can write to it are stopped. */
1214 if (afs_cacheInodep) /* memcache won't set this */
1216 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1217 afs_cacheInodep = 0;
1219 return; /* Just kill daemons for now */
1223 shutdown_rxkernel();
1227 shutdown_bufferpackage();
1233 shutdown_vnodeops();
1235 shutdown_exporter();
1236 shutdown_memcache();
1237 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1238 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1239 /* this routine does not exist in Ultrix systems... 93.01.19 */
1241 #endif /* AFS_DEC_ENV */
1244 /* The following hold the cm stats */
1246 bzero(&afs_cmstats, sizeof(struct afs_CMStats));
1247 bzero(&afs_stats_cmperf, sizeof(struct afs_stats_CMPerf));
1248 bzero(&afs_stats_cmfullperf, sizeof(struct afs_stats_CMFullPerf));
1250 afs_warn(" ALL allocated tables\n");
1251 afs_shuttingdown = 0;
1257 AFS_STATCNT(shutdown_afstest);
1258 afs_initState = afs_termState = afs_setTime = 0;
1259 AFS_Running = afs_CB_Running = 0;
1260 afs_CacheInit_Done = afs_Go_Done = 0;
1261 if (afs_cold_shutdown) {
1262 *afs_rootVolumeName = 0;
1267 /* In case there is a bunch of dynamically build bkg daemons to free */
1269 { AFS_STATCNT(shutdown_BKG); }
1272 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1273 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1274 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1275 int afs_icl_sizeofLong = 1;
1277 int afs_icl_sizeofLong = 2;
1280 int afs_icl_sizeofLong = 1;
1283 int afs_icl_inited = 0;
1285 /* init function, called once, under afs_icl_lock */
1292 extern struct afs_icl_log *afs_icl_FindLog();
1293 extern struct afs_icl_set *afs_icl_FindSet();
1297 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1300 afs_int32 *lp, elts, flags;
1301 register afs_int32 code;
1302 struct afs_icl_log *logp;
1303 struct afs_icl_set *setp;
1304 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV)
1306 #else /* AFS_SGI61_ENV */
1308 #endif /* AFS_SGI61_ENV */
1310 afs_int32 startCookie;
1311 afs_int32 allocated;
1312 struct afs_icl_log *tlp;
1315 if (!afs_suser(CRED())) { /* only root can run this code */
1319 if (!afs_suser()) { /* only root can run this code */
1320 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
1329 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1330 case ICL_OP_COPYOUT: /* copy ouy data */
1331 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1332 * return flags<<24 + nwords.
1333 * updates cookie to updated start (not end) if we had to
1334 * skip some records.
1336 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1337 if (code) return code;
1338 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1339 if (code) return code;
1340 logp = afs_icl_FindLog(tname);
1341 if (!logp) return ENOENT;
1342 #define BUFFERSIZE AFS_LRALLOCSIZ
1343 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1344 elts = BUFFERSIZE / sizeof(afs_int32);
1345 if (p3 < elts) elts = p3;
1346 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1347 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1350 osi_FreeLargeSpace((struct osi_buffer *) lp);
1353 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1354 if (code) goto done;
1355 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1356 if (code) goto done;
1357 *retval = (flags<<24) | (elts & 0xffffff);
1359 afs_icl_LogRele(logp);
1360 osi_FreeLargeSpace((struct osi_buffer *) lp);
1363 case ICL_OP_ENUMLOGS: /* enumerate logs */
1364 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1365 * return 0 for success, otherwise error.
1367 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1368 if (p1-- == 0) break;
1370 if (!tlp) return ENOENT; /* past the end of file */
1371 temp = strlen(tlp->name)+1;
1372 if (temp > p3) return EINVAL;
1373 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1374 if (!code) /* copy out size of log */
1375 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1378 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1379 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1380 * return 0 for success, otherwise error.
1382 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1383 if (code) return code;
1384 setp = afs_icl_FindSet(tname);
1385 if (!setp) return ENOENT;
1386 if (p2 > ICL_LOGSPERSET)
1388 if (!(tlp = setp->logs[p2]))
1390 temp = strlen(tlp->name)+1;
1391 if (temp > p4) return EINVAL;
1392 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1395 case ICL_OP_CLRLOG: /* clear specified log */
1396 /* zero out the specified log: p1=logname */
1397 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1398 if (code) return code;
1399 logp = afs_icl_FindLog(tname);
1400 if (!logp) return ENOENT;
1401 code = afs_icl_ZeroLog(logp);
1402 afs_icl_LogRele(logp);
1405 case ICL_OP_CLRSET: /* clear specified set */
1406 /* zero out the specified set: p1=setname */
1407 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1408 if (code) return code;
1409 setp = afs_icl_FindSet(tname);
1410 if (!setp) return ENOENT;
1411 code = afs_icl_ZeroSet(setp);
1412 afs_icl_SetRele(setp);
1415 case ICL_OP_CLRALL: /* clear all logs */
1416 /* zero out all logs -- no args */
1418 ObtainWriteLock(&afs_icl_lock,178);
1419 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1420 tlp->refCount++; /* hold this guy */
1421 ReleaseWriteLock(&afs_icl_lock);
1422 /* don't clear persistent logs */
1423 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1424 code = afs_icl_ZeroLog(tlp);
1425 ObtainWriteLock(&afs_icl_lock,179);
1426 if (--tlp->refCount == 0)
1427 afs_icl_ZapLog(tlp);
1430 ReleaseWriteLock(&afs_icl_lock);
1433 case ICL_OP_ENUMSETS: /* enumerate all sets */
1434 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1435 * return 0 for success, otherwise error.
1437 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1438 if (p1-- == 0) break;
1440 if (!setp) return ENOENT; /* past the end of file */
1441 temp = strlen(setp->name)+1;
1442 if (temp > p3) return EINVAL;
1443 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1444 if (!code) /* copy out size of log */
1445 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1448 case ICL_OP_SETSTAT: /* set status on a set */
1449 /* activate the specified set: p1=setname, p2=op */
1450 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1451 if (code) return code;
1452 setp = afs_icl_FindSet(tname);
1453 if (!setp) return ENOENT;
1454 code = afs_icl_SetSetStat(setp, p2);
1455 afs_icl_SetRele(setp);
1458 case ICL_OP_SETSTATALL: /* set status on all sets */
1459 /* activate the specified set: p1=op */
1461 ObtainWriteLock(&afs_icl_lock,180);
1462 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1463 setp->refCount++; /* hold this guy */
1464 ReleaseWriteLock(&afs_icl_lock);
1465 /* don't set states on persistent sets */
1466 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1467 code = afs_icl_SetSetStat(setp, p1);
1468 ObtainWriteLock(&afs_icl_lock,181);
1469 if (--setp->refCount == 0)
1470 afs_icl_ZapSet(setp);
1473 ReleaseWriteLock(&afs_icl_lock);
1476 case ICL_OP_SETLOGSIZE: /* set size of log */
1477 /* set the size of the specified log: p1=logname, p2=size (in words) */
1478 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1479 if (code) return code;
1480 logp = afs_icl_FindLog(tname);
1481 if (!logp) return ENOENT;
1482 code = afs_icl_LogSetSize(logp, p2);
1483 afs_icl_LogRele(logp);
1486 case ICL_OP_GETLOGINFO: /* get size of log */
1487 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1488 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1489 if (code) return code;
1490 logp = afs_icl_FindLog(tname);
1491 if (!logp) return ENOENT;
1492 allocated = !!logp->datap;
1493 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1495 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1496 afs_icl_LogRele(logp);
1499 case ICL_OP_GETSETINFO: /* get state of set */
1500 /* zero out the specified set: p1=setname, p2=&state */
1501 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1502 if (code) return code;
1503 setp = afs_icl_FindSet(tname);
1504 if (!setp) return ENOENT;
1505 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1506 afs_icl_SetRele(setp);
1517 afs_lock_t afs_icl_lock;
1519 /* exported routine: a 4 parameter event */
1520 afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, p4)
1521 register struct afs_icl_set *setp;
1524 long p1, p2, p3, p4;
1526 register struct afs_icl_log *logp;
1529 register afs_int32 tmask;
1532 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1533 if (!ICL_SETACTIVE(setp)) return;
1536 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1537 ix = ICL_EVENTBYTE(eventID);
1538 ObtainReadLock(&setp->lock);
1539 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1540 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1542 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1546 if (mask == 0) break; /* break early */
1549 ReleaseReadLock(&setp->lock);
1552 /* Next 4 routines should be implemented via var-args or something.
1553 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1554 * Otherwise, could call afs_icl_Event4 directly.
1556 afs_icl_Event3(setp, eventID, lAndT, p1, p2, p3)
1557 register struct afs_icl_set *setp;
1562 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1565 afs_icl_Event2(setp, eventID, lAndT, p1, p2)
1566 register struct afs_icl_set *setp;
1571 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1574 afs_icl_Event1(setp, eventID, lAndT, p1)
1575 register struct afs_icl_set *setp;
1580 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1583 afs_icl_Event0(setp, eventID, lAndT)
1584 register struct afs_icl_set *setp;
1588 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1591 struct afs_icl_log *afs_icl_allLogs = 0;
1593 /* function to purge records from the start of the log, until there
1594 * is at least minSpace long's worth of space available without
1595 * making the head and the tail point to the same word.
1597 * Log must be write-locked.
1599 static afs_icl_GetLogSpace(logp, minSpace)
1600 register struct afs_icl_log *logp;
1603 register unsigned int tsize;
1605 while (logp->logSize - logp->logElements <= minSpace) {
1607 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1608 logp->logElements -= tsize;
1609 logp->firstUsed += tsize;
1610 if (logp->firstUsed >= logp->logSize)
1611 logp->firstUsed -= logp->logSize;
1612 logp->baseCookie += tsize;
1616 /* append string astr to buffer, including terminating null char.
1618 * log must be write-locked.
1620 #define ICL_CHARSPERLONG 4
1621 static afs_int32 afs_icl_AppendString(logp, astr)
1622 struct afs_icl_log *logp;
1625 char *op; /* ptr to char to write */
1627 register int bib; /* bytes in buffer */
1630 op = (char *) &(logp->datap[logp->firstFree]);
1634 if (++bib >= ICL_CHARSPERLONG) {
1637 if (++(logp->firstFree) >= logp->logSize) {
1638 logp->firstFree = 0;
1639 op = (char *) &(logp->datap[0]);
1641 logp->logElements++;
1646 /* if we've used this word at all, allocate it */
1647 if (++(logp->firstFree) >= logp->logSize) {
1648 logp->firstFree = 0;
1650 logp->logElements++;
1654 /* add a long to the log, ignoring overflow (checked already) */
1655 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1656 #define ICL_APPENDINT32(lp, x) \
1658 (lp)->datap[(lp)->firstFree] = (x); \
1659 if (++((lp)->firstFree) >= (lp)->logSize) { \
1660 (lp)->firstFree = 0; \
1662 (lp)->logElements++; \
1665 #define ICL_APPENDLONG(lp, x) \
1667 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1668 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1671 #else /* AFS_ALPHA_ENV */
1672 #define ICL_APPENDLONG(lp, x) \
1674 (lp)->datap[(lp)->firstFree] = (x); \
1675 if (++((lp)->firstFree) >= (lp)->logSize) { \
1676 (lp)->firstFree = 0; \
1678 (lp)->logElements++; \
1680 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1681 #endif /* AFS_ALPHA_ENV */
1683 /* routine to tell whether we're dealing with the address or the
1686 afs_icl_UseAddr(type)
1689 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1690 || type == ICL_TYPE_FID)
1696 /* Function to append a record to the log. Written for speed
1697 * since we know that we're going to have to make this work fast
1698 * pretty soon, anyway. The log must be unlocked.
1701 afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4)
1702 register struct afs_icl_log *logp;
1705 long p1, p2, p3, p4;
1707 int rsize; /* record size in longs */
1708 register int tsize; /* temp size */
1712 t4 = types & 0x3f; /* decode types */
1720 osi_GetTime(&tv); /* It panics for solaris if inside */
1721 ObtainWriteLock(&logp->lock,182);
1723 ReleaseWriteLock(&logp->lock);
1727 /* get timestamp as # of microseconds since some time that doesn't
1728 * change that often. This algorithm ticks over every 20 minutes
1729 * or so (1000 seconds). Write a timestamp record if it has.
1731 if (tv.tv_sec - logp->lastTS > 1024)
1733 /* the timer has wrapped -- write a timestamp record */
1734 if (logp->logSize - logp->logElements <= 5)
1735 afs_icl_GetLogSpace(logp, 5);
1737 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1738 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1739 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1740 ICL_APPENDINT32(logp,
1741 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1742 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1744 logp->lastTS = tv.tv_sec;
1747 rsize = 4; /* base case */
1749 /* compute size of parameter p1. Only tricky case is string.
1750 * In that case, we have to call strlen to get the string length.
1752 ICL_SIZEHACK(t1, p1);
1755 /* compute size of parameter p2. Only tricky case is string.
1756 * In that case, we have to call strlen to get the string length.
1758 ICL_SIZEHACK(t2, p2);
1761 /* compute size of parameter p3. Only tricky case is string.
1762 * In that case, we have to call strlen to get the string length.
1764 ICL_SIZEHACK(t3, p3);
1767 /* compute size of parameter p4. Only tricky case is string.
1768 * In that case, we have to call strlen to get the string length.
1770 ICL_SIZEHACK(t4, p4);
1773 /* At this point, we've computed all of the parameter sizes, and
1774 * have in rsize the size of the entire record we want to append.
1775 * Next, we check that we actually have room in the log to do this
1776 * work, and then we do the append.
1779 ReleaseWriteLock(&logp->lock);
1780 return; /* log record too big to express */
1783 if (logp->logSize - logp->logElements <= rsize)
1784 afs_icl_GetLogSpace(logp, rsize);
1786 ICL_APPENDINT32(logp,
1787 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
1788 ICL_APPENDINT32(logp, (afs_int32)op);
1789 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
1790 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1793 /* marshall parameter 1 now */
1794 if (t1 == ICL_TYPE_STRING) {
1795 afs_icl_AppendString(logp, (char *) p1);
1797 else if (t1 == ICL_TYPE_HYPER) {
1798 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
1799 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
1801 else if (t1 == ICL_TYPE_FID) {
1802 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1803 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1804 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
1805 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
1807 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1808 else if (t1 == ICL_TYPE_INT32)
1809 ICL_APPENDINT32(logp, (afs_int32)p1);
1810 #endif /* AFS_ALPHA_ENV */
1811 else ICL_APPENDLONG(logp, p1);
1814 /* marshall parameter 2 now */
1815 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
1816 else if (t2 == ICL_TYPE_HYPER) {
1817 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
1818 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
1820 else if (t2 == ICL_TYPE_FID) {
1821 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1822 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1823 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
1824 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
1826 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1827 else if (t2 == ICL_TYPE_INT32)
1828 ICL_APPENDINT32(logp, (afs_int32)p2);
1829 #endif /* AFS_ALPHA_ENV */
1830 else ICL_APPENDLONG(logp, p2);
1833 /* marshall parameter 3 now */
1834 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
1835 else if (t3 == ICL_TYPE_HYPER) {
1836 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
1837 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
1839 else if (t3 == ICL_TYPE_FID) {
1840 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1841 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1842 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
1843 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
1845 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1846 else if (t3 == ICL_TYPE_INT32)
1847 ICL_APPENDINT32(logp, (afs_int32)p3);
1848 #endif /* AFS_ALPHA_ENV */
1849 else ICL_APPENDLONG(logp, p3);
1852 /* marshall parameter 4 now */
1853 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
1854 else if (t4 == ICL_TYPE_HYPER) {
1855 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
1856 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
1858 else if (t4 == ICL_TYPE_FID) {
1859 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
1860 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
1861 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
1862 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
1864 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1865 else if (t4 == ICL_TYPE_INT32)
1866 ICL_APPENDINT32(logp, (afs_int32)p4);
1867 #endif /* AFS_ALPHA_ENV */
1868 else ICL_APPENDLONG(logp, p4);
1870 ReleaseWriteLock(&logp->lock);
1873 /* create a log with size logSize; return it in *outLogpp and tag
1874 * it with name "name."
1876 afs_icl_CreateLog(name, logSize, outLogpp)
1879 struct afs_icl_log **outLogpp;
1881 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
1884 /* create a log with size logSize; return it in *outLogpp and tag
1885 * it with name "name." 'flags' can be set to make the log unclearable.
1887 afs_icl_CreateLogWithFlags(name, logSize, flags, outLogpp)
1891 struct afs_icl_log **outLogpp;
1893 register struct afs_icl_log *logp;
1895 /* add into global list under lock */
1896 ObtainWriteLock(&afs_icl_lock,183);
1897 if (!afs_icl_inited) afs_icl_Init();
1899 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
1900 if (strcmp(logp->name, name) == 0) {
1901 /* found it already created, just return it */
1904 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
1906 ObtainWriteLock(&logp->lock,184);
1907 logp->states |= ICL_LOGF_PERSISTENT;
1908 ReleaseWriteLock(&logp->lock);
1910 ReleaseWriteLock(&afs_icl_lock);
1915 logp = (struct afs_icl_log *)
1916 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
1917 bzero((caddr_t)logp, sizeof(*logp));
1920 logp->name = osi_AllocSmallSpace(strlen(name)+1);
1921 strcpy(logp->name, name);
1922 LOCK_INIT(&logp->lock, "logp lock");
1923 logp->logSize = logSize;
1924 logp->datap = (afs_int32 *)0; /* don't allocate it until we need it */
1926 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
1927 logp->states |= ICL_LOGF_PERSISTENT;
1929 logp->nextp = afs_icl_allLogs;
1930 afs_icl_allLogs = logp;
1931 ReleaseWriteLock(&afs_icl_lock);
1937 /* called with a log, a pointer to a buffer, the size of the buffer
1938 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
1939 * and returns data in the provided buffer, and returns output flags
1940 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
1941 * find the record with cookie value cookie.
1943 afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp)
1944 register struct afs_icl_log *logp;
1946 afs_int32 *bufSizep;
1947 afs_uint32 *cookiep;
1950 afs_int32 nwords; /* number of words to copy out */
1951 afs_uint32 startCookie; /* first cookie to use */
1952 register afs_int32 i;
1953 afs_int32 outWords; /* words we've copied out */
1954 afs_int32 inWords; /* max words to copy out */
1955 afs_int32 code; /* return code */
1956 afs_int32 ix; /* index we're copying from */
1957 afs_int32 outFlags; /* return flags */
1958 afs_int32 inFlags; /* flags passed in */
1961 inWords = *bufSizep; /* max to copy out */
1962 outWords = 0; /* amount copied out */
1963 startCookie = *cookiep;
1968 ObtainWriteLock(&logp->lock,185);
1970 ReleaseWriteLock(&logp->lock);
1974 /* first, compute the index of the start cookie we've been passed */
1976 /* (re-)compute where we should start */
1977 if (startCookie < logp->baseCookie) {
1978 if (startCookie) /* missed some output */
1979 outFlags |= ICL_COPYOUTF_MISSEDSOME;
1980 /* skip to the first available record */
1981 startCookie = logp->baseCookie;
1982 *cookiep = startCookie;
1985 /* compute where we find the first element to copy out */
1986 ix = logp->firstUsed + startCookie - logp->baseCookie;
1987 if (ix >= logp->logSize) ix -= logp->logSize;
1989 /* if have some data now, break out and process it */
1990 if (startCookie - logp->baseCookie < logp->logElements) break;
1992 /* At end of log, so clear it if we need to */
1993 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
1995 logp->firstUsed = logp->firstFree = 0;
1996 logp->logElements = 0;
1998 /* otherwise, either wait for the data to arrive, or return */
1999 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2000 ReleaseWriteLock(&logp->lock);
2004 logp->states |= ICL_LOGF_WAITING;
2005 ReleaseWriteLock(&logp->lock);
2006 afs_osi_Sleep(&logp->lock);
2007 ObtainWriteLock(&logp->lock,186);
2009 /* copy out data from ix to logSize or firstFree, depending
2010 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2011 * be careful not to copy out more than nwords.
2013 if (ix >= logp->firstUsed) {
2014 if (logp->firstUsed <= logp->firstFree)
2016 end = logp->firstFree; /* first element not to copy */
2018 end = logp->logSize;
2019 nwords = inWords; /* don't copy more than this */
2020 if (end - ix < nwords)
2023 bcopy((char *) &logp->datap[ix], (char *) bufferp,
2024 sizeof(afs_int32) * nwords);
2029 /* if we're going to copy more out below, we'll start here */
2032 /* now, if active part of the log has wrapped, there's more stuff
2033 * starting at the head of the log. Copy out more from there.
2035 if (logp->firstUsed > logp->firstFree
2036 && ix < logp->firstFree && inWords > 0) {
2037 /* (more to) copy out from the wrapped section at the
2038 * start of the log. May get here even if didn't copy any
2039 * above, if the cookie points directly into the wrapped section.
2042 if (logp->firstFree - ix < nwords)
2043 nwords = logp->firstFree - ix;
2044 bcopy((char *) &logp->datap[ix], (char *) bufferp,
2045 sizeof(afs_int32) * nwords);
2051 ReleaseWriteLock(&logp->lock);
2055 *bufSizep = outWords;
2061 /* return basic parameter information about a log */
2062 afs_icl_GetLogParms(logp, maxSizep, curSizep)
2063 struct afs_icl_log *logp;
2064 afs_int32 *maxSizep;
2065 afs_int32 *curSizep;
2067 ObtainReadLock(&logp->lock);
2068 *maxSizep = logp->logSize;
2069 *curSizep = logp->logElements;
2070 ReleaseReadLock(&logp->lock);
2075 /* hold and release logs */
2076 afs_icl_LogHold(logp)
2077 register struct afs_icl_log *logp;
2079 ObtainWriteLock(&afs_icl_lock,187);
2081 ReleaseWriteLock(&afs_icl_lock);
2085 /* hold and release logs, called with lock already held */
2086 afs_icl_LogHoldNL(logp)
2087 register struct afs_icl_log *logp;
2093 /* keep track of how many sets believe the log itself is allocated */
2094 afs_icl_LogUse(logp)
2095 register struct afs_icl_log *logp;
2097 ObtainWriteLock(&logp->lock,188);
2098 if (logp->setCount == 0) {
2099 /* this is the first set actually using the log -- allocate it */
2100 if (logp->logSize == 0) {
2101 /* we weren't passed in a hint and it wasn't set */
2102 logp->logSize = ICL_DEFAULT_LOGSIZE;
2104 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2105 #ifdef AFS_AIX32_ENV
2106 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2110 ReleaseWriteLock(&logp->lock);
2114 /* decrement the number of real users of the log, free if possible */
2115 afs_icl_LogFreeUse(logp)
2116 register struct afs_icl_log *logp;
2118 ObtainWriteLock(&logp->lock,189);
2119 if (--logp->setCount == 0) {
2120 /* no more users -- free it (but keep log structure around)*/
2121 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2122 #ifdef AFS_AIX32_ENV
2123 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2125 logp->firstUsed = logp->firstFree = 0;
2126 logp->logElements = 0;
2127 logp->datap = (afs_int32 *)0;
2129 ReleaseWriteLock(&logp->lock);
2133 /* set the size of the log to 'logSize' */
2134 afs_icl_LogSetSize(logp, logSize)
2135 register struct afs_icl_log *logp;
2138 ObtainWriteLock(&logp->lock,190);
2140 /* nothing to worry about since it's not allocated */
2141 logp->logSize = logSize;
2145 logp->firstUsed = logp->firstFree = 0;
2146 logp->logElements = 0;
2148 /* free and allocate a new one */
2149 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2150 #ifdef AFS_AIX32_ENV
2151 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2153 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2154 #ifdef AFS_AIX32_ENV
2155 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2157 logp->logSize = logSize;
2159 ReleaseWriteLock(&logp->lock);
2164 /* free a log. Called with afs_icl_lock locked. */
2165 afs_icl_ZapLog(logp)
2166 register struct afs_icl_log *logp;
2168 register struct afs_icl_log **lpp, *tp;
2170 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2172 /* found the dude we want to remove */
2174 osi_FreeSmallSpace(logp->name);
2175 osi_FreeSmallSpace(logp->datap);
2176 osi_FreeSmallSpace(logp);
2177 break; /* won't find it twice */
2183 /* do the release, watching for deleted entries */
2184 afs_icl_LogRele(logp)
2185 register struct afs_icl_log *logp;
2187 ObtainWriteLock(&afs_icl_lock,191);
2188 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2189 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2191 ReleaseWriteLock(&afs_icl_lock);
2195 /* do the release, watching for deleted entries, log already held */
2196 afs_icl_LogReleNL(logp)
2197 register struct afs_icl_log *logp;
2199 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2200 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2205 /* zero out the log */
2206 afs_icl_ZeroLog(logp)
2207 register struct afs_icl_log *logp;
2209 ObtainWriteLock(&logp->lock,192);
2210 logp->firstUsed = logp->firstFree = 0;
2211 logp->logElements = 0;
2212 logp->baseCookie = 0;
2213 ReleaseWriteLock(&logp->lock);
2217 /* free a log entry, and drop its reference count */
2218 afs_icl_LogFree(logp)
2219 register struct afs_icl_log *logp;
2221 ObtainWriteLock(&logp->lock,193);
2222 logp->states |= ICL_LOGF_DELETED;
2223 ReleaseWriteLock(&logp->lock);
2224 afs_icl_LogRele(logp);
2228 /* find a log by name, returning it held */
2229 struct afs_icl_log *afs_icl_FindLog(name)
2232 register struct afs_icl_log *tp;
2233 ObtainWriteLock(&afs_icl_lock,194);
2234 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2235 if (strcmp(tp->name, name) == 0) {
2236 /* this is the dude we want */
2241 ReleaseWriteLock(&afs_icl_lock);
2245 afs_icl_EnumerateLogs(aproc, arock)
2249 register struct afs_icl_log *tp;
2250 register afs_int32 code;
2253 ObtainWriteLock(&afs_icl_lock,195);
2254 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2255 tp->refCount++; /* hold this guy */
2256 ReleaseWriteLock(&afs_icl_lock);
2257 ObtainReadLock(&tp->lock);
2258 code = (*aproc)(tp->name, arock, tp);
2259 ReleaseReadLock(&tp->lock);
2260 ObtainWriteLock(&afs_icl_lock,196);
2261 if (--tp->refCount == 0)
2265 ReleaseWriteLock(&afs_icl_lock);
2269 struct afs_icl_set *afs_icl_allSets = 0;
2271 afs_icl_CreateSet(name, baseLogp, fatalLogp, outSetpp)
2273 struct afs_icl_log *baseLogp;
2274 struct afs_icl_log *fatalLogp;
2275 struct afs_icl_set **outSetpp;
2277 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2278 /*flags*/0, outSetpp);
2281 /* create a set, given pointers to base and fatal logs, if any.
2282 * Logs are unlocked, but referenced, and *outSetpp is returned
2283 * referenced. Function bumps reference count on logs, since it
2284 * addds references from the new afs_icl_set. When the set is destroyed,
2285 * those references will be released.
2287 afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp)
2289 struct afs_icl_log *baseLogp;
2290 struct afs_icl_log *fatalLogp;
2292 struct afs_icl_set **outSetpp;
2294 register struct afs_icl_set *setp;
2296 afs_int32 states = ICL_DEFAULT_SET_STATES;
2298 ObtainWriteLock(&afs_icl_lock,197);
2299 if (!afs_icl_inited) afs_icl_Init();
2301 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2302 if (strcmp(setp->name, name) == 0) {
2305 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2307 ObtainWriteLock(&setp->lock,198);
2308 setp->states |= ICL_SETF_PERSISTENT;
2309 ReleaseWriteLock(&setp->lock);
2311 ReleaseWriteLock(&afs_icl_lock);
2316 /* determine initial state */
2317 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2318 states = ICL_SETF_ACTIVE;
2319 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2320 states = ICL_SETF_FREED;
2321 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2322 states |= ICL_SETF_PERSISTENT;
2324 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2325 bzero((caddr_t)setp, sizeof(*setp));
2327 if (states & ICL_SETF_FREED)
2328 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2329 setp->states = states;
2331 LOCK_INIT(&setp->lock, "setp lock");
2332 /* next lock is obtained in wrong order, hierarchy-wise, but
2333 * it doesn't matter, since no one can find this lock yet, since
2334 * the afs_icl_lock is still held, and thus the obtain can't block.
2336 ObtainWriteLock(&setp->lock,199);
2337 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2338 strcpy(setp->name, name);
2339 setp->nevents = ICL_DEFAULTEVENTS;
2340 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2341 #ifdef AFS_AIX32_ENV
2342 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2344 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2345 setp->eventFlags[i] = 0xff; /* default to enabled */
2347 /* update this global info under the afs_icl_lock */
2348 setp->nextp = afs_icl_allSets;
2349 afs_icl_allSets = setp;
2350 ReleaseWriteLock(&afs_icl_lock);
2352 /* set's basic lock is still held, so we can finish init */
2354 setp->logs[0] = baseLogp;
2355 afs_icl_LogHold(baseLogp);
2356 if (!(setp->states & ICL_SETF_FREED))
2357 afs_icl_LogUse(baseLogp); /* log is actually being used */
2360 setp->logs[1] = fatalLogp;
2361 afs_icl_LogHold(fatalLogp);
2362 if (!(setp->states & ICL_SETF_FREED))
2363 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2365 ReleaseWriteLock(&setp->lock);
2371 /* function to change event enabling information for a particular set */
2372 afs_icl_SetEnable(setp, eventID, setValue)
2373 struct afs_icl_set *setp;
2379 ObtainWriteLock(&setp->lock,200);
2380 if (!ICL_EVENTOK(setp, eventID)) {
2381 ReleaseWriteLock(&setp->lock);
2384 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2386 *tp |= ICL_EVENTMASK(eventID);
2388 *tp &= ~(ICL_EVENTMASK(eventID));
2389 ReleaseWriteLock(&setp->lock);
2393 /* return indication of whether a particular event ID is enabled
2394 * for tracing. If *getValuep is set to 0, the event is disabled,
2395 * otherwise it is enabled. All events start out enabled by default.
2397 afs_icl_GetEnable(setp, eventID, getValuep)
2398 struct afs_icl_set *setp;
2402 ObtainReadLock(&setp->lock);
2403 if (!ICL_EVENTOK(setp, eventID)) {
2404 ReleaseWriteLock(&setp->lock);
2407 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2411 ReleaseReadLock(&setp->lock);
2415 /* hold and release event sets */
2416 afs_icl_SetHold(setp)
2417 register struct afs_icl_set *setp;
2419 ObtainWriteLock(&afs_icl_lock,201);
2421 ReleaseWriteLock(&afs_icl_lock);
2425 /* free a set. Called with afs_icl_lock locked */
2426 afs_icl_ZapSet(setp)
2427 register struct afs_icl_set *setp;
2429 register struct afs_icl_set **lpp, *tp;
2431 register struct afs_icl_log *tlp;
2433 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2435 /* found the dude we want to remove */
2437 osi_FreeSmallSpace(setp->name);
2438 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2439 #ifdef AFS_AIX32_ENV
2440 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2442 for(i=0; i < ICL_LOGSPERSET; i++) {
2443 if (tlp = setp->logs[i])
2444 afs_icl_LogReleNL(tlp);
2446 osi_FreeSmallSpace(setp);
2447 break; /* won't find it twice */
2453 /* do the release, watching for deleted entries */
2454 afs_icl_SetRele(setp)
2455 register struct afs_icl_set *setp;
2457 ObtainWriteLock(&afs_icl_lock,202);
2458 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2459 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2461 ReleaseWriteLock(&afs_icl_lock);
2465 /* free a set entry, dropping its reference count */
2466 afs_icl_SetFree(setp)
2467 register struct afs_icl_set *setp;
2469 ObtainWriteLock(&setp->lock,203);
2470 setp->states |= ICL_SETF_DELETED;
2471 ReleaseWriteLock(&setp->lock);
2472 afs_icl_SetRele(setp);
2476 /* find a set by name, returning it held */
2477 struct afs_icl_set *afs_icl_FindSet(name)
2480 register struct afs_icl_set *tp;
2481 ObtainWriteLock(&afs_icl_lock,204);
2482 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2483 if (strcmp(tp->name, name) == 0) {
2484 /* this is the dude we want */
2489 ReleaseWriteLock(&afs_icl_lock);
2493 /* zero out all the logs in the set */
2494 afs_icl_ZeroSet(setp)
2495 struct afs_icl_set *setp;
2500 struct afs_icl_log *logp;
2502 ObtainReadLock(&setp->lock);
2503 for(i = 0; i < ICL_LOGSPERSET; i++) {
2504 logp = setp->logs[i];
2506 afs_icl_LogHold(logp);
2507 tcode = afs_icl_ZeroLog(logp);
2508 if (tcode != 0) code = tcode; /* save the last bad one */
2509 afs_icl_LogRele(logp);
2512 ReleaseReadLock(&setp->lock);
2516 afs_icl_EnumerateSets(aproc, arock)
2520 register struct afs_icl_set *tp, *np;
2521 register afs_int32 code;
2524 ObtainWriteLock(&afs_icl_lock,205);
2525 for(tp = afs_icl_allSets; tp; tp=np) {
2526 tp->refCount++; /* hold this guy */
2527 ReleaseWriteLock(&afs_icl_lock);
2528 code = (*aproc)(tp->name, arock, tp);
2529 ObtainWriteLock(&afs_icl_lock,206);
2530 np = tp->nextp; /* tp may disappear next, but not np */
2531 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2535 ReleaseWriteLock(&afs_icl_lock);
2539 afs_icl_AddLogToSet(setp, newlogp)
2540 struct afs_icl_set *setp;
2541 struct afs_icl_log *newlogp;
2545 struct afs_icl_log *logp;
2547 ObtainWriteLock(&setp->lock,207);
2548 for(i = 0; i < ICL_LOGSPERSET; i++) {
2549 if (!setp->logs[i]) {
2550 setp->logs[i] = newlogp;
2552 afs_icl_LogHold(newlogp);
2553 if (!(setp->states & ICL_SETF_FREED)) {
2554 /* bump up the number of sets using the log */
2555 afs_icl_LogUse(newlogp);
2560 ReleaseWriteLock(&setp->lock);
2564 afs_icl_SetSetStat(setp, op)
2565 struct afs_icl_set *setp;
2570 struct afs_icl_log *logp;
2572 ObtainWriteLock(&setp->lock,208);
2574 case ICL_OP_SS_ACTIVATE: /* activate a log */
2576 * If we are not already active, see if we have released
2577 * our demand that the log be allocated (FREED set). If
2578 * we have, reassert our desire.
2580 if (!(setp->states & ICL_SETF_ACTIVE)) {
2581 if (setp->states & ICL_SETF_FREED) {
2582 /* have to reassert desire for logs */
2583 for(i = 0; i < ICL_LOGSPERSET; i++) {
2584 logp = setp->logs[i];
2586 afs_icl_LogHold(logp);
2587 afs_icl_LogUse(logp);
2588 afs_icl_LogRele(logp);
2591 setp->states &= ~ICL_SETF_FREED;
2593 setp->states |= ICL_SETF_ACTIVE;
2598 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2599 /* this doesn't require anything beyond clearing the ACTIVE flag */
2600 setp->states &= ~ICL_SETF_ACTIVE;
2604 case ICL_OP_SS_FREE: /* deassert design for log */
2606 * if we are already in this state, do nothing; otherwise
2607 * deassert desire for log
2609 if (setp->states & ICL_SETF_ACTIVE)
2612 if (!(setp->states & ICL_SETF_FREED)) {
2613 for(i = 0; i < ICL_LOGSPERSET; i++) {
2614 logp = setp->logs[i];
2616 afs_icl_LogHold(logp);
2617 afs_icl_LogFreeUse(logp);
2618 afs_icl_LogRele(logp);
2621 setp->states |= ICL_SETF_FREED;
2630 ReleaseWriteLock(&setp->lock);