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)
46 kmutex_t afs_global_lock;
47 kmutex_t afs_rxglobal_lock;
49 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
50 long afs_global_owner;
54 #if defined(AFS_OSF_ENV)
55 simple_lock_data_t afs_global_lock;
56 thread_t afs_global_owner;
57 #endif /* AFS_OSF_ENV */
59 #if defined(AFS_AIX41_ENV)
60 simple_lock_data afs_global_lock;
63 afs_int32 afs_initState = 0;
64 afs_int32 afs_termState = 0;
65 afs_int32 afs_setTime = 0;
66 int afs_cold_shutdown = 0;
67 char afs_SynchronousCloses = '\0';
68 static int afs_CB_Running = 0;
69 static int AFS_Running = 0;
70 static int afs_CacheInit_Done = 0;
71 static int afs_Go_Done = 0;
72 extern struct interfaceAddr afs_cb_interface;
73 static int afs_RX_Running = 0;
76 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval);
78 #if defined(AFS_HPUX_ENV)
79 extern int afs_vfs_mount();
80 #endif /* defined(AFS_HPUX_ENV) */
82 /* This is code which needs to be called once when the first daemon enters
83 * the client. A non-zero return means an error and AFS should not start.
85 static int afs_InitSetup(int preallocs)
87 extern void afs_InitStats();
92 * Set up all the AFS statistics variables. This should be done
93 * exactly once, and it should be done here, the first resource-setting
94 * routine to be called by the CM/RX.
97 #endif /* AFS_NOSTATS */
99 bzero(afs_zeros, AFS_ZEROS);
102 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
103 code = rx_Init(htons(7001));
105 printf("AFS: RX failed to initialize.\n");
108 rx_SetRxDeadTime(AFS_RXDEADTIME);
109 /* resource init creates the services */
110 afs_ResourceInit(preallocs);
115 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
116 long parm, parm2, parm3, parm4, parm5, parm6;
120 AFS_STATCNT(afs_syscall_call);
122 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
123 && (parm != AFSOP_GETMASK)) {
124 /* only root can run this code */
127 if (!afs_suser() && (parm != AFSOP_GETMTU)
128 && (parm != AFSOP_GETMASK)) {
129 /* only root can run this code */
130 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV)
134 #if defined(AFS_OSF_ENV)
136 #else /* AFS_OSF_ENV */
143 if (parm == AFSOP_START_RXCALLBACK) {
144 if (afs_CB_Running) goto out;
146 #ifndef RXK_LISTENER_ENV
147 code = afs_InitSetup(parm2);
149 #endif /* RXK_LISTENER_ENV */
151 #ifdef RXK_LISTENER_ENV
152 while (afs_RX_Running != 2)
153 afs_osi_Sleep(&afs_RX_Running);
155 afs_initState = AFSOP_START_AFS;
156 afs_osi_Wakeup(&afs_initState);
157 #endif /* RXK_LISTENER_ENV */
159 afs_RXCallBackServer();
163 exit(CLD_EXITED, code);
166 #ifdef RXK_LISTENER_ENV
167 else if (parm == AFSOP_RXLISTENER_DAEMON) {
168 if (afs_RX_Running) goto out;
170 code = afs_InitSetup(parm2);
172 rx_enablePeerRPCStats();
175 rx_enableProcessRPCStats();
178 afs_initState = AFSOP_START_AFS;
179 afs_osi_Wakeup(&afs_initState);
182 afs_osi_Wakeup(&afs_RX_Running);
187 exit(CLD_EXITED, code);
191 else if (parm == AFSOP_START_AFS) {
195 if (AFS_Running) goto out;
197 while (afs_initState < AFSOP_START_AFS)
198 afs_osi_Sleep(&afs_initState);
200 #if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
201 temp = AFS_MINBUFFERS; /* Should fix this soon */
203 temp = ((afs_bufferpages * NBPG)>>11); /* number of 2k buffers we could get from all of the buffer space */
204 temp = temp>>2; /* don't take more than 25% (our magic parameter) */
205 if (temp < AFS_MINBUFFERS) temp = AFS_MINBUFFERS; /* although we really should have this many */
208 afs_initState = AFSOP_START_BKG;
209 afs_osi_Wakeup(&afs_initState);
217 else if (parm == AFSOP_START_CS) {
219 afs_CheckServerDaemon();
225 else if (parm == AFSOP_START_BKG) {
226 while (afs_initState < AFSOP_START_BKG)
227 afs_osi_Sleep(&afs_initState);
228 if (afs_initState < AFSOP_GO) {
229 afs_initState = AFSOP_GO;
230 afs_osi_Wakeup(&afs_initState);
232 /* start the bkg daemon */
236 afs_BioDaemon(parm2);
239 afs_BackgroundDaemon();
245 else if (parm == AFSOP_START_TRUNCDAEMON) {
246 while (afs_initState < AFSOP_GO)
247 afs_osi_Sleep(&afs_initState);
248 /* start the bkg daemon */
250 afs_CacheTruncateDaemon();
256 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
257 else if (parm == AFSOP_RXEVENT_DAEMON) {
258 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
260 afs_rxevent_daemon();
267 else if (parm == AFSOP_ADDCELL) {
268 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
269 name. Parameter 4 is the length of the name, including the null. Parm 5 is the
270 home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
271 struct afsop_cell tcell;
273 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
274 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
276 if (parm4 > sizeof(tcell.cellName))
279 AFS_COPYIN((char *)parm3, tcell.cellName, parm4, code);
281 afs_NewCell(tcell.cellName, tcell.hosts, parm5,
282 (char *)0, (u_short)0, (u_short)0);
285 } else if (parm == AFSOP_ADDCELL2) {
286 struct afsop_cell tcell;
287 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
288 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *cnamep = 0;
289 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV)
291 #else /* AFS_SGI61_ENV */
293 #endif /* AFS_SGI61_ENV */
296 /* wait for basic init */
297 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
299 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
301 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, &bufferSize, code);
304 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
307 cflags |= CLinkedCell;
311 afs_NewCell(tbuffer1, tcell.hosts, cflags,
312 lcnamep, (u_short)0, (u_short)0);
315 osi_FreeSmallSpace(tbuffer);
316 osi_FreeSmallSpace(tbuffer1);
318 else if (parm == AFSOP_CACHEINIT) {
319 struct afs_cacheParams cparms;
321 if (afs_CacheInit_Done) goto out;
323 /* wait for basic init */
324 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
325 AFS_COPYIN((char *)parm2, (caddr_t) &cparms, sizeof(cparms), code);
327 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined (AFS_SGI64_ENV) || defined(AFS_LINUX20_ENV)
335 afs_CacheInit_Done = 1;
337 struct afs_icl_log *logp;
338 /* initialize the ICL system */
339 code = afs_icl_CreateLog("cmfx", 60*1024, &logp);
341 code = afs_icl_CreateSetWithFlags("cm", logp,
342 (struct icl_log *) 0,
343 ICL_CRSET_FLAG_DEFAULT_OFF,
345 code = afs_icl_CreateSet("cmlongterm", logp, (struct icl_log*) 0,
346 &afs_iclLongTermSetp);
348 afs_setTime = cparms.setTimeFlag;
350 code = afs_CacheInit(cparms.cacheScaches,
361 else if (parm == AFSOP_CACHEINODE) {
362 ino_t ainode = parm2;
363 /* wait for basic init */
364 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
368 ainode = (ainode << 32) | (parm3 & 0xffffffff);
370 code = afs_InitCacheFile((char *) 0, ainode);
372 else if (parm == AFSOP_ROOTVOLUME) {
373 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV)
375 #else /* AFS_SGI61_ENV */
377 #endif /* AFS_SGI61_ENV */
379 /* wait for basic init */
380 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
383 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code);
384 afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0;
388 else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO ||
389 parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG) {
390 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
391 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV)
393 #else /* AFS_SGI61_ENV */
395 #endif /* AFS_SGI61_ENV */
397 /* wait for basic init */
398 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
400 AFS_COPYINSTR((char *)parm2, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
402 osi_FreeSmallSpace(tbuffer);
406 tbuffer[AFS_SMALLOCSIZ-1] = 0; /* null-terminate the name */
407 /* we now have the cache dir copied in. Call the cache init routines */
408 if (parm == AFSOP_CACHEFILE) code = afs_InitCacheFile(tbuffer, 0);
409 else if (parm == AFSOP_CACHEINFO) code = afs_InitCacheInfo(tbuffer);
410 else if (parm == AFSOP_VOLUMEINFO) code = afs_InitVolumeInfo(tbuffer);
412 osi_FreeSmallSpace(tbuffer);
414 else if (parm == AFSOP_GO) {
415 /* the generic initialization calls come here. One parameter: should we do the
416 set-time operation on this workstation */
417 if (afs_Go_Done) goto out;
419 while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState);
422 afs_osi_Wakeup(&afs_initState);
423 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
424 afs_nfsclient_init();
426 printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused,
427 (100*afs_stats_cmperf.cacheFilesReused) /
428 (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1));
430 else if (parm == AFSOP_ADVISEADDR) {
431 /* pass in the host address to the rx package */
432 afs_int32 count = parm2;
433 afs_int32 buffer[AFS_MAX_INTERFACE_ADDR];
434 afs_int32 maskbuffer[AFS_MAX_INTERFACE_ADDR];
435 afs_int32 mtubuffer[AFS_MAX_INTERFACE_ADDR];
439 if ( count > AFS_MAX_INTERFACE_ADDR ) {
441 count = AFS_MAX_INTERFACE_ADDR;
444 AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code);
446 AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code);
448 AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code);
450 afs_cb_interface.numberOfInterfaces = count;
451 for (i=0; i < count ; i++) {
452 afs_cb_interface.addr_in[i] = buffer[i];
453 #ifdef AFS_USERSPACE_IP_ADDR
454 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
455 * machines IP addresses when in the kernel (the in_ifaddr
456 * struct is not available), so we pass the info in at
457 * startup. We also pass in the subnetmask and mtu size. The
458 * subnetmask is used when setting the rank:
459 * afsi_SetServerIPRank(); and the mtu size is used when
460 * finding the best mtu size. rxi_FindIfnet() is replaced
461 * with rxi_Findcbi().
463 afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff);
464 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
467 afs_uuid_create(&afs_cb_interface.uuid);
468 rxi_setaddr(buffer[0]);
472 else if (parm == AFSOP_NFSSTATICADDR) {
473 extern int (*nfs_rfsdisptab_v2)();
474 nfs_rfsdisptab_v2 = (int (*)())parm2;
476 else if (parm == AFSOP_NFSSTATICADDR2) {
477 extern int (*nfs_rfsdisptab_v2)();
479 nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
481 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
484 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
485 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
486 extern int (*afs_sblockp)();
487 extern void (*afs_sbunlockp)();
489 afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
490 afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff));
492 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
493 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
496 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
497 #endif /* AFS_SGI53_ENV */
498 else if (parm == AFSOP_SHUTDOWN) {
499 #if defined(AFS_OSF_ENV)
500 extern struct mount *afs_globalVFS;
501 #else /* AFS_OSF_ENV */
502 extern struct vfs *afs_globalVFS;
504 afs_cold_shutdown = 0;
505 if (parm == 1) afs_cold_shutdown = 1;
506 if (afs_globalVFS != 0) {
507 afs_warn("AFS isn't unmounted yet! Call aborted\n");
513 #if ! defined(AFS_HPUX90_ENV) || defined(AFS_HPUX100_ENV)
514 else if (parm == AFSOP_AFS_VFSMOUNT) {
516 #if defined(AFS_HPUX100_ENV)
517 vfsmount(parm2, parm3, parm4, parm5);
519 afs_vfs_mount(parm2, parm3, parm4, parm5);
520 #endif /* AFS_HPUX100_ENV */
521 #else /* defined(AFS_HPUX_ENV) */
522 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV)
527 #endif /* defined(AFS_HPUX_ENV) */
530 else if (parm == AFSOP_CLOSEWAIT) {
531 afs_SynchronousCloses = 'S';
533 else if (parm == AFSOP_GETMTU) {
535 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
536 #ifdef AFS_USERSPACE_IP_ADDR
538 i = rxi_Findcbi(parm2);
539 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
540 #else /* AFS_USERSPACE_IP_ADDR */
542 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
543 extern struct ifnet *rxi_FindIfnet();
545 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
546 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
547 #endif /* else AFS_USERSPACE_IP_ADDR */
548 #endif /* !AFS_SUN5_ENV */
550 AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code);
552 /* this is disabled for now because I can't figure out how to get access
553 * to these kernel variables. It's only for supporting user-mode rx
554 * programs -- it makes a huge difference on the 220's in my testbed,
555 * though I don't know why. The bosserver does this with /etc/no, so it's
556 * being handled a different way for the servers right now. */
559 extern u_long sb_max_dflt;
562 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
563 if (sb_max < 131072) sb_max = 131072;
566 #endif /* AFS_AIX32_ENV */
568 else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
570 #if !defined(AFS_SUN5_ENV)
571 #ifdef AFS_USERSPACE_IP_ADDR
573 i = rxi_Findcbi(parm2);
575 mask = afs_cb_interface.subnetmask[i];
579 #else /* AFS_USERSPACE_IP_ADDR */
581 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
582 extern struct ifnet *rxi_FindIfnet();
583 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
584 if (tifnp && tifadp) {
585 mask = tifadp->ia_subnetmask;
589 #endif /* else AFS_USERSPACE_IP_ADDR */
590 #endif /* !AFS_SUN5_ENV */
592 AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code);
598 #ifdef AFS_LINUX20_ENV
607 #include "sys/lockl.h"
610 * syscall - this is the VRMIX system call entry point.
613 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
614 * all the user-level calls to `syscall' to change.
616 syscall(syscall, p1, p2, p3, p4, p5, p6) {
617 register rval1=0, code;
620 #ifndef AFS_AIX41_ENV
621 extern lock_t kernel_lock;
622 monster = lockl(&kernel_lock, LOCK_SHORT);
623 #endif /* !AFS_AIX41_ENV */
625 AFS_STATCNT(syscall);
629 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
634 rval1 = afs_setpag();
640 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
644 case AFSCALL_ICREATE:
645 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
649 rval1 = afs_syscall_iopen(p1, p2, p3);
653 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
657 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
662 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
664 if (!code) rval1 = retval;
665 if (!rval1) rval1 = code;
675 #ifndef AFS_AIX41_ENV
676 if (monster != LOCK_NEST)
677 unlockl(&kernel_lock);
678 #endif /* !AFS_AIX41_ENV */
679 return getuerror() ? -1 : rval1;
683 * lsetpag - interface to afs_setpag().
687 AFS_STATCNT(lsetpag);
688 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
692 * lpioctl - interface to pioctl()
694 lpioctl(path, cmd, cmarg, follow)
695 char *path, *cmarg; {
697 AFS_STATCNT(lpioctl);
698 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
701 #else /* !AFS_AIX32_ENV */
703 #if defined(AFS_SGI_ENV)
716 Afs_syscall (struct afsargs *uap, rval_t *rvp)
721 AFS_STATCNT(afs_syscall);
722 switch(uap->syscall) {
726 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
728 rvp->r_val1 = retval;
730 #ifdef AFS_SGI_XFS_IOPS_ENV
732 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
733 uap->parm4, uap->parm5);
736 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
737 uap->parm4, uap->parm5);
739 case AFSCALL_ILISTINODE64:
740 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
741 uap->parm4, uap->parm5);
743 case AFSCALL_ICREATENAME64:
744 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
745 uap->parm4, uap->parm5);
748 #ifdef AFS_SGI_VNODE_GLUE
749 case AFSCALL_INIT_KERNEL_CONFIG:
750 error = afs_init_kernel_config(uap->parm1);
754 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
755 uap->parm3, uap->parm4, uap->parm5);
760 #else /* AFS_SGI_ENV */
778 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
780 dst->param1 = src->param1;
781 dst->param2 = src->param2;
782 dst->param3 = src->param3;
783 dst->param4 = src->param4;
787 * If you need to change copyin_iparam(), you may also need to change
788 * copyin_afs_ioctl().
792 copyin_iparam(caddr_t cmarg, struct iparam *dst)
796 #if defined(AFS_HPUX_64BIT_ENV)
797 struct iparam32 dst32;
799 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
801 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
803 iparam32_to_iparam(&dst32, dst);
806 #endif /* AFS_HPUX_64BIT_ENV */
808 #if defined(AFS_SUN57_64BIT_ENV)
809 struct iparam32 dst32;
811 if (get_udatamodel() == DATAMODEL_ILP32) {
812 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
814 iparam32_to_iparam(&dst32, dst);
817 #endif /* AFS_SUN57_64BIT_ENV */
819 #if defined(AFS_LINUX_64BIT_KERNEL)
820 struct iparam32 dst32;
822 #ifdef AFS_SPARC64_LINUX20_ENV
823 if (current->tss.flags & SPARC_FLAG_32BIT) {
825 #error Not done for this linux version
827 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
829 iparam32_to_iparam(&dst32, dst);
832 #endif /* AFS_LINUX_64BIT_KERNEL */
834 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
838 /* Main entry of all afs system calls */
840 extern int afs_sinited;
842 /** The 32 bit OS expects the members of this structure to be 32 bit
843 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
844 * to accomodate both, *long* is used instead of afs_int32
869 Afs_syscall (uap, rvp)
870 register struct afssysa *uap;
873 int *retval = &rvp->r_val1;
874 #else /* AFS_SUN5_ENV */
875 #if defined(AFS_OSF_ENV)
876 afs3_syscall(p, args, retval)
889 } *uap = (struct a *)args;
890 #else /* AFS_OSF_ENV */
891 #ifdef AFS_LINUX20_ENV
899 long parm6; /* not actually used - should be removed */
901 /* Linux system calls only set up for 5 arguments. */
902 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
905 struct afssysargs args, *uap = &args;
907 long *retval = &linux_ret;
908 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
921 } *uap = (struct a *)u.u_ap;
923 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
927 #endif /* SUN && !SUN5 */
937 } *uap = (struct a *)u.u_ap;
939 #if defined(AFS_DEC_ENV)
940 int *retval = &u.u_r.r_val1;
942 #if defined(AFS_HPUX_ENV)
943 long *retval = &u.u_rval1;
945 int *retval = &u.u_rval1;
948 #endif /* AFS_LINUX20_ENV */
949 #endif /* AFS_OSF_ENV */
950 #endif /* AFS_SUN5_ENV */
951 register int code = 0;
953 AFS_STATCNT(afs_syscall);
960 #ifdef AFS_LINUX20_ENV
962 /* setup uap for use below - pull out the magic decoder ring to know
963 * which syscalls have folded argument lists.
965 uap->syscall = syscall;
969 if (syscall == AFSCALL_ICL) {
970 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
971 uap->parm4 = eparm[0];
972 uap->parm5 = eparm[1];
973 uap->parm6 = eparm[2];
982 #if defined(AFS_HPUX_ENV)
984 * There used to be code here (duplicated from osi_Init()) for
985 * initializing the semaphore used by AFS_GLOCK(). Was the
986 * duplication to handle the case of a dynamically loaded kernel
991 if (uap->syscall == AFSCALL_CALL) {
993 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
994 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
996 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
998 } else if (uap->syscall == AFSCALL_SETPAG) {
1001 register proc_t *procp;
1003 procp = ttoproc(curthread);
1004 mutex_enter(&procp->p_crlock);
1005 cred = procp->p_cred;
1007 code = afs_setpag(&cred);
1009 procp->p_cred = cred;
1010 mutex_exit(&procp->p_crlock);
1013 #if defined(AFS_OSF_ENV)
1014 code = afs_setpag(p, args, retval);
1015 #else /* AFS_OSF_ENV */
1016 code = afs_setpag();
1020 } else if (uap->syscall == AFSCALL_PIOCTL) {
1023 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1025 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1028 } else if (uap->syscall == AFSCALL_ICREATE) {
1029 struct iparam iparams;
1031 code = copyin_iparam((char *)uap->parm3, &iparams);
1033 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV)
1038 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1039 iparams.param3, iparams.param4, rvp, CRED());
1041 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1043 iparams.param3, iparams.param4, retval);
1045 iparams.param3, iparams.param4);
1047 #endif /* AFS_SUN5_ENV */
1048 } else if (uap->syscall == AFSCALL_IOPEN) {
1050 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1053 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1055 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1057 #endif /* AFS_SUN5_ENV */
1058 } else if (uap->syscall == AFSCALL_IDEC) {
1060 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1062 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1063 #endif /* AFS_SUN5_ENV */
1064 } else if (uap->syscall == AFSCALL_IINC) {
1066 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1068 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1069 #endif /* AFS_SUN5_ENV */
1070 } else if (uap->syscall == AFSCALL_ICL) {
1072 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1074 #ifdef AFS_LINUX20_ENV
1076 /* ICL commands can return values. */
1077 code = -linux_ret; /* Gets negated again at exit below */
1081 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV)
1085 #endif /* !AFS_LINUX20_ENV */
1087 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV)
1091 #endif /* AFS_SUN5_ENV */
1094 #ifdef AFS_LINUX20_ENV
1100 #endif /* AFS_SGI_ENV */
1101 #endif /* !AFS_AIX32_ENV */
1104 * Initstate in the range 0 < x < 100 are early initialization states.
1105 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1106 * the cache may be initialized.
1107 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1108 * is done after all the cache initialization has been done.
1109 * Initstate of 200 means that the volume has been looked up once, possibly
1111 * Initstate of 300 means that the volume has been *successfully* looked up.
1114 register int code = 0;
1116 AFS_STATCNT(afs_CheckInit);
1117 if (afs_initState <= 100)
1118 code = ENXIO; /* never finished init phase */
1119 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1120 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1121 } else if (afs_initState == 200)
1122 code = ETIMEDOUT; /* didn't find root volume */
1126 int afs_shuttingdown = 0;
1130 extern short afs_brsDaemons;
1131 extern afs_int32 afs_CheckServerDaemonStarted;
1132 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1133 extern struct osi_file *afs_cacheInodep;
1135 AFS_STATCNT(afs_shutdown);
1136 if (afs_shuttingdown) return;
1137 afs_shuttingdown = 1;
1138 if (afs_cold_shutdown) afs_warn("COLD ");
1139 else afs_warn("WARM ");
1140 afs_warn("shutting down of: CB... ");
1142 afs_termState = AFSOP_STOP_RXCALLBACK;
1143 rx_WakeupServerProcs();
1144 /* shutdown_rxkernel(); */
1145 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1146 afs_osi_Sleep(&afs_termState);
1148 afs_warn("afs... ");
1149 while (afs_termState == AFSOP_STOP_AFS) {
1150 afs_osi_CancelWait(&AFS_WaitHandler);
1151 afs_osi_Sleep(&afs_termState);
1153 if (afs_CheckServerDaemonStarted) {
1154 while (afs_termState == AFSOP_STOP_CS) {
1155 afs_osi_CancelWait(&AFS_CSWaitHandler);
1156 afs_osi_Sleep(&afs_termState);
1159 afs_warn("BkG... ");
1160 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1161 while (afs_termState == AFSOP_STOP_BKG) {
1162 afs_osi_Wakeup(&afs_brsDaemons);
1163 afs_osi_Sleep(&afs_termState);
1165 afs_warn("CTrunc... ");
1166 /* Cancel cache truncate daemon. */
1167 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1168 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1169 afs_osi_Sleep(&afs_termState);
1171 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1172 afs_warn("RxEvent... ");
1173 /* cancel rx event deamon */
1174 while (afs_termState == AFSOP_STOP_RXEVENT)
1175 afs_osi_Sleep(&afs_termState);
1176 #if defined(RXK_LISTENER_ENV)
1177 afs_warn("RxListener... ");
1178 /* cancel rx listener */
1179 osi_StopListener(); /* This closes rx_socket. */
1180 while (afs_termState == AFSOP_STOP_RXK_LISTENER)
1181 afs_osi_Sleep(&afs_termState);
1184 afs_termState = AFSOP_STOP_COMPLETE;
1188 /* Close file only after daemons which can write to it are stopped. */
1189 if (afs_cacheInodep) /* memcache won't set this */
1191 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1192 afs_cacheInodep = 0;
1194 return; /* Just kill daemons for now */
1198 shutdown_rxkernel();
1202 shutdown_bufferpackage();
1208 shutdown_vnodeops();
1210 shutdown_exporter();
1211 shutdown_memcache();
1212 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1213 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1214 /* this routine does not exist in Ultrix systems... 93.01.19 */
1216 #endif /* AFS_DEC_ENV */
1219 /* The following hold the cm stats */
1221 bzero(&afs_cmstats, sizeof(struct afs_CMStats));
1222 bzero(&afs_stats_cmperf, sizeof(struct afs_stats_CMPerf));
1223 bzero(&afs_stats_cmfullperf, sizeof(struct afs_stats_CMFullPerf));
1225 afs_warn(" ALL allocated tables\n");
1226 afs_shuttingdown = 0;
1232 AFS_STATCNT(shutdown_afstest);
1233 afs_initState = afs_termState = afs_setTime = 0;
1234 AFS_Running = afs_CB_Running = 0;
1235 afs_CacheInit_Done = afs_Go_Done = 0;
1236 if (afs_cold_shutdown) {
1237 *afs_rootVolumeName = 0;
1242 /* In case there is a bunch of dynamically build bkg daemons to free */
1244 { AFS_STATCNT(shutdown_BKG); }
1247 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1248 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1249 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1250 int afs_icl_sizeofLong = 1;
1252 int afs_icl_sizeofLong = 2;
1255 int afs_icl_sizeofLong = 1;
1258 int afs_icl_inited = 0;
1260 /* init function, called once, under afs_icl_lock */
1267 extern struct afs_icl_log *afs_icl_FindLog();
1268 extern struct afs_icl_set *afs_icl_FindSet();
1272 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1275 afs_int32 *lp, elts, flags;
1276 register afs_int32 code;
1277 struct afs_icl_log *logp;
1278 struct afs_icl_set *setp;
1279 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV)
1281 #else /* AFS_SGI61_ENV */
1283 #endif /* AFS_SGI61_ENV */
1285 afs_int32 startCookie;
1286 afs_int32 allocated;
1287 struct afs_icl_log *tlp;
1290 if (!afs_suser(CRED())) { /* only root can run this code */
1294 if (!afs_suser()) { /* only root can run this code */
1295 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV)
1304 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1305 case ICL_OP_COPYOUT: /* copy ouy data */
1306 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1307 * return flags<<24 + nwords.
1308 * updates cookie to updated start (not end) if we had to
1309 * skip some records.
1311 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1312 if (code) return code;
1313 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1314 if (code) return code;
1315 logp = afs_icl_FindLog(tname);
1316 if (!logp) return ENOENT;
1317 #define BUFFERSIZE AFS_LRALLOCSIZ
1318 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1319 elts = BUFFERSIZE / sizeof(afs_int32);
1320 if (p3 < elts) elts = p3;
1321 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1322 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1325 osi_FreeLargeSpace((struct osi_buffer *) lp);
1328 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1329 if (code) goto done;
1330 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1331 if (code) goto done;
1332 *retval = (flags<<24) | (elts & 0xffffff);
1334 afs_icl_LogRele(logp);
1335 osi_FreeLargeSpace((struct osi_buffer *) lp);
1338 case ICL_OP_ENUMLOGS: /* enumerate logs */
1339 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1340 * return 0 for success, otherwise error.
1342 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1343 if (p1-- == 0) break;
1345 if (!tlp) return ENOENT; /* past the end of file */
1346 temp = strlen(tlp->name)+1;
1347 if (temp > p3) return EINVAL;
1348 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1349 if (!code) /* copy out size of log */
1350 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1353 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1354 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1355 * return 0 for success, otherwise error.
1357 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1358 if (code) return code;
1359 setp = afs_icl_FindSet(tname);
1360 if (!setp) return ENOENT;
1361 if (p2 > ICL_LOGSPERSET)
1363 if (!(tlp = setp->logs[p2]))
1365 temp = strlen(tlp->name)+1;
1366 if (temp > p4) return EINVAL;
1367 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1370 case ICL_OP_CLRLOG: /* clear specified log */
1371 /* zero out the specified log: p1=logname */
1372 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1373 if (code) return code;
1374 logp = afs_icl_FindLog(tname);
1375 if (!logp) return ENOENT;
1376 code = afs_icl_ZeroLog(logp);
1377 afs_icl_LogRele(logp);
1380 case ICL_OP_CLRSET: /* clear specified set */
1381 /* zero out the specified set: p1=setname */
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 code = afs_icl_ZeroSet(setp);
1387 afs_icl_SetRele(setp);
1390 case ICL_OP_CLRALL: /* clear all logs */
1391 /* zero out all logs -- no args */
1393 ObtainWriteLock(&afs_icl_lock,178);
1394 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1395 tlp->refCount++; /* hold this guy */
1396 ReleaseWriteLock(&afs_icl_lock);
1397 /* don't clear persistent logs */
1398 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1399 code = afs_icl_ZeroLog(tlp);
1400 ObtainWriteLock(&afs_icl_lock,179);
1401 if (--tlp->refCount == 0)
1402 afs_icl_ZapLog(tlp);
1405 ReleaseWriteLock(&afs_icl_lock);
1408 case ICL_OP_ENUMSETS: /* enumerate all sets */
1409 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1410 * return 0 for success, otherwise error.
1412 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1413 if (p1-- == 0) break;
1415 if (!setp) return ENOENT; /* past the end of file */
1416 temp = strlen(setp->name)+1;
1417 if (temp > p3) return EINVAL;
1418 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1419 if (!code) /* copy out size of log */
1420 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1423 case ICL_OP_SETSTAT: /* set status on a set */
1424 /* activate the specified set: p1=setname, p2=op */
1425 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1426 if (code) return code;
1427 setp = afs_icl_FindSet(tname);
1428 if (!setp) return ENOENT;
1429 code = afs_icl_SetSetStat(setp, p2);
1430 afs_icl_SetRele(setp);
1433 case ICL_OP_SETSTATALL: /* set status on all sets */
1434 /* activate the specified set: p1=op */
1436 ObtainWriteLock(&afs_icl_lock,180);
1437 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1438 setp->refCount++; /* hold this guy */
1439 ReleaseWriteLock(&afs_icl_lock);
1440 /* don't set states on persistent sets */
1441 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1442 code = afs_icl_SetSetStat(setp, p1);
1443 ObtainWriteLock(&afs_icl_lock,181);
1444 if (--setp->refCount == 0)
1445 afs_icl_ZapSet(setp);
1448 ReleaseWriteLock(&afs_icl_lock);
1451 case ICL_OP_SETLOGSIZE: /* set size of log */
1452 /* set the size of the specified log: p1=logname, p2=size (in words) */
1453 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1454 if (code) return code;
1455 logp = afs_icl_FindLog(tname);
1456 if (!logp) return ENOENT;
1457 code = afs_icl_LogSetSize(logp, p2);
1458 afs_icl_LogRele(logp);
1461 case ICL_OP_GETLOGINFO: /* get size of log */
1462 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
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 allocated = !!logp->datap;
1468 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1470 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1471 afs_icl_LogRele(logp);
1474 case ICL_OP_GETSETINFO: /* get state of set */
1475 /* zero out the specified set: p1=setname, p2=&state */
1476 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1477 if (code) return code;
1478 setp = afs_icl_FindSet(tname);
1479 if (!setp) return ENOENT;
1480 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1481 afs_icl_SetRele(setp);
1492 afs_lock_t afs_icl_lock;
1494 /* exported routine: a 4 parameter event */
1495 afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, p4)
1496 register struct afs_icl_set *setp;
1499 long p1, p2, p3, p4;
1501 register struct afs_icl_log *logp;
1504 register afs_int32 tmask;
1507 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1508 if (!ICL_SETACTIVE(setp)) return;
1511 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1512 ix = ICL_EVENTBYTE(eventID);
1513 ObtainReadLock(&setp->lock);
1514 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1515 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1517 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1521 if (mask == 0) break; /* break early */
1524 ReleaseReadLock(&setp->lock);
1527 /* Next 4 routines should be implemented via var-args or something.
1528 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1529 * Otherwise, could call afs_icl_Event4 directly.
1531 afs_icl_Event3(setp, eventID, lAndT, p1, p2, p3)
1532 register struct afs_icl_set *setp;
1537 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1540 afs_icl_Event2(setp, eventID, lAndT, p1, p2)
1541 register struct afs_icl_set *setp;
1546 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1549 afs_icl_Event1(setp, eventID, lAndT, p1)
1550 register struct afs_icl_set *setp;
1555 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1558 afs_icl_Event0(setp, eventID, lAndT)
1559 register struct afs_icl_set *setp;
1563 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1566 struct afs_icl_log *afs_icl_allLogs = 0;
1568 /* function to purge records from the start of the log, until there
1569 * is at least minSpace long's worth of space available without
1570 * making the head and the tail point to the same word.
1572 * Log must be write-locked.
1574 static afs_icl_GetLogSpace(logp, minSpace)
1575 register struct afs_icl_log *logp;
1578 register unsigned int tsize;
1580 while (logp->logSize - logp->logElements <= minSpace) {
1582 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1583 logp->logElements -= tsize;
1584 logp->firstUsed += tsize;
1585 if (logp->firstUsed >= logp->logSize)
1586 logp->firstUsed -= logp->logSize;
1587 logp->baseCookie += tsize;
1591 /* append string astr to buffer, including terminating null char.
1593 * log must be write-locked.
1595 #define ICL_CHARSPERLONG 4
1596 static afs_int32 afs_icl_AppendString(logp, astr)
1597 struct afs_icl_log *logp;
1600 char *op; /* ptr to char to write */
1602 register int bib; /* bytes in buffer */
1605 op = (char *) &(logp->datap[logp->firstFree]);
1609 if (++bib >= ICL_CHARSPERLONG) {
1612 if (++(logp->firstFree) >= logp->logSize) {
1613 logp->firstFree = 0;
1614 op = (char *) &(logp->datap[0]);
1616 logp->logElements++;
1621 /* if we've used this word at all, allocate it */
1622 if (++(logp->firstFree) >= logp->logSize) {
1623 logp->firstFree = 0;
1625 logp->logElements++;
1629 /* add a long to the log, ignoring overflow (checked already) */
1630 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1631 #define ICL_APPENDINT32(lp, x) \
1633 (lp)->datap[(lp)->firstFree] = (x); \
1634 if (++((lp)->firstFree) >= (lp)->logSize) { \
1635 (lp)->firstFree = 0; \
1637 (lp)->logElements++; \
1640 #define ICL_APPENDLONG(lp, x) \
1642 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1643 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1646 #else /* AFS_ALPHA_ENV */
1647 #define ICL_APPENDLONG(lp, x) \
1649 (lp)->datap[(lp)->firstFree] = (x); \
1650 if (++((lp)->firstFree) >= (lp)->logSize) { \
1651 (lp)->firstFree = 0; \
1653 (lp)->logElements++; \
1655 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1656 #endif /* AFS_ALPHA_ENV */
1658 /* routine to tell whether we're dealing with the address or the
1661 afs_icl_UseAddr(type)
1664 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1665 || type == ICL_TYPE_FID)
1671 /* Function to append a record to the log. Written for speed
1672 * since we know that we're going to have to make this work fast
1673 * pretty soon, anyway. The log must be unlocked.
1676 afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4)
1677 register struct afs_icl_log *logp;
1680 long p1, p2, p3, p4;
1682 int rsize; /* record size in longs */
1683 register int tsize; /* temp size */
1687 t4 = types & 0x3f; /* decode types */
1695 osi_GetTime(&tv); /* It panics for solaris if inside */
1696 ObtainWriteLock(&logp->lock,182);
1698 ReleaseWriteLock(&logp->lock);
1702 /* get timestamp as # of microseconds since some time that doesn't
1703 * change that often. This algorithm ticks over every 20 minutes
1704 * or so (1000 seconds). Write a timestamp record if it has.
1706 if (tv.tv_sec - logp->lastTS > 1024)
1708 /* the timer has wrapped -- write a timestamp record */
1709 if (logp->logSize - logp->logElements <= 5)
1710 afs_icl_GetLogSpace(logp, 5);
1712 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1713 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1714 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1715 ICL_APPENDINT32(logp,
1716 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1717 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1719 logp->lastTS = tv.tv_sec;
1722 rsize = 4; /* base case */
1724 /* compute size of parameter p1. Only tricky case is string.
1725 * In that case, we have to call strlen to get the string length.
1727 ICL_SIZEHACK(t1, p1);
1730 /* compute size of parameter p2. Only tricky case is string.
1731 * In that case, we have to call strlen to get the string length.
1733 ICL_SIZEHACK(t2, p2);
1736 /* compute size of parameter p3. Only tricky case is string.
1737 * In that case, we have to call strlen to get the string length.
1739 ICL_SIZEHACK(t3, p3);
1742 /* compute size of parameter p4. Only tricky case is string.
1743 * In that case, we have to call strlen to get the string length.
1745 ICL_SIZEHACK(t4, p4);
1748 /* At this point, we've computed all of the parameter sizes, and
1749 * have in rsize the size of the entire record we want to append.
1750 * Next, we check that we actually have room in the log to do this
1751 * work, and then we do the append.
1754 ReleaseWriteLock(&logp->lock);
1755 return; /* log record too big to express */
1758 if (logp->logSize - logp->logElements <= rsize)
1759 afs_icl_GetLogSpace(logp, rsize);
1761 ICL_APPENDINT32(logp,
1762 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
1763 ICL_APPENDINT32(logp, (afs_int32)op);
1764 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
1765 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1768 /* marshall parameter 1 now */
1769 if (t1 == ICL_TYPE_STRING) {
1770 afs_icl_AppendString(logp, (char *) p1);
1772 else if (t1 == ICL_TYPE_HYPER) {
1773 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
1774 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
1776 else if (t1 == ICL_TYPE_FID) {
1777 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1778 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1779 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
1780 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
1782 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1783 else if (t1 == ICL_TYPE_INT32)
1784 ICL_APPENDINT32(logp, (afs_int32)p1);
1785 #endif /* AFS_ALPHA_ENV */
1786 else ICL_APPENDLONG(logp, p1);
1789 /* marshall parameter 2 now */
1790 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
1791 else if (t2 == ICL_TYPE_HYPER) {
1792 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
1793 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
1795 else if (t2 == ICL_TYPE_FID) {
1796 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1797 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1798 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
1799 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
1801 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1802 else if (t2 == ICL_TYPE_INT32)
1803 ICL_APPENDINT32(logp, (afs_int32)p2);
1804 #endif /* AFS_ALPHA_ENV */
1805 else ICL_APPENDLONG(logp, p2);
1808 /* marshall parameter 3 now */
1809 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
1810 else if (t3 == ICL_TYPE_HYPER) {
1811 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
1812 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
1814 else if (t3 == ICL_TYPE_FID) {
1815 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1816 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1817 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
1818 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
1820 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1821 else if (t3 == ICL_TYPE_INT32)
1822 ICL_APPENDINT32(logp, (afs_int32)p3);
1823 #endif /* AFS_ALPHA_ENV */
1824 else ICL_APPENDLONG(logp, p3);
1827 /* marshall parameter 4 now */
1828 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
1829 else if (t4 == ICL_TYPE_HYPER) {
1830 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
1831 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
1833 else if (t4 == ICL_TYPE_FID) {
1834 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
1835 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
1836 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
1837 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
1839 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1840 else if (t4 == ICL_TYPE_INT32)
1841 ICL_APPENDINT32(logp, (afs_int32)p4);
1842 #endif /* AFS_ALPHA_ENV */
1843 else ICL_APPENDLONG(logp, p4);
1845 ReleaseWriteLock(&logp->lock);
1848 /* create a log with size logSize; return it in *outLogpp and tag
1849 * it with name "name."
1851 afs_icl_CreateLog(name, logSize, outLogpp)
1854 struct afs_icl_log **outLogpp;
1856 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
1859 /* create a log with size logSize; return it in *outLogpp and tag
1860 * it with name "name." 'flags' can be set to make the log unclearable.
1862 afs_icl_CreateLogWithFlags(name, logSize, flags, outLogpp)
1866 struct afs_icl_log **outLogpp;
1868 register struct afs_icl_log *logp;
1870 /* add into global list under lock */
1871 ObtainWriteLock(&afs_icl_lock,183);
1872 if (!afs_icl_inited) afs_icl_Init();
1874 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
1875 if (strcmp(logp->name, name) == 0) {
1876 /* found it already created, just return it */
1879 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
1881 ObtainWriteLock(&logp->lock,184);
1882 logp->states |= ICL_LOGF_PERSISTENT;
1883 ReleaseWriteLock(&logp->lock);
1885 ReleaseWriteLock(&afs_icl_lock);
1890 logp = (struct afs_icl_log *)
1891 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
1892 bzero((caddr_t)logp, sizeof(*logp));
1895 logp->name = osi_AllocSmallSpace(strlen(name)+1);
1896 strcpy(logp->name, name);
1897 LOCK_INIT(&logp->lock, "logp lock");
1898 logp->logSize = logSize;
1899 logp->datap = (afs_int32 *)0; /* don't allocate it until we need it */
1901 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
1902 logp->states |= ICL_LOGF_PERSISTENT;
1904 logp->nextp = afs_icl_allLogs;
1905 afs_icl_allLogs = logp;
1906 ReleaseWriteLock(&afs_icl_lock);
1912 /* called with a log, a pointer to a buffer, the size of the buffer
1913 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
1914 * and returns data in the provided buffer, and returns output flags
1915 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
1916 * find the record with cookie value cookie.
1918 afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp)
1919 register struct afs_icl_log *logp;
1921 afs_int32 *bufSizep;
1922 afs_uint32 *cookiep;
1925 afs_int32 nwords; /* number of words to copy out */
1926 afs_uint32 startCookie; /* first cookie to use */
1927 register afs_int32 i;
1928 afs_int32 outWords; /* words we've copied out */
1929 afs_int32 inWords; /* max words to copy out */
1930 afs_int32 code; /* return code */
1931 afs_int32 ix; /* index we're copying from */
1932 afs_int32 outFlags; /* return flags */
1933 afs_int32 inFlags; /* flags passed in */
1936 inWords = *bufSizep; /* max to copy out */
1937 outWords = 0; /* amount copied out */
1938 startCookie = *cookiep;
1943 ObtainWriteLock(&logp->lock,185);
1945 ReleaseWriteLock(&logp->lock);
1949 /* first, compute the index of the start cookie we've been passed */
1951 /* (re-)compute where we should start */
1952 if (startCookie < logp->baseCookie) {
1953 if (startCookie) /* missed some output */
1954 outFlags |= ICL_COPYOUTF_MISSEDSOME;
1955 /* skip to the first available record */
1956 startCookie = logp->baseCookie;
1957 *cookiep = startCookie;
1960 /* compute where we find the first element to copy out */
1961 ix = logp->firstUsed + startCookie - logp->baseCookie;
1962 if (ix >= logp->logSize) ix -= logp->logSize;
1964 /* if have some data now, break out and process it */
1965 if (startCookie - logp->baseCookie < logp->logElements) break;
1967 /* At end of log, so clear it if we need to */
1968 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
1970 logp->firstUsed = logp->firstFree = 0;
1971 logp->logElements = 0;
1973 /* otherwise, either wait for the data to arrive, or return */
1974 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
1975 ReleaseWriteLock(&logp->lock);
1979 logp->states |= ICL_LOGF_WAITING;
1980 ReleaseWriteLock(&logp->lock);
1981 afs_osi_Sleep(&logp->lock);
1982 ObtainWriteLock(&logp->lock,186);
1984 /* copy out data from ix to logSize or firstFree, depending
1985 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
1986 * be careful not to copy out more than nwords.
1988 if (ix >= logp->firstUsed) {
1989 if (logp->firstUsed <= logp->firstFree)
1991 end = logp->firstFree; /* first element not to copy */
1993 end = logp->logSize;
1994 nwords = inWords; /* don't copy more than this */
1995 if (end - ix < nwords)
1998 bcopy((char *) &logp->datap[ix], (char *) bufferp,
1999 sizeof(afs_int32) * nwords);
2004 /* if we're going to copy more out below, we'll start here */
2007 /* now, if active part of the log has wrapped, there's more stuff
2008 * starting at the head of the log. Copy out more from there.
2010 if (logp->firstUsed > logp->firstFree
2011 && ix < logp->firstFree && inWords > 0) {
2012 /* (more to) copy out from the wrapped section at the
2013 * start of the log. May get here even if didn't copy any
2014 * above, if the cookie points directly into the wrapped section.
2017 if (logp->firstFree - ix < nwords)
2018 nwords = logp->firstFree - ix;
2019 bcopy((char *) &logp->datap[ix], (char *) bufferp,
2020 sizeof(afs_int32) * nwords);
2026 ReleaseWriteLock(&logp->lock);
2030 *bufSizep = outWords;
2036 /* return basic parameter information about a log */
2037 afs_icl_GetLogParms(logp, maxSizep, curSizep)
2038 struct afs_icl_log *logp;
2039 afs_int32 *maxSizep;
2040 afs_int32 *curSizep;
2042 ObtainReadLock(&logp->lock);
2043 *maxSizep = logp->logSize;
2044 *curSizep = logp->logElements;
2045 ReleaseReadLock(&logp->lock);
2050 /* hold and release logs */
2051 afs_icl_LogHold(logp)
2052 register struct afs_icl_log *logp;
2054 ObtainWriteLock(&afs_icl_lock,187);
2056 ReleaseWriteLock(&afs_icl_lock);
2060 /* hold and release logs, called with lock already held */
2061 afs_icl_LogHoldNL(logp)
2062 register struct afs_icl_log *logp;
2068 /* keep track of how many sets believe the log itself is allocated */
2069 afs_icl_LogUse(logp)
2070 register struct afs_icl_log *logp;
2072 ObtainWriteLock(&logp->lock,188);
2073 if (logp->setCount == 0) {
2074 /* this is the first set actually using the log -- allocate it */
2075 if (logp->logSize == 0) {
2076 /* we weren't passed in a hint and it wasn't set */
2077 logp->logSize = ICL_DEFAULT_LOGSIZE;
2079 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2080 #ifdef AFS_AIX32_ENV
2081 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2085 ReleaseWriteLock(&logp->lock);
2089 /* decrement the number of real users of the log, free if possible */
2090 afs_icl_LogFreeUse(logp)
2091 register struct afs_icl_log *logp;
2093 ObtainWriteLock(&logp->lock,189);
2094 if (--logp->setCount == 0) {
2095 /* no more users -- free it (but keep log structure around)*/
2096 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2097 #ifdef AFS_AIX32_ENV
2098 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2100 logp->firstUsed = logp->firstFree = 0;
2101 logp->logElements = 0;
2102 logp->datap = (afs_int32 *)0;
2104 ReleaseWriteLock(&logp->lock);
2108 /* set the size of the log to 'logSize' */
2109 afs_icl_LogSetSize(logp, logSize)
2110 register struct afs_icl_log *logp;
2113 ObtainWriteLock(&logp->lock,190);
2115 /* nothing to worry about since it's not allocated */
2116 logp->logSize = logSize;
2120 logp->firstUsed = logp->firstFree = 0;
2121 logp->logElements = 0;
2123 /* free and allocate a new one */
2124 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2125 #ifdef AFS_AIX32_ENV
2126 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2128 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2129 #ifdef AFS_AIX32_ENV
2130 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2132 logp->logSize = logSize;
2134 ReleaseWriteLock(&logp->lock);
2139 /* free a log. Called with afs_icl_lock locked. */
2140 afs_icl_ZapLog(logp)
2141 register struct afs_icl_log *logp;
2143 register struct afs_icl_log **lpp, *tp;
2145 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2147 /* found the dude we want to remove */
2149 osi_FreeSmallSpace(logp->name);
2150 osi_FreeSmallSpace(logp->datap);
2151 osi_FreeSmallSpace(logp);
2152 break; /* won't find it twice */
2158 /* do the release, watching for deleted entries */
2159 afs_icl_LogRele(logp)
2160 register struct afs_icl_log *logp;
2162 ObtainWriteLock(&afs_icl_lock,191);
2163 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2164 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2166 ReleaseWriteLock(&afs_icl_lock);
2170 /* do the release, watching for deleted entries, log already held */
2171 afs_icl_LogReleNL(logp)
2172 register struct afs_icl_log *logp;
2174 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2175 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2180 /* zero out the log */
2181 afs_icl_ZeroLog(logp)
2182 register struct afs_icl_log *logp;
2184 ObtainWriteLock(&logp->lock,192);
2185 logp->firstUsed = logp->firstFree = 0;
2186 logp->logElements = 0;
2187 logp->baseCookie = 0;
2188 ReleaseWriteLock(&logp->lock);
2192 /* free a log entry, and drop its reference count */
2193 afs_icl_LogFree(logp)
2194 register struct afs_icl_log *logp;
2196 ObtainWriteLock(&logp->lock,193);
2197 logp->states |= ICL_LOGF_DELETED;
2198 ReleaseWriteLock(&logp->lock);
2199 afs_icl_LogRele(logp);
2203 /* find a log by name, returning it held */
2204 struct afs_icl_log *afs_icl_FindLog(name)
2207 register struct afs_icl_log *tp;
2208 ObtainWriteLock(&afs_icl_lock,194);
2209 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2210 if (strcmp(tp->name, name) == 0) {
2211 /* this is the dude we want */
2216 ReleaseWriteLock(&afs_icl_lock);
2220 afs_icl_EnumerateLogs(aproc, arock)
2224 register struct afs_icl_log *tp;
2225 register afs_int32 code;
2228 ObtainWriteLock(&afs_icl_lock,195);
2229 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2230 tp->refCount++; /* hold this guy */
2231 ReleaseWriteLock(&afs_icl_lock);
2232 ObtainReadLock(&tp->lock);
2233 code = (*aproc)(tp->name, arock, tp);
2234 ReleaseReadLock(&tp->lock);
2235 ObtainWriteLock(&afs_icl_lock,196);
2236 if (--tp->refCount == 0)
2240 ReleaseWriteLock(&afs_icl_lock);
2244 struct afs_icl_set *afs_icl_allSets = 0;
2246 afs_icl_CreateSet(name, baseLogp, fatalLogp, outSetpp)
2248 struct afs_icl_log *baseLogp;
2249 struct afs_icl_log *fatalLogp;
2250 struct afs_icl_set **outSetpp;
2252 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2253 /*flags*/0, outSetpp);
2256 /* create a set, given pointers to base and fatal logs, if any.
2257 * Logs are unlocked, but referenced, and *outSetpp is returned
2258 * referenced. Function bumps reference count on logs, since it
2259 * addds references from the new afs_icl_set. When the set is destroyed,
2260 * those references will be released.
2262 afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp)
2264 struct afs_icl_log *baseLogp;
2265 struct afs_icl_log *fatalLogp;
2267 struct afs_icl_set **outSetpp;
2269 register struct afs_icl_set *setp;
2271 afs_int32 states = ICL_DEFAULT_SET_STATES;
2273 ObtainWriteLock(&afs_icl_lock,197);
2274 if (!afs_icl_inited) afs_icl_Init();
2276 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2277 if (strcmp(setp->name, name) == 0) {
2280 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2282 ObtainWriteLock(&setp->lock,198);
2283 setp->states |= ICL_SETF_PERSISTENT;
2284 ReleaseWriteLock(&setp->lock);
2286 ReleaseWriteLock(&afs_icl_lock);
2291 /* determine initial state */
2292 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2293 states = ICL_SETF_ACTIVE;
2294 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2295 states = ICL_SETF_FREED;
2296 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2297 states |= ICL_SETF_PERSISTENT;
2299 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2300 bzero((caddr_t)setp, sizeof(*setp));
2302 if (states & ICL_SETF_FREED)
2303 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2304 setp->states = states;
2306 LOCK_INIT(&setp->lock, "setp lock");
2307 /* next lock is obtained in wrong order, hierarchy-wise, but
2308 * it doesn't matter, since no one can find this lock yet, since
2309 * the afs_icl_lock is still held, and thus the obtain can't block.
2311 ObtainWriteLock(&setp->lock,199);
2312 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2313 strcpy(setp->name, name);
2314 setp->nevents = ICL_DEFAULTEVENTS;
2315 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2316 #ifdef AFS_AIX32_ENV
2317 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2319 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2320 setp->eventFlags[i] = 0xff; /* default to enabled */
2322 /* update this global info under the afs_icl_lock */
2323 setp->nextp = afs_icl_allSets;
2324 afs_icl_allSets = setp;
2325 ReleaseWriteLock(&afs_icl_lock);
2327 /* set's basic lock is still held, so we can finish init */
2329 setp->logs[0] = baseLogp;
2330 afs_icl_LogHold(baseLogp);
2331 if (!(setp->states & ICL_SETF_FREED))
2332 afs_icl_LogUse(baseLogp); /* log is actually being used */
2335 setp->logs[1] = fatalLogp;
2336 afs_icl_LogHold(fatalLogp);
2337 if (!(setp->states & ICL_SETF_FREED))
2338 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2340 ReleaseWriteLock(&setp->lock);
2346 /* function to change event enabling information for a particular set */
2347 afs_icl_SetEnable(setp, eventID, setValue)
2348 struct afs_icl_set *setp;
2354 ObtainWriteLock(&setp->lock,200);
2355 if (!ICL_EVENTOK(setp, eventID)) {
2356 ReleaseWriteLock(&setp->lock);
2359 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2361 *tp |= ICL_EVENTMASK(eventID);
2363 *tp &= ~(ICL_EVENTMASK(eventID));
2364 ReleaseWriteLock(&setp->lock);
2368 /* return indication of whether a particular event ID is enabled
2369 * for tracing. If *getValuep is set to 0, the event is disabled,
2370 * otherwise it is enabled. All events start out enabled by default.
2372 afs_icl_GetEnable(setp, eventID, getValuep)
2373 struct afs_icl_set *setp;
2377 ObtainReadLock(&setp->lock);
2378 if (!ICL_EVENTOK(setp, eventID)) {
2379 ReleaseWriteLock(&setp->lock);
2382 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2386 ReleaseReadLock(&setp->lock);
2390 /* hold and release event sets */
2391 afs_icl_SetHold(setp)
2392 register struct afs_icl_set *setp;
2394 ObtainWriteLock(&afs_icl_lock,201);
2396 ReleaseWriteLock(&afs_icl_lock);
2400 /* free a set. Called with afs_icl_lock locked */
2401 afs_icl_ZapSet(setp)
2402 register struct afs_icl_set *setp;
2404 register struct afs_icl_set **lpp, *tp;
2406 register struct afs_icl_log *tlp;
2408 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2410 /* found the dude we want to remove */
2412 osi_FreeSmallSpace(setp->name);
2413 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2414 #ifdef AFS_AIX32_ENV
2415 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2417 for(i=0; i < ICL_LOGSPERSET; i++) {
2418 if (tlp = setp->logs[i])
2419 afs_icl_LogReleNL(tlp);
2421 osi_FreeSmallSpace(setp);
2422 break; /* won't find it twice */
2428 /* do the release, watching for deleted entries */
2429 afs_icl_SetRele(setp)
2430 register struct afs_icl_set *setp;
2432 ObtainWriteLock(&afs_icl_lock,202);
2433 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2434 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2436 ReleaseWriteLock(&afs_icl_lock);
2440 /* free a set entry, dropping its reference count */
2441 afs_icl_SetFree(setp)
2442 register struct afs_icl_set *setp;
2444 ObtainWriteLock(&setp->lock,203);
2445 setp->states |= ICL_SETF_DELETED;
2446 ReleaseWriteLock(&setp->lock);
2447 afs_icl_SetRele(setp);
2451 /* find a set by name, returning it held */
2452 struct afs_icl_set *afs_icl_FindSet(name)
2455 register struct afs_icl_set *tp;
2456 ObtainWriteLock(&afs_icl_lock,204);
2457 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2458 if (strcmp(tp->name, name) == 0) {
2459 /* this is the dude we want */
2464 ReleaseWriteLock(&afs_icl_lock);
2468 /* zero out all the logs in the set */
2469 afs_icl_ZeroSet(setp)
2470 struct afs_icl_set *setp;
2475 struct afs_icl_log *logp;
2477 ObtainReadLock(&setp->lock);
2478 for(i = 0; i < ICL_LOGSPERSET; i++) {
2479 logp = setp->logs[i];
2481 afs_icl_LogHold(logp);
2482 tcode = afs_icl_ZeroLog(logp);
2483 if (tcode != 0) code = tcode; /* save the last bad one */
2484 afs_icl_LogRele(logp);
2487 ReleaseReadLock(&setp->lock);
2491 afs_icl_EnumerateSets(aproc, arock)
2495 register struct afs_icl_set *tp, *np;
2496 register afs_int32 code;
2499 ObtainWriteLock(&afs_icl_lock,205);
2500 for(tp = afs_icl_allSets; tp; tp=np) {
2501 tp->refCount++; /* hold this guy */
2502 ReleaseWriteLock(&afs_icl_lock);
2503 code = (*aproc)(tp->name, arock, tp);
2504 ObtainWriteLock(&afs_icl_lock,206);
2505 np = tp->nextp; /* tp may disappear next, but not np */
2506 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2510 ReleaseWriteLock(&afs_icl_lock);
2514 afs_icl_AddLogToSet(setp, newlogp)
2515 struct afs_icl_set *setp;
2516 struct afs_icl_log *newlogp;
2520 struct afs_icl_log *logp;
2522 ObtainWriteLock(&setp->lock,207);
2523 for(i = 0; i < ICL_LOGSPERSET; i++) {
2524 if (!setp->logs[i]) {
2525 setp->logs[i] = newlogp;
2527 afs_icl_LogHold(newlogp);
2528 if (!(setp->states & ICL_SETF_FREED)) {
2529 /* bump up the number of sets using the log */
2530 afs_icl_LogUse(newlogp);
2535 ReleaseWriteLock(&setp->lock);
2539 afs_icl_SetSetStat(setp, op)
2540 struct afs_icl_set *setp;
2545 struct afs_icl_log *logp;
2547 ObtainWriteLock(&setp->lock,208);
2549 case ICL_OP_SS_ACTIVATE: /* activate a log */
2551 * If we are not already active, see if we have released
2552 * our demand that the log be allocated (FREED set). If
2553 * we have, reassert our desire.
2555 if (!(setp->states & ICL_SETF_ACTIVE)) {
2556 if (setp->states & ICL_SETF_FREED) {
2557 /* have to reassert desire for logs */
2558 for(i = 0; i < ICL_LOGSPERSET; i++) {
2559 logp = setp->logs[i];
2561 afs_icl_LogHold(logp);
2562 afs_icl_LogUse(logp);
2563 afs_icl_LogRele(logp);
2566 setp->states &= ~ICL_SETF_FREED;
2568 setp->states |= ICL_SETF_ACTIVE;
2573 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2574 /* this doesn't require anything beyond clearing the ACTIVE flag */
2575 setp->states &= ~ICL_SETF_ACTIVE;
2579 case ICL_OP_SS_FREE: /* deassert design for log */
2581 * if we are already in this state, do nothing; otherwise
2582 * deassert desire for log
2584 if (setp->states & ICL_SETF_ACTIVE)
2587 if (!(setp->states & ICL_SETF_FREED)) {
2588 for(i = 0; i < ICL_LOGSPERSET; i++) {
2589 logp = setp->logs[i];
2591 afs_icl_LogHold(logp);
2592 afs_icl_LogFreeUse(logp);
2593 afs_icl_LogRele(logp);
2596 setp->states |= ICL_SETF_FREED;
2605 ReleaseWriteLock(&setp->lock);