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 /* eparm is also used by AFSCALL_CALL in afsd.c */
1001 } *uap = (struct a *)u.u_ap;
1003 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
1007 #endif /* SUN && !SUN5 */
1017 } *uap = (struct a *)u.u_ap;
1018 #endif /* UKERNEL */
1019 #if defined(AFS_DEC_ENV)
1020 int *retval = &u.u_r.r_val1;
1022 #if defined(AFS_HPUX_ENV)
1023 long *retval = &u.u_rval1;
1025 int *retval = &u.u_rval1;
1028 #endif /* AFS_LINUX20_ENV */
1029 #endif /* AFS_OSF_ENV */
1030 #endif /* AFS_SUN5_ENV */
1031 register int code = 0;
1033 AFS_STATCNT(afs_syscall);
1040 #ifdef AFS_LINUX20_ENV
1042 /* setup uap for use below - pull out the magic decoder ring to know
1043 * which syscalls have folded argument lists.
1045 uap->syscall = syscall;
1049 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
1050 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
1051 uap->parm4 = eparm[0];
1052 uap->parm5 = eparm[1];
1053 uap->parm6 = eparm[2];
1062 #if defined(AFS_HPUX_ENV)
1064 * There used to be code here (duplicated from osi_Init()) for
1065 * initializing the semaphore used by AFS_GLOCK(). Was the
1066 * duplication to handle the case of a dynamically loaded kernel
1071 if (uap->syscall == AFSCALL_CALL) {
1073 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1074 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1076 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1078 } else if (uap->syscall == AFSCALL_SETPAG) {
1080 register proc_t *procp;
1082 procp = ttoproc(curthread);
1084 code = afs_setpag(&procp->p_cred);
1088 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1089 code = afs_setpag(p, args, retval);
1090 #else /* AFS_OSF_ENV */
1091 code = afs_setpag();
1095 } else if (uap->syscall == AFSCALL_PIOCTL) {
1098 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1100 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1101 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1103 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1107 } else if (uap->syscall == AFSCALL_ICREATE) {
1108 struct iparam iparams;
1110 code = copyin_iparam((char *)uap->parm3, &iparams);
1112 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1117 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1118 iparams.param3, iparams.param4, rvp, CRED());
1120 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1121 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1122 iparams.param3, iparams.param4, retval);
1124 iparams.param3, iparams.param4);
1126 #endif /* AFS_SUN5_ENV */
1127 } else if (uap->syscall == AFSCALL_IOPEN) {
1129 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1131 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1132 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1134 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1136 #endif /* AFS_SUN5_ENV */
1137 } else if (uap->syscall == AFSCALL_IDEC) {
1139 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1141 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1142 #endif /* AFS_SUN5_ENV */
1143 } else if (uap->syscall == AFSCALL_IINC) {
1145 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1147 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1148 #endif /* AFS_SUN5_ENV */
1149 } else if (uap->syscall == AFSCALL_ICL) {
1151 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1153 #ifdef AFS_LINUX20_ENV
1155 /* ICL commands can return values. */
1156 code = -linux_ret; /* Gets negated again at exit below */
1160 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1164 #endif /* !AFS_LINUX20_ENV */
1166 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1170 #endif /* AFS_SUN5_ENV */
1173 #ifdef AFS_LINUX20_ENV
1179 #endif /* AFS_SGI_ENV */
1180 #endif /* !AFS_AIX32_ENV */
1183 * Initstate in the range 0 < x < 100 are early initialization states.
1184 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1185 * the cache may be initialized.
1186 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1187 * is done after all the cache initialization has been done.
1188 * Initstate of 200 means that the volume has been looked up once, possibly
1190 * Initstate of 300 means that the volume has been *successfully* looked up.
1193 register int code = 0;
1195 AFS_STATCNT(afs_CheckInit);
1196 if (afs_initState <= 100)
1197 code = ENXIO; /* never finished init phase */
1198 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1199 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1200 } else if (afs_initState == 200)
1201 code = ETIMEDOUT; /* didn't find root volume */
1205 int afs_shuttingdown = 0;
1209 extern short afs_brsDaemons;
1210 extern afs_int32 afs_CheckServerDaemonStarted;
1211 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1212 extern struct osi_file *afs_cacheInodep;
1214 AFS_STATCNT(afs_shutdown);
1215 if (afs_shuttingdown) return;
1216 afs_shuttingdown = 1;
1217 if (afs_cold_shutdown) afs_warn("COLD ");
1218 else afs_warn("WARM ");
1219 afs_warn("shutting down of: CB... ");
1221 afs_termState = AFSOP_STOP_RXCALLBACK;
1222 rx_WakeupServerProcs();
1223 /* shutdown_rxkernel(); */
1224 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1225 afs_osi_Sleep(&afs_termState);
1227 afs_warn("afs... ");
1228 while (afs_termState == AFSOP_STOP_AFS) {
1229 afs_osi_CancelWait(&AFS_WaitHandler);
1230 afs_osi_Sleep(&afs_termState);
1232 if (afs_CheckServerDaemonStarted) {
1233 while (afs_termState == AFSOP_STOP_CS) {
1234 afs_osi_CancelWait(&AFS_CSWaitHandler);
1235 afs_osi_Sleep(&afs_termState);
1238 afs_warn("BkG... ");
1239 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1240 while (afs_termState == AFSOP_STOP_BKG) {
1241 afs_osi_Wakeup(&afs_brsDaemons);
1242 afs_osi_Sleep(&afs_termState);
1244 afs_warn("CTrunc... ");
1245 /* Cancel cache truncate daemon. */
1246 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1247 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1248 afs_osi_Sleep(&afs_termState);
1250 #ifdef AFS_AFSDB_ENV
1251 afs_warn("AFSDB... ");
1253 while (afs_termState == AFSOP_STOP_AFSDB)
1254 afs_osi_Sleep(&afs_termState);
1256 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1257 afs_warn("RxEvent... ");
1258 /* cancel rx event deamon */
1259 while (afs_termState == AFSOP_STOP_RXEVENT)
1260 afs_osi_Sleep(&afs_termState);
1261 #if defined(RXK_LISTENER_ENV)
1262 afs_warn("RxListener... ");
1264 afs_osi_UnmaskRxkSignals();
1266 /* cancel rx listener */
1267 osi_StopListener(); /* This closes rx_socket. */
1268 while (afs_termState == AFSOP_STOP_RXK_LISTENER)
1269 afs_osi_Sleep(&afs_termState);
1272 afs_termState = AFSOP_STOP_COMPLETE;
1276 /* Close file only after daemons which can write to it are stopped. */
1277 if (afs_cacheInodep) /* memcache won't set this */
1279 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1280 afs_cacheInodep = 0;
1282 return; /* Just kill daemons for now */
1286 shutdown_rxkernel();
1290 shutdown_bufferpackage();
1296 shutdown_vnodeops();
1298 shutdown_exporter();
1299 shutdown_memcache();
1300 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1301 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1302 /* this routine does not exist in Ultrix systems... 93.01.19 */
1304 #endif /* AFS_DEC_ENV */
1307 /* The following hold the cm stats */
1309 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1310 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1311 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1313 afs_warn(" ALL allocated tables\n");
1314 afs_shuttingdown = 0;
1320 AFS_STATCNT(shutdown_afstest);
1321 afs_initState = afs_termState = afs_setTime = 0;
1322 AFS_Running = afs_CB_Running = 0;
1323 afs_CacheInit_Done = afs_Go_Done = 0;
1324 if (afs_cold_shutdown) {
1325 *afs_rootVolumeName = 0;
1330 /* In case there is a bunch of dynamically build bkg daemons to free */
1332 { AFS_STATCNT(shutdown_BKG); }
1335 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1336 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1337 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1338 int afs_icl_sizeofLong = 1;
1340 int afs_icl_sizeofLong = 2;
1343 int afs_icl_sizeofLong = 1;
1346 int afs_icl_inited = 0;
1348 /* init function, called once, under afs_icl_lock */
1355 extern struct afs_icl_log *afs_icl_FindLog();
1356 extern struct afs_icl_set *afs_icl_FindSet();
1360 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1363 afs_int32 *lp, elts, flags;
1364 register afs_int32 code;
1365 struct afs_icl_log *logp;
1366 struct afs_icl_set *setp;
1367 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1369 #else /* AFS_SGI61_ENV */
1371 #endif /* AFS_SGI61_ENV */
1373 afs_int32 startCookie;
1374 afs_int32 allocated;
1375 struct afs_icl_log *tlp;
1378 if (!afs_suser(CRED())) { /* only root can run this code */
1382 if (!afs_suser()) { /* only root can run this code */
1383 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1392 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1393 case ICL_OP_COPYOUT: /* copy ouy data */
1394 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1395 * return flags<<24 + nwords.
1396 * updates cookie to updated start (not end) if we had to
1397 * skip some records.
1399 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1400 if (code) return code;
1401 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1402 if (code) return code;
1403 logp = afs_icl_FindLog(tname);
1404 if (!logp) return ENOENT;
1405 #define BUFFERSIZE AFS_LRALLOCSIZ
1406 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1407 elts = BUFFERSIZE / sizeof(afs_int32);
1408 if (p3 < elts) elts = p3;
1409 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1410 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1413 osi_FreeLargeSpace((struct osi_buffer *) lp);
1416 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1417 if (code) goto done;
1418 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1419 if (code) goto done;
1420 *retval = (flags<<24) | (elts & 0xffffff);
1422 afs_icl_LogRele(logp);
1423 osi_FreeLargeSpace((struct osi_buffer *) lp);
1426 case ICL_OP_ENUMLOGS: /* enumerate logs */
1427 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1428 * return 0 for success, otherwise error.
1430 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1431 if (p1-- == 0) break;
1433 if (!tlp) return ENOENT; /* past the end of file */
1434 temp = strlen(tlp->name)+1;
1435 if (temp > p3) return EINVAL;
1436 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1437 if (!code) /* copy out size of log */
1438 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1441 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1442 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1443 * return 0 for success, otherwise error.
1445 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1446 if (code) return code;
1447 setp = afs_icl_FindSet(tname);
1448 if (!setp) return ENOENT;
1449 if (p2 > ICL_LOGSPERSET)
1451 if (!(tlp = setp->logs[p2]))
1453 temp = strlen(tlp->name)+1;
1454 if (temp > p4) return EINVAL;
1455 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1458 case ICL_OP_CLRLOG: /* clear specified log */
1459 /* zero out the specified log: p1=logname */
1460 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1461 if (code) return code;
1462 logp = afs_icl_FindLog(tname);
1463 if (!logp) return ENOENT;
1464 code = afs_icl_ZeroLog(logp);
1465 afs_icl_LogRele(logp);
1468 case ICL_OP_CLRSET: /* clear specified set */
1469 /* zero out the specified set: p1=setname */
1470 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1471 if (code) return code;
1472 setp = afs_icl_FindSet(tname);
1473 if (!setp) return ENOENT;
1474 code = afs_icl_ZeroSet(setp);
1475 afs_icl_SetRele(setp);
1478 case ICL_OP_CLRALL: /* clear all logs */
1479 /* zero out all logs -- no args */
1481 ObtainWriteLock(&afs_icl_lock,178);
1482 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1483 tlp->refCount++; /* hold this guy */
1484 ReleaseWriteLock(&afs_icl_lock);
1485 /* don't clear persistent logs */
1486 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1487 code = afs_icl_ZeroLog(tlp);
1488 ObtainWriteLock(&afs_icl_lock,179);
1489 if (--tlp->refCount == 0)
1490 afs_icl_ZapLog(tlp);
1493 ReleaseWriteLock(&afs_icl_lock);
1496 case ICL_OP_ENUMSETS: /* enumerate all sets */
1497 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1498 * return 0 for success, otherwise error.
1500 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1501 if (p1-- == 0) break;
1503 if (!setp) return ENOENT; /* past the end of file */
1504 temp = strlen(setp->name)+1;
1505 if (temp > p3) return EINVAL;
1506 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1507 if (!code) /* copy out size of log */
1508 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1511 case ICL_OP_SETSTAT: /* set status on a set */
1512 /* activate the specified set: p1=setname, p2=op */
1513 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1514 if (code) return code;
1515 setp = afs_icl_FindSet(tname);
1516 if (!setp) return ENOENT;
1517 code = afs_icl_SetSetStat(setp, p2);
1518 afs_icl_SetRele(setp);
1521 case ICL_OP_SETSTATALL: /* set status on all sets */
1522 /* activate the specified set: p1=op */
1524 ObtainWriteLock(&afs_icl_lock,180);
1525 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1526 setp->refCount++; /* hold this guy */
1527 ReleaseWriteLock(&afs_icl_lock);
1528 /* don't set states on persistent sets */
1529 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1530 code = afs_icl_SetSetStat(setp, p1);
1531 ObtainWriteLock(&afs_icl_lock,181);
1532 if (--setp->refCount == 0)
1533 afs_icl_ZapSet(setp);
1536 ReleaseWriteLock(&afs_icl_lock);
1539 case ICL_OP_SETLOGSIZE: /* set size of log */
1540 /* set the size of the specified log: p1=logname, p2=size (in words) */
1541 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1542 if (code) return code;
1543 logp = afs_icl_FindLog(tname);
1544 if (!logp) return ENOENT;
1545 code = afs_icl_LogSetSize(logp, p2);
1546 afs_icl_LogRele(logp);
1549 case ICL_OP_GETLOGINFO: /* get size of log */
1550 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1551 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1552 if (code) return code;
1553 logp = afs_icl_FindLog(tname);
1554 if (!logp) return ENOENT;
1555 allocated = !!logp->datap;
1556 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1558 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1559 afs_icl_LogRele(logp);
1562 case ICL_OP_GETSETINFO: /* get state of set */
1563 /* zero out the specified set: p1=setname, p2=&state */
1564 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1565 if (code) return code;
1566 setp = afs_icl_FindSet(tname);
1567 if (!setp) return ENOENT;
1568 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1569 afs_icl_SetRele(setp);
1580 afs_lock_t afs_icl_lock;
1582 /* exported routine: a 4 parameter event */
1583 afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, p4)
1584 register struct afs_icl_set *setp;
1587 long p1, p2, p3, p4;
1589 register struct afs_icl_log *logp;
1592 register afs_int32 tmask;
1595 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1596 if (!ICL_SETACTIVE(setp)) return;
1599 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1600 ix = ICL_EVENTBYTE(eventID);
1601 ObtainReadLock(&setp->lock);
1602 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1603 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1605 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1609 if (mask == 0) break; /* break early */
1612 ReleaseReadLock(&setp->lock);
1615 /* Next 4 routines should be implemented via var-args or something.
1616 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1617 * Otherwise, could call afs_icl_Event4 directly.
1619 afs_icl_Event3(setp, eventID, lAndT, p1, p2, p3)
1620 register struct afs_icl_set *setp;
1625 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1628 afs_icl_Event2(setp, eventID, lAndT, p1, p2)
1629 register struct afs_icl_set *setp;
1634 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1637 afs_icl_Event1(setp, eventID, lAndT, p1)
1638 register struct afs_icl_set *setp;
1643 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1646 afs_icl_Event0(setp, eventID, lAndT)
1647 register struct afs_icl_set *setp;
1651 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1654 struct afs_icl_log *afs_icl_allLogs = 0;
1656 /* function to purge records from the start of the log, until there
1657 * is at least minSpace long's worth of space available without
1658 * making the head and the tail point to the same word.
1660 * Log must be write-locked.
1662 static afs_icl_GetLogSpace(logp, minSpace)
1663 register struct afs_icl_log *logp;
1666 register unsigned int tsize;
1668 while (logp->logSize - logp->logElements <= minSpace) {
1670 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1671 logp->logElements -= tsize;
1672 logp->firstUsed += tsize;
1673 if (logp->firstUsed >= logp->logSize)
1674 logp->firstUsed -= logp->logSize;
1675 logp->baseCookie += tsize;
1679 /* append string astr to buffer, including terminating null char.
1681 * log must be write-locked.
1683 #define ICL_CHARSPERLONG 4
1684 static afs_int32 afs_icl_AppendString(logp, astr)
1685 struct afs_icl_log *logp;
1688 char *op; /* ptr to char to write */
1690 register int bib; /* bytes in buffer */
1693 op = (char *) &(logp->datap[logp->firstFree]);
1697 if (++bib >= ICL_CHARSPERLONG) {
1700 if (++(logp->firstFree) >= logp->logSize) {
1701 logp->firstFree = 0;
1702 op = (char *) &(logp->datap[0]);
1704 logp->logElements++;
1709 /* if we've used this word at all, allocate it */
1710 if (++(logp->firstFree) >= logp->logSize) {
1711 logp->firstFree = 0;
1713 logp->logElements++;
1717 /* add a long to the log, ignoring overflow (checked already) */
1718 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1719 #define ICL_APPENDINT32(lp, x) \
1721 (lp)->datap[(lp)->firstFree] = (x); \
1722 if (++((lp)->firstFree) >= (lp)->logSize) { \
1723 (lp)->firstFree = 0; \
1725 (lp)->logElements++; \
1728 #define ICL_APPENDLONG(lp, x) \
1730 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1731 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1734 #else /* AFS_ALPHA_ENV */
1735 #define ICL_APPENDLONG(lp, x) \
1737 (lp)->datap[(lp)->firstFree] = (x); \
1738 if (++((lp)->firstFree) >= (lp)->logSize) { \
1739 (lp)->firstFree = 0; \
1741 (lp)->logElements++; \
1743 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1744 #endif /* AFS_ALPHA_ENV */
1746 /* routine to tell whether we're dealing with the address or the
1749 afs_icl_UseAddr(type)
1752 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1753 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
1759 /* Function to append a record to the log. Written for speed
1760 * since we know that we're going to have to make this work fast
1761 * pretty soon, anyway. The log must be unlocked.
1764 afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4)
1765 register struct afs_icl_log *logp;
1768 long p1, p2, p3, p4;
1770 int rsize; /* record size in longs */
1771 register int tsize; /* temp size */
1775 t4 = types & 0x3f; /* decode types */
1783 osi_GetTime(&tv); /* It panics for solaris if inside */
1784 ObtainWriteLock(&logp->lock,182);
1786 ReleaseWriteLock(&logp->lock);
1790 /* get timestamp as # of microseconds since some time that doesn't
1791 * change that often. This algorithm ticks over every 20 minutes
1792 * or so (1000 seconds). Write a timestamp record if it has.
1794 if (tv.tv_sec - logp->lastTS > 1024)
1796 /* the timer has wrapped -- write a timestamp record */
1797 if (logp->logSize - logp->logElements <= 5)
1798 afs_icl_GetLogSpace(logp, 5);
1800 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1801 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1802 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1803 ICL_APPENDINT32(logp,
1804 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1805 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1807 logp->lastTS = tv.tv_sec;
1810 rsize = 4; /* base case */
1812 /* compute size of parameter p1. Only tricky case is string.
1813 * In that case, we have to call strlen to get the string length.
1815 ICL_SIZEHACK(t1, p1);
1818 /* compute size of parameter p2. Only tricky case is string.
1819 * In that case, we have to call strlen to get the string length.
1821 ICL_SIZEHACK(t2, p2);
1824 /* compute size of parameter p3. Only tricky case is string.
1825 * In that case, we have to call strlen to get the string length.
1827 ICL_SIZEHACK(t3, p3);
1830 /* compute size of parameter p4. Only tricky case is string.
1831 * In that case, we have to call strlen to get the string length.
1833 ICL_SIZEHACK(t4, p4);
1836 /* At this point, we've computed all of the parameter sizes, and
1837 * have in rsize the size of the entire record we want to append.
1838 * Next, we check that we actually have room in the log to do this
1839 * work, and then we do the append.
1842 ReleaseWriteLock(&logp->lock);
1843 return; /* log record too big to express */
1846 if (logp->logSize - logp->logElements <= rsize)
1847 afs_icl_GetLogSpace(logp, rsize);
1849 ICL_APPENDINT32(logp,
1850 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
1851 ICL_APPENDINT32(logp, (afs_int32)op);
1852 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
1853 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1856 /* marshall parameter 1 now */
1857 if (t1 == ICL_TYPE_STRING) {
1858 afs_icl_AppendString(logp, (char *) p1);
1860 else if (t1 == ICL_TYPE_HYPER) {
1861 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
1862 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
1864 else if (t1 == ICL_TYPE_INT64) {
1865 #ifdef AFSLITTLE_ENDIAN
1866 #ifdef AFS_64BIT_CLIENT
1867 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1868 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1869 #else /* AFS_64BIT_CLIENT */
1870 ICL_APPENDINT32(logp, (afs_int32) p1);
1871 ICL_APPENDINT32(logp, (afs_int32) 0);
1872 #endif /* AFS_64BIT_CLIENT */
1873 #else /* AFSLITTLE_ENDIAN */
1874 #ifdef AFS_64BIT_CLIENT
1875 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1876 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1877 #else /* AFS_64BIT_CLIENT */
1878 ICL_APPENDINT32(logp, (afs_int32) 0);
1879 ICL_APPENDINT32(logp, (afs_int32) p1);
1880 #endif /* AFS_64BIT_CLIENT */
1881 #endif /* AFSLITTLE_ENDIAN */
1883 else if (t1 == ICL_TYPE_FID) {
1884 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1885 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1886 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
1887 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
1889 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1890 else if (t1 == ICL_TYPE_INT32)
1891 ICL_APPENDINT32(logp, (afs_int32)p1);
1892 #endif /* AFS_ALPHA_ENV */
1893 else ICL_APPENDLONG(logp, p1);
1896 /* marshall parameter 2 now */
1897 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
1898 else if (t2 == ICL_TYPE_HYPER) {
1899 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
1900 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
1902 else if (t2 == ICL_TYPE_INT64) {
1903 #ifdef AFSLITTLE_ENDIAN
1904 #ifdef AFS_64BIT_CLIENT
1905 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1906 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1907 #else /* AFS_64BIT_CLIENT */
1908 ICL_APPENDINT32(logp, (afs_int32) p2);
1909 ICL_APPENDINT32(logp, (afs_int32) 0);
1910 #endif /* AFS_64BIT_CLIENT */
1911 #else /* AFSLITTLE_ENDIAN */
1912 #ifdef AFS_64BIT_CLIENT
1913 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1914 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1915 #else /* AFS_64BIT_CLIENT */
1916 ICL_APPENDINT32(logp, (afs_int32) 0);
1917 ICL_APPENDINT32(logp, (afs_int32) p2);
1918 #endif /* AFS_64BIT_CLIENT */
1919 #endif /* AFSLITTLE_ENDIAN */
1921 else if (t2 == ICL_TYPE_FID) {
1922 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1923 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1924 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
1925 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
1927 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1928 else if (t2 == ICL_TYPE_INT32)
1929 ICL_APPENDINT32(logp, (afs_int32)p2);
1930 #endif /* AFS_ALPHA_ENV */
1931 else ICL_APPENDLONG(logp, p2);
1934 /* marshall parameter 3 now */
1935 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
1936 else if (t3 == ICL_TYPE_HYPER) {
1937 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
1938 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
1940 else if (t3 == ICL_TYPE_INT64) {
1941 #ifdef AFSLITTLE_ENDIAN
1942 #ifdef AFS_64BIT_CLIENT
1943 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1944 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1945 #else /* AFS_64BIT_CLIENT */
1946 ICL_APPENDINT32(logp, (afs_int32) p3);
1947 ICL_APPENDINT32(logp, (afs_int32) 0);
1948 #endif /* AFS_64BIT_CLIENT */
1949 #else /* AFSLITTLE_ENDIAN */
1950 #ifdef AFS_64BIT_CLIENT
1951 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1952 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1953 #else /* AFS_64BIT_CLIENT */
1954 ICL_APPENDINT32(logp, (afs_int32) 0);
1955 ICL_APPENDINT32(logp, (afs_int32) p3);
1956 #endif /* AFS_64BIT_CLIENT */
1957 #endif /* AFSLITTLE_ENDIAN */
1959 else if (t3 == ICL_TYPE_FID) {
1960 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1961 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1962 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
1963 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
1965 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1966 else if (t3 == ICL_TYPE_INT32)
1967 ICL_APPENDINT32(logp, (afs_int32)p3);
1968 #endif /* AFS_ALPHA_ENV */
1969 else ICL_APPENDLONG(logp, p3);
1972 /* marshall parameter 4 now */
1973 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
1974 else if (t4 == ICL_TYPE_HYPER) {
1975 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
1976 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
1978 else if (t4 == ICL_TYPE_INT64) {
1979 #ifdef AFSLITTLE_ENDIAN
1980 #ifdef AFS_64BIT_CLIENT
1981 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
1982 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
1983 #else /* AFS_64BIT_CLIENT */
1984 ICL_APPENDINT32(logp, (afs_int32) p4);
1985 ICL_APPENDINT32(logp, (afs_int32) 0);
1986 #endif /* AFS_64BIT_CLIENT */
1987 #else /* AFSLITTLE_ENDIAN */
1988 #ifdef AFS_64BIT_CLIENT
1989 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
1990 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
1991 #else /* AFS_64BIT_CLIENT */
1992 ICL_APPENDINT32(logp, (afs_int32) 0);
1993 ICL_APPENDINT32(logp, (afs_int32) p4);
1994 #endif /* AFS_64BIT_CLIENT */
1995 #endif /* AFSLITTLE_ENDIAN */
1997 else if (t4 == ICL_TYPE_FID) {
1998 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
1999 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2000 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
2001 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
2003 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2004 else if (t4 == ICL_TYPE_INT32)
2005 ICL_APPENDINT32(logp, (afs_int32)p4);
2006 #endif /* AFS_ALPHA_ENV */
2007 else ICL_APPENDLONG(logp, p4);
2009 ReleaseWriteLock(&logp->lock);
2012 /* create a log with size logSize; return it in *outLogpp and tag
2013 * it with name "name."
2015 afs_icl_CreateLog(name, logSize, outLogpp)
2018 struct afs_icl_log **outLogpp;
2020 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
2023 /* create a log with size logSize; return it in *outLogpp and tag
2024 * it with name "name." 'flags' can be set to make the log unclearable.
2026 afs_icl_CreateLogWithFlags(name, logSize, flags, outLogpp)
2030 struct afs_icl_log **outLogpp;
2032 register struct afs_icl_log *logp;
2034 /* add into global list under lock */
2035 ObtainWriteLock(&afs_icl_lock,183);
2036 if (!afs_icl_inited) afs_icl_Init();
2038 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
2039 if (strcmp(logp->name, name) == 0) {
2040 /* found it already created, just return it */
2043 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2045 ObtainWriteLock(&logp->lock,184);
2046 logp->states |= ICL_LOGF_PERSISTENT;
2047 ReleaseWriteLock(&logp->lock);
2049 ReleaseWriteLock(&afs_icl_lock);
2054 logp = (struct afs_icl_log *)
2055 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
2056 memset((caddr_t)logp, 0, sizeof(*logp));
2059 logp->name = osi_AllocSmallSpace(strlen(name)+1);
2060 strcpy(logp->name, name);
2061 LOCK_INIT(&logp->lock, "logp lock");
2062 logp->logSize = logSize;
2063 logp->datap = (afs_int32 *)0; /* don't allocate it until we need it */
2065 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2066 logp->states |= ICL_LOGF_PERSISTENT;
2068 logp->nextp = afs_icl_allLogs;
2069 afs_icl_allLogs = logp;
2070 ReleaseWriteLock(&afs_icl_lock);
2076 /* called with a log, a pointer to a buffer, the size of the buffer
2077 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
2078 * and returns data in the provided buffer, and returns output flags
2079 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
2080 * find the record with cookie value cookie.
2082 afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp)
2083 register struct afs_icl_log *logp;
2085 afs_int32 *bufSizep;
2086 afs_uint32 *cookiep;
2089 afs_int32 nwords; /* number of words to copy out */
2090 afs_uint32 startCookie; /* first cookie to use */
2091 register afs_int32 i;
2092 afs_int32 outWords; /* words we've copied out */
2093 afs_int32 inWords; /* max words to copy out */
2094 afs_int32 code; /* return code */
2095 afs_int32 ix; /* index we're copying from */
2096 afs_int32 outFlags; /* return flags */
2097 afs_int32 inFlags; /* flags passed in */
2100 inWords = *bufSizep; /* max to copy out */
2101 outWords = 0; /* amount copied out */
2102 startCookie = *cookiep;
2107 ObtainWriteLock(&logp->lock,185);
2109 ReleaseWriteLock(&logp->lock);
2113 /* first, compute the index of the start cookie we've been passed */
2115 /* (re-)compute where we should start */
2116 if (startCookie < logp->baseCookie) {
2117 if (startCookie) /* missed some output */
2118 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2119 /* skip to the first available record */
2120 startCookie = logp->baseCookie;
2121 *cookiep = startCookie;
2124 /* compute where we find the first element to copy out */
2125 ix = logp->firstUsed + startCookie - logp->baseCookie;
2126 if (ix >= logp->logSize) ix -= logp->logSize;
2128 /* if have some data now, break out and process it */
2129 if (startCookie - logp->baseCookie < logp->logElements) break;
2131 /* At end of log, so clear it if we need to */
2132 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
2134 logp->firstUsed = logp->firstFree = 0;
2135 logp->logElements = 0;
2137 /* otherwise, either wait for the data to arrive, or return */
2138 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2139 ReleaseWriteLock(&logp->lock);
2143 logp->states |= ICL_LOGF_WAITING;
2144 ReleaseWriteLock(&logp->lock);
2145 afs_osi_Sleep(&logp->lock);
2146 ObtainWriteLock(&logp->lock,186);
2148 /* copy out data from ix to logSize or firstFree, depending
2149 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2150 * be careful not to copy out more than nwords.
2152 if (ix >= logp->firstUsed) {
2153 if (logp->firstUsed <= logp->firstFree)
2155 end = logp->firstFree; /* first element not to copy */
2157 end = logp->logSize;
2158 nwords = inWords; /* don't copy more than this */
2159 if (end - ix < nwords)
2162 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2167 /* if we're going to copy more out below, we'll start here */
2170 /* now, if active part of the log has wrapped, there's more stuff
2171 * starting at the head of the log. Copy out more from there.
2173 if (logp->firstUsed > logp->firstFree
2174 && ix < logp->firstFree && inWords > 0) {
2175 /* (more to) copy out from the wrapped section at the
2176 * start of the log. May get here even if didn't copy any
2177 * above, if the cookie points directly into the wrapped section.
2180 if (logp->firstFree - ix < nwords)
2181 nwords = logp->firstFree - ix;
2182 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2188 ReleaseWriteLock(&logp->lock);
2192 *bufSizep = outWords;
2198 /* return basic parameter information about a log */
2199 afs_icl_GetLogParms(logp, maxSizep, curSizep)
2200 struct afs_icl_log *logp;
2201 afs_int32 *maxSizep;
2202 afs_int32 *curSizep;
2204 ObtainReadLock(&logp->lock);
2205 *maxSizep = logp->logSize;
2206 *curSizep = logp->logElements;
2207 ReleaseReadLock(&logp->lock);
2212 /* hold and release logs */
2213 afs_icl_LogHold(logp)
2214 register struct afs_icl_log *logp;
2216 ObtainWriteLock(&afs_icl_lock,187);
2218 ReleaseWriteLock(&afs_icl_lock);
2222 /* hold and release logs, called with lock already held */
2223 afs_icl_LogHoldNL(logp)
2224 register struct afs_icl_log *logp;
2230 /* keep track of how many sets believe the log itself is allocated */
2231 afs_icl_LogUse(logp)
2232 register struct afs_icl_log *logp;
2234 ObtainWriteLock(&logp->lock,188);
2235 if (logp->setCount == 0) {
2236 /* this is the first set actually using the log -- allocate it */
2237 if (logp->logSize == 0) {
2238 /* we weren't passed in a hint and it wasn't set */
2239 logp->logSize = ICL_DEFAULT_LOGSIZE;
2241 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2242 #ifdef AFS_AIX32_ENV
2243 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2247 ReleaseWriteLock(&logp->lock);
2251 /* decrement the number of real users of the log, free if possible */
2252 afs_icl_LogFreeUse(logp)
2253 register struct afs_icl_log *logp;
2255 ObtainWriteLock(&logp->lock,189);
2256 if (--logp->setCount == 0) {
2257 /* no more users -- free it (but keep log structure around)*/
2258 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2259 #ifdef AFS_AIX32_ENV
2260 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2262 logp->firstUsed = logp->firstFree = 0;
2263 logp->logElements = 0;
2264 logp->datap = (afs_int32 *)0;
2266 ReleaseWriteLock(&logp->lock);
2270 /* set the size of the log to 'logSize' */
2271 afs_icl_LogSetSize(logp, logSize)
2272 register struct afs_icl_log *logp;
2275 ObtainWriteLock(&logp->lock,190);
2277 /* nothing to worry about since it's not allocated */
2278 logp->logSize = logSize;
2282 logp->firstUsed = logp->firstFree = 0;
2283 logp->logElements = 0;
2285 /* free and allocate a new one */
2286 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2287 #ifdef AFS_AIX32_ENV
2288 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2290 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2291 #ifdef AFS_AIX32_ENV
2292 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2294 logp->logSize = logSize;
2296 ReleaseWriteLock(&logp->lock);
2301 /* free a log. Called with afs_icl_lock locked. */
2302 afs_icl_ZapLog(logp)
2303 register struct afs_icl_log *logp;
2305 register struct afs_icl_log **lpp, *tp;
2307 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2309 /* found the dude we want to remove */
2311 osi_FreeSmallSpace(logp->name);
2312 osi_FreeSmallSpace(logp->datap);
2313 osi_FreeSmallSpace(logp);
2314 break; /* won't find it twice */
2320 /* do the release, watching for deleted entries */
2321 afs_icl_LogRele(logp)
2322 register struct afs_icl_log *logp;
2324 ObtainWriteLock(&afs_icl_lock,191);
2325 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2326 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2328 ReleaseWriteLock(&afs_icl_lock);
2332 /* do the release, watching for deleted entries, log already held */
2333 afs_icl_LogReleNL(logp)
2334 register struct afs_icl_log *logp;
2336 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2337 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2342 /* zero out the log */
2343 afs_icl_ZeroLog(logp)
2344 register struct afs_icl_log *logp;
2346 ObtainWriteLock(&logp->lock,192);
2347 logp->firstUsed = logp->firstFree = 0;
2348 logp->logElements = 0;
2349 logp->baseCookie = 0;
2350 ReleaseWriteLock(&logp->lock);
2354 /* free a log entry, and drop its reference count */
2355 afs_icl_LogFree(logp)
2356 register struct afs_icl_log *logp;
2358 ObtainWriteLock(&logp->lock,193);
2359 logp->states |= ICL_LOGF_DELETED;
2360 ReleaseWriteLock(&logp->lock);
2361 afs_icl_LogRele(logp);
2365 /* find a log by name, returning it held */
2366 struct afs_icl_log *afs_icl_FindLog(name)
2369 register struct afs_icl_log *tp;
2370 ObtainWriteLock(&afs_icl_lock,194);
2371 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2372 if (strcmp(tp->name, name) == 0) {
2373 /* this is the dude we want */
2378 ReleaseWriteLock(&afs_icl_lock);
2382 afs_icl_EnumerateLogs(aproc, arock)
2386 register struct afs_icl_log *tp;
2387 register afs_int32 code;
2390 ObtainWriteLock(&afs_icl_lock,195);
2391 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2392 tp->refCount++; /* hold this guy */
2393 ReleaseWriteLock(&afs_icl_lock);
2394 ObtainReadLock(&tp->lock);
2395 code = (*aproc)(tp->name, arock, tp);
2396 ReleaseReadLock(&tp->lock);
2397 ObtainWriteLock(&afs_icl_lock,196);
2398 if (--tp->refCount == 0)
2402 ReleaseWriteLock(&afs_icl_lock);
2406 struct afs_icl_set *afs_icl_allSets = 0;
2408 afs_icl_CreateSet(name, baseLogp, fatalLogp, outSetpp)
2410 struct afs_icl_log *baseLogp;
2411 struct afs_icl_log *fatalLogp;
2412 struct afs_icl_set **outSetpp;
2414 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2415 /*flags*/0, outSetpp);
2418 /* create a set, given pointers to base and fatal logs, if any.
2419 * Logs are unlocked, but referenced, and *outSetpp is returned
2420 * referenced. Function bumps reference count on logs, since it
2421 * addds references from the new afs_icl_set. When the set is destroyed,
2422 * those references will be released.
2424 afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp)
2426 struct afs_icl_log *baseLogp;
2427 struct afs_icl_log *fatalLogp;
2429 struct afs_icl_set **outSetpp;
2431 register struct afs_icl_set *setp;
2433 afs_int32 states = ICL_DEFAULT_SET_STATES;
2435 ObtainWriteLock(&afs_icl_lock,197);
2436 if (!afs_icl_inited) afs_icl_Init();
2438 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2439 if (strcmp(setp->name, name) == 0) {
2442 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2444 ObtainWriteLock(&setp->lock,198);
2445 setp->states |= ICL_SETF_PERSISTENT;
2446 ReleaseWriteLock(&setp->lock);
2448 ReleaseWriteLock(&afs_icl_lock);
2453 /* determine initial state */
2454 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2455 states = ICL_SETF_ACTIVE;
2456 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2457 states = ICL_SETF_FREED;
2458 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2459 states |= ICL_SETF_PERSISTENT;
2461 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2462 memset((caddr_t)setp, 0, sizeof(*setp));
2464 if (states & ICL_SETF_FREED)
2465 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2466 setp->states = states;
2468 LOCK_INIT(&setp->lock, "setp lock");
2469 /* next lock is obtained in wrong order, hierarchy-wise, but
2470 * it doesn't matter, since no one can find this lock yet, since
2471 * the afs_icl_lock is still held, and thus the obtain can't block.
2473 ObtainWriteLock(&setp->lock,199);
2474 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2475 strcpy(setp->name, name);
2476 setp->nevents = ICL_DEFAULTEVENTS;
2477 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2478 #ifdef AFS_AIX32_ENV
2479 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2481 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2482 setp->eventFlags[i] = 0xff; /* default to enabled */
2484 /* update this global info under the afs_icl_lock */
2485 setp->nextp = afs_icl_allSets;
2486 afs_icl_allSets = setp;
2487 ReleaseWriteLock(&afs_icl_lock);
2489 /* set's basic lock is still held, so we can finish init */
2491 setp->logs[0] = baseLogp;
2492 afs_icl_LogHold(baseLogp);
2493 if (!(setp->states & ICL_SETF_FREED))
2494 afs_icl_LogUse(baseLogp); /* log is actually being used */
2497 setp->logs[1] = fatalLogp;
2498 afs_icl_LogHold(fatalLogp);
2499 if (!(setp->states & ICL_SETF_FREED))
2500 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2502 ReleaseWriteLock(&setp->lock);
2508 /* function to change event enabling information for a particular set */
2509 afs_icl_SetEnable(setp, eventID, setValue)
2510 struct afs_icl_set *setp;
2516 ObtainWriteLock(&setp->lock,200);
2517 if (!ICL_EVENTOK(setp, eventID)) {
2518 ReleaseWriteLock(&setp->lock);
2521 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2523 *tp |= ICL_EVENTMASK(eventID);
2525 *tp &= ~(ICL_EVENTMASK(eventID));
2526 ReleaseWriteLock(&setp->lock);
2530 /* return indication of whether a particular event ID is enabled
2531 * for tracing. If *getValuep is set to 0, the event is disabled,
2532 * otherwise it is enabled. All events start out enabled by default.
2534 afs_icl_GetEnable(setp, eventID, getValuep)
2535 struct afs_icl_set *setp;
2539 ObtainReadLock(&setp->lock);
2540 if (!ICL_EVENTOK(setp, eventID)) {
2541 ReleaseWriteLock(&setp->lock);
2544 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2548 ReleaseReadLock(&setp->lock);
2552 /* hold and release event sets */
2553 afs_icl_SetHold(setp)
2554 register struct afs_icl_set *setp;
2556 ObtainWriteLock(&afs_icl_lock,201);
2558 ReleaseWriteLock(&afs_icl_lock);
2562 /* free a set. Called with afs_icl_lock locked */
2563 afs_icl_ZapSet(setp)
2564 register struct afs_icl_set *setp;
2566 register struct afs_icl_set **lpp, *tp;
2568 register struct afs_icl_log *tlp;
2570 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2572 /* found the dude we want to remove */
2574 osi_FreeSmallSpace(setp->name);
2575 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2576 #ifdef AFS_AIX32_ENV
2577 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2579 for(i=0; i < ICL_LOGSPERSET; i++) {
2580 if (tlp = setp->logs[i])
2581 afs_icl_LogReleNL(tlp);
2583 osi_FreeSmallSpace(setp);
2584 break; /* won't find it twice */
2590 /* do the release, watching for deleted entries */
2591 afs_icl_SetRele(setp)
2592 register struct afs_icl_set *setp;
2594 ObtainWriteLock(&afs_icl_lock,202);
2595 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2596 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2598 ReleaseWriteLock(&afs_icl_lock);
2602 /* free a set entry, dropping its reference count */
2603 afs_icl_SetFree(setp)
2604 register struct afs_icl_set *setp;
2606 ObtainWriteLock(&setp->lock,203);
2607 setp->states |= ICL_SETF_DELETED;
2608 ReleaseWriteLock(&setp->lock);
2609 afs_icl_SetRele(setp);
2613 /* find a set by name, returning it held */
2614 struct afs_icl_set *afs_icl_FindSet(name)
2617 register struct afs_icl_set *tp;
2618 ObtainWriteLock(&afs_icl_lock,204);
2619 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2620 if (strcmp(tp->name, name) == 0) {
2621 /* this is the dude we want */
2626 ReleaseWriteLock(&afs_icl_lock);
2630 /* zero out all the logs in the set */
2631 afs_icl_ZeroSet(setp)
2632 struct afs_icl_set *setp;
2637 struct afs_icl_log *logp;
2639 ObtainReadLock(&setp->lock);
2640 for(i = 0; i < ICL_LOGSPERSET; i++) {
2641 logp = setp->logs[i];
2643 afs_icl_LogHold(logp);
2644 tcode = afs_icl_ZeroLog(logp);
2645 if (tcode != 0) code = tcode; /* save the last bad one */
2646 afs_icl_LogRele(logp);
2649 ReleaseReadLock(&setp->lock);
2653 afs_icl_EnumerateSets(aproc, arock)
2657 register struct afs_icl_set *tp, *np;
2658 register afs_int32 code;
2661 ObtainWriteLock(&afs_icl_lock,205);
2662 for(tp = afs_icl_allSets; tp; tp=np) {
2663 tp->refCount++; /* hold this guy */
2664 ReleaseWriteLock(&afs_icl_lock);
2665 code = (*aproc)(tp->name, arock, tp);
2666 ObtainWriteLock(&afs_icl_lock,206);
2667 np = tp->nextp; /* tp may disappear next, but not np */
2668 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2672 ReleaseWriteLock(&afs_icl_lock);
2676 afs_icl_AddLogToSet(setp, newlogp)
2677 struct afs_icl_set *setp;
2678 struct afs_icl_log *newlogp;
2682 struct afs_icl_log *logp;
2684 ObtainWriteLock(&setp->lock,207);
2685 for(i = 0; i < ICL_LOGSPERSET; i++) {
2686 if (!setp->logs[i]) {
2687 setp->logs[i] = newlogp;
2689 afs_icl_LogHold(newlogp);
2690 if (!(setp->states & ICL_SETF_FREED)) {
2691 /* bump up the number of sets using the log */
2692 afs_icl_LogUse(newlogp);
2697 ReleaseWriteLock(&setp->lock);
2701 afs_icl_SetSetStat(setp, op)
2702 struct afs_icl_set *setp;
2707 struct afs_icl_log *logp;
2709 ObtainWriteLock(&setp->lock,208);
2711 case ICL_OP_SS_ACTIVATE: /* activate a log */
2713 * If we are not already active, see if we have released
2714 * our demand that the log be allocated (FREED set). If
2715 * we have, reassert our desire.
2717 if (!(setp->states & ICL_SETF_ACTIVE)) {
2718 if (setp->states & ICL_SETF_FREED) {
2719 /* have to reassert desire for logs */
2720 for(i = 0; i < ICL_LOGSPERSET; i++) {
2721 logp = setp->logs[i];
2723 afs_icl_LogHold(logp);
2724 afs_icl_LogUse(logp);
2725 afs_icl_LogRele(logp);
2728 setp->states &= ~ICL_SETF_FREED;
2730 setp->states |= ICL_SETF_ACTIVE;
2735 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2736 /* this doesn't require anything beyond clearing the ACTIVE flag */
2737 setp->states &= ~ICL_SETF_ACTIVE;
2741 case ICL_OP_SS_FREE: /* deassert design for log */
2743 * if we are already in this state, do nothing; otherwise
2744 * deassert desire for log
2746 if (setp->states & ICL_SETF_ACTIVE)
2749 if (!(setp->states & ICL_SETF_FREED)) {
2750 for(i = 0; i < ICL_LOGSPERSET; i++) {
2751 logp = setp->logs[i];
2753 afs_icl_LogHold(logp);
2754 afs_icl_LogFreeUse(logp);
2755 afs_icl_LogRele(logp);
2758 setp->states |= ICL_SETF_FREED;
2767 ReleaseWriteLock(&setp->lock);