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"
37 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV)
38 #define AFS_MINBUFFERS 100
40 #define AFS_MINBUFFERS 50
44 afs_int32 hosts[MAXCELLHOSTS];
48 char afs_zeros[AFS_ZEROS];
49 char afs_rootVolumeName[64] = "";
50 afs_uint32 rx_bindhost;
53 ddi_taskq_t *afs_taskq;
54 krwlock_t afsifinfo_lock;
57 afs_int32 afs_initState = 0;
58 afs_int32 afs_termState = 0;
59 afs_int32 afs_setTime = 0;
60 int afs_cold_shutdown = 0;
61 char afs_SynchronousCloses = '\0';
62 static int afs_CB_Running = 0;
63 static int AFS_Running = 0;
64 static int afs_CacheInit_Done = 0;
65 static int afs_Go_Done = 0;
66 extern struct interfaceAddr afs_cb_interface;
67 static int afs_RX_Running = 0;
68 static int afs_InitSetup_done = 0;
69 afs_int32 afs_numcachefiles = -1;
70 afs_int32 afs_numfilesperdir = -1;
71 char afs_cachebasedir[1024];
73 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
74 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
75 afs_int32 afs_rx_idledead = AFS_IDLEDEADTIME;
77 static int afscall_set_rxpck_received = 0;
79 #if defined(AFS_HPUX_ENV)
80 extern int afs_vfs_mount();
81 #endif /* defined(AFS_HPUX_ENV) */
83 /* This is code which needs to be called once when the first daemon enters
84 * the client. A non-zero return means an error and AFS should not start.
87 afs_InitSetup(int preallocs)
91 if (afs_InitSetup_done)
95 /* Initialize a RW lock for the ifinfo global array */
96 rw_init(&afsifinfo_lock, NULL, RW_DRIVER, NULL);
99 afs_taskq = ddi_taskq_create(NULL, "afs_taskq", 2, TASKQ_DEFAULTPRI, 0);
101 osi_StartNetIfPoller();
106 * Set up all the AFS statistics variables. This should be done
107 * exactly once, and it should be done here, the first resource-setting
108 * routine to be called by the CM/RX.
111 #endif /* AFS_NOSTATS */
113 memset(afs_zeros, 0, AFS_ZEROS);
116 if(!afscall_set_rxpck_received)
117 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
118 code = rx_InitHost(rx_bindhost, htons(7001));
120 printf("AFS: RX failed to initialize %d).\n", code);
123 rx_SetRxDeadTime(afs_rx_deadtime);
124 /* resource init creates the services */
125 afs_ResourceInit(preallocs);
127 afs_InitSetup_done = 1;
128 afs_osi_Wakeup(&afs_InitSetup_done);
132 #if defined(AFS_DARWIN80_ENV)
133 struct afsd_thread_info {
137 afsd_thread(int *rock)
139 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
140 unsigned long parm = arg->parm;
143 case AFSOP_START_RXCALLBACK:
147 while (afs_RX_Running != 2)
148 afs_osi_Sleep(&afs_RX_Running);
149 afs_RXCallBackServer();
151 thread_terminate(current_thread());
153 case AFSOP_START_AFS:
157 while (afs_initState < AFSOP_START_AFS)
158 afs_osi_Sleep(&afs_initState);
159 afs_initState = AFSOP_START_BKG;
160 afs_osi_Wakeup(&afs_initState);
163 thread_terminate(current_thread());
165 case AFSOP_START_BKG:
168 while (afs_initState < AFSOP_START_BKG)
169 afs_osi_Sleep(&afs_initState);
170 if (afs_initState < AFSOP_GO) {
171 afs_initState = AFSOP_GO;
172 afs_osi_Wakeup(&afs_initState);
174 afs_BackgroundDaemon();
176 thread_terminate(current_thread());
178 case AFSOP_START_TRUNCDAEMON:
181 while (afs_initState < AFSOP_GO)
182 afs_osi_Sleep(&afs_initState);
183 afs_CacheTruncateDaemon();
185 thread_terminate(current_thread());
190 afs_CheckServerDaemon();
192 thread_terminate(current_thread());
194 case AFSOP_RXEVENT_DAEMON:
197 while (afs_initState < AFSOP_START_BKG)
198 afs_osi_Sleep(&afs_initState);
199 afs_rxevent_daemon();
201 thread_terminate(current_thread());
203 case AFSOP_RXLISTENER_DAEMON:
206 afs_initState = AFSOP_START_AFS;
207 afs_osi_Wakeup(&afs_initState);
209 afs_osi_Wakeup(&afs_RX_Running);
210 afs_osi_RxkRegister();
213 thread_terminate(current_thread());
216 printf("Unknown op %ld in StartDaemon()\n", (long)parm);
222 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
226 struct afsd_thread_info info;
229 if (parm == AFSOP_START_RXCALLBACK) {
232 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
236 code = afs_InitSetup(parm2);
238 rx_enablePeerRPCStats();
241 rx_enableProcessRPCStats();
245 } else if (parm == AFSOP_START_AFS) {
248 } /* other functions don't need setup in the parent */
250 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
252 /* we need to wait cause we passed stack pointers around.... */
253 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
255 thread_deallocate(thread);
260 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)
261 struct afsd_thread_info {
262 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
263 struct work_struct tq;
266 struct completion *complete;
270 afsd_thread(void *rock)
272 struct afsd_thread_info *arg = rock;
273 unsigned long parm = arg->parm;
274 #ifdef SYS_SETPRIORITY_EXPORTED
275 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
277 #if defined(AFS_LINUX26_ENV)
282 /* doesn't do much, since we were forked from keventd, but
283 * does call mm_release, which wakes up our parent (since it
284 * used CLONE_VFORK) */
285 #if !defined(AFS_LINUX26_ENV)
288 afs_osi_MaskSignals();
290 case AFSOP_START_RXCALLBACK:
291 sprintf(current->comm, "afs_cbstart");
293 complete(arg->complete);
295 while (afs_RX_Running != 2)
296 afs_osi_Sleep(&afs_RX_Running);
297 sprintf(current->comm, "afs_callback");
298 afs_RXCallBackServer();
300 complete_and_exit(0, 0);
302 case AFSOP_START_AFS:
303 sprintf(current->comm, "afs_afsstart");
305 complete(arg->complete);
307 while (afs_initState < AFSOP_START_AFS)
308 afs_osi_Sleep(&afs_initState);
309 afs_initState = AFSOP_START_BKG;
310 afs_osi_Wakeup(&afs_initState);
311 sprintf(current->comm, "afsd");
314 complete_and_exit(0, 0);
316 case AFSOP_START_BKG:
317 sprintf(current->comm, "afs_bkgstart");
319 complete(arg->complete);
320 while (afs_initState < AFSOP_START_BKG)
321 afs_osi_Sleep(&afs_initState);
322 if (afs_initState < AFSOP_GO) {
323 afs_initState = AFSOP_GO;
324 afs_osi_Wakeup(&afs_initState);
326 sprintf(current->comm, "afs_background");
327 afs_BackgroundDaemon();
329 complete_and_exit(0, 0);
331 case AFSOP_START_TRUNCDAEMON:
332 sprintf(current->comm, "afs_trimstart");
334 complete(arg->complete);
335 while (afs_initState < AFSOP_GO)
336 afs_osi_Sleep(&afs_initState);
337 sprintf(current->comm, "afs_cachetrim");
338 afs_CacheTruncateDaemon();
340 complete_and_exit(0, 0);
343 sprintf(current->comm, "afs_checkserver");
345 complete(arg->complete);
346 afs_CheckServerDaemon();
348 complete_and_exit(0, 0);
350 case AFSOP_RXEVENT_DAEMON:
351 sprintf(current->comm, "afs_evtstart");
352 #ifdef SYS_SETPRIORITY_EXPORTED
353 sys_setpriority(PRIO_PROCESS, 0, -10);
355 #ifdef CURRENT_INCLUDES_NICE
360 complete(arg->complete);
361 while (afs_initState < AFSOP_START_BKG)
362 afs_osi_Sleep(&afs_initState);
363 sprintf(current->comm, "afs_rxevent");
364 afs_rxevent_daemon();
366 complete_and_exit(0, 0);
368 case AFSOP_RXLISTENER_DAEMON:
369 sprintf(current->comm, "afs_lsnstart");
370 #ifdef SYS_SETPRIORITY_EXPORTED
371 sys_setpriority(PRIO_PROCESS, 0, -10);
373 #ifdef CURRENT_INCLUDES_NICE
378 complete(arg->complete);
379 afs_initState = AFSOP_START_AFS;
380 afs_osi_Wakeup(&afs_initState);
382 afs_osi_Wakeup(&afs_RX_Running);
383 afs_osi_RxkRegister();
384 sprintf(current->comm, "afs_rxlistener");
387 complete_and_exit(0, 0);
390 printf("Unknown op %ld in StartDaemon()\n", (long)parm);
397 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
398 afsd_launcher(struct work_struct *work)
400 afsd_launcher(void *rock)
403 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
404 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
407 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
408 printf("kernel_thread failed. afs startup will not complete\n");
412 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
416 DECLARE_COMPLETION(c);
417 #if defined(AFS_LINUX26_ENV)
418 struct work_struct tq;
422 struct afsd_thread_info info;
423 if (parm == AFSOP_START_RXCALLBACK) {
426 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
430 code = afs_InitSetup(parm2);
432 rx_enablePeerRPCStats();
435 rx_enableProcessRPCStats();
439 } else if (parm == AFSOP_START_AFS) {
442 } /* other functions don't need setup in the parent */
445 #if defined(AFS_LINUX26_ENV)
446 #if !defined(INIT_WORK_HAS_DATA)
447 INIT_WORK(&info.tq, afsd_launcher);
448 schedule_work(&info.tq);
450 INIT_WORK(&tq, afsd_launcher, &info);
455 INIT_LIST_HEAD(&tq.list);
456 tq.routine = afsd_launcher;
461 /* we need to wait cause we passed stack pointers around.... */
462 wait_for_completion(&c);
468 wait_for_cachedefs(void) {
469 #ifdef AFS_CACHE_VNODE_PATH
470 if (cacheDiskType != AFS_FCACHE_TYPE_MEM)
471 while ((afs_numcachefiles < 1) || (afs_numfilesperdir < 1) ||
472 (afs_cachebasedir[0] != '/')) {
473 printf("afs: waiting for cache parameter definitions\n");
474 afs_osi_Sleep(&afs_initState);
480 afs_syscall_call(long parm, long parm2, long parm3, long parm4, long parm5, long parm6)
483 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
485 #else /* AFS_SGI61_ENV */
487 #endif /* AFS_SGI61_ENV */
489 AFS_STATCNT(afs_syscall_call);
496 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
497 /* only root can run this code */
498 #if defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
499 #if defined(KERNEL_HAVE_UERROR)
507 #ifdef AFS_DARWIN80_ENV
513 #ifdef AFS_DARWIN80_ENV
516 #if ((defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)) || defined(AFS_DARWIN80_ENV)) && !defined(UKERNEL)
517 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
518 || parm == AFSOP_RXLISTENER_DAEMON) {
519 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
521 #else /* !(AFS_LINUX24_ENV && !UKERNEL) */
522 if (parm == AFSOP_START_RXCALLBACK) {
526 #ifndef RXK_LISTENER_ENV
527 code = afs_InitSetup(parm2);
529 #endif /* !RXK_LISTENER_ENV */
531 #ifdef RXK_LISTENER_ENV
532 while (afs_RX_Running != 2)
533 afs_osi_Sleep(&afs_RX_Running);
534 #else /* !RXK_LISTENER_ENV */
535 afs_initState = AFSOP_START_AFS;
536 afs_osi_Wakeup(&afs_initState);
537 #endif /* RXK_LISTENER_ENV */
539 afs_RXCallBackServer();
544 exit(CLD_EXITED, code);
545 #endif /* AFS_SGI_ENV */
547 #ifdef RXK_LISTENER_ENV
548 else if (parm == AFSOP_RXLISTENER_DAEMON) {
552 code = afs_InitSetup(parm2);
554 rx_enablePeerRPCStats();
557 rx_enableProcessRPCStats();
560 afs_initState = AFSOP_START_AFS;
561 afs_osi_Wakeup(&afs_initState);
564 afs_osi_Wakeup(&afs_RX_Running);
566 afs_osi_RxkRegister();
567 #endif /* !UKERNEL */
573 exit(CLD_EXITED, code);
574 #endif /* AFS_SGI_ENV */
576 #endif /* RXK_LISTENER_ENV */
577 else if (parm == AFSOP_START_AFS) {
582 while (afs_initState < AFSOP_START_AFS)
583 afs_osi_Sleep(&afs_initState);
585 afs_initState = AFSOP_START_BKG;
586 afs_osi_Wakeup(&afs_initState);
593 #endif /* AFS_SGI_ENV */
594 } else if (parm == AFSOP_START_CS) {
596 afs_CheckServerDaemon();
601 #endif /* AFS_SGI_ENV */
602 } else if (parm == AFSOP_START_BKG) {
603 while (afs_initState < AFSOP_START_BKG)
604 afs_osi_Sleep(&afs_initState);
605 if (afs_initState < AFSOP_GO) {
606 afs_initState = AFSOP_GO;
607 afs_osi_Wakeup(&afs_initState);
609 /* start the bkg daemon */
613 afs_BioDaemon(parm2);
615 #endif /* AFS_AIX32_ENV */
616 afs_BackgroundDaemon();
621 #endif /* AFS_SGI_ENV */
622 } else if (parm == AFSOP_START_TRUNCDAEMON) {
623 while (afs_initState < AFSOP_GO)
624 afs_osi_Sleep(&afs_initState);
625 /* start the bkg daemon */
627 afs_CacheTruncateDaemon();
632 #endif /* AFS_SGI_ENV */
634 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
635 else if (parm == AFSOP_RXEVENT_DAEMON) {
636 while (afs_initState < AFSOP_START_BKG)
637 afs_osi_Sleep(&afs_initState);
639 afs_rxevent_daemon();
644 #endif /* AFS_SGI_ENV */
646 #endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
647 #endif /* AFS_LINUX24_ENV && !UKERNEL */
648 else if (parm == AFSOP_BASIC_INIT) {
651 while (!afs_InitSetup_done)
652 afs_osi_Sleep(&afs_InitSetup_done);
654 #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)
655 temp = AFS_MINBUFFERS; /* Should fix this soon */
657 /* number of 2k buffers we could get from all of the buffer space */
658 temp = ((afs_bufferpages * NBPG) >> 11);
659 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
660 if (temp < AFS_MINBUFFERS)
661 temp = AFS_MINBUFFERS; /* though we really should have this many */
664 afs_rootFid.Fid.Volume = 0;
666 } else if (parm == AFSOP_BUCKETPCT) {
667 /* need to enable this now, will disable again before GO
668 if we don't have 100% */
678 } else if (parm == AFSOP_ADDCELL) {
679 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
680 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
681 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
682 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
684 code = afs_InitDynroot();
686 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts),
690 if (parm4 > sizeof(tcell->cellName))
693 AFS_COPYIN((char *)parm3, tcell->cellName, parm4, code);
695 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
699 afs_osi_Free(tcell, sizeof(struct afsop_cell));
700 } else if (parm == AFSOP_ADDCELL2) {
701 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
702 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
703 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
706 code = afs_InitDynroot();
709 /* wait for basic init - XXX can't find any reason we need this? */
710 while (afs_initState < AFSOP_START_BKG)
711 afs_osi_Sleep(&afs_initState);
714 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts),
718 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ,
722 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ,
726 cflags |= CLinkedCell;
731 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
735 afs_osi_Free(tcell, sizeof(struct afsop_cell));
736 osi_FreeSmallSpace(tbuffer);
737 osi_FreeSmallSpace(tbuffer1);
738 } else if (parm == AFSOP_ADDCELLALIAS) {
741 * parm2 is the alias name
742 * parm3 is the real cell name
744 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
745 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
747 code = afs_InitDynroot();
749 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize,
753 AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ,
756 afs_NewCellAlias(aliasName, cellName);
757 osi_FreeSmallSpace(aliasName);
758 osi_FreeSmallSpace(cellName);
759 } else if (parm == AFSOP_SET_THISCELL) {
762 * parm2 is the primary cell name
764 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
766 code = afs_InitDynroot();
768 AFS_COPYINSTR((char *)parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code);
771 afs_SetPrimaryCell(cell);
772 osi_FreeSmallSpace(cell);
773 } else if (parm == AFSOP_CACHEINIT) {
774 struct afs_cacheParams cparms;
776 if (afs_CacheInit_Done)
779 AFS_COPYIN((char *)parm2, (caddr_t) & cparms, sizeof(cparms), code);
781 #if defined(KERNEL_HAVE_UERROR)
787 afs_CacheInit_Done = 1;
788 code = afs_icl_InitLogs();
789 afs_setTime = cparms.setTimeFlag;
792 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
793 cparms.cacheBlocks, cparms.cacheDcaches,
794 cparms.cacheVolumes, cparms.chunkSize,
795 cparms.memCacheFlag, cparms.inodes, cparms.users);
797 } else if (parm == AFSOP_CACHEINODE) {
798 ino_t ainode = parm2;
799 /* wait for basic init */
800 while (afs_initState < AFSOP_START_BKG)
801 afs_osi_Sleep(&afs_initState);
803 #ifdef AFS_DARWIN80_ENV
808 ainode = (ainode << 32) | (parm3 & 0xffffffff);
810 code = afs_InitCacheFile(NULL, ainode);
811 #ifdef AFS_DARWIN80_ENV
814 } else if (parm == AFSOP_CACHEDIRS) {
815 afs_numfilesperdir = parm2;
816 afs_osi_Wakeup(&afs_initState);
817 } else if (parm == AFSOP_CACHEFILES) {
818 afs_numcachefiles = parm2;
819 afs_osi_Wakeup(&afs_initState);
820 } else if (parm == AFSOP_ROOTVOLUME) {
821 /* wait for basic init */
822 while (afs_initState < AFSOP_START_BKG)
823 afs_osi_Sleep(&afs_initState);
826 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName,
827 sizeof(afs_rootVolumeName), &bufferSize, code);
828 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
831 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
832 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG
833 || parm == AFSOP_CELLINFO || parm == AFSOP_CACHEBASEDIR) {
834 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
837 AFS_COPYINSTR((char *)parm2, tbuffer, AFS_SMALLOCSIZ, &bufferSize,
840 osi_FreeSmallSpace(tbuffer);
844 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
845 /* We have the cache dir copied in. Call the cache init routine */
846 #ifdef AFS_DARWIN80_ENV
849 if (parm == AFSOP_CACHEBASEDIR) {
850 strncpy(afs_cachebasedir, tbuffer, 1024);
851 afs_cachebasedir[1023] = '\0';
852 afs_osi_Wakeup(&afs_initState);
853 } else if (parm == AFSOP_CACHEFILE) {
854 wait_for_cachedefs();
855 code = afs_InitCacheFile(tbuffer, 0);
856 } else if (parm == AFSOP_CACHEINFO) {
857 wait_for_cachedefs();
858 code = afs_InitCacheInfo(tbuffer);
859 } else if (parm == AFSOP_VOLUMEINFO) {
860 wait_for_cachedefs();
861 code = afs_InitVolumeInfo(tbuffer);
862 } else if (parm == AFSOP_CELLINFO) {
863 wait_for_cachedefs();
864 code = afs_InitCellInfo(tbuffer);
866 #ifdef AFS_DARWIN80_ENV
870 osi_FreeSmallSpace(tbuffer);
871 } else if (parm == AFSOP_GO) {
872 #ifdef AFS_CACHE_VNODE_PATH
873 if (cacheDiskType != AFS_FCACHE_TYPE_MEM) {
876 wait_for_cachedefs();
878 #ifdef AFS_DARWIN80_ENV
881 if ((afs_numcachefiles > 0) && (afs_numfilesperdir > 0) &&
882 (afs_cachebasedir[0] == '/')) {
883 for (dummy = 0; dummy < afs_numcachefiles; dummy++) {
884 code = afs_InitCacheFile(NULL, dummy);
887 #ifdef AFS_DARWIN80_ENV
892 /* the generic initialization calls come here. One parameter: should we do the
893 * set-time operation on this workstation */
897 while (afs_initState < AFSOP_GO)
898 afs_osi_Sleep(&afs_initState);
901 if (afs_tpct1 + afs_tpct2 != 100) {
908 afs_osi_Wakeup(&afs_initState);
909 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
910 afs_nfsclient_init();
912 afs_uuid_create(&afs_cb_interface.uuid);
913 printf("found %d non-empty cache files (%d%%).\n",
914 afs_stats_cmperf.cacheFilesReused,
915 (100 * afs_stats_cmperf.cacheFilesReused) /
916 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
917 cacheNumEntries : 1));
918 } else if (parm == AFSOP_ADVISEADDR) {
919 /* pass in the host address to the rx package */
923 afs_int32 count = parm2;
925 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
926 afs_int32 *maskbuffer =
927 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
928 afs_int32 *mtubuffer =
929 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
932 /* This is a refresh */
933 if (count & 0x40000000) {
934 count &= ~0x40000000;
935 /* Can't bind after we start. Fix? */
936 count &= ~0x80000000;
940 /* Bind, but only if there's only one address configured */
941 if ( count & 0x80000000) {
942 count &= ~0x80000000;
947 if (count > AFS_MAX_INTERFACE_ADDR) {
949 count = AFS_MAX_INTERFACE_ADDR;
952 AFS_COPYIN((char *)parm3, (char *)buffer, count * sizeof(afs_int32),
955 AFS_COPYIN((char *)parm4, (char *)maskbuffer,
956 count * sizeof(afs_int32), code);
958 AFS_COPYIN((char *)parm5, (char *)mtubuffer,
959 count * sizeof(afs_int32), code);
961 afs_cb_interface.numberOfInterfaces = count;
962 for (i = 0; i < count; i++) {
963 afs_cb_interface.addr_in[i] = buffer[i];
964 #ifdef AFS_USERSPACE_IP_ADDR
965 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
966 * machines IP addresses when in the kernel (the in_ifaddr
967 * struct is not available), so we pass the info in at
968 * startup. We also pass in the subnetmask and mtu size. The
969 * subnetmask is used when setting the rank:
970 * afsi_SetServerIPRank(); and the mtu size is used when
971 * finding the best mtu size. rxi_FindIfnet() is replaced
972 * with rxi_Findcbi().
974 afs_cb_interface.subnetmask[i] =
975 (parm4 ? maskbuffer[i] : 0xffffffff);
976 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
979 rxi_setaddr(buffer[0]);
982 rx_bindhost = buffer[0];
984 rx_bindhost = htonl(INADDR_ANY);
987 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
988 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
989 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
992 afs_CheckServers(1, NULL); /* check down servers */
993 afs_CheckServers(0, NULL); /* check down servers */
997 else if (parm == AFSOP_NFSSTATICADDR) {
998 extern int (*nfs_rfsdisptab_v2) ();
999 nfs_rfsdisptab_v2 = (int (*)())parm2;
1000 } else if (parm == AFSOP_NFSSTATICADDR2) {
1001 extern int (*nfs_rfsdisptab_v2) ();
1003 nfs_rfsdisptab_v2 = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
1005 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
1006 #endif /* _K64U64 */
1008 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
1009 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
1010 extern int (*afs_sblockp) ();
1011 extern void (*afs_sbunlockp) ();
1013 afs_sblockp = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
1014 afs_sbunlockp = (void (*)())((parm4 << 32) | (parm5 & 0xffffffff));
1016 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
1017 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
1018 #endif /* _K64U64 */
1020 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
1021 #endif /* AFS_SGI53_ENV */
1022 else if (parm == AFSOP_SHUTDOWN) {
1023 afs_cold_shutdown = 0;
1025 afs_cold_shutdown = 1;
1026 #ifndef AFS_DARWIN_ENV
1027 if (afs_globalVFS != 0) {
1028 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1033 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1035 vfsmount(parm2, parm3, parm4, parm5);
1036 #else /* defined(AFS_HPUX_ENV) */
1037 #if defined(KERNEL_HAVE_UERROR)
1042 #endif /* defined(AFS_HPUX_ENV) */
1043 } else if (parm == AFSOP_CLOSEWAIT) {
1044 afs_SynchronousCloses = 'S';
1045 } else if (parm == AFSOP_GETMTU) {
1047 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1048 #ifdef AFS_USERSPACE_IP_ADDR
1050 i = rxi_Findcbi(parm2);
1051 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1052 #else /* AFS_USERSPACE_IP_ADDR */
1055 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1056 mtu = (tifnp ? ifnet_mtu(tifnp) : htonl(1500));
1057 #endif /* else AFS_USERSPACE_IP_ADDR */
1058 #endif /* !AFS_SUN5_ENV */
1060 AFS_COPYOUT((caddr_t) & mtu, (caddr_t) parm3, sizeof(afs_int32),
1062 #ifdef AFS_AIX32_ENV
1063 /* this is disabled for now because I can't figure out how to get access
1064 * to these kernel variables. It's only for supporting user-mode rx
1065 * programs -- it makes a huge difference on the 220's in my testbed,
1066 * though I don't know why. The bosserver does this with /etc/no, so it's
1067 * being handled a different way for the servers right now. */
1069 static adjusted = 0;
1070 extern u_long sb_max_dflt;
1073 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1074 if (sb_max < 131072) sb_max = 131072;
1077 #endif /* AFS_AIX32_ENV */
1078 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1079 afs_uint32 mask = 0;
1080 #if !defined(AFS_SUN5_ENV)
1081 #ifdef AFS_USERSPACE_IP_ADDR
1083 i = rxi_Findcbi(parm2);
1085 mask = afs_cb_interface.subnetmask[i];
1089 #else /* AFS_USERSPACE_IP_ADDR */
1092 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1095 #endif /* else AFS_USERSPACE_IP_ADDR */
1096 #endif /* !AFS_SUN5_ENV */
1098 AFS_COPYOUT((caddr_t) & mask, (caddr_t) parm3, sizeof(afs_int32),
1101 #ifdef AFS_AFSDB_ENV
1102 else if (parm == AFSOP_AFSDB_HANDLER) {
1103 int sizeArg = (int)parm4;
1104 int kmsgLen = sizeArg & 0xffff;
1105 int cellLen = (sizeArg & 0xffff0000) >> 16;
1106 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1107 char *cellname = afs_osi_Alloc(cellLen);
1110 afs_osi_MaskUserLoop();
1112 AFS_COPYIN((afs_int32 *) parm2, cellname, cellLen, code);
1113 AFS_COPYIN((afs_int32 *) parm3, kmsg, kmsgLen, code);
1115 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1118 if (code == -2) { /* Shutting down? */
1124 AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
1125 afs_osi_Free(kmsg, kmsgLen);
1126 afs_osi_Free(cellname, cellLen);
1129 else if (parm == AFSOP_SET_DYNROOT) {
1130 code = afs_SetDynrootEnable(parm2);
1131 } else if (parm == AFSOP_SET_FAKESTAT) {
1132 afs_fakestat_enable = parm2;
1134 } else if (parm == AFSOP_SET_BACKUPTREE) {
1135 afs_bkvolpref = parm2;
1136 } else if (parm == AFSOP_SET_RXPCK) {
1137 rx_extraPackets = parm2;
1138 afscall_set_rxpck_received = 1;
1144 #ifdef AFS_LINUX20_ENV
1152 * Initstate in the range 0 < x < 100 are early initialization states.
1153 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1154 * the cache may be initialized.
1155 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1156 * is done after all the cache initialization has been done.
1157 * Initstate of 200 means that the volume has been looked up once, possibly
1159 * Initstate of 300 means that the volume has been *successfully* looked up.
1164 register int code = 0;
1166 AFS_STATCNT(afs_CheckInit);
1167 if (afs_initState <= 100)
1168 code = ENXIO; /* never finished init phase */
1169 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1170 while (afs_initState < 200)
1171 afs_osi_Sleep(&afs_initState);
1172 } else if (afs_initState == 200)
1173 code = ETIMEDOUT; /* didn't find root volume */
1177 int afs_shuttingdown = 0;
1181 extern short afs_brsDaemons;
1182 extern afs_int32 afs_CheckServerDaemonStarted;
1183 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1184 extern struct osi_file *afs_cacheInodep;
1186 AFS_STATCNT(afs_shutdown);
1187 if (afs_initState == 0) {
1188 afs_warn("AFS not initialized - not shutting down\n");
1192 if (afs_shuttingdown)
1194 afs_shuttingdown = 1;
1195 if (afs_cold_shutdown)
1199 afs_warn("shutting down of: CB... ");
1201 afs_termState = AFSOP_STOP_RXCALLBACK;
1202 rx_WakeupServerProcs();
1203 #ifdef AFS_AIX51_ENV
1204 shutdown_rxkernel();
1206 /* shutdown_rxkernel(); */
1207 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1208 afs_osi_Sleep(&afs_termState);
1210 afs_warn("afs... ");
1211 while (afs_termState == AFSOP_STOP_AFS) {
1212 afs_osi_CancelWait(&AFS_WaitHandler);
1213 afs_osi_Sleep(&afs_termState);
1215 if (afs_CheckServerDaemonStarted) {
1216 while (afs_termState == AFSOP_STOP_CS) {
1217 afs_osi_CancelWait(&AFS_CSWaitHandler);
1218 afs_osi_Sleep(&afs_termState);
1221 afs_warn("BkG... ");
1222 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1223 while (afs_termState == AFSOP_STOP_BKG) {
1224 afs_osi_Wakeup(&afs_brsDaemons);
1225 afs_osi_Sleep(&afs_termState);
1227 afs_warn("CTrunc... ");
1228 /* Cancel cache truncate daemon. */
1229 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1230 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1231 afs_osi_Sleep(&afs_termState);
1233 #ifdef AFS_AFSDB_ENV
1234 afs_warn("AFSDB... ");
1236 while (afs_termState == AFSOP_STOP_AFSDB)
1237 afs_osi_Sleep(&afs_termState);
1239 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1240 afs_warn("RxEvent... ");
1241 /* cancel rx event daemon */
1242 while (afs_termState == AFSOP_STOP_RXEVENT)
1243 afs_osi_Sleep(&afs_termState);
1244 #if defined(RXK_LISTENER_ENV)
1246 afs_warn("UnmaskRxkSignals... ");
1247 afs_osi_UnmaskRxkSignals();
1249 /* cancel rx listener */
1250 afs_warn("RxListener... ");
1251 osi_StopListener(); /* This closes rx_socket. */
1252 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1253 afs_warn("Sleep... ");
1254 afs_osi_Sleep(&afs_termState);
1258 afs_termState = AFSOP_STOP_COMPLETE;
1262 #ifdef AFS_AIX51_ENV
1269 shutdown_rxkernel();
1274 shutdown_bufferpackage();
1279 shutdown_vnodeops();
1280 shutdown_memcache();
1281 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)) && !defined(AFS_OSF_ENV)
1282 shutdown_exporter();
1286 /* The following hold the cm stats */
1288 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1289 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1290 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1292 afs_warn(" ALL allocated tables\n");
1294 /* Close file only after daemons which can write to it are stopped. */
1295 if (afs_cacheInodep) { /* memcache won't set this */
1296 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1297 afs_cacheInodep = 0;
1300 afs_shuttingdown = 0;
1302 return; /* Just kill daemons for now */
1306 shutdown_afstest(void)
1308 AFS_STATCNT(shutdown_afstest);
1309 afs_initState = afs_termState = afs_setTime = 0;
1310 AFS_Running = afs_CB_Running = 0;
1311 afs_CacheInit_Done = afs_Go_Done = 0;
1312 if (afs_cold_shutdown) {
1313 *afs_rootVolumeName = 0;
1318 /* In case there is a bunch of dynamically build bkg daemons to free */
1320 afs_shutdown_BKG(void)
1322 AFS_STATCNT(shutdown_BKG);