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"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
15 #include "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h"
17 #include "rx/rx_globals.h"
18 #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
21 #include "h/hashing.h"
23 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN60_ENV)
24 #include "netinet/in_var.h"
26 #endif /* !defined(UKERNEL) */
27 #ifdef AFS_LINUX22_ENV
28 #include "h/smp_lock.h"
35 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV)
36 #define AFS_MINBUFFERS 100
38 #define AFS_MINBUFFERS 50
42 afs_int32 hosts[MAXCELLHOSTS];
46 char afs_zeros[AFS_ZEROS];
47 char afs_rootVolumeName[64] = "";
48 afs_uint32 rx_bindhost;
51 ddi_taskq_t *afs_taskq;
52 krwlock_t afsifinfo_lock;
55 afs_int32 afs_initState = 0;
56 afs_int32 afs_termState = 0;
57 afs_int32 afs_setTime = 0;
58 int afs_cold_shutdown = 0;
59 char afs_SynchronousCloses = '\0';
60 static int afs_CB_Running = 0;
61 static int AFS_Running = 0;
62 static int afs_CacheInit_Done = 0;
63 static int afs_Go_Done = 0;
64 extern struct interfaceAddr afs_cb_interface;
65 static int afs_RX_Running = 0;
66 static int afs_InitSetup_done = 0;
67 afs_int32 afs_numcachefiles = -1;
68 afs_int32 afs_numfilesperdir = -1;
69 char afs_cachebasedir[1024];
71 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
72 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
73 afs_int32 afs_rx_idledead = AFS_IDLEDEADTIME;
75 static int afscall_set_rxpck_received = 0;
77 #if defined(AFS_HPUX_ENV)
78 extern int afs_vfs_mount();
79 #endif /* defined(AFS_HPUX_ENV) */
81 /* This is code which needs to be called once when the first daemon enters
82 * the client. A non-zero return means an error and AFS should not start.
85 afs_InitSetup(int preallocs)
89 if (afs_InitSetup_done)
93 /* Initialize a RW lock for the ifinfo global array */
94 rw_init(&afsifinfo_lock, NULL, RW_DRIVER, NULL);
97 afs_taskq = ddi_taskq_create(NULL, "afs_taskq", 2, TASKQ_DEFAULTPRI, 0);
99 osi_StartNetIfPoller();
104 * Set up all the AFS statistics variables. This should be done
105 * exactly once, and it should be done here, the first resource-setting
106 * routine to be called by the CM/RX.
109 #endif /* AFS_NOSTATS */
111 memset(afs_zeros, 0, AFS_ZEROS);
114 if(!afscall_set_rxpck_received)
115 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
116 code = rx_InitHost(rx_bindhost, htons(7001));
118 printf("AFS: RX failed to initialize %d).\n", code);
121 rx_SetRxDeadTime(afs_rx_deadtime);
122 /* resource init creates the services */
123 afs_ResourceInit(preallocs);
125 afs_InitSetup_done = 1;
126 afs_osi_Wakeup(&afs_InitSetup_done);
130 #if defined(AFS_DARWIN80_ENV)
131 struct afsd_thread_info {
135 afsd_thread(int *rock)
137 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
138 unsigned long parm = arg->parm;
141 case AFSOP_START_RXCALLBACK:
145 while (afs_RX_Running != 2)
146 afs_osi_Sleep(&afs_RX_Running);
147 afs_RXCallBackServer();
149 thread_terminate(current_thread());
151 case AFSOP_START_AFS:
155 while (afs_initState < AFSOP_START_AFS)
156 afs_osi_Sleep(&afs_initState);
157 afs_initState = AFSOP_START_BKG;
158 afs_osi_Wakeup(&afs_initState);
161 thread_terminate(current_thread());
163 case AFSOP_START_BKG:
166 while (afs_initState < AFSOP_START_BKG)
167 afs_osi_Sleep(&afs_initState);
168 if (afs_initState < AFSOP_GO) {
169 afs_initState = AFSOP_GO;
170 afs_osi_Wakeup(&afs_initState);
172 afs_BackgroundDaemon();
174 thread_terminate(current_thread());
176 case AFSOP_START_TRUNCDAEMON:
179 while (afs_initState < AFSOP_GO)
180 afs_osi_Sleep(&afs_initState);
181 afs_CacheTruncateDaemon();
183 thread_terminate(current_thread());
188 afs_CheckServerDaemon();
190 thread_terminate(current_thread());
192 case AFSOP_RXEVENT_DAEMON:
195 while (afs_initState < AFSOP_START_BKG)
196 afs_osi_Sleep(&afs_initState);
197 afs_rxevent_daemon();
199 thread_terminate(current_thread());
201 case AFSOP_RXLISTENER_DAEMON:
204 afs_initState = AFSOP_START_AFS;
205 afs_osi_Wakeup(&afs_initState);
207 afs_osi_Wakeup(&afs_RX_Running);
208 afs_osi_RxkRegister();
211 thread_terminate(current_thread());
214 printf("Unknown op %ld in StartDaemon()\n", (long)parm);
220 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
224 struct afsd_thread_info info;
227 if (parm == AFSOP_START_RXCALLBACK) {
230 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
234 code = afs_InitSetup(parm2);
236 rx_enablePeerRPCStats();
239 rx_enableProcessRPCStats();
243 } else if (parm == AFSOP_START_AFS) {
246 } /* other functions don't need setup in the parent */
248 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
250 /* we need to wait cause we passed stack pointers around.... */
251 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
253 thread_deallocate(thread);
258 #if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)
259 struct afsd_thread_info {
260 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
261 struct work_struct tq;
264 struct completion *complete;
268 afsd_thread(void *rock)
270 struct afsd_thread_info *arg = rock;
271 unsigned long parm = arg->parm;
272 #ifdef SYS_SETPRIORITY_EXPORTED
273 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
275 #if defined(AFS_LINUX26_ENV)
280 /* doesn't do much, since we were forked from keventd, but
281 * does call mm_release, which wakes up our parent (since it
282 * used CLONE_VFORK) */
283 #if !defined(AFS_LINUX26_ENV)
286 afs_osi_MaskSignals();
288 case AFSOP_START_RXCALLBACK:
289 sprintf(current->comm, "afs_cbstart");
291 complete(arg->complete);
293 while (afs_RX_Running != 2)
294 afs_osi_Sleep(&afs_RX_Running);
295 sprintf(current->comm, "afs_callback");
296 afs_RXCallBackServer();
298 complete_and_exit(0, 0);
300 case AFSOP_START_AFS:
301 sprintf(current->comm, "afs_afsstart");
303 complete(arg->complete);
305 while (afs_initState < AFSOP_START_AFS)
306 afs_osi_Sleep(&afs_initState);
307 afs_initState = AFSOP_START_BKG;
308 afs_osi_Wakeup(&afs_initState);
309 sprintf(current->comm, "afsd");
312 complete_and_exit(0, 0);
314 case AFSOP_START_BKG:
315 sprintf(current->comm, "afs_bkgstart");
317 complete(arg->complete);
318 while (afs_initState < AFSOP_START_BKG)
319 afs_osi_Sleep(&afs_initState);
320 if (afs_initState < AFSOP_GO) {
321 afs_initState = AFSOP_GO;
322 afs_osi_Wakeup(&afs_initState);
324 sprintf(current->comm, "afs_background");
325 afs_BackgroundDaemon();
327 complete_and_exit(0, 0);
329 case AFSOP_START_TRUNCDAEMON:
330 sprintf(current->comm, "afs_trimstart");
332 complete(arg->complete);
333 while (afs_initState < AFSOP_GO)
334 afs_osi_Sleep(&afs_initState);
335 sprintf(current->comm, "afs_cachetrim");
336 afs_CacheTruncateDaemon();
338 complete_and_exit(0, 0);
341 sprintf(current->comm, "afs_checkserver");
343 complete(arg->complete);
344 afs_CheckServerDaemon();
346 complete_and_exit(0, 0);
348 case AFSOP_RXEVENT_DAEMON:
349 sprintf(current->comm, "afs_evtstart");
350 #ifdef SYS_SETPRIORITY_EXPORTED
351 sys_setpriority(PRIO_PROCESS, 0, -10);
353 #ifdef CURRENT_INCLUDES_NICE
358 complete(arg->complete);
359 while (afs_initState < AFSOP_START_BKG)
360 afs_osi_Sleep(&afs_initState);
361 sprintf(current->comm, "afs_rxevent");
362 afs_rxevent_daemon();
364 complete_and_exit(0, 0);
366 case AFSOP_RXLISTENER_DAEMON:
367 sprintf(current->comm, "afs_lsnstart");
368 #ifdef SYS_SETPRIORITY_EXPORTED
369 sys_setpriority(PRIO_PROCESS, 0, -10);
371 #ifdef CURRENT_INCLUDES_NICE
376 complete(arg->complete);
377 afs_initState = AFSOP_START_AFS;
378 afs_osi_Wakeup(&afs_initState);
380 afs_osi_Wakeup(&afs_RX_Running);
381 afs_osi_RxkRegister();
382 sprintf(current->comm, "afs_rxlistener");
385 complete_and_exit(0, 0);
388 printf("Unknown op %ld in StartDaemon()\n", (long)parm);
395 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
396 afsd_launcher(struct work_struct *work)
398 afsd_launcher(void *rock)
401 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
402 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
405 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
406 printf("kernel_thread failed. afs startup will not complete\n");
410 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
414 DECLARE_COMPLETION(c);
415 #if defined(AFS_LINUX26_ENV)
416 #if defined(INIT_WORK_HAS_DATA)
417 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);
479 #ifdef AFS_DARWIN100_ENV
480 #define AFSKPTR(X) k ## X
482 afs_syscall_call(long parm, long parm2, long parm3,
483 long parm4, long parm5, long parm6)
485 return afs_syscall64_call(CAST_USER_ADDR_T((parm)),
486 CAST_USER_ADDR_T((parm2)),
487 CAST_USER_ADDR_T((parm3)),
488 CAST_USER_ADDR_T((parm4)),
489 CAST_USER_ADDR_T((parm5)),
490 CAST_USER_ADDR_T((parm6)));
493 #define AFSKPTR(X) ((caddr_t)X)
496 #ifdef AFS_DARWIN100_ENV
497 afs_syscall64_call(user_addr_t kparm, user_addr_t kparm2, user_addr_t kparm3,
498 user_addr_t kparm4, user_addr_t kparm5, user_addr_t kparm6)
500 afs_syscall_call(long parm, long parm2, long parm3,
501 long parm4, long parm5, long parm6)
505 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
507 #else /* AFS_SGI61_ENV */
509 #endif /* AFS_SGI61_ENV */
510 #ifdef AFS_DARWIN100_ENV
511 /* AFSKPTR macro relies on this name format/mapping */
512 afs_uint32 parm = (afs_uint32)kparm;
513 afs_uint32 parm2 = (afs_uint32)kparm2;
514 afs_uint32 parm3 = (afs_uint32)kparm3;
515 afs_uint32 parm4 = (afs_uint32)kparm4;
516 afs_uint32 parm5 = (afs_uint32)kparm5;
517 afs_uint32 parm6 = (afs_uint32)kparm6;
520 AFS_STATCNT(afs_syscall_call);
527 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
528 /* only root can run this code */
529 #if defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
530 #if defined(KERNEL_HAVE_UERROR)
538 #ifdef AFS_DARWIN80_ENV
544 #ifdef AFS_DARWIN80_ENV
547 #if ((defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)) || defined(AFS_DARWIN80_ENV)) && !defined(UKERNEL)
548 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
549 || parm == AFSOP_RXLISTENER_DAEMON) {
550 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
552 #else /* !(AFS_LINUX24_ENV && !UKERNEL) */
553 if (parm == AFSOP_START_RXCALLBACK) {
557 #ifndef RXK_LISTENER_ENV
558 code = afs_InitSetup(parm2);
560 #endif /* !RXK_LISTENER_ENV */
562 #ifdef RXK_LISTENER_ENV
563 while (afs_RX_Running != 2)
564 afs_osi_Sleep(&afs_RX_Running);
565 #else /* !RXK_LISTENER_ENV */
566 afs_initState = AFSOP_START_AFS;
567 afs_osi_Wakeup(&afs_initState);
568 #endif /* RXK_LISTENER_ENV */
570 afs_RXCallBackServer();
575 exit(CLD_EXITED, code);
576 #endif /* AFS_SGI_ENV */
578 #ifdef RXK_LISTENER_ENV
579 else if (parm == AFSOP_RXLISTENER_DAEMON) {
583 code = afs_InitSetup(parm2);
585 rx_enablePeerRPCStats();
588 rx_enableProcessRPCStats();
591 afs_initState = AFSOP_START_AFS;
592 afs_osi_Wakeup(&afs_initState);
595 afs_osi_Wakeup(&afs_RX_Running);
597 afs_osi_RxkRegister();
598 #endif /* !UKERNEL */
604 exit(CLD_EXITED, code);
605 #endif /* AFS_SGI_ENV */
607 #endif /* RXK_LISTENER_ENV */
608 else if (parm == AFSOP_START_AFS) {
613 while (afs_initState < AFSOP_START_AFS)
614 afs_osi_Sleep(&afs_initState);
616 afs_initState = AFSOP_START_BKG;
617 afs_osi_Wakeup(&afs_initState);
624 #endif /* AFS_SGI_ENV */
625 } else if (parm == AFSOP_START_CS) {
627 afs_CheckServerDaemon();
632 #endif /* AFS_SGI_ENV */
633 } else if (parm == AFSOP_START_BKG) {
634 while (afs_initState < AFSOP_START_BKG)
635 afs_osi_Sleep(&afs_initState);
636 if (afs_initState < AFSOP_GO) {
637 afs_initState = AFSOP_GO;
638 afs_osi_Wakeup(&afs_initState);
640 /* start the bkg daemon */
644 afs_BioDaemon(parm2);
646 #endif /* AFS_AIX32_ENV */
647 afs_BackgroundDaemon();
652 #endif /* AFS_SGI_ENV */
653 } else if (parm == AFSOP_START_TRUNCDAEMON) {
654 while (afs_initState < AFSOP_GO)
655 afs_osi_Sleep(&afs_initState);
656 /* start the bkg daemon */
658 afs_CacheTruncateDaemon();
663 #endif /* AFS_SGI_ENV */
665 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
666 else if (parm == AFSOP_RXEVENT_DAEMON) {
667 while (afs_initState < AFSOP_START_BKG)
668 afs_osi_Sleep(&afs_initState);
670 afs_rxevent_daemon();
675 #endif /* AFS_SGI_ENV */
677 #endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
678 #endif /* AFS_LINUX24_ENV && !UKERNEL */
679 else if (parm == AFSOP_BASIC_INIT) {
682 while (!afs_InitSetup_done)
683 afs_osi_Sleep(&afs_InitSetup_done);
685 #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)
686 temp = AFS_MINBUFFERS; /* Should fix this soon */
688 /* number of 2k buffers we could get from all of the buffer space */
689 temp = ((afs_bufferpages * NBPG) >> 11);
690 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
691 if (temp < AFS_MINBUFFERS)
692 temp = AFS_MINBUFFERS; /* though we really should have this many */
695 afs_rootFid.Fid.Volume = 0;
697 } else if (parm == AFSOP_BUCKETPCT) {
698 /* need to enable this now, will disable again before GO
699 if we don't have 100% */
709 } else if (parm == AFSOP_ADDCELL) {
710 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
711 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
712 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
713 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
715 code = afs_InitDynroot();
717 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
721 if (parm4 > sizeof(tcell->cellName))
724 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)tcell->cellName, parm4, code);
726 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
730 afs_osi_Free(tcell, sizeof(struct afsop_cell));
731 } else if (parm == AFSOP_ADDCELL2) {
732 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
733 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
734 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
737 code = afs_InitDynroot();
740 /* wait for basic init - XXX can't find any reason we need this? */
741 while (afs_initState < AFSOP_START_BKG)
742 afs_osi_Sleep(&afs_initState);
745 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
749 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
753 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
757 cflags |= CLinkedCell;
762 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
766 afs_osi_Free(tcell, sizeof(struct afsop_cell));
767 osi_FreeSmallSpace(tbuffer);
768 osi_FreeSmallSpace(tbuffer1);
769 } else if (parm == AFSOP_ADDCELLALIAS) {
772 * parm2 is the alias name
773 * parm3 is the real cell name
775 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
776 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
778 code = afs_InitDynroot();
780 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
784 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
787 afs_NewCellAlias(aliasName, cellName);
788 osi_FreeSmallSpace(aliasName);
789 osi_FreeSmallSpace(cellName);
790 } else if (parm == AFSOP_SET_THISCELL) {
793 * parm2 is the primary cell name
795 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
797 code = afs_InitDynroot();
799 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
802 afs_SetPrimaryCell(cell);
803 osi_FreeSmallSpace(cell);
804 } else if (parm == AFSOP_CACHEINIT) {
805 struct afs_cacheParams cparms;
807 if (afs_CacheInit_Done)
810 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
812 #if defined(KERNEL_HAVE_UERROR)
818 afs_CacheInit_Done = 1;
819 code = afs_icl_InitLogs();
820 afs_setTime = cparms.setTimeFlag;
823 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
824 cparms.cacheBlocks, cparms.cacheDcaches,
825 cparms.cacheVolumes, cparms.chunkSize,
826 cparms.memCacheFlag, cparms.inodes, cparms.users,
827 cparms.dynamic_vcaches);
829 } else if (parm == AFSOP_CACHEINODE) {
830 ino_t ainode = parm2;
831 /* wait for basic init */
832 while (afs_initState < AFSOP_START_BKG)
833 afs_osi_Sleep(&afs_initState);
835 #ifdef AFS_DARWIN80_ENV
840 ainode = (ainode << 32) | (parm3 & 0xffffffff);
842 code = afs_InitCacheFile(NULL, ainode);
843 #ifdef AFS_DARWIN80_ENV
846 } else if (parm == AFSOP_CACHEDIRS) {
847 afs_numfilesperdir = parm2;
848 afs_osi_Wakeup(&afs_initState);
849 } else if (parm == AFSOP_CACHEFILES) {
850 afs_numcachefiles = parm2;
851 afs_osi_Wakeup(&afs_initState);
852 } else if (parm == AFSOP_ROOTVOLUME) {
853 /* wait for basic init */
854 while (afs_initState < AFSOP_START_BKG)
855 afs_osi_Sleep(&afs_initState);
858 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
859 sizeof(afs_rootVolumeName), &bufferSize, code);
860 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
863 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
864 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG
865 || parm == AFSOP_CELLINFO || parm == AFSOP_CACHEBASEDIR) {
866 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
869 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
872 osi_FreeSmallSpace(tbuffer);
876 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
877 /* We have the cache dir copied in. Call the cache init routine */
878 #ifdef AFS_DARWIN80_ENV
881 if (parm == AFSOP_CACHEBASEDIR) {
882 strncpy(afs_cachebasedir, tbuffer, 1024);
883 afs_cachebasedir[1023] = '\0';
884 afs_osi_Wakeup(&afs_initState);
885 } else if (parm == AFSOP_CACHEFILE) {
886 wait_for_cachedefs();
887 code = afs_InitCacheFile(tbuffer, 0);
888 } else if (parm == AFSOP_CACHEINFO) {
889 wait_for_cachedefs();
890 code = afs_InitCacheInfo(tbuffer);
891 } else if (parm == AFSOP_VOLUMEINFO) {
892 wait_for_cachedefs();
893 code = afs_InitVolumeInfo(tbuffer);
894 } else if (parm == AFSOP_CELLINFO) {
895 wait_for_cachedefs();
896 code = afs_InitCellInfo(tbuffer);
898 #ifdef AFS_DARWIN80_ENV
902 osi_FreeSmallSpace(tbuffer);
903 } else if (parm == AFSOP_GO) {
904 #ifdef AFS_CACHE_VNODE_PATH
905 if (cacheDiskType != AFS_FCACHE_TYPE_MEM) {
908 wait_for_cachedefs();
910 #ifdef AFS_DARWIN80_ENV
913 if ((afs_numcachefiles > 0) && (afs_numfilesperdir > 0) &&
914 (afs_cachebasedir[0] == '/')) {
915 for (dummy = 0; dummy < afs_numcachefiles; dummy++) {
916 code = afs_InitCacheFile(NULL, dummy);
919 #ifdef AFS_DARWIN80_ENV
924 /* the generic initialization calls come here. One parameter: should we do the
925 * set-time operation on this workstation */
929 while (afs_initState < AFSOP_GO)
930 afs_osi_Sleep(&afs_initState);
933 if (afs_tpct1 + afs_tpct2 != 100) {
940 afs_osi_Wakeup(&afs_initState);
941 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
942 afs_nfsclient_init();
944 afs_uuid_create(&afs_cb_interface.uuid);
945 printf("found %d non-empty cache files (%d%%).\n",
946 afs_stats_cmperf.cacheFilesReused,
947 (100 * afs_stats_cmperf.cacheFilesReused) /
948 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
949 cacheNumEntries : 1));
950 } else if (parm == AFSOP_ADVISEADDR) {
951 /* pass in the host address to the rx package */
955 afs_int32 count = parm2;
957 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
958 afs_int32 *maskbuffer =
959 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
960 afs_int32 *mtubuffer =
961 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
964 /* This is a refresh */
965 if (count & 0x40000000) {
966 count &= ~0x40000000;
967 /* Can't bind after we start. Fix? */
968 count &= ~0x80000000;
972 /* Bind, but only if there's only one address configured */
973 if ( count & 0x80000000) {
974 count &= ~0x80000000;
979 if (count > AFS_MAX_INTERFACE_ADDR) {
981 count = AFS_MAX_INTERFACE_ADDR;
984 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
987 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
988 count * sizeof(afs_int32), code);
990 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
991 count * sizeof(afs_int32), code);
994 afs_cb_interface.numberOfInterfaces = count;
995 for (i = 0; i < count; i++) {
996 afs_cb_interface.addr_in[i] = buffer[i];
997 #ifdef AFS_USERSPACE_IP_ADDR
998 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
999 * machines IP addresses when in the kernel (the in_ifaddr
1000 * struct is not available), so we pass the info in at
1001 * startup. We also pass in the subnetmask and mtu size. The
1002 * subnetmask is used when setting the rank:
1003 * afsi_SetServerIPRank(); and the mtu size is used when
1004 * finding the best mtu size. rxi_FindIfnet() is replaced
1005 * with rxi_Findcbi().
1007 afs_cb_interface.subnetmask[i] =
1008 (parm4 ? maskbuffer[i] : 0xffffffff);
1009 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1012 rxi_setaddr(buffer[0]);
1015 rx_bindhost = buffer[0];
1017 rx_bindhost = htonl(INADDR_ANY);
1023 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1024 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1025 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1028 afs_CheckServers(1, NULL); /* check down servers */
1029 afs_CheckServers(0, NULL); /* check down servers */
1032 #ifdef AFS_SGI53_ENV
1033 else if (parm == AFSOP_NFSSTATICADDR) {
1034 extern int (*nfs_rfsdisptab_v2) ();
1035 nfs_rfsdisptab_v2 = (int (*)())parm2;
1036 } else if (parm == AFSOP_NFSSTATICADDR2) {
1037 extern int (*nfs_rfsdisptab_v2) ();
1039 nfs_rfsdisptab_v2 = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
1041 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
1042 #endif /* _K64U64 */
1044 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
1045 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
1046 extern int (*afs_sblockp) ();
1047 extern void (*afs_sbunlockp) ();
1049 afs_sblockp = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
1050 afs_sbunlockp = (void (*)())((parm4 << 32) | (parm5 & 0xffffffff));
1052 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
1053 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
1054 #endif /* _K64U64 */
1056 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
1057 #endif /* AFS_SGI53_ENV */
1058 else if (parm == AFSOP_SHUTDOWN) {
1059 afs_cold_shutdown = 0;
1061 afs_cold_shutdown = 1;
1062 #ifndef AFS_DARWIN_ENV
1063 if (afs_globalVFS != 0) {
1064 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1069 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1071 vfsmount(parm2, parm3, parm4, parm5);
1072 #else /* defined(AFS_HPUX_ENV) */
1073 #if defined(KERNEL_HAVE_UERROR)
1078 #endif /* defined(AFS_HPUX_ENV) */
1079 } else if (parm == AFSOP_CLOSEWAIT) {
1080 afs_SynchronousCloses = 'S';
1081 } else if (parm == AFSOP_GETMTU) {
1083 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1084 #ifdef AFS_USERSPACE_IP_ADDR
1086 i = rxi_Findcbi(parm2);
1087 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1088 #else /* AFS_USERSPACE_IP_ADDR */
1091 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1092 mtu = (tifnp ? ifnet_mtu(tifnp) : htonl(1500));
1093 #endif /* else AFS_USERSPACE_IP_ADDR */
1094 #endif /* !AFS_SUN5_ENV */
1096 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1097 sizeof(afs_int32), code);
1098 #ifdef AFS_AIX32_ENV
1099 /* this is disabled for now because I can't figure out how to get access
1100 * to these kernel variables. It's only for supporting user-mode rx
1101 * programs -- it makes a huge difference on the 220's in my testbed,
1102 * though I don't know why. The bosserver does this with /etc/no, so it's
1103 * being handled a different way for the servers right now. */
1105 static adjusted = 0;
1106 extern u_long sb_max_dflt;
1109 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1110 if (sb_max < 131072) sb_max = 131072;
1113 #endif /* AFS_AIX32_ENV */
1114 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1115 afs_uint32 mask = 0;
1116 #if !defined(AFS_SUN5_ENV)
1117 #ifdef AFS_USERSPACE_IP_ADDR
1119 i = rxi_Findcbi(parm2);
1121 mask = afs_cb_interface.subnetmask[i];
1125 #else /* AFS_USERSPACE_IP_ADDR */
1128 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1131 #endif /* else AFS_USERSPACE_IP_ADDR */
1132 #endif /* !AFS_SUN5_ENV */
1134 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1135 sizeof(afs_int32), code);
1137 #ifdef AFS_AFSDB_ENV
1138 else if (parm == AFSOP_AFSDB_HANDLER) {
1139 int sizeArg = (int)parm4;
1140 int kmsgLen = sizeArg & 0xffff;
1141 int cellLen = (sizeArg & 0xffff0000) >> 16;
1142 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1143 char *cellname = afs_osi_Alloc(cellLen);
1146 afs_osi_MaskUserLoop();
1148 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1149 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1151 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1154 if (code == -2) { /* Shutting down? */
1160 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1161 afs_osi_Free(kmsg, kmsgLen);
1162 afs_osi_Free(cellname, cellLen);
1165 else if (parm == AFSOP_SET_DYNROOT) {
1166 code = afs_SetDynrootEnable(parm2);
1167 } else if (parm == AFSOP_SET_FAKESTAT) {
1168 afs_fakestat_enable = parm2;
1170 } else if (parm == AFSOP_SET_BACKUPTREE) {
1171 afs_bkvolpref = parm2;
1172 } else if (parm == AFSOP_SET_RXPCK) {
1173 rx_extraPackets = parm2;
1174 afscall_set_rxpck_received = 1;
1175 } else if (parm == AFSOP_SET_RXMAXMTU) {
1176 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1183 #ifdef AFS_LINUX20_ENV
1191 * Initstate in the range 0 < x < 100 are early initialization states.
1192 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1193 * the cache may be initialized.
1194 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1195 * is done after all the cache initialization has been done.
1196 * Initstate of 200 means that the volume has been looked up once, possibly
1198 * Initstate of 300 means that the volume has been *successfully* looked up.
1203 register int code = 0;
1205 AFS_STATCNT(afs_CheckInit);
1206 if (afs_initState <= 100)
1207 code = ENXIO; /* never finished init phase */
1208 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1209 while (afs_initState < 200)
1210 afs_osi_Sleep(&afs_initState);
1211 } else if (afs_initState == 200)
1212 code = ETIMEDOUT; /* didn't find root volume */
1216 int afs_shuttingdown = 0;
1220 extern short afs_brsDaemons;
1221 extern afs_int32 afs_CheckServerDaemonStarted;
1222 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1223 extern struct osi_file *afs_cacheInodep;
1225 AFS_STATCNT(afs_shutdown);
1226 if (afs_initState == 0) {
1227 afs_warn("AFS not initialized - not shutting down\n");
1231 if (afs_shuttingdown)
1233 afs_shuttingdown = 1;
1234 if (afs_cold_shutdown)
1238 afs_warn("shutting down of: CB... ");
1240 afs_termState = AFSOP_STOP_RXCALLBACK;
1241 rx_WakeupServerProcs();
1242 #ifdef AFS_AIX51_ENV
1243 shutdown_rxkernel();
1245 /* shutdown_rxkernel(); */
1246 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1247 afs_osi_Sleep(&afs_termState);
1249 afs_warn("afs... ");
1250 while (afs_termState == AFSOP_STOP_AFS) {
1251 afs_osi_CancelWait(&AFS_WaitHandler);
1252 afs_osi_Sleep(&afs_termState);
1254 if (afs_CheckServerDaemonStarted) {
1255 while (afs_termState == AFSOP_STOP_CS) {
1256 afs_osi_CancelWait(&AFS_CSWaitHandler);
1257 afs_osi_Sleep(&afs_termState);
1260 afs_warn("BkG... ");
1261 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1262 while (afs_termState == AFSOP_STOP_BKG) {
1263 afs_osi_Wakeup(&afs_brsDaemons);
1264 afs_osi_Sleep(&afs_termState);
1266 afs_warn("CTrunc... ");
1267 /* Cancel cache truncate daemon. */
1268 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1269 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1270 afs_osi_Sleep(&afs_termState);
1272 #ifdef AFS_AFSDB_ENV
1273 afs_warn("AFSDB... ");
1275 while (afs_termState == AFSOP_STOP_AFSDB)
1276 afs_osi_Sleep(&afs_termState);
1278 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1279 afs_warn("RxEvent... ");
1280 /* cancel rx event daemon */
1281 while (afs_termState == AFSOP_STOP_RXEVENT)
1282 afs_osi_Sleep(&afs_termState);
1283 #if defined(RXK_LISTENER_ENV)
1285 afs_warn("UnmaskRxkSignals... ");
1286 afs_osi_UnmaskRxkSignals();
1288 /* cancel rx listener */
1289 afs_warn("RxListener... ");
1290 osi_StopListener(); /* This closes rx_socket. */
1291 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1292 afs_warn("Sleep... ");
1293 afs_osi_Sleep(&afs_termState);
1297 afs_termState = AFSOP_STOP_COMPLETE;
1301 #ifdef AFS_AIX51_ENV
1308 shutdown_rxkernel();
1313 shutdown_bufferpackage();
1318 shutdown_vnodeops();
1319 shutdown_memcache();
1320 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)) && !defined(AFS_OSF_ENV)
1321 shutdown_exporter();
1325 /* The following hold the cm stats */
1327 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1328 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1329 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1331 afs_warn(" ALL allocated tables\n");
1333 /* Close file only after daemons which can write to it are stopped. */
1334 if (afs_cacheInodep) { /* memcache won't set this */
1335 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1336 afs_cacheInodep = 0;
1339 afs_shuttingdown = 0;
1341 return; /* Just kill daemons for now */
1345 shutdown_afstest(void)
1347 AFS_STATCNT(shutdown_afstest);
1348 afs_initState = afs_termState = afs_setTime = 0;
1349 AFS_Running = afs_CB_Running = 0;
1350 afs_CacheInit_Done = afs_Go_Done = 0;
1351 if (afs_cold_shutdown) {
1352 *afs_rootVolumeName = 0;
1357 /* In case there is a bunch of dynamically build bkg daemons to free */
1359 afs_shutdown_BKG(void)
1361 AFS_STATCNT(shutdown_BKG);