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;
86 static int afs_InitSetup_done = 0;
89 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval);
91 #if defined(AFS_HPUX_ENV)
92 extern int afs_vfs_mount();
93 #endif /* defined(AFS_HPUX_ENV) */
95 /* This is code which needs to be called once when the first daemon enters
96 * the client. A non-zero return means an error and AFS should not start.
98 static int afs_InitSetup(int preallocs)
100 extern void afs_InitStats();
103 if (afs_InitSetup_done)
108 * Set up all the AFS statistics variables. This should be done
109 * exactly once, and it should be done here, the first resource-setting
110 * routine to be called by the CM/RX.
113 #endif /* AFS_NOSTATS */
115 memset(afs_zeros, 0, AFS_ZEROS);
118 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
119 code = rx_Init(htons(7001));
121 printf("AFS: RX failed to initialize.\n");
124 rx_SetRxDeadTime(AFS_RXDEADTIME);
125 /* resource init creates the services */
126 afs_ResourceInit(preallocs);
128 afs_InitSetup_done = 1;
129 afs_osi_Wakeup(&afs_InitSetup_done);
134 /* leaving as is, probably will barf if we add prototypes here since it's likely being called
136 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
137 long parm, parm2, parm3, parm4, parm5, parm6;
140 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
142 #else /* AFS_SGI61_ENV */
144 #endif /* AFS_SGI61_ENV */
146 AFS_STATCNT(afs_syscall_call);
148 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
149 && (parm != AFSOP_GETMASK)) {
150 /* only root can run this code */
153 if (!afs_suser() && (parm != AFSOP_GETMTU)
154 && (parm != AFSOP_GETMASK)) {
155 /* only root can run this code */
156 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
160 #if defined(AFS_OSF_ENV)
162 #else /* AFS_OSF_ENV */
169 if (parm == AFSOP_START_RXCALLBACK) {
170 if (afs_CB_Running) goto out;
172 #ifndef RXK_LISTENER_ENV
173 code = afs_InitSetup(parm2);
175 #endif /* RXK_LISTENER_ENV */
177 #ifdef RXK_LISTENER_ENV
178 while (afs_RX_Running != 2)
179 afs_osi_Sleep(&afs_RX_Running);
181 afs_initState = AFSOP_START_AFS;
182 afs_osi_Wakeup(&afs_initState);
183 #endif /* RXK_LISTENER_ENV */
185 afs_RXCallBackServer();
189 exit(CLD_EXITED, code);
192 #ifdef RXK_LISTENER_ENV
193 else if (parm == AFSOP_RXLISTENER_DAEMON) {
194 if (afs_RX_Running) goto out;
196 code = afs_InitSetup(parm2);
198 rx_enablePeerRPCStats();
201 rx_enableProcessRPCStats();
204 afs_initState = AFSOP_START_AFS;
205 afs_osi_Wakeup(&afs_initState);
208 afs_osi_Wakeup(&afs_RX_Running);
210 afs_osi_RxkRegister();
216 exit(CLD_EXITED, code);
220 else if (parm == AFSOP_BASIC_INIT) {
223 while (!afs_InitSetup_done)
224 afs_osi_Sleep(&afs_InitSetup_done);
226 #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)
227 temp = AFS_MINBUFFERS; /* Should fix this soon */
229 /* number of 2k buffers we could get from all of the buffer space */
230 temp = ((afs_bufferpages * NBPG)>>11);
231 temp = temp>>2; /* don't take more than 25% (our magic parameter) */
232 if (temp < AFS_MINBUFFERS)
233 temp = AFS_MINBUFFERS; /* though we really should have this many */
236 afs_rootFid.Fid.Volume = 0;
239 else if (parm == AFSOP_START_AFS) {
241 if (AFS_Running) goto out;
243 while (afs_initState < AFSOP_START_AFS)
244 afs_osi_Sleep(&afs_initState);
246 afs_initState = AFSOP_START_BKG;
247 afs_osi_Wakeup(&afs_initState);
255 else if (parm == AFSOP_START_CS) {
257 afs_CheckServerDaemon();
263 else if (parm == AFSOP_START_BKG) {
264 while (afs_initState < AFSOP_START_BKG)
265 afs_osi_Sleep(&afs_initState);
266 if (afs_initState < AFSOP_GO) {
267 afs_initState = AFSOP_GO;
268 afs_osi_Wakeup(&afs_initState);
270 /* start the bkg daemon */
274 afs_BioDaemon(parm2);
277 afs_BackgroundDaemon();
283 else if (parm == AFSOP_START_TRUNCDAEMON) {
284 while (afs_initState < AFSOP_GO)
285 afs_osi_Sleep(&afs_initState);
286 /* start the bkg daemon */
288 afs_CacheTruncateDaemon();
294 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
295 else if (parm == AFSOP_RXEVENT_DAEMON) {
296 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
298 afs_rxevent_daemon();
305 else if (parm == AFSOP_ADDCELL) {
306 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
307 name. Parameter 4 is the length of the name, including the null. Parm 5 is the
308 home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
309 struct afsop_cell tcell;
311 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
313 if (parm4 > sizeof(tcell.cellName))
316 AFS_COPYIN((char *)parm3, tcell.cellName, parm4, code);
318 afs_NewCell(tcell.cellName, tcell.hosts, parm5,
322 } else if (parm == AFSOP_ADDCELL2) {
323 struct afsop_cell tcell;
324 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
325 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *cnamep = 0;
328 /* wait for basic init */
329 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
331 AFS_COPYIN((char *)parm2, (char *)tcell.hosts, sizeof(tcell.hosts), code);
333 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ, &bufferSize, code);
336 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ, &bufferSize, code);
339 cflags |= CLinkedCell;
343 code = afs_NewCell(tbuffer1, tcell.hosts, cflags,
347 osi_FreeSmallSpace(tbuffer);
348 osi_FreeSmallSpace(tbuffer1);
350 else if (parm == AFSOP_ADDCELLALIAS) {
353 * parm2 is the alias name
354 * parm3 is the real cell name
356 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
357 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
359 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize, code);
360 if (!code) AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ, &bufferSize, code);
361 if (!code) afs_NewCellAlias(aliasName, cellName);
362 osi_FreeSmallSpace(aliasName);
363 osi_FreeSmallSpace(cellName);
365 else if (parm == AFSOP_SET_THISCELL) {
368 * parm2 is the primary cell name
370 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
372 AFS_COPYINSTR((char *) parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code);
374 afs_SetPrimaryCell(cell);
375 osi_FreeSmallSpace(cell);
377 else if (parm == AFSOP_CACHEINIT) {
378 struct afs_cacheParams cparms;
380 if (afs_CacheInit_Done) goto out;
382 AFS_COPYIN((char *)parm2, (caddr_t) &cparms, sizeof(cparms), code);
384 #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)
392 afs_CacheInit_Done = 1;
394 struct afs_icl_log *logp;
395 /* initialize the ICL system */
396 code = afs_icl_CreateLog("cmfx", 60*1024, &logp);
398 code = afs_icl_CreateSetWithFlags("cm", logp,
399 (struct icl_log *) 0,
400 ICL_CRSET_FLAG_DEFAULT_OFF,
402 code = afs_icl_CreateSet("cmlongterm", logp, (struct icl_log*) 0,
403 &afs_iclLongTermSetp);
405 afs_setTime = cparms.setTimeFlag;
407 code = afs_CacheInit(cparms.cacheScaches,
418 else if (parm == AFSOP_CACHEINODE) {
419 ino_t ainode = parm2;
420 /* wait for basic init */
421 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
425 ainode = (ainode << 32) | (parm3 & 0xffffffff);
427 code = afs_InitCacheFile(NULL, ainode);
429 else if (parm == AFSOP_ROOTVOLUME) {
430 /* wait for basic init */
431 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
434 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code);
435 afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0;
439 else if (parm == AFSOP_CACHEFILE ||
440 parm == AFSOP_CACHEINFO ||
441 parm == AFSOP_VOLUMEINFO ||
442 parm == AFSOP_AFSLOG ||
443 parm == AFSOP_CELLINFO) {
444 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
447 AFS_COPYINSTR((char *) parm2, tbuffer, AFS_SMALLOCSIZ,
450 osi_FreeSmallSpace(tbuffer);
454 tbuffer[AFS_SMALLOCSIZ-1] = '\0'; /* null-terminate the name */
455 /* We have the cache dir copied in. Call the cache init routine */
456 if (parm == AFSOP_CACHEFILE)
457 code = afs_InitCacheFile(tbuffer, 0);
458 else if (parm == AFSOP_CACHEINFO)
459 code = afs_InitCacheInfo(tbuffer);
460 else if (parm == AFSOP_VOLUMEINFO)
461 code = afs_InitVolumeInfo(tbuffer);
462 else if (parm == AFSOP_CELLINFO)
463 code = afs_InitCellInfo(tbuffer);
465 osi_FreeSmallSpace(tbuffer);
467 else if (parm == AFSOP_GO) {
468 /* the generic initialization calls come here. One parameter: should we do the
469 set-time operation on this workstation */
470 if (afs_Go_Done) goto out;
472 while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState);
475 afs_osi_Wakeup(&afs_initState);
476 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
477 afs_nfsclient_init();
479 printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused,
480 (100*afs_stats_cmperf.cacheFilesReused) /
481 (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1));
483 else if (parm == AFSOP_ADVISEADDR) {
484 /* pass in the host address to the rx package */
485 afs_int32 count = parm2;
486 afs_int32 buffer[AFS_MAX_INTERFACE_ADDR];
487 afs_int32 maskbuffer[AFS_MAX_INTERFACE_ADDR];
488 afs_int32 mtubuffer[AFS_MAX_INTERFACE_ADDR];
492 if ( count > AFS_MAX_INTERFACE_ADDR ) {
494 count = AFS_MAX_INTERFACE_ADDR;
497 AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code);
499 AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code);
501 AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code);
503 afs_cb_interface.numberOfInterfaces = count;
504 for (i=0; i < count ; i++) {
505 afs_cb_interface.addr_in[i] = buffer[i];
506 #ifdef AFS_USERSPACE_IP_ADDR
507 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
508 * machines IP addresses when in the kernel (the in_ifaddr
509 * struct is not available), so we pass the info in at
510 * startup. We also pass in the subnetmask and mtu size. The
511 * subnetmask is used when setting the rank:
512 * afsi_SetServerIPRank(); and the mtu size is used when
513 * finding the best mtu size. rxi_FindIfnet() is replaced
514 * with rxi_Findcbi().
516 afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff);
517 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
520 afs_uuid_create(&afs_cb_interface.uuid);
521 rxi_setaddr(buffer[0]);
525 else if (parm == AFSOP_NFSSTATICADDR) {
526 extern int (*nfs_rfsdisptab_v2)();
527 nfs_rfsdisptab_v2 = (int (*)())parm2;
529 else if (parm == AFSOP_NFSSTATICADDR2) {
530 extern int (*nfs_rfsdisptab_v2)();
532 nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
534 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
537 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
538 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
539 extern int (*afs_sblockp)();
540 extern void (*afs_sbunlockp)();
542 afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
543 afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff));
545 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
546 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
549 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
550 #endif /* AFS_SGI53_ENV */
551 else if (parm == AFSOP_SHUTDOWN) {
552 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
553 extern struct mount *afs_globalVFS;
554 #else /* AFS_OSF_ENV */
555 extern struct vfs *afs_globalVFS;
557 afs_cold_shutdown = 0;
558 if (parm == 1) afs_cold_shutdown = 1;
559 if (afs_globalVFS != 0) {
560 afs_warn("AFS isn't unmounted yet! Call aborted\n");
566 #if ! defined(AFS_HPUX90_ENV) || defined(AFS_HPUX100_ENV)
567 else if (parm == AFSOP_AFS_VFSMOUNT) {
569 #if defined(AFS_HPUX100_ENV)
570 vfsmount(parm2, parm3, parm4, parm5);
572 afs_vfs_mount(parm2, parm3, parm4, parm5);
573 #endif /* AFS_HPUX100_ENV */
574 #else /* defined(AFS_HPUX_ENV) */
575 #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)
580 #endif /* defined(AFS_HPUX_ENV) */
583 else if (parm == AFSOP_CLOSEWAIT) {
584 afs_SynchronousCloses = 'S';
586 else if (parm == AFSOP_GETMTU) {
588 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
589 #ifdef AFS_USERSPACE_IP_ADDR
591 i = rxi_Findcbi(parm2);
592 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
593 #else /* AFS_USERSPACE_IP_ADDR */
595 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
596 extern struct ifnet *rxi_FindIfnet();
598 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
599 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
600 #endif /* else AFS_USERSPACE_IP_ADDR */
601 #endif /* !AFS_SUN5_ENV */
603 AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code);
605 /* this is disabled for now because I can't figure out how to get access
606 * to these kernel variables. It's only for supporting user-mode rx
607 * programs -- it makes a huge difference on the 220's in my testbed,
608 * though I don't know why. The bosserver does this with /etc/no, so it's
609 * being handled a different way for the servers right now. */
612 extern u_long sb_max_dflt;
615 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
616 if (sb_max < 131072) sb_max = 131072;
619 #endif /* AFS_AIX32_ENV */
621 else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
623 #if !defined(AFS_SUN5_ENV)
624 #ifdef AFS_USERSPACE_IP_ADDR
626 i = rxi_Findcbi(parm2);
628 mask = afs_cb_interface.subnetmask[i];
632 #else /* AFS_USERSPACE_IP_ADDR */
634 #ifdef AFS_DARWIN60_ENV
635 struct ifaddr *tifadp = (struct ifaddr *) 0;
637 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
639 extern struct ifnet *rxi_FindIfnet();
640 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
641 if (tifnp && tifadp) {
642 #ifdef AFS_DARWIN60_ENV
643 mask = ((struct sockaddr_in *)tifadp->ifa_netmask)->sin_addr.s_addr;
645 mask = tifadp->ia_subnetmask;
650 #endif /* else AFS_USERSPACE_IP_ADDR */
651 #endif /* !AFS_SUN5_ENV */
653 AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code);
656 else if (parm == AFSOP_AFSDB_HANDLER) {
657 int sizeArg = (int)parm4;
658 int kmsgLen = sizeArg & 0xffff;
659 int cellLen = (sizeArg & 0xffff0000) >> 16;
660 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
661 char *cellname = afs_osi_Alloc(cellLen);
664 afs_osi_MaskSignals();
666 AFS_COPYIN((afs_int32 *)parm2, cellname, cellLen, code);
667 AFS_COPYIN((afs_int32 *)parm3, kmsg, kmsgLen, code);
669 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
670 if (*cellname == 1) *cellname = 0;
671 if (code == -2) { /* Shutting down? */
676 if (!code) AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
677 afs_osi_Free(kmsg, kmsgLen);
678 afs_osi_Free(cellname, cellLen);
681 else if (parm == AFSOP_SET_DYNROOT) {
682 code = afs_SetDynrootEnable(parm2);
684 else if (parm == AFSOP_SET_FAKESTAT) {
685 afs_fakestat_enable = parm2;
693 #ifdef AFS_LINUX20_ENV
702 #include "sys/lockl.h"
705 * syscall - this is the VRMIX system call entry point.
708 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
709 * all the user-level calls to `syscall' to change.
711 syscall(syscall, p1, p2, p3, p4, p5, p6) {
712 register rval1=0, code;
715 #ifndef AFS_AIX41_ENV
716 extern lock_t kernel_lock;
717 monster = lockl(&kernel_lock, LOCK_SHORT);
718 #endif /* !AFS_AIX41_ENV */
720 AFS_STATCNT(syscall);
724 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
729 rval1 = afs_setpag();
735 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
739 case AFSCALL_ICREATE:
740 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
744 rval1 = afs_syscall_iopen(p1, p2, p3);
748 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
752 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
757 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
759 if (!code) rval1 = retval;
760 if (!rval1) rval1 = code;
770 #ifndef AFS_AIX41_ENV
771 if (monster != LOCK_NEST)
772 unlockl(&kernel_lock);
773 #endif /* !AFS_AIX41_ENV */
774 return getuerror() ? -1 : rval1;
778 * lsetpag - interface to afs_setpag().
782 AFS_STATCNT(lsetpag);
783 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
787 * lpioctl - interface to pioctl()
789 lpioctl(path, cmd, cmarg, follow)
790 char *path, *cmarg; {
792 AFS_STATCNT(lpioctl);
793 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
796 #else /* !AFS_AIX32_ENV */
798 #if defined(AFS_SGI_ENV)
811 Afs_syscall (struct afsargs *uap, rval_t *rvp)
816 AFS_STATCNT(afs_syscall);
817 switch(uap->syscall) {
821 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
823 rvp->r_val1 = retval;
825 #ifdef AFS_SGI_XFS_IOPS_ENV
827 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
828 uap->parm4, uap->parm5);
831 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
832 uap->parm4, uap->parm5);
834 case AFSCALL_ILISTINODE64:
835 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
836 uap->parm4, uap->parm5);
838 case AFSCALL_ICREATENAME64:
839 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
840 uap->parm4, uap->parm5);
843 #ifdef AFS_SGI_VNODE_GLUE
844 case AFSCALL_INIT_KERNEL_CONFIG:
845 error = afs_init_kernel_config(uap->parm1);
849 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
850 uap->parm3, uap->parm4, uap->parm5);
855 #else /* AFS_SGI_ENV */
873 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
875 dst->param1 = src->param1;
876 dst->param2 = src->param2;
877 dst->param3 = src->param3;
878 dst->param4 = src->param4;
882 * If you need to change copyin_iparam(), you may also need to change
883 * copyin_afs_ioctl().
887 copyin_iparam(caddr_t cmarg, struct iparam *dst)
891 #if defined(AFS_HPUX_64BIT_ENV)
892 struct iparam32 dst32;
894 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
896 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
898 iparam32_to_iparam(&dst32, dst);
901 #endif /* AFS_HPUX_64BIT_ENV */
903 #if defined(AFS_SUN57_64BIT_ENV)
904 struct iparam32 dst32;
906 if (get_udatamodel() == DATAMODEL_ILP32) {
907 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
909 iparam32_to_iparam(&dst32, dst);
912 #endif /* AFS_SUN57_64BIT_ENV */
914 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
915 struct iparam32 dst32;
917 #ifdef AFS_SPARC64_LINUX24_ENV
918 if (current->thread.flags & SPARC_FLAG_32BIT)
919 #elif AFS_SPARC64_LINUX20_ENV
920 if (current->tss.flags & SPARC_FLAG_32BIT)
922 #error Not done for this linux version
923 #endif /* AFS_SPARC64_LINUX20_ENV */
925 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
927 iparam32_to_iparam(&dst32, dst);
930 #endif /* AFS_LINUX_64BIT_KERNEL */
932 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
936 /* Main entry of all afs system calls */
938 extern int afs_sinited;
940 /** The 32 bit OS expects the members of this structure to be 32 bit
941 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
942 * to accomodate both, *long* is used instead of afs_int32
967 Afs_syscall (uap, rvp)
968 register struct afssysa *uap;
971 int *retval = &rvp->r_val1;
972 #else /* AFS_SUN5_ENV */
973 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
974 afs3_syscall(p, args, retval)
987 } *uap = (struct a *)args;
988 #else /* AFS_OSF_ENV */
989 #ifdef AFS_LINUX20_ENV
997 long parm6; /* not actually used - should be removed */
999 /* Linux system calls only set up for 5 arguments. */
1000 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
1003 struct afssysargs args, *uap = &args;
1005 long *retval = &linux_ret;
1006 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
1007 #ifdef AFS_SPARC64_LINUX24_ENV
1008 afs_int32 eparm32[4];
1010 /* eparm is also used by AFSCALL_CALL in afsd.c */
1012 #if defined(UKERNEL)
1023 } *uap = (struct a *)u.u_ap;
1025 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
1029 #endif /* SUN && !SUN5 */
1039 } *uap = (struct a *)u.u_ap;
1040 #endif /* UKERNEL */
1041 #if defined(AFS_DEC_ENV)
1042 int *retval = &u.u_r.r_val1;
1044 #if defined(AFS_HPUX_ENV)
1045 long *retval = &u.u_rval1;
1047 int *retval = &u.u_rval1;
1050 #endif /* AFS_LINUX20_ENV */
1051 #endif /* AFS_OSF_ENV */
1052 #endif /* AFS_SUN5_ENV */
1053 register int code = 0;
1055 AFS_STATCNT(afs_syscall);
1062 #ifdef AFS_LINUX20_ENV
1064 /* setup uap for use below - pull out the magic decoder ring to know
1065 * which syscalls have folded argument lists.
1067 uap->syscall = syscall;
1071 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
1072 #ifdef AFS_SPARC64_LINUX24_ENV
1073 /* from arch/sparc64/kernel/sys_sparc32.c */
1075 ({ unsigned long __ret; \
1076 __asm__ ("srl %0, 0, %0" \
1083 if (current->thread.flags & SPARC_FLAG_32BIT) {
1084 AFS_COPYIN((char*)parm4, (char*)eparm32, sizeof(eparm32), code);
1085 eparm[0]=AA(eparm32[0]);
1086 eparm[1]=AA(eparm32[1]);
1087 eparm[2]=AA(eparm32[2]);
1091 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
1092 uap->parm4 = eparm[0];
1093 uap->parm5 = eparm[1];
1094 uap->parm6 = eparm[2];
1103 #if defined(AFS_HPUX_ENV)
1105 * There used to be code here (duplicated from osi_Init()) for
1106 * initializing the semaphore used by AFS_GLOCK(). Was the
1107 * duplication to handle the case of a dynamically loaded kernel
1112 if (uap->syscall == AFSCALL_CALL) {
1114 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1115 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1117 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1119 } else if (uap->syscall == AFSCALL_SETPAG) {
1121 register proc_t *procp;
1123 procp = ttoproc(curthread);
1125 code = afs_setpag(&procp->p_cred);
1129 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1130 code = afs_setpag(p, args, retval);
1131 #else /* AFS_OSF_ENV */
1132 code = afs_setpag();
1136 } else if (uap->syscall == AFSCALL_PIOCTL) {
1139 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1141 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1142 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1144 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1148 } else if (uap->syscall == AFSCALL_ICREATE) {
1149 struct iparam iparams;
1151 code = copyin_iparam((char *)uap->parm3, &iparams);
1153 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1158 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1159 iparams.param3, iparams.param4, rvp, CRED());
1161 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1162 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1163 iparams.param3, iparams.param4, retval);
1165 iparams.param3, iparams.param4);
1167 #endif /* AFS_SUN5_ENV */
1168 } else if (uap->syscall == AFSCALL_IOPEN) {
1170 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1172 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1173 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1175 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1177 #endif /* AFS_SUN5_ENV */
1178 } else if (uap->syscall == AFSCALL_IDEC) {
1180 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1182 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1183 #endif /* AFS_SUN5_ENV */
1184 } else if (uap->syscall == AFSCALL_IINC) {
1186 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1188 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1189 #endif /* AFS_SUN5_ENV */
1190 } else if (uap->syscall == AFSCALL_ICL) {
1192 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1194 #ifdef AFS_LINUX20_ENV
1196 /* ICL commands can return values. */
1197 code = -linux_ret; /* Gets negated again at exit below */
1201 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1205 #endif /* !AFS_LINUX20_ENV */
1207 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1211 #endif /* AFS_SUN5_ENV */
1214 #ifdef AFS_LINUX20_ENV
1220 #endif /* AFS_SGI_ENV */
1221 #endif /* !AFS_AIX32_ENV */
1224 * Initstate in the range 0 < x < 100 are early initialization states.
1225 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1226 * the cache may be initialized.
1227 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1228 * is done after all the cache initialization has been done.
1229 * Initstate of 200 means that the volume has been looked up once, possibly
1231 * Initstate of 300 means that the volume has been *successfully* looked up.
1233 int afs_CheckInit(void)
1235 register int code = 0;
1237 AFS_STATCNT(afs_CheckInit);
1238 if (afs_initState <= 100)
1239 code = ENXIO; /* never finished init phase */
1240 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1241 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1242 } else if (afs_initState == 200)
1243 code = ETIMEDOUT; /* didn't find root volume */
1247 int afs_shuttingdown = 0;
1248 void afs_shutdown(void)
1250 extern short afs_brsDaemons;
1251 extern afs_int32 afs_CheckServerDaemonStarted;
1252 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1253 extern struct osi_file *afs_cacheInodep;
1255 AFS_STATCNT(afs_shutdown);
1256 if (afs_shuttingdown) return;
1257 afs_shuttingdown = 1;
1258 if (afs_cold_shutdown) afs_warn("COLD ");
1259 else afs_warn("WARM ");
1260 afs_warn("shutting down of: CB... ");
1262 afs_termState = AFSOP_STOP_RXCALLBACK;
1263 rx_WakeupServerProcs();
1264 /* shutdown_rxkernel(); */
1265 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1266 afs_osi_Sleep(&afs_termState);
1268 afs_warn("afs... ");
1269 while (afs_termState == AFSOP_STOP_AFS) {
1270 afs_osi_CancelWait(&AFS_WaitHandler);
1271 afs_osi_Sleep(&afs_termState);
1273 if (afs_CheckServerDaemonStarted) {
1274 while (afs_termState == AFSOP_STOP_CS) {
1275 afs_osi_CancelWait(&AFS_CSWaitHandler);
1276 afs_osi_Sleep(&afs_termState);
1279 afs_warn("BkG... ");
1280 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1281 while (afs_termState == AFSOP_STOP_BKG) {
1282 afs_osi_Wakeup(&afs_brsDaemons);
1283 afs_osi_Sleep(&afs_termState);
1285 afs_warn("CTrunc... ");
1286 /* Cancel cache truncate daemon. */
1287 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1288 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1289 afs_osi_Sleep(&afs_termState);
1291 #ifdef AFS_AFSDB_ENV
1292 afs_warn("AFSDB... ");
1294 while (afs_termState == AFSOP_STOP_AFSDB)
1295 afs_osi_Sleep(&afs_termState);
1297 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1298 afs_warn("RxEvent... ");
1299 /* cancel rx event deamon */
1300 while (afs_termState == AFSOP_STOP_RXEVENT)
1301 afs_osi_Sleep(&afs_termState);
1302 #if defined(RXK_LISTENER_ENV)
1304 afs_warn("UnmaskRxkSignals... ");
1305 afs_osi_UnmaskRxkSignals();
1307 /* cancel rx listener */
1308 afs_warn("RxListener... ");
1309 osi_StopListener(); /* This closes rx_socket. */
1310 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1311 afs_warn("Sleep... ");
1312 afs_osi_Sleep(&afs_termState);
1316 afs_termState = AFSOP_STOP_COMPLETE;
1320 /* Close file only after daemons which can write to it are stopped. */
1321 if (afs_cacheInodep) /* memcache won't set this */
1323 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1324 afs_cacheInodep = 0;
1326 return; /* Just kill daemons for now */
1330 shutdown_rxkernel();
1334 shutdown_bufferpackage();
1340 shutdown_vnodeops();
1342 shutdown_exporter();
1343 shutdown_memcache();
1344 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1345 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1346 /* this routine does not exist in Ultrix systems... 93.01.19 */
1348 #endif /* AFS_DEC_ENV */
1351 /* The following hold the cm stats */
1353 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1354 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1355 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1357 afs_warn(" ALL allocated tables\n");
1358 afs_shuttingdown = 0;
1362 void shutdown_afstest(void)
1364 AFS_STATCNT(shutdown_afstest);
1365 afs_initState = afs_termState = afs_setTime = 0;
1366 AFS_Running = afs_CB_Running = 0;
1367 afs_CacheInit_Done = afs_Go_Done = 0;
1368 if (afs_cold_shutdown) {
1369 *afs_rootVolumeName = 0;
1374 /* In case there is a bunch of dynamically build bkg daemons to free */
1375 void afs_shutdown_BKG(void)
1377 AFS_STATCNT(shutdown_BKG);
1381 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1382 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1383 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1384 int afs_icl_sizeofLong = 1;
1386 int afs_icl_sizeofLong = 2;
1389 int afs_icl_sizeofLong = 1;
1392 int afs_icl_inited = 0;
1394 /* init function, called once, under afs_icl_lock */
1395 int afs_icl_Init(void)
1401 extern struct afs_icl_log *afs_icl_FindLog();
1402 extern struct afs_icl_set *afs_icl_FindSet();
1406 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1409 afs_int32 *lp, elts, flags;
1410 register afs_int32 code;
1411 struct afs_icl_log *logp;
1412 struct afs_icl_set *setp;
1413 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1415 #else /* AFS_SGI61_ENV */
1417 #endif /* AFS_SGI61_ENV */
1419 afs_int32 startCookie;
1420 afs_int32 allocated;
1421 struct afs_icl_log *tlp;
1424 if (!afs_suser(CRED())) { /* only root can run this code */
1428 if (!afs_suser()) { /* only root can run this code */
1429 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
1438 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1439 case ICL_OP_COPYOUT: /* copy ouy data */
1440 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1441 * return flags<<24 + nwords.
1442 * updates cookie to updated start (not end) if we had to
1443 * skip some records.
1445 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1446 if (code) return code;
1447 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1448 if (code) return code;
1449 logp = afs_icl_FindLog(tname);
1450 if (!logp) return ENOENT;
1451 #define BUFFERSIZE AFS_LRALLOCSIZ
1452 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1453 elts = BUFFERSIZE / sizeof(afs_int32);
1454 if (p3 < elts) elts = p3;
1455 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1456 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1459 osi_FreeLargeSpace((struct osi_buffer *) lp);
1462 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1463 if (code) goto done;
1464 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1465 if (code) goto done;
1466 *retval = (flags<<24) | (elts & 0xffffff);
1468 afs_icl_LogRele(logp);
1469 osi_FreeLargeSpace((struct osi_buffer *) lp);
1472 case ICL_OP_ENUMLOGS: /* enumerate logs */
1473 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1474 * return 0 for success, otherwise error.
1476 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1477 if (p1-- == 0) break;
1479 if (!tlp) return ENOENT; /* past the end of file */
1480 temp = strlen(tlp->name)+1;
1481 if (temp > p3) return EINVAL;
1482 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1483 if (!code) /* copy out size of log */
1484 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1487 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1488 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1489 * return 0 for success, otherwise error.
1491 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1492 if (code) return code;
1493 setp = afs_icl_FindSet(tname);
1494 if (!setp) return ENOENT;
1495 if (p2 > ICL_LOGSPERSET)
1497 if (!(tlp = setp->logs[p2]))
1499 temp = strlen(tlp->name)+1;
1500 if (temp > p4) return EINVAL;
1501 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1504 case ICL_OP_CLRLOG: /* clear specified log */
1505 /* zero out the specified log: p1=logname */
1506 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1507 if (code) return code;
1508 logp = afs_icl_FindLog(tname);
1509 if (!logp) return ENOENT;
1510 code = afs_icl_ZeroLog(logp);
1511 afs_icl_LogRele(logp);
1514 case ICL_OP_CLRSET: /* clear specified set */
1515 /* zero out the specified set: p1=setname */
1516 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1517 if (code) return code;
1518 setp = afs_icl_FindSet(tname);
1519 if (!setp) return ENOENT;
1520 code = afs_icl_ZeroSet(setp);
1521 afs_icl_SetRele(setp);
1524 case ICL_OP_CLRALL: /* clear all logs */
1525 /* zero out all logs -- no args */
1527 ObtainWriteLock(&afs_icl_lock,178);
1528 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1529 tlp->refCount++; /* hold this guy */
1530 ReleaseWriteLock(&afs_icl_lock);
1531 /* don't clear persistent logs */
1532 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1533 code = afs_icl_ZeroLog(tlp);
1534 ObtainWriteLock(&afs_icl_lock,179);
1535 if (--tlp->refCount == 0)
1536 afs_icl_ZapLog(tlp);
1539 ReleaseWriteLock(&afs_icl_lock);
1542 case ICL_OP_ENUMSETS: /* enumerate all sets */
1543 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1544 * return 0 for success, otherwise error.
1546 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1547 if (p1-- == 0) break;
1549 if (!setp) return ENOENT; /* past the end of file */
1550 temp = strlen(setp->name)+1;
1551 if (temp > p3) return EINVAL;
1552 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1553 if (!code) /* copy out size of log */
1554 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1557 case ICL_OP_SETSTAT: /* set status on a set */
1558 /* activate the specified set: p1=setname, p2=op */
1559 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1560 if (code) return code;
1561 setp = afs_icl_FindSet(tname);
1562 if (!setp) return ENOENT;
1563 code = afs_icl_SetSetStat(setp, p2);
1564 afs_icl_SetRele(setp);
1567 case ICL_OP_SETSTATALL: /* set status on all sets */
1568 /* activate the specified set: p1=op */
1570 ObtainWriteLock(&afs_icl_lock,180);
1571 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1572 setp->refCount++; /* hold this guy */
1573 ReleaseWriteLock(&afs_icl_lock);
1574 /* don't set states on persistent sets */
1575 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1576 code = afs_icl_SetSetStat(setp, p1);
1577 ObtainWriteLock(&afs_icl_lock,181);
1578 if (--setp->refCount == 0)
1579 afs_icl_ZapSet(setp);
1582 ReleaseWriteLock(&afs_icl_lock);
1585 case ICL_OP_SETLOGSIZE: /* set size of log */
1586 /* set the size of the specified log: p1=logname, p2=size (in words) */
1587 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1588 if (code) return code;
1589 logp = afs_icl_FindLog(tname);
1590 if (!logp) return ENOENT;
1591 code = afs_icl_LogSetSize(logp, p2);
1592 afs_icl_LogRele(logp);
1595 case ICL_OP_GETLOGINFO: /* get size of log */
1596 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1597 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1598 if (code) return code;
1599 logp = afs_icl_FindLog(tname);
1600 if (!logp) return ENOENT;
1601 allocated = !!logp->datap;
1602 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1604 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1605 afs_icl_LogRele(logp);
1608 case ICL_OP_GETSETINFO: /* get state of set */
1609 /* zero out the specified set: p1=setname, p2=&state */
1610 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1611 if (code) return code;
1612 setp = afs_icl_FindSet(tname);
1613 if (!setp) return ENOENT;
1614 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1615 afs_icl_SetRele(setp);
1626 afs_lock_t afs_icl_lock;
1628 /* exported routine: a 4 parameter event */
1629 int afs_icl_Event4(register struct afs_icl_set *setp, afs_int32 eventID,
1630 afs_int32 lAndT, long p1, long p2, long p3, long p4)
1632 register struct afs_icl_log *logp;
1635 register afs_int32 tmask;
1638 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1639 if (!ICL_SETACTIVE(setp)) return;
1642 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1643 ix = ICL_EVENTBYTE(eventID);
1644 ObtainReadLock(&setp->lock);
1645 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1646 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1648 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1652 if (mask == 0) break; /* break early */
1655 ReleaseReadLock(&setp->lock);
1658 /* Next 4 routines should be implemented via var-args or something.
1659 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1660 * Otherwise, could call afs_icl_Event4 directly.
1662 int afs_icl_Event3(register struct afs_icl_set *setp, afs_int32 eventID,
1663 afs_int32 lAndT, long p1, long p2, long p3)
1665 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1668 int afs_icl_Event2(register struct afs_icl_set *setp, afs_int32 eventID,
1669 afs_int32 lAndT, long p1, long p2)
1671 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1674 int afs_icl_Event1(register struct afs_icl_set *setp, afs_int32 eventID,
1675 afs_int32 lAndT, long p1)
1677 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1680 int afs_icl_Event0(register struct afs_icl_set *setp, afs_int32 eventID,
1683 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1686 struct afs_icl_log *afs_icl_allLogs = 0;
1688 /* function to purge records from the start of the log, until there
1689 * is at least minSpace long's worth of space available without
1690 * making the head and the tail point to the same word.
1692 * Log must be write-locked.
1694 static afs_icl_GetLogSpace(register struct afs_icl_log *logp, afs_int32 minSpace)
1696 register unsigned int tsize;
1698 while (logp->logSize - logp->logElements <= minSpace) {
1700 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1701 logp->logElements -= tsize;
1702 logp->firstUsed += tsize;
1703 if (logp->firstUsed >= logp->logSize)
1704 logp->firstUsed -= logp->logSize;
1705 logp->baseCookie += tsize;
1709 /* append string astr to buffer, including terminating null char.
1711 * log must be write-locked.
1713 #define ICL_CHARSPERLONG 4
1714 static afs_int32 afs_icl_AppendString(struct afs_icl_log *logp, char *astr)
1716 char *op; /* ptr to char to write */
1718 register int bib; /* bytes in buffer */
1721 op = (char *) &(logp->datap[logp->firstFree]);
1725 if (++bib >= ICL_CHARSPERLONG) {
1728 if (++(logp->firstFree) >= logp->logSize) {
1729 logp->firstFree = 0;
1730 op = (char *) &(logp->datap[0]);
1732 logp->logElements++;
1737 /* if we've used this word at all, allocate it */
1738 if (++(logp->firstFree) >= logp->logSize) {
1739 logp->firstFree = 0;
1741 logp->logElements++;
1745 /* add a long to the log, ignoring overflow (checked already) */
1746 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1747 #define ICL_APPENDINT32(lp, x) \
1749 (lp)->datap[(lp)->firstFree] = (x); \
1750 if (++((lp)->firstFree) >= (lp)->logSize) { \
1751 (lp)->firstFree = 0; \
1753 (lp)->logElements++; \
1756 #define ICL_APPENDLONG(lp, x) \
1758 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1759 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1762 #else /* AFS_ALPHA_ENV */
1763 #define ICL_APPENDLONG(lp, x) \
1765 (lp)->datap[(lp)->firstFree] = (x); \
1766 if (++((lp)->firstFree) >= (lp)->logSize) { \
1767 (lp)->firstFree = 0; \
1769 (lp)->logElements++; \
1771 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1772 #endif /* AFS_ALPHA_ENV */
1774 /* routine to tell whether we're dealing with the address or the
1777 int afs_icl_UseAddr(int type)
1779 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1780 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
1786 /* Function to append a record to the log. Written for speed
1787 * since we know that we're going to have to make this work fast
1788 * pretty soon, anyway. The log must be unlocked.
1791 int afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
1792 afs_int32 types, long p1, long p2, long p3, long p4)
1794 int rsize; /* record size in longs */
1795 register int tsize; /* temp size */
1799 t4 = types & 0x3f; /* decode types */
1807 osi_GetTime(&tv); /* It panics for solaris if inside */
1808 ObtainWriteLock(&logp->lock,182);
1810 ReleaseWriteLock(&logp->lock);
1814 /* get timestamp as # of microseconds since some time that doesn't
1815 * change that often. This algorithm ticks over every 20 minutes
1816 * or so (1000 seconds). Write a timestamp record if it has.
1818 if (tv.tv_sec - logp->lastTS > 1024)
1820 /* the timer has wrapped -- write a timestamp record */
1821 if (logp->logSize - logp->logElements <= 5)
1822 afs_icl_GetLogSpace(logp, 5);
1824 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1825 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1826 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1827 ICL_APPENDINT32(logp,
1828 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1829 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1831 logp->lastTS = tv.tv_sec;
1834 rsize = 4; /* base case */
1836 /* compute size of parameter p1. Only tricky case is string.
1837 * In that case, we have to call strlen to get the string length.
1839 ICL_SIZEHACK(t1, p1);
1842 /* compute size of parameter p2. Only tricky case is string.
1843 * In that case, we have to call strlen to get the string length.
1845 ICL_SIZEHACK(t2, p2);
1848 /* compute size of parameter p3. Only tricky case is string.
1849 * In that case, we have to call strlen to get the string length.
1851 ICL_SIZEHACK(t3, p3);
1854 /* compute size of parameter p4. Only tricky case is string.
1855 * In that case, we have to call strlen to get the string length.
1857 ICL_SIZEHACK(t4, p4);
1860 /* At this point, we've computed all of the parameter sizes, and
1861 * have in rsize the size of the entire record we want to append.
1862 * Next, we check that we actually have room in the log to do this
1863 * work, and then we do the append.
1866 ReleaseWriteLock(&logp->lock);
1867 return; /* log record too big to express */
1870 if (logp->logSize - logp->logElements <= rsize)
1871 afs_icl_GetLogSpace(logp, rsize);
1873 ICL_APPENDINT32(logp,
1874 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
1875 ICL_APPENDINT32(logp, (afs_int32)op);
1876 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
1877 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1880 /* marshall parameter 1 now */
1881 if (t1 == ICL_TYPE_STRING) {
1882 afs_icl_AppendString(logp, (char *) p1);
1884 else if (t1 == ICL_TYPE_HYPER) {
1885 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
1886 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
1888 else if (t1 == ICL_TYPE_INT64) {
1889 #ifdef AFSLITTLE_ENDIAN
1890 #ifdef AFS_64BIT_CLIENT
1891 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1892 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1893 #else /* AFS_64BIT_CLIENT */
1894 ICL_APPENDINT32(logp, (afs_int32) p1);
1895 ICL_APPENDINT32(logp, (afs_int32) 0);
1896 #endif /* AFS_64BIT_CLIENT */
1897 #else /* AFSLITTLE_ENDIAN */
1898 #ifdef AFS_64BIT_CLIENT
1899 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1900 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1901 #else /* AFS_64BIT_CLIENT */
1902 ICL_APPENDINT32(logp, (afs_int32) 0);
1903 ICL_APPENDINT32(logp, (afs_int32) p1);
1904 #endif /* AFS_64BIT_CLIENT */
1905 #endif /* AFSLITTLE_ENDIAN */
1907 else if (t1 == ICL_TYPE_FID) {
1908 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1909 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1910 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
1911 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
1913 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1914 else if (t1 == ICL_TYPE_INT32)
1915 ICL_APPENDINT32(logp, (afs_int32)p1);
1916 #endif /* AFS_ALPHA_ENV */
1917 else ICL_APPENDLONG(logp, p1);
1920 /* marshall parameter 2 now */
1921 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
1922 else if (t2 == ICL_TYPE_HYPER) {
1923 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
1924 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
1926 else if (t2 == ICL_TYPE_INT64) {
1927 #ifdef AFSLITTLE_ENDIAN
1928 #ifdef AFS_64BIT_CLIENT
1929 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1930 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1931 #else /* AFS_64BIT_CLIENT */
1932 ICL_APPENDINT32(logp, (afs_int32) p2);
1933 ICL_APPENDINT32(logp, (afs_int32) 0);
1934 #endif /* AFS_64BIT_CLIENT */
1935 #else /* AFSLITTLE_ENDIAN */
1936 #ifdef AFS_64BIT_CLIENT
1937 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1938 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1939 #else /* AFS_64BIT_CLIENT */
1940 ICL_APPENDINT32(logp, (afs_int32) 0);
1941 ICL_APPENDINT32(logp, (afs_int32) p2);
1942 #endif /* AFS_64BIT_CLIENT */
1943 #endif /* AFSLITTLE_ENDIAN */
1945 else if (t2 == ICL_TYPE_FID) {
1946 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1947 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1948 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
1949 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
1951 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1952 else if (t2 == ICL_TYPE_INT32)
1953 ICL_APPENDINT32(logp, (afs_int32)p2);
1954 #endif /* AFS_ALPHA_ENV */
1955 else ICL_APPENDLONG(logp, p2);
1958 /* marshall parameter 3 now */
1959 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
1960 else if (t3 == ICL_TYPE_HYPER) {
1961 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
1962 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
1964 else if (t3 == ICL_TYPE_INT64) {
1965 #ifdef AFSLITTLE_ENDIAN
1966 #ifdef AFS_64BIT_CLIENT
1967 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1968 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1969 #else /* AFS_64BIT_CLIENT */
1970 ICL_APPENDINT32(logp, (afs_int32) p3);
1971 ICL_APPENDINT32(logp, (afs_int32) 0);
1972 #endif /* AFS_64BIT_CLIENT */
1973 #else /* AFSLITTLE_ENDIAN */
1974 #ifdef AFS_64BIT_CLIENT
1975 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1976 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1977 #else /* AFS_64BIT_CLIENT */
1978 ICL_APPENDINT32(logp, (afs_int32) 0);
1979 ICL_APPENDINT32(logp, (afs_int32) p3);
1980 #endif /* AFS_64BIT_CLIENT */
1981 #endif /* AFSLITTLE_ENDIAN */
1983 else if (t3 == ICL_TYPE_FID) {
1984 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1985 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1986 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
1987 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
1989 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1990 else if (t3 == ICL_TYPE_INT32)
1991 ICL_APPENDINT32(logp, (afs_int32)p3);
1992 #endif /* AFS_ALPHA_ENV */
1993 else ICL_APPENDLONG(logp, p3);
1996 /* marshall parameter 4 now */
1997 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
1998 else if (t4 == ICL_TYPE_HYPER) {
1999 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
2000 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
2002 else if (t4 == ICL_TYPE_INT64) {
2003 #ifdef AFSLITTLE_ENDIAN
2004 #ifdef AFS_64BIT_CLIENT
2005 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2006 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2007 #else /* AFS_64BIT_CLIENT */
2008 ICL_APPENDINT32(logp, (afs_int32) p4);
2009 ICL_APPENDINT32(logp, (afs_int32) 0);
2010 #endif /* AFS_64BIT_CLIENT */
2011 #else /* AFSLITTLE_ENDIAN */
2012 #ifdef AFS_64BIT_CLIENT
2013 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2014 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2015 #else /* AFS_64BIT_CLIENT */
2016 ICL_APPENDINT32(logp, (afs_int32) 0);
2017 ICL_APPENDINT32(logp, (afs_int32) p4);
2018 #endif /* AFS_64BIT_CLIENT */
2019 #endif /* AFSLITTLE_ENDIAN */
2021 else if (t4 == ICL_TYPE_FID) {
2022 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2023 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2024 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
2025 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
2027 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2028 else if (t4 == ICL_TYPE_INT32)
2029 ICL_APPENDINT32(logp, (afs_int32)p4);
2030 #endif /* AFS_ALPHA_ENV */
2031 else ICL_APPENDLONG(logp, p4);
2033 ReleaseWriteLock(&logp->lock);
2036 /* create a log with size logSize; return it in *outLogpp and tag
2037 * it with name "name."
2039 int afs_icl_CreateLog(char *name, afs_int32 logSize, struct afs_icl_log **outLogpp)
2041 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
2044 /* create a log with size logSize; return it in *outLogpp and tag
2045 * it with name "name." 'flags' can be set to make the log unclearable.
2047 int afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, afs_uint32 flags,
2048 struct afs_icl_log **outLogpp)
2050 register struct afs_icl_log *logp;
2052 /* add into global list under lock */
2053 ObtainWriteLock(&afs_icl_lock,183);
2054 if (!afs_icl_inited) afs_icl_Init();
2056 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
2057 if (strcmp(logp->name, name) == 0) {
2058 /* found it already created, just return it */
2061 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2063 ObtainWriteLock(&logp->lock,184);
2064 logp->states |= ICL_LOGF_PERSISTENT;
2065 ReleaseWriteLock(&logp->lock);
2067 ReleaseWriteLock(&afs_icl_lock);
2072 logp = (struct afs_icl_log *)
2073 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
2074 memset((caddr_t)logp, 0, sizeof(*logp));
2077 logp->name = osi_AllocSmallSpace(strlen(name)+1);
2078 strcpy(logp->name, name);
2079 LOCK_INIT(&logp->lock, "logp lock");
2080 logp->logSize = logSize;
2081 logp->datap = NULL; /* don't allocate it until we need it */
2083 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2084 logp->states |= ICL_LOGF_PERSISTENT;
2086 logp->nextp = afs_icl_allLogs;
2087 afs_icl_allLogs = logp;
2088 ReleaseWriteLock(&afs_icl_lock);
2094 /* called with a log, a pointer to a buffer, the size of the buffer
2095 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
2096 * and returns data in the provided buffer, and returns output flags
2097 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
2098 * find the record with cookie value cookie.
2100 int afs_icl_CopyOut(register struct afs_icl_log *logp, afs_int32 *bufferp,
2101 afs_int32 *bufSizep, afs_uint32 *cookiep, afs_int32 *flagsp)
2103 afs_int32 nwords; /* number of words to copy out */
2104 afs_uint32 startCookie; /* first cookie to use */
2105 register afs_int32 i;
2106 afs_int32 outWords; /* words we've copied out */
2107 afs_int32 inWords; /* max words to copy out */
2108 afs_int32 code; /* return code */
2109 afs_int32 ix; /* index we're copying from */
2110 afs_int32 outFlags; /* return flags */
2111 afs_int32 inFlags; /* flags passed in */
2114 inWords = *bufSizep; /* max to copy out */
2115 outWords = 0; /* amount copied out */
2116 startCookie = *cookiep;
2121 ObtainWriteLock(&logp->lock,185);
2123 ReleaseWriteLock(&logp->lock);
2127 /* first, compute the index of the start cookie we've been passed */
2129 /* (re-)compute where we should start */
2130 if (startCookie < logp->baseCookie) {
2131 if (startCookie) /* missed some output */
2132 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2133 /* skip to the first available record */
2134 startCookie = logp->baseCookie;
2135 *cookiep = startCookie;
2138 /* compute where we find the first element to copy out */
2139 ix = logp->firstUsed + startCookie - logp->baseCookie;
2140 if (ix >= logp->logSize) ix -= logp->logSize;
2142 /* if have some data now, break out and process it */
2143 if (startCookie - logp->baseCookie < logp->logElements) break;
2145 /* At end of log, so clear it if we need to */
2146 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
2148 logp->firstUsed = logp->firstFree = 0;
2149 logp->logElements = 0;
2151 /* otherwise, either wait for the data to arrive, or return */
2152 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2153 ReleaseWriteLock(&logp->lock);
2157 logp->states |= ICL_LOGF_WAITING;
2158 ReleaseWriteLock(&logp->lock);
2159 afs_osi_Sleep(&logp->lock);
2160 ObtainWriteLock(&logp->lock,186);
2162 /* copy out data from ix to logSize or firstFree, depending
2163 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2164 * be careful not to copy out more than nwords.
2166 if (ix >= logp->firstUsed) {
2167 if (logp->firstUsed <= logp->firstFree)
2169 end = logp->firstFree; /* first element not to copy */
2171 end = logp->logSize;
2172 nwords = inWords; /* don't copy more than this */
2173 if (end - ix < nwords)
2176 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2181 /* if we're going to copy more out below, we'll start here */
2184 /* now, if active part of the log has wrapped, there's more stuff
2185 * starting at the head of the log. Copy out more from there.
2187 if (logp->firstUsed > logp->firstFree
2188 && ix < logp->firstFree && inWords > 0) {
2189 /* (more to) copy out from the wrapped section at the
2190 * start of the log. May get here even if didn't copy any
2191 * above, if the cookie points directly into the wrapped section.
2194 if (logp->firstFree - ix < nwords)
2195 nwords = logp->firstFree - ix;
2196 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2202 ReleaseWriteLock(&logp->lock);
2206 *bufSizep = outWords;
2212 /* return basic parameter information about a log */
2213 int afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 *maxSizep,
2214 afs_int32 *curSizep)
2216 ObtainReadLock(&logp->lock);
2217 *maxSizep = logp->logSize;
2218 *curSizep = logp->logElements;
2219 ReleaseReadLock(&logp->lock);
2224 /* hold and release logs */
2225 int afs_icl_LogHold(register struct afs_icl_log *logp)
2227 ObtainWriteLock(&afs_icl_lock,187);
2229 ReleaseWriteLock(&afs_icl_lock);
2233 /* hold and release logs, called with lock already held */
2234 int afs_icl_LogHoldNL(register struct afs_icl_log *logp)
2240 /* keep track of how many sets believe the log itself is allocated */
2241 int afs_icl_LogUse(register struct afs_icl_log *logp)
2243 ObtainWriteLock(&logp->lock,188);
2244 if (logp->setCount == 0) {
2245 /* this is the first set actually using the log -- allocate it */
2246 if (logp->logSize == 0) {
2247 /* we weren't passed in a hint and it wasn't set */
2248 logp->logSize = ICL_DEFAULT_LOGSIZE;
2250 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2251 #ifdef AFS_AIX32_ENV
2252 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2256 ReleaseWriteLock(&logp->lock);
2260 /* decrement the number of real users of the log, free if possible */
2261 int afs_icl_LogFreeUse(register struct afs_icl_log *logp)
2263 ObtainWriteLock(&logp->lock,189);
2264 if (--logp->setCount == 0) {
2265 /* no more users -- free it (but keep log structure around)*/
2266 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2267 #ifdef AFS_AIX32_ENV
2268 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2270 logp->firstUsed = logp->firstFree = 0;
2271 logp->logElements = 0;
2274 ReleaseWriteLock(&logp->lock);
2278 /* set the size of the log to 'logSize' */
2279 int afs_icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
2281 ObtainWriteLock(&logp->lock,190);
2283 /* nothing to worry about since it's not allocated */
2284 logp->logSize = logSize;
2288 logp->firstUsed = logp->firstFree = 0;
2289 logp->logElements = 0;
2291 /* free and allocate a new one */
2292 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2293 #ifdef AFS_AIX32_ENV
2294 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2296 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2297 #ifdef AFS_AIX32_ENV
2298 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2300 logp->logSize = logSize;
2302 ReleaseWriteLock(&logp->lock);
2307 /* free a log. Called with afs_icl_lock locked. */
2308 int afs_icl_ZapLog(register struct afs_icl_log *logp)
2310 register struct afs_icl_log **lpp, *tp;
2312 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2314 /* found the dude we want to remove */
2316 osi_FreeSmallSpace(logp->name);
2317 osi_FreeSmallSpace(logp->datap);
2318 osi_FreeSmallSpace(logp);
2319 break; /* won't find it twice */
2325 /* do the release, watching for deleted entries */
2326 int afs_icl_LogRele(register struct afs_icl_log *logp)
2328 ObtainWriteLock(&afs_icl_lock,191);
2329 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2330 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2332 ReleaseWriteLock(&afs_icl_lock);
2336 /* do the release, watching for deleted entries, log already held */
2337 int afs_icl_LogReleNL(register struct afs_icl_log *logp)
2339 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2340 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2345 /* zero out the log */
2346 int afs_icl_ZeroLog(register struct afs_icl_log *logp)
2348 ObtainWriteLock(&logp->lock,192);
2349 logp->firstUsed = logp->firstFree = 0;
2350 logp->logElements = 0;
2351 logp->baseCookie = 0;
2352 ReleaseWriteLock(&logp->lock);
2356 /* free a log entry, and drop its reference count */
2357 int afs_icl_LogFree(register struct afs_icl_log *logp)
2359 ObtainWriteLock(&logp->lock,193);
2360 logp->states |= ICL_LOGF_DELETED;
2361 ReleaseWriteLock(&logp->lock);
2362 afs_icl_LogRele(logp);
2366 /* find a log by name, returning it held */
2367 struct afs_icl_log *afs_icl_FindLog(char *name)
2369 register struct afs_icl_log *tp;
2370 ObtainWriteLock(&afs_icl_lock,194);
2371 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2372 if (strcmp(tp->name, name) == 0) {
2373 /* this is the dude we want */
2378 ReleaseWriteLock(&afs_icl_lock);
2382 int afs_icl_EnumerateLogs(int (*aproc)(), char *arock)
2384 register struct afs_icl_log *tp;
2385 register afs_int32 code;
2388 ObtainWriteLock(&afs_icl_lock,195);
2389 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2390 tp->refCount++; /* hold this guy */
2391 ReleaseWriteLock(&afs_icl_lock);
2392 ObtainReadLock(&tp->lock);
2393 code = (*aproc)(tp->name, arock, tp);
2394 ReleaseReadLock(&tp->lock);
2395 ObtainWriteLock(&afs_icl_lock,196);
2396 if (--tp->refCount == 0)
2400 ReleaseWriteLock(&afs_icl_lock);
2404 struct afs_icl_set *afs_icl_allSets = 0;
2406 int afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
2407 struct afs_icl_log *fatalLogp, struct afs_icl_set **outSetpp)
2409 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2410 /*flags*/0, outSetpp);
2413 /* create a set, given pointers to base and fatal logs, if any.
2414 * Logs are unlocked, but referenced, and *outSetpp is returned
2415 * referenced. Function bumps reference count on logs, since it
2416 * addds references from the new afs_icl_set. When the set is destroyed,
2417 * those references will be released.
2419 int afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
2420 struct afs_icl_log *fatalLogp, afs_uint32 flags, struct afs_icl_set **outSetpp)
2422 register struct afs_icl_set *setp;
2424 afs_int32 states = ICL_DEFAULT_SET_STATES;
2426 ObtainWriteLock(&afs_icl_lock,197);
2427 if (!afs_icl_inited) afs_icl_Init();
2429 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2430 if (strcmp(setp->name, name) == 0) {
2433 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2435 ObtainWriteLock(&setp->lock,198);
2436 setp->states |= ICL_SETF_PERSISTENT;
2437 ReleaseWriteLock(&setp->lock);
2439 ReleaseWriteLock(&afs_icl_lock);
2444 /* determine initial state */
2445 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2446 states = ICL_SETF_ACTIVE;
2447 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2448 states = ICL_SETF_FREED;
2449 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2450 states |= ICL_SETF_PERSISTENT;
2452 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2453 memset((caddr_t)setp, 0, sizeof(*setp));
2455 if (states & ICL_SETF_FREED)
2456 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2457 setp->states = states;
2459 LOCK_INIT(&setp->lock, "setp lock");
2460 /* next lock is obtained in wrong order, hierarchy-wise, but
2461 * it doesn't matter, since no one can find this lock yet, since
2462 * the afs_icl_lock is still held, and thus the obtain can't block.
2464 ObtainWriteLock(&setp->lock,199);
2465 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2466 strcpy(setp->name, name);
2467 setp->nevents = ICL_DEFAULTEVENTS;
2468 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2469 #ifdef AFS_AIX32_ENV
2470 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2472 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2473 setp->eventFlags[i] = 0xff; /* default to enabled */
2475 /* update this global info under the afs_icl_lock */
2476 setp->nextp = afs_icl_allSets;
2477 afs_icl_allSets = setp;
2478 ReleaseWriteLock(&afs_icl_lock);
2480 /* set's basic lock is still held, so we can finish init */
2482 setp->logs[0] = baseLogp;
2483 afs_icl_LogHold(baseLogp);
2484 if (!(setp->states & ICL_SETF_FREED))
2485 afs_icl_LogUse(baseLogp); /* log is actually being used */
2488 setp->logs[1] = fatalLogp;
2489 afs_icl_LogHold(fatalLogp);
2490 if (!(setp->states & ICL_SETF_FREED))
2491 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2493 ReleaseWriteLock(&setp->lock);
2499 /* function to change event enabling information for a particular set */
2500 int afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
2504 ObtainWriteLock(&setp->lock,200);
2505 if (!ICL_EVENTOK(setp, eventID)) {
2506 ReleaseWriteLock(&setp->lock);
2509 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2511 *tp |= ICL_EVENTMASK(eventID);
2513 *tp &= ~(ICL_EVENTMASK(eventID));
2514 ReleaseWriteLock(&setp->lock);
2518 /* return indication of whether a particular event ID is enabled
2519 * for tracing. If *getValuep is set to 0, the event is disabled,
2520 * otherwise it is enabled. All events start out enabled by default.
2522 int afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID,
2525 ObtainReadLock(&setp->lock);
2526 if (!ICL_EVENTOK(setp, eventID)) {
2527 ReleaseWriteLock(&setp->lock);
2530 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2534 ReleaseReadLock(&setp->lock);
2538 /* hold and release event sets */
2539 int afs_icl_SetHold(register struct afs_icl_set *setp)
2541 ObtainWriteLock(&afs_icl_lock,201);
2543 ReleaseWriteLock(&afs_icl_lock);
2547 /* free a set. Called with afs_icl_lock locked */
2548 int afs_icl_ZapSet(register struct afs_icl_set *setp)
2550 register struct afs_icl_set **lpp, *tp;
2552 register struct afs_icl_log *tlp;
2554 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2556 /* found the dude we want to remove */
2558 osi_FreeSmallSpace(setp->name);
2559 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2560 #ifdef AFS_AIX32_ENV
2561 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2563 for(i=0; i < ICL_LOGSPERSET; i++) {
2564 if ((tlp = setp->logs[i]))
2565 afs_icl_LogReleNL(tlp);
2567 osi_FreeSmallSpace(setp);
2568 break; /* won't find it twice */
2574 /* do the release, watching for deleted entries */
2575 int afs_icl_SetRele(register struct afs_icl_set *setp)
2577 ObtainWriteLock(&afs_icl_lock,202);
2578 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2579 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2581 ReleaseWriteLock(&afs_icl_lock);
2585 /* free a set entry, dropping its reference count */
2586 int afs_icl_SetFree(register struct afs_icl_set *setp)
2588 ObtainWriteLock(&setp->lock,203);
2589 setp->states |= ICL_SETF_DELETED;
2590 ReleaseWriteLock(&setp->lock);
2591 afs_icl_SetRele(setp);
2595 /* find a set by name, returning it held */
2596 struct afs_icl_set *afs_icl_FindSet(char *name)
2598 register struct afs_icl_set *tp;
2599 ObtainWriteLock(&afs_icl_lock,204);
2600 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2601 if (strcmp(tp->name, name) == 0) {
2602 /* this is the dude we want */
2607 ReleaseWriteLock(&afs_icl_lock);
2611 /* zero out all the logs in the set */
2612 int afs_icl_ZeroSet(struct afs_icl_set *setp)
2617 struct afs_icl_log *logp;
2619 ObtainReadLock(&setp->lock);
2620 for(i = 0; i < ICL_LOGSPERSET; i++) {
2621 logp = setp->logs[i];
2623 afs_icl_LogHold(logp);
2624 tcode = afs_icl_ZeroLog(logp);
2625 if (tcode != 0) code = tcode; /* save the last bad one */
2626 afs_icl_LogRele(logp);
2629 ReleaseReadLock(&setp->lock);
2633 int afs_icl_EnumerateSets(int (*aproc)(), char *arock)
2635 register struct afs_icl_set *tp, *np;
2636 register afs_int32 code;
2639 ObtainWriteLock(&afs_icl_lock,205);
2640 for(tp = afs_icl_allSets; tp; tp=np) {
2641 tp->refCount++; /* hold this guy */
2642 ReleaseWriteLock(&afs_icl_lock);
2643 code = (*aproc)(tp->name, arock, tp);
2644 ObtainWriteLock(&afs_icl_lock,206);
2645 np = tp->nextp; /* tp may disappear next, but not np */
2646 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2650 ReleaseWriteLock(&afs_icl_lock);
2654 int afs_icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
2658 struct afs_icl_log *logp;
2660 ObtainWriteLock(&setp->lock,207);
2661 for(i = 0; i < ICL_LOGSPERSET; i++) {
2662 if (!setp->logs[i]) {
2663 setp->logs[i] = newlogp;
2665 afs_icl_LogHold(newlogp);
2666 if (!(setp->states & ICL_SETF_FREED)) {
2667 /* bump up the number of sets using the log */
2668 afs_icl_LogUse(newlogp);
2673 ReleaseWriteLock(&setp->lock);
2677 int afs_icl_SetSetStat(struct afs_icl_set *setp, int op)
2681 struct afs_icl_log *logp;
2683 ObtainWriteLock(&setp->lock,208);
2685 case ICL_OP_SS_ACTIVATE: /* activate a log */
2687 * If we are not already active, see if we have released
2688 * our demand that the log be allocated (FREED set). If
2689 * we have, reassert our desire.
2691 if (!(setp->states & ICL_SETF_ACTIVE)) {
2692 if (setp->states & ICL_SETF_FREED) {
2693 /* have to reassert desire for logs */
2694 for(i = 0; i < ICL_LOGSPERSET; i++) {
2695 logp = setp->logs[i];
2697 afs_icl_LogHold(logp);
2698 afs_icl_LogUse(logp);
2699 afs_icl_LogRele(logp);
2702 setp->states &= ~ICL_SETF_FREED;
2704 setp->states |= ICL_SETF_ACTIVE;
2709 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2710 /* this doesn't require anything beyond clearing the ACTIVE flag */
2711 setp->states &= ~ICL_SETF_ACTIVE;
2715 case ICL_OP_SS_FREE: /* deassert design for log */
2717 * if we are already in this state, do nothing; otherwise
2718 * deassert desire for log
2720 if (setp->states & ICL_SETF_ACTIVE)
2723 if (!(setp->states & ICL_SETF_FREED)) {
2724 for(i = 0; i < ICL_LOGSPERSET; i++) {
2725 logp = setp->logs[i];
2727 afs_icl_LogHold(logp);
2728 afs_icl_LogFreeUse(logp);
2729 afs_icl_LogRele(logp);
2732 setp->states |= ICL_SETF_FREED;
2741 ReleaseWriteLock(&setp->lock);