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) && !defined(AFS_DARWIN60_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 /* leaving as is, probably will barf if we add prototypes here since it's likely being called
129 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
130 long parm, parm2, parm3, parm4, parm5, parm6;
134 AFS_STATCNT(afs_syscall_call);
136 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
137 && (parm != AFSOP_GETMASK)) {
138 /* only root can run this code */
141 if (!afs_suser() && (parm != AFSOP_GETMTU)
142 && (parm != AFSOP_GETMASK)) {
143 /* only root can run this code */
144 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
148 #if defined(AFS_OSF_ENV)
150 #else /* AFS_OSF_ENV */
157 if (parm == AFSOP_START_RXCALLBACK) {
158 if (afs_CB_Running) goto out;
160 #ifndef RXK_LISTENER_ENV
161 code = afs_InitSetup(parm2);
163 #endif /* RXK_LISTENER_ENV */
165 #ifdef RXK_LISTENER_ENV
166 while (afs_RX_Running != 2)
167 afs_osi_Sleep(&afs_RX_Running);
169 afs_initState = AFSOP_START_AFS;
170 afs_osi_Wakeup(&afs_initState);
171 #endif /* RXK_LISTENER_ENV */
173 afs_RXCallBackServer();
177 exit(CLD_EXITED, code);
180 #ifdef RXK_LISTENER_ENV
181 else if (parm == AFSOP_RXLISTENER_DAEMON) {
182 if (afs_RX_Running) goto out;
184 code = afs_InitSetup(parm2);
186 rx_enablePeerRPCStats();
189 rx_enableProcessRPCStats();
192 afs_initState = AFSOP_START_AFS;
193 afs_osi_Wakeup(&afs_initState);
196 afs_osi_Wakeup(&afs_RX_Running);
198 afs_osi_RxkRegister();
204 exit(CLD_EXITED, code);
208 else if (parm == AFSOP_START_AFS) {
212 if (AFS_Running) goto out;
214 while (afs_initState < AFSOP_START_AFS)
215 afs_osi_Sleep(&afs_initState);
217 #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)
218 temp = AFS_MINBUFFERS; /* Should fix this soon */
220 temp = ((afs_bufferpages * NBPG)>>11); /* number of 2k buffers we could get from all of the buffer space */
221 temp = temp>>2; /* don't take more than 25% (our magic parameter) */
222 if (temp < AFS_MINBUFFERS) temp = AFS_MINBUFFERS; /* although we really should have this many */
225 afs_initState = AFSOP_START_BKG;
226 afs_osi_Wakeup(&afs_initState);
234 else if (parm == AFSOP_START_CS) {
236 afs_CheckServerDaemon();
242 else if (parm == AFSOP_START_BKG) {
243 while (afs_initState < AFSOP_START_BKG)
244 afs_osi_Sleep(&afs_initState);
245 if (afs_initState < AFSOP_GO) {
246 afs_initState = AFSOP_GO;
247 afs_osi_Wakeup(&afs_initState);
249 /* start the bkg daemon */
253 afs_BioDaemon(parm2);
256 afs_BackgroundDaemon();
262 else if (parm == AFSOP_START_TRUNCDAEMON) {
263 while (afs_initState < AFSOP_GO)
264 afs_osi_Sleep(&afs_initState);
265 /* start the bkg daemon */
267 afs_CacheTruncateDaemon();
273 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
274 else if (parm == AFSOP_RXEVENT_DAEMON) {
275 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
277 afs_rxevent_daemon();
284 else if (parm == AFSOP_ADDCELL) {
285 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
286 name. Parameter 4 is the length of the name, including the null. Parm 5 is the
287 home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
288 struct afsop_cell tcell;
290 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
291 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
293 if (parm4 > sizeof(tcell.cellName))
296 AFS_COPYIN((char *)parm3, tcell.cellName, parm4, code);
298 afs_NewCell(tcell.cellName, tcell.hosts, parm5,
302 } else if (parm == AFSOP_ADDCELL2) {
303 struct afsop_cell tcell;
304 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
305 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *cnamep = 0;
306 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
308 #else /* AFS_SGI61_ENV */
310 #endif /* AFS_SGI61_ENV */
313 /* wait for basic init */
314 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
316 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
318 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, &bufferSize, code);
321 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
324 cflags |= CLinkedCell;
328 afs_NewCell(tbuffer1, tcell.hosts, cflags,
329 lcnamep, 0, 0, 0, 0);
332 osi_FreeSmallSpace(tbuffer);
333 osi_FreeSmallSpace(tbuffer1);
335 else if (parm == AFSOP_ADDCELLALIAS) {
338 * parm2 is the alias name
339 * parm3 is the real cell name
341 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
343 #else /* AFS_SGI61_ENV */
345 #endif /* AFS_SGI61_ENV */
346 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
347 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
349 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize, code);
350 if (!code) AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ, &bufferSize, code);
351 if (!code) afs_NewCell(aliasName, /* new entry name */
354 NULL, /* linked cell */
355 0, 0, /* fs & vl ports */
357 cellName); /* real cell name */
359 osi_FreeSmallSpace(aliasName);
360 osi_FreeSmallSpace(cellName);
362 else if (parm == AFSOP_CACHEINIT) {
363 struct afs_cacheParams cparms;
365 if (afs_CacheInit_Done) goto out;
367 /* wait for basic init */
368 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
369 AFS_COPYIN((char *)parm2, (caddr_t) &cparms, sizeof(cparms), code);
371 #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)
379 afs_CacheInit_Done = 1;
381 struct afs_icl_log *logp;
382 /* initialize the ICL system */
383 code = afs_icl_CreateLog("cmfx", 60*1024, &logp);
385 code = afs_icl_CreateSetWithFlags("cm", logp,
386 (struct icl_log *) 0,
387 ICL_CRSET_FLAG_DEFAULT_OFF,
389 code = afs_icl_CreateSet("cmlongterm", logp, (struct icl_log*) 0,
390 &afs_iclLongTermSetp);
392 afs_setTime = cparms.setTimeFlag;
394 code = afs_CacheInit(cparms.cacheScaches,
405 else if (parm == AFSOP_CACHEINODE) {
406 ino_t ainode = parm2;
407 /* wait for basic init */
408 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
412 ainode = (ainode << 32) | (parm3 & 0xffffffff);
414 code = afs_InitCacheFile(NULL, ainode);
416 else if (parm == AFSOP_ROOTVOLUME) {
417 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
419 #else /* AFS_SGI61_ENV */
421 #endif /* AFS_SGI61_ENV */
423 /* wait for basic init */
424 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
427 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code);
428 afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0;
432 else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO ||
433 parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG) {
434 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
435 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
437 #else /* AFS_SGI61_ENV */
439 #endif /* AFS_SGI61_ENV */
441 /* wait for basic init */
442 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
444 AFS_COPYINSTR((char *)parm2, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
446 osi_FreeSmallSpace(tbuffer);
450 tbuffer[AFS_SMALLOCSIZ-1] = 0; /* null-terminate the name */
451 /* we now have the cache dir copied in. Call the cache init routines */
452 if (parm == AFSOP_CACHEFILE) code = afs_InitCacheFile(tbuffer, 0);
453 else if (parm == AFSOP_CACHEINFO) code = afs_InitCacheInfo(tbuffer);
454 else if (parm == AFSOP_VOLUMEINFO) code = afs_InitVolumeInfo(tbuffer);
456 osi_FreeSmallSpace(tbuffer);
458 else if (parm == AFSOP_GO) {
459 /* the generic initialization calls come here. One parameter: should we do the
460 set-time operation on this workstation */
461 if (afs_Go_Done) goto out;
463 while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState);
466 afs_osi_Wakeup(&afs_initState);
467 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
468 afs_nfsclient_init();
470 printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused,
471 (100*afs_stats_cmperf.cacheFilesReused) /
472 (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1));
474 else if (parm == AFSOP_ADVISEADDR) {
475 /* pass in the host address to the rx package */
476 afs_int32 count = parm2;
477 afs_int32 buffer[AFS_MAX_INTERFACE_ADDR];
478 afs_int32 maskbuffer[AFS_MAX_INTERFACE_ADDR];
479 afs_int32 mtubuffer[AFS_MAX_INTERFACE_ADDR];
483 if ( count > AFS_MAX_INTERFACE_ADDR ) {
485 count = AFS_MAX_INTERFACE_ADDR;
488 AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code);
490 AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code);
492 AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code);
494 afs_cb_interface.numberOfInterfaces = count;
495 for (i=0; i < count ; i++) {
496 afs_cb_interface.addr_in[i] = buffer[i];
497 #ifdef AFS_USERSPACE_IP_ADDR
498 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
499 * machines IP addresses when in the kernel (the in_ifaddr
500 * struct is not available), so we pass the info in at
501 * startup. We also pass in the subnetmask and mtu size. The
502 * subnetmask is used when setting the rank:
503 * afsi_SetServerIPRank(); and the mtu size is used when
504 * finding the best mtu size. rxi_FindIfnet() is replaced
505 * with rxi_Findcbi().
507 afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff);
508 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
511 afs_uuid_create(&afs_cb_interface.uuid);
512 rxi_setaddr(buffer[0]);
516 else if (parm == AFSOP_NFSSTATICADDR) {
517 extern int (*nfs_rfsdisptab_v2)();
518 nfs_rfsdisptab_v2 = (int (*)())parm2;
520 else if (parm == AFSOP_NFSSTATICADDR2) {
521 extern int (*nfs_rfsdisptab_v2)();
523 nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
525 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
528 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
529 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
530 extern int (*afs_sblockp)();
531 extern void (*afs_sbunlockp)();
533 afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
534 afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff));
536 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
537 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
540 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
541 #endif /* AFS_SGI53_ENV */
542 else if (parm == AFSOP_SHUTDOWN) {
543 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
544 extern struct mount *afs_globalVFS;
545 #else /* AFS_OSF_ENV */
546 extern struct vfs *afs_globalVFS;
548 afs_cold_shutdown = 0;
549 if (parm == 1) afs_cold_shutdown = 1;
550 if (afs_globalVFS != 0) {
551 afs_warn("AFS isn't unmounted yet! Call aborted\n");
557 #if ! defined(AFS_HPUX90_ENV) || defined(AFS_HPUX100_ENV)
558 else if (parm == AFSOP_AFS_VFSMOUNT) {
560 #if defined(AFS_HPUX100_ENV)
561 vfsmount(parm2, parm3, parm4, parm5);
563 afs_vfs_mount(parm2, parm3, parm4, parm5);
564 #endif /* AFS_HPUX100_ENV */
565 #else /* defined(AFS_HPUX_ENV) */
566 #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)
571 #endif /* defined(AFS_HPUX_ENV) */
574 else if (parm == AFSOP_CLOSEWAIT) {
575 afs_SynchronousCloses = 'S';
577 else if (parm == AFSOP_GETMTU) {
579 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
580 #ifdef AFS_USERSPACE_IP_ADDR
582 i = rxi_Findcbi(parm2);
583 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
584 #else /* AFS_USERSPACE_IP_ADDR */
586 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
587 extern struct ifnet *rxi_FindIfnet();
589 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
590 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
591 #endif /* else AFS_USERSPACE_IP_ADDR */
592 #endif /* !AFS_SUN5_ENV */
594 AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code);
596 /* this is disabled for now because I can't figure out how to get access
597 * to these kernel variables. It's only for supporting user-mode rx
598 * programs -- it makes a huge difference on the 220's in my testbed,
599 * though I don't know why. The bosserver does this with /etc/no, so it's
600 * being handled a different way for the servers right now. */
603 extern u_long sb_max_dflt;
606 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
607 if (sb_max < 131072) sb_max = 131072;
610 #endif /* AFS_AIX32_ENV */
612 else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
614 #if !defined(AFS_SUN5_ENV)
615 #ifdef AFS_USERSPACE_IP_ADDR
617 i = rxi_Findcbi(parm2);
619 mask = afs_cb_interface.subnetmask[i];
623 #else /* AFS_USERSPACE_IP_ADDR */
625 #ifdef AFS_DARWIN60_ENV
626 struct ifaddr *tifadp = (struct ifaddr *) 0;
628 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
630 extern struct ifnet *rxi_FindIfnet();
631 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
632 if (tifnp && tifadp) {
633 #ifdef AFS_DARWIN60_ENV
634 mask = ((struct sockaddr_in *)tifadp->ifa_netmask)->sin_addr.s_addr;
636 mask = tifadp->ia_subnetmask;
641 #endif /* else AFS_USERSPACE_IP_ADDR */
642 #endif /* !AFS_SUN5_ENV */
644 AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code);
647 else if (parm == AFSOP_AFSDB_HANDLER) {
648 int sizeArg = (int)parm4;
649 int kmsgLen = sizeArg & 0xffff;
650 int cellLen = (sizeArg & 0xffff0000) >> 16;
651 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
652 char *cellname = afs_osi_Alloc(cellLen);
655 afs_osi_MaskSignals();
657 AFS_COPYIN((afs_int32 *)parm2, cellname, cellLen, code);
658 AFS_COPYIN((afs_int32 *)parm3, kmsg, kmsgLen, code);
660 code = afs_AfsdbHandler(cellname, cellLen, kmsg);
661 if (*cellname == 1) *cellname = 0;
662 if (code == -2) { /* Shutting down? */
667 if (!code) AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
668 afs_osi_Free(kmsg, kmsgLen);
669 afs_osi_Free(cellname, cellLen);
672 else if (parm == AFSOP_SET_DYNROOT) {
673 code = afs_SetDynrootEnable(parm2);
675 else if (parm == AFSOP_SET_FAKESTAT) {
676 afs_fakestat_enable = parm2;
684 #ifdef AFS_LINUX20_ENV
693 #include "sys/lockl.h"
696 * syscall - this is the VRMIX system call entry point.
699 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
700 * all the user-level calls to `syscall' to change.
702 syscall(syscall, p1, p2, p3, p4, p5, p6) {
703 register rval1=0, code;
706 #ifndef AFS_AIX41_ENV
707 extern lock_t kernel_lock;
708 monster = lockl(&kernel_lock, LOCK_SHORT);
709 #endif /* !AFS_AIX41_ENV */
711 AFS_STATCNT(syscall);
715 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
720 rval1 = afs_setpag();
726 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
730 case AFSCALL_ICREATE:
731 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
735 rval1 = afs_syscall_iopen(p1, p2, p3);
739 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
743 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
748 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
750 if (!code) rval1 = retval;
751 if (!rval1) rval1 = code;
761 #ifndef AFS_AIX41_ENV
762 if (monster != LOCK_NEST)
763 unlockl(&kernel_lock);
764 #endif /* !AFS_AIX41_ENV */
765 return getuerror() ? -1 : rval1;
769 * lsetpag - interface to afs_setpag().
773 AFS_STATCNT(lsetpag);
774 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
778 * lpioctl - interface to pioctl()
780 lpioctl(path, cmd, cmarg, follow)
781 char *path, *cmarg; {
783 AFS_STATCNT(lpioctl);
784 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
787 #else /* !AFS_AIX32_ENV */
789 #if defined(AFS_SGI_ENV)
802 Afs_syscall (struct afsargs *uap, rval_t *rvp)
807 AFS_STATCNT(afs_syscall);
808 switch(uap->syscall) {
812 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
814 rvp->r_val1 = retval;
816 #ifdef AFS_SGI_XFS_IOPS_ENV
818 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
819 uap->parm4, uap->parm5);
822 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
823 uap->parm4, uap->parm5);
825 case AFSCALL_ILISTINODE64:
826 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
827 uap->parm4, uap->parm5);
829 case AFSCALL_ICREATENAME64:
830 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
831 uap->parm4, uap->parm5);
834 #ifdef AFS_SGI_VNODE_GLUE
835 case AFSCALL_INIT_KERNEL_CONFIG:
836 error = afs_init_kernel_config(uap->parm1);
840 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
841 uap->parm3, uap->parm4, uap->parm5);
846 #else /* AFS_SGI_ENV */
864 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
866 dst->param1 = src->param1;
867 dst->param2 = src->param2;
868 dst->param3 = src->param3;
869 dst->param4 = src->param4;
873 * If you need to change copyin_iparam(), you may also need to change
874 * copyin_afs_ioctl().
878 copyin_iparam(caddr_t cmarg, struct iparam *dst)
882 #if defined(AFS_HPUX_64BIT_ENV)
883 struct iparam32 dst32;
885 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
887 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
889 iparam32_to_iparam(&dst32, dst);
892 #endif /* AFS_HPUX_64BIT_ENV */
894 #if defined(AFS_SUN57_64BIT_ENV)
895 struct iparam32 dst32;
897 if (get_udatamodel() == DATAMODEL_ILP32) {
898 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
900 iparam32_to_iparam(&dst32, dst);
903 #endif /* AFS_SUN57_64BIT_ENV */
905 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
906 struct iparam32 dst32;
908 #ifdef AFS_SPARC64_LINUX24_ENV
909 if (current->thread.flags & SPARC_FLAG_32BIT)
910 #elif AFS_SPARC64_LINUX20_ENV
911 if (current->tss.flags & SPARC_FLAG_32BIT)
913 #error Not done for this linux version
914 #endif /* AFS_SPARC64_LINUX20_ENV */
916 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
918 iparam32_to_iparam(&dst32, dst);
921 #endif /* AFS_LINUX_64BIT_KERNEL */
923 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
927 /* Main entry of all afs system calls */
929 extern int afs_sinited;
931 /** The 32 bit OS expects the members of this structure to be 32 bit
932 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
933 * to accomodate both, *long* is used instead of afs_int32
958 Afs_syscall (uap, rvp)
959 register struct afssysa *uap;
962 int *retval = &rvp->r_val1;
963 #else /* AFS_SUN5_ENV */
964 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
965 afs3_syscall(p, args, retval)
978 } *uap = (struct a *)args;
979 #else /* AFS_OSF_ENV */
980 #ifdef AFS_LINUX20_ENV
988 long parm6; /* not actually used - should be removed */
990 /* Linux system calls only set up for 5 arguments. */
991 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
994 struct afssysargs args, *uap = &args;
996 long *retval = &linux_ret;
997 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
998 #ifdef AFS_SPARC64_LINUX24_ENV
999 afs_int32 eparm32[4];
1001 /* eparm is also used by AFSCALL_CALL in afsd.c */
1003 #if defined(UKERNEL)
1014 } *uap = (struct a *)u.u_ap;
1016 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
1020 #endif /* SUN && !SUN5 */
1030 } *uap = (struct a *)u.u_ap;
1031 #endif /* UKERNEL */
1032 #if defined(AFS_DEC_ENV)
1033 int *retval = &u.u_r.r_val1;
1035 #if defined(AFS_HPUX_ENV)
1036 long *retval = &u.u_rval1;
1038 int *retval = &u.u_rval1;
1041 #endif /* AFS_LINUX20_ENV */
1042 #endif /* AFS_OSF_ENV */
1043 #endif /* AFS_SUN5_ENV */
1044 register int code = 0;
1046 AFS_STATCNT(afs_syscall);
1053 #ifdef AFS_LINUX20_ENV
1055 /* setup uap for use below - pull out the magic decoder ring to know
1056 * which syscalls have folded argument lists.
1058 uap->syscall = syscall;
1062 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
1063 #ifdef AFS_SPARC64_LINUX24_ENV
1064 /* from arch/sparc64/kernel/sys_sparc32.c */
1066 ({ unsigned long __ret; \
1067 __asm__ ("srl %0, 0, %0" \
1074 if (current->thread.flags & SPARC_FLAG_32BIT) {
1075 AFS_COPYIN((char*)parm4, (char*)eparm32, sizeof(eparm32), code);
1076 eparm[0]=AA(eparm32[0]);
1077 eparm[1]=AA(eparm32[1]);
1078 eparm[2]=AA(eparm32[2]);
1082 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
1083 uap->parm4 = eparm[0];
1084 uap->parm5 = eparm[1];
1085 uap->parm6 = eparm[2];
1094 #if defined(AFS_HPUX_ENV)
1096 * There used to be code here (duplicated from osi_Init()) for
1097 * initializing the semaphore used by AFS_GLOCK(). Was the
1098 * duplication to handle the case of a dynamically loaded kernel
1103 if (uap->syscall == AFSCALL_CALL) {
1105 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1106 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1108 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1110 } else if (uap->syscall == AFSCALL_SETPAG) {
1112 register proc_t *procp;
1114 procp = ttoproc(curthread);
1116 code = afs_setpag(&procp->p_cred);
1120 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1121 code = afs_setpag(p, args, retval);
1122 #else /* AFS_OSF_ENV */
1123 code = afs_setpag();
1127 } else if (uap->syscall == AFSCALL_PIOCTL) {
1130 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1132 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1133 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1135 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1139 } else if (uap->syscall == AFSCALL_ICREATE) {
1140 struct iparam iparams;
1142 code = copyin_iparam((char *)uap->parm3, &iparams);
1144 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1149 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1150 iparams.param3, iparams.param4, rvp, CRED());
1152 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1153 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1154 iparams.param3, iparams.param4, retval);
1156 iparams.param3, iparams.param4);
1158 #endif /* AFS_SUN5_ENV */
1159 } else if (uap->syscall == AFSCALL_IOPEN) {
1161 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1163 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1164 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1166 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1168 #endif /* AFS_SUN5_ENV */
1169 } else if (uap->syscall == AFSCALL_IDEC) {
1171 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1173 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1174 #endif /* AFS_SUN5_ENV */
1175 } else if (uap->syscall == AFSCALL_IINC) {
1177 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1179 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1180 #endif /* AFS_SUN5_ENV */
1181 } else if (uap->syscall == AFSCALL_ICL) {
1183 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1185 #ifdef AFS_LINUX20_ENV
1187 /* ICL commands can return values. */
1188 code = -linux_ret; /* Gets negated again at exit below */
1192 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1196 #endif /* !AFS_LINUX20_ENV */
1198 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1202 #endif /* AFS_SUN5_ENV */
1205 #ifdef AFS_LINUX20_ENV
1211 #endif /* AFS_SGI_ENV */
1212 #endif /* !AFS_AIX32_ENV */
1215 * Initstate in the range 0 < x < 100 are early initialization states.
1216 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1217 * the cache may be initialized.
1218 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1219 * is done after all the cache initialization has been done.
1220 * Initstate of 200 means that the volume has been looked up once, possibly
1222 * Initstate of 300 means that the volume has been *successfully* looked up.
1224 int afs_CheckInit(void)
1226 register int code = 0;
1228 AFS_STATCNT(afs_CheckInit);
1229 if (afs_initState <= 100)
1230 code = ENXIO; /* never finished init phase */
1231 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1232 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1233 } else if (afs_initState == 200)
1234 code = ETIMEDOUT; /* didn't find root volume */
1238 int afs_shuttingdown = 0;
1239 void afs_shutdown(void)
1241 extern short afs_brsDaemons;
1242 extern afs_int32 afs_CheckServerDaemonStarted;
1243 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1244 extern struct osi_file *afs_cacheInodep;
1246 AFS_STATCNT(afs_shutdown);
1247 if (afs_shuttingdown) return;
1248 afs_shuttingdown = 1;
1249 if (afs_cold_shutdown) afs_warn("COLD ");
1250 else afs_warn("WARM ");
1251 afs_warn("shutting down of: CB... ");
1253 afs_termState = AFSOP_STOP_RXCALLBACK;
1254 rx_WakeupServerProcs();
1255 /* shutdown_rxkernel(); */
1256 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1257 afs_osi_Sleep(&afs_termState);
1259 afs_warn("afs... ");
1260 while (afs_termState == AFSOP_STOP_AFS) {
1261 afs_osi_CancelWait(&AFS_WaitHandler);
1262 afs_osi_Sleep(&afs_termState);
1264 if (afs_CheckServerDaemonStarted) {
1265 while (afs_termState == AFSOP_STOP_CS) {
1266 afs_osi_CancelWait(&AFS_CSWaitHandler);
1267 afs_osi_Sleep(&afs_termState);
1270 afs_warn("BkG... ");
1271 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1272 while (afs_termState == AFSOP_STOP_BKG) {
1273 afs_osi_Wakeup(&afs_brsDaemons);
1274 afs_osi_Sleep(&afs_termState);
1276 afs_warn("CTrunc... ");
1277 /* Cancel cache truncate daemon. */
1278 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1279 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1280 afs_osi_Sleep(&afs_termState);
1282 #ifdef AFS_AFSDB_ENV
1283 afs_warn("AFSDB... ");
1285 while (afs_termState == AFSOP_STOP_AFSDB)
1286 afs_osi_Sleep(&afs_termState);
1288 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1289 afs_warn("RxEvent... ");
1290 /* cancel rx event deamon */
1291 while (afs_termState == AFSOP_STOP_RXEVENT)
1292 afs_osi_Sleep(&afs_termState);
1293 #if defined(RXK_LISTENER_ENV)
1295 afs_warn("UnmaskRxkSignals... ");
1296 afs_osi_UnmaskRxkSignals();
1298 /* cancel rx listener */
1299 afs_warn("RxListener... ");
1300 osi_StopListener(); /* This closes rx_socket. */
1301 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1302 afs_warn("Sleep... ");
1303 afs_osi_Sleep(&afs_termState);
1307 afs_termState = AFSOP_STOP_COMPLETE;
1311 /* Close file only after daemons which can write to it are stopped. */
1312 if (afs_cacheInodep) /* memcache won't set this */
1314 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1315 afs_cacheInodep = 0;
1317 return; /* Just kill daemons for now */
1321 shutdown_rxkernel();
1325 shutdown_bufferpackage();
1331 shutdown_vnodeops();
1333 shutdown_exporter();
1334 shutdown_memcache();
1335 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1336 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1337 /* this routine does not exist in Ultrix systems... 93.01.19 */
1339 #endif /* AFS_DEC_ENV */
1342 /* The following hold the cm stats */
1344 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1345 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1346 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1348 afs_warn(" ALL allocated tables\n");
1349 afs_shuttingdown = 0;
1353 void shutdown_afstest(void)
1355 AFS_STATCNT(shutdown_afstest);
1356 afs_initState = afs_termState = afs_setTime = 0;
1357 AFS_Running = afs_CB_Running = 0;
1358 afs_CacheInit_Done = afs_Go_Done = 0;
1359 if (afs_cold_shutdown) {
1360 *afs_rootVolumeName = 0;
1365 /* In case there is a bunch of dynamically build bkg daemons to free */
1366 void afs_shutdown_BKG(void)
1368 AFS_STATCNT(shutdown_BKG);
1372 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1373 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1374 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1375 int afs_icl_sizeofLong = 1;
1377 int afs_icl_sizeofLong = 2;
1380 int afs_icl_sizeofLong = 1;
1383 int afs_icl_inited = 0;
1385 /* init function, called once, under afs_icl_lock */
1386 int afs_icl_Init(void)
1392 extern struct afs_icl_log *afs_icl_FindLog();
1393 extern struct afs_icl_set *afs_icl_FindSet();
1397 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1400 afs_int32 *lp, elts, flags;
1401 register afs_int32 code;
1402 struct afs_icl_log *logp;
1403 struct afs_icl_set *setp;
1404 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1406 #else /* AFS_SGI61_ENV */
1408 #endif /* AFS_SGI61_ENV */
1410 afs_int32 startCookie;
1411 afs_int32 allocated;
1412 struct afs_icl_log *tlp;
1415 if (!afs_suser(CRED())) { /* only root can run this code */
1419 if (!afs_suser()) { /* only root can run this code */
1420 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1429 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1430 case ICL_OP_COPYOUT: /* copy ouy data */
1431 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1432 * return flags<<24 + nwords.
1433 * updates cookie to updated start (not end) if we had to
1434 * skip some records.
1436 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1437 if (code) return code;
1438 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1439 if (code) return code;
1440 logp = afs_icl_FindLog(tname);
1441 if (!logp) return ENOENT;
1442 #define BUFFERSIZE AFS_LRALLOCSIZ
1443 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1444 elts = BUFFERSIZE / sizeof(afs_int32);
1445 if (p3 < elts) elts = p3;
1446 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1447 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1450 osi_FreeLargeSpace((struct osi_buffer *) lp);
1453 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1454 if (code) goto done;
1455 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1456 if (code) goto done;
1457 *retval = (flags<<24) | (elts & 0xffffff);
1459 afs_icl_LogRele(logp);
1460 osi_FreeLargeSpace((struct osi_buffer *) lp);
1463 case ICL_OP_ENUMLOGS: /* enumerate logs */
1464 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1465 * return 0 for success, otherwise error.
1467 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1468 if (p1-- == 0) break;
1470 if (!tlp) return ENOENT; /* past the end of file */
1471 temp = strlen(tlp->name)+1;
1472 if (temp > p3) return EINVAL;
1473 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1474 if (!code) /* copy out size of log */
1475 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1478 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1479 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1480 * return 0 for success, otherwise error.
1482 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1483 if (code) return code;
1484 setp = afs_icl_FindSet(tname);
1485 if (!setp) return ENOENT;
1486 if (p2 > ICL_LOGSPERSET)
1488 if (!(tlp = setp->logs[p2]))
1490 temp = strlen(tlp->name)+1;
1491 if (temp > p4) return EINVAL;
1492 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1495 case ICL_OP_CLRLOG: /* clear specified log */
1496 /* zero out the specified log: p1=logname */
1497 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1498 if (code) return code;
1499 logp = afs_icl_FindLog(tname);
1500 if (!logp) return ENOENT;
1501 code = afs_icl_ZeroLog(logp);
1502 afs_icl_LogRele(logp);
1505 case ICL_OP_CLRSET: /* clear specified set */
1506 /* zero out the specified set: p1=setname */
1507 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1508 if (code) return code;
1509 setp = afs_icl_FindSet(tname);
1510 if (!setp) return ENOENT;
1511 code = afs_icl_ZeroSet(setp);
1512 afs_icl_SetRele(setp);
1515 case ICL_OP_CLRALL: /* clear all logs */
1516 /* zero out all logs -- no args */
1518 ObtainWriteLock(&afs_icl_lock,178);
1519 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1520 tlp->refCount++; /* hold this guy */
1521 ReleaseWriteLock(&afs_icl_lock);
1522 /* don't clear persistent logs */
1523 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1524 code = afs_icl_ZeroLog(tlp);
1525 ObtainWriteLock(&afs_icl_lock,179);
1526 if (--tlp->refCount == 0)
1527 afs_icl_ZapLog(tlp);
1530 ReleaseWriteLock(&afs_icl_lock);
1533 case ICL_OP_ENUMSETS: /* enumerate all sets */
1534 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1535 * return 0 for success, otherwise error.
1537 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1538 if (p1-- == 0) break;
1540 if (!setp) return ENOENT; /* past the end of file */
1541 temp = strlen(setp->name)+1;
1542 if (temp > p3) return EINVAL;
1543 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1544 if (!code) /* copy out size of log */
1545 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1548 case ICL_OP_SETSTAT: /* set status on a set */
1549 /* activate the specified set: p1=setname, p2=op */
1550 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1551 if (code) return code;
1552 setp = afs_icl_FindSet(tname);
1553 if (!setp) return ENOENT;
1554 code = afs_icl_SetSetStat(setp, p2);
1555 afs_icl_SetRele(setp);
1558 case ICL_OP_SETSTATALL: /* set status on all sets */
1559 /* activate the specified set: p1=op */
1561 ObtainWriteLock(&afs_icl_lock,180);
1562 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1563 setp->refCount++; /* hold this guy */
1564 ReleaseWriteLock(&afs_icl_lock);
1565 /* don't set states on persistent sets */
1566 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1567 code = afs_icl_SetSetStat(setp, p1);
1568 ObtainWriteLock(&afs_icl_lock,181);
1569 if (--setp->refCount == 0)
1570 afs_icl_ZapSet(setp);
1573 ReleaseWriteLock(&afs_icl_lock);
1576 case ICL_OP_SETLOGSIZE: /* set size of log */
1577 /* set the size of the specified log: p1=logname, p2=size (in words) */
1578 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1579 if (code) return code;
1580 logp = afs_icl_FindLog(tname);
1581 if (!logp) return ENOENT;
1582 code = afs_icl_LogSetSize(logp, p2);
1583 afs_icl_LogRele(logp);
1586 case ICL_OP_GETLOGINFO: /* get size of log */
1587 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1588 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1589 if (code) return code;
1590 logp = afs_icl_FindLog(tname);
1591 if (!logp) return ENOENT;
1592 allocated = !!logp->datap;
1593 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1595 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1596 afs_icl_LogRele(logp);
1599 case ICL_OP_GETSETINFO: /* get state of set */
1600 /* zero out the specified set: p1=setname, p2=&state */
1601 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1602 if (code) return code;
1603 setp = afs_icl_FindSet(tname);
1604 if (!setp) return ENOENT;
1605 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1606 afs_icl_SetRele(setp);
1617 afs_lock_t afs_icl_lock;
1619 /* exported routine: a 4 parameter event */
1620 int afs_icl_Event4(register struct afs_icl_set *setp, afs_int32 eventID,
1621 afs_int32 lAndT, long p1, long p2, long p3, long p4)
1623 register struct afs_icl_log *logp;
1626 register afs_int32 tmask;
1629 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1630 if (!ICL_SETACTIVE(setp)) return;
1633 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1634 ix = ICL_EVENTBYTE(eventID);
1635 ObtainReadLock(&setp->lock);
1636 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1637 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1639 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1643 if (mask == 0) break; /* break early */
1646 ReleaseReadLock(&setp->lock);
1649 /* Next 4 routines should be implemented via var-args or something.
1650 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1651 * Otherwise, could call afs_icl_Event4 directly.
1653 int afs_icl_Event3(register struct afs_icl_set *setp, afs_int32 eventID,
1654 afs_int32 lAndT, long p1, long p2, long p3)
1656 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1659 int afs_icl_Event2(register struct afs_icl_set *setp, afs_int32 eventID,
1660 afs_int32 lAndT, long p1, long p2)
1662 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1665 int afs_icl_Event1(register struct afs_icl_set *setp, afs_int32 eventID,
1666 afs_int32 lAndT, long p1)
1668 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1671 int afs_icl_Event0(register struct afs_icl_set *setp, afs_int32 eventID,
1674 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1677 struct afs_icl_log *afs_icl_allLogs = 0;
1679 /* function to purge records from the start of the log, until there
1680 * is at least minSpace long's worth of space available without
1681 * making the head and the tail point to the same word.
1683 * Log must be write-locked.
1685 static afs_icl_GetLogSpace(register struct afs_icl_log *logp, afs_int32 minSpace)
1687 register unsigned int tsize;
1689 while (logp->logSize - logp->logElements <= minSpace) {
1691 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1692 logp->logElements -= tsize;
1693 logp->firstUsed += tsize;
1694 if (logp->firstUsed >= logp->logSize)
1695 logp->firstUsed -= logp->logSize;
1696 logp->baseCookie += tsize;
1700 /* append string astr to buffer, including terminating null char.
1702 * log must be write-locked.
1704 #define ICL_CHARSPERLONG 4
1705 static afs_int32 afs_icl_AppendString(struct afs_icl_log *logp, char *astr)
1707 char *op; /* ptr to char to write */
1709 register int bib; /* bytes in buffer */
1712 op = (char *) &(logp->datap[logp->firstFree]);
1716 if (++bib >= ICL_CHARSPERLONG) {
1719 if (++(logp->firstFree) >= logp->logSize) {
1720 logp->firstFree = 0;
1721 op = (char *) &(logp->datap[0]);
1723 logp->logElements++;
1728 /* if we've used this word at all, allocate it */
1729 if (++(logp->firstFree) >= logp->logSize) {
1730 logp->firstFree = 0;
1732 logp->logElements++;
1736 /* add a long to the log, ignoring overflow (checked already) */
1737 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1738 #define ICL_APPENDINT32(lp, x) \
1740 (lp)->datap[(lp)->firstFree] = (x); \
1741 if (++((lp)->firstFree) >= (lp)->logSize) { \
1742 (lp)->firstFree = 0; \
1744 (lp)->logElements++; \
1747 #define ICL_APPENDLONG(lp, x) \
1749 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1750 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1753 #else /* AFS_ALPHA_ENV */
1754 #define ICL_APPENDLONG(lp, x) \
1756 (lp)->datap[(lp)->firstFree] = (x); \
1757 if (++((lp)->firstFree) >= (lp)->logSize) { \
1758 (lp)->firstFree = 0; \
1760 (lp)->logElements++; \
1762 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1763 #endif /* AFS_ALPHA_ENV */
1765 /* routine to tell whether we're dealing with the address or the
1768 int afs_icl_UseAddr(int type)
1770 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1771 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
1777 /* Function to append a record to the log. Written for speed
1778 * since we know that we're going to have to make this work fast
1779 * pretty soon, anyway. The log must be unlocked.
1782 int afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
1783 afs_int32 types, long p1, long p2, long p3, long p4)
1785 int rsize; /* record size in longs */
1786 register int tsize; /* temp size */
1790 t4 = types & 0x3f; /* decode types */
1798 osi_GetTime(&tv); /* It panics for solaris if inside */
1799 ObtainWriteLock(&logp->lock,182);
1801 ReleaseWriteLock(&logp->lock);
1805 /* get timestamp as # of microseconds since some time that doesn't
1806 * change that often. This algorithm ticks over every 20 minutes
1807 * or so (1000 seconds). Write a timestamp record if it has.
1809 if (tv.tv_sec - logp->lastTS > 1024)
1811 /* the timer has wrapped -- write a timestamp record */
1812 if (logp->logSize - logp->logElements <= 5)
1813 afs_icl_GetLogSpace(logp, 5);
1815 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1816 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1817 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1818 ICL_APPENDINT32(logp,
1819 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1820 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1822 logp->lastTS = tv.tv_sec;
1825 rsize = 4; /* base case */
1827 /* compute size of parameter p1. Only tricky case is string.
1828 * In that case, we have to call strlen to get the string length.
1830 ICL_SIZEHACK(t1, p1);
1833 /* compute size of parameter p2. Only tricky case is string.
1834 * In that case, we have to call strlen to get the string length.
1836 ICL_SIZEHACK(t2, p2);
1839 /* compute size of parameter p3. Only tricky case is string.
1840 * In that case, we have to call strlen to get the string length.
1842 ICL_SIZEHACK(t3, p3);
1845 /* compute size of parameter p4. Only tricky case is string.
1846 * In that case, we have to call strlen to get the string length.
1848 ICL_SIZEHACK(t4, p4);
1851 /* At this point, we've computed all of the parameter sizes, and
1852 * have in rsize the size of the entire record we want to append.
1853 * Next, we check that we actually have room in the log to do this
1854 * work, and then we do the append.
1857 ReleaseWriteLock(&logp->lock);
1858 return; /* log record too big to express */
1861 if (logp->logSize - logp->logElements <= rsize)
1862 afs_icl_GetLogSpace(logp, rsize);
1864 ICL_APPENDINT32(logp,
1865 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
1866 ICL_APPENDINT32(logp, (afs_int32)op);
1867 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
1868 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1871 /* marshall parameter 1 now */
1872 if (t1 == ICL_TYPE_STRING) {
1873 afs_icl_AppendString(logp, (char *) p1);
1875 else if (t1 == ICL_TYPE_HYPER) {
1876 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
1877 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
1879 else if (t1 == ICL_TYPE_INT64) {
1880 #ifdef AFSLITTLE_ENDIAN
1881 #ifdef AFS_64BIT_CLIENT
1882 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1883 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1884 #else /* AFS_64BIT_CLIENT */
1885 ICL_APPENDINT32(logp, (afs_int32) p1);
1886 ICL_APPENDINT32(logp, (afs_int32) 0);
1887 #endif /* AFS_64BIT_CLIENT */
1888 #else /* AFSLITTLE_ENDIAN */
1889 #ifdef AFS_64BIT_CLIENT
1890 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1891 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1892 #else /* AFS_64BIT_CLIENT */
1893 ICL_APPENDINT32(logp, (afs_int32) 0);
1894 ICL_APPENDINT32(logp, (afs_int32) p1);
1895 #endif /* AFS_64BIT_CLIENT */
1896 #endif /* AFSLITTLE_ENDIAN */
1898 else if (t1 == ICL_TYPE_FID) {
1899 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1900 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1901 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
1902 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
1904 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1905 else if (t1 == ICL_TYPE_INT32)
1906 ICL_APPENDINT32(logp, (afs_int32)p1);
1907 #endif /* AFS_ALPHA_ENV */
1908 else ICL_APPENDLONG(logp, p1);
1911 /* marshall parameter 2 now */
1912 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
1913 else if (t2 == ICL_TYPE_HYPER) {
1914 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
1915 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
1917 else if (t2 == ICL_TYPE_INT64) {
1918 #ifdef AFSLITTLE_ENDIAN
1919 #ifdef AFS_64BIT_CLIENT
1920 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1921 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1922 #else /* AFS_64BIT_CLIENT */
1923 ICL_APPENDINT32(logp, (afs_int32) p2);
1924 ICL_APPENDINT32(logp, (afs_int32) 0);
1925 #endif /* AFS_64BIT_CLIENT */
1926 #else /* AFSLITTLE_ENDIAN */
1927 #ifdef AFS_64BIT_CLIENT
1928 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1929 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1930 #else /* AFS_64BIT_CLIENT */
1931 ICL_APPENDINT32(logp, (afs_int32) 0);
1932 ICL_APPENDINT32(logp, (afs_int32) p2);
1933 #endif /* AFS_64BIT_CLIENT */
1934 #endif /* AFSLITTLE_ENDIAN */
1936 else if (t2 == ICL_TYPE_FID) {
1937 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1938 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1939 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
1940 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
1942 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1943 else if (t2 == ICL_TYPE_INT32)
1944 ICL_APPENDINT32(logp, (afs_int32)p2);
1945 #endif /* AFS_ALPHA_ENV */
1946 else ICL_APPENDLONG(logp, p2);
1949 /* marshall parameter 3 now */
1950 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
1951 else if (t3 == ICL_TYPE_HYPER) {
1952 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
1953 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
1955 else if (t3 == ICL_TYPE_INT64) {
1956 #ifdef AFSLITTLE_ENDIAN
1957 #ifdef AFS_64BIT_CLIENT
1958 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1959 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1960 #else /* AFS_64BIT_CLIENT */
1961 ICL_APPENDINT32(logp, (afs_int32) p3);
1962 ICL_APPENDINT32(logp, (afs_int32) 0);
1963 #endif /* AFS_64BIT_CLIENT */
1964 #else /* AFSLITTLE_ENDIAN */
1965 #ifdef AFS_64BIT_CLIENT
1966 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1967 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1968 #else /* AFS_64BIT_CLIENT */
1969 ICL_APPENDINT32(logp, (afs_int32) 0);
1970 ICL_APPENDINT32(logp, (afs_int32) p3);
1971 #endif /* AFS_64BIT_CLIENT */
1972 #endif /* AFSLITTLE_ENDIAN */
1974 else if (t3 == ICL_TYPE_FID) {
1975 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1976 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1977 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
1978 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
1980 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1981 else if (t3 == ICL_TYPE_INT32)
1982 ICL_APPENDINT32(logp, (afs_int32)p3);
1983 #endif /* AFS_ALPHA_ENV */
1984 else ICL_APPENDLONG(logp, p3);
1987 /* marshall parameter 4 now */
1988 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
1989 else if (t4 == ICL_TYPE_HYPER) {
1990 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
1991 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
1993 else if (t4 == ICL_TYPE_INT64) {
1994 #ifdef AFSLITTLE_ENDIAN
1995 #ifdef AFS_64BIT_CLIENT
1996 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
1997 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
1998 #else /* AFS_64BIT_CLIENT */
1999 ICL_APPENDINT32(logp, (afs_int32) p4);
2000 ICL_APPENDINT32(logp, (afs_int32) 0);
2001 #endif /* AFS_64BIT_CLIENT */
2002 #else /* AFSLITTLE_ENDIAN */
2003 #ifdef AFS_64BIT_CLIENT
2004 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2005 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2006 #else /* AFS_64BIT_CLIENT */
2007 ICL_APPENDINT32(logp, (afs_int32) 0);
2008 ICL_APPENDINT32(logp, (afs_int32) p4);
2009 #endif /* AFS_64BIT_CLIENT */
2010 #endif /* AFSLITTLE_ENDIAN */
2012 else if (t4 == ICL_TYPE_FID) {
2013 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2014 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2015 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
2016 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
2018 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2019 else if (t4 == ICL_TYPE_INT32)
2020 ICL_APPENDINT32(logp, (afs_int32)p4);
2021 #endif /* AFS_ALPHA_ENV */
2022 else ICL_APPENDLONG(logp, p4);
2024 ReleaseWriteLock(&logp->lock);
2027 /* create a log with size logSize; return it in *outLogpp and tag
2028 * it with name "name."
2030 int afs_icl_CreateLog(char *name, afs_int32 logSize, struct afs_icl_log **outLogpp)
2032 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
2035 /* create a log with size logSize; return it in *outLogpp and tag
2036 * it with name "name." 'flags' can be set to make the log unclearable.
2038 int afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, afs_uint32 flags,
2039 struct afs_icl_log **outLogpp)
2041 register struct afs_icl_log *logp;
2043 /* add into global list under lock */
2044 ObtainWriteLock(&afs_icl_lock,183);
2045 if (!afs_icl_inited) afs_icl_Init();
2047 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
2048 if (strcmp(logp->name, name) == 0) {
2049 /* found it already created, just return it */
2052 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2054 ObtainWriteLock(&logp->lock,184);
2055 logp->states |= ICL_LOGF_PERSISTENT;
2056 ReleaseWriteLock(&logp->lock);
2058 ReleaseWriteLock(&afs_icl_lock);
2063 logp = (struct afs_icl_log *)
2064 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
2065 memset((caddr_t)logp, 0, sizeof(*logp));
2068 logp->name = osi_AllocSmallSpace(strlen(name)+1);
2069 strcpy(logp->name, name);
2070 LOCK_INIT(&logp->lock, "logp lock");
2071 logp->logSize = logSize;
2072 logp->datap = NULL; /* don't allocate it until we need it */
2074 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2075 logp->states |= ICL_LOGF_PERSISTENT;
2077 logp->nextp = afs_icl_allLogs;
2078 afs_icl_allLogs = logp;
2079 ReleaseWriteLock(&afs_icl_lock);
2085 /* called with a log, a pointer to a buffer, the size of the buffer
2086 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
2087 * and returns data in the provided buffer, and returns output flags
2088 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
2089 * find the record with cookie value cookie.
2091 int afs_icl_CopyOut(register struct afs_icl_log *logp, afs_int32 *bufferp,
2092 afs_int32 *bufSizep, afs_uint32 *cookiep, afs_int32 *flagsp)
2094 afs_int32 nwords; /* number of words to copy out */
2095 afs_uint32 startCookie; /* first cookie to use */
2096 register afs_int32 i;
2097 afs_int32 outWords; /* words we've copied out */
2098 afs_int32 inWords; /* max words to copy out */
2099 afs_int32 code; /* return code */
2100 afs_int32 ix; /* index we're copying from */
2101 afs_int32 outFlags; /* return flags */
2102 afs_int32 inFlags; /* flags passed in */
2105 inWords = *bufSizep; /* max to copy out */
2106 outWords = 0; /* amount copied out */
2107 startCookie = *cookiep;
2112 ObtainWriteLock(&logp->lock,185);
2114 ReleaseWriteLock(&logp->lock);
2118 /* first, compute the index of the start cookie we've been passed */
2120 /* (re-)compute where we should start */
2121 if (startCookie < logp->baseCookie) {
2122 if (startCookie) /* missed some output */
2123 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2124 /* skip to the first available record */
2125 startCookie = logp->baseCookie;
2126 *cookiep = startCookie;
2129 /* compute where we find the first element to copy out */
2130 ix = logp->firstUsed + startCookie - logp->baseCookie;
2131 if (ix >= logp->logSize) ix -= logp->logSize;
2133 /* if have some data now, break out and process it */
2134 if (startCookie - logp->baseCookie < logp->logElements) break;
2136 /* At end of log, so clear it if we need to */
2137 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
2139 logp->firstUsed = logp->firstFree = 0;
2140 logp->logElements = 0;
2142 /* otherwise, either wait for the data to arrive, or return */
2143 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2144 ReleaseWriteLock(&logp->lock);
2148 logp->states |= ICL_LOGF_WAITING;
2149 ReleaseWriteLock(&logp->lock);
2150 afs_osi_Sleep(&logp->lock);
2151 ObtainWriteLock(&logp->lock,186);
2153 /* copy out data from ix to logSize or firstFree, depending
2154 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2155 * be careful not to copy out more than nwords.
2157 if (ix >= logp->firstUsed) {
2158 if (logp->firstUsed <= logp->firstFree)
2160 end = logp->firstFree; /* first element not to copy */
2162 end = logp->logSize;
2163 nwords = inWords; /* don't copy more than this */
2164 if (end - ix < nwords)
2167 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2172 /* if we're going to copy more out below, we'll start here */
2175 /* now, if active part of the log has wrapped, there's more stuff
2176 * starting at the head of the log. Copy out more from there.
2178 if (logp->firstUsed > logp->firstFree
2179 && ix < logp->firstFree && inWords > 0) {
2180 /* (more to) copy out from the wrapped section at the
2181 * start of the log. May get here even if didn't copy any
2182 * above, if the cookie points directly into the wrapped section.
2185 if (logp->firstFree - ix < nwords)
2186 nwords = logp->firstFree - ix;
2187 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2193 ReleaseWriteLock(&logp->lock);
2197 *bufSizep = outWords;
2203 /* return basic parameter information about a log */
2204 int afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 *maxSizep,
2205 afs_int32 *curSizep)
2207 ObtainReadLock(&logp->lock);
2208 *maxSizep = logp->logSize;
2209 *curSizep = logp->logElements;
2210 ReleaseReadLock(&logp->lock);
2215 /* hold and release logs */
2216 int afs_icl_LogHold(register struct afs_icl_log *logp)
2218 ObtainWriteLock(&afs_icl_lock,187);
2220 ReleaseWriteLock(&afs_icl_lock);
2224 /* hold and release logs, called with lock already held */
2225 int afs_icl_LogHoldNL(register struct afs_icl_log *logp)
2231 /* keep track of how many sets believe the log itself is allocated */
2232 int afs_icl_LogUse(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 int afs_icl_LogFreeUse(register struct afs_icl_log *logp)
2254 ObtainWriteLock(&logp->lock,189);
2255 if (--logp->setCount == 0) {
2256 /* no more users -- free it (but keep log structure around)*/
2257 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2258 #ifdef AFS_AIX32_ENV
2259 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2261 logp->firstUsed = logp->firstFree = 0;
2262 logp->logElements = 0;
2265 ReleaseWriteLock(&logp->lock);
2269 /* set the size of the log to 'logSize' */
2270 int afs_icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
2272 ObtainWriteLock(&logp->lock,190);
2274 /* nothing to worry about since it's not allocated */
2275 logp->logSize = logSize;
2279 logp->firstUsed = logp->firstFree = 0;
2280 logp->logElements = 0;
2282 /* free and allocate a new one */
2283 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2284 #ifdef AFS_AIX32_ENV
2285 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2287 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2288 #ifdef AFS_AIX32_ENV
2289 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2291 logp->logSize = logSize;
2293 ReleaseWriteLock(&logp->lock);
2298 /* free a log. Called with afs_icl_lock locked. */
2299 int afs_icl_ZapLog(register struct afs_icl_log *logp)
2301 register struct afs_icl_log **lpp, *tp;
2303 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2305 /* found the dude we want to remove */
2307 osi_FreeSmallSpace(logp->name);
2308 osi_FreeSmallSpace(logp->datap);
2309 osi_FreeSmallSpace(logp);
2310 break; /* won't find it twice */
2316 /* do the release, watching for deleted entries */
2317 int afs_icl_LogRele(register struct afs_icl_log *logp)
2319 ObtainWriteLock(&afs_icl_lock,191);
2320 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2321 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2323 ReleaseWriteLock(&afs_icl_lock);
2327 /* do the release, watching for deleted entries, log already held */
2328 int afs_icl_LogReleNL(register struct afs_icl_log *logp)
2330 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2331 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2336 /* zero out the log */
2337 int afs_icl_ZeroLog(register struct afs_icl_log *logp)
2339 ObtainWriteLock(&logp->lock,192);
2340 logp->firstUsed = logp->firstFree = 0;
2341 logp->logElements = 0;
2342 logp->baseCookie = 0;
2343 ReleaseWriteLock(&logp->lock);
2347 /* free a log entry, and drop its reference count */
2348 int afs_icl_LogFree(register struct afs_icl_log *logp)
2350 ObtainWriteLock(&logp->lock,193);
2351 logp->states |= ICL_LOGF_DELETED;
2352 ReleaseWriteLock(&logp->lock);
2353 afs_icl_LogRele(logp);
2357 /* find a log by name, returning it held */
2358 struct afs_icl_log *afs_icl_FindLog(char *name)
2360 register struct afs_icl_log *tp;
2361 ObtainWriteLock(&afs_icl_lock,194);
2362 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2363 if (strcmp(tp->name, name) == 0) {
2364 /* this is the dude we want */
2369 ReleaseWriteLock(&afs_icl_lock);
2373 int afs_icl_EnumerateLogs(int (*aproc)(), char *arock)
2375 register struct afs_icl_log *tp;
2376 register afs_int32 code;
2379 ObtainWriteLock(&afs_icl_lock,195);
2380 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2381 tp->refCount++; /* hold this guy */
2382 ReleaseWriteLock(&afs_icl_lock);
2383 ObtainReadLock(&tp->lock);
2384 code = (*aproc)(tp->name, arock, tp);
2385 ReleaseReadLock(&tp->lock);
2386 ObtainWriteLock(&afs_icl_lock,196);
2387 if (--tp->refCount == 0)
2391 ReleaseWriteLock(&afs_icl_lock);
2395 struct afs_icl_set *afs_icl_allSets = 0;
2397 int afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
2398 struct afs_icl_log *fatalLogp, struct afs_icl_set **outSetpp)
2400 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2401 /*flags*/0, outSetpp);
2404 /* create a set, given pointers to base and fatal logs, if any.
2405 * Logs are unlocked, but referenced, and *outSetpp is returned
2406 * referenced. Function bumps reference count on logs, since it
2407 * addds references from the new afs_icl_set. When the set is destroyed,
2408 * those references will be released.
2410 int afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
2411 struct afs_icl_log *fatalLogp, afs_uint32 flags, struct afs_icl_set **outSetpp)
2413 register struct afs_icl_set *setp;
2415 afs_int32 states = ICL_DEFAULT_SET_STATES;
2417 ObtainWriteLock(&afs_icl_lock,197);
2418 if (!afs_icl_inited) afs_icl_Init();
2420 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2421 if (strcmp(setp->name, name) == 0) {
2424 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2426 ObtainWriteLock(&setp->lock,198);
2427 setp->states |= ICL_SETF_PERSISTENT;
2428 ReleaseWriteLock(&setp->lock);
2430 ReleaseWriteLock(&afs_icl_lock);
2435 /* determine initial state */
2436 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2437 states = ICL_SETF_ACTIVE;
2438 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2439 states = ICL_SETF_FREED;
2440 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2441 states |= ICL_SETF_PERSISTENT;
2443 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2444 memset((caddr_t)setp, 0, sizeof(*setp));
2446 if (states & ICL_SETF_FREED)
2447 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2448 setp->states = states;
2450 LOCK_INIT(&setp->lock, "setp lock");
2451 /* next lock is obtained in wrong order, hierarchy-wise, but
2452 * it doesn't matter, since no one can find this lock yet, since
2453 * the afs_icl_lock is still held, and thus the obtain can't block.
2455 ObtainWriteLock(&setp->lock,199);
2456 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2457 strcpy(setp->name, name);
2458 setp->nevents = ICL_DEFAULTEVENTS;
2459 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2460 #ifdef AFS_AIX32_ENV
2461 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2463 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2464 setp->eventFlags[i] = 0xff; /* default to enabled */
2466 /* update this global info under the afs_icl_lock */
2467 setp->nextp = afs_icl_allSets;
2468 afs_icl_allSets = setp;
2469 ReleaseWriteLock(&afs_icl_lock);
2471 /* set's basic lock is still held, so we can finish init */
2473 setp->logs[0] = baseLogp;
2474 afs_icl_LogHold(baseLogp);
2475 if (!(setp->states & ICL_SETF_FREED))
2476 afs_icl_LogUse(baseLogp); /* log is actually being used */
2479 setp->logs[1] = fatalLogp;
2480 afs_icl_LogHold(fatalLogp);
2481 if (!(setp->states & ICL_SETF_FREED))
2482 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2484 ReleaseWriteLock(&setp->lock);
2490 /* function to change event enabling information for a particular set */
2491 int afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
2495 ObtainWriteLock(&setp->lock,200);
2496 if (!ICL_EVENTOK(setp, eventID)) {
2497 ReleaseWriteLock(&setp->lock);
2500 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2502 *tp |= ICL_EVENTMASK(eventID);
2504 *tp &= ~(ICL_EVENTMASK(eventID));
2505 ReleaseWriteLock(&setp->lock);
2509 /* return indication of whether a particular event ID is enabled
2510 * for tracing. If *getValuep is set to 0, the event is disabled,
2511 * otherwise it is enabled. All events start out enabled by default.
2513 int afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID,
2516 ObtainReadLock(&setp->lock);
2517 if (!ICL_EVENTOK(setp, eventID)) {
2518 ReleaseWriteLock(&setp->lock);
2521 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2525 ReleaseReadLock(&setp->lock);
2529 /* hold and release event sets */
2530 int afs_icl_SetHold(register struct afs_icl_set *setp)
2532 ObtainWriteLock(&afs_icl_lock,201);
2534 ReleaseWriteLock(&afs_icl_lock);
2538 /* free a set. Called with afs_icl_lock locked */
2539 int afs_icl_ZapSet(register struct afs_icl_set *setp)
2541 register struct afs_icl_set **lpp, *tp;
2543 register struct afs_icl_log *tlp;
2545 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2547 /* found the dude we want to remove */
2549 osi_FreeSmallSpace(setp->name);
2550 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2551 #ifdef AFS_AIX32_ENV
2552 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2554 for(i=0; i < ICL_LOGSPERSET; i++) {
2555 if ((tlp = setp->logs[i]))
2556 afs_icl_LogReleNL(tlp);
2558 osi_FreeSmallSpace(setp);
2559 break; /* won't find it twice */
2565 /* do the release, watching for deleted entries */
2566 int afs_icl_SetRele(register struct afs_icl_set *setp)
2568 ObtainWriteLock(&afs_icl_lock,202);
2569 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2570 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2572 ReleaseWriteLock(&afs_icl_lock);
2576 /* free a set entry, dropping its reference count */
2577 int afs_icl_SetFree(register struct afs_icl_set *setp)
2579 ObtainWriteLock(&setp->lock,203);
2580 setp->states |= ICL_SETF_DELETED;
2581 ReleaseWriteLock(&setp->lock);
2582 afs_icl_SetRele(setp);
2586 /* find a set by name, returning it held */
2587 struct afs_icl_set *afs_icl_FindSet(char *name)
2589 register struct afs_icl_set *tp;
2590 ObtainWriteLock(&afs_icl_lock,204);
2591 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2592 if (strcmp(tp->name, name) == 0) {
2593 /* this is the dude we want */
2598 ReleaseWriteLock(&afs_icl_lock);
2602 /* zero out all the logs in the set */
2603 int afs_icl_ZeroSet(struct afs_icl_set *setp)
2608 struct afs_icl_log *logp;
2610 ObtainReadLock(&setp->lock);
2611 for(i = 0; i < ICL_LOGSPERSET; i++) {
2612 logp = setp->logs[i];
2614 afs_icl_LogHold(logp);
2615 tcode = afs_icl_ZeroLog(logp);
2616 if (tcode != 0) code = tcode; /* save the last bad one */
2617 afs_icl_LogRele(logp);
2620 ReleaseReadLock(&setp->lock);
2624 int afs_icl_EnumerateSets(int (*aproc)(), char *arock)
2626 register struct afs_icl_set *tp, *np;
2627 register afs_int32 code;
2630 ObtainWriteLock(&afs_icl_lock,205);
2631 for(tp = afs_icl_allSets; tp; tp=np) {
2632 tp->refCount++; /* hold this guy */
2633 ReleaseWriteLock(&afs_icl_lock);
2634 code = (*aproc)(tp->name, arock, tp);
2635 ObtainWriteLock(&afs_icl_lock,206);
2636 np = tp->nextp; /* tp may disappear next, but not np */
2637 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2641 ReleaseWriteLock(&afs_icl_lock);
2645 int afs_icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
2649 struct afs_icl_log *logp;
2651 ObtainWriteLock(&setp->lock,207);
2652 for(i = 0; i < ICL_LOGSPERSET; i++) {
2653 if (!setp->logs[i]) {
2654 setp->logs[i] = newlogp;
2656 afs_icl_LogHold(newlogp);
2657 if (!(setp->states & ICL_SETF_FREED)) {
2658 /* bump up the number of sets using the log */
2659 afs_icl_LogUse(newlogp);
2664 ReleaseWriteLock(&setp->lock);
2668 int afs_icl_SetSetStat(struct afs_icl_set *setp, int op)
2672 struct afs_icl_log *logp;
2674 ObtainWriteLock(&setp->lock,208);
2676 case ICL_OP_SS_ACTIVATE: /* activate a log */
2678 * If we are not already active, see if we have released
2679 * our demand that the log be allocated (FREED set). If
2680 * we have, reassert our desire.
2682 if (!(setp->states & ICL_SETF_ACTIVE)) {
2683 if (setp->states & ICL_SETF_FREED) {
2684 /* have to reassert desire for logs */
2685 for(i = 0; i < ICL_LOGSPERSET; i++) {
2686 logp = setp->logs[i];
2688 afs_icl_LogHold(logp);
2689 afs_icl_LogUse(logp);
2690 afs_icl_LogRele(logp);
2693 setp->states &= ~ICL_SETF_FREED;
2695 setp->states |= ICL_SETF_ACTIVE;
2700 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2701 /* this doesn't require anything beyond clearing the ACTIVE flag */
2702 setp->states &= ~ICL_SETF_ACTIVE;
2706 case ICL_OP_SS_FREE: /* deassert design for log */
2708 * if we are already in this state, do nothing; otherwise
2709 * deassert desire for log
2711 if (setp->states & ICL_SETF_ACTIVE)
2714 if (!(setp->states & ICL_SETF_FREED)) {
2715 for(i = 0; i < ICL_LOGSPERSET; i++) {
2716 logp = setp->logs[i];
2718 afs_icl_LogHold(logp);
2719 afs_icl_LogFreeUse(logp);
2720 afs_icl_LogRele(logp);
2723 setp->states |= ICL_SETF_FREED;
2732 ReleaseWriteLock(&setp->lock);