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 #if defined(INIT_WORK_HAS_DATA)
419 struct work_struct tq;
424 struct afsd_thread_info info;
425 if (parm == AFSOP_START_RXCALLBACK) {
428 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
432 code = afs_InitSetup(parm2);
434 rx_enablePeerRPCStats();
437 rx_enableProcessRPCStats();
441 } else if (parm == AFSOP_START_AFS) {
444 } /* other functions don't need setup in the parent */
447 #if defined(AFS_LINUX26_ENV)
448 #if !defined(INIT_WORK_HAS_DATA)
449 INIT_WORK(&info.tq, afsd_launcher);
450 schedule_work(&info.tq);
452 INIT_WORK(&tq, afsd_launcher, &info);
457 INIT_LIST_HEAD(&tq.list);
458 tq.routine = afsd_launcher;
463 /* we need to wait cause we passed stack pointers around.... */
464 wait_for_completion(&c);
470 wait_for_cachedefs(void) {
471 #ifdef AFS_CACHE_VNODE_PATH
472 if (cacheDiskType != AFS_FCACHE_TYPE_MEM)
473 while ((afs_numcachefiles < 1) || (afs_numfilesperdir < 1) ||
474 (afs_cachebasedir[0] != '/')) {
475 printf("afs: waiting for cache parameter definitions\n");
476 afs_osi_Sleep(&afs_initState);
482 afs_syscall_call(long parm, long parm2, long parm3, long parm4, long parm5, long parm6)
485 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
487 #else /* AFS_SGI61_ENV */
489 #endif /* AFS_SGI61_ENV */
491 AFS_STATCNT(afs_syscall_call);
498 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
499 /* only root can run this code */
500 #if defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
501 #if defined(KERNEL_HAVE_UERROR)
509 #ifdef AFS_DARWIN80_ENV
515 #ifdef AFS_DARWIN80_ENV
518 #if ((defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)) || defined(AFS_DARWIN80_ENV)) && !defined(UKERNEL)
519 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
520 || parm == AFSOP_RXLISTENER_DAEMON) {
521 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
523 #else /* !(AFS_LINUX24_ENV && !UKERNEL) */
524 if (parm == AFSOP_START_RXCALLBACK) {
528 #ifndef RXK_LISTENER_ENV
529 code = afs_InitSetup(parm2);
531 #endif /* !RXK_LISTENER_ENV */
533 #ifdef RXK_LISTENER_ENV
534 while (afs_RX_Running != 2)
535 afs_osi_Sleep(&afs_RX_Running);
536 #else /* !RXK_LISTENER_ENV */
537 afs_initState = AFSOP_START_AFS;
538 afs_osi_Wakeup(&afs_initState);
539 #endif /* RXK_LISTENER_ENV */
541 afs_RXCallBackServer();
546 exit(CLD_EXITED, code);
547 #endif /* AFS_SGI_ENV */
549 #ifdef RXK_LISTENER_ENV
550 else if (parm == AFSOP_RXLISTENER_DAEMON) {
554 code = afs_InitSetup(parm2);
556 rx_enablePeerRPCStats();
559 rx_enableProcessRPCStats();
562 afs_initState = AFSOP_START_AFS;
563 afs_osi_Wakeup(&afs_initState);
566 afs_osi_Wakeup(&afs_RX_Running);
568 afs_osi_RxkRegister();
569 #endif /* !UKERNEL */
575 exit(CLD_EXITED, code);
576 #endif /* AFS_SGI_ENV */
578 #endif /* RXK_LISTENER_ENV */
579 else if (parm == AFSOP_START_AFS) {
584 while (afs_initState < AFSOP_START_AFS)
585 afs_osi_Sleep(&afs_initState);
587 afs_initState = AFSOP_START_BKG;
588 afs_osi_Wakeup(&afs_initState);
595 #endif /* AFS_SGI_ENV */
596 } else if (parm == AFSOP_START_CS) {
598 afs_CheckServerDaemon();
603 #endif /* AFS_SGI_ENV */
604 } else if (parm == AFSOP_START_BKG) {
605 while (afs_initState < AFSOP_START_BKG)
606 afs_osi_Sleep(&afs_initState);
607 if (afs_initState < AFSOP_GO) {
608 afs_initState = AFSOP_GO;
609 afs_osi_Wakeup(&afs_initState);
611 /* start the bkg daemon */
615 afs_BioDaemon(parm2);
617 #endif /* AFS_AIX32_ENV */
618 afs_BackgroundDaemon();
623 #endif /* AFS_SGI_ENV */
624 } else if (parm == AFSOP_START_TRUNCDAEMON) {
625 while (afs_initState < AFSOP_GO)
626 afs_osi_Sleep(&afs_initState);
627 /* start the bkg daemon */
629 afs_CacheTruncateDaemon();
634 #endif /* AFS_SGI_ENV */
636 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
637 else if (parm == AFSOP_RXEVENT_DAEMON) {
638 while (afs_initState < AFSOP_START_BKG)
639 afs_osi_Sleep(&afs_initState);
641 afs_rxevent_daemon();
646 #endif /* AFS_SGI_ENV */
648 #endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
649 #endif /* AFS_LINUX24_ENV && !UKERNEL */
650 else if (parm == AFSOP_BASIC_INIT) {
653 while (!afs_InitSetup_done)
654 afs_osi_Sleep(&afs_InitSetup_done);
656 #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)
657 temp = AFS_MINBUFFERS; /* Should fix this soon */
659 /* number of 2k buffers we could get from all of the buffer space */
660 temp = ((afs_bufferpages * NBPG) >> 11);
661 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
662 if (temp < AFS_MINBUFFERS)
663 temp = AFS_MINBUFFERS; /* though we really should have this many */
666 afs_rootFid.Fid.Volume = 0;
668 } else if (parm == AFSOP_BUCKETPCT) {
669 /* need to enable this now, will disable again before GO
670 if we don't have 100% */
680 } else if (parm == AFSOP_ADDCELL) {
681 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
682 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
683 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
684 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
686 code = afs_InitDynroot();
688 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts),
692 if (parm4 > sizeof(tcell->cellName))
695 AFS_COPYIN((char *)parm3, tcell->cellName, parm4, code);
697 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
701 afs_osi_Free(tcell, sizeof(struct afsop_cell));
702 } else if (parm == AFSOP_ADDCELL2) {
703 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
704 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
705 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
708 code = afs_InitDynroot();
711 /* wait for basic init - XXX can't find any reason we need this? */
712 while (afs_initState < AFSOP_START_BKG)
713 afs_osi_Sleep(&afs_initState);
716 AFS_COPYIN((char *)parm2, (char *)tcell->hosts, sizeof(tcell->hosts),
720 AFS_COPYINSTR((char *)parm3, tbuffer1, AFS_SMALLOCSIZ,
724 AFS_COPYINSTR((char *)parm5, tbuffer, AFS_SMALLOCSIZ,
728 cflags |= CLinkedCell;
733 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
737 afs_osi_Free(tcell, sizeof(struct afsop_cell));
738 osi_FreeSmallSpace(tbuffer);
739 osi_FreeSmallSpace(tbuffer1);
740 } else if (parm == AFSOP_ADDCELLALIAS) {
743 * parm2 is the alias name
744 * parm3 is the real cell name
746 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
747 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
749 code = afs_InitDynroot();
751 AFS_COPYINSTR((char *)parm2, aliasName, AFS_SMALLOCSIZ, &bufferSize,
755 AFS_COPYINSTR((char *)parm3, cellName, AFS_SMALLOCSIZ,
758 afs_NewCellAlias(aliasName, cellName);
759 osi_FreeSmallSpace(aliasName);
760 osi_FreeSmallSpace(cellName);
761 } else if (parm == AFSOP_SET_THISCELL) {
764 * parm2 is the primary cell name
766 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
768 code = afs_InitDynroot();
770 AFS_COPYINSTR((char *)parm2, cell, AFS_SMALLOCSIZ, &bufferSize, code);
773 afs_SetPrimaryCell(cell);
774 osi_FreeSmallSpace(cell);
775 } else if (parm == AFSOP_CACHEINIT) {
776 struct afs_cacheParams cparms;
778 if (afs_CacheInit_Done)
781 AFS_COPYIN((char *)parm2, (caddr_t) & cparms, sizeof(cparms), code);
783 #if defined(KERNEL_HAVE_UERROR)
789 afs_CacheInit_Done = 1;
790 code = afs_icl_InitLogs();
791 afs_setTime = cparms.setTimeFlag;
794 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
795 cparms.cacheBlocks, cparms.cacheDcaches,
796 cparms.cacheVolumes, cparms.chunkSize,
797 cparms.memCacheFlag, cparms.inodes, cparms.users,
798 cparms.dynamic_vcaches);
800 } else if (parm == AFSOP_CACHEINODE) {
801 ino_t ainode = parm2;
802 /* wait for basic init */
803 while (afs_initState < AFSOP_START_BKG)
804 afs_osi_Sleep(&afs_initState);
806 #ifdef AFS_DARWIN80_ENV
811 ainode = (ainode << 32) | (parm3 & 0xffffffff);
813 code = afs_InitCacheFile(NULL, ainode);
814 #ifdef AFS_DARWIN80_ENV
817 } else if (parm == AFSOP_CACHEDIRS) {
818 afs_numfilesperdir = parm2;
819 afs_osi_Wakeup(&afs_initState);
820 } else if (parm == AFSOP_CACHEFILES) {
821 afs_numcachefiles = parm2;
822 afs_osi_Wakeup(&afs_initState);
823 } else if (parm == AFSOP_ROOTVOLUME) {
824 /* wait for basic init */
825 while (afs_initState < AFSOP_START_BKG)
826 afs_osi_Sleep(&afs_initState);
829 AFS_COPYINSTR((char *)parm2, afs_rootVolumeName,
830 sizeof(afs_rootVolumeName), &bufferSize, code);
831 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
834 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
835 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG
836 || parm == AFSOP_CELLINFO || parm == AFSOP_CACHEBASEDIR) {
837 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
840 AFS_COPYINSTR((char *)parm2, tbuffer, AFS_SMALLOCSIZ, &bufferSize,
843 osi_FreeSmallSpace(tbuffer);
847 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
848 /* We have the cache dir copied in. Call the cache init routine */
849 #ifdef AFS_DARWIN80_ENV
852 if (parm == AFSOP_CACHEBASEDIR) {
853 strncpy(afs_cachebasedir, tbuffer, 1024);
854 afs_cachebasedir[1023] = '\0';
855 afs_osi_Wakeup(&afs_initState);
856 } else if (parm == AFSOP_CACHEFILE) {
857 wait_for_cachedefs();
858 code = afs_InitCacheFile(tbuffer, 0);
859 } else if (parm == AFSOP_CACHEINFO) {
860 wait_for_cachedefs();
861 code = afs_InitCacheInfo(tbuffer);
862 } else if (parm == AFSOP_VOLUMEINFO) {
863 wait_for_cachedefs();
864 code = afs_InitVolumeInfo(tbuffer);
865 } else if (parm == AFSOP_CELLINFO) {
866 wait_for_cachedefs();
867 code = afs_InitCellInfo(tbuffer);
869 #ifdef AFS_DARWIN80_ENV
873 osi_FreeSmallSpace(tbuffer);
874 } else if (parm == AFSOP_GO) {
875 #ifdef AFS_CACHE_VNODE_PATH
876 if (cacheDiskType != AFS_FCACHE_TYPE_MEM) {
879 wait_for_cachedefs();
881 #ifdef AFS_DARWIN80_ENV
884 if ((afs_numcachefiles > 0) && (afs_numfilesperdir > 0) &&
885 (afs_cachebasedir[0] == '/')) {
886 for (dummy = 0; dummy < afs_numcachefiles; dummy++) {
887 code = afs_InitCacheFile(NULL, dummy);
890 #ifdef AFS_DARWIN80_ENV
895 /* the generic initialization calls come here. One parameter: should we do the
896 * set-time operation on this workstation */
900 while (afs_initState < AFSOP_GO)
901 afs_osi_Sleep(&afs_initState);
904 if (afs_tpct1 + afs_tpct2 != 100) {
911 afs_osi_Wakeup(&afs_initState);
912 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
913 afs_nfsclient_init();
915 afs_uuid_create(&afs_cb_interface.uuid);
916 printf("found %d non-empty cache files (%d%%).\n",
917 afs_stats_cmperf.cacheFilesReused,
918 (100 * afs_stats_cmperf.cacheFilesReused) /
919 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
920 cacheNumEntries : 1));
921 } else if (parm == AFSOP_ADVISEADDR) {
922 /* pass in the host address to the rx package */
926 afs_int32 count = parm2;
928 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
929 afs_int32 *maskbuffer =
930 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
931 afs_int32 *mtubuffer =
932 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
935 /* This is a refresh */
936 if (count & 0x40000000) {
937 count &= ~0x40000000;
938 /* Can't bind after we start. Fix? */
939 count &= ~0x80000000;
943 /* Bind, but only if there's only one address configured */
944 if ( count & 0x80000000) {
945 count &= ~0x80000000;
950 if (count > AFS_MAX_INTERFACE_ADDR) {
952 count = AFS_MAX_INTERFACE_ADDR;
955 AFS_COPYIN((char *)parm3, (char *)buffer, count * sizeof(afs_int32),
958 AFS_COPYIN((char *)parm4, (char *)maskbuffer,
959 count * sizeof(afs_int32), code);
961 AFS_COPYIN((char *)parm5, (char *)mtubuffer,
962 count * sizeof(afs_int32), code);
964 afs_cb_interface.numberOfInterfaces = count;
965 for (i = 0; i < count; i++) {
966 afs_cb_interface.addr_in[i] = buffer[i];
967 #ifdef AFS_USERSPACE_IP_ADDR
968 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
969 * machines IP addresses when in the kernel (the in_ifaddr
970 * struct is not available), so we pass the info in at
971 * startup. We also pass in the subnetmask and mtu size. The
972 * subnetmask is used when setting the rank:
973 * afsi_SetServerIPRank(); and the mtu size is used when
974 * finding the best mtu size. rxi_FindIfnet() is replaced
975 * with rxi_Findcbi().
977 afs_cb_interface.subnetmask[i] =
978 (parm4 ? maskbuffer[i] : 0xffffffff);
979 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
982 rxi_setaddr(buffer[0]);
985 rx_bindhost = buffer[0];
987 rx_bindhost = htonl(INADDR_ANY);
990 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
991 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
992 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
995 afs_CheckServers(1, NULL); /* check down servers */
996 afs_CheckServers(0, NULL); /* check down servers */
1000 else if (parm == AFSOP_NFSSTATICADDR) {
1001 extern int (*nfs_rfsdisptab_v2) ();
1002 nfs_rfsdisptab_v2 = (int (*)())parm2;
1003 } else if (parm == AFSOP_NFSSTATICADDR2) {
1004 extern int (*nfs_rfsdisptab_v2) ();
1006 nfs_rfsdisptab_v2 = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
1008 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
1009 #endif /* _K64U64 */
1011 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
1012 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
1013 extern int (*afs_sblockp) ();
1014 extern void (*afs_sbunlockp) ();
1016 afs_sblockp = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
1017 afs_sbunlockp = (void (*)())((parm4 << 32) | (parm5 & 0xffffffff));
1019 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
1020 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
1021 #endif /* _K64U64 */
1023 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
1024 #endif /* AFS_SGI53_ENV */
1025 else if (parm == AFSOP_SHUTDOWN) {
1026 afs_cold_shutdown = 0;
1028 afs_cold_shutdown = 1;
1029 #ifndef AFS_DARWIN_ENV
1030 if (afs_globalVFS != 0) {
1031 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1036 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1038 vfsmount(parm2, parm3, parm4, parm5);
1039 #else /* defined(AFS_HPUX_ENV) */
1040 #if defined(KERNEL_HAVE_UERROR)
1045 #endif /* defined(AFS_HPUX_ENV) */
1046 } else if (parm == AFSOP_CLOSEWAIT) {
1047 afs_SynchronousCloses = 'S';
1048 } else if (parm == AFSOP_GETMTU) {
1050 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1051 #ifdef AFS_USERSPACE_IP_ADDR
1053 i = rxi_Findcbi(parm2);
1054 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1055 #else /* AFS_USERSPACE_IP_ADDR */
1058 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1059 mtu = (tifnp ? ifnet_mtu(tifnp) : htonl(1500));
1060 #endif /* else AFS_USERSPACE_IP_ADDR */
1061 #endif /* !AFS_SUN5_ENV */
1063 AFS_COPYOUT((caddr_t) & mtu, (caddr_t) parm3, sizeof(afs_int32),
1065 #ifdef AFS_AIX32_ENV
1066 /* this is disabled for now because I can't figure out how to get access
1067 * to these kernel variables. It's only for supporting user-mode rx
1068 * programs -- it makes a huge difference on the 220's in my testbed,
1069 * though I don't know why. The bosserver does this with /etc/no, so it's
1070 * being handled a different way for the servers right now. */
1072 static adjusted = 0;
1073 extern u_long sb_max_dflt;
1076 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1077 if (sb_max < 131072) sb_max = 131072;
1080 #endif /* AFS_AIX32_ENV */
1081 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1082 afs_uint32 mask = 0;
1083 #if !defined(AFS_SUN5_ENV)
1084 #ifdef AFS_USERSPACE_IP_ADDR
1086 i = rxi_Findcbi(parm2);
1088 mask = afs_cb_interface.subnetmask[i];
1092 #else /* AFS_USERSPACE_IP_ADDR */
1095 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1098 #endif /* else AFS_USERSPACE_IP_ADDR */
1099 #endif /* !AFS_SUN5_ENV */
1101 AFS_COPYOUT((caddr_t) & mask, (caddr_t) parm3, sizeof(afs_int32),
1104 #ifdef AFS_AFSDB_ENV
1105 else if (parm == AFSOP_AFSDB_HANDLER) {
1106 int sizeArg = (int)parm4;
1107 int kmsgLen = sizeArg & 0xffff;
1108 int cellLen = (sizeArg & 0xffff0000) >> 16;
1109 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1110 char *cellname = afs_osi_Alloc(cellLen);
1113 afs_osi_MaskUserLoop();
1115 AFS_COPYIN((afs_int32 *) parm2, cellname, cellLen, code);
1116 AFS_COPYIN((afs_int32 *) parm3, kmsg, kmsgLen, code);
1118 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1121 if (code == -2) { /* Shutting down? */
1127 AFS_COPYOUT(cellname, (char *)parm2, cellLen, code);
1128 afs_osi_Free(kmsg, kmsgLen);
1129 afs_osi_Free(cellname, cellLen);
1132 else if (parm == AFSOP_SET_DYNROOT) {
1133 code = afs_SetDynrootEnable(parm2);
1134 } else if (parm == AFSOP_SET_FAKESTAT) {
1135 afs_fakestat_enable = parm2;
1137 } else if (parm == AFSOP_SET_BACKUPTREE) {
1138 afs_bkvolpref = parm2;
1139 } else if (parm == AFSOP_SET_RXPCK) {
1140 rx_extraPackets = parm2;
1141 afscall_set_rxpck_received = 1;
1142 } else if (parm == AFSOP_SET_RXMAXMTU) {
1143 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1149 #ifdef AFS_LINUX20_ENV
1157 * Initstate in the range 0 < x < 100 are early initialization states.
1158 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1159 * the cache may be initialized.
1160 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1161 * is done after all the cache initialization has been done.
1162 * Initstate of 200 means that the volume has been looked up once, possibly
1164 * Initstate of 300 means that the volume has been *successfully* looked up.
1169 register int code = 0;
1171 AFS_STATCNT(afs_CheckInit);
1172 if (afs_initState <= 100)
1173 code = ENXIO; /* never finished init phase */
1174 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1175 while (afs_initState < 200)
1176 afs_osi_Sleep(&afs_initState);
1177 } else if (afs_initState == 200)
1178 code = ETIMEDOUT; /* didn't find root volume */
1182 int afs_shuttingdown = 0;
1186 extern short afs_brsDaemons;
1187 extern afs_int32 afs_CheckServerDaemonStarted;
1188 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1189 extern struct osi_file *afs_cacheInodep;
1191 AFS_STATCNT(afs_shutdown);
1192 if (afs_initState == 0) {
1193 afs_warn("AFS not initialized - not shutting down\n");
1197 if (afs_shuttingdown)
1199 afs_shuttingdown = 1;
1200 if (afs_cold_shutdown)
1204 afs_warn("shutting down of: CB... ");
1206 afs_termState = AFSOP_STOP_RXCALLBACK;
1207 rx_WakeupServerProcs();
1208 #ifdef AFS_AIX51_ENV
1209 shutdown_rxkernel();
1211 /* shutdown_rxkernel(); */
1212 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1213 afs_osi_Sleep(&afs_termState);
1215 afs_warn("afs... ");
1216 while (afs_termState == AFSOP_STOP_AFS) {
1217 afs_osi_CancelWait(&AFS_WaitHandler);
1218 afs_osi_Sleep(&afs_termState);
1220 if (afs_CheckServerDaemonStarted) {
1221 while (afs_termState == AFSOP_STOP_CS) {
1222 afs_osi_CancelWait(&AFS_CSWaitHandler);
1223 afs_osi_Sleep(&afs_termState);
1226 afs_warn("BkG... ");
1227 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1228 while (afs_termState == AFSOP_STOP_BKG) {
1229 afs_osi_Wakeup(&afs_brsDaemons);
1230 afs_osi_Sleep(&afs_termState);
1232 afs_warn("CTrunc... ");
1233 /* Cancel cache truncate daemon. */
1234 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1235 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1236 afs_osi_Sleep(&afs_termState);
1238 #ifdef AFS_AFSDB_ENV
1239 afs_warn("AFSDB... ");
1241 while (afs_termState == AFSOP_STOP_AFSDB)
1242 afs_osi_Sleep(&afs_termState);
1244 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1245 afs_warn("RxEvent... ");
1246 /* cancel rx event daemon */
1247 while (afs_termState == AFSOP_STOP_RXEVENT)
1248 afs_osi_Sleep(&afs_termState);
1249 #if defined(RXK_LISTENER_ENV)
1251 afs_warn("UnmaskRxkSignals... ");
1252 afs_osi_UnmaskRxkSignals();
1254 /* cancel rx listener */
1255 afs_warn("RxListener... ");
1256 osi_StopListener(); /* This closes rx_socket. */
1257 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1258 afs_warn("Sleep... ");
1259 afs_osi_Sleep(&afs_termState);
1263 afs_termState = AFSOP_STOP_COMPLETE;
1267 #ifdef AFS_AIX51_ENV
1274 shutdown_rxkernel();
1279 shutdown_bufferpackage();
1284 shutdown_vnodeops();
1285 shutdown_memcache();
1286 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)) && !defined(AFS_OSF_ENV)
1287 shutdown_exporter();
1291 /* The following hold the cm stats */
1293 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1294 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1295 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1297 afs_warn(" ALL allocated tables\n");
1299 /* Close file only after daemons which can write to it are stopped. */
1300 if (afs_cacheInodep) { /* memcache won't set this */
1301 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1302 afs_cacheInodep = 0;
1305 afs_shuttingdown = 0;
1307 return; /* Just kill daemons for now */
1311 shutdown_afstest(void)
1313 AFS_STATCNT(shutdown_afstest);
1314 afs_initState = afs_termState = afs_setTime = 0;
1315 AFS_Running = afs_CB_Running = 0;
1316 afs_CacheInit_Done = afs_Go_Done = 0;
1317 if (afs_cold_shutdown) {
1318 *afs_rootVolumeName = 0;
1323 /* In case there is a bunch of dynamically build bkg daemons to free */
1325 afs_shutdown_BKG(void)
1327 AFS_STATCNT(shutdown_BKG);