2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "../afs/param.h"
15 #include "../afs/sysincludes.h" /* Standard vendor system headers */
16 #include "../afs/afsincludes.h" /* Afs-based standard headers */
17 #include "../afs/afs_stats.h"
18 #include "../rx/rx_globals.h"
19 #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
22 #include "../h/hashing.h"
24 #if !defined(AFS_HPUX110_ENV)
25 #include "netinet/in_var.h"
27 #endif /* !defined(UKERNEL) */
28 #ifdef AFS_LINUX22_ENV
29 #include "../h/smp_lock.h"
33 #if defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
34 #define AFS_MINBUFFERS 100
36 #define AFS_MINBUFFERS 50
40 afs_int32 hosts[MAXCELLHOSTS];
44 char afs_zeros[AFS_ZEROS];
45 char afs_rootVolumeName[64]="";
46 struct afs_icl_set *afs_iclSetp = (struct afs_icl_set*)0;
47 struct afs_icl_set *afs_iclLongTermSetp = (struct afs_icl_set*)0;
49 #if defined(AFS_GLOBAL_SUNLOCK) && !defined(AFS_HPUX_ENV) && !defined(AFS_AIX41_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
51 kmutex_t afs_global_lock;
52 kmutex_t afs_rxglobal_lock;
54 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
55 long afs_global_owner;
59 #if defined(AFS_OSF_ENV)
60 simple_lock_data_t afs_global_lock;
61 #elif defined(AFS_DARWIN_ENV)
62 struct lock__bsd__ afs_global_lock;
63 #elif defined(AFS_FBSD_ENV)
64 struct lock afs_global_lock;
65 struct proc *afs_global_owner;
67 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
68 thread_t afs_global_owner;
69 #endif /* AFS_OSF_ENV */
71 #if defined(AFS_AIX41_ENV)
72 simple_lock_data afs_global_lock;
75 afs_int32 afs_initState = 0;
76 afs_int32 afs_termState = 0;
77 afs_int32 afs_setTime = 0;
78 int afs_cold_shutdown = 0;
79 char afs_SynchronousCloses = '\0';
80 static int afs_CB_Running = 0;
81 static int AFS_Running = 0;
82 static int afs_CacheInit_Done = 0;
83 static int afs_Go_Done = 0;
84 extern struct interfaceAddr afs_cb_interface;
85 static int afs_RX_Running = 0;
88 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval);
90 #if defined(AFS_HPUX_ENV)
91 extern int afs_vfs_mount();
92 #endif /* defined(AFS_HPUX_ENV) */
94 /* This is code which needs to be called once when the first daemon enters
95 * the client. A non-zero return means an error and AFS should not start.
97 static int afs_InitSetup(int preallocs)
99 extern void afs_InitStats();
104 * Set up all the AFS statistics variables. This should be done
105 * exactly once, and it should be done here, the first resource-setting
106 * routine to be called by the CM/RX.
109 #endif /* AFS_NOSTATS */
111 memset(afs_zeros, 0, AFS_ZEROS);
114 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
115 code = rx_Init(htons(7001));
117 printf("AFS: RX failed to initialize.\n");
120 rx_SetRxDeadTime(AFS_RXDEADTIME);
121 /* resource init creates the services */
122 afs_ResourceInit(preallocs);
127 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
128 long parm, parm2, parm3, parm4, parm5, parm6;
132 AFS_STATCNT(afs_syscall_call);
134 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
135 && (parm != AFSOP_GETMASK)) {
136 /* only root can run this code */
139 if (!afs_suser() && (parm != AFSOP_GETMTU)
140 && (parm != AFSOP_GETMASK)) {
141 /* only root can run this code */
142 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
146 #if defined(AFS_OSF_ENV)
148 #else /* AFS_OSF_ENV */
155 if (parm == AFSOP_START_RXCALLBACK) {
156 if (afs_CB_Running) goto out;
158 #ifndef RXK_LISTENER_ENV
159 code = afs_InitSetup(parm2);
161 #endif /* RXK_LISTENER_ENV */
163 #ifdef RXK_LISTENER_ENV
164 while (afs_RX_Running != 2)
165 afs_osi_Sleep(&afs_RX_Running);
167 afs_initState = AFSOP_START_AFS;
168 afs_osi_Wakeup(&afs_initState);
169 #endif /* RXK_LISTENER_ENV */
171 afs_RXCallBackServer();
175 exit(CLD_EXITED, code);
178 #ifdef RXK_LISTENER_ENV
179 else if (parm == AFSOP_RXLISTENER_DAEMON) {
180 if (afs_RX_Running) goto out;
182 code = afs_InitSetup(parm2);
184 rx_enablePeerRPCStats();
187 rx_enableProcessRPCStats();
190 afs_initState = AFSOP_START_AFS;
191 afs_osi_Wakeup(&afs_initState);
194 afs_osi_Wakeup(&afs_RX_Running);
196 afs_osi_RxkRegister();
202 exit(CLD_EXITED, code);
206 else if (parm == AFSOP_START_AFS) {
210 if (AFS_Running) goto out;
212 while (afs_initState < AFSOP_START_AFS)
213 afs_osi_Sleep(&afs_initState);
215 #if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
216 temp = AFS_MINBUFFERS; /* Should fix this soon */
218 temp = ((afs_bufferpages * NBPG)>>11); /* number of 2k buffers we could get from all of the buffer space */
219 temp = temp>>2; /* don't take more than 25% (our magic parameter) */
220 if (temp < AFS_MINBUFFERS) temp = AFS_MINBUFFERS; /* although we really should have this many */
223 afs_initState = AFSOP_START_BKG;
224 afs_osi_Wakeup(&afs_initState);
232 else if (parm == AFSOP_START_CS) {
234 afs_CheckServerDaemon();
240 else if (parm == AFSOP_START_BKG) {
241 while (afs_initState < AFSOP_START_BKG)
242 afs_osi_Sleep(&afs_initState);
243 if (afs_initState < AFSOP_GO) {
244 afs_initState = AFSOP_GO;
245 afs_osi_Wakeup(&afs_initState);
247 /* start the bkg daemon */
251 afs_BioDaemon(parm2);
254 afs_BackgroundDaemon();
260 else if (parm == AFSOP_START_TRUNCDAEMON) {
261 while (afs_initState < AFSOP_GO)
262 afs_osi_Sleep(&afs_initState);
263 /* start the bkg daemon */
265 afs_CacheTruncateDaemon();
271 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
272 else if (parm == AFSOP_RXEVENT_DAEMON) {
273 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
275 afs_rxevent_daemon();
282 else if (parm == AFSOP_ADDCELL) {
283 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
284 name. Parameter 4 is the length of the name, including the null. Parm 5 is the
285 home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
286 struct afsop_cell tcell;
288 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
289 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
291 if (parm4 > sizeof(tcell.cellName))
294 AFS_COPYIN((char *)parm3, tcell.cellName, parm4, code);
296 afs_NewCell(tcell.cellName, tcell.hosts, parm5,
297 (char *)0, (u_short)0, (u_short)0, (int)0);
300 } else if (parm == AFSOP_ADDCELL2) {
301 struct afsop_cell tcell;
302 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
303 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *cnamep = 0;
304 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
306 #else /* AFS_SGI61_ENV */
308 #endif /* AFS_SGI61_ENV */
311 /* wait for basic init */
312 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
314 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
316 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, &bufferSize, code);
319 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
322 cflags |= CLinkedCell;
326 afs_NewCell(tbuffer1, tcell.hosts, cflags,
327 lcnamep, (u_short)0, (u_short)0, (int)0);
330 osi_FreeSmallSpace(tbuffer);
331 osi_FreeSmallSpace(tbuffer1);
333 else if (parm == AFSOP_ADDCELLALIAS) {
336 * parm2 is the alias name
337 * parm3 is the real cell name
339 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
341 #else /* AFS_SGI61_ENV */
343 #endif /* AFS_SGI61_ENV */
344 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
345 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
347 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize, code);
348 if (!code) AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ, &bufferSize, code);
349 if (!code) afs_NewCell(aliasName, /* new entry name */
352 (char *) 0, /* linked cell */
353 0, 0, /* fs & vl ports */
355 cellName); /* real cell name */
357 osi_FreeSmallSpace(aliasName);
358 osi_FreeSmallSpace(cellName);
360 else if (parm == AFSOP_CACHEINIT) {
361 struct afs_cacheParams cparms;
363 if (afs_CacheInit_Done) goto out;
365 /* wait for basic init */
366 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
367 AFS_COPYIN((char *)parm2, (caddr_t) &cparms, sizeof(cparms), code);
369 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined (AFS_SGI64_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
377 afs_CacheInit_Done = 1;
379 struct afs_icl_log *logp;
380 /* initialize the ICL system */
381 code = afs_icl_CreateLog("cmfx", 60*1024, &logp);
383 code = afs_icl_CreateSetWithFlags("cm", logp,
384 (struct icl_log *) 0,
385 ICL_CRSET_FLAG_DEFAULT_OFF,
387 code = afs_icl_CreateSet("cmlongterm", logp, (struct icl_log*) 0,
388 &afs_iclLongTermSetp);
390 afs_setTime = cparms.setTimeFlag;
392 code = afs_CacheInit(cparms.cacheScaches,
403 else if (parm == AFSOP_CACHEINODE) {
404 ino_t ainode = parm2;
405 /* wait for basic init */
406 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
410 ainode = (ainode << 32) | (parm3 & 0xffffffff);
412 code = afs_InitCacheFile((char *) 0, ainode);
414 else if (parm == AFSOP_ROOTVOLUME) {
415 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
417 #else /* AFS_SGI61_ENV */
419 #endif /* AFS_SGI61_ENV */
421 /* wait for basic init */
422 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
425 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code);
426 afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0;
430 else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO ||
431 parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG) {
432 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
433 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
435 #else /* AFS_SGI61_ENV */
437 #endif /* AFS_SGI61_ENV */
439 /* wait for basic init */
440 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
442 AFS_COPYINSTR((char *)parm2, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
444 osi_FreeSmallSpace(tbuffer);
448 tbuffer[AFS_SMALLOCSIZ-1] = 0; /* null-terminate the name */
449 /* we now have the cache dir copied in. Call the cache init routines */
450 if (parm == AFSOP_CACHEFILE) code = afs_InitCacheFile(tbuffer, 0);
451 else if (parm == AFSOP_CACHEINFO) code = afs_InitCacheInfo(tbuffer);
452 else if (parm == AFSOP_VOLUMEINFO) code = afs_InitVolumeInfo(tbuffer);
454 osi_FreeSmallSpace(tbuffer);
456 else if (parm == AFSOP_GO) {
457 /* the generic initialization calls come here. One parameter: should we do the
458 set-time operation on this workstation */
459 if (afs_Go_Done) goto out;
461 while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState);
464 afs_osi_Wakeup(&afs_initState);
465 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
466 afs_nfsclient_init();
468 printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused,
469 (100*afs_stats_cmperf.cacheFilesReused) /
470 (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1));
472 else if (parm == AFSOP_ADVISEADDR) {
473 /* pass in the host address to the rx package */
474 afs_int32 count = parm2;
475 afs_int32 buffer[AFS_MAX_INTERFACE_ADDR];
476 afs_int32 maskbuffer[AFS_MAX_INTERFACE_ADDR];
477 afs_int32 mtubuffer[AFS_MAX_INTERFACE_ADDR];
481 if ( count > AFS_MAX_INTERFACE_ADDR ) {
483 count = AFS_MAX_INTERFACE_ADDR;
486 AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code);
488 AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code);
490 AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code);
492 afs_cb_interface.numberOfInterfaces = count;
493 for (i=0; i < count ; i++) {
494 afs_cb_interface.addr_in[i] = buffer[i];
495 #ifdef AFS_USERSPACE_IP_ADDR
496 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
497 * machines IP addresses when in the kernel (the in_ifaddr
498 * struct is not available), so we pass the info in at
499 * startup. We also pass in the subnetmask and mtu size. The
500 * subnetmask is used when setting the rank:
501 * afsi_SetServerIPRank(); and the mtu size is used when
502 * finding the best mtu size. rxi_FindIfnet() is replaced
503 * with rxi_Findcbi().
505 afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff);
506 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
509 afs_uuid_create(&afs_cb_interface.uuid);
510 rxi_setaddr(buffer[0]);
514 else if (parm == AFSOP_NFSSTATICADDR) {
515 extern int (*nfs_rfsdisptab_v2)();
516 nfs_rfsdisptab_v2 = (int (*)())parm2;
518 else if (parm == AFSOP_NFSSTATICADDR2) {
519 extern int (*nfs_rfsdisptab_v2)();
521 nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
523 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
526 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
527 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
528 extern int (*afs_sblockp)();
529 extern void (*afs_sbunlockp)();
531 afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
532 afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff));
534 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
535 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
538 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
539 #endif /* AFS_SGI53_ENV */
540 else if (parm == AFSOP_SHUTDOWN) {
541 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
542 extern struct mount *afs_globalVFS;
543 #else /* AFS_OSF_ENV */
544 extern struct vfs *afs_globalVFS;
546 afs_cold_shutdown = 0;
547 if (parm == 1) afs_cold_shutdown = 1;
548 if (afs_globalVFS != 0) {
549 afs_warn("AFS isn't unmounted yet! Call aborted\n");
555 #if ! defined(AFS_HPUX90_ENV) || defined(AFS_HPUX100_ENV)
556 else if (parm == AFSOP_AFS_VFSMOUNT) {
558 #if defined(AFS_HPUX100_ENV)
559 vfsmount(parm2, parm3, parm4, parm5);
561 afs_vfs_mount(parm2, parm3, parm4, parm5);
562 #endif /* AFS_HPUX100_ENV */
563 #else /* defined(AFS_HPUX_ENV) */
564 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
569 #endif /* defined(AFS_HPUX_ENV) */
572 else if (parm == AFSOP_CLOSEWAIT) {
573 afs_SynchronousCloses = 'S';
575 else if (parm == AFSOP_GETMTU) {
577 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
578 #ifdef AFS_USERSPACE_IP_ADDR
580 i = rxi_Findcbi(parm2);
581 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
582 #else /* AFS_USERSPACE_IP_ADDR */
584 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
585 extern struct ifnet *rxi_FindIfnet();
587 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
588 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
589 #endif /* else AFS_USERSPACE_IP_ADDR */
590 #endif /* !AFS_SUN5_ENV */
592 AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code);
594 /* this is disabled for now because I can't figure out how to get access
595 * to these kernel variables. It's only for supporting user-mode rx
596 * programs -- it makes a huge difference on the 220's in my testbed,
597 * though I don't know why. The bosserver does this with /etc/no, so it's
598 * being handled a different way for the servers right now. */
601 extern u_long sb_max_dflt;
604 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
605 if (sb_max < 131072) sb_max = 131072;
608 #endif /* AFS_AIX32_ENV */
610 else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
612 #if !defined(AFS_SUN5_ENV)
613 #ifdef AFS_USERSPACE_IP_ADDR
615 i = rxi_Findcbi(parm2);
617 mask = afs_cb_interface.subnetmask[i];
621 #else /* AFS_USERSPACE_IP_ADDR */
623 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
624 extern struct ifnet *rxi_FindIfnet();
625 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
626 if (tifnp && tifadp) {
627 mask = tifadp->ia_subnetmask;
631 #endif /* else AFS_USERSPACE_IP_ADDR */
632 #endif /* !AFS_SUN5_ENV */
634 AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code);
637 else if (parm == AFSOP_AFSDB_HANDLER) {
638 int sizeArg = (int)parm4;
639 int kmsgLen = sizeArg & 0xffff;
640 int cellLen = (sizeArg & 0xffff0000) >> 16;
641 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
642 char *cellname = afs_osi_Alloc(cellLen);
645 afs_osi_MaskSignals();
647 AFS_COPYIN((afs_int32 *)parm2, cellname, cellLen, code);
648 AFS_COPYIN((afs_int32 *)parm3, kmsg, kmsgLen, code);
650 code = afs_AfsdbHandler(cellname, cellLen, kmsg);
651 if (*cellname == 1) *cellname = 0;
652 if (code == -2) { /* Shutting down? */
657 if (!code) AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
658 afs_osi_Free(kmsg, kmsgLen);
659 afs_osi_Free(cellname, cellLen);
662 else if (parm == AFSOP_SET_DYNROOT) {
663 code = afs_SetDynrootEnable(parm2);
665 else if (parm == AFSOP_SET_FAKESTAT) {
666 afs_fakestat_enable = parm2;
674 #ifdef AFS_LINUX20_ENV
683 #include "sys/lockl.h"
686 * syscall - this is the VRMIX system call entry point.
689 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
690 * all the user-level calls to `syscall' to change.
692 syscall(syscall, p1, p2, p3, p4, p5, p6) {
693 register rval1=0, code;
696 #ifndef AFS_AIX41_ENV
697 extern lock_t kernel_lock;
698 monster = lockl(&kernel_lock, LOCK_SHORT);
699 #endif /* !AFS_AIX41_ENV */
701 AFS_STATCNT(syscall);
705 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
710 rval1 = afs_setpag();
716 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
720 case AFSCALL_ICREATE:
721 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
725 rval1 = afs_syscall_iopen(p1, p2, p3);
729 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
733 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
738 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
740 if (!code) rval1 = retval;
741 if (!rval1) rval1 = code;
751 #ifndef AFS_AIX41_ENV
752 if (monster != LOCK_NEST)
753 unlockl(&kernel_lock);
754 #endif /* !AFS_AIX41_ENV */
755 return getuerror() ? -1 : rval1;
759 * lsetpag - interface to afs_setpag().
763 AFS_STATCNT(lsetpag);
764 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
768 * lpioctl - interface to pioctl()
770 lpioctl(path, cmd, cmarg, follow)
771 char *path, *cmarg; {
773 AFS_STATCNT(lpioctl);
774 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
777 #else /* !AFS_AIX32_ENV */
779 #if defined(AFS_SGI_ENV)
792 Afs_syscall (struct afsargs *uap, rval_t *rvp)
797 AFS_STATCNT(afs_syscall);
798 switch(uap->syscall) {
802 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
804 rvp->r_val1 = retval;
806 #ifdef AFS_SGI_XFS_IOPS_ENV
808 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
809 uap->parm4, uap->parm5);
812 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
813 uap->parm4, uap->parm5);
815 case AFSCALL_ILISTINODE64:
816 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
817 uap->parm4, uap->parm5);
819 case AFSCALL_ICREATENAME64:
820 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
821 uap->parm4, uap->parm5);
824 #ifdef AFS_SGI_VNODE_GLUE
825 case AFSCALL_INIT_KERNEL_CONFIG:
826 error = afs_init_kernel_config(uap->parm1);
830 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
831 uap->parm3, uap->parm4, uap->parm5);
836 #else /* AFS_SGI_ENV */
854 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
856 dst->param1 = src->param1;
857 dst->param2 = src->param2;
858 dst->param3 = src->param3;
859 dst->param4 = src->param4;
863 * If you need to change copyin_iparam(), you may also need to change
864 * copyin_afs_ioctl().
868 copyin_iparam(caddr_t cmarg, struct iparam *dst)
872 #if defined(AFS_HPUX_64BIT_ENV)
873 struct iparam32 dst32;
875 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
877 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
879 iparam32_to_iparam(&dst32, dst);
882 #endif /* AFS_HPUX_64BIT_ENV */
884 #if defined(AFS_SUN57_64BIT_ENV)
885 struct iparam32 dst32;
887 if (get_udatamodel() == DATAMODEL_ILP32) {
888 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
890 iparam32_to_iparam(&dst32, dst);
893 #endif /* AFS_SUN57_64BIT_ENV */
895 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
896 struct iparam32 dst32;
898 #ifdef AFS_SPARC64_LINUX24_ENV
899 if (current->thread.flags & SPARC_FLAG_32BIT)
900 #elif AFS_SPARC64_LINUX20_ENV
901 if (current->tss.flags & SPARC_FLAG_32BIT)
903 #error Not done for this linux version
904 #endif /* AFS_SPARC64_LINUX20_ENV */
906 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
908 iparam32_to_iparam(&dst32, dst);
911 #endif /* AFS_LINUX_64BIT_KERNEL */
913 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
917 /* Main entry of all afs system calls */
919 extern int afs_sinited;
921 /** The 32 bit OS expects the members of this structure to be 32 bit
922 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
923 * to accomodate both, *long* is used instead of afs_int32
948 Afs_syscall (uap, rvp)
949 register struct afssysa *uap;
952 int *retval = &rvp->r_val1;
953 #else /* AFS_SUN5_ENV */
954 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
955 afs3_syscall(p, args, retval)
968 } *uap = (struct a *)args;
969 #else /* AFS_OSF_ENV */
970 #ifdef AFS_LINUX20_ENV
978 long parm6; /* not actually used - should be removed */
980 /* Linux system calls only set up for 5 arguments. */
981 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
984 struct afssysargs args, *uap = &args;
986 long *retval = &linux_ret;
987 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
988 #ifdef AFS_SPARC64_LINUX24_ENV
989 afs_int32 eparm32[4];
991 /* eparm is also used by AFSCALL_CALL in afsd.c */
1004 } *uap = (struct a *)u.u_ap;
1006 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
1010 #endif /* SUN && !SUN5 */
1020 } *uap = (struct a *)u.u_ap;
1021 #endif /* UKERNEL */
1022 #if defined(AFS_DEC_ENV)
1023 int *retval = &u.u_r.r_val1;
1025 #if defined(AFS_HPUX_ENV)
1026 long *retval = &u.u_rval1;
1028 int *retval = &u.u_rval1;
1031 #endif /* AFS_LINUX20_ENV */
1032 #endif /* AFS_OSF_ENV */
1033 #endif /* AFS_SUN5_ENV */
1034 register int code = 0;
1036 AFS_STATCNT(afs_syscall);
1043 #ifdef AFS_LINUX20_ENV
1045 /* setup uap for use below - pull out the magic decoder ring to know
1046 * which syscalls have folded argument lists.
1048 uap->syscall = syscall;
1052 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
1053 #ifdef AFS_SPARC64_LINUX24_ENV
1054 /* from arch/sparc64/kernel/sys_sparc32.c */
1056 ({ unsigned long __ret; \
1057 __asm__ ("srl %0, 0, %0" \
1064 if (current->thread.flags & SPARC_FLAG_32BIT) {
1065 AFS_COPYIN((char*)parm4, (char*)eparm32, sizeof(eparm32), code);
1066 eparm[0]=AA(eparm32[0]);
1067 eparm[1]=AA(eparm32[1]);
1068 eparm[2]=AA(eparm32[2]);
1072 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
1073 uap->parm4 = eparm[0];
1074 uap->parm5 = eparm[1];
1075 uap->parm6 = eparm[2];
1084 #if defined(AFS_HPUX_ENV)
1086 * There used to be code here (duplicated from osi_Init()) for
1087 * initializing the semaphore used by AFS_GLOCK(). Was the
1088 * duplication to handle the case of a dynamically loaded kernel
1093 if (uap->syscall == AFSCALL_CALL) {
1095 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1096 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1098 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1100 } else if (uap->syscall == AFSCALL_SETPAG) {
1102 register proc_t *procp;
1104 procp = ttoproc(curthread);
1106 code = afs_setpag(&procp->p_cred);
1110 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1111 code = afs_setpag(p, args, retval);
1112 #else /* AFS_OSF_ENV */
1113 code = afs_setpag();
1117 } else if (uap->syscall == AFSCALL_PIOCTL) {
1120 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1122 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1123 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1125 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1129 } else if (uap->syscall == AFSCALL_ICREATE) {
1130 struct iparam iparams;
1132 code = copyin_iparam((char *)uap->parm3, &iparams);
1134 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1139 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1140 iparams.param3, iparams.param4, rvp, CRED());
1142 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1143 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1144 iparams.param3, iparams.param4, retval);
1146 iparams.param3, iparams.param4);
1148 #endif /* AFS_SUN5_ENV */
1149 } else if (uap->syscall == AFSCALL_IOPEN) {
1151 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1153 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1154 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1156 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1158 #endif /* AFS_SUN5_ENV */
1159 } else if (uap->syscall == AFSCALL_IDEC) {
1161 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1163 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1164 #endif /* AFS_SUN5_ENV */
1165 } else if (uap->syscall == AFSCALL_IINC) {
1167 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1169 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1170 #endif /* AFS_SUN5_ENV */
1171 } else if (uap->syscall == AFSCALL_ICL) {
1173 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1175 #ifdef AFS_LINUX20_ENV
1177 /* ICL commands can return values. */
1178 code = -linux_ret; /* Gets negated again at exit below */
1182 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1186 #endif /* !AFS_LINUX20_ENV */
1188 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1192 #endif /* AFS_SUN5_ENV */
1195 #ifdef AFS_LINUX20_ENV
1201 #endif /* AFS_SGI_ENV */
1202 #endif /* !AFS_AIX32_ENV */
1205 * Initstate in the range 0 < x < 100 are early initialization states.
1206 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1207 * the cache may be initialized.
1208 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1209 * is done after all the cache initialization has been done.
1210 * Initstate of 200 means that the volume has been looked up once, possibly
1212 * Initstate of 300 means that the volume has been *successfully* looked up.
1215 register int code = 0;
1217 AFS_STATCNT(afs_CheckInit);
1218 if (afs_initState <= 100)
1219 code = ENXIO; /* never finished init phase */
1220 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1221 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1222 } else if (afs_initState == 200)
1223 code = ETIMEDOUT; /* didn't find root volume */
1227 int afs_shuttingdown = 0;
1231 extern short afs_brsDaemons;
1232 extern afs_int32 afs_CheckServerDaemonStarted;
1233 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1234 extern struct osi_file *afs_cacheInodep;
1236 AFS_STATCNT(afs_shutdown);
1237 if (afs_shuttingdown) return;
1238 afs_shuttingdown = 1;
1239 if (afs_cold_shutdown) afs_warn("COLD ");
1240 else afs_warn("WARM ");
1241 afs_warn("shutting down of: CB... ");
1243 afs_termState = AFSOP_STOP_RXCALLBACK;
1244 rx_WakeupServerProcs();
1245 /* shutdown_rxkernel(); */
1246 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1247 afs_osi_Sleep(&afs_termState);
1249 afs_warn("afs... ");
1250 while (afs_termState == AFSOP_STOP_AFS) {
1251 afs_osi_CancelWait(&AFS_WaitHandler);
1252 afs_osi_Sleep(&afs_termState);
1254 if (afs_CheckServerDaemonStarted) {
1255 while (afs_termState == AFSOP_STOP_CS) {
1256 afs_osi_CancelWait(&AFS_CSWaitHandler);
1257 afs_osi_Sleep(&afs_termState);
1260 afs_warn("BkG... ");
1261 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1262 while (afs_termState == AFSOP_STOP_BKG) {
1263 afs_osi_Wakeup(&afs_brsDaemons);
1264 afs_osi_Sleep(&afs_termState);
1266 afs_warn("CTrunc... ");
1267 /* Cancel cache truncate daemon. */
1268 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1269 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1270 afs_osi_Sleep(&afs_termState);
1272 #ifdef AFS_AFSDB_ENV
1273 afs_warn("AFSDB... ");
1275 while (afs_termState == AFSOP_STOP_AFSDB)
1276 afs_osi_Sleep(&afs_termState);
1278 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1279 afs_warn("RxEvent... ");
1280 /* cancel rx event deamon */
1281 while (afs_termState == AFSOP_STOP_RXEVENT)
1282 afs_osi_Sleep(&afs_termState);
1283 #if defined(RXK_LISTENER_ENV)
1284 afs_warn("RxListener... ");
1286 afs_osi_UnmaskRxkSignals();
1288 /* cancel rx listener */
1289 osi_StopListener(); /* This closes rx_socket. */
1290 while (afs_termState == AFSOP_STOP_RXK_LISTENER)
1291 afs_osi_Sleep(&afs_termState);
1294 afs_termState = AFSOP_STOP_COMPLETE;
1298 /* Close file only after daemons which can write to it are stopped. */
1299 if (afs_cacheInodep) /* memcache won't set this */
1301 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1302 afs_cacheInodep = 0;
1304 return; /* Just kill daemons for now */
1308 shutdown_rxkernel();
1312 shutdown_bufferpackage();
1318 shutdown_vnodeops();
1320 shutdown_exporter();
1321 shutdown_memcache();
1322 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1323 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1324 /* this routine does not exist in Ultrix systems... 93.01.19 */
1326 #endif /* AFS_DEC_ENV */
1329 /* The following hold the cm stats */
1331 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1332 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1333 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1335 afs_warn(" ALL allocated tables\n");
1336 afs_shuttingdown = 0;
1342 AFS_STATCNT(shutdown_afstest);
1343 afs_initState = afs_termState = afs_setTime = 0;
1344 AFS_Running = afs_CB_Running = 0;
1345 afs_CacheInit_Done = afs_Go_Done = 0;
1346 if (afs_cold_shutdown) {
1347 *afs_rootVolumeName = 0;
1352 /* In case there is a bunch of dynamically build bkg daemons to free */
1354 { AFS_STATCNT(shutdown_BKG); }
1357 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1358 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1359 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1360 int afs_icl_sizeofLong = 1;
1362 int afs_icl_sizeofLong = 2;
1365 int afs_icl_sizeofLong = 1;
1368 int afs_icl_inited = 0;
1370 /* init function, called once, under afs_icl_lock */
1377 extern struct afs_icl_log *afs_icl_FindLog();
1378 extern struct afs_icl_set *afs_icl_FindSet();
1382 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1385 afs_int32 *lp, elts, flags;
1386 register afs_int32 code;
1387 struct afs_icl_log *logp;
1388 struct afs_icl_set *setp;
1389 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1391 #else /* AFS_SGI61_ENV */
1393 #endif /* AFS_SGI61_ENV */
1395 afs_int32 startCookie;
1396 afs_int32 allocated;
1397 struct afs_icl_log *tlp;
1400 if (!afs_suser(CRED())) { /* only root can run this code */
1404 if (!afs_suser()) { /* only root can run this code */
1405 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1414 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1415 case ICL_OP_COPYOUT: /* copy ouy data */
1416 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1417 * return flags<<24 + nwords.
1418 * updates cookie to updated start (not end) if we had to
1419 * skip some records.
1421 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1422 if (code) return code;
1423 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1424 if (code) return code;
1425 logp = afs_icl_FindLog(tname);
1426 if (!logp) return ENOENT;
1427 #define BUFFERSIZE AFS_LRALLOCSIZ
1428 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1429 elts = BUFFERSIZE / sizeof(afs_int32);
1430 if (p3 < elts) elts = p3;
1431 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1432 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1435 osi_FreeLargeSpace((struct osi_buffer *) lp);
1438 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1439 if (code) goto done;
1440 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1441 if (code) goto done;
1442 *retval = (flags<<24) | (elts & 0xffffff);
1444 afs_icl_LogRele(logp);
1445 osi_FreeLargeSpace((struct osi_buffer *) lp);
1448 case ICL_OP_ENUMLOGS: /* enumerate logs */
1449 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1450 * return 0 for success, otherwise error.
1452 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1453 if (p1-- == 0) break;
1455 if (!tlp) return ENOENT; /* past the end of file */
1456 temp = strlen(tlp->name)+1;
1457 if (temp > p3) return EINVAL;
1458 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1459 if (!code) /* copy out size of log */
1460 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1463 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1464 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1465 * return 0 for success, otherwise error.
1467 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1468 if (code) return code;
1469 setp = afs_icl_FindSet(tname);
1470 if (!setp) return ENOENT;
1471 if (p2 > ICL_LOGSPERSET)
1473 if (!(tlp = setp->logs[p2]))
1475 temp = strlen(tlp->name)+1;
1476 if (temp > p4) return EINVAL;
1477 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1480 case ICL_OP_CLRLOG: /* clear specified log */
1481 /* zero out the specified log: p1=logname */
1482 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1483 if (code) return code;
1484 logp = afs_icl_FindLog(tname);
1485 if (!logp) return ENOENT;
1486 code = afs_icl_ZeroLog(logp);
1487 afs_icl_LogRele(logp);
1490 case ICL_OP_CLRSET: /* clear specified set */
1491 /* zero out the specified set: p1=setname */
1492 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1493 if (code) return code;
1494 setp = afs_icl_FindSet(tname);
1495 if (!setp) return ENOENT;
1496 code = afs_icl_ZeroSet(setp);
1497 afs_icl_SetRele(setp);
1500 case ICL_OP_CLRALL: /* clear all logs */
1501 /* zero out all logs -- no args */
1503 ObtainWriteLock(&afs_icl_lock,178);
1504 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1505 tlp->refCount++; /* hold this guy */
1506 ReleaseWriteLock(&afs_icl_lock);
1507 /* don't clear persistent logs */
1508 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1509 code = afs_icl_ZeroLog(tlp);
1510 ObtainWriteLock(&afs_icl_lock,179);
1511 if (--tlp->refCount == 0)
1512 afs_icl_ZapLog(tlp);
1515 ReleaseWriteLock(&afs_icl_lock);
1518 case ICL_OP_ENUMSETS: /* enumerate all sets */
1519 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1520 * return 0 for success, otherwise error.
1522 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1523 if (p1-- == 0) break;
1525 if (!setp) return ENOENT; /* past the end of file */
1526 temp = strlen(setp->name)+1;
1527 if (temp > p3) return EINVAL;
1528 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1529 if (!code) /* copy out size of log */
1530 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1533 case ICL_OP_SETSTAT: /* set status on a set */
1534 /* activate the specified set: p1=setname, p2=op */
1535 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1536 if (code) return code;
1537 setp = afs_icl_FindSet(tname);
1538 if (!setp) return ENOENT;
1539 code = afs_icl_SetSetStat(setp, p2);
1540 afs_icl_SetRele(setp);
1543 case ICL_OP_SETSTATALL: /* set status on all sets */
1544 /* activate the specified set: p1=op */
1546 ObtainWriteLock(&afs_icl_lock,180);
1547 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1548 setp->refCount++; /* hold this guy */
1549 ReleaseWriteLock(&afs_icl_lock);
1550 /* don't set states on persistent sets */
1551 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1552 code = afs_icl_SetSetStat(setp, p1);
1553 ObtainWriteLock(&afs_icl_lock,181);
1554 if (--setp->refCount == 0)
1555 afs_icl_ZapSet(setp);
1558 ReleaseWriteLock(&afs_icl_lock);
1561 case ICL_OP_SETLOGSIZE: /* set size of log */
1562 /* set the size of the specified log: p1=logname, p2=size (in words) */
1563 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1564 if (code) return code;
1565 logp = afs_icl_FindLog(tname);
1566 if (!logp) return ENOENT;
1567 code = afs_icl_LogSetSize(logp, p2);
1568 afs_icl_LogRele(logp);
1571 case ICL_OP_GETLOGINFO: /* get size of log */
1572 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1573 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1574 if (code) return code;
1575 logp = afs_icl_FindLog(tname);
1576 if (!logp) return ENOENT;
1577 allocated = !!logp->datap;
1578 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1580 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1581 afs_icl_LogRele(logp);
1584 case ICL_OP_GETSETINFO: /* get state of set */
1585 /* zero out the specified set: p1=setname, p2=&state */
1586 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1587 if (code) return code;
1588 setp = afs_icl_FindSet(tname);
1589 if (!setp) return ENOENT;
1590 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1591 afs_icl_SetRele(setp);
1602 afs_lock_t afs_icl_lock;
1604 /* exported routine: a 4 parameter event */
1605 afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, p4)
1606 register struct afs_icl_set *setp;
1609 long p1, p2, p3, p4;
1611 register struct afs_icl_log *logp;
1614 register afs_int32 tmask;
1617 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1618 if (!ICL_SETACTIVE(setp)) return;
1621 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1622 ix = ICL_EVENTBYTE(eventID);
1623 ObtainReadLock(&setp->lock);
1624 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1625 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1627 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1631 if (mask == 0) break; /* break early */
1634 ReleaseReadLock(&setp->lock);
1637 /* Next 4 routines should be implemented via var-args or something.
1638 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1639 * Otherwise, could call afs_icl_Event4 directly.
1641 afs_icl_Event3(setp, eventID, lAndT, p1, p2, p3)
1642 register struct afs_icl_set *setp;
1647 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1650 afs_icl_Event2(setp, eventID, lAndT, p1, p2)
1651 register struct afs_icl_set *setp;
1656 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1659 afs_icl_Event1(setp, eventID, lAndT, p1)
1660 register struct afs_icl_set *setp;
1665 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1668 afs_icl_Event0(setp, eventID, lAndT)
1669 register struct afs_icl_set *setp;
1673 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1676 struct afs_icl_log *afs_icl_allLogs = 0;
1678 /* function to purge records from the start of the log, until there
1679 * is at least minSpace long's worth of space available without
1680 * making the head and the tail point to the same word.
1682 * Log must be write-locked.
1684 static afs_icl_GetLogSpace(logp, minSpace)
1685 register struct afs_icl_log *logp;
1688 register unsigned int tsize;
1690 while (logp->logSize - logp->logElements <= minSpace) {
1692 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1693 logp->logElements -= tsize;
1694 logp->firstUsed += tsize;
1695 if (logp->firstUsed >= logp->logSize)
1696 logp->firstUsed -= logp->logSize;
1697 logp->baseCookie += tsize;
1701 /* append string astr to buffer, including terminating null char.
1703 * log must be write-locked.
1705 #define ICL_CHARSPERLONG 4
1706 static afs_int32 afs_icl_AppendString(logp, astr)
1707 struct afs_icl_log *logp;
1710 char *op; /* ptr to char to write */
1712 register int bib; /* bytes in buffer */
1715 op = (char *) &(logp->datap[logp->firstFree]);
1719 if (++bib >= ICL_CHARSPERLONG) {
1722 if (++(logp->firstFree) >= logp->logSize) {
1723 logp->firstFree = 0;
1724 op = (char *) &(logp->datap[0]);
1726 logp->logElements++;
1731 /* if we've used this word at all, allocate it */
1732 if (++(logp->firstFree) >= logp->logSize) {
1733 logp->firstFree = 0;
1735 logp->logElements++;
1739 /* add a long to the log, ignoring overflow (checked already) */
1740 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1741 #define ICL_APPENDINT32(lp, x) \
1743 (lp)->datap[(lp)->firstFree] = (x); \
1744 if (++((lp)->firstFree) >= (lp)->logSize) { \
1745 (lp)->firstFree = 0; \
1747 (lp)->logElements++; \
1750 #define ICL_APPENDLONG(lp, x) \
1752 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1753 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1756 #else /* AFS_ALPHA_ENV */
1757 #define ICL_APPENDLONG(lp, x) \
1759 (lp)->datap[(lp)->firstFree] = (x); \
1760 if (++((lp)->firstFree) >= (lp)->logSize) { \
1761 (lp)->firstFree = 0; \
1763 (lp)->logElements++; \
1765 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1766 #endif /* AFS_ALPHA_ENV */
1768 /* routine to tell whether we're dealing with the address or the
1771 afs_icl_UseAddr(type)
1774 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1775 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
1781 /* Function to append a record to the log. Written for speed
1782 * since we know that we're going to have to make this work fast
1783 * pretty soon, anyway. The log must be unlocked.
1786 afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4)
1787 register struct afs_icl_log *logp;
1790 long p1, p2, p3, p4;
1792 int rsize; /* record size in longs */
1793 register int tsize; /* temp size */
1797 t4 = types & 0x3f; /* decode types */
1805 osi_GetTime(&tv); /* It panics for solaris if inside */
1806 ObtainWriteLock(&logp->lock,182);
1808 ReleaseWriteLock(&logp->lock);
1812 /* get timestamp as # of microseconds since some time that doesn't
1813 * change that often. This algorithm ticks over every 20 minutes
1814 * or so (1000 seconds). Write a timestamp record if it has.
1816 if (tv.tv_sec - logp->lastTS > 1024)
1818 /* the timer has wrapped -- write a timestamp record */
1819 if (logp->logSize - logp->logElements <= 5)
1820 afs_icl_GetLogSpace(logp, 5);
1822 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1823 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1824 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1825 ICL_APPENDINT32(logp,
1826 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1827 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1829 logp->lastTS = tv.tv_sec;
1832 rsize = 4; /* base case */
1834 /* compute size of parameter p1. Only tricky case is string.
1835 * In that case, we have to call strlen to get the string length.
1837 ICL_SIZEHACK(t1, p1);
1840 /* compute size of parameter p2. Only tricky case is string.
1841 * In that case, we have to call strlen to get the string length.
1843 ICL_SIZEHACK(t2, p2);
1846 /* compute size of parameter p3. Only tricky case is string.
1847 * In that case, we have to call strlen to get the string length.
1849 ICL_SIZEHACK(t3, p3);
1852 /* compute size of parameter p4. Only tricky case is string.
1853 * In that case, we have to call strlen to get the string length.
1855 ICL_SIZEHACK(t4, p4);
1858 /* At this point, we've computed all of the parameter sizes, and
1859 * have in rsize the size of the entire record we want to append.
1860 * Next, we check that we actually have room in the log to do this
1861 * work, and then we do the append.
1864 ReleaseWriteLock(&logp->lock);
1865 return; /* log record too big to express */
1868 if (logp->logSize - logp->logElements <= rsize)
1869 afs_icl_GetLogSpace(logp, rsize);
1871 ICL_APPENDINT32(logp,
1872 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
1873 ICL_APPENDINT32(logp, (afs_int32)op);
1874 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
1875 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1878 /* marshall parameter 1 now */
1879 if (t1 == ICL_TYPE_STRING) {
1880 afs_icl_AppendString(logp, (char *) p1);
1882 else if (t1 == ICL_TYPE_HYPER) {
1883 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
1884 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
1886 else if (t1 == ICL_TYPE_INT64) {
1887 #ifdef AFSLITTLE_ENDIAN
1888 #ifdef AFS_64BIT_CLIENT
1889 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1890 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1891 #else /* AFS_64BIT_CLIENT */
1892 ICL_APPENDINT32(logp, (afs_int32) p1);
1893 ICL_APPENDINT32(logp, (afs_int32) 0);
1894 #endif /* AFS_64BIT_CLIENT */
1895 #else /* AFSLITTLE_ENDIAN */
1896 #ifdef AFS_64BIT_CLIENT
1897 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1898 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1899 #else /* AFS_64BIT_CLIENT */
1900 ICL_APPENDINT32(logp, (afs_int32) 0);
1901 ICL_APPENDINT32(logp, (afs_int32) p1);
1902 #endif /* AFS_64BIT_CLIENT */
1903 #endif /* AFSLITTLE_ENDIAN */
1905 else if (t1 == ICL_TYPE_FID) {
1906 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1907 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1908 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
1909 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
1911 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1912 else if (t1 == ICL_TYPE_INT32)
1913 ICL_APPENDINT32(logp, (afs_int32)p1);
1914 #endif /* AFS_ALPHA_ENV */
1915 else ICL_APPENDLONG(logp, p1);
1918 /* marshall parameter 2 now */
1919 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
1920 else if (t2 == ICL_TYPE_HYPER) {
1921 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
1922 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
1924 else if (t2 == ICL_TYPE_INT64) {
1925 #ifdef AFSLITTLE_ENDIAN
1926 #ifdef AFS_64BIT_CLIENT
1927 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1928 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1929 #else /* AFS_64BIT_CLIENT */
1930 ICL_APPENDINT32(logp, (afs_int32) p2);
1931 ICL_APPENDINT32(logp, (afs_int32) 0);
1932 #endif /* AFS_64BIT_CLIENT */
1933 #else /* AFSLITTLE_ENDIAN */
1934 #ifdef AFS_64BIT_CLIENT
1935 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1936 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1937 #else /* AFS_64BIT_CLIENT */
1938 ICL_APPENDINT32(logp, (afs_int32) 0);
1939 ICL_APPENDINT32(logp, (afs_int32) p2);
1940 #endif /* AFS_64BIT_CLIENT */
1941 #endif /* AFSLITTLE_ENDIAN */
1943 else if (t2 == ICL_TYPE_FID) {
1944 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1945 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1946 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
1947 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
1949 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1950 else if (t2 == ICL_TYPE_INT32)
1951 ICL_APPENDINT32(logp, (afs_int32)p2);
1952 #endif /* AFS_ALPHA_ENV */
1953 else ICL_APPENDLONG(logp, p2);
1956 /* marshall parameter 3 now */
1957 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
1958 else if (t3 == ICL_TYPE_HYPER) {
1959 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
1960 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
1962 else if (t3 == ICL_TYPE_INT64) {
1963 #ifdef AFSLITTLE_ENDIAN
1964 #ifdef AFS_64BIT_CLIENT
1965 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1966 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1967 #else /* AFS_64BIT_CLIENT */
1968 ICL_APPENDINT32(logp, (afs_int32) p3);
1969 ICL_APPENDINT32(logp, (afs_int32) 0);
1970 #endif /* AFS_64BIT_CLIENT */
1971 #else /* AFSLITTLE_ENDIAN */
1972 #ifdef AFS_64BIT_CLIENT
1973 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1974 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1975 #else /* AFS_64BIT_CLIENT */
1976 ICL_APPENDINT32(logp, (afs_int32) 0);
1977 ICL_APPENDINT32(logp, (afs_int32) p3);
1978 #endif /* AFS_64BIT_CLIENT */
1979 #endif /* AFSLITTLE_ENDIAN */
1981 else if (t3 == ICL_TYPE_FID) {
1982 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1983 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1984 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
1985 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
1987 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1988 else if (t3 == ICL_TYPE_INT32)
1989 ICL_APPENDINT32(logp, (afs_int32)p3);
1990 #endif /* AFS_ALPHA_ENV */
1991 else ICL_APPENDLONG(logp, p3);
1994 /* marshall parameter 4 now */
1995 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
1996 else if (t4 == ICL_TYPE_HYPER) {
1997 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
1998 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
2000 else if (t4 == ICL_TYPE_INT64) {
2001 #ifdef AFSLITTLE_ENDIAN
2002 #ifdef AFS_64BIT_CLIENT
2003 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2004 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2005 #else /* AFS_64BIT_CLIENT */
2006 ICL_APPENDINT32(logp, (afs_int32) p4);
2007 ICL_APPENDINT32(logp, (afs_int32) 0);
2008 #endif /* AFS_64BIT_CLIENT */
2009 #else /* AFSLITTLE_ENDIAN */
2010 #ifdef AFS_64BIT_CLIENT
2011 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2012 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2013 #else /* AFS_64BIT_CLIENT */
2014 ICL_APPENDINT32(logp, (afs_int32) 0);
2015 ICL_APPENDINT32(logp, (afs_int32) p4);
2016 #endif /* AFS_64BIT_CLIENT */
2017 #endif /* AFSLITTLE_ENDIAN */
2019 else if (t4 == ICL_TYPE_FID) {
2020 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2021 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2022 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
2023 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
2025 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2026 else if (t4 == ICL_TYPE_INT32)
2027 ICL_APPENDINT32(logp, (afs_int32)p4);
2028 #endif /* AFS_ALPHA_ENV */
2029 else ICL_APPENDLONG(logp, p4);
2031 ReleaseWriteLock(&logp->lock);
2034 /* create a log with size logSize; return it in *outLogpp and tag
2035 * it with name "name."
2037 afs_icl_CreateLog(name, logSize, outLogpp)
2040 struct afs_icl_log **outLogpp;
2042 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
2045 /* create a log with size logSize; return it in *outLogpp and tag
2046 * it with name "name." 'flags' can be set to make the log unclearable.
2048 afs_icl_CreateLogWithFlags(name, logSize, flags, outLogpp)
2052 struct afs_icl_log **outLogpp;
2054 register struct afs_icl_log *logp;
2056 /* add into global list under lock */
2057 ObtainWriteLock(&afs_icl_lock,183);
2058 if (!afs_icl_inited) afs_icl_Init();
2060 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
2061 if (strcmp(logp->name, name) == 0) {
2062 /* found it already created, just return it */
2065 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2067 ObtainWriteLock(&logp->lock,184);
2068 logp->states |= ICL_LOGF_PERSISTENT;
2069 ReleaseWriteLock(&logp->lock);
2071 ReleaseWriteLock(&afs_icl_lock);
2076 logp = (struct afs_icl_log *)
2077 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
2078 memset((caddr_t)logp, 0, sizeof(*logp));
2081 logp->name = osi_AllocSmallSpace(strlen(name)+1);
2082 strcpy(logp->name, name);
2083 LOCK_INIT(&logp->lock, "logp lock");
2084 logp->logSize = logSize;
2085 logp->datap = (afs_int32 *)0; /* don't allocate it until we need it */
2087 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2088 logp->states |= ICL_LOGF_PERSISTENT;
2090 logp->nextp = afs_icl_allLogs;
2091 afs_icl_allLogs = logp;
2092 ReleaseWriteLock(&afs_icl_lock);
2098 /* called with a log, a pointer to a buffer, the size of the buffer
2099 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
2100 * and returns data in the provided buffer, and returns output flags
2101 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
2102 * find the record with cookie value cookie.
2104 afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp)
2105 register struct afs_icl_log *logp;
2107 afs_int32 *bufSizep;
2108 afs_uint32 *cookiep;
2111 afs_int32 nwords; /* number of words to copy out */
2112 afs_uint32 startCookie; /* first cookie to use */
2113 register afs_int32 i;
2114 afs_int32 outWords; /* words we've copied out */
2115 afs_int32 inWords; /* max words to copy out */
2116 afs_int32 code; /* return code */
2117 afs_int32 ix; /* index we're copying from */
2118 afs_int32 outFlags; /* return flags */
2119 afs_int32 inFlags; /* flags passed in */
2122 inWords = *bufSizep; /* max to copy out */
2123 outWords = 0; /* amount copied out */
2124 startCookie = *cookiep;
2129 ObtainWriteLock(&logp->lock,185);
2131 ReleaseWriteLock(&logp->lock);
2135 /* first, compute the index of the start cookie we've been passed */
2137 /* (re-)compute where we should start */
2138 if (startCookie < logp->baseCookie) {
2139 if (startCookie) /* missed some output */
2140 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2141 /* skip to the first available record */
2142 startCookie = logp->baseCookie;
2143 *cookiep = startCookie;
2146 /* compute where we find the first element to copy out */
2147 ix = logp->firstUsed + startCookie - logp->baseCookie;
2148 if (ix >= logp->logSize) ix -= logp->logSize;
2150 /* if have some data now, break out and process it */
2151 if (startCookie - logp->baseCookie < logp->logElements) break;
2153 /* At end of log, so clear it if we need to */
2154 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
2156 logp->firstUsed = logp->firstFree = 0;
2157 logp->logElements = 0;
2159 /* otherwise, either wait for the data to arrive, or return */
2160 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2161 ReleaseWriteLock(&logp->lock);
2165 logp->states |= ICL_LOGF_WAITING;
2166 ReleaseWriteLock(&logp->lock);
2167 afs_osi_Sleep(&logp->lock);
2168 ObtainWriteLock(&logp->lock,186);
2170 /* copy out data from ix to logSize or firstFree, depending
2171 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2172 * be careful not to copy out more than nwords.
2174 if (ix >= logp->firstUsed) {
2175 if (logp->firstUsed <= logp->firstFree)
2177 end = logp->firstFree; /* first element not to copy */
2179 end = logp->logSize;
2180 nwords = inWords; /* don't copy more than this */
2181 if (end - ix < nwords)
2184 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2189 /* if we're going to copy more out below, we'll start here */
2192 /* now, if active part of the log has wrapped, there's more stuff
2193 * starting at the head of the log. Copy out more from there.
2195 if (logp->firstUsed > logp->firstFree
2196 && ix < logp->firstFree && inWords > 0) {
2197 /* (more to) copy out from the wrapped section at the
2198 * start of the log. May get here even if didn't copy any
2199 * above, if the cookie points directly into the wrapped section.
2202 if (logp->firstFree - ix < nwords)
2203 nwords = logp->firstFree - ix;
2204 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2210 ReleaseWriteLock(&logp->lock);
2214 *bufSizep = outWords;
2220 /* return basic parameter information about a log */
2221 afs_icl_GetLogParms(logp, maxSizep, curSizep)
2222 struct afs_icl_log *logp;
2223 afs_int32 *maxSizep;
2224 afs_int32 *curSizep;
2226 ObtainReadLock(&logp->lock);
2227 *maxSizep = logp->logSize;
2228 *curSizep = logp->logElements;
2229 ReleaseReadLock(&logp->lock);
2234 /* hold and release logs */
2235 afs_icl_LogHold(logp)
2236 register struct afs_icl_log *logp;
2238 ObtainWriteLock(&afs_icl_lock,187);
2240 ReleaseWriteLock(&afs_icl_lock);
2244 /* hold and release logs, called with lock already held */
2245 afs_icl_LogHoldNL(logp)
2246 register struct afs_icl_log *logp;
2252 /* keep track of how many sets believe the log itself is allocated */
2253 afs_icl_LogUse(logp)
2254 register struct afs_icl_log *logp;
2256 ObtainWriteLock(&logp->lock,188);
2257 if (logp->setCount == 0) {
2258 /* this is the first set actually using the log -- allocate it */
2259 if (logp->logSize == 0) {
2260 /* we weren't passed in a hint and it wasn't set */
2261 logp->logSize = ICL_DEFAULT_LOGSIZE;
2263 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2264 #ifdef AFS_AIX32_ENV
2265 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2269 ReleaseWriteLock(&logp->lock);
2273 /* decrement the number of real users of the log, free if possible */
2274 afs_icl_LogFreeUse(logp)
2275 register struct afs_icl_log *logp;
2277 ObtainWriteLock(&logp->lock,189);
2278 if (--logp->setCount == 0) {
2279 /* no more users -- free it (but keep log structure around)*/
2280 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2281 #ifdef AFS_AIX32_ENV
2282 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2284 logp->firstUsed = logp->firstFree = 0;
2285 logp->logElements = 0;
2286 logp->datap = (afs_int32 *)0;
2288 ReleaseWriteLock(&logp->lock);
2292 /* set the size of the log to 'logSize' */
2293 afs_icl_LogSetSize(logp, logSize)
2294 register struct afs_icl_log *logp;
2297 ObtainWriteLock(&logp->lock,190);
2299 /* nothing to worry about since it's not allocated */
2300 logp->logSize = logSize;
2304 logp->firstUsed = logp->firstFree = 0;
2305 logp->logElements = 0;
2307 /* free and allocate a new one */
2308 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2309 #ifdef AFS_AIX32_ENV
2310 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2312 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2313 #ifdef AFS_AIX32_ENV
2314 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2316 logp->logSize = logSize;
2318 ReleaseWriteLock(&logp->lock);
2323 /* free a log. Called with afs_icl_lock locked. */
2324 afs_icl_ZapLog(logp)
2325 register struct afs_icl_log *logp;
2327 register struct afs_icl_log **lpp, *tp;
2329 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2331 /* found the dude we want to remove */
2333 osi_FreeSmallSpace(logp->name);
2334 osi_FreeSmallSpace(logp->datap);
2335 osi_FreeSmallSpace(logp);
2336 break; /* won't find it twice */
2342 /* do the release, watching for deleted entries */
2343 afs_icl_LogRele(logp)
2344 register struct afs_icl_log *logp;
2346 ObtainWriteLock(&afs_icl_lock,191);
2347 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2348 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2350 ReleaseWriteLock(&afs_icl_lock);
2354 /* do the release, watching for deleted entries, log already held */
2355 afs_icl_LogReleNL(logp)
2356 register struct afs_icl_log *logp;
2358 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2359 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2364 /* zero out the log */
2365 afs_icl_ZeroLog(logp)
2366 register struct afs_icl_log *logp;
2368 ObtainWriteLock(&logp->lock,192);
2369 logp->firstUsed = logp->firstFree = 0;
2370 logp->logElements = 0;
2371 logp->baseCookie = 0;
2372 ReleaseWriteLock(&logp->lock);
2376 /* free a log entry, and drop its reference count */
2377 afs_icl_LogFree(logp)
2378 register struct afs_icl_log *logp;
2380 ObtainWriteLock(&logp->lock,193);
2381 logp->states |= ICL_LOGF_DELETED;
2382 ReleaseWriteLock(&logp->lock);
2383 afs_icl_LogRele(logp);
2387 /* find a log by name, returning it held */
2388 struct afs_icl_log *afs_icl_FindLog(name)
2391 register struct afs_icl_log *tp;
2392 ObtainWriteLock(&afs_icl_lock,194);
2393 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2394 if (strcmp(tp->name, name) == 0) {
2395 /* this is the dude we want */
2400 ReleaseWriteLock(&afs_icl_lock);
2404 afs_icl_EnumerateLogs(aproc, arock)
2408 register struct afs_icl_log *tp;
2409 register afs_int32 code;
2412 ObtainWriteLock(&afs_icl_lock,195);
2413 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2414 tp->refCount++; /* hold this guy */
2415 ReleaseWriteLock(&afs_icl_lock);
2416 ObtainReadLock(&tp->lock);
2417 code = (*aproc)(tp->name, arock, tp);
2418 ReleaseReadLock(&tp->lock);
2419 ObtainWriteLock(&afs_icl_lock,196);
2420 if (--tp->refCount == 0)
2424 ReleaseWriteLock(&afs_icl_lock);
2428 struct afs_icl_set *afs_icl_allSets = 0;
2430 afs_icl_CreateSet(name, baseLogp, fatalLogp, outSetpp)
2432 struct afs_icl_log *baseLogp;
2433 struct afs_icl_log *fatalLogp;
2434 struct afs_icl_set **outSetpp;
2436 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2437 /*flags*/0, outSetpp);
2440 /* create a set, given pointers to base and fatal logs, if any.
2441 * Logs are unlocked, but referenced, and *outSetpp is returned
2442 * referenced. Function bumps reference count on logs, since it
2443 * addds references from the new afs_icl_set. When the set is destroyed,
2444 * those references will be released.
2446 afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp)
2448 struct afs_icl_log *baseLogp;
2449 struct afs_icl_log *fatalLogp;
2451 struct afs_icl_set **outSetpp;
2453 register struct afs_icl_set *setp;
2455 afs_int32 states = ICL_DEFAULT_SET_STATES;
2457 ObtainWriteLock(&afs_icl_lock,197);
2458 if (!afs_icl_inited) afs_icl_Init();
2460 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2461 if (strcmp(setp->name, name) == 0) {
2464 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2466 ObtainWriteLock(&setp->lock,198);
2467 setp->states |= ICL_SETF_PERSISTENT;
2468 ReleaseWriteLock(&setp->lock);
2470 ReleaseWriteLock(&afs_icl_lock);
2475 /* determine initial state */
2476 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2477 states = ICL_SETF_ACTIVE;
2478 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2479 states = ICL_SETF_FREED;
2480 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2481 states |= ICL_SETF_PERSISTENT;
2483 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2484 memset((caddr_t)setp, 0, sizeof(*setp));
2486 if (states & ICL_SETF_FREED)
2487 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2488 setp->states = states;
2490 LOCK_INIT(&setp->lock, "setp lock");
2491 /* next lock is obtained in wrong order, hierarchy-wise, but
2492 * it doesn't matter, since no one can find this lock yet, since
2493 * the afs_icl_lock is still held, and thus the obtain can't block.
2495 ObtainWriteLock(&setp->lock,199);
2496 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2497 strcpy(setp->name, name);
2498 setp->nevents = ICL_DEFAULTEVENTS;
2499 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2500 #ifdef AFS_AIX32_ENV
2501 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2503 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2504 setp->eventFlags[i] = 0xff; /* default to enabled */
2506 /* update this global info under the afs_icl_lock */
2507 setp->nextp = afs_icl_allSets;
2508 afs_icl_allSets = setp;
2509 ReleaseWriteLock(&afs_icl_lock);
2511 /* set's basic lock is still held, so we can finish init */
2513 setp->logs[0] = baseLogp;
2514 afs_icl_LogHold(baseLogp);
2515 if (!(setp->states & ICL_SETF_FREED))
2516 afs_icl_LogUse(baseLogp); /* log is actually being used */
2519 setp->logs[1] = fatalLogp;
2520 afs_icl_LogHold(fatalLogp);
2521 if (!(setp->states & ICL_SETF_FREED))
2522 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2524 ReleaseWriteLock(&setp->lock);
2530 /* function to change event enabling information for a particular set */
2531 afs_icl_SetEnable(setp, eventID, setValue)
2532 struct afs_icl_set *setp;
2538 ObtainWriteLock(&setp->lock,200);
2539 if (!ICL_EVENTOK(setp, eventID)) {
2540 ReleaseWriteLock(&setp->lock);
2543 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2545 *tp |= ICL_EVENTMASK(eventID);
2547 *tp &= ~(ICL_EVENTMASK(eventID));
2548 ReleaseWriteLock(&setp->lock);
2552 /* return indication of whether a particular event ID is enabled
2553 * for tracing. If *getValuep is set to 0, the event is disabled,
2554 * otherwise it is enabled. All events start out enabled by default.
2556 afs_icl_GetEnable(setp, eventID, getValuep)
2557 struct afs_icl_set *setp;
2561 ObtainReadLock(&setp->lock);
2562 if (!ICL_EVENTOK(setp, eventID)) {
2563 ReleaseWriteLock(&setp->lock);
2566 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2570 ReleaseReadLock(&setp->lock);
2574 /* hold and release event sets */
2575 afs_icl_SetHold(setp)
2576 register struct afs_icl_set *setp;
2578 ObtainWriteLock(&afs_icl_lock,201);
2580 ReleaseWriteLock(&afs_icl_lock);
2584 /* free a set. Called with afs_icl_lock locked */
2585 afs_icl_ZapSet(setp)
2586 register struct afs_icl_set *setp;
2588 register struct afs_icl_set **lpp, *tp;
2590 register struct afs_icl_log *tlp;
2592 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2594 /* found the dude we want to remove */
2596 osi_FreeSmallSpace(setp->name);
2597 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2598 #ifdef AFS_AIX32_ENV
2599 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2601 for(i=0; i < ICL_LOGSPERSET; i++) {
2602 if (tlp = setp->logs[i])
2603 afs_icl_LogReleNL(tlp);
2605 osi_FreeSmallSpace(setp);
2606 break; /* won't find it twice */
2612 /* do the release, watching for deleted entries */
2613 afs_icl_SetRele(setp)
2614 register struct afs_icl_set *setp;
2616 ObtainWriteLock(&afs_icl_lock,202);
2617 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2618 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2620 ReleaseWriteLock(&afs_icl_lock);
2624 /* free a set entry, dropping its reference count */
2625 afs_icl_SetFree(setp)
2626 register struct afs_icl_set *setp;
2628 ObtainWriteLock(&setp->lock,203);
2629 setp->states |= ICL_SETF_DELETED;
2630 ReleaseWriteLock(&setp->lock);
2631 afs_icl_SetRele(setp);
2635 /* find a set by name, returning it held */
2636 struct afs_icl_set *afs_icl_FindSet(name)
2639 register struct afs_icl_set *tp;
2640 ObtainWriteLock(&afs_icl_lock,204);
2641 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2642 if (strcmp(tp->name, name) == 0) {
2643 /* this is the dude we want */
2648 ReleaseWriteLock(&afs_icl_lock);
2652 /* zero out all the logs in the set */
2653 afs_icl_ZeroSet(setp)
2654 struct afs_icl_set *setp;
2659 struct afs_icl_log *logp;
2661 ObtainReadLock(&setp->lock);
2662 for(i = 0; i < ICL_LOGSPERSET; i++) {
2663 logp = setp->logs[i];
2665 afs_icl_LogHold(logp);
2666 tcode = afs_icl_ZeroLog(logp);
2667 if (tcode != 0) code = tcode; /* save the last bad one */
2668 afs_icl_LogRele(logp);
2671 ReleaseReadLock(&setp->lock);
2675 afs_icl_EnumerateSets(aproc, arock)
2679 register struct afs_icl_set *tp, *np;
2680 register afs_int32 code;
2683 ObtainWriteLock(&afs_icl_lock,205);
2684 for(tp = afs_icl_allSets; tp; tp=np) {
2685 tp->refCount++; /* hold this guy */
2686 ReleaseWriteLock(&afs_icl_lock);
2687 code = (*aproc)(tp->name, arock, tp);
2688 ObtainWriteLock(&afs_icl_lock,206);
2689 np = tp->nextp; /* tp may disappear next, but not np */
2690 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2694 ReleaseWriteLock(&afs_icl_lock);
2698 afs_icl_AddLogToSet(setp, newlogp)
2699 struct afs_icl_set *setp;
2700 struct afs_icl_log *newlogp;
2704 struct afs_icl_log *logp;
2706 ObtainWriteLock(&setp->lock,207);
2707 for(i = 0; i < ICL_LOGSPERSET; i++) {
2708 if (!setp->logs[i]) {
2709 setp->logs[i] = newlogp;
2711 afs_icl_LogHold(newlogp);
2712 if (!(setp->states & ICL_SETF_FREED)) {
2713 /* bump up the number of sets using the log */
2714 afs_icl_LogUse(newlogp);
2719 ReleaseWriteLock(&setp->lock);
2723 afs_icl_SetSetStat(setp, op)
2724 struct afs_icl_set *setp;
2729 struct afs_icl_log *logp;
2731 ObtainWriteLock(&setp->lock,208);
2733 case ICL_OP_SS_ACTIVATE: /* activate a log */
2735 * If we are not already active, see if we have released
2736 * our demand that the log be allocated (FREED set). If
2737 * we have, reassert our desire.
2739 if (!(setp->states & ICL_SETF_ACTIVE)) {
2740 if (setp->states & ICL_SETF_FREED) {
2741 /* have to reassert desire for logs */
2742 for(i = 0; i < ICL_LOGSPERSET; i++) {
2743 logp = setp->logs[i];
2745 afs_icl_LogHold(logp);
2746 afs_icl_LogUse(logp);
2747 afs_icl_LogRele(logp);
2750 setp->states &= ~ICL_SETF_FREED;
2752 setp->states |= ICL_SETF_ACTIVE;
2757 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2758 /* this doesn't require anything beyond clearing the ACTIVE flag */
2759 setp->states &= ~ICL_SETF_ACTIVE;
2763 case ICL_OP_SS_FREE: /* deassert design for log */
2765 * if we are already in this state, do nothing; otherwise
2766 * deassert desire for log
2768 if (setp->states & ICL_SETF_ACTIVE)
2771 if (!(setp->states & ICL_SETF_FREED)) {
2772 for(i = 0; i < ICL_LOGSPERSET; i++) {
2773 logp = setp->logs[i];
2775 afs_icl_LogHold(logp);
2776 afs_icl_LogFreeUse(logp);
2777 afs_icl_LogRele(logp);
2780 setp->states |= ICL_SETF_FREED;
2789 ReleaseWriteLock(&setp->lock);