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"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
17 #include "afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h"
19 #include "rx/rx_globals.h"
20 #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
23 #include "h/hashing.h"
25 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN60_ENV)
26 #include "netinet/in_var.h"
28 #endif /* !defined(UKERNEL) */
29 #ifdef AFS_LINUX22_ENV
30 #include "h/smp_lock.h"
34 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV)
35 #define AFS_MINBUFFERS 100
37 #define AFS_MINBUFFERS 50
41 afs_int32 hosts[MAXCELLHOSTS];
45 char afs_zeros[AFS_ZEROS];
46 char afs_rootVolumeName[64] = "";
47 afs_uint32 rx_bindhost;
49 afs_int32 afs_initState = 0;
50 afs_int32 afs_termState = 0;
51 afs_int32 afs_setTime = 0;
52 int afs_cold_shutdown = 0;
53 char afs_SynchronousCloses = '\0';
54 static int afs_CB_Running = 0;
55 static int AFS_Running = 0;
56 static int afs_CacheInit_Done = 0;
57 static int afs_Go_Done = 0;
58 extern struct interfaceAddr afs_cb_interface;
59 static int afs_RX_Running = 0;
60 static int afs_InitSetup_done = 0;
62 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
63 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
65 static int afscall_set_rxpck_received = 0;
67 #if defined(AFS_HPUX_ENV)
68 extern int afs_vfs_mount();
69 #endif /* defined(AFS_HPUX_ENV) */
71 /* This is code which needs to be called once when the first daemon enters
72 * the client. A non-zero return means an error and AFS should not start.
75 afs_InitSetup(int preallocs)
77 extern void afs_InitStats();
80 if (afs_InitSetup_done)
85 * Set up all the AFS statistics variables. This should be done
86 * exactly once, and it should be done here, the first resource-setting
87 * routine to be called by the CM/RX.
90 #endif /* AFS_NOSTATS */
92 memset(afs_zeros, 0, AFS_ZEROS);
95 if(!afscall_set_rxpck_received)
96 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
97 code = rx_InitHost(rx_bindhost, htons(7001));
99 printf("AFS: RX failed to initialize %d).\n", code);
102 rx_SetRxDeadTime(afs_rx_deadtime);
103 /* resource init creates the services */
104 afs_ResourceInit(preallocs);
106 afs_InitSetup_done = 1;
107 afs_osi_Wakeup(&afs_InitSetup_done);
111 #if defined(AFS_DARWIN80_ENV)
112 struct afsd_thread_info {
116 afsd_thread(int *rock)
118 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
119 unsigned long parm = arg->parm;
122 case AFSOP_START_RXCALLBACK:
126 while (afs_RX_Running != 2)
127 afs_osi_Sleep(&afs_RX_Running);
128 afs_RXCallBackServer();
130 thread_terminate(current_thread());
132 case AFSOP_START_AFS:
136 while (afs_initState < AFSOP_START_AFS)
137 afs_osi_Sleep(&afs_initState);
138 afs_initState = AFSOP_START_BKG;
139 afs_osi_Wakeup(&afs_initState);
142 thread_terminate(current_thread());
144 case AFSOP_START_BKG:
147 while (afs_initState < AFSOP_START_BKG)
148 afs_osi_Sleep(&afs_initState);
149 if (afs_initState < AFSOP_GO) {
150 afs_initState = AFSOP_GO;
151 afs_osi_Wakeup(&afs_initState);
153 afs_BackgroundDaemon();
155 thread_terminate(current_thread());
157 case AFSOP_START_TRUNCDAEMON:
160 while (afs_initState < AFSOP_GO)
161 afs_osi_Sleep(&afs_initState);
162 afs_CacheTruncateDaemon();
164 thread_terminate(current_thread());
169 afs_CheckServerDaemon();
171 thread_terminate(current_thread());
173 case AFSOP_RXEVENT_DAEMON:
176 while (afs_initState < AFSOP_START_BKG)
177 afs_osi_Sleep(&afs_initState);
178 afs_rxevent_daemon();
180 thread_terminate(current_thread());
182 case AFSOP_RXLISTENER_DAEMON:
185 afs_initState = AFSOP_START_AFS;
186 afs_osi_Wakeup(&afs_initState);
188 afs_osi_Wakeup(&afs_RX_Running);
189 afs_osi_RxkRegister();
192 thread_terminate(current_thread());
195 printf("Unknown op %ld in StartDaemon()\n", (long)parm);
201 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
205 struct afsd_thread_info info;
208 if (parm == AFSOP_START_RXCALLBACK) {
211 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
215 code = afs_InitSetup(parm2);
217 rx_enablePeerRPCStats();
220 rx_enableProcessRPCStats();
224 } else if (parm == AFSOP_START_AFS) {
227 } /* other functions don't need setup in the parent */
229 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
231 /* we need to wait cause we passed stack pointers around.... */
232 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
234 thread_deallocate(thread);
239 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)
240 struct afsd_thread_info {
241 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
242 struct work_struct tq;
245 struct completion *complete;
249 afsd_thread(void *rock)
251 struct afsd_thread_info *arg = rock;
252 unsigned long parm = arg->parm;
253 #ifdef SYS_SETPRIORITY_EXPORTED
254 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
256 #if defined(AFS_LINUX26_ENV)
261 /* doesn't do much, since we were forked from keventd, but
262 * does call mm_release, which wakes up our parent (since it
263 * used CLONE_VFORK) */
264 #if !defined(AFS_LINUX26_ENV)
267 afs_osi_MaskSignals();
269 case AFSOP_START_RXCALLBACK:
270 sprintf(current->comm, "afs_cbstart");
272 complete(arg->complete);
274 while (afs_RX_Running != 2)
275 afs_osi_Sleep(&afs_RX_Running);
276 sprintf(current->comm, "afs_callback");
277 afs_RXCallBackServer();
279 complete_and_exit(0, 0);
281 case AFSOP_START_AFS:
282 sprintf(current->comm, "afs_afsstart");
284 complete(arg->complete);
286 while (afs_initState < AFSOP_START_AFS)
287 afs_osi_Sleep(&afs_initState);
288 afs_initState = AFSOP_START_BKG;
289 afs_osi_Wakeup(&afs_initState);
290 sprintf(current->comm, "afsd");
293 complete_and_exit(0, 0);
295 case AFSOP_START_BKG:
296 sprintf(current->comm, "afs_bkgstart");
298 complete(arg->complete);
299 while (afs_initState < AFSOP_START_BKG)
300 afs_osi_Sleep(&afs_initState);
301 if (afs_initState < AFSOP_GO) {
302 afs_initState = AFSOP_GO;
303 afs_osi_Wakeup(&afs_initState);
305 sprintf(current->comm, "afs_background");
306 afs_BackgroundDaemon();
308 complete_and_exit(0, 0);
310 case AFSOP_START_TRUNCDAEMON:
311 sprintf(current->comm, "afs_trimstart");
313 complete(arg->complete);
314 while (afs_initState < AFSOP_GO)
315 afs_osi_Sleep(&afs_initState);
316 sprintf(current->comm, "afs_cachetrim");
317 afs_CacheTruncateDaemon();
319 complete_and_exit(0, 0);
322 sprintf(current->comm, "afs_checkserver");
324 complete(arg->complete);
325 afs_CheckServerDaemon();
327 complete_and_exit(0, 0);
329 case AFSOP_RXEVENT_DAEMON:
330 sprintf(current->comm, "afs_evtstart");
331 #ifdef SYS_SETPRIORITY_EXPORTED
332 sys_setpriority(PRIO_PROCESS, 0, -10);
334 #ifdef CURRENT_INCLUDES_NICE
339 complete(arg->complete);
340 while (afs_initState < AFSOP_START_BKG)
341 afs_osi_Sleep(&afs_initState);
342 sprintf(current->comm, "afs_rxevent");
343 afs_rxevent_daemon();
345 complete_and_exit(0, 0);
347 case AFSOP_RXLISTENER_DAEMON:
348 sprintf(current->comm, "afs_lsnstart");
349 #ifdef SYS_SETPRIORITY_EXPORTED
350 sys_setpriority(PRIO_PROCESS, 0, -10);
352 #ifdef CURRENT_INCLUDES_NICE
357 complete(arg->complete);
358 afs_initState = AFSOP_START_AFS;
359 afs_osi_Wakeup(&afs_initState);
361 afs_osi_Wakeup(&afs_RX_Running);
362 afs_osi_RxkRegister();
363 sprintf(current->comm, "afs_rxlistener");
366 complete_and_exit(0, 0);
369 printf("Unknown op %ld in StartDaemon()\n", (long)parm);
376 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
377 afsd_launcher(struct work_struct *work)
379 afsd_launcher(void *rock)
382 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
383 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
386 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
387 printf("kernel_thread failed. afs startup will not complete\n");
391 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
395 DECLARE_COMPLETION(c);
396 #if defined(AFS_LINUX26_ENV)
397 struct work_struct tq;
401 struct afsd_thread_info info;
402 if (parm == AFSOP_START_RXCALLBACK) {
405 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
409 code = afs_InitSetup(parm2);
411 rx_enablePeerRPCStats();
414 rx_enableProcessRPCStats();
418 } else if (parm == AFSOP_START_AFS) {
421 } /* other functions don't need setup in the parent */
424 #if defined(AFS_LINUX26_ENV)
425 #if !defined(INIT_WORK_HAS_DATA)
426 INIT_WORK(&info.tq, afsd_launcher);
427 schedule_work(&info.tq);
429 INIT_WORK(&tq, afsd_launcher, &info);
434 INIT_LIST_HEAD(&tq.list);
435 tq.routine = afsd_launcher;
440 /* we need to wait cause we passed stack pointers around.... */
441 wait_for_completion(&c);
446 /* leaving as is, probably will barf if we add prototypes here since it's likely being called
449 afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
450 long parm, parm2, parm3, parm4, parm5, parm6;
453 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
455 #else /* AFS_SGI61_ENV */
457 #endif /* AFS_SGI61_ENV */
459 AFS_STATCNT(afs_syscall_call);
461 if (!afs_suser(CRED()) && (parm != AFSOP_GETMTU)
462 && (parm != AFSOP_GETMASK)) {
463 /* only root can run this code */
466 if (!afs_suser(NULL) && (parm != AFSOP_GETMTU)
467 && (parm != AFSOP_GETMASK)) {
468 /* only root can run this code */
469 #if defined(KERNEL_HAVE_UERROR)
473 #if defined(AFS_OSF_ENV)
475 #else /* AFS_OSF_ENV */
477 #endif /* AFS_OSF_ENV */
482 #ifdef AFS_DARWIN80_ENV
485 #if ((defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)) || defined(AFS_DARWIN80_ENV)) && !defined(UKERNEL)
486 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
487 || parm == AFSOP_RXLISTENER_DAEMON) {
488 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
490 #else /* !(AFS_LINUX24_ENV && !UKERNEL) */
491 if (parm == AFSOP_START_RXCALLBACK) {
495 #ifndef RXK_LISTENER_ENV
496 code = afs_InitSetup(parm2);
498 #endif /* !RXK_LISTENER_ENV */
500 #ifdef RXK_LISTENER_ENV
501 while (afs_RX_Running != 2)
502 afs_osi_Sleep(&afs_RX_Running);
503 #else /* !RXK_LISTENER_ENV */
504 afs_initState = AFSOP_START_AFS;
505 afs_osi_Wakeup(&afs_initState);
506 #endif /* RXK_LISTENER_ENV */
508 afs_RXCallBackServer();
512 exit(CLD_EXITED, code);
513 #endif /* AFS_SGI_ENV */
515 #ifdef RXK_LISTENER_ENV
516 else if (parm == AFSOP_RXLISTENER_DAEMON) {
520 code = afs_InitSetup(parm2);
522 rx_enablePeerRPCStats();
525 rx_enableProcessRPCStats();
528 afs_initState = AFSOP_START_AFS;
529 afs_osi_Wakeup(&afs_initState);
532 afs_osi_Wakeup(&afs_RX_Running);
534 afs_osi_RxkRegister();
535 #endif /* !UKERNEL */
540 exit(CLD_EXITED, code);
541 #endif /* AFS_SGI_ENV */
543 #endif /* RXK_LISTENER_ENV */
544 else if (parm == AFSOP_START_AFS) {
549 while (afs_initState < AFSOP_START_AFS)
550 afs_osi_Sleep(&afs_initState);
552 afs_initState = AFSOP_START_BKG;
553 afs_osi_Wakeup(&afs_initState);
559 #endif /* AFS_SGI_ENV */
560 } else if (parm == AFSOP_START_CS) {
562 afs_CheckServerDaemon();
566 #endif /* AFS_SGI_ENV */
567 } else if (parm == AFSOP_START_BKG) {
568 while (afs_initState < AFSOP_START_BKG)
569 afs_osi_Sleep(&afs_initState);
570 if (afs_initState < AFSOP_GO) {
571 afs_initState = AFSOP_GO;
572 afs_osi_Wakeup(&afs_initState);
574 /* start the bkg daemon */
578 afs_BioDaemon(parm2);
580 #endif /* AFS_AIX32_ENV */
581 afs_BackgroundDaemon();
585 #endif /* AFS_SGI_ENV */
586 } else if (parm == AFSOP_START_TRUNCDAEMON) {
587 while (afs_initState < AFSOP_GO)
588 afs_osi_Sleep(&afs_initState);
589 /* start the bkg daemon */
591 afs_CacheTruncateDaemon();
595 #endif /* AFS_SGI_ENV */
597 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
598 else if (parm == AFSOP_RXEVENT_DAEMON) {
599 while (afs_initState < AFSOP_START_BKG)
600 afs_osi_Sleep(&afs_initState);
602 afs_rxevent_daemon();
606 #endif /* AFS_SGI_ENV */
608 #endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
609 #endif /* AFS_LINUX24_ENV && !UKERNEL */
610 else if (parm == AFSOP_BASIC_INIT) {
613 while (!afs_InitSetup_done)
614 afs_osi_Sleep(&afs_InitSetup_done);
616 #if defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_SUN5_ENV)
617 temp = AFS_MINBUFFERS; /* Should fix this soon */
619 /* number of 2k buffers we could get from all of the buffer space */
620 temp = ((afs_bufferpages * NBPG) >> 11);
621 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
622 if (temp < AFS_MINBUFFERS)
623 temp = AFS_MINBUFFERS; /* though we really should have this many */
626 afs_rootFid.Fid.Volume = 0;
628 } else if (parm == AFSOP_BUCKETPCT) {
629 /* need to enable this now, will disable again before GO
630 if we don't have 100% */
640 } else if (parm == AFSOP_ADDCELL) {
641 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
642 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
643 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
644 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
646 code = afs_InitDynroot();
648 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts),
652 if (parm4 > sizeof(tcell->cellName))
655 AFS_COPYIN((char *)parm3, tcell->cellName, parm4, code);
657 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
661 afs_osi_Free(tcell, sizeof(struct afsop_cell));
662 } else if (parm == AFSOP_ADDCELL2) {
663 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
664 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
665 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
668 code = afs_InitDynroot();
671 /* wait for basic init - XXX can't find any reason we need this? */
672 while (afs_initState < AFSOP_START_BKG)
673 afs_osi_Sleep(&afs_initState);
676 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts),
680 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ,
684 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ,
688 cflags |= CLinkedCell;
693 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
697 afs_osi_Free(tcell, sizeof(struct afsop_cell));
698 osi_FreeSmallSpace(tbuffer);
699 osi_FreeSmallSpace(tbuffer1);
700 } else if (parm == AFSOP_ADDCELLALIAS) {
703 * parm2 is the alias name
704 * parm3 is the real cell name
706 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
707 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
709 code = afs_InitDynroot();
711 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize,
715 AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ,
718 afs_NewCellAlias(aliasName, cellName);
719 osi_FreeSmallSpace(aliasName);
720 osi_FreeSmallSpace(cellName);
721 } else if (parm == AFSOP_SET_THISCELL) {
724 * parm2 is the primary cell name
726 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
728 code = afs_InitDynroot();
730 AFS_COPYINSTR((char *)parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code);
733 afs_SetPrimaryCell(cell);
734 osi_FreeSmallSpace(cell);
735 } else if (parm == AFSOP_CACHEINIT) {
736 struct afs_cacheParams cparms;
738 if (afs_CacheInit_Done)
741 AFS_COPYIN((char *)parm2, (caddr_t) & cparms, sizeof(cparms), code);
743 #if defined(KERNEL_HAVE_UERROR)
749 afs_CacheInit_Done = 1;
750 code = afs_icl_InitLogs();
751 afs_setTime = cparms.setTimeFlag;
754 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
755 cparms.cacheBlocks, cparms.cacheDcaches,
756 cparms.cacheVolumes, cparms.chunkSize,
757 cparms.memCacheFlag, cparms.inodes, cparms.users);
759 } else if (parm == AFSOP_CACHEINODE) {
760 ino_t ainode = parm2;
761 /* wait for basic init */
762 while (afs_initState < AFSOP_START_BKG)
763 afs_osi_Sleep(&afs_initState);
765 #ifdef AFS_DARWIN80_ENV
770 ainode = (ainode << 32) | (parm3 & 0xffffffff);
772 code = afs_InitCacheFile(NULL, ainode);
773 #ifdef AFS_DARWIN80_ENV
776 } else if (parm == AFSOP_ROOTVOLUME) {
777 /* wait for basic init */
778 while (afs_initState < AFSOP_START_BKG)
779 afs_osi_Sleep(&afs_initState);
782 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName,
783 sizeof(afs_rootVolumeName), &bufferSize, code);
784 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
787 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
788 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG
789 || parm == AFSOP_CELLINFO) {
790 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
793 AFS_COPYINSTR((char *)parm2, tbuffer, AFS_SMALLOCSIZ, &bufferSize,
796 osi_FreeSmallSpace(tbuffer);
800 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
801 /* We have the cache dir copied in. Call the cache init routine */
802 #ifdef AFS_DARWIN80_ENV
805 if (parm == AFSOP_CACHEFILE)
806 code = afs_InitCacheFile(tbuffer, 0);
807 else if (parm == AFSOP_CACHEINFO)
808 code = afs_InitCacheInfo(tbuffer);
809 else if (parm == AFSOP_VOLUMEINFO)
810 code = afs_InitVolumeInfo(tbuffer);
811 else if (parm == AFSOP_CELLINFO)
812 code = afs_InitCellInfo(tbuffer);
813 #ifdef AFS_DARWIN80_ENV
817 osi_FreeSmallSpace(tbuffer);
818 } else if (parm == AFSOP_GO) {
819 /* the generic initialization calls come here. One parameter: should we do the
820 * set-time operation on this workstation */
824 while (afs_initState < AFSOP_GO)
825 afs_osi_Sleep(&afs_initState);
828 if (afs_tpct1 + afs_tpct2 != 100) {
835 afs_osi_Wakeup(&afs_initState);
836 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
837 afs_nfsclient_init();
839 printf("found %d non-empty cache files (%d%%).\n",
840 afs_stats_cmperf.cacheFilesReused,
841 (100 * afs_stats_cmperf.cacheFilesReused) /
842 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
843 cacheNumEntries : 1));
844 } else if (parm == AFSOP_ADVISEADDR) {
845 /* pass in the host address to the rx package */
847 afs_int32 count = parm2;
849 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
850 afs_int32 *maskbuffer =
851 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
852 afs_int32 *mtubuffer =
853 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
856 /* Bind, but only if there's only one address configured */
857 if ( count & 0x80000000) {
858 count &= ~0x80000000;
863 if (count > AFS_MAX_INTERFACE_ADDR) {
865 count = AFS_MAX_INTERFACE_ADDR;
868 AFS_COPYIN((char *)parm3, (char *)buffer, count * sizeof(afs_int32),
871 AFS_COPYIN((char *)parm4, (char *)maskbuffer,
872 count * sizeof(afs_int32), code);
874 AFS_COPYIN((char *)parm5, (char *)mtubuffer,
875 count * sizeof(afs_int32), code);
877 afs_cb_interface.numberOfInterfaces = count;
878 for (i = 0; i < count; i++) {
879 afs_cb_interface.addr_in[i] = buffer[i];
880 #ifdef AFS_USERSPACE_IP_ADDR
881 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
882 * machines IP addresses when in the kernel (the in_ifaddr
883 * struct is not available), so we pass the info in at
884 * startup. We also pass in the subnetmask and mtu size. The
885 * subnetmask is used when setting the rank:
886 * afsi_SetServerIPRank(); and the mtu size is used when
887 * finding the best mtu size. rxi_FindIfnet() is replaced
888 * with rxi_Findcbi().
890 afs_cb_interface.subnetmask[i] =
891 (parm4 ? maskbuffer[i] : 0xffffffff);
892 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
895 afs_uuid_create(&afs_cb_interface.uuid);
896 rxi_setaddr(buffer[0]);
898 rx_bindhost = buffer[0];
900 rx_bindhost = htonl(INADDR_ANY);
902 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
903 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
904 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
907 else if (parm == AFSOP_NFSSTATICADDR) {
908 extern int (*nfs_rfsdisptab_v2) ();
909 nfs_rfsdisptab_v2 = (int (*)())parm2;
910 } else if (parm == AFSOP_NFSSTATICADDR2) {
911 extern int (*nfs_rfsdisptab_v2) ();
913 nfs_rfsdisptab_v2 = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
915 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
918 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
919 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
920 extern int (*afs_sblockp) ();
921 extern void (*afs_sbunlockp) ();
923 afs_sblockp = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
924 afs_sbunlockp = (void (*)())((parm4 << 32) | (parm5 & 0xffffffff));
926 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
927 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
930 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
931 #endif /* AFS_SGI53_ENV */
932 else if (parm == AFSOP_SHUTDOWN) {
933 afs_cold_shutdown = 0;
935 afs_cold_shutdown = 1;
936 #ifndef AFS_DARWIN_ENV
937 if (afs_globalVFS != 0) {
938 afs_warn("AFS isn't unmounted yet! Call aborted\n");
943 } else if (parm == AFSOP_AFS_VFSMOUNT) {
945 vfsmount(parm2, parm3, parm4, parm5);
946 #else /* defined(AFS_HPUX_ENV) */
947 #if defined(KERNEL_HAVE_UERROR)
952 #endif /* defined(AFS_HPUX_ENV) */
953 } else if (parm == AFSOP_CLOSEWAIT) {
954 afs_SynchronousCloses = 'S';
955 } else if (parm == AFSOP_GETMTU) {
957 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
958 #ifdef AFS_USERSPACE_IP_ADDR
960 i = rxi_Findcbi(parm2);
961 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
962 #else /* AFS_USERSPACE_IP_ADDR */
965 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
966 mtu = (tifnp ? ifnet_mtu(tifnp) : htonl(1500));
967 #endif /* else AFS_USERSPACE_IP_ADDR */
968 #endif /* !AFS_SUN5_ENV */
970 AFS_COPYOUT((caddr_t) & mtu, (caddr_t) parm3, sizeof(afs_int32),
973 /* this is disabled for now because I can't figure out how to get access
974 * to these kernel variables. It's only for supporting user-mode rx
975 * programs -- it makes a huge difference on the 220's in my testbed,
976 * though I don't know why. The bosserver does this with /etc/no, so it's
977 * being handled a different way for the servers right now. */
980 extern u_long sb_max_dflt;
983 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
984 if (sb_max < 131072) sb_max = 131072;
987 #endif /* AFS_AIX32_ENV */
988 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
990 #if !defined(AFS_SUN5_ENV)
991 #ifdef AFS_USERSPACE_IP_ADDR
993 i = rxi_Findcbi(parm2);
995 mask = afs_cb_interface.subnetmask[i];
999 #else /* AFS_USERSPACE_IP_ADDR */
1002 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1005 #endif /* else AFS_USERSPACE_IP_ADDR */
1006 #endif /* !AFS_SUN5_ENV */
1008 AFS_COPYOUT((caddr_t) & mask, (caddr_t) parm3, sizeof(afs_int32),
1011 #ifdef AFS_AFSDB_ENV
1012 else if (parm == AFSOP_AFSDB_HANDLER) {
1013 int sizeArg = (int)parm4;
1014 int kmsgLen = sizeArg & 0xffff;
1015 int cellLen = (sizeArg & 0xffff0000) >> 16;
1016 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1017 char *cellname = afs_osi_Alloc(cellLen);
1020 afs_osi_MaskUserLoop();
1022 AFS_COPYIN((afs_int32 *) parm2, cellname, cellLen, code);
1023 AFS_COPYIN((afs_int32 *) parm3, kmsg, kmsgLen, code);
1025 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1028 if (code == -2) { /* Shutting down? */
1034 AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
1035 afs_osi_Free(kmsg, kmsgLen);
1036 afs_osi_Free(cellname, cellLen);
1039 else if (parm == AFSOP_SET_DYNROOT) {
1040 code = afs_SetDynrootEnable(parm2);
1041 } else if (parm == AFSOP_SET_FAKESTAT) {
1042 afs_fakestat_enable = parm2;
1044 } else if (parm == AFSOP_SET_BACKUPTREE) {
1045 afs_bkvolpref = parm2;
1046 } else if (parm == AFSOP_SET_RXPCK) {
1047 rx_extraPackets = parm2;
1048 afscall_set_rxpck_received = 1;
1053 #ifdef AFS_DARWIN80_ENV /* to balance the put in afs3_syscall() */
1057 #ifdef AFS_LINUX20_ENV
1065 * Initstate in the range 0 < x < 100 are early initialization states.
1066 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1067 * the cache may be initialized.
1068 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1069 * is done after all the cache initialization has been done.
1070 * Initstate of 200 means that the volume has been looked up once, possibly
1072 * Initstate of 300 means that the volume has been *successfully* looked up.
1077 register int code = 0;
1079 AFS_STATCNT(afs_CheckInit);
1080 if (afs_initState <= 100)
1081 code = ENXIO; /* never finished init phase */
1082 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1083 while (afs_initState < 200)
1084 afs_osi_Sleep(&afs_initState);
1085 } else if (afs_initState == 200)
1086 code = ETIMEDOUT; /* didn't find root volume */
1090 int afs_shuttingdown = 0;
1094 extern short afs_brsDaemons;
1095 extern afs_int32 afs_CheckServerDaemonStarted;
1096 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1097 extern struct osi_file *afs_cacheInodep;
1099 AFS_STATCNT(afs_shutdown);
1100 if (afs_initState == 0) {
1101 afs_warn("AFS not initialized - not shutting down\n");
1105 if (afs_shuttingdown)
1107 afs_shuttingdown = 1;
1108 if (afs_cold_shutdown)
1112 afs_warn("shutting down of: CB... ");
1114 afs_termState = AFSOP_STOP_RXCALLBACK;
1115 rx_WakeupServerProcs();
1116 #ifdef AFS_AIX51_ENV
1117 shutdown_rxkernel();
1119 /* shutdown_rxkernel(); */
1120 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1121 afs_osi_Sleep(&afs_termState);
1123 afs_warn("afs... ");
1124 while (afs_termState == AFSOP_STOP_AFS) {
1125 afs_osi_CancelWait(&AFS_WaitHandler);
1126 afs_osi_Sleep(&afs_termState);
1128 if (afs_CheckServerDaemonStarted) {
1129 while (afs_termState == AFSOP_STOP_CS) {
1130 afs_osi_CancelWait(&AFS_CSWaitHandler);
1131 afs_osi_Sleep(&afs_termState);
1134 afs_warn("BkG... ");
1135 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1136 while (afs_termState == AFSOP_STOP_BKG) {
1137 afs_osi_Wakeup(&afs_brsDaemons);
1138 afs_osi_Sleep(&afs_termState);
1140 afs_warn("CTrunc... ");
1141 /* Cancel cache truncate daemon. */
1142 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1143 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1144 afs_osi_Sleep(&afs_termState);
1146 #ifdef AFS_AFSDB_ENV
1147 afs_warn("AFSDB... ");
1149 while (afs_termState == AFSOP_STOP_AFSDB)
1150 afs_osi_Sleep(&afs_termState);
1152 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1153 afs_warn("RxEvent... ");
1154 /* cancel rx event daemon */
1155 while (afs_termState == AFSOP_STOP_RXEVENT)
1156 afs_osi_Sleep(&afs_termState);
1157 #if defined(RXK_LISTENER_ENV)
1159 afs_warn("UnmaskRxkSignals... ");
1160 afs_osi_UnmaskRxkSignals();
1162 /* cancel rx listener */
1163 afs_warn("RxListener... ");
1164 osi_StopListener(); /* This closes rx_socket. */
1165 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1166 afs_warn("Sleep... ");
1167 afs_osi_Sleep(&afs_termState);
1171 afs_termState = AFSOP_STOP_COMPLETE;
1175 /* Close file only after daemons which can write to it are stopped. */
1176 if (afs_cacheInodep) { /* memcache won't set this */
1177 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1178 afs_cacheInodep = 0;
1180 return; /* Just kill daemons for now */
1184 shutdown_rxkernel();
1188 shutdown_bufferpackage();
1190 #ifdef AFS_AIX51_ENV
1198 shutdown_vnodeops();
1200 shutdown_exporter();
1201 shutdown_memcache();
1202 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)) && !defined(AFS_OSF_ENV)
1206 /* The following hold the cm stats */
1208 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1209 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1210 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1212 afs_warn(" ALL allocated tables\n");
1213 afs_shuttingdown = 0;
1218 shutdown_afstest(void)
1220 AFS_STATCNT(shutdown_afstest);
1221 afs_initState = afs_termState = afs_setTime = 0;
1222 AFS_Running = afs_CB_Running = 0;
1223 afs_CacheInit_Done = afs_Go_Done = 0;
1224 if (afs_cold_shutdown) {
1225 *afs_rootVolumeName = 0;
1230 /* In case there is a bunch of dynamically build bkg daemons to free */
1232 afs_shutdown_BKG(void)
1234 AFS_STATCNT(shutdown_BKG);