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 simplelock afs_global_lock;
66 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
67 thread_t afs_global_owner;
68 #endif /* AFS_OSF_ENV */
70 #if defined(AFS_AIX41_ENV)
71 simple_lock_data afs_global_lock;
74 afs_int32 afs_initState = 0;
75 afs_int32 afs_termState = 0;
76 afs_int32 afs_setTime = 0;
77 int afs_cold_shutdown = 0;
78 char afs_SynchronousCloses = '\0';
79 static int afs_CB_Running = 0;
80 static int AFS_Running = 0;
81 static int afs_CacheInit_Done = 0;
82 static int afs_Go_Done = 0;
83 extern struct interfaceAddr afs_cb_interface;
84 static int afs_RX_Running = 0;
87 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval);
89 #if defined(AFS_HPUX_ENV)
90 extern int afs_vfs_mount();
91 #endif /* defined(AFS_HPUX_ENV) */
93 /* This is code which needs to be called once when the first daemon enters
94 * the client. A non-zero return means an error and AFS should not start.
96 static int afs_InitSetup(int preallocs)
98 extern void afs_InitStats();
103 * Set up all the AFS statistics variables. This should be done
104 * exactly once, and it should be done here, the first resource-setting
105 * routine to be called by the CM/RX.
108 #endif /* AFS_NOSTATS */
110 memset(afs_zeros, 0, AFS_ZEROS);
113 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
114 code = rx_Init(htons(7001));
116 printf("AFS: RX failed to initialize.\n");
119 rx_SetRxDeadTime(AFS_RXDEADTIME);
120 /* resource init creates the services */
121 afs_ResourceInit(preallocs);
126 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
127 long parm, parm2, parm3, parm4, parm5, parm6;
131 AFS_STATCNT(afs_syscall_call);
133 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
134 && (parm != AFSOP_GETMASK)) {
135 /* only root can run this code */
138 if (!afs_suser() && (parm != AFSOP_GETMTU)
139 && (parm != AFSOP_GETMASK)) {
140 /* only root can run this code */
141 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
145 #if defined(AFS_OSF_ENV)
147 #else /* AFS_OSF_ENV */
154 if (parm == AFSOP_START_RXCALLBACK) {
155 if (afs_CB_Running) goto out;
157 #ifndef RXK_LISTENER_ENV
158 code = afs_InitSetup(parm2);
160 #endif /* RXK_LISTENER_ENV */
162 #ifdef RXK_LISTENER_ENV
163 while (afs_RX_Running != 2)
164 afs_osi_Sleep(&afs_RX_Running);
166 afs_initState = AFSOP_START_AFS;
167 afs_osi_Wakeup(&afs_initState);
168 #endif /* RXK_LISTENER_ENV */
170 afs_RXCallBackServer();
174 exit(CLD_EXITED, code);
177 #ifdef RXK_LISTENER_ENV
178 else if (parm == AFSOP_RXLISTENER_DAEMON) {
179 if (afs_RX_Running) goto out;
181 code = afs_InitSetup(parm2);
183 rx_enablePeerRPCStats();
186 rx_enableProcessRPCStats();
189 afs_initState = AFSOP_START_AFS;
190 afs_osi_Wakeup(&afs_initState);
193 afs_osi_Wakeup(&afs_RX_Running);
198 exit(CLD_EXITED, code);
202 else if (parm == AFSOP_START_AFS) {
206 if (AFS_Running) goto out;
208 while (afs_initState < AFSOP_START_AFS)
209 afs_osi_Sleep(&afs_initState);
211 #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)
212 temp = AFS_MINBUFFERS; /* Should fix this soon */
214 temp = ((afs_bufferpages * NBPG)>>11); /* number of 2k buffers we could get from all of the buffer space */
215 temp = temp>>2; /* don't take more than 25% (our magic parameter) */
216 if (temp < AFS_MINBUFFERS) temp = AFS_MINBUFFERS; /* although we really should have this many */
219 afs_initState = AFSOP_START_BKG;
220 afs_osi_Wakeup(&afs_initState);
228 else if (parm == AFSOP_START_CS) {
230 afs_CheckServerDaemon();
236 else if (parm == AFSOP_START_BKG) {
237 while (afs_initState < AFSOP_START_BKG)
238 afs_osi_Sleep(&afs_initState);
239 if (afs_initState < AFSOP_GO) {
240 afs_initState = AFSOP_GO;
241 afs_osi_Wakeup(&afs_initState);
243 /* start the bkg daemon */
247 afs_BioDaemon(parm2);
250 afs_BackgroundDaemon();
256 else if (parm == AFSOP_START_TRUNCDAEMON) {
257 while (afs_initState < AFSOP_GO)
258 afs_osi_Sleep(&afs_initState);
259 /* start the bkg daemon */
261 afs_CacheTruncateDaemon();
267 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
268 else if (parm == AFSOP_RXEVENT_DAEMON) {
269 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
271 afs_rxevent_daemon();
278 else if (parm == AFSOP_ADDCELL) {
279 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
280 name. Parameter 4 is the length of the name, including the null. Parm 5 is the
281 home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
282 struct afsop_cell tcell;
284 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
285 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
287 if (parm4 > sizeof(tcell.cellName))
290 AFS_COPYIN((char *)parm3, tcell.cellName, parm4, code);
292 afs_NewCell(tcell.cellName, tcell.hosts, parm5,
293 (char *)0, (u_short)0, (u_short)0, (int)0);
296 } else if (parm == AFSOP_ADDCELL2) {
297 struct afsop_cell tcell;
298 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
299 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *cnamep = 0;
300 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
302 #else /* AFS_SGI61_ENV */
304 #endif /* AFS_SGI61_ENV */
307 /* wait for basic init */
308 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
310 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
312 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, &bufferSize, code);
315 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
318 cflags |= CLinkedCell;
322 afs_NewCell(tbuffer1, tcell.hosts, cflags,
323 lcnamep, (u_short)0, (u_short)0, (int)0);
326 osi_FreeSmallSpace(tbuffer);
327 osi_FreeSmallSpace(tbuffer1);
329 else if (parm == AFSOP_CACHEINIT) {
330 struct afs_cacheParams cparms;
332 if (afs_CacheInit_Done) goto out;
334 /* wait for basic init */
335 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
336 AFS_COPYIN((char *)parm2, (caddr_t) &cparms, sizeof(cparms), code);
338 #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)
346 afs_CacheInit_Done = 1;
348 struct afs_icl_log *logp;
349 /* initialize the ICL system */
350 code = afs_icl_CreateLog("cmfx", 60*1024, &logp);
352 code = afs_icl_CreateSetWithFlags("cm", logp,
353 (struct icl_log *) 0,
354 ICL_CRSET_FLAG_DEFAULT_OFF,
356 code = afs_icl_CreateSet("cmlongterm", logp, (struct icl_log*) 0,
357 &afs_iclLongTermSetp);
359 afs_setTime = cparms.setTimeFlag;
361 code = afs_CacheInit(cparms.cacheScaches,
372 else if (parm == AFSOP_CACHEINODE) {
373 ino_t ainode = parm2;
374 /* wait for basic init */
375 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
379 ainode = (ainode << 32) | (parm3 & 0xffffffff);
381 code = afs_InitCacheFile((char *) 0, ainode);
383 else if (parm == AFSOP_ROOTVOLUME) {
384 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
386 #else /* AFS_SGI61_ENV */
388 #endif /* AFS_SGI61_ENV */
390 /* wait for basic init */
391 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
394 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code);
395 afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0;
399 else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO ||
400 parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG) {
401 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
402 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
404 #else /* AFS_SGI61_ENV */
406 #endif /* AFS_SGI61_ENV */
408 /* wait for basic init */
409 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
411 AFS_COPYINSTR((char *)parm2, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
413 osi_FreeSmallSpace(tbuffer);
417 tbuffer[AFS_SMALLOCSIZ-1] = 0; /* null-terminate the name */
418 /* we now have the cache dir copied in. Call the cache init routines */
419 if (parm == AFSOP_CACHEFILE) code = afs_InitCacheFile(tbuffer, 0);
420 else if (parm == AFSOP_CACHEINFO) code = afs_InitCacheInfo(tbuffer);
421 else if (parm == AFSOP_VOLUMEINFO) code = afs_InitVolumeInfo(tbuffer);
423 osi_FreeSmallSpace(tbuffer);
425 else if (parm == AFSOP_GO) {
426 /* the generic initialization calls come here. One parameter: should we do the
427 set-time operation on this workstation */
428 if (afs_Go_Done) goto out;
430 while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState);
433 afs_osi_Wakeup(&afs_initState);
434 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
435 afs_nfsclient_init();
437 printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused,
438 (100*afs_stats_cmperf.cacheFilesReused) /
439 (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1));
441 else if (parm == AFSOP_ADVISEADDR) {
442 /* pass in the host address to the rx package */
443 afs_int32 count = parm2;
444 afs_int32 buffer[AFS_MAX_INTERFACE_ADDR];
445 afs_int32 maskbuffer[AFS_MAX_INTERFACE_ADDR];
446 afs_int32 mtubuffer[AFS_MAX_INTERFACE_ADDR];
450 if ( count > AFS_MAX_INTERFACE_ADDR ) {
452 count = AFS_MAX_INTERFACE_ADDR;
455 AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code);
457 AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code);
459 AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code);
461 afs_cb_interface.numberOfInterfaces = count;
462 for (i=0; i < count ; i++) {
463 afs_cb_interface.addr_in[i] = buffer[i];
464 #ifdef AFS_USERSPACE_IP_ADDR
465 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
466 * machines IP addresses when in the kernel (the in_ifaddr
467 * struct is not available), so we pass the info in at
468 * startup. We also pass in the subnetmask and mtu size. The
469 * subnetmask is used when setting the rank:
470 * afsi_SetServerIPRank(); and the mtu size is used when
471 * finding the best mtu size. rxi_FindIfnet() is replaced
472 * with rxi_Findcbi().
474 afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff);
475 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
478 afs_uuid_create(&afs_cb_interface.uuid);
479 rxi_setaddr(buffer[0]);
483 else if (parm == AFSOP_NFSSTATICADDR) {
484 extern int (*nfs_rfsdisptab_v2)();
485 nfs_rfsdisptab_v2 = (int (*)())parm2;
487 else if (parm == AFSOP_NFSSTATICADDR2) {
488 extern int (*nfs_rfsdisptab_v2)();
490 nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
492 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
495 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
496 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
497 extern int (*afs_sblockp)();
498 extern void (*afs_sbunlockp)();
500 afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
501 afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff));
503 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
504 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
507 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
508 #endif /* AFS_SGI53_ENV */
509 else if (parm == AFSOP_SHUTDOWN) {
510 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
511 extern struct mount *afs_globalVFS;
512 #else /* AFS_OSF_ENV */
513 extern struct vfs *afs_globalVFS;
515 afs_cold_shutdown = 0;
516 if (parm == 1) afs_cold_shutdown = 1;
517 if (afs_globalVFS != 0) {
518 afs_warn("AFS isn't unmounted yet! Call aborted\n");
524 #if ! defined(AFS_HPUX90_ENV) || defined(AFS_HPUX100_ENV)
525 else if (parm == AFSOP_AFS_VFSMOUNT) {
527 #if defined(AFS_HPUX100_ENV)
528 vfsmount(parm2, parm3, parm4, parm5);
530 afs_vfs_mount(parm2, parm3, parm4, parm5);
531 #endif /* AFS_HPUX100_ENV */
532 #else /* defined(AFS_HPUX_ENV) */
533 #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)
538 #endif /* defined(AFS_HPUX_ENV) */
541 else if (parm == AFSOP_CLOSEWAIT) {
542 afs_SynchronousCloses = 'S';
544 else if (parm == AFSOP_GETMTU) {
546 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
547 #ifdef AFS_USERSPACE_IP_ADDR
549 i = rxi_Findcbi(parm2);
550 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
551 #else /* AFS_USERSPACE_IP_ADDR */
553 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
554 extern struct ifnet *rxi_FindIfnet();
556 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
557 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
558 #endif /* else AFS_USERSPACE_IP_ADDR */
559 #endif /* !AFS_SUN5_ENV */
561 AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code);
563 /* this is disabled for now because I can't figure out how to get access
564 * to these kernel variables. It's only for supporting user-mode rx
565 * programs -- it makes a huge difference on the 220's in my testbed,
566 * though I don't know why. The bosserver does this with /etc/no, so it's
567 * being handled a different way for the servers right now. */
570 extern u_long sb_max_dflt;
573 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
574 if (sb_max < 131072) sb_max = 131072;
577 #endif /* AFS_AIX32_ENV */
579 else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
581 #if !defined(AFS_SUN5_ENV)
582 #ifdef AFS_USERSPACE_IP_ADDR
584 i = rxi_Findcbi(parm2);
586 mask = afs_cb_interface.subnetmask[i];
590 #else /* AFS_USERSPACE_IP_ADDR */
592 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
593 extern struct ifnet *rxi_FindIfnet();
594 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
595 if (tifnp && tifadp) {
596 mask = tifadp->ia_subnetmask;
600 #endif /* else AFS_USERSPACE_IP_ADDR */
601 #endif /* !AFS_SUN5_ENV */
603 AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code);
606 else if (parm == AFSOP_AFSDB_HANDLER) {
607 int sizeArg = (int)parm4;
608 int kmsgLen = sizeArg & 0xffff;
609 int cellLen = (sizeArg & 0xffff0000) >> 16;
610 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
611 char *cellname = afs_osi_Alloc(cellLen);
613 AFS_COPYIN((afs_int32 *)parm3, kmsg, kmsgLen, code);
615 code = afs_AfsdbHandler(cellname, cellLen, kmsg);
616 if (*cellname == 1) *cellname = 0;
617 if (code == -2) { /* Shutting down? */
622 if (!code) AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
623 afs_osi_Free(kmsg, kmsgLen);
624 afs_osi_Free(cellname, cellLen);
632 #ifdef AFS_LINUX20_ENV
641 #include "sys/lockl.h"
644 * syscall - this is the VRMIX system call entry point.
647 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
648 * all the user-level calls to `syscall' to change.
650 syscall(syscall, p1, p2, p3, p4, p5, p6) {
651 register rval1=0, code;
654 #ifndef AFS_AIX41_ENV
655 extern lock_t kernel_lock;
656 monster = lockl(&kernel_lock, LOCK_SHORT);
657 #endif /* !AFS_AIX41_ENV */
659 AFS_STATCNT(syscall);
663 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
668 rval1 = afs_setpag();
674 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
678 case AFSCALL_ICREATE:
679 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
683 rval1 = afs_syscall_iopen(p1, p2, p3);
687 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
691 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
696 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
698 if (!code) rval1 = retval;
699 if (!rval1) rval1 = code;
709 #ifndef AFS_AIX41_ENV
710 if (monster != LOCK_NEST)
711 unlockl(&kernel_lock);
712 #endif /* !AFS_AIX41_ENV */
713 return getuerror() ? -1 : rval1;
717 * lsetpag - interface to afs_setpag().
721 AFS_STATCNT(lsetpag);
722 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
726 * lpioctl - interface to pioctl()
728 lpioctl(path, cmd, cmarg, follow)
729 char *path, *cmarg; {
731 AFS_STATCNT(lpioctl);
732 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
735 #else /* !AFS_AIX32_ENV */
737 #if defined(AFS_SGI_ENV)
750 Afs_syscall (struct afsargs *uap, rval_t *rvp)
755 AFS_STATCNT(afs_syscall);
756 switch(uap->syscall) {
760 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
762 rvp->r_val1 = retval;
764 #ifdef AFS_SGI_XFS_IOPS_ENV
766 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
767 uap->parm4, uap->parm5);
770 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
771 uap->parm4, uap->parm5);
773 case AFSCALL_ILISTINODE64:
774 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
775 uap->parm4, uap->parm5);
777 case AFSCALL_ICREATENAME64:
778 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
779 uap->parm4, uap->parm5);
782 #ifdef AFS_SGI_VNODE_GLUE
783 case AFSCALL_INIT_KERNEL_CONFIG:
784 error = afs_init_kernel_config(uap->parm1);
788 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
789 uap->parm3, uap->parm4, uap->parm5);
794 #else /* AFS_SGI_ENV */
812 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
814 dst->param1 = src->param1;
815 dst->param2 = src->param2;
816 dst->param3 = src->param3;
817 dst->param4 = src->param4;
821 * If you need to change copyin_iparam(), you may also need to change
822 * copyin_afs_ioctl().
826 copyin_iparam(caddr_t cmarg, struct iparam *dst)
830 #if defined(AFS_HPUX_64BIT_ENV)
831 struct iparam32 dst32;
833 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
835 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
837 iparam32_to_iparam(&dst32, dst);
840 #endif /* AFS_HPUX_64BIT_ENV */
842 #if defined(AFS_SUN57_64BIT_ENV)
843 struct iparam32 dst32;
845 if (get_udatamodel() == DATAMODEL_ILP32) {
846 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
848 iparam32_to_iparam(&dst32, dst);
851 #endif /* AFS_SUN57_64BIT_ENV */
853 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
854 struct iparam32 dst32;
856 #ifdef AFS_SPARC64_LINUX24_ENV
857 if (current->thread.flags & SPARC_FLAG_32BIT)
858 #elif AFS_SPARC64_LINUX20_ENV
859 if (current->tss.flags & SPARC_FLAG_32BIT)
861 #error Not done for this linux version
862 #endif /* AFS_SPARC64_LINUX20_ENV */
864 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
866 iparam32_to_iparam(&dst32, dst);
869 #endif /* AFS_LINUX_64BIT_KERNEL */
871 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
875 /* Main entry of all afs system calls */
877 extern int afs_sinited;
879 /** The 32 bit OS expects the members of this structure to be 32 bit
880 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
881 * to accomodate both, *long* is used instead of afs_int32
906 Afs_syscall (uap, rvp)
907 register struct afssysa *uap;
910 int *retval = &rvp->r_val1;
911 #else /* AFS_SUN5_ENV */
912 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
913 afs3_syscall(p, args, retval)
926 } *uap = (struct a *)args;
927 #else /* AFS_OSF_ENV */
928 #ifdef AFS_LINUX20_ENV
936 long parm6; /* not actually used - should be removed */
938 /* Linux system calls only set up for 5 arguments. */
939 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
942 struct afssysargs args, *uap = &args;
944 long *retval = &linux_ret;
945 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
958 } *uap = (struct a *)u.u_ap;
960 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
964 #endif /* SUN && !SUN5 */
974 } *uap = (struct a *)u.u_ap;
976 #if defined(AFS_DEC_ENV)
977 int *retval = &u.u_r.r_val1;
979 #if defined(AFS_HPUX_ENV)
980 long *retval = &u.u_rval1;
982 int *retval = &u.u_rval1;
985 #endif /* AFS_LINUX20_ENV */
986 #endif /* AFS_OSF_ENV */
987 #endif /* AFS_SUN5_ENV */
988 register int code = 0;
990 AFS_STATCNT(afs_syscall);
997 #ifdef AFS_LINUX20_ENV
999 /* setup uap for use below - pull out the magic decoder ring to know
1000 * which syscalls have folded argument lists.
1002 uap->syscall = syscall;
1006 if (syscall == AFSCALL_ICL) {
1007 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
1008 uap->parm4 = eparm[0];
1009 uap->parm5 = eparm[1];
1010 uap->parm6 = eparm[2];
1019 #if defined(AFS_HPUX_ENV)
1021 * There used to be code here (duplicated from osi_Init()) for
1022 * initializing the semaphore used by AFS_GLOCK(). Was the
1023 * duplication to handle the case of a dynamically loaded kernel
1028 if (uap->syscall == AFSCALL_CALL) {
1030 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1031 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1033 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1035 } else if (uap->syscall == AFSCALL_SETPAG) {
1038 register proc_t *procp;
1040 procp = ttoproc(curthread);
1041 mutex_enter(&procp->p_crlock);
1042 cred = procp->p_cred;
1044 code = afs_setpag(&cred);
1046 procp->p_cred = cred;
1047 mutex_exit(&procp->p_crlock);
1050 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1051 code = afs_setpag(p, args, retval);
1052 #else /* AFS_OSF_ENV */
1053 code = afs_setpag();
1057 } else if (uap->syscall == AFSCALL_PIOCTL) {
1060 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1062 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1063 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1065 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1069 } else if (uap->syscall == AFSCALL_ICREATE) {
1070 struct iparam iparams;
1072 code = copyin_iparam((char *)uap->parm3, &iparams);
1074 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1079 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1080 iparams.param3, iparams.param4, rvp, CRED());
1082 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1083 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1084 iparams.param3, iparams.param4, retval);
1086 iparams.param3, iparams.param4);
1088 #endif /* AFS_SUN5_ENV */
1089 } else if (uap->syscall == AFSCALL_IOPEN) {
1091 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1093 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1094 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1096 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1098 #endif /* AFS_SUN5_ENV */
1099 } else if (uap->syscall == AFSCALL_IDEC) {
1101 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1103 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1104 #endif /* AFS_SUN5_ENV */
1105 } else if (uap->syscall == AFSCALL_IINC) {
1107 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1109 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1110 #endif /* AFS_SUN5_ENV */
1111 } else if (uap->syscall == AFSCALL_ICL) {
1113 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1115 #ifdef AFS_LINUX20_ENV
1117 /* ICL commands can return values. */
1118 code = -linux_ret; /* Gets negated again at exit below */
1122 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1126 #endif /* !AFS_LINUX20_ENV */
1128 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1132 #endif /* AFS_SUN5_ENV */
1135 #ifdef AFS_LINUX20_ENV
1141 #endif /* AFS_SGI_ENV */
1142 #endif /* !AFS_AIX32_ENV */
1145 * Initstate in the range 0 < x < 100 are early initialization states.
1146 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1147 * the cache may be initialized.
1148 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1149 * is done after all the cache initialization has been done.
1150 * Initstate of 200 means that the volume has been looked up once, possibly
1152 * Initstate of 300 means that the volume has been *successfully* looked up.
1155 register int code = 0;
1157 AFS_STATCNT(afs_CheckInit);
1158 if (afs_initState <= 100)
1159 code = ENXIO; /* never finished init phase */
1160 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1161 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1162 } else if (afs_initState == 200)
1163 code = ETIMEDOUT; /* didn't find root volume */
1167 int afs_shuttingdown = 0;
1171 extern short afs_brsDaemons;
1172 extern afs_int32 afs_CheckServerDaemonStarted;
1173 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1174 extern struct osi_file *afs_cacheInodep;
1176 AFS_STATCNT(afs_shutdown);
1177 if (afs_shuttingdown) return;
1178 afs_shuttingdown = 1;
1179 if (afs_cold_shutdown) afs_warn("COLD ");
1180 else afs_warn("WARM ");
1181 afs_warn("shutting down of: CB... ");
1183 afs_termState = AFSOP_STOP_RXCALLBACK;
1184 rx_WakeupServerProcs();
1185 /* shutdown_rxkernel(); */
1186 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1187 afs_osi_Sleep(&afs_termState);
1189 afs_warn("afs... ");
1190 while (afs_termState == AFSOP_STOP_AFS) {
1191 afs_osi_CancelWait(&AFS_WaitHandler);
1192 afs_osi_Sleep(&afs_termState);
1194 if (afs_CheckServerDaemonStarted) {
1195 while (afs_termState == AFSOP_STOP_CS) {
1196 afs_osi_CancelWait(&AFS_CSWaitHandler);
1197 afs_osi_Sleep(&afs_termState);
1200 afs_warn("BkG... ");
1201 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1202 while (afs_termState == AFSOP_STOP_BKG) {
1203 afs_osi_Wakeup(&afs_brsDaemons);
1204 afs_osi_Sleep(&afs_termState);
1206 afs_warn("CTrunc... ");
1207 /* Cancel cache truncate daemon. */
1208 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1209 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1210 afs_osi_Sleep(&afs_termState);
1212 #ifdef AFS_AFSDB_ENV
1213 afs_warn("AFSDB... ");
1215 while (afs_termState == AFSOP_STOP_AFSDB)
1216 afs_osi_Sleep(&afs_termState);
1218 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1219 afs_warn("RxEvent... ");
1220 /* cancel rx event deamon */
1221 while (afs_termState == AFSOP_STOP_RXEVENT)
1222 afs_osi_Sleep(&afs_termState);
1223 #if defined(RXK_LISTENER_ENV)
1224 afs_warn("RxListener... ");
1225 /* cancel rx listener */
1226 osi_StopListener(); /* This closes rx_socket. */
1227 while (afs_termState == AFSOP_STOP_RXK_LISTENER)
1228 afs_osi_Sleep(&afs_termState);
1231 afs_termState = AFSOP_STOP_COMPLETE;
1235 /* Close file only after daemons which can write to it are stopped. */
1236 if (afs_cacheInodep) /* memcache won't set this */
1238 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1239 afs_cacheInodep = 0;
1241 return; /* Just kill daemons for now */
1245 shutdown_rxkernel();
1249 shutdown_bufferpackage();
1255 shutdown_vnodeops();
1257 shutdown_exporter();
1258 shutdown_memcache();
1259 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1260 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1261 /* this routine does not exist in Ultrix systems... 93.01.19 */
1263 #endif /* AFS_DEC_ENV */
1266 /* The following hold the cm stats */
1268 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1269 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1270 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1272 afs_warn(" ALL allocated tables\n");
1273 afs_shuttingdown = 0;
1279 AFS_STATCNT(shutdown_afstest);
1280 afs_initState = afs_termState = afs_setTime = 0;
1281 AFS_Running = afs_CB_Running = 0;
1282 afs_CacheInit_Done = afs_Go_Done = 0;
1283 if (afs_cold_shutdown) {
1284 *afs_rootVolumeName = 0;
1289 /* In case there is a bunch of dynamically build bkg daemons to free */
1291 { AFS_STATCNT(shutdown_BKG); }
1294 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1295 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1296 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1297 int afs_icl_sizeofLong = 1;
1299 int afs_icl_sizeofLong = 2;
1302 int afs_icl_sizeofLong = 1;
1305 int afs_icl_inited = 0;
1307 /* init function, called once, under afs_icl_lock */
1314 extern struct afs_icl_log *afs_icl_FindLog();
1315 extern struct afs_icl_set *afs_icl_FindSet();
1319 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1322 afs_int32 *lp, elts, flags;
1323 register afs_int32 code;
1324 struct afs_icl_log *logp;
1325 struct afs_icl_set *setp;
1326 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1328 #else /* AFS_SGI61_ENV */
1330 #endif /* AFS_SGI61_ENV */
1332 afs_int32 startCookie;
1333 afs_int32 allocated;
1334 struct afs_icl_log *tlp;
1337 if (!afs_suser(CRED())) { /* only root can run this code */
1341 if (!afs_suser()) { /* only root can run this code */
1342 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1351 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1352 case ICL_OP_COPYOUT: /* copy ouy data */
1353 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1354 * return flags<<24 + nwords.
1355 * updates cookie to updated start (not end) if we had to
1356 * skip some records.
1358 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1359 if (code) return code;
1360 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1361 if (code) return code;
1362 logp = afs_icl_FindLog(tname);
1363 if (!logp) return ENOENT;
1364 #define BUFFERSIZE AFS_LRALLOCSIZ
1365 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1366 elts = BUFFERSIZE / sizeof(afs_int32);
1367 if (p3 < elts) elts = p3;
1368 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1369 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1372 osi_FreeLargeSpace((struct osi_buffer *) lp);
1375 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1376 if (code) goto done;
1377 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1378 if (code) goto done;
1379 *retval = (flags<<24) | (elts & 0xffffff);
1381 afs_icl_LogRele(logp);
1382 osi_FreeLargeSpace((struct osi_buffer *) lp);
1385 case ICL_OP_ENUMLOGS: /* enumerate logs */
1386 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1387 * return 0 for success, otherwise error.
1389 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1390 if (p1-- == 0) break;
1392 if (!tlp) return ENOENT; /* past the end of file */
1393 temp = strlen(tlp->name)+1;
1394 if (temp > p3) return EINVAL;
1395 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1396 if (!code) /* copy out size of log */
1397 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1400 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1401 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1402 * return 0 for success, otherwise error.
1404 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1405 if (code) return code;
1406 setp = afs_icl_FindSet(tname);
1407 if (!setp) return ENOENT;
1408 if (p2 > ICL_LOGSPERSET)
1410 if (!(tlp = setp->logs[p2]))
1412 temp = strlen(tlp->name)+1;
1413 if (temp > p4) return EINVAL;
1414 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1417 case ICL_OP_CLRLOG: /* clear specified log */
1418 /* zero out the specified log: p1=logname */
1419 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1420 if (code) return code;
1421 logp = afs_icl_FindLog(tname);
1422 if (!logp) return ENOENT;
1423 code = afs_icl_ZeroLog(logp);
1424 afs_icl_LogRele(logp);
1427 case ICL_OP_CLRSET: /* clear specified set */
1428 /* zero out the specified set: p1=setname */
1429 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1430 if (code) return code;
1431 setp = afs_icl_FindSet(tname);
1432 if (!setp) return ENOENT;
1433 code = afs_icl_ZeroSet(setp);
1434 afs_icl_SetRele(setp);
1437 case ICL_OP_CLRALL: /* clear all logs */
1438 /* zero out all logs -- no args */
1440 ObtainWriteLock(&afs_icl_lock,178);
1441 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1442 tlp->refCount++; /* hold this guy */
1443 ReleaseWriteLock(&afs_icl_lock);
1444 /* don't clear persistent logs */
1445 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1446 code = afs_icl_ZeroLog(tlp);
1447 ObtainWriteLock(&afs_icl_lock,179);
1448 if (--tlp->refCount == 0)
1449 afs_icl_ZapLog(tlp);
1452 ReleaseWriteLock(&afs_icl_lock);
1455 case ICL_OP_ENUMSETS: /* enumerate all sets */
1456 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1457 * return 0 for success, otherwise error.
1459 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1460 if (p1-- == 0) break;
1462 if (!setp) return ENOENT; /* past the end of file */
1463 temp = strlen(setp->name)+1;
1464 if (temp > p3) return EINVAL;
1465 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1466 if (!code) /* copy out size of log */
1467 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1470 case ICL_OP_SETSTAT: /* set status on a set */
1471 /* activate the specified set: p1=setname, p2=op */
1472 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1473 if (code) return code;
1474 setp = afs_icl_FindSet(tname);
1475 if (!setp) return ENOENT;
1476 code = afs_icl_SetSetStat(setp, p2);
1477 afs_icl_SetRele(setp);
1480 case ICL_OP_SETSTATALL: /* set status on all sets */
1481 /* activate the specified set: p1=op */
1483 ObtainWriteLock(&afs_icl_lock,180);
1484 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1485 setp->refCount++; /* hold this guy */
1486 ReleaseWriteLock(&afs_icl_lock);
1487 /* don't set states on persistent sets */
1488 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1489 code = afs_icl_SetSetStat(setp, p1);
1490 ObtainWriteLock(&afs_icl_lock,181);
1491 if (--setp->refCount == 0)
1492 afs_icl_ZapSet(setp);
1495 ReleaseWriteLock(&afs_icl_lock);
1498 case ICL_OP_SETLOGSIZE: /* set size of log */
1499 /* set the size of the specified log: p1=logname, p2=size (in words) */
1500 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1501 if (code) return code;
1502 logp = afs_icl_FindLog(tname);
1503 if (!logp) return ENOENT;
1504 code = afs_icl_LogSetSize(logp, p2);
1505 afs_icl_LogRele(logp);
1508 case ICL_OP_GETLOGINFO: /* get size of log */
1509 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1510 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1511 if (code) return code;
1512 logp = afs_icl_FindLog(tname);
1513 if (!logp) return ENOENT;
1514 allocated = !!logp->datap;
1515 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1517 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1518 afs_icl_LogRele(logp);
1521 case ICL_OP_GETSETINFO: /* get state of set */
1522 /* zero out the specified set: p1=setname, p2=&state */
1523 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1524 if (code) return code;
1525 setp = afs_icl_FindSet(tname);
1526 if (!setp) return ENOENT;
1527 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1528 afs_icl_SetRele(setp);
1539 afs_lock_t afs_icl_lock;
1541 /* exported routine: a 4 parameter event */
1542 afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, p4)
1543 register struct afs_icl_set *setp;
1546 long p1, p2, p3, p4;
1548 register struct afs_icl_log *logp;
1551 register afs_int32 tmask;
1554 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1555 if (!ICL_SETACTIVE(setp)) return;
1558 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1559 ix = ICL_EVENTBYTE(eventID);
1560 ObtainReadLock(&setp->lock);
1561 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1562 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1564 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1568 if (mask == 0) break; /* break early */
1571 ReleaseReadLock(&setp->lock);
1574 /* Next 4 routines should be implemented via var-args or something.
1575 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1576 * Otherwise, could call afs_icl_Event4 directly.
1578 afs_icl_Event3(setp, eventID, lAndT, p1, p2, p3)
1579 register struct afs_icl_set *setp;
1584 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1587 afs_icl_Event2(setp, eventID, lAndT, p1, p2)
1588 register struct afs_icl_set *setp;
1593 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1596 afs_icl_Event1(setp, eventID, lAndT, p1)
1597 register struct afs_icl_set *setp;
1602 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1605 afs_icl_Event0(setp, eventID, lAndT)
1606 register struct afs_icl_set *setp;
1610 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1613 struct afs_icl_log *afs_icl_allLogs = 0;
1615 /* function to purge records from the start of the log, until there
1616 * is at least minSpace long's worth of space available without
1617 * making the head and the tail point to the same word.
1619 * Log must be write-locked.
1621 static afs_icl_GetLogSpace(logp, minSpace)
1622 register struct afs_icl_log *logp;
1625 register unsigned int tsize;
1627 while (logp->logSize - logp->logElements <= minSpace) {
1629 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1630 logp->logElements -= tsize;
1631 logp->firstUsed += tsize;
1632 if (logp->firstUsed >= logp->logSize)
1633 logp->firstUsed -= logp->logSize;
1634 logp->baseCookie += tsize;
1638 /* append string astr to buffer, including terminating null char.
1640 * log must be write-locked.
1642 #define ICL_CHARSPERLONG 4
1643 static afs_int32 afs_icl_AppendString(logp, astr)
1644 struct afs_icl_log *logp;
1647 char *op; /* ptr to char to write */
1649 register int bib; /* bytes in buffer */
1652 op = (char *) &(logp->datap[logp->firstFree]);
1656 if (++bib >= ICL_CHARSPERLONG) {
1659 if (++(logp->firstFree) >= logp->logSize) {
1660 logp->firstFree = 0;
1661 op = (char *) &(logp->datap[0]);
1663 logp->logElements++;
1668 /* if we've used this word at all, allocate it */
1669 if (++(logp->firstFree) >= logp->logSize) {
1670 logp->firstFree = 0;
1672 logp->logElements++;
1676 /* add a long to the log, ignoring overflow (checked already) */
1677 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1678 #define ICL_APPENDINT32(lp, x) \
1680 (lp)->datap[(lp)->firstFree] = (x); \
1681 if (++((lp)->firstFree) >= (lp)->logSize) { \
1682 (lp)->firstFree = 0; \
1684 (lp)->logElements++; \
1687 #define ICL_APPENDLONG(lp, x) \
1689 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1690 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1693 #else /* AFS_ALPHA_ENV */
1694 #define ICL_APPENDLONG(lp, x) \
1696 (lp)->datap[(lp)->firstFree] = (x); \
1697 if (++((lp)->firstFree) >= (lp)->logSize) { \
1698 (lp)->firstFree = 0; \
1700 (lp)->logElements++; \
1702 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1703 #endif /* AFS_ALPHA_ENV */
1705 /* routine to tell whether we're dealing with the address or the
1708 afs_icl_UseAddr(type)
1711 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1712 || type == ICL_TYPE_FID)
1718 /* Function to append a record to the log. Written for speed
1719 * since we know that we're going to have to make this work fast
1720 * pretty soon, anyway. The log must be unlocked.
1723 afs_icl_AppendRecord(logp, op, types, p1, p2, p3, p4)
1724 register struct afs_icl_log *logp;
1727 long p1, p2, p3, p4;
1729 int rsize; /* record size in longs */
1730 register int tsize; /* temp size */
1734 t4 = types & 0x3f; /* decode types */
1742 osi_GetTime(&tv); /* It panics for solaris if inside */
1743 ObtainWriteLock(&logp->lock,182);
1745 ReleaseWriteLock(&logp->lock);
1749 /* get timestamp as # of microseconds since some time that doesn't
1750 * change that often. This algorithm ticks over every 20 minutes
1751 * or so (1000 seconds). Write a timestamp record if it has.
1753 if (tv.tv_sec - logp->lastTS > 1024)
1755 /* the timer has wrapped -- write a timestamp record */
1756 if (logp->logSize - logp->logElements <= 5)
1757 afs_icl_GetLogSpace(logp, 5);
1759 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1760 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1761 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1762 ICL_APPENDINT32(logp,
1763 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1764 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1766 logp->lastTS = tv.tv_sec;
1769 rsize = 4; /* base case */
1771 /* compute size of parameter p1. Only tricky case is string.
1772 * In that case, we have to call strlen to get the string length.
1774 ICL_SIZEHACK(t1, p1);
1777 /* compute size of parameter p2. Only tricky case is string.
1778 * In that case, we have to call strlen to get the string length.
1780 ICL_SIZEHACK(t2, p2);
1783 /* compute size of parameter p3. Only tricky case is string.
1784 * In that case, we have to call strlen to get the string length.
1786 ICL_SIZEHACK(t3, p3);
1789 /* compute size of parameter p4. Only tricky case is string.
1790 * In that case, we have to call strlen to get the string length.
1792 ICL_SIZEHACK(t4, p4);
1795 /* At this point, we've computed all of the parameter sizes, and
1796 * have in rsize the size of the entire record we want to append.
1797 * Next, we check that we actually have room in the log to do this
1798 * work, and then we do the append.
1801 ReleaseWriteLock(&logp->lock);
1802 return; /* log record too big to express */
1805 if (logp->logSize - logp->logElements <= rsize)
1806 afs_icl_GetLogSpace(logp, rsize);
1808 ICL_APPENDINT32(logp,
1809 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
1810 ICL_APPENDINT32(logp, (afs_int32)op);
1811 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
1812 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1815 /* marshall parameter 1 now */
1816 if (t1 == ICL_TYPE_STRING) {
1817 afs_icl_AppendString(logp, (char *) p1);
1819 else if (t1 == ICL_TYPE_HYPER) {
1820 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
1821 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
1823 else if (t1 == ICL_TYPE_FID) {
1824 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1825 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1826 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
1827 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
1829 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1830 else if (t1 == ICL_TYPE_INT32)
1831 ICL_APPENDINT32(logp, (afs_int32)p1);
1832 #endif /* AFS_ALPHA_ENV */
1833 else ICL_APPENDLONG(logp, p1);
1836 /* marshall parameter 2 now */
1837 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
1838 else if (t2 == ICL_TYPE_HYPER) {
1839 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
1840 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
1842 else if (t2 == ICL_TYPE_FID) {
1843 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1844 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1845 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
1846 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
1848 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1849 else if (t2 == ICL_TYPE_INT32)
1850 ICL_APPENDINT32(logp, (afs_int32)p2);
1851 #endif /* AFS_ALPHA_ENV */
1852 else ICL_APPENDLONG(logp, p2);
1855 /* marshall parameter 3 now */
1856 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
1857 else if (t3 == ICL_TYPE_HYPER) {
1858 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
1859 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
1861 else if (t3 == ICL_TYPE_FID) {
1862 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1863 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1864 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
1865 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
1867 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1868 else if (t3 == ICL_TYPE_INT32)
1869 ICL_APPENDINT32(logp, (afs_int32)p3);
1870 #endif /* AFS_ALPHA_ENV */
1871 else ICL_APPENDLONG(logp, p3);
1874 /* marshall parameter 4 now */
1875 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
1876 else if (t4 == ICL_TYPE_HYPER) {
1877 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
1878 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
1880 else if (t4 == ICL_TYPE_FID) {
1881 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
1882 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
1883 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
1884 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
1886 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1887 else if (t4 == ICL_TYPE_INT32)
1888 ICL_APPENDINT32(logp, (afs_int32)p4);
1889 #endif /* AFS_ALPHA_ENV */
1890 else ICL_APPENDLONG(logp, p4);
1892 ReleaseWriteLock(&logp->lock);
1895 /* create a log with size logSize; return it in *outLogpp and tag
1896 * it with name "name."
1898 afs_icl_CreateLog(name, logSize, outLogpp)
1901 struct afs_icl_log **outLogpp;
1903 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
1906 /* create a log with size logSize; return it in *outLogpp and tag
1907 * it with name "name." 'flags' can be set to make the log unclearable.
1909 afs_icl_CreateLogWithFlags(name, logSize, flags, outLogpp)
1913 struct afs_icl_log **outLogpp;
1915 register struct afs_icl_log *logp;
1917 /* add into global list under lock */
1918 ObtainWriteLock(&afs_icl_lock,183);
1919 if (!afs_icl_inited) afs_icl_Init();
1921 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
1922 if (strcmp(logp->name, name) == 0) {
1923 /* found it already created, just return it */
1926 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
1928 ObtainWriteLock(&logp->lock,184);
1929 logp->states |= ICL_LOGF_PERSISTENT;
1930 ReleaseWriteLock(&logp->lock);
1932 ReleaseWriteLock(&afs_icl_lock);
1937 logp = (struct afs_icl_log *)
1938 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
1939 memset((caddr_t)logp, 0, sizeof(*logp));
1942 logp->name = osi_AllocSmallSpace(strlen(name)+1);
1943 strcpy(logp->name, name);
1944 LOCK_INIT(&logp->lock, "logp lock");
1945 logp->logSize = logSize;
1946 logp->datap = (afs_int32 *)0; /* don't allocate it until we need it */
1948 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
1949 logp->states |= ICL_LOGF_PERSISTENT;
1951 logp->nextp = afs_icl_allLogs;
1952 afs_icl_allLogs = logp;
1953 ReleaseWriteLock(&afs_icl_lock);
1959 /* called with a log, a pointer to a buffer, the size of the buffer
1960 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
1961 * and returns data in the provided buffer, and returns output flags
1962 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
1963 * find the record with cookie value cookie.
1965 afs_icl_CopyOut(logp, bufferp, bufSizep, cookiep, flagsp)
1966 register struct afs_icl_log *logp;
1968 afs_int32 *bufSizep;
1969 afs_uint32 *cookiep;
1972 afs_int32 nwords; /* number of words to copy out */
1973 afs_uint32 startCookie; /* first cookie to use */
1974 register afs_int32 i;
1975 afs_int32 outWords; /* words we've copied out */
1976 afs_int32 inWords; /* max words to copy out */
1977 afs_int32 code; /* return code */
1978 afs_int32 ix; /* index we're copying from */
1979 afs_int32 outFlags; /* return flags */
1980 afs_int32 inFlags; /* flags passed in */
1983 inWords = *bufSizep; /* max to copy out */
1984 outWords = 0; /* amount copied out */
1985 startCookie = *cookiep;
1990 ObtainWriteLock(&logp->lock,185);
1992 ReleaseWriteLock(&logp->lock);
1996 /* first, compute the index of the start cookie we've been passed */
1998 /* (re-)compute where we should start */
1999 if (startCookie < logp->baseCookie) {
2000 if (startCookie) /* missed some output */
2001 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2002 /* skip to the first available record */
2003 startCookie = logp->baseCookie;
2004 *cookiep = startCookie;
2007 /* compute where we find the first element to copy out */
2008 ix = logp->firstUsed + startCookie - logp->baseCookie;
2009 if (ix >= logp->logSize) ix -= logp->logSize;
2011 /* if have some data now, break out and process it */
2012 if (startCookie - logp->baseCookie < logp->logElements) break;
2014 /* At end of log, so clear it if we need to */
2015 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
2017 logp->firstUsed = logp->firstFree = 0;
2018 logp->logElements = 0;
2020 /* otherwise, either wait for the data to arrive, or return */
2021 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2022 ReleaseWriteLock(&logp->lock);
2026 logp->states |= ICL_LOGF_WAITING;
2027 ReleaseWriteLock(&logp->lock);
2028 afs_osi_Sleep(&logp->lock);
2029 ObtainWriteLock(&logp->lock,186);
2031 /* copy out data from ix to logSize or firstFree, depending
2032 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2033 * be careful not to copy out more than nwords.
2035 if (ix >= logp->firstUsed) {
2036 if (logp->firstUsed <= logp->firstFree)
2038 end = logp->firstFree; /* first element not to copy */
2040 end = logp->logSize;
2041 nwords = inWords; /* don't copy more than this */
2042 if (end - ix < nwords)
2045 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2050 /* if we're going to copy more out below, we'll start here */
2053 /* now, if active part of the log has wrapped, there's more stuff
2054 * starting at the head of the log. Copy out more from there.
2056 if (logp->firstUsed > logp->firstFree
2057 && ix < logp->firstFree && inWords > 0) {
2058 /* (more to) copy out from the wrapped section at the
2059 * start of the log. May get here even if didn't copy any
2060 * above, if the cookie points directly into the wrapped section.
2063 if (logp->firstFree - ix < nwords)
2064 nwords = logp->firstFree - ix;
2065 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2071 ReleaseWriteLock(&logp->lock);
2075 *bufSizep = outWords;
2081 /* return basic parameter information about a log */
2082 afs_icl_GetLogParms(logp, maxSizep, curSizep)
2083 struct afs_icl_log *logp;
2084 afs_int32 *maxSizep;
2085 afs_int32 *curSizep;
2087 ObtainReadLock(&logp->lock);
2088 *maxSizep = logp->logSize;
2089 *curSizep = logp->logElements;
2090 ReleaseReadLock(&logp->lock);
2095 /* hold and release logs */
2096 afs_icl_LogHold(logp)
2097 register struct afs_icl_log *logp;
2099 ObtainWriteLock(&afs_icl_lock,187);
2101 ReleaseWriteLock(&afs_icl_lock);
2105 /* hold and release logs, called with lock already held */
2106 afs_icl_LogHoldNL(logp)
2107 register struct afs_icl_log *logp;
2113 /* keep track of how many sets believe the log itself is allocated */
2114 afs_icl_LogUse(logp)
2115 register struct afs_icl_log *logp;
2117 ObtainWriteLock(&logp->lock,188);
2118 if (logp->setCount == 0) {
2119 /* this is the first set actually using the log -- allocate it */
2120 if (logp->logSize == 0) {
2121 /* we weren't passed in a hint and it wasn't set */
2122 logp->logSize = ICL_DEFAULT_LOGSIZE;
2124 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2125 #ifdef AFS_AIX32_ENV
2126 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2130 ReleaseWriteLock(&logp->lock);
2134 /* decrement the number of real users of the log, free if possible */
2135 afs_icl_LogFreeUse(logp)
2136 register struct afs_icl_log *logp;
2138 ObtainWriteLock(&logp->lock,189);
2139 if (--logp->setCount == 0) {
2140 /* no more users -- free it (but keep log structure around)*/
2141 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2142 #ifdef AFS_AIX32_ENV
2143 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2145 logp->firstUsed = logp->firstFree = 0;
2146 logp->logElements = 0;
2147 logp->datap = (afs_int32 *)0;
2149 ReleaseWriteLock(&logp->lock);
2153 /* set the size of the log to 'logSize' */
2154 afs_icl_LogSetSize(logp, logSize)
2155 register struct afs_icl_log *logp;
2158 ObtainWriteLock(&logp->lock,190);
2160 /* nothing to worry about since it's not allocated */
2161 logp->logSize = logSize;
2165 logp->firstUsed = logp->firstFree = 0;
2166 logp->logElements = 0;
2168 /* free and allocate a new one */
2169 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2170 #ifdef AFS_AIX32_ENV
2171 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2173 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2174 #ifdef AFS_AIX32_ENV
2175 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2177 logp->logSize = logSize;
2179 ReleaseWriteLock(&logp->lock);
2184 /* free a log. Called with afs_icl_lock locked. */
2185 afs_icl_ZapLog(logp)
2186 register struct afs_icl_log *logp;
2188 register struct afs_icl_log **lpp, *tp;
2190 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2192 /* found the dude we want to remove */
2194 osi_FreeSmallSpace(logp->name);
2195 osi_FreeSmallSpace(logp->datap);
2196 osi_FreeSmallSpace(logp);
2197 break; /* won't find it twice */
2203 /* do the release, watching for deleted entries */
2204 afs_icl_LogRele(logp)
2205 register struct afs_icl_log *logp;
2207 ObtainWriteLock(&afs_icl_lock,191);
2208 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2209 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2211 ReleaseWriteLock(&afs_icl_lock);
2215 /* do the release, watching for deleted entries, log already held */
2216 afs_icl_LogReleNL(logp)
2217 register struct afs_icl_log *logp;
2219 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2220 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2225 /* zero out the log */
2226 afs_icl_ZeroLog(logp)
2227 register struct afs_icl_log *logp;
2229 ObtainWriteLock(&logp->lock,192);
2230 logp->firstUsed = logp->firstFree = 0;
2231 logp->logElements = 0;
2232 logp->baseCookie = 0;
2233 ReleaseWriteLock(&logp->lock);
2237 /* free a log entry, and drop its reference count */
2238 afs_icl_LogFree(logp)
2239 register struct afs_icl_log *logp;
2241 ObtainWriteLock(&logp->lock,193);
2242 logp->states |= ICL_LOGF_DELETED;
2243 ReleaseWriteLock(&logp->lock);
2244 afs_icl_LogRele(logp);
2248 /* find a log by name, returning it held */
2249 struct afs_icl_log *afs_icl_FindLog(name)
2252 register struct afs_icl_log *tp;
2253 ObtainWriteLock(&afs_icl_lock,194);
2254 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2255 if (strcmp(tp->name, name) == 0) {
2256 /* this is the dude we want */
2261 ReleaseWriteLock(&afs_icl_lock);
2265 afs_icl_EnumerateLogs(aproc, arock)
2269 register struct afs_icl_log *tp;
2270 register afs_int32 code;
2273 ObtainWriteLock(&afs_icl_lock,195);
2274 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2275 tp->refCount++; /* hold this guy */
2276 ReleaseWriteLock(&afs_icl_lock);
2277 ObtainReadLock(&tp->lock);
2278 code = (*aproc)(tp->name, arock, tp);
2279 ReleaseReadLock(&tp->lock);
2280 ObtainWriteLock(&afs_icl_lock,196);
2281 if (--tp->refCount == 0)
2285 ReleaseWriteLock(&afs_icl_lock);
2289 struct afs_icl_set *afs_icl_allSets = 0;
2291 afs_icl_CreateSet(name, baseLogp, fatalLogp, outSetpp)
2293 struct afs_icl_log *baseLogp;
2294 struct afs_icl_log *fatalLogp;
2295 struct afs_icl_set **outSetpp;
2297 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2298 /*flags*/0, outSetpp);
2301 /* create a set, given pointers to base and fatal logs, if any.
2302 * Logs are unlocked, but referenced, and *outSetpp is returned
2303 * referenced. Function bumps reference count on logs, since it
2304 * addds references from the new afs_icl_set. When the set is destroyed,
2305 * those references will be released.
2307 afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp)
2309 struct afs_icl_log *baseLogp;
2310 struct afs_icl_log *fatalLogp;
2312 struct afs_icl_set **outSetpp;
2314 register struct afs_icl_set *setp;
2316 afs_int32 states = ICL_DEFAULT_SET_STATES;
2318 ObtainWriteLock(&afs_icl_lock,197);
2319 if (!afs_icl_inited) afs_icl_Init();
2321 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2322 if (strcmp(setp->name, name) == 0) {
2325 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2327 ObtainWriteLock(&setp->lock,198);
2328 setp->states |= ICL_SETF_PERSISTENT;
2329 ReleaseWriteLock(&setp->lock);
2331 ReleaseWriteLock(&afs_icl_lock);
2336 /* determine initial state */
2337 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2338 states = ICL_SETF_ACTIVE;
2339 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2340 states = ICL_SETF_FREED;
2341 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2342 states |= ICL_SETF_PERSISTENT;
2344 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2345 memset((caddr_t)setp, 0, sizeof(*setp));
2347 if (states & ICL_SETF_FREED)
2348 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2349 setp->states = states;
2351 LOCK_INIT(&setp->lock, "setp lock");
2352 /* next lock is obtained in wrong order, hierarchy-wise, but
2353 * it doesn't matter, since no one can find this lock yet, since
2354 * the afs_icl_lock is still held, and thus the obtain can't block.
2356 ObtainWriteLock(&setp->lock,199);
2357 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2358 strcpy(setp->name, name);
2359 setp->nevents = ICL_DEFAULTEVENTS;
2360 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2361 #ifdef AFS_AIX32_ENV
2362 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2364 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2365 setp->eventFlags[i] = 0xff; /* default to enabled */
2367 /* update this global info under the afs_icl_lock */
2368 setp->nextp = afs_icl_allSets;
2369 afs_icl_allSets = setp;
2370 ReleaseWriteLock(&afs_icl_lock);
2372 /* set's basic lock is still held, so we can finish init */
2374 setp->logs[0] = baseLogp;
2375 afs_icl_LogHold(baseLogp);
2376 if (!(setp->states & ICL_SETF_FREED))
2377 afs_icl_LogUse(baseLogp); /* log is actually being used */
2380 setp->logs[1] = fatalLogp;
2381 afs_icl_LogHold(fatalLogp);
2382 if (!(setp->states & ICL_SETF_FREED))
2383 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2385 ReleaseWriteLock(&setp->lock);
2391 /* function to change event enabling information for a particular set */
2392 afs_icl_SetEnable(setp, eventID, setValue)
2393 struct afs_icl_set *setp;
2399 ObtainWriteLock(&setp->lock,200);
2400 if (!ICL_EVENTOK(setp, eventID)) {
2401 ReleaseWriteLock(&setp->lock);
2404 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2406 *tp |= ICL_EVENTMASK(eventID);
2408 *tp &= ~(ICL_EVENTMASK(eventID));
2409 ReleaseWriteLock(&setp->lock);
2413 /* return indication of whether a particular event ID is enabled
2414 * for tracing. If *getValuep is set to 0, the event is disabled,
2415 * otherwise it is enabled. All events start out enabled by default.
2417 afs_icl_GetEnable(setp, eventID, getValuep)
2418 struct afs_icl_set *setp;
2422 ObtainReadLock(&setp->lock);
2423 if (!ICL_EVENTOK(setp, eventID)) {
2424 ReleaseWriteLock(&setp->lock);
2427 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2431 ReleaseReadLock(&setp->lock);
2435 /* hold and release event sets */
2436 afs_icl_SetHold(setp)
2437 register struct afs_icl_set *setp;
2439 ObtainWriteLock(&afs_icl_lock,201);
2441 ReleaseWriteLock(&afs_icl_lock);
2445 /* free a set. Called with afs_icl_lock locked */
2446 afs_icl_ZapSet(setp)
2447 register struct afs_icl_set *setp;
2449 register struct afs_icl_set **lpp, *tp;
2451 register struct afs_icl_log *tlp;
2453 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2455 /* found the dude we want to remove */
2457 osi_FreeSmallSpace(setp->name);
2458 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2459 #ifdef AFS_AIX32_ENV
2460 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2462 for(i=0; i < ICL_LOGSPERSET; i++) {
2463 if (tlp = setp->logs[i])
2464 afs_icl_LogReleNL(tlp);
2466 osi_FreeSmallSpace(setp);
2467 break; /* won't find it twice */
2473 /* do the release, watching for deleted entries */
2474 afs_icl_SetRele(setp)
2475 register struct afs_icl_set *setp;
2477 ObtainWriteLock(&afs_icl_lock,202);
2478 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2479 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2481 ReleaseWriteLock(&afs_icl_lock);
2485 /* free a set entry, dropping its reference count */
2486 afs_icl_SetFree(setp)
2487 register struct afs_icl_set *setp;
2489 ObtainWriteLock(&setp->lock,203);
2490 setp->states |= ICL_SETF_DELETED;
2491 ReleaseWriteLock(&setp->lock);
2492 afs_icl_SetRele(setp);
2496 /* find a set by name, returning it held */
2497 struct afs_icl_set *afs_icl_FindSet(name)
2500 register struct afs_icl_set *tp;
2501 ObtainWriteLock(&afs_icl_lock,204);
2502 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2503 if (strcmp(tp->name, name) == 0) {
2504 /* this is the dude we want */
2509 ReleaseWriteLock(&afs_icl_lock);
2513 /* zero out all the logs in the set */
2514 afs_icl_ZeroSet(setp)
2515 struct afs_icl_set *setp;
2520 struct afs_icl_log *logp;
2522 ObtainReadLock(&setp->lock);
2523 for(i = 0; i < ICL_LOGSPERSET; i++) {
2524 logp = setp->logs[i];
2526 afs_icl_LogHold(logp);
2527 tcode = afs_icl_ZeroLog(logp);
2528 if (tcode != 0) code = tcode; /* save the last bad one */
2529 afs_icl_LogRele(logp);
2532 ReleaseReadLock(&setp->lock);
2536 afs_icl_EnumerateSets(aproc, arock)
2540 register struct afs_icl_set *tp, *np;
2541 register afs_int32 code;
2544 ObtainWriteLock(&afs_icl_lock,205);
2545 for(tp = afs_icl_allSets; tp; tp=np) {
2546 tp->refCount++; /* hold this guy */
2547 ReleaseWriteLock(&afs_icl_lock);
2548 code = (*aproc)(tp->name, arock, tp);
2549 ObtainWriteLock(&afs_icl_lock,206);
2550 np = tp->nextp; /* tp may disappear next, but not np */
2551 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2555 ReleaseWriteLock(&afs_icl_lock);
2559 afs_icl_AddLogToSet(setp, newlogp)
2560 struct afs_icl_set *setp;
2561 struct afs_icl_log *newlogp;
2565 struct afs_icl_log *logp;
2567 ObtainWriteLock(&setp->lock,207);
2568 for(i = 0; i < ICL_LOGSPERSET; i++) {
2569 if (!setp->logs[i]) {
2570 setp->logs[i] = newlogp;
2572 afs_icl_LogHold(newlogp);
2573 if (!(setp->states & ICL_SETF_FREED)) {
2574 /* bump up the number of sets using the log */
2575 afs_icl_LogUse(newlogp);
2580 ReleaseWriteLock(&setp->lock);
2584 afs_icl_SetSetStat(setp, op)
2585 struct afs_icl_set *setp;
2590 struct afs_icl_log *logp;
2592 ObtainWriteLock(&setp->lock,208);
2594 case ICL_OP_SS_ACTIVATE: /* activate a log */
2596 * If we are not already active, see if we have released
2597 * our demand that the log be allocated (FREED set). If
2598 * we have, reassert our desire.
2600 if (!(setp->states & ICL_SETF_ACTIVE)) {
2601 if (setp->states & ICL_SETF_FREED) {
2602 /* have to reassert desire for logs */
2603 for(i = 0; i < ICL_LOGSPERSET; i++) {
2604 logp = setp->logs[i];
2606 afs_icl_LogHold(logp);
2607 afs_icl_LogUse(logp);
2608 afs_icl_LogRele(logp);
2611 setp->states &= ~ICL_SETF_FREED;
2613 setp->states |= ICL_SETF_ACTIVE;
2618 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2619 /* this doesn't require anything beyond clearing the ACTIVE flag */
2620 setp->states &= ~ICL_SETF_ACTIVE;
2624 case ICL_OP_SS_FREE: /* deassert design for log */
2626 * if we are already in this state, do nothing; otherwise
2627 * deassert desire for log
2629 if (setp->states & ICL_SETF_ACTIVE)
2632 if (!(setp->states & ICL_SETF_FREED)) {
2633 for(i = 0; i < ICL_LOGSPERSET; i++) {
2634 logp = setp->logs[i];
2636 afs_icl_LogHold(logp);
2637 afs_icl_LogFreeUse(logp);
2638 afs_icl_LogRele(logp);
2641 setp->states |= ICL_SETF_FREED;
2650 ReleaseWriteLock(&setp->lock);