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 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
823 /* Main entry of all afs system calls */
825 extern int afs_sinited;
827 /** The 32 bit OS expects the members of this structure to be 32 bit
828 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
829 * to accomodate both, *long* is used instead of afs_int32
854 Afs_syscall (uap, rvp)
855 register struct afssysa *uap;
858 int *retval = &rvp->r_val1;
859 #else /* AFS_SUN5_ENV */
860 #if defined(AFS_OSF_ENV)
861 afs3_syscall(p, args, retval)
874 } *uap = (struct a *)args;
875 #else /* AFS_OSF_ENV */
876 #ifdef AFS_LINUX20_ENV
884 long parm6; /* not actually used - should be removed */
886 /* Linux system calls only set up for 5 arguments. */
887 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
890 struct afssysargs args, *uap = &args;
892 int *retval = &linux_ret;
893 int eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
906 } *uap = (struct a *)u.u_ap;
908 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
912 #endif /* SUN && !SUN5 */
922 } *uap = (struct a *)u.u_ap;
924 #if defined(AFS_DEC_ENV)
925 int *retval = &u.u_r.r_val1;
927 #if defined(AFS_HPUX_ENV)
928 long *retval = &u.u_rval1;
930 int *retval = &u.u_rval1;
933 #endif /* AFS_LINUX20_ENV */
934 #endif /* AFS_OSF_ENV */
935 #endif /* AFS_SUN5_ENV */
936 register int code = 0;
938 AFS_STATCNT(afs_syscall);
945 #ifdef AFS_LINUX20_ENV
947 /* setup uap for use below - pull out the magic decoder ring to know
948 * which syscalls have folded argument lists.
950 uap->syscall = syscall;
954 if (syscall == AFSCALL_ICL) {
955 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
956 uap->parm4 = eparm[0];
957 uap->parm5 = eparm[1];
958 uap->parm6 = eparm[2];
967 #if defined(AFS_HPUX_ENV)
969 * There used to be code here (duplicated from osi_Init()) for
970 * initializing the semaphore used by AFS_GLOCK(). Was the
971 * duplication to handle the case of a dynamically loaded kernel
976 if (uap->syscall == AFSCALL_CALL) {
978 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
979 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
981 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
983 } else if (uap->syscall == AFSCALL_SETPAG) {
986 register proc_t *procp;
988 procp = ttoproc(curthread);
989 mutex_enter(&procp->p_crlock);
990 cred = procp->p_cred;
992 code = afs_setpag(&cred);
994 procp->p_cred = cred;
995 mutex_exit(&procp->p_crlock);
998 #if defined(AFS_OSF_ENV)
999 code = afs_setpag(p, args, retval);
1000 #else /* AFS_OSF_ENV */
1001 code = afs_setpag();
1005 } else if (uap->syscall == AFSCALL_PIOCTL) {
1008 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1010 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1013 } else if (uap->syscall == AFSCALL_ICREATE) {
1014 struct iparam iparams;
1016 code = copyin_iparam((char *)uap->parm3, &iparams);
1018 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV)
1023 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1024 iparams.param3, iparams.param4, rvp, CRED());
1026 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1028 iparams.param3, iparams.param4, retval);
1030 iparams.param3, iparams.param4);
1032 #endif /* AFS_SUN5_ENV */
1033 } else if (uap->syscall == AFSCALL_IOPEN) {
1035 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1038 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1040 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1042 #endif /* AFS_SUN5_ENV */
1043 } else if (uap->syscall == AFSCALL_IDEC) {
1045 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1047 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1048 #endif /* AFS_SUN5_ENV */
1049 } else if (uap->syscall == AFSCALL_IINC) {
1051 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1053 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1054 #endif /* AFS_SUN5_ENV */
1055 } else if (uap->syscall == AFSCALL_ICL) {
1057 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1059 #ifdef AFS_LINUX20_ENV
1061 /* ICL commands can return values. */
1062 code = -linux_ret; /* Gets negated again at exit below */
1066 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV)
1070 #endif /* !AFS_LINUX20_ENV */
1072 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV)
1076 #endif /* AFS_SUN5_ENV */
1079 #ifdef AFS_LINUX20_ENV
1085 #endif /* AFS_SGI_ENV */
1086 #endif /* !AFS_AIX32_ENV */
1089 * Initstate in the range 0 < x < 100 are early initialization states.
1090 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1091 * the cache may be initialized.
1092 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1093 * is done after all the cache initialization has been done.
1094 * Initstate of 200 means that the volume has been looked up once, possibly
1096 * Initstate of 300 means that the volume has been *successfully* looked up.
1099 register int code = 0;
1101 AFS_STATCNT(afs_CheckInit);
1102 if (afs_initState <= 100)
1103 code = ENXIO; /* never finished init phase */
1104 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1105 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1106 } else if (afs_initState == 200)
1107 code = ETIMEDOUT; /* didn't find root volume */
1111 int afs_shuttingdown = 0;
1115 extern short afs_brsDaemons;
1116 extern afs_int32 afs_CheckServerDaemonStarted;
1117 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1118 extern struct osi_file *afs_cacheInodep;
1120 AFS_STATCNT(afs_shutdown);
1121 if (afs_shuttingdown) return;
1122 afs_shuttingdown = 1;
1123 if (afs_cold_shutdown) afs_warn("COLD ");
1124 else afs_warn("WARM ");
1125 afs_warn("shutting down of: CB... ");
1127 afs_termState = AFSOP_STOP_RXCALLBACK;
1128 rx_WakeupServerProcs();
1129 /* shutdown_rxkernel(); */
1130 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1131 afs_osi_Sleep(&afs_termState);
1133 afs_warn("afs... ");
1134 while (afs_termState == AFSOP_STOP_AFS) {
1135 afs_osi_CancelWait(&AFS_WaitHandler);
1136 afs_osi_Sleep(&afs_termState);
1138 if (afs_CheckServerDaemonStarted) {
1139 while (afs_termState == AFSOP_STOP_CS) {
1140 afs_osi_CancelWait(&AFS_CSWaitHandler);
1141 afs_osi_Sleep(&afs_termState);
1144 afs_warn("BkG... ");
1145 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1146 while (afs_termState == AFSOP_STOP_BKG) {
1147 afs_osi_Wakeup(&afs_brsDaemons);
1148 afs_osi_Sleep(&afs_termState);
1150 afs_warn("CTrunc... ");
1151 /* Cancel cache truncate daemon. */
1152 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1153 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1154 afs_osi_Sleep(&afs_termState);
1156 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1157 afs_warn("RxEvent... ");
1158 /* cancel rx event deamon */
1159 while (afs_termState == AFSOP_STOP_RXEVENT)
1160 afs_osi_Sleep(&afs_termState);
1161 #if defined(RXK_LISTENER_ENV)
1162 afs_warn("RxListener... ");
1163 /* cancel rx listener */
1164 osi_StopListener(); /* This closes rx_socket. */
1165 while (afs_termState == AFSOP_STOP_RXK_LISTENER)
1166 afs_osi_Sleep(&afs_termState);
1169 afs_termState = AFSOP_STOP_COMPLETE;
1173 /* Close file only after daemons which can write to it are stopped. */
1174 if (afs_cacheInodep) /* memcache won't set this */
1176 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1177 afs_cacheInodep = 0;
1179 return; /* Just kill daemons for now */
1183 shutdown_rxkernel();
1187 shutdown_bufferpackage();
1193 shutdown_vnodeops();
1195 shutdown_exporter();
1196 shutdown_memcache();
1197 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1198 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1199 /* this routine does not exist in Ultrix systems... 93.01.19 */
1201 #endif /* AFS_DEC_ENV */
1204 /* The following hold the cm stats */
1206 bzero(&afs_cmstats, sizeof(struct afs_CMStats));
1207 bzero(&afs_stats_cmperf, sizeof(struct afs_stats_CMPerf));
1208 bzero(&afs_stats_cmfullperf, sizeof(struct afs_stats_CMFullPerf));
1210 afs_warn(" ALL allocated tables\n");
1211 afs_shuttingdown = 0;
1217 AFS_STATCNT(shutdown_afstest);
1218 afs_initState = afs_termState = afs_setTime = 0;
1219 AFS_Running = afs_CB_Running = 0;
1220 afs_CacheInit_Done = afs_Go_Done = 0;
1221 if (afs_cold_shutdown) {
1222 *afs_rootVolumeName = 0;
1227 /* In case there is a bunch of dynamically build bkg daemons to free */
1229 { AFS_STATCNT(shutdown_BKG); }
1232 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1233 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1234 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1235 int afs_icl_sizeofLong = 1;
1237 int afs_icl_sizeofLong = 2;
1240 int afs_icl_sizeofLong = 1;
1243 int afs_icl_inited = 0;
1245 /* init function, called once, under afs_icl_lock */
1252 extern struct afs_icl_log *afs_icl_FindLog();
1253 extern struct afs_icl_set *afs_icl_FindSet();
1257 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1260 afs_int32 *lp, elts, flags;
1261 register afs_int32 code;
1262 struct afs_icl_log *logp;
1263 struct afs_icl_set *setp;
1264 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV)
1266 #else /* AFS_SGI61_ENV */
1268 #endif /* AFS_SGI61_ENV */
1270 afs_int32 startCookie;
1271 afs_int32 allocated;
1272 struct afs_icl_log *tlp;
1275 if (!afs_suser(CRED())) { /* only root can run this code */
1279 if (!afs_suser()) { /* only root can run this code */
1280 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV)
1289 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1290 case ICL_OP_COPYOUT: /* copy ouy data */
1291 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1292 * return flags<<24 + nwords.
1293 * updates cookie to updated start (not end) if we had to
1294 * skip some records.
1296 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1297 if (code) return code;
1298 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1299 if (code) return code;
1300 logp = afs_icl_FindLog(tname);
1301 if (!logp) return ENOENT;
1302 #define BUFFERSIZE AFS_LRALLOCSIZ
1303 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1304 elts = BUFFERSIZE / sizeof(afs_int32);
1305 if (p3 < elts) elts = p3;
1306 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1307 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1310 osi_FreeLargeSpace((struct osi_buffer *) lp);
1313 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1314 if (code) goto done;
1315 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1316 if (code) goto done;
1317 *retval = (flags<<24) | (elts & 0xffffff);
1319 afs_icl_LogRele(logp);
1320 osi_FreeLargeSpace((struct osi_buffer *) lp);
1323 case ICL_OP_ENUMLOGS: /* enumerate logs */
1324 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1325 * return 0 for success, otherwise error.
1327 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1328 if (p1-- == 0) break;
1330 if (!tlp) return ENOENT; /* past the end of file */
1331 temp = strlen(tlp->name)+1;
1332 if (temp > p3) return EINVAL;
1333 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1334 if (!code) /* copy out size of log */
1335 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1338 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1339 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1340 * return 0 for success, otherwise error.
1342 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1343 if (code) return code;
1344 setp = afs_icl_FindSet(tname);
1345 if (!setp) return ENOENT;
1346 if (p2 > ICL_LOGSPERSET)
1348 if (!(tlp = setp->logs[p2]))
1350 temp = strlen(tlp->name)+1;
1351 if (temp > p4) return EINVAL;
1352 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1355 case ICL_OP_CLRLOG: /* clear specified log */
1356 /* zero out the specified log: p1=logname */
1357 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1358 if (code) return code;
1359 logp = afs_icl_FindLog(tname);
1360 if (!logp) return ENOENT;
1361 code = afs_icl_ZeroLog(logp);
1362 afs_icl_LogRele(logp);
1365 case ICL_OP_CLRSET: /* clear specified set */
1366 /* zero out the specified set: p1=setname */
1367 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1368 if (code) return code;
1369 setp = afs_icl_FindSet(tname);
1370 if (!setp) return ENOENT;
1371 code = afs_icl_ZeroSet(setp);
1372 afs_icl_SetRele(setp);
1375 case ICL_OP_CLRALL: /* clear all logs */
1376 /* zero out all logs -- no args */
1378 ObtainWriteLock(&afs_icl_lock,178);
1379 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1380 tlp->refCount++; /* hold this guy */
1381 ReleaseWriteLock(&afs_icl_lock);
1382 /* don't clear persistent logs */
1383 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1384 code = afs_icl_ZeroLog(tlp);
1385 ObtainWriteLock(&afs_icl_lock,179);
1386 if (--tlp->refCount == 0)
1387 afs_icl_ZapLog(tlp);
1390 ReleaseWriteLock(&afs_icl_lock);
1393 case ICL_OP_ENUMSETS: /* enumerate all sets */
1394 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1395 * return 0 for success, otherwise error.
1397 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1398 if (p1-- == 0) break;
1400 if (!setp) return ENOENT; /* past the end of file */
1401 temp = strlen(setp->name)+1;
1402 if (temp > p3) return EINVAL;
1403 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1404 if (!code) /* copy out size of log */
1405 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1408 case ICL_OP_SETSTAT: /* set status on a set */
1409 /* activate the specified set: p1=setname, p2=op */
1410 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1411 if (code) return code;
1412 setp = afs_icl_FindSet(tname);
1413 if (!setp) return ENOENT;
1414 code = afs_icl_SetSetStat(setp, p2);
1415 afs_icl_SetRele(setp);
1418 case ICL_OP_SETSTATALL: /* set status on all sets */
1419 /* activate the specified set: p1=op */
1421 ObtainWriteLock(&afs_icl_lock,180);
1422 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1423 setp->refCount++; /* hold this guy */
1424 ReleaseWriteLock(&afs_icl_lock);
1425 /* don't set states on persistent sets */
1426 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1427 code = afs_icl_SetSetStat(setp, p1);
1428 ObtainWriteLock(&afs_icl_lock,181);
1429 if (--setp->refCount == 0)
1430 afs_icl_ZapSet(setp);
1433 ReleaseWriteLock(&afs_icl_lock);
1436 case ICL_OP_SETLOGSIZE: /* set size of log */
1437 /* set the size of the specified log: p1=logname, p2=size (in words) */
1438 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1439 if (code) return code;
1440 logp = afs_icl_FindLog(tname);
1441 if (!logp) return ENOENT;
1442 code = afs_icl_LogSetSize(logp, p2);
1443 afs_icl_LogRele(logp);
1446 case ICL_OP_GETLOGINFO: /* get size of log */
1447 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1448 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1449 if (code) return code;
1450 logp = afs_icl_FindLog(tname);
1451 if (!logp) return ENOENT;
1452 allocated = !!logp->datap;
1453 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1455 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1456 afs_icl_LogRele(logp);
1459 case ICL_OP_GETSETINFO: /* get state of set */
1460 /* zero out the specified set: p1=setname, p2=&state */
1461 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1462 if (code) return code;
1463 setp = afs_icl_FindSet(tname);
1464 if (!setp) return ENOENT;
1465 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1466 afs_icl_SetRele(setp);
1477 afs_lock_t afs_icl_lock;
1479 /* exported routine: a 4 parameter event */
1480 afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, p4)
1481 register struct afs_icl_set *setp;
1484 long p1, p2, p3, p4;
1486 register struct afs_icl_log *logp;
1489 register afs_int32 tmask;
1492 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1493 if (!ICL_SETACTIVE(setp)) return;
1496 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1497 ix = ICL_EVENTBYTE(eventID);
1498 ObtainReadLock(&setp->lock);
1499 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1500 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1502 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1506 if (mask == 0) break; /* break early */
1509 ReleaseReadLock(&setp->lock);
1512 /* Next 4 routines should be implemented via var-args or something.
1513 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1514 * Otherwise, could call afs_icl_Event4 directly.
1516 afs_icl_Event3(setp, eventID, lAndT, p1, p2, p3)
1517 register struct afs_icl_set *setp;
1522 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1525 afs_icl_Event2(setp, eventID, lAndT, p1, p2)
1526 register struct afs_icl_set *setp;
1531 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1534 afs_icl_Event1(setp, eventID, lAndT, p1)
1535 register struct afs_icl_set *setp;
1540 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1543 afs_icl_Event0(setp, eventID, lAndT)
1544 register struct afs_icl_set *setp;
1548 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1551 struct afs_icl_log *afs_icl_allLogs = 0;
1553 /* function to purge records from the start of the log, until there
1554 * is at least minSpace long's worth of space available without
1555 * making the head and the tail point to the same word.
1557 * Log must be write-locked.
1559 static afs_icl_GetLogSpace(logp, minSpace)
1560 register struct afs_icl_log *logp;
1563 register unsigned int tsize;
1565 while (logp->logSize - logp->logElements <= minSpace) {
1567 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1568 logp->logElements -= tsize;
1569 logp->firstUsed += tsize;
1570 if (logp->firstUsed >= logp->logSize)
1571 logp->firstUsed -= logp->logSize;
1572 logp->baseCookie += tsize;
1576 /* append string astr to buffer, including terminating null char.
1578 * log must be write-locked.
1580 #define ICL_CHARSPERLONG 4
1581 static afs_int32 afs_icl_AppendString(logp, astr)
1582 struct afs_icl_log *logp;
1585 char *op; /* ptr to char to write */
1587 register int bib; /* bytes in buffer */
1590 op = (char *) &(logp->datap[logp->firstFree]);
1594 if (++bib >= ICL_CHARSPERLONG) {
1597 if (++(logp->firstFree) >= logp->logSize) {
1598 logp->firstFree = 0;
1599 op = (char *) &(logp->datap[0]);
1601 logp->logElements++;
1606 /* if we've used this word at all, allocate it */
1607 if (++(logp->firstFree) >= logp->logSize) {
1608 logp->firstFree = 0;
1610 logp->logElements++;
1614 /* add a long to the log, ignoring overflow (checked already) */
1615 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1616 #define ICL_APPENDINT32(lp, x) \
1618 (lp)->datap[(lp)->firstFree] = (x); \
1619 if (++((lp)->firstFree) >= (lp)->logSize) { \
1620 (lp)->firstFree = 0; \
1622 (lp)->logElements++; \
1625 #define ICL_APPENDLONG(lp, x) \
1627 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1628 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1631 #else /* AFS_ALPHA_ENV */
1632 #define ICL_APPENDLONG(lp, x) \
1634 (lp)->datap[(lp)->firstFree] = (x); \
1635 if (++((lp)->firstFree) >= (lp)->logSize) { \
1636 (lp)->firstFree = 0; \
1638 (lp)->logElements++; \
1640 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1641 #endif /* AFS_ALPHA_ENV */
1643 /* routine to tell whether we're dealing with the address or the
1646 afs_icl_UseAddr(type)
1649 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1650 || type == ICL_TYPE_FID)
1656 /* Function to append a record to the log. Written for speed
1657 * since we know that we're going to have to make this work fast
1658 * pretty soon, anyway. The log must be unlocked.
1661 afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4)
1662 register struct afs_icl_log *logp;
1665 long p1, p2, p3, p4;
1667 int rsize; /* record size in longs */
1668 register int tsize; /* temp size */
1672 t4 = types & 0x3f; /* decode types */
1680 osi_GetTime(&tv); /* It panics for solaris if inside */
1681 ObtainWriteLock(&logp->lock,182);
1683 ReleaseWriteLock(&logp->lock);
1687 /* get timestamp as # of microseconds since some time that doesn't
1688 * change that often. This algorithm ticks over every 20 minutes
1689 * or so (1000 seconds). Write a timestamp record if it has.
1691 if (tv.tv_sec - logp->lastTS > 1024)
1693 /* the timer has wrapped -- write a timestamp record */
1694 if (logp->logSize - logp->logElements <= 5)
1695 afs_icl_GetLogSpace(logp, 5);
1697 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1698 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1699 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1700 ICL_APPENDINT32(logp,
1701 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1702 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1704 logp->lastTS = tv.tv_sec;
1707 rsize = 4; /* base case */
1709 /* compute size of parameter p1. Only tricky case is string.
1710 * In that case, we have to call strlen to get the string length.
1712 ICL_SIZEHACK(t1, p1);
1715 /* compute size of parameter p2. Only tricky case is string.
1716 * In that case, we have to call strlen to get the string length.
1718 ICL_SIZEHACK(t2, p2);
1721 /* compute size of parameter p3. Only tricky case is string.
1722 * In that case, we have to call strlen to get the string length.
1724 ICL_SIZEHACK(t3, p3);
1727 /* compute size of parameter p4. Only tricky case is string.
1728 * In that case, we have to call strlen to get the string length.
1730 ICL_SIZEHACK(t4, p4);
1733 /* At this point, we've computed all of the parameter sizes, and
1734 * have in rsize the size of the entire record we want to append.
1735 * Next, we check that we actually have room in the log to do this
1736 * work, and then we do the append.
1739 ReleaseWriteLock(&logp->lock);
1740 return; /* log record too big to express */
1743 if (logp->logSize - logp->logElements <= rsize)
1744 afs_icl_GetLogSpace(logp, rsize);
1746 ICL_APPENDINT32(logp,
1747 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
1748 ICL_APPENDINT32(logp, (afs_int32)op);
1749 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
1750 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1753 /* marshall parameter 1 now */
1754 if (t1 == ICL_TYPE_STRING) {
1755 afs_icl_AppendString(logp, (char *) p1);
1757 else if (t1 == ICL_TYPE_HYPER) {
1758 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
1759 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
1761 else if (t1 == ICL_TYPE_FID) {
1762 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1763 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1764 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
1765 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
1767 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1768 else if (t1 == ICL_TYPE_INT32)
1769 ICL_APPENDINT32(logp, (afs_int32)p1);
1770 #endif /* AFS_ALPHA_ENV */
1771 else ICL_APPENDLONG(logp, p1);
1774 /* marshall parameter 2 now */
1775 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
1776 else if (t2 == ICL_TYPE_HYPER) {
1777 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
1778 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
1780 else if (t2 == ICL_TYPE_FID) {
1781 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1782 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1783 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
1784 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
1786 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1787 else if (t2 == ICL_TYPE_INT32)
1788 ICL_APPENDINT32(logp, (afs_int32)p2);
1789 #endif /* AFS_ALPHA_ENV */
1790 else ICL_APPENDLONG(logp, p2);
1793 /* marshall parameter 3 now */
1794 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
1795 else if (t3 == ICL_TYPE_HYPER) {
1796 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
1797 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
1799 else if (t3 == ICL_TYPE_FID) {
1800 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1801 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1802 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
1803 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
1805 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1806 else if (t3 == ICL_TYPE_INT32)
1807 ICL_APPENDINT32(logp, (afs_int32)p3);
1808 #endif /* AFS_ALPHA_ENV */
1809 else ICL_APPENDLONG(logp, p3);
1812 /* marshall parameter 4 now */
1813 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
1814 else if (t4 == ICL_TYPE_HYPER) {
1815 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
1816 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
1818 else if (t4 == ICL_TYPE_FID) {
1819 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
1820 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
1821 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
1822 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
1824 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1825 else if (t4 == ICL_TYPE_INT32)
1826 ICL_APPENDINT32(logp, (afs_int32)p4);
1827 #endif /* AFS_ALPHA_ENV */
1828 else ICL_APPENDLONG(logp, p4);
1830 ReleaseWriteLock(&logp->lock);
1833 /* create a log with size logSize; return it in *outLogpp and tag
1834 * it with name "name."
1836 afs_icl_CreateLog(name, logSize, outLogpp)
1839 struct afs_icl_log **outLogpp;
1841 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
1844 /* create a log with size logSize; return it in *outLogpp and tag
1845 * it with name "name." 'flags' can be set to make the log unclearable.
1847 afs_icl_CreateLogWithFlags(name, logSize, flags, outLogpp)
1851 struct afs_icl_log **outLogpp;
1853 register struct afs_icl_log *logp;
1855 /* add into global list under lock */
1856 ObtainWriteLock(&afs_icl_lock,183);
1857 if (!afs_icl_inited) afs_icl_Init();
1859 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
1860 if (strcmp(logp->name, name) == 0) {
1861 /* found it already created, just return it */
1864 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
1866 ObtainWriteLock(&logp->lock,184);
1867 logp->states |= ICL_LOGF_PERSISTENT;
1868 ReleaseWriteLock(&logp->lock);
1870 ReleaseWriteLock(&afs_icl_lock);
1875 logp = (struct afs_icl_log *)
1876 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
1877 bzero((caddr_t)logp, sizeof(*logp));
1880 logp->name = osi_AllocSmallSpace(strlen(name)+1);
1881 strcpy(logp->name, name);
1882 LOCK_INIT(&logp->lock, "logp lock");
1883 logp->logSize = logSize;
1884 logp->datap = (afs_int32 *)0; /* don't allocate it until we need it */
1886 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
1887 logp->states |= ICL_LOGF_PERSISTENT;
1889 logp->nextp = afs_icl_allLogs;
1890 afs_icl_allLogs = logp;
1891 ReleaseWriteLock(&afs_icl_lock);
1897 /* called with a log, a pointer to a buffer, the size of the buffer
1898 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
1899 * and returns data in the provided buffer, and returns output flags
1900 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
1901 * find the record with cookie value cookie.
1903 afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp)
1904 register struct afs_icl_log *logp;
1906 afs_int32 *bufSizep;
1907 afs_uint32 *cookiep;
1910 afs_int32 nwords; /* number of words to copy out */
1911 afs_uint32 startCookie; /* first cookie to use */
1912 register afs_int32 i;
1913 afs_int32 outWords; /* words we've copied out */
1914 afs_int32 inWords; /* max words to copy out */
1915 afs_int32 code; /* return code */
1916 afs_int32 ix; /* index we're copying from */
1917 afs_int32 outFlags; /* return flags */
1918 afs_int32 inFlags; /* flags passed in */
1921 inWords = *bufSizep; /* max to copy out */
1922 outWords = 0; /* amount copied out */
1923 startCookie = *cookiep;
1928 ObtainWriteLock(&logp->lock,185);
1930 ReleaseWriteLock(&logp->lock);
1934 /* first, compute the index of the start cookie we've been passed */
1936 /* (re-)compute where we should start */
1937 if (startCookie < logp->baseCookie) {
1938 if (startCookie) /* missed some output */
1939 outFlags |= ICL_COPYOUTF_MISSEDSOME;
1940 /* skip to the first available record */
1941 startCookie = logp->baseCookie;
1942 *cookiep = startCookie;
1945 /* compute where we find the first element to copy out */
1946 ix = logp->firstUsed + startCookie - logp->baseCookie;
1947 if (ix >= logp->logSize) ix -= logp->logSize;
1949 /* if have some data now, break out and process it */
1950 if (startCookie - logp->baseCookie < logp->logElements) break;
1952 /* At end of log, so clear it if we need to */
1953 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
1955 logp->firstUsed = logp->firstFree = 0;
1956 logp->logElements = 0;
1958 /* otherwise, either wait for the data to arrive, or return */
1959 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
1960 ReleaseWriteLock(&logp->lock);
1964 logp->states |= ICL_LOGF_WAITING;
1965 ReleaseWriteLock(&logp->lock);
1966 afs_osi_Sleep(&logp->lock);
1967 ObtainWriteLock(&logp->lock,186);
1969 /* copy out data from ix to logSize or firstFree, depending
1970 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
1971 * be careful not to copy out more than nwords.
1973 if (ix >= logp->firstUsed) {
1974 if (logp->firstUsed <= logp->firstFree)
1976 end = logp->firstFree; /* first element not to copy */
1978 end = logp->logSize;
1979 nwords = inWords; /* don't copy more than this */
1980 if (end - ix < nwords)
1983 bcopy((char *) &logp->datap[ix], (char *) bufferp,
1984 sizeof(afs_int32) * nwords);
1989 /* if we're going to copy more out below, we'll start here */
1992 /* now, if active part of the log has wrapped, there's more stuff
1993 * starting at the head of the log. Copy out more from there.
1995 if (logp->firstUsed > logp->firstFree
1996 && ix < logp->firstFree && inWords > 0) {
1997 /* (more to) copy out from the wrapped section at the
1998 * start of the log. May get here even if didn't copy any
1999 * above, if the cookie points directly into the wrapped section.
2002 if (logp->firstFree - ix < nwords)
2003 nwords = logp->firstFree - ix;
2004 bcopy((char *) &logp->datap[ix], (char *) bufferp,
2005 sizeof(afs_int32) * nwords);
2011 ReleaseWriteLock(&logp->lock);
2015 *bufSizep = outWords;
2021 /* return basic parameter information about a log */
2022 afs_icl_GetLogParms(logp, maxSizep, curSizep)
2023 struct afs_icl_log *logp;
2024 afs_int32 *maxSizep;
2025 afs_int32 *curSizep;
2027 ObtainReadLock(&logp->lock);
2028 *maxSizep = logp->logSize;
2029 *curSizep = logp->logElements;
2030 ReleaseReadLock(&logp->lock);
2035 /* hold and release logs */
2036 afs_icl_LogHold(logp)
2037 register struct afs_icl_log *logp;
2039 ObtainWriteLock(&afs_icl_lock,187);
2041 ReleaseWriteLock(&afs_icl_lock);
2045 /* hold and release logs, called with lock already held */
2046 afs_icl_LogHoldNL(logp)
2047 register struct afs_icl_log *logp;
2053 /* keep track of how many sets believe the log itself is allocated */
2054 afs_icl_LogUse(logp)
2055 register struct afs_icl_log *logp;
2057 ObtainWriteLock(&logp->lock,188);
2058 if (logp->setCount == 0) {
2059 /* this is the first set actually using the log -- allocate it */
2060 if (logp->logSize == 0) {
2061 /* we weren't passed in a hint and it wasn't set */
2062 logp->logSize = ICL_DEFAULT_LOGSIZE;
2064 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2065 #ifdef AFS_AIX32_ENV
2066 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2070 ReleaseWriteLock(&logp->lock);
2074 /* decrement the number of real users of the log, free if possible */
2075 afs_icl_LogFreeUse(logp)
2076 register struct afs_icl_log *logp;
2078 ObtainWriteLock(&logp->lock,189);
2079 if (--logp->setCount == 0) {
2080 /* no more users -- free it (but keep log structure around)*/
2081 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2082 #ifdef AFS_AIX32_ENV
2083 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2085 logp->firstUsed = logp->firstFree = 0;
2086 logp->logElements = 0;
2087 logp->datap = (afs_int32 *)0;
2089 ReleaseWriteLock(&logp->lock);
2093 /* set the size of the log to 'logSize' */
2094 afs_icl_LogSetSize(logp, logSize)
2095 register struct afs_icl_log *logp;
2098 ObtainWriteLock(&logp->lock,190);
2100 /* nothing to worry about since it's not allocated */
2101 logp->logSize = logSize;
2105 logp->firstUsed = logp->firstFree = 0;
2106 logp->logElements = 0;
2108 /* free and allocate a new one */
2109 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2110 #ifdef AFS_AIX32_ENV
2111 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2113 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2114 #ifdef AFS_AIX32_ENV
2115 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2117 logp->logSize = logSize;
2119 ReleaseWriteLock(&logp->lock);
2124 /* free a log. Called with afs_icl_lock locked. */
2125 afs_icl_ZapLog(logp)
2126 register struct afs_icl_log *logp;
2128 register struct afs_icl_log **lpp, *tp;
2130 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2132 /* found the dude we want to remove */
2134 osi_FreeSmallSpace(logp->name);
2135 osi_FreeSmallSpace(logp->datap);
2136 osi_FreeSmallSpace(logp);
2137 break; /* won't find it twice */
2143 /* do the release, watching for deleted entries */
2144 afs_icl_LogRele(logp)
2145 register struct afs_icl_log *logp;
2147 ObtainWriteLock(&afs_icl_lock,191);
2148 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2149 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2151 ReleaseWriteLock(&afs_icl_lock);
2155 /* do the release, watching for deleted entries, log already held */
2156 afs_icl_LogReleNL(logp)
2157 register struct afs_icl_log *logp;
2159 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2160 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2165 /* zero out the log */
2166 afs_icl_ZeroLog(logp)
2167 register struct afs_icl_log *logp;
2169 ObtainWriteLock(&logp->lock,192);
2170 logp->firstUsed = logp->firstFree = 0;
2171 logp->logElements = 0;
2172 logp->baseCookie = 0;
2173 ReleaseWriteLock(&logp->lock);
2177 /* free a log entry, and drop its reference count */
2178 afs_icl_LogFree(logp)
2179 register struct afs_icl_log *logp;
2181 ObtainWriteLock(&logp->lock,193);
2182 logp->states |= ICL_LOGF_DELETED;
2183 ReleaseWriteLock(&logp->lock);
2184 afs_icl_LogRele(logp);
2188 /* find a log by name, returning it held */
2189 struct afs_icl_log *afs_icl_FindLog(name)
2192 register struct afs_icl_log *tp;
2193 ObtainWriteLock(&afs_icl_lock,194);
2194 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2195 if (strcmp(tp->name, name) == 0) {
2196 /* this is the dude we want */
2201 ReleaseWriteLock(&afs_icl_lock);
2205 afs_icl_EnumerateLogs(aproc, arock)
2209 register struct afs_icl_log *tp;
2210 register afs_int32 code;
2213 ObtainWriteLock(&afs_icl_lock,195);
2214 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2215 tp->refCount++; /* hold this guy */
2216 ReleaseWriteLock(&afs_icl_lock);
2217 ObtainReadLock(&tp->lock);
2218 code = (*aproc)(tp->name, arock, tp);
2219 ReleaseReadLock(&tp->lock);
2220 ObtainWriteLock(&afs_icl_lock,196);
2221 if (--tp->refCount == 0)
2225 ReleaseWriteLock(&afs_icl_lock);
2229 struct afs_icl_set *afs_icl_allSets = 0;
2231 afs_icl_CreateSet(name, baseLogp, fatalLogp, outSetpp)
2233 struct afs_icl_log *baseLogp;
2234 struct afs_icl_log *fatalLogp;
2235 struct afs_icl_set **outSetpp;
2237 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2238 /*flags*/0, outSetpp);
2241 /* create a set, given pointers to base and fatal logs, if any.
2242 * Logs are unlocked, but referenced, and *outSetpp is returned
2243 * referenced. Function bumps reference count on logs, since it
2244 * addds references from the new afs_icl_set. When the set is destroyed,
2245 * those references will be released.
2247 afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp)
2249 struct afs_icl_log *baseLogp;
2250 struct afs_icl_log *fatalLogp;
2252 struct afs_icl_set **outSetpp;
2254 register struct afs_icl_set *setp;
2256 afs_int32 states = ICL_DEFAULT_SET_STATES;
2258 ObtainWriteLock(&afs_icl_lock,197);
2259 if (!afs_icl_inited) afs_icl_Init();
2261 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2262 if (strcmp(setp->name, name) == 0) {
2265 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2267 ObtainWriteLock(&setp->lock,198);
2268 setp->states |= ICL_SETF_PERSISTENT;
2269 ReleaseWriteLock(&setp->lock);
2271 ReleaseWriteLock(&afs_icl_lock);
2276 /* determine initial state */
2277 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2278 states = ICL_SETF_ACTIVE;
2279 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2280 states = ICL_SETF_FREED;
2281 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2282 states |= ICL_SETF_PERSISTENT;
2284 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2285 bzero((caddr_t)setp, sizeof(*setp));
2287 if (states & ICL_SETF_FREED)
2288 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2289 setp->states = states;
2291 LOCK_INIT(&setp->lock, "setp lock");
2292 /* next lock is obtained in wrong order, hierarchy-wise, but
2293 * it doesn't matter, since no one can find this lock yet, since
2294 * the afs_icl_lock is still held, and thus the obtain can't block.
2296 ObtainWriteLock(&setp->lock,199);
2297 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2298 strcpy(setp->name, name);
2299 setp->nevents = ICL_DEFAULTEVENTS;
2300 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2301 #ifdef AFS_AIX32_ENV
2302 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2304 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2305 setp->eventFlags[i] = 0xff; /* default to enabled */
2307 /* update this global info under the afs_icl_lock */
2308 setp->nextp = afs_icl_allSets;
2309 afs_icl_allSets = setp;
2310 ReleaseWriteLock(&afs_icl_lock);
2312 /* set's basic lock is still held, so we can finish init */
2314 setp->logs[0] = baseLogp;
2315 afs_icl_LogHold(baseLogp);
2316 if (!(setp->states & ICL_SETF_FREED))
2317 afs_icl_LogUse(baseLogp); /* log is actually being used */
2320 setp->logs[1] = fatalLogp;
2321 afs_icl_LogHold(fatalLogp);
2322 if (!(setp->states & ICL_SETF_FREED))
2323 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2325 ReleaseWriteLock(&setp->lock);
2331 /* function to change event enabling information for a particular set */
2332 afs_icl_SetEnable(setp, eventID, setValue)
2333 struct afs_icl_set *setp;
2339 ObtainWriteLock(&setp->lock,200);
2340 if (!ICL_EVENTOK(setp, eventID)) {
2341 ReleaseWriteLock(&setp->lock);
2344 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2346 *tp |= ICL_EVENTMASK(eventID);
2348 *tp &= ~(ICL_EVENTMASK(eventID));
2349 ReleaseWriteLock(&setp->lock);
2353 /* return indication of whether a particular event ID is enabled
2354 * for tracing. If *getValuep is set to 0, the event is disabled,
2355 * otherwise it is enabled. All events start out enabled by default.
2357 afs_icl_GetEnable(setp, eventID, getValuep)
2358 struct afs_icl_set *setp;
2362 ObtainReadLock(&setp->lock);
2363 if (!ICL_EVENTOK(setp, eventID)) {
2364 ReleaseWriteLock(&setp->lock);
2367 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2371 ReleaseReadLock(&setp->lock);
2375 /* hold and release event sets */
2376 afs_icl_SetHold(setp)
2377 register struct afs_icl_set *setp;
2379 ObtainWriteLock(&afs_icl_lock,201);
2381 ReleaseWriteLock(&afs_icl_lock);
2385 /* free a set. Called with afs_icl_lock locked */
2386 afs_icl_ZapSet(setp)
2387 register struct afs_icl_set *setp;
2389 register struct afs_icl_set **lpp, *tp;
2391 register struct afs_icl_log *tlp;
2393 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2395 /* found the dude we want to remove */
2397 osi_FreeSmallSpace(setp->name);
2398 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2399 #ifdef AFS_AIX32_ENV
2400 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2402 for(i=0; i < ICL_LOGSPERSET; i++) {
2403 if (tlp = setp->logs[i])
2404 afs_icl_LogReleNL(tlp);
2406 osi_FreeSmallSpace(setp);
2407 break; /* won't find it twice */
2413 /* do the release, watching for deleted entries */
2414 afs_icl_SetRele(setp)
2415 register struct afs_icl_set *setp;
2417 ObtainWriteLock(&afs_icl_lock,202);
2418 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2419 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2421 ReleaseWriteLock(&afs_icl_lock);
2425 /* free a set entry, dropping its reference count */
2426 afs_icl_SetFree(setp)
2427 register struct afs_icl_set *setp;
2429 ObtainWriteLock(&setp->lock,203);
2430 setp->states |= ICL_SETF_DELETED;
2431 ReleaseWriteLock(&setp->lock);
2432 afs_icl_SetRele(setp);
2436 /* find a set by name, returning it held */
2437 struct afs_icl_set *afs_icl_FindSet(name)
2440 register struct afs_icl_set *tp;
2441 ObtainWriteLock(&afs_icl_lock,204);
2442 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2443 if (strcmp(tp->name, name) == 0) {
2444 /* this is the dude we want */
2449 ReleaseWriteLock(&afs_icl_lock);
2453 /* zero out all the logs in the set */
2454 afs_icl_ZeroSet(setp)
2455 struct afs_icl_set *setp;
2460 struct afs_icl_log *logp;
2462 ObtainReadLock(&setp->lock);
2463 for(i = 0; i < ICL_LOGSPERSET; i++) {
2464 logp = setp->logs[i];
2466 afs_icl_LogHold(logp);
2467 tcode = afs_icl_ZeroLog(logp);
2468 if (tcode != 0) code = tcode; /* save the last bad one */
2469 afs_icl_LogRele(logp);
2472 ReleaseReadLock(&setp->lock);
2476 afs_icl_EnumerateSets(aproc, arock)
2480 register struct afs_icl_set *tp, *np;
2481 register afs_int32 code;
2484 ObtainWriteLock(&afs_icl_lock,205);
2485 for(tp = afs_icl_allSets; tp; tp=np) {
2486 tp->refCount++; /* hold this guy */
2487 ReleaseWriteLock(&afs_icl_lock);
2488 code = (*aproc)(tp->name, arock, tp);
2489 ObtainWriteLock(&afs_icl_lock,206);
2490 np = tp->nextp; /* tp may disappear next, but not np */
2491 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2495 ReleaseWriteLock(&afs_icl_lock);
2499 afs_icl_AddLogToSet(setp, newlogp)
2500 struct afs_icl_set *setp;
2501 struct afs_icl_log *newlogp;
2505 struct afs_icl_log *logp;
2507 ObtainWriteLock(&setp->lock,207);
2508 for(i = 0; i < ICL_LOGSPERSET; i++) {
2509 if (!setp->logs[i]) {
2510 setp->logs[i] = newlogp;
2512 afs_icl_LogHold(newlogp);
2513 if (!(setp->states & ICL_SETF_FREED)) {
2514 /* bump up the number of sets using the log */
2515 afs_icl_LogUse(newlogp);
2520 ReleaseWriteLock(&setp->lock);
2524 afs_icl_SetSetStat(setp, op)
2525 struct afs_icl_set *setp;
2530 struct afs_icl_log *logp;
2532 ObtainWriteLock(&setp->lock,208);
2534 case ICL_OP_SS_ACTIVATE: /* activate a log */
2536 * If we are not already active, see if we have released
2537 * our demand that the log be allocated (FREED set). If
2538 * we have, reassert our desire.
2540 if (!(setp->states & ICL_SETF_ACTIVE)) {
2541 if (setp->states & ICL_SETF_FREED) {
2542 /* have to reassert desire for logs */
2543 for(i = 0; i < ICL_LOGSPERSET; i++) {
2544 logp = setp->logs[i];
2546 afs_icl_LogHold(logp);
2547 afs_icl_LogUse(logp);
2548 afs_icl_LogRele(logp);
2551 setp->states &= ~ICL_SETF_FREED;
2553 setp->states |= ICL_SETF_ACTIVE;
2558 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2559 /* this doesn't require anything beyond clearing the ACTIVE flag */
2560 setp->states &= ~ICL_SETF_ACTIVE;
2564 case ICL_OP_SS_FREE: /* deassert design for log */
2566 * if we are already in this state, do nothing; otherwise
2567 * deassert desire for log
2569 if (setp->states & ICL_SETF_ACTIVE)
2572 if (!(setp->states & ICL_SETF_FREED)) {
2573 for(i = 0; i < ICL_LOGSPERSET; i++) {
2574 logp = setp->logs[i];
2576 afs_icl_LogHold(logp);
2577 afs_icl_LogFreeUse(logp);
2578 afs_icl_LogRele(logp);
2581 setp->states |= ICL_SETF_FREED;
2590 ReleaseWriteLock(&setp->lock);