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(KERNEL_HAVE_SETUERROR)
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(KERNEL_HAVE_SETUERROR)
390 afs_CacheInit_Done = 1;
392 struct afs_icl_log *logp;
393 /* initialize the ICL system */
394 code = afs_icl_CreateLog("cmfx", 60*1024, &logp);
396 code = afs_icl_CreateSetWithFlags("cm", logp,
397 (struct icl_log *) 0,
398 ICL_CRSET_FLAG_DEFAULT_OFF,
400 code = afs_icl_CreateSet("cmlongterm", logp, (struct icl_log*) 0,
401 &afs_iclLongTermSetp);
403 afs_setTime = cparms.setTimeFlag;
405 code = afs_CacheInit(cparms.cacheScaches,
416 else if (parm == AFSOP_CACHEINODE) {
417 ino_t ainode = parm2;
418 /* wait for basic init */
419 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
423 ainode = (ainode << 32) | (parm3 & 0xffffffff);
425 code = afs_InitCacheFile(NULL, ainode);
427 else if (parm == AFSOP_ROOTVOLUME) {
428 /* wait for basic init */
429 while (afs_initState < AFSOP_START_BKG) afs_osi_Sleep(&afs_initState);
432 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName, sizeof(afs_rootVolumeName), &bufferSize, code);
433 afs_rootVolumeName[sizeof(afs_rootVolumeName)-1] = 0;
437 else if (parm == AFSOP_CACHEFILE ||
438 parm == AFSOP_CACHEINFO ||
439 parm == AFSOP_VOLUMEINFO ||
440 parm == AFSOP_AFSLOG ||
441 parm == AFSOP_CELLINFO) {
442 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
445 AFS_COPYINSTR((char *) parm2, tbuffer, AFS_SMALLOCSIZ,
448 osi_FreeSmallSpace(tbuffer);
452 tbuffer[AFS_SMALLOCSIZ-1] = '\0'; /* null-terminate the name */
453 /* We have the cache dir copied in. Call the cache init routine */
454 if (parm == AFSOP_CACHEFILE)
455 code = afs_InitCacheFile(tbuffer, 0);
456 else if (parm == AFSOP_CACHEINFO)
457 code = afs_InitCacheInfo(tbuffer);
458 else if (parm == AFSOP_VOLUMEINFO)
459 code = afs_InitVolumeInfo(tbuffer);
460 else if (parm == AFSOP_CELLINFO)
461 code = afs_InitCellInfo(tbuffer);
463 osi_FreeSmallSpace(tbuffer);
465 else if (parm == AFSOP_GO) {
466 /* the generic initialization calls come here. One parameter: should we do the
467 set-time operation on this workstation */
468 if (afs_Go_Done) goto out;
470 while (afs_initState < AFSOP_GO) afs_osi_Sleep(&afs_initState);
473 afs_osi_Wakeup(&afs_initState);
474 #if (!defined(AFS_NONFSTRANS) && !defined(AFS_DEC_ENV)) || defined(AFS_AIX_IAUTH_ENV)
475 afs_nfsclient_init();
477 printf("found %d non-empty cache files (%d%%).\n", afs_stats_cmperf.cacheFilesReused,
478 (100*afs_stats_cmperf.cacheFilesReused) /
479 (afs_stats_cmperf.cacheNumEntries?afs_stats_cmperf.cacheNumEntries : 1));
481 else if (parm == AFSOP_ADVISEADDR) {
482 /* pass in the host address to the rx package */
483 afs_int32 count = parm2;
484 afs_int32 buffer[AFS_MAX_INTERFACE_ADDR];
485 afs_int32 maskbuffer[AFS_MAX_INTERFACE_ADDR];
486 afs_int32 mtubuffer[AFS_MAX_INTERFACE_ADDR];
490 if ( count > AFS_MAX_INTERFACE_ADDR ) {
492 count = AFS_MAX_INTERFACE_ADDR;
495 AFS_COPYIN( (char *)parm3, (char *)buffer, count*sizeof(afs_int32), code);
497 AFS_COPYIN((char *)parm4, (char *)maskbuffer, count*sizeof(afs_int32), code);
499 AFS_COPYIN((char *)parm5, (char *)mtubuffer, count*sizeof(afs_int32), code);
501 afs_cb_interface.numberOfInterfaces = count;
502 for (i=0; i < count ; i++) {
503 afs_cb_interface.addr_in[i] = buffer[i];
504 #ifdef AFS_USERSPACE_IP_ADDR
505 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
506 * machines IP addresses when in the kernel (the in_ifaddr
507 * struct is not available), so we pass the info in at
508 * startup. We also pass in the subnetmask and mtu size. The
509 * subnetmask is used when setting the rank:
510 * afsi_SetServerIPRank(); and the mtu size is used when
511 * finding the best mtu size. rxi_FindIfnet() is replaced
512 * with rxi_Findcbi().
514 afs_cb_interface.subnetmask[i] = (parm4 ? maskbuffer[i] : 0xffffffff);
515 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
518 afs_uuid_create(&afs_cb_interface.uuid);
519 rxi_setaddr(buffer[0]);
523 else if (parm == AFSOP_NFSSTATICADDR) {
524 extern int (*nfs_rfsdisptab_v2)();
525 nfs_rfsdisptab_v2 = (int (*)())parm2;
527 else if (parm == AFSOP_NFSSTATICADDR2) {
528 extern int (*nfs_rfsdisptab_v2)();
530 nfs_rfsdisptab_v2 = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
532 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
535 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
536 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
537 extern int (*afs_sblockp)();
538 extern void (*afs_sbunlockp)();
540 afs_sblockp = (int (*)())((parm2<<32) | (parm3 & 0xffffffff));
541 afs_sbunlockp = (void (*)())((parm4<<32) | (parm5 & 0xffffffff));
543 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
544 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
547 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
548 #endif /* AFS_SGI53_ENV */
549 else if (parm == AFSOP_SHUTDOWN) {
550 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
551 extern struct mount *afs_globalVFS;
552 #else /* AFS_OSF_ENV */
553 extern struct vfs *afs_globalVFS;
555 afs_cold_shutdown = 0;
556 if (parm == 1) afs_cold_shutdown = 1;
557 if (afs_globalVFS != 0) {
558 afs_warn("AFS isn't unmounted yet! Call aborted\n");
564 #if ! defined(AFS_HPUX90_ENV) || defined(AFS_HPUX100_ENV)
565 else if (parm == AFSOP_AFS_VFSMOUNT) {
567 #if defined(AFS_HPUX100_ENV)
568 vfsmount(parm2, parm3, parm4, parm5);
570 afs_vfs_mount(parm2, parm3, parm4, parm5);
571 #endif /* AFS_HPUX100_ENV */
572 #else /* defined(AFS_HPUX_ENV) */
573 #if defined(KERNEL_HAVE_SETUERROR)
578 #endif /* defined(AFS_HPUX_ENV) */
581 else if (parm == AFSOP_CLOSEWAIT) {
582 afs_SynchronousCloses = 'S';
584 else if (parm == AFSOP_GETMTU) {
586 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
587 #ifdef AFS_USERSPACE_IP_ADDR
589 i = rxi_Findcbi(parm2);
590 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
591 #else /* AFS_USERSPACE_IP_ADDR */
593 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
594 extern struct ifnet *rxi_FindIfnet();
596 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
597 mtu = (tifnp ? tifnp->if_mtu : htonl(1500));
598 #endif /* else AFS_USERSPACE_IP_ADDR */
599 #endif /* !AFS_SUN5_ENV */
601 AFS_COPYOUT ((caddr_t)&mtu, (caddr_t)parm3, sizeof(afs_int32), code);
603 /* this is disabled for now because I can't figure out how to get access
604 * to these kernel variables. It's only for supporting user-mode rx
605 * programs -- it makes a huge difference on the 220's in my testbed,
606 * though I don't know why. The bosserver does this with /etc/no, so it's
607 * being handled a different way for the servers right now. */
610 extern u_long sb_max_dflt;
613 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
614 if (sb_max < 131072) sb_max = 131072;
617 #endif /* AFS_AIX32_ENV */
619 else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
621 #if !defined(AFS_SUN5_ENV)
622 #ifdef AFS_USERSPACE_IP_ADDR
624 i = rxi_Findcbi(parm2);
626 mask = afs_cb_interface.subnetmask[i];
630 #else /* AFS_USERSPACE_IP_ADDR */
632 #ifdef AFS_DARWIN60_ENV
633 struct ifaddr *tifadp = (struct ifaddr *) 0;
635 struct in_ifaddr *tifadp = (struct in_ifaddr *) 0;
637 extern struct ifnet *rxi_FindIfnet();
638 tifnp = rxi_FindIfnet(parm2, &tifadp); /* make iterative */
639 if (tifnp && tifadp) {
640 #ifdef AFS_DARWIN60_ENV
641 mask = ((struct sockaddr_in *)tifadp->ifa_netmask)->sin_addr.s_addr;
643 mask = tifadp->ia_subnetmask;
648 #endif /* else AFS_USERSPACE_IP_ADDR */
649 #endif /* !AFS_SUN5_ENV */
651 AFS_COPYOUT ((caddr_t)&mask, (caddr_t)parm3, sizeof(afs_int32), code);
654 else if (parm == AFSOP_AFSDB_HANDLER) {
655 int sizeArg = (int)parm4;
656 int kmsgLen = sizeArg & 0xffff;
657 int cellLen = (sizeArg & 0xffff0000) >> 16;
658 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
659 char *cellname = afs_osi_Alloc(cellLen);
662 afs_osi_MaskSignals();
664 AFS_COPYIN((afs_int32 *)parm2, cellname, cellLen, code);
665 AFS_COPYIN((afs_int32 *)parm3, kmsg, kmsgLen, code);
667 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
668 if (*cellname == 1) *cellname = 0;
669 if (code == -2) { /* Shutting down? */
674 if (!code) AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
675 afs_osi_Free(kmsg, kmsgLen);
676 afs_osi_Free(cellname, cellLen);
679 else if (parm == AFSOP_SET_DYNROOT) {
680 code = afs_SetDynrootEnable(parm2);
682 else if (parm == AFSOP_SET_FAKESTAT) {
683 afs_fakestat_enable = parm2;
691 #ifdef AFS_LINUX20_ENV
700 #include "sys/lockl.h"
703 * syscall - this is the VRMIX system call entry point.
706 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
707 * all the user-level calls to `syscall' to change.
709 syscall(syscall, p1, p2, p3, p4, p5, p6) {
710 register rval1=0, code;
713 #ifndef AFS_AIX41_ENV
714 extern lock_t kernel_lock;
715 monster = lockl(&kernel_lock, LOCK_SHORT);
716 #endif /* !AFS_AIX41_ENV */
718 AFS_STATCNT(syscall);
722 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
727 rval1 = afs_setpag();
733 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
737 case AFSCALL_ICREATE:
738 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
742 rval1 = afs_syscall_iopen(p1, p2, p3);
746 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
750 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
755 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
757 if (!code) rval1 = retval;
758 if (!rval1) rval1 = code;
768 #ifndef AFS_AIX41_ENV
769 if (monster != LOCK_NEST)
770 unlockl(&kernel_lock);
771 #endif /* !AFS_AIX41_ENV */
772 return getuerror() ? -1 : rval1;
776 * lsetpag - interface to afs_setpag().
780 AFS_STATCNT(lsetpag);
781 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
785 * lpioctl - interface to pioctl()
787 lpioctl(path, cmd, cmarg, follow)
788 char *path, *cmarg; {
790 AFS_STATCNT(lpioctl);
791 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
794 #else /* !AFS_AIX32_ENV */
796 #if defined(AFS_SGI_ENV)
809 Afs_syscall (struct afsargs *uap, rval_t *rvp)
814 AFS_STATCNT(afs_syscall);
815 switch(uap->syscall) {
819 error=Afscall_icl(uap->parm1,uap->parm2,uap->parm3,uap->parm4,uap->parm5, &retval);
821 rvp->r_val1 = retval;
823 #ifdef AFS_SGI_XFS_IOPS_ENV
825 error = afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3,
826 uap->parm4, uap->parm5);
829 error = afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3,
830 uap->parm4, uap->parm5);
832 case AFSCALL_ILISTINODE64:
833 error = afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
834 uap->parm4, uap->parm5);
836 case AFSCALL_ICREATENAME64:
837 error = afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
838 uap->parm4, uap->parm5);
841 #ifdef AFS_SGI_VNODE_GLUE
842 case AFSCALL_INIT_KERNEL_CONFIG:
843 error = afs_init_kernel_config(uap->parm1);
847 error = afs_syscall_call(uap->syscall, uap->parm1, uap->parm2,
848 uap->parm3, uap->parm4, uap->parm5);
853 #else /* AFS_SGI_ENV */
871 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
873 dst->param1 = src->param1;
874 dst->param2 = src->param2;
875 dst->param3 = src->param3;
876 dst->param4 = src->param4;
880 * If you need to change copyin_iparam(), you may also need to change
881 * copyin_afs_ioctl().
885 copyin_iparam(caddr_t cmarg, struct iparam *dst)
889 #if defined(AFS_HPUX_64BIT_ENV)
890 struct iparam32 dst32;
892 if (is_32bit(u.u_procp)) /* is_32bit() in proc_iface.h */
894 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
896 iparam32_to_iparam(&dst32, dst);
899 #endif /* AFS_HPUX_64BIT_ENV */
901 #if defined(AFS_SUN57_64BIT_ENV)
902 struct iparam32 dst32;
904 if (get_udatamodel() == DATAMODEL_ILP32) {
905 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
907 iparam32_to_iparam(&dst32, dst);
910 #endif /* AFS_SUN57_64BIT_ENV */
912 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
913 struct iparam32 dst32;
915 #ifdef AFS_SPARC64_LINUX24_ENV
916 if (current->thread.flags & SPARC_FLAG_32BIT)
917 #elif AFS_SPARC64_LINUX20_ENV
918 if (current->tss.flags & SPARC_FLAG_32BIT)
920 #error Not done for this linux version
921 #endif /* AFS_SPARC64_LINUX20_ENV */
923 AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
925 iparam32_to_iparam(&dst32, dst);
928 #endif /* AFS_LINUX_64BIT_KERNEL */
930 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
934 /* Main entry of all afs system calls */
936 extern int afs_sinited;
938 /** The 32 bit OS expects the members of this structure to be 32 bit
939 * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
940 * to accomodate both, *long* is used instead of afs_int32
965 Afs_syscall (uap, rvp)
966 register struct afssysa *uap;
969 int *retval = &rvp->r_val1;
970 #else /* AFS_SUN5_ENV */
971 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
972 afs3_syscall(p, args, retval)
985 } *uap = (struct a *)args;
986 #else /* AFS_OSF_ENV */
987 #ifdef AFS_LINUX20_ENV
995 long parm6; /* not actually used - should be removed */
997 /* Linux system calls only set up for 5 arguments. */
998 asmlinkage int afs_syscall(long syscall, long parm1, long parm2, long parm3,
1001 struct afssysargs args, *uap = &args;
1003 long *retval = &linux_ret;
1004 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
1005 #ifdef AFS_SPARC64_LINUX24_ENV
1006 afs_int32 eparm32[4];
1008 /* eparm is also used by AFSCALL_CALL in afsd.c */
1010 #if defined(UKERNEL)
1021 } *uap = (struct a *)u.u_ap;
1023 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)
1027 #endif /* SUN && !SUN5 */
1037 } *uap = (struct a *)u.u_ap;
1038 #endif /* UKERNEL */
1039 #if defined(AFS_DEC_ENV)
1040 int *retval = &u.u_r.r_val1;
1042 #if defined(AFS_HPUX_ENV)
1043 long *retval = &u.u_rval1;
1045 int *retval = &u.u_rval1;
1048 #endif /* AFS_LINUX20_ENV */
1049 #endif /* AFS_OSF_ENV */
1050 #endif /* AFS_SUN5_ENV */
1051 register int code = 0;
1053 AFS_STATCNT(afs_syscall);
1060 #ifdef AFS_LINUX20_ENV
1062 /* setup uap for use below - pull out the magic decoder ring to know
1063 * which syscalls have folded argument lists.
1065 uap->syscall = syscall;
1069 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
1070 #ifdef AFS_SPARC64_LINUX24_ENV
1071 /* from arch/sparc64/kernel/sys_sparc32.c */
1073 ({ unsigned long __ret; \
1074 __asm__ ("srl %0, 0, %0" \
1081 if (current->thread.flags & SPARC_FLAG_32BIT) {
1082 AFS_COPYIN((char*)parm4, (char*)eparm32, sizeof(eparm32), code);
1083 eparm[0]=AA(eparm32[0]);
1084 eparm[1]=AA(eparm32[1]);
1085 eparm[2]=AA(eparm32[2]);
1089 AFS_COPYIN((char*)parm4, (char*)eparm, sizeof(eparm), code);
1090 uap->parm4 = eparm[0];
1091 uap->parm5 = eparm[1];
1092 uap->parm6 = eparm[2];
1101 #if defined(AFS_HPUX_ENV)
1103 * There used to be code here (duplicated from osi_Init()) for
1104 * initializing the semaphore used by AFS_GLOCK(). Was the
1105 * duplication to handle the case of a dynamically loaded kernel
1110 if (uap->syscall == AFSCALL_CALL) {
1112 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
1113 uap->parm4, uap->parm5, uap->parm6, rvp, CRED());
1115 code = afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, uap->parm6);
1117 } else if (uap->syscall == AFSCALL_SETPAG) {
1119 register proc_t *procp;
1121 procp = ttoproc(curthread);
1123 code = afs_setpag(&procp->p_cred);
1127 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1128 code = afs_setpag(p, args, retval);
1129 #else /* AFS_OSF_ENV */
1130 code = afs_setpag();
1134 } else if (uap->syscall == AFSCALL_PIOCTL) {
1137 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, rvp, CRED());
1139 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1140 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, p->p_cred->pc_ucred);
1142 code = afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4);
1146 } else if (uap->syscall == AFSCALL_ICREATE) {
1147 struct iparam iparams;
1149 code = copyin_iparam((char *)uap->parm3, &iparams);
1151 #if defined(KERNEL_HAVE_SETUERROR)
1156 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1157 iparams.param3, iparams.param4, rvp, CRED());
1159 code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, iparams.param2,
1160 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1161 iparams.param3, iparams.param4, retval);
1163 iparams.param3, iparams.param4);
1165 #endif /* AFS_SUN5_ENV */
1166 } else if (uap->syscall == AFSCALL_IOPEN) {
1168 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp, CRED());
1170 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1171 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
1173 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
1175 #endif /* AFS_SUN5_ENV */
1176 } else if (uap->syscall == AFSCALL_IDEC) {
1178 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp, CRED());
1180 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
1181 #endif /* AFS_SUN5_ENV */
1182 } else if (uap->syscall == AFSCALL_IINC) {
1184 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp, CRED());
1186 code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
1187 #endif /* AFS_SUN5_ENV */
1188 } else if (uap->syscall == AFSCALL_ICL) {
1190 code = Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4, uap->parm5, retval);
1192 #ifdef AFS_LINUX20_ENV
1194 /* ICL commands can return values. */
1195 code = -linux_ret; /* Gets negated again at exit below */
1199 #if defined(KERNEL_HAVE_SETUERROR)
1203 #endif /* !AFS_LINUX20_ENV */
1205 #if defined(KERNEL_HAVE_SETUERROR)
1212 #ifdef AFS_LINUX20_ENV
1218 #endif /* AFS_SGI_ENV */
1219 #endif /* !AFS_AIX32_ENV */
1222 * Initstate in the range 0 < x < 100 are early initialization states.
1223 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1224 * the cache may be initialized.
1225 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1226 * is done after all the cache initialization has been done.
1227 * Initstate of 200 means that the volume has been looked up once, possibly
1229 * Initstate of 300 means that the volume has been *successfully* looked up.
1231 int afs_CheckInit(void)
1233 register int code = 0;
1235 AFS_STATCNT(afs_CheckInit);
1236 if (afs_initState <= 100)
1237 code = ENXIO; /* never finished init phase */
1238 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1239 while (afs_initState < 200) afs_osi_Sleep(&afs_initState);
1240 } else if (afs_initState == 200)
1241 code = ETIMEDOUT; /* didn't find root volume */
1245 int afs_shuttingdown = 0;
1246 void afs_shutdown(void)
1248 extern short afs_brsDaemons;
1249 extern afs_int32 afs_CheckServerDaemonStarted;
1250 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1251 extern struct osi_file *afs_cacheInodep;
1253 AFS_STATCNT(afs_shutdown);
1254 if (afs_shuttingdown) return;
1255 afs_shuttingdown = 1;
1256 if (afs_cold_shutdown) afs_warn("COLD ");
1257 else afs_warn("WARM ");
1258 afs_warn("shutting down of: CB... ");
1260 afs_termState = AFSOP_STOP_RXCALLBACK;
1261 rx_WakeupServerProcs();
1262 /* shutdown_rxkernel(); */
1263 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1264 afs_osi_Sleep(&afs_termState);
1266 afs_warn("afs... ");
1267 while (afs_termState == AFSOP_STOP_AFS) {
1268 afs_osi_CancelWait(&AFS_WaitHandler);
1269 afs_osi_Sleep(&afs_termState);
1271 if (afs_CheckServerDaemonStarted) {
1272 while (afs_termState == AFSOP_STOP_CS) {
1273 afs_osi_CancelWait(&AFS_CSWaitHandler);
1274 afs_osi_Sleep(&afs_termState);
1277 afs_warn("BkG... ");
1278 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1279 while (afs_termState == AFSOP_STOP_BKG) {
1280 afs_osi_Wakeup(&afs_brsDaemons);
1281 afs_osi_Sleep(&afs_termState);
1283 afs_warn("CTrunc... ");
1284 /* Cancel cache truncate daemon. */
1285 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1286 afs_osi_Wakeup((char*)&afs_CacheTruncateDaemon);
1287 afs_osi_Sleep(&afs_termState);
1289 #ifdef AFS_AFSDB_ENV
1290 afs_warn("AFSDB... ");
1292 while (afs_termState == AFSOP_STOP_AFSDB)
1293 afs_osi_Sleep(&afs_termState);
1295 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1296 afs_warn("RxEvent... ");
1297 /* cancel rx event deamon */
1298 while (afs_termState == AFSOP_STOP_RXEVENT)
1299 afs_osi_Sleep(&afs_termState);
1300 #if defined(RXK_LISTENER_ENV)
1302 afs_warn("UnmaskRxkSignals... ");
1303 afs_osi_UnmaskRxkSignals();
1305 /* cancel rx listener */
1306 afs_warn("RxListener... ");
1307 osi_StopListener(); /* This closes rx_socket. */
1308 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1309 afs_warn("Sleep... ");
1310 afs_osi_Sleep(&afs_termState);
1314 afs_termState = AFSOP_STOP_COMPLETE;
1318 /* Close file only after daemons which can write to it are stopped. */
1319 if (afs_cacheInodep) /* memcache won't set this */
1321 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1322 afs_cacheInodep = 0;
1324 return; /* Just kill daemons for now */
1328 shutdown_rxkernel();
1332 shutdown_bufferpackage();
1338 shutdown_vnodeops();
1340 shutdown_exporter();
1341 shutdown_memcache();
1342 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
1343 #if !defined(AFS_DEC_ENV) && !defined(AFS_OSF_ENV)
1344 /* this routine does not exist in Ultrix systems... 93.01.19 */
1346 #endif /* AFS_DEC_ENV */
1349 /* The following hold the cm stats */
1351 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1352 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1353 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1355 afs_warn(" ALL allocated tables\n");
1356 afs_shuttingdown = 0;
1360 void shutdown_afstest(void)
1362 AFS_STATCNT(shutdown_afstest);
1363 afs_initState = afs_termState = afs_setTime = 0;
1364 AFS_Running = afs_CB_Running = 0;
1365 afs_CacheInit_Done = afs_Go_Done = 0;
1366 if (afs_cold_shutdown) {
1367 *afs_rootVolumeName = 0;
1372 /* In case there is a bunch of dynamically build bkg daemons to free */
1373 void afs_shutdown_BKG(void)
1375 AFS_STATCNT(shutdown_BKG);
1379 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
1380 /* For SGI 6.2, this can is changed to 1 if it's a 32 bit kernel. */
1381 #if defined(AFS_SGI62_ENV) && defined(KERNEL) && !defined(_K64U64)
1382 int afs_icl_sizeofLong = 1;
1384 int afs_icl_sizeofLong = 2;
1387 int afs_icl_sizeofLong = 1;
1390 int afs_icl_inited = 0;
1392 /* init function, called once, under afs_icl_lock */
1393 int afs_icl_Init(void)
1399 extern struct afs_icl_log *afs_icl_FindLog();
1400 extern struct afs_icl_set *afs_icl_FindSet();
1404 Afscall_icl(long opcode, long p1, long p2, long p3, long p4, long *retval)
1407 afs_int32 *lp, elts, flags;
1408 register afs_int32 code;
1409 struct afs_icl_log *logp;
1410 struct afs_icl_set *setp;
1411 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1413 #else /* AFS_SGI61_ENV */
1415 #endif /* AFS_SGI61_ENV */
1417 afs_int32 startCookie;
1418 afs_int32 allocated;
1419 struct afs_icl_log *tlp;
1422 if (!afs_suser(CRED())) { /* only root can run this code */
1426 if (!afs_suser()) { /* only root can run this code */
1427 #if defined(KERNEL_HAVE_SETUERROR)
1436 case ICL_OP_COPYOUTCLR: /* copy out data then clear */
1437 case ICL_OP_COPYOUT: /* copy ouy data */
1438 /* copyout: p1=logname, p2=&buffer, p3=size(words), p4=&cookie
1439 * return flags<<24 + nwords.
1440 * updates cookie to updated start (not end) if we had to
1441 * skip some records.
1443 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1444 if (code) return code;
1445 AFS_COPYIN((char *)p4, (char *)&startCookie, sizeof(afs_int32), code);
1446 if (code) return code;
1447 logp = afs_icl_FindLog(tname);
1448 if (!logp) return ENOENT;
1449 #define BUFFERSIZE AFS_LRALLOCSIZ
1450 lp = (afs_int32 *) osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1451 elts = BUFFERSIZE / sizeof(afs_int32);
1452 if (p3 < elts) elts = p3;
1453 flags = (opcode == ICL_OP_COPYOUT) ? 0 : ICL_COPYOUTF_CLRAFTERREAD;
1454 code = afs_icl_CopyOut(logp, lp, &elts, (afs_uint32 *) &startCookie,
1457 osi_FreeLargeSpace((struct osi_buffer *) lp);
1460 AFS_COPYOUT((char *)lp, (char *)p2, elts * sizeof(afs_int32), code);
1461 if (code) goto done;
1462 AFS_COPYOUT((char *) &startCookie, (char *)p4, sizeof(afs_int32), code);
1463 if (code) goto done;
1464 *retval = (flags<<24) | (elts & 0xffffff);
1466 afs_icl_LogRele(logp);
1467 osi_FreeLargeSpace((struct osi_buffer *) lp);
1470 case ICL_OP_ENUMLOGS: /* enumerate logs */
1471 /* enumerate logs: p1=index, p2=&name, p3=sizeof(name), p4=&size.
1472 * return 0 for success, otherwise error.
1474 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1475 if (p1-- == 0) break;
1477 if (!tlp) return ENOENT; /* past the end of file */
1478 temp = strlen(tlp->name)+1;
1479 if (temp > p3) return EINVAL;
1480 AFS_COPYOUT(tlp->name, (char *) p2, temp, code);
1481 if (!code) /* copy out size of log */
1482 AFS_COPYOUT((char *)&tlp->logSize, (char *)p4, sizeof (afs_int32), code);
1485 case ICL_OP_ENUMLOGSBYSET: /* enumerate logs by set name */
1486 /* enumerate logs: p1=setname, p2=index, p3=&name, p4=sizeof(name).
1487 * return 0 for success, otherwise error.
1489 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1490 if (code) return code;
1491 setp = afs_icl_FindSet(tname);
1492 if (!setp) return ENOENT;
1493 if (p2 > ICL_LOGSPERSET)
1495 if (!(tlp = setp->logs[p2]))
1497 temp = strlen(tlp->name)+1;
1498 if (temp > p4) return EINVAL;
1499 AFS_COPYOUT(tlp->name, (char *)p3, temp, code);
1502 case ICL_OP_CLRLOG: /* clear specified log */
1503 /* zero out the specified log: p1=logname */
1504 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1505 if (code) return code;
1506 logp = afs_icl_FindLog(tname);
1507 if (!logp) return ENOENT;
1508 code = afs_icl_ZeroLog(logp);
1509 afs_icl_LogRele(logp);
1512 case ICL_OP_CLRSET: /* clear specified set */
1513 /* zero out the specified set: p1=setname */
1514 AFS_COPYINSTR((char *)p1, tname, sizeof (tname), &temp, code);
1515 if (code) return code;
1516 setp = afs_icl_FindSet(tname);
1517 if (!setp) return ENOENT;
1518 code = afs_icl_ZeroSet(setp);
1519 afs_icl_SetRele(setp);
1522 case ICL_OP_CLRALL: /* clear all logs */
1523 /* zero out all logs -- no args */
1525 ObtainWriteLock(&afs_icl_lock,178);
1526 for(tlp = afs_icl_allLogs; tlp; tlp=tlp->nextp) {
1527 tlp->refCount++; /* hold this guy */
1528 ReleaseWriteLock(&afs_icl_lock);
1529 /* don't clear persistent logs */
1530 if ((tlp->states & ICL_LOGF_PERSISTENT) == 0)
1531 code = afs_icl_ZeroLog(tlp);
1532 ObtainWriteLock(&afs_icl_lock,179);
1533 if (--tlp->refCount == 0)
1534 afs_icl_ZapLog(tlp);
1537 ReleaseWriteLock(&afs_icl_lock);
1540 case ICL_OP_ENUMSETS: /* enumerate all sets */
1541 /* enumerate sets: p1=index, p2=&name, p3=sizeof(name), p4=&states.
1542 * return 0 for success, otherwise error.
1544 for(setp = afs_icl_allSets; setp; setp = setp->nextp) {
1545 if (p1-- == 0) break;
1547 if (!setp) return ENOENT; /* past the end of file */
1548 temp = strlen(setp->name)+1;
1549 if (temp > p3) return EINVAL;
1550 AFS_COPYOUT(setp->name, (char *)p2, temp, code);
1551 if (!code) /* copy out size of log */
1552 AFS_COPYOUT((char *)&setp->states,(char *)p4, sizeof (afs_int32), code);
1555 case ICL_OP_SETSTAT: /* set status on a set */
1556 /* activate the specified set: p1=setname, p2=op */
1557 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1558 if (code) return code;
1559 setp = afs_icl_FindSet(tname);
1560 if (!setp) return ENOENT;
1561 code = afs_icl_SetSetStat(setp, p2);
1562 afs_icl_SetRele(setp);
1565 case ICL_OP_SETSTATALL: /* set status on all sets */
1566 /* activate the specified set: p1=op */
1568 ObtainWriteLock(&afs_icl_lock,180);
1569 for(setp = afs_icl_allSets; setp; setp=setp->nextp) {
1570 setp->refCount++; /* hold this guy */
1571 ReleaseWriteLock(&afs_icl_lock);
1572 /* don't set states on persistent sets */
1573 if ((setp->states & ICL_SETF_PERSISTENT) == 0)
1574 code = afs_icl_SetSetStat(setp, p1);
1575 ObtainWriteLock(&afs_icl_lock,181);
1576 if (--setp->refCount == 0)
1577 afs_icl_ZapSet(setp);
1580 ReleaseWriteLock(&afs_icl_lock);
1583 case ICL_OP_SETLOGSIZE: /* set size of log */
1584 /* set the size of the specified log: p1=logname, p2=size (in words) */
1585 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1586 if (code) return code;
1587 logp = afs_icl_FindLog(tname);
1588 if (!logp) return ENOENT;
1589 code = afs_icl_LogSetSize(logp, p2);
1590 afs_icl_LogRele(logp);
1593 case ICL_OP_GETLOGINFO: /* get size of log */
1594 /* zero out the specified log: p1=logname, p2=&logSize, p3=&allocated */
1595 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1596 if (code) return code;
1597 logp = afs_icl_FindLog(tname);
1598 if (!logp) return ENOENT;
1599 allocated = !!logp->datap;
1600 AFS_COPYOUT((char *)&logp->logSize, (char *) p2, sizeof(afs_int32), code);
1602 AFS_COPYOUT((char *)&allocated, (char *) p3, sizeof(afs_int32), code);
1603 afs_icl_LogRele(logp);
1606 case ICL_OP_GETSETINFO: /* get state of set */
1607 /* zero out the specified set: p1=setname, p2=&state */
1608 AFS_COPYINSTR((char *)p1, tname, sizeof(tname), &temp, code);
1609 if (code) return code;
1610 setp = afs_icl_FindSet(tname);
1611 if (!setp) return ENOENT;
1612 AFS_COPYOUT((char *)&setp->states, (char *) p2, sizeof(afs_int32), code);
1613 afs_icl_SetRele(setp);
1624 afs_lock_t afs_icl_lock;
1626 /* exported routine: a 4 parameter event */
1627 int afs_icl_Event4(register struct afs_icl_set *setp, afs_int32 eventID,
1628 afs_int32 lAndT, long p1, long p2, long p3, long p4)
1630 register struct afs_icl_log *logp;
1633 register afs_int32 tmask;
1636 /* If things aren't init'ed yet (or the set is inactive), don't panic */
1637 if (!ICL_SETACTIVE(setp)) return;
1640 mask = lAndT>>24 & 0xff; /* mask of which logs to log to */
1641 ix = ICL_EVENTBYTE(eventID);
1642 ObtainReadLock(&setp->lock);
1643 if (setp->eventFlags[ix] & ICL_EVENTMASK(eventID)) {
1644 for(i=0, tmask = 1; i<ICL_LOGSPERSET; i++, tmask <<= 1) {
1646 afs_icl_AppendRecord(setp->logs[i], eventID, lAndT & 0xffffff,
1650 if (mask == 0) break; /* break early */
1653 ReleaseReadLock(&setp->lock);
1656 /* Next 4 routines should be implemented via var-args or something.
1657 * Whole purpose is to avoid compiler warnings about parameter # mismatches.
1658 * Otherwise, could call afs_icl_Event4 directly.
1660 int afs_icl_Event3(register struct afs_icl_set *setp, afs_int32 eventID,
1661 afs_int32 lAndT, long p1, long p2, long p3)
1663 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, p3, (long)0);
1666 int afs_icl_Event2(register struct afs_icl_set *setp, afs_int32 eventID,
1667 afs_int32 lAndT, long p1, long p2)
1669 return afs_icl_Event4(setp, eventID, lAndT, p1, p2, (long)0, (long)0);
1672 int afs_icl_Event1(register struct afs_icl_set *setp, afs_int32 eventID,
1673 afs_int32 lAndT, long p1)
1675 return afs_icl_Event4(setp, eventID, lAndT, p1, (long)0, (long)0, (long)0);
1678 int afs_icl_Event0(register struct afs_icl_set *setp, afs_int32 eventID,
1681 return afs_icl_Event4(setp, eventID, lAndT, (long)0, (long)0, (long)0, (long)0);
1684 struct afs_icl_log *afs_icl_allLogs = 0;
1686 /* function to purge records from the start of the log, until there
1687 * is at least minSpace long's worth of space available without
1688 * making the head and the tail point to the same word.
1690 * Log must be write-locked.
1692 static afs_icl_GetLogSpace(register struct afs_icl_log *logp, afs_int32 minSpace)
1694 register unsigned int tsize;
1696 while (logp->logSize - logp->logElements <= minSpace) {
1698 tsize = ((logp->datap[logp->firstUsed]) >> 24) & 0xff;
1699 logp->logElements -= tsize;
1700 logp->firstUsed += tsize;
1701 if (logp->firstUsed >= logp->logSize)
1702 logp->firstUsed -= logp->logSize;
1703 logp->baseCookie += tsize;
1707 /* append string astr to buffer, including terminating null char.
1709 * log must be write-locked.
1711 #define ICL_CHARSPERLONG 4
1712 static afs_int32 afs_icl_AppendString(struct afs_icl_log *logp, char *astr)
1714 char *op; /* ptr to char to write */
1716 register int bib; /* bytes in buffer */
1719 op = (char *) &(logp->datap[logp->firstFree]);
1723 if (++bib >= ICL_CHARSPERLONG) {
1726 if (++(logp->firstFree) >= logp->logSize) {
1727 logp->firstFree = 0;
1728 op = (char *) &(logp->datap[0]);
1730 logp->logElements++;
1735 /* if we've used this word at all, allocate it */
1736 if (++(logp->firstFree) >= logp->logSize) {
1737 logp->firstFree = 0;
1739 logp->logElements++;
1743 /* add a long to the log, ignoring overflow (checked already) */
1744 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1745 #define ICL_APPENDINT32(lp, x) \
1747 (lp)->datap[(lp)->firstFree] = (x); \
1748 if (++((lp)->firstFree) >= (lp)->logSize) { \
1749 (lp)->firstFree = 0; \
1751 (lp)->logElements++; \
1754 #define ICL_APPENDLONG(lp, x) \
1756 ICL_APPENDINT32((lp), ((x) >> 32) & 0xffffffffL); \
1757 ICL_APPENDINT32((lp), (x) & 0xffffffffL); \
1760 #else /* AFS_ALPHA_ENV */
1761 #define ICL_APPENDLONG(lp, x) \
1763 (lp)->datap[(lp)->firstFree] = (x); \
1764 if (++((lp)->firstFree) >= (lp)->logSize) { \
1765 (lp)->firstFree = 0; \
1767 (lp)->logElements++; \
1769 #define ICL_APPENDINT32(lp, x) ICL_APPENDLONG((lp), (x))
1770 #endif /* AFS_ALPHA_ENV */
1772 /* routine to tell whether we're dealing with the address or the
1775 int afs_icl_UseAddr(int type)
1777 if (type == ICL_TYPE_HYPER || type == ICL_TYPE_STRING
1778 || type == ICL_TYPE_FID || type == ICL_TYPE_INT64)
1784 /* Function to append a record to the log. Written for speed
1785 * since we know that we're going to have to make this work fast
1786 * pretty soon, anyway. The log must be unlocked.
1789 int afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
1790 afs_int32 types, long p1, long p2, long p3, long p4)
1792 int rsize; /* record size in longs */
1793 register int tsize; /* temp size */
1797 t4 = types & 0x3f; /* decode types */
1805 osi_GetTime(&tv); /* It panics for solaris if inside */
1806 ObtainWriteLock(&logp->lock,182);
1808 ReleaseWriteLock(&logp->lock);
1812 /* get timestamp as # of microseconds since some time that doesn't
1813 * change that often. This algorithm ticks over every 20 minutes
1814 * or so (1000 seconds). Write a timestamp record if it has.
1816 if (tv.tv_sec - logp->lastTS > 1024)
1818 /* the timer has wrapped -- write a timestamp record */
1819 if (logp->logSize - logp->logElements <= 5)
1820 afs_icl_GetLogSpace(logp, 5);
1822 ICL_APPENDINT32(logp, (afs_int32)(5<<24) + (ICL_TYPE_UNIXDATE<<18));
1823 ICL_APPENDINT32(logp, (afs_int32)ICL_INFO_TIMESTAMP);
1824 ICL_APPENDINT32(logp, (afs_int32)0); /* use thread ID zero for clocks */
1825 ICL_APPENDINT32(logp,
1826 (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1827 ICL_APPENDINT32(logp, (afs_int32)tv.tv_sec);
1829 logp->lastTS = tv.tv_sec;
1832 rsize = 4; /* base case */
1834 /* compute size of parameter p1. Only tricky case is string.
1835 * In that case, we have to call strlen to get the string length.
1837 ICL_SIZEHACK(t1, p1);
1840 /* compute size of parameter p2. Only tricky case is string.
1841 * In that case, we have to call strlen to get the string length.
1843 ICL_SIZEHACK(t2, p2);
1846 /* compute size of parameter p3. Only tricky case is string.
1847 * In that case, we have to call strlen to get the string length.
1849 ICL_SIZEHACK(t3, p3);
1852 /* compute size of parameter p4. Only tricky case is string.
1853 * In that case, we have to call strlen to get the string length.
1855 ICL_SIZEHACK(t4, p4);
1858 /* At this point, we've computed all of the parameter sizes, and
1859 * have in rsize the size of the entire record we want to append.
1860 * Next, we check that we actually have room in the log to do this
1861 * work, and then we do the append.
1864 ReleaseWriteLock(&logp->lock);
1865 return; /* log record too big to express */
1868 if (logp->logSize - logp->logElements <= rsize)
1869 afs_icl_GetLogSpace(logp, rsize);
1871 ICL_APPENDINT32(logp,
1872 (afs_int32)(rsize<<24) + (t1<<18) + (t2<<12) + (t3<<6) + t4);
1873 ICL_APPENDINT32(logp, (afs_int32)op);
1874 ICL_APPENDINT32(logp, (afs_int32)osi_ThreadUnique());
1875 ICL_APPENDINT32(logp, (afs_int32)(tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
1878 /* marshall parameter 1 now */
1879 if (t1 == ICL_TYPE_STRING) {
1880 afs_icl_AppendString(logp, (char *) p1);
1882 else if (t1 == ICL_TYPE_HYPER) {
1883 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->high);
1884 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p1)->low);
1886 else if (t1 == ICL_TYPE_INT64) {
1887 #ifdef AFSLITTLE_ENDIAN
1888 #ifdef AFS_64BIT_CLIENT
1889 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1890 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1891 #else /* AFS_64BIT_CLIENT */
1892 ICL_APPENDINT32(logp, (afs_int32) p1);
1893 ICL_APPENDINT32(logp, (afs_int32) 0);
1894 #endif /* AFS_64BIT_CLIENT */
1895 #else /* AFSLITTLE_ENDIAN */
1896 #ifdef AFS_64BIT_CLIENT
1897 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1898 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1899 #else /* AFS_64BIT_CLIENT */
1900 ICL_APPENDINT32(logp, (afs_int32) 0);
1901 ICL_APPENDINT32(logp, (afs_int32) p1);
1902 #endif /* AFS_64BIT_CLIENT */
1903 #endif /* AFSLITTLE_ENDIAN */
1905 else if (t1 == ICL_TYPE_FID) {
1906 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[0]);
1907 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[1]);
1908 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[2]);
1909 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p1)[3]);
1911 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1912 else if (t1 == ICL_TYPE_INT32)
1913 ICL_APPENDINT32(logp, (afs_int32)p1);
1914 #endif /* AFS_ALPHA_ENV */
1915 else ICL_APPENDLONG(logp, p1);
1918 /* marshall parameter 2 now */
1919 if (t2 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p2);
1920 else if (t2 == ICL_TYPE_HYPER) {
1921 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->high);
1922 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p2)->low);
1924 else if (t2 == ICL_TYPE_INT64) {
1925 #ifdef AFSLITTLE_ENDIAN
1926 #ifdef AFS_64BIT_CLIENT
1927 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1928 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1929 #else /* AFS_64BIT_CLIENT */
1930 ICL_APPENDINT32(logp, (afs_int32) p2);
1931 ICL_APPENDINT32(logp, (afs_int32) 0);
1932 #endif /* AFS_64BIT_CLIENT */
1933 #else /* AFSLITTLE_ENDIAN */
1934 #ifdef AFS_64BIT_CLIENT
1935 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1936 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1937 #else /* AFS_64BIT_CLIENT */
1938 ICL_APPENDINT32(logp, (afs_int32) 0);
1939 ICL_APPENDINT32(logp, (afs_int32) p2);
1940 #endif /* AFS_64BIT_CLIENT */
1941 #endif /* AFSLITTLE_ENDIAN */
1943 else if (t2 == ICL_TYPE_FID) {
1944 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[0]);
1945 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[1]);
1946 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[2]);
1947 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p2)[3]);
1949 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1950 else if (t2 == ICL_TYPE_INT32)
1951 ICL_APPENDINT32(logp, (afs_int32)p2);
1952 #endif /* AFS_ALPHA_ENV */
1953 else ICL_APPENDLONG(logp, p2);
1956 /* marshall parameter 3 now */
1957 if (t3 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p3);
1958 else if (t3 == ICL_TYPE_HYPER) {
1959 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->high);
1960 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p3)->low);
1962 else if (t3 == ICL_TYPE_INT64) {
1963 #ifdef AFSLITTLE_ENDIAN
1964 #ifdef AFS_64BIT_CLIENT
1965 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1966 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1967 #else /* AFS_64BIT_CLIENT */
1968 ICL_APPENDINT32(logp, (afs_int32) p3);
1969 ICL_APPENDINT32(logp, (afs_int32) 0);
1970 #endif /* AFS_64BIT_CLIENT */
1971 #else /* AFSLITTLE_ENDIAN */
1972 #ifdef AFS_64BIT_CLIENT
1973 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1974 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1975 #else /* AFS_64BIT_CLIENT */
1976 ICL_APPENDINT32(logp, (afs_int32) 0);
1977 ICL_APPENDINT32(logp, (afs_int32) p3);
1978 #endif /* AFS_64BIT_CLIENT */
1979 #endif /* AFSLITTLE_ENDIAN */
1981 else if (t3 == ICL_TYPE_FID) {
1982 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[0]);
1983 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[1]);
1984 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[2]);
1985 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p3)[3]);
1987 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
1988 else if (t3 == ICL_TYPE_INT32)
1989 ICL_APPENDINT32(logp, (afs_int32)p3);
1990 #endif /* AFS_ALPHA_ENV */
1991 else ICL_APPENDLONG(logp, p3);
1994 /* marshall parameter 4 now */
1995 if (t4 == ICL_TYPE_STRING) afs_icl_AppendString(logp, (char *) p4);
1996 else if (t4 == ICL_TYPE_HYPER) {
1997 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->high);
1998 ICL_APPENDINT32(logp, (afs_int32)((struct afs_hyper_t *)p4)->low);
2000 else if (t4 == ICL_TYPE_INT64) {
2001 #ifdef AFSLITTLE_ENDIAN
2002 #ifdef AFS_64BIT_CLIENT
2003 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2004 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2005 #else /* AFS_64BIT_CLIENT */
2006 ICL_APPENDINT32(logp, (afs_int32) p4);
2007 ICL_APPENDINT32(logp, (afs_int32) 0);
2008 #endif /* AFS_64BIT_CLIENT */
2009 #else /* AFSLITTLE_ENDIAN */
2010 #ifdef AFS_64BIT_CLIENT
2011 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2012 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2013 #else /* AFS_64BIT_CLIENT */
2014 ICL_APPENDINT32(logp, (afs_int32) 0);
2015 ICL_APPENDINT32(logp, (afs_int32) p4);
2016 #endif /* AFS_64BIT_CLIENT */
2017 #endif /* AFSLITTLE_ENDIAN */
2019 else if (t4 == ICL_TYPE_FID) {
2020 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[0]);
2021 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[1]);
2022 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[2]);
2023 ICL_APPENDINT32(logp, (afs_int32)((afs_int32 *)p4)[3]);
2025 #if defined(AFS_ALPHA_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64))
2026 else if (t4 == ICL_TYPE_INT32)
2027 ICL_APPENDINT32(logp, (afs_int32)p4);
2028 #endif /* AFS_ALPHA_ENV */
2029 else ICL_APPENDLONG(logp, p4);
2031 ReleaseWriteLock(&logp->lock);
2034 /* create a log with size logSize; return it in *outLogpp and tag
2035 * it with name "name."
2037 int afs_icl_CreateLog(char *name, afs_int32 logSize, struct afs_icl_log **outLogpp)
2039 return afs_icl_CreateLogWithFlags(name, logSize, /*flags*/0, outLogpp);
2042 /* create a log with size logSize; return it in *outLogpp and tag
2043 * it with name "name." 'flags' can be set to make the log unclearable.
2045 int afs_icl_CreateLogWithFlags(char *name, afs_int32 logSize, afs_uint32 flags,
2046 struct afs_icl_log **outLogpp)
2048 register struct afs_icl_log *logp;
2050 /* add into global list under lock */
2051 ObtainWriteLock(&afs_icl_lock,183);
2052 if (!afs_icl_inited) afs_icl_Init();
2054 for (logp = afs_icl_allLogs; logp; logp=logp->nextp) {
2055 if (strcmp(logp->name, name) == 0) {
2056 /* found it already created, just return it */
2059 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2061 ObtainWriteLock(&logp->lock,184);
2062 logp->states |= ICL_LOGF_PERSISTENT;
2063 ReleaseWriteLock(&logp->lock);
2065 ReleaseWriteLock(&afs_icl_lock);
2070 logp = (struct afs_icl_log *)
2071 osi_AllocSmallSpace(sizeof(struct afs_icl_log));
2072 memset((caddr_t)logp, 0, sizeof(*logp));
2075 logp->name = osi_AllocSmallSpace(strlen(name)+1);
2076 strcpy(logp->name, name);
2077 LOCK_INIT(&logp->lock, "logp lock");
2078 logp->logSize = logSize;
2079 logp->datap = NULL; /* don't allocate it until we need it */
2081 if (flags & ICL_CRLOG_FLAG_PERSISTENT)
2082 logp->states |= ICL_LOGF_PERSISTENT;
2084 logp->nextp = afs_icl_allLogs;
2085 afs_icl_allLogs = logp;
2086 ReleaseWriteLock(&afs_icl_lock);
2092 /* called with a log, a pointer to a buffer, the size of the buffer
2093 * (in *bufSizep), the starting cookie (in *cookiep, use 0 at the start)
2094 * and returns data in the provided buffer, and returns output flags
2095 * in *flagsp. The flag ICL_COPYOUTF_MISSEDSOME is set if we can't
2096 * find the record with cookie value cookie.
2098 int afs_icl_CopyOut(register struct afs_icl_log *logp, afs_int32 *bufferp,
2099 afs_int32 *bufSizep, afs_uint32 *cookiep, afs_int32 *flagsp)
2101 afs_int32 nwords; /* number of words to copy out */
2102 afs_uint32 startCookie; /* first cookie to use */
2103 register afs_int32 i;
2104 afs_int32 outWords; /* words we've copied out */
2105 afs_int32 inWords; /* max words to copy out */
2106 afs_int32 code; /* return code */
2107 afs_int32 ix; /* index we're copying from */
2108 afs_int32 outFlags; /* return flags */
2109 afs_int32 inFlags; /* flags passed in */
2112 inWords = *bufSizep; /* max to copy out */
2113 outWords = 0; /* amount copied out */
2114 startCookie = *cookiep;
2119 ObtainWriteLock(&logp->lock,185);
2121 ReleaseWriteLock(&logp->lock);
2125 /* first, compute the index of the start cookie we've been passed */
2127 /* (re-)compute where we should start */
2128 if (startCookie < logp->baseCookie) {
2129 if (startCookie) /* missed some output */
2130 outFlags |= ICL_COPYOUTF_MISSEDSOME;
2131 /* skip to the first available record */
2132 startCookie = logp->baseCookie;
2133 *cookiep = startCookie;
2136 /* compute where we find the first element to copy out */
2137 ix = logp->firstUsed + startCookie - logp->baseCookie;
2138 if (ix >= logp->logSize) ix -= logp->logSize;
2140 /* if have some data now, break out and process it */
2141 if (startCookie - logp->baseCookie < logp->logElements) break;
2143 /* At end of log, so clear it if we need to */
2144 if (inFlags & ICL_COPYOUTF_CLRAFTERREAD)
2146 logp->firstUsed = logp->firstFree = 0;
2147 logp->logElements = 0;
2149 /* otherwise, either wait for the data to arrive, or return */
2150 if (!(inFlags & ICL_COPYOUTF_WAITIO)) {
2151 ReleaseWriteLock(&logp->lock);
2155 logp->states |= ICL_LOGF_WAITING;
2156 ReleaseWriteLock(&logp->lock);
2157 afs_osi_Sleep(&logp->lock);
2158 ObtainWriteLock(&logp->lock,186);
2160 /* copy out data from ix to logSize or firstFree, depending
2161 * upon whether firstUsed <= firstFree (no wrap) or otherwise.
2162 * be careful not to copy out more than nwords.
2164 if (ix >= logp->firstUsed) {
2165 if (logp->firstUsed <= logp->firstFree)
2167 end = logp->firstFree; /* first element not to copy */
2169 end = logp->logSize;
2170 nwords = inWords; /* don't copy more than this */
2171 if (end - ix < nwords)
2174 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2179 /* if we're going to copy more out below, we'll start here */
2182 /* now, if active part of the log has wrapped, there's more stuff
2183 * starting at the head of the log. Copy out more from there.
2185 if (logp->firstUsed > logp->firstFree
2186 && ix < logp->firstFree && inWords > 0) {
2187 /* (more to) copy out from the wrapped section at the
2188 * start of the log. May get here even if didn't copy any
2189 * above, if the cookie points directly into the wrapped section.
2192 if (logp->firstFree - ix < nwords)
2193 nwords = logp->firstFree - ix;
2194 memcpy((char *) bufferp, (char *) &logp->datap[ix], sizeof(afs_int32) * nwords);
2200 ReleaseWriteLock(&logp->lock);
2204 *bufSizep = outWords;
2210 /* return basic parameter information about a log */
2211 int afs_icl_GetLogParms(struct afs_icl_log *logp, afs_int32 *maxSizep,
2212 afs_int32 *curSizep)
2214 ObtainReadLock(&logp->lock);
2215 *maxSizep = logp->logSize;
2216 *curSizep = logp->logElements;
2217 ReleaseReadLock(&logp->lock);
2222 /* hold and release logs */
2223 int afs_icl_LogHold(register struct afs_icl_log *logp)
2225 ObtainWriteLock(&afs_icl_lock,187);
2227 ReleaseWriteLock(&afs_icl_lock);
2231 /* hold and release logs, called with lock already held */
2232 int afs_icl_LogHoldNL(register struct afs_icl_log *logp)
2238 /* keep track of how many sets believe the log itself is allocated */
2239 int afs_icl_LogUse(register struct afs_icl_log *logp)
2241 ObtainWriteLock(&logp->lock,188);
2242 if (logp->setCount == 0) {
2243 /* this is the first set actually using the log -- allocate it */
2244 if (logp->logSize == 0) {
2245 /* we weren't passed in a hint and it wasn't set */
2246 logp->logSize = ICL_DEFAULT_LOGSIZE;
2248 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logp->logSize);
2249 #ifdef AFS_AIX32_ENV
2250 pin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2254 ReleaseWriteLock(&logp->lock);
2258 /* decrement the number of real users of the log, free if possible */
2259 int afs_icl_LogFreeUse(register struct afs_icl_log *logp)
2261 ObtainWriteLock(&logp->lock,189);
2262 if (--logp->setCount == 0) {
2263 /* no more users -- free it (but keep log structure around)*/
2264 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2265 #ifdef AFS_AIX32_ENV
2266 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2268 logp->firstUsed = logp->firstFree = 0;
2269 logp->logElements = 0;
2272 ReleaseWriteLock(&logp->lock);
2276 /* set the size of the log to 'logSize' */
2277 int afs_icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
2279 ObtainWriteLock(&logp->lock,190);
2281 /* nothing to worry about since it's not allocated */
2282 logp->logSize = logSize;
2286 logp->firstUsed = logp->firstFree = 0;
2287 logp->logElements = 0;
2289 /* free and allocate a new one */
2290 afs_osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2291 #ifdef AFS_AIX32_ENV
2292 unpin((char *)logp->datap, sizeof(afs_int32) * logp->logSize);
2294 logp->datap = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * logSize);
2295 #ifdef AFS_AIX32_ENV
2296 pin((char *)logp->datap, sizeof(afs_int32) * logSize);
2298 logp->logSize = logSize;
2300 ReleaseWriteLock(&logp->lock);
2305 /* free a log. Called with afs_icl_lock locked. */
2306 int afs_icl_ZapLog(register struct afs_icl_log *logp)
2308 register struct afs_icl_log **lpp, *tp;
2310 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2312 /* found the dude we want to remove */
2314 osi_FreeSmallSpace(logp->name);
2315 osi_FreeSmallSpace(logp->datap);
2316 osi_FreeSmallSpace(logp);
2317 break; /* won't find it twice */
2323 /* do the release, watching for deleted entries */
2324 int afs_icl_LogRele(register struct afs_icl_log *logp)
2326 ObtainWriteLock(&afs_icl_lock,191);
2327 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2328 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2330 ReleaseWriteLock(&afs_icl_lock);
2334 /* do the release, watching for deleted entries, log already held */
2335 int afs_icl_LogReleNL(register struct afs_icl_log *logp)
2337 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2338 afs_icl_ZapLog(logp); /* destroys logp's lock! */
2343 /* zero out the log */
2344 int afs_icl_ZeroLog(register struct afs_icl_log *logp)
2346 ObtainWriteLock(&logp->lock,192);
2347 logp->firstUsed = logp->firstFree = 0;
2348 logp->logElements = 0;
2349 logp->baseCookie = 0;
2350 ReleaseWriteLock(&logp->lock);
2354 /* free a log entry, and drop its reference count */
2355 int afs_icl_LogFree(register struct afs_icl_log *logp)
2357 ObtainWriteLock(&logp->lock,193);
2358 logp->states |= ICL_LOGF_DELETED;
2359 ReleaseWriteLock(&logp->lock);
2360 afs_icl_LogRele(logp);
2364 /* find a log by name, returning it held */
2365 struct afs_icl_log *afs_icl_FindLog(char *name)
2367 register struct afs_icl_log *tp;
2368 ObtainWriteLock(&afs_icl_lock,194);
2369 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2370 if (strcmp(tp->name, name) == 0) {
2371 /* this is the dude we want */
2376 ReleaseWriteLock(&afs_icl_lock);
2380 int afs_icl_EnumerateLogs(int (*aproc)(), char *arock)
2382 register struct afs_icl_log *tp;
2383 register afs_int32 code;
2386 ObtainWriteLock(&afs_icl_lock,195);
2387 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2388 tp->refCount++; /* hold this guy */
2389 ReleaseWriteLock(&afs_icl_lock);
2390 ObtainReadLock(&tp->lock);
2391 code = (*aproc)(tp->name, arock, tp);
2392 ReleaseReadLock(&tp->lock);
2393 ObtainWriteLock(&afs_icl_lock,196);
2394 if (--tp->refCount == 0)
2398 ReleaseWriteLock(&afs_icl_lock);
2402 struct afs_icl_set *afs_icl_allSets = 0;
2404 int afs_icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
2405 struct afs_icl_log *fatalLogp, struct afs_icl_set **outSetpp)
2407 return afs_icl_CreateSetWithFlags(name, baseLogp, fatalLogp,
2408 /*flags*/0, outSetpp);
2411 /* create a set, given pointers to base and fatal logs, if any.
2412 * Logs are unlocked, but referenced, and *outSetpp is returned
2413 * referenced. Function bumps reference count on logs, since it
2414 * addds references from the new afs_icl_set. When the set is destroyed,
2415 * those references will be released.
2417 int afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
2418 struct afs_icl_log *fatalLogp, afs_uint32 flags, struct afs_icl_set **outSetpp)
2420 register struct afs_icl_set *setp;
2422 afs_int32 states = ICL_DEFAULT_SET_STATES;
2424 ObtainWriteLock(&afs_icl_lock,197);
2425 if (!afs_icl_inited) afs_icl_Init();
2427 for (setp = afs_icl_allSets; setp; setp = setp->nextp) {
2428 if (strcmp(setp->name, name) == 0) {
2431 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2433 ObtainWriteLock(&setp->lock,198);
2434 setp->states |= ICL_SETF_PERSISTENT;
2435 ReleaseWriteLock(&setp->lock);
2437 ReleaseWriteLock(&afs_icl_lock);
2442 /* determine initial state */
2443 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2444 states = ICL_SETF_ACTIVE;
2445 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2446 states = ICL_SETF_FREED;
2447 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2448 states |= ICL_SETF_PERSISTENT;
2450 setp = (struct afs_icl_set *) afs_osi_Alloc(sizeof(struct afs_icl_set));
2451 memset((caddr_t)setp, 0, sizeof(*setp));
2453 if (states & ICL_SETF_FREED)
2454 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2455 setp->states = states;
2457 LOCK_INIT(&setp->lock, "setp lock");
2458 /* next lock is obtained in wrong order, hierarchy-wise, but
2459 * it doesn't matter, since no one can find this lock yet, since
2460 * the afs_icl_lock is still held, and thus the obtain can't block.
2462 ObtainWriteLock(&setp->lock,199);
2463 setp->name = osi_AllocSmallSpace(strlen(name)+1);
2464 strcpy(setp->name, name);
2465 setp->nevents = ICL_DEFAULTEVENTS;
2466 setp->eventFlags = afs_osi_Alloc(ICL_DEFAULTEVENTS);
2467 #ifdef AFS_AIX32_ENV
2468 pin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2470 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2471 setp->eventFlags[i] = 0xff; /* default to enabled */
2473 /* update this global info under the afs_icl_lock */
2474 setp->nextp = afs_icl_allSets;
2475 afs_icl_allSets = setp;
2476 ReleaseWriteLock(&afs_icl_lock);
2478 /* set's basic lock is still held, so we can finish init */
2480 setp->logs[0] = baseLogp;
2481 afs_icl_LogHold(baseLogp);
2482 if (!(setp->states & ICL_SETF_FREED))
2483 afs_icl_LogUse(baseLogp); /* log is actually being used */
2486 setp->logs[1] = fatalLogp;
2487 afs_icl_LogHold(fatalLogp);
2488 if (!(setp->states & ICL_SETF_FREED))
2489 afs_icl_LogUse(fatalLogp); /* log is actually being used */
2491 ReleaseWriteLock(&setp->lock);
2497 /* function to change event enabling information for a particular set */
2498 int afs_icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
2502 ObtainWriteLock(&setp->lock,200);
2503 if (!ICL_EVENTOK(setp, eventID)) {
2504 ReleaseWriteLock(&setp->lock);
2507 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2509 *tp |= ICL_EVENTMASK(eventID);
2511 *tp &= ~(ICL_EVENTMASK(eventID));
2512 ReleaseWriteLock(&setp->lock);
2516 /* return indication of whether a particular event ID is enabled
2517 * for tracing. If *getValuep is set to 0, the event is disabled,
2518 * otherwise it is enabled. All events start out enabled by default.
2520 int afs_icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID,
2523 ObtainReadLock(&setp->lock);
2524 if (!ICL_EVENTOK(setp, eventID)) {
2525 ReleaseWriteLock(&setp->lock);
2528 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2532 ReleaseReadLock(&setp->lock);
2536 /* hold and release event sets */
2537 int afs_icl_SetHold(register struct afs_icl_set *setp)
2539 ObtainWriteLock(&afs_icl_lock,201);
2541 ReleaseWriteLock(&afs_icl_lock);
2545 /* free a set. Called with afs_icl_lock locked */
2546 int afs_icl_ZapSet(register struct afs_icl_set *setp)
2548 register struct afs_icl_set **lpp, *tp;
2550 register struct afs_icl_log *tlp;
2552 for(lpp = &afs_icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2554 /* found the dude we want to remove */
2556 osi_FreeSmallSpace(setp->name);
2557 afs_osi_Free(setp->eventFlags, ICL_DEFAULTEVENTS);
2558 #ifdef AFS_AIX32_ENV
2559 unpin((char *)setp->eventFlags, ICL_DEFAULTEVENTS);
2561 for(i=0; i < ICL_LOGSPERSET; i++) {
2562 if ((tlp = setp->logs[i]))
2563 afs_icl_LogReleNL(tlp);
2565 osi_FreeSmallSpace(setp);
2566 break; /* won't find it twice */
2572 /* do the release, watching for deleted entries */
2573 int afs_icl_SetRele(register struct afs_icl_set *setp)
2575 ObtainWriteLock(&afs_icl_lock,202);
2576 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2577 afs_icl_ZapSet(setp); /* destroys setp's lock! */
2579 ReleaseWriteLock(&afs_icl_lock);
2583 /* free a set entry, dropping its reference count */
2584 int afs_icl_SetFree(register struct afs_icl_set *setp)
2586 ObtainWriteLock(&setp->lock,203);
2587 setp->states |= ICL_SETF_DELETED;
2588 ReleaseWriteLock(&setp->lock);
2589 afs_icl_SetRele(setp);
2593 /* find a set by name, returning it held */
2594 struct afs_icl_set *afs_icl_FindSet(char *name)
2596 register struct afs_icl_set *tp;
2597 ObtainWriteLock(&afs_icl_lock,204);
2598 for(tp = afs_icl_allSets; tp; tp=tp->nextp) {
2599 if (strcmp(tp->name, name) == 0) {
2600 /* this is the dude we want */
2605 ReleaseWriteLock(&afs_icl_lock);
2609 /* zero out all the logs in the set */
2610 int afs_icl_ZeroSet(struct afs_icl_set *setp)
2615 struct afs_icl_log *logp;
2617 ObtainReadLock(&setp->lock);
2618 for(i = 0; i < ICL_LOGSPERSET; i++) {
2619 logp = setp->logs[i];
2621 afs_icl_LogHold(logp);
2622 tcode = afs_icl_ZeroLog(logp);
2623 if (tcode != 0) code = tcode; /* save the last bad one */
2624 afs_icl_LogRele(logp);
2627 ReleaseReadLock(&setp->lock);
2631 int afs_icl_EnumerateSets(int (*aproc)(), char *arock)
2633 register struct afs_icl_set *tp, *np;
2634 register afs_int32 code;
2637 ObtainWriteLock(&afs_icl_lock,205);
2638 for(tp = afs_icl_allSets; tp; tp=np) {
2639 tp->refCount++; /* hold this guy */
2640 ReleaseWriteLock(&afs_icl_lock);
2641 code = (*aproc)(tp->name, arock, tp);
2642 ObtainWriteLock(&afs_icl_lock,206);
2643 np = tp->nextp; /* tp may disappear next, but not np */
2644 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2648 ReleaseWriteLock(&afs_icl_lock);
2652 int afs_icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
2656 struct afs_icl_log *logp;
2658 ObtainWriteLock(&setp->lock,207);
2659 for(i = 0; i < ICL_LOGSPERSET; i++) {
2660 if (!setp->logs[i]) {
2661 setp->logs[i] = newlogp;
2663 afs_icl_LogHold(newlogp);
2664 if (!(setp->states & ICL_SETF_FREED)) {
2665 /* bump up the number of sets using the log */
2666 afs_icl_LogUse(newlogp);
2671 ReleaseWriteLock(&setp->lock);
2675 int afs_icl_SetSetStat(struct afs_icl_set *setp, int op)
2679 struct afs_icl_log *logp;
2681 ObtainWriteLock(&setp->lock,208);
2683 case ICL_OP_SS_ACTIVATE: /* activate a log */
2685 * If we are not already active, see if we have released
2686 * our demand that the log be allocated (FREED set). If
2687 * we have, reassert our desire.
2689 if (!(setp->states & ICL_SETF_ACTIVE)) {
2690 if (setp->states & ICL_SETF_FREED) {
2691 /* have to reassert desire for logs */
2692 for(i = 0; i < ICL_LOGSPERSET; i++) {
2693 logp = setp->logs[i];
2695 afs_icl_LogHold(logp);
2696 afs_icl_LogUse(logp);
2697 afs_icl_LogRele(logp);
2700 setp->states &= ~ICL_SETF_FREED;
2702 setp->states |= ICL_SETF_ACTIVE;
2707 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2708 /* this doesn't require anything beyond clearing the ACTIVE flag */
2709 setp->states &= ~ICL_SETF_ACTIVE;
2713 case ICL_OP_SS_FREE: /* deassert design for log */
2715 * if we are already in this state, do nothing; otherwise
2716 * deassert desire for log
2718 if (setp->states & ICL_SETF_ACTIVE)
2721 if (!(setp->states & ICL_SETF_FREED)) {
2722 for(i = 0; i < ICL_LOGSPERSET; i++) {
2723 logp = setp->logs[i];
2725 afs_icl_LogHold(logp);
2726 afs_icl_LogFreeUse(logp);
2727 afs_icl_LogRele(logp);
2730 setp->states |= ICL_SETF_FREED;
2739 ReleaseWriteLock(&setp->lock);