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"
13 #if defined(HAVE_LINUX_KTHREAD_RUN) && !defined(UKERNEL)
14 # include "h/kthread.h"
17 #include "afs/sysincludes.h" /* Standard vendor system headers */
18 #include "afsincludes.h" /* Afs-based standard headers */
19 #include "afs/afs_stats.h"
20 #include "rx/rx_globals.h"
22 # if !defined(AFS_LINUX20_ENV)
25 # include "h/hashing.h"
27 # if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN_ENV)
28 # include "netinet/in_var.h"
31 #endif /* !defined(UKERNEL) */
36 #include <hcrypto/rand.h>
38 /* No hckernel-specific header for this prototype. */
40 extern void init_hckernel_mutex(void);
43 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV)
44 #define AFS_MINBUFFERS 100
46 #define AFS_MINBUFFERS 50
49 #if (defined(AFS_SUN5_ENV) || (defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)) || defined(AFS_DARWIN80_ENV)) && !defined(UKERNEL)
50 /* If AFS_DAEMONOP_ENV is defined, it indicates we run "daemon" AFS syscalls by
51 * spawning a kernel thread to do the work, instead of running them in the
53 # define AFS_DAEMONOP_ENV
57 afs_int32 hosts[AFS_MAXCELLHOSTS];
61 char afs_zeros[AFS_ZEROS];
62 char afs_rootVolumeName[64] = "";
63 afs_uint32 rx_bindhost;
66 ddi_taskq_t *afs_taskq;
67 krwlock_t afsifinfo_lock;
70 afs_int32 afs_initState = 0;
71 afs_int32 afs_termState = 0;
72 int afs_cold_shutdown = 0;
73 char afs_SynchronousCloses = '\0';
74 static int afs_CB_Running = 0;
75 static int AFS_Running = 0;
76 static int afs_CacheInit_Done = 0;
77 static int afs_Go_Done = 0;
78 extern struct interfaceAddr afs_cb_interface;
79 #ifdef RXK_LISTENER_ENV
80 static int afs_RX_Running = 0;
82 static int afs_InitSetup_done = 0;
83 afs_int32 afs_numcachefiles = -1;
84 afs_int32 afs_numfilesperdir = -1;
85 char afs_cachebasedir[1024];
86 afs_int32 afs_rmtsys_enable = 0;
88 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
89 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
90 afs_int32 afs_rx_idledead = AFS_IDLEDEADTIME;
91 afs_int32 afs_rx_idledead_rep = AFS_IDLEDEADTIME_REP;
93 static int afscall_set_rxpck_received = 0;
95 #if defined(AFS_HPUX_ENV)
96 extern int afs_vfs_mount();
97 #endif /* defined(AFS_HPUX_ENV) */
99 /* This is code which needs to be called once when the first daemon enters
100 * the client. A non-zero return means an error and AFS should not start.
103 afs_InitSetup(int preallocs)
107 if (afs_InitSetup_done)
110 /* Initialize a lock for the kernel hcrypto bits. */
112 init_hckernel_mutex();
115 #ifdef AFS_SUN510_ENV
116 /* Initialize a RW lock for the ifinfo global array */
117 rw_init(&afsifinfo_lock, NULL, RW_DRIVER, NULL);
120 afs_taskq = ddi_taskq_create(NULL, "afs_taskq", 2, TASKQ_DEFAULTPRI, 0);
122 osi_StartNetIfPoller();
127 * Set up all the AFS statistics variables. This should be done
128 * exactly once, and it should be done here, the first resource-setting
129 * routine to be called by the CM/RX.
132 #endif /* AFS_NOSTATS */
134 memset(afs_zeros, 0, AFS_ZEROS);
136 rx_SetBusyChannelError(1); /* turn on busy call error reporting */
139 if(!afscall_set_rxpck_received)
140 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
141 code = rx_InitHost(rx_bindhost, htons(7001));
143 afs_warn("AFS: RX failed to initialize %d).\n", code);
146 rx_SetRxDeadTime(afs_rx_deadtime);
147 /* resource init creates the services */
148 afs_ResourceInit(preallocs);
150 afs_InitSetup_done = 1;
151 afs_osi_Wakeup(&afs_InitSetup_done);
156 #ifdef AFS_DAEMONOP_ENV
158 daemonOp_common(long parm, long parm2, long parm3, long parm4, long parm5,
162 if (parm == AFSOP_START_RXCALLBACK) {
165 # ifdef RXK_LISTENER_ENV
166 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
171 code = afs_InitSetup(parm2);
173 rx_enablePeerRPCStats();
176 rx_enableProcessRPCStats();
180 } else if (parm == AFSOP_START_AFS) {
183 } /* other functions don't need setup in the parent */
186 #endif /* AFS_DAEMONOP_ENV */
188 #if defined(AFS_DARWIN80_ENV)
189 struct afsd_thread_info {
193 afsd_thread(int *rock)
195 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
196 unsigned long parm = arg->parm;
199 case AFSOP_START_RXCALLBACK:
203 #ifndef RXK_LISTENER_ENV
204 afs_initState = AFSOP_START_AFS;
205 afs_osi_Wakeup(&afs_initState);
207 while (afs_RX_Running != 2)
208 afs_osi_Sleep(&afs_RX_Running);
210 afs_RXCallBackServer();
212 thread_terminate(current_thread());
214 case AFSOP_START_AFS:
218 while (afs_initState < AFSOP_START_AFS)
219 afs_osi_Sleep(&afs_initState);
220 afs_initState = AFSOP_START_BKG;
221 afs_osi_Wakeup(&afs_initState);
224 thread_terminate(current_thread());
226 case AFSOP_START_BKG:
227 afs_warn("Install matching afsd! Old background daemons not supported.\n");
228 thread_terminate(current_thread());
230 case AFSOP_START_TRUNCDAEMON:
233 while (afs_initState < AFSOP_GO)
234 afs_osi_Sleep(&afs_initState);
235 afs_CacheTruncateDaemon();
237 thread_terminate(current_thread());
242 afs_CheckServerDaemon();
244 thread_terminate(current_thread());
246 case AFSOP_RXEVENT_DAEMON:
249 while (afs_initState < AFSOP_START_BKG)
250 afs_osi_Sleep(&afs_initState);
251 afs_rxevent_daemon();
253 thread_terminate(current_thread());
255 #ifdef RXK_LISTENER_ENV
256 case AFSOP_RXLISTENER_DAEMON:
259 afs_initState = AFSOP_START_AFS;
260 afs_osi_Wakeup(&afs_initState);
262 afs_osi_Wakeup(&afs_RX_Running);
263 afs_osi_RxkRegister();
266 thread_terminate(current_thread());
270 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
276 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
279 struct afsd_thread_info info;
281 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
285 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
287 /* we need to wait cause we passed stack pointers around.... */
288 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
290 thread_deallocate(thread);
295 #if defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)
296 struct afsd_thread_info {
297 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
298 struct work_struct tq;
301 struct completion *complete;
305 afsd_thread(void *rock)
307 struct afsd_thread_info *arg = rock;
308 unsigned long parm = arg->parm;
309 # ifdef SYS_SETPRIORITY_EXPORTED
310 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
312 # if !defined(HAVE_LINUX_KTHREAD_RUN)
313 # if defined(AFS_LINUX26_ENV)
318 # endif /* !HAVE_LINUX_KTHREAD_RUN */
319 /* doesn't do much, since we were forked from keventd, but
320 * does call mm_release, which wakes up our parent (since it
321 * used CLONE_VFORK) */
322 # if !defined(AFS_LINUX26_ENV)
325 afs_osi_MaskSignals();
327 case AFSOP_START_RXCALLBACK:
328 sprintf(current->comm, "afs_cbstart");
330 complete(arg->complete);
332 #if !defined(RXK_LISTENER_ENV)
333 afs_initState = AFSOP_START_AFS;
334 afs_osi_Wakeup(&afs_initState);
336 while (afs_RX_Running != 2)
337 afs_osi_Sleep(&afs_RX_Running);
339 sprintf(current->comm, "afs_callback");
340 afs_RXCallBackServer();
342 complete_and_exit(0, 0);
344 case AFSOP_START_AFS:
345 sprintf(current->comm, "afs_afsstart");
347 complete(arg->complete);
349 while (afs_initState < AFSOP_START_AFS)
350 afs_osi_Sleep(&afs_initState);
351 afs_initState = AFSOP_START_BKG;
352 afs_osi_Wakeup(&afs_initState);
353 sprintf(current->comm, "afsd");
356 complete_and_exit(0, 0);
358 case AFSOP_START_BKG:
360 afs_warn("Install matching afsd! Old background daemons not supported.\n");
362 sprintf(current->comm, "afs_bkgstart");
364 complete(arg->complete);
365 while (afs_initState < AFSOP_START_BKG)
366 afs_osi_Sleep(&afs_initState);
367 if (afs_initState < AFSOP_GO) {
368 afs_initState = AFSOP_GO;
369 afs_osi_Wakeup(&afs_initState);
371 sprintf(current->comm, "afs_background");
372 afs_BackgroundDaemon();
375 complete_and_exit(0, 0);
377 case AFSOP_START_TRUNCDAEMON:
378 sprintf(current->comm, "afs_trimstart");
380 complete(arg->complete);
381 while (afs_initState < AFSOP_GO)
382 afs_osi_Sleep(&afs_initState);
383 sprintf(current->comm, "afs_cachetrim");
384 afs_CacheTruncateDaemon();
386 complete_and_exit(0, 0);
389 sprintf(current->comm, "afs_checkserver");
391 complete(arg->complete);
392 afs_CheckServerDaemon();
394 complete_and_exit(0, 0);
396 case AFSOP_RXEVENT_DAEMON:
397 sprintf(current->comm, "afs_evtstart");
398 # ifdef SYS_SETPRIORITY_EXPORTED
399 sys_setpriority(PRIO_PROCESS, 0, -10);
401 # ifdef CURRENT_INCLUDES_NICE
406 complete(arg->complete);
407 while (afs_initState < AFSOP_START_BKG)
408 afs_osi_Sleep(&afs_initState);
409 sprintf(current->comm, "afs_rxevent");
410 afs_rxevent_daemon();
412 complete_and_exit(0, 0);
414 #ifdef RXK_LISTENER_ENV
415 case AFSOP_RXLISTENER_DAEMON:
416 sprintf(current->comm, "afs_lsnstart");
417 # ifdef SYS_SETPRIORITY_EXPORTED
418 sys_setpriority(PRIO_PROCESS, 0, -10);
420 # ifdef CURRENT_INCLUDES_NICE
425 complete(arg->complete);
426 afs_initState = AFSOP_START_AFS;
427 afs_osi_Wakeup(&afs_initState);
429 afs_osi_Wakeup(&afs_RX_Running);
430 afs_osi_RxkRegister();
431 sprintf(current->comm, "afs_rxlistener");
434 complete_and_exit(0, 0);
438 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
445 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
446 afsd_launcher(struct work_struct *work)
448 afsd_launcher(void *rock)
451 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
452 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
455 # if defined(HAVE_LINUX_KTHREAD_RUN)
456 if (IS_ERR(kthread_run(afsd_thread, (void *)rock, "afsd"))) {
457 afs_warn("kthread_run failed; afs startup will not complete\n");
459 # else /* !HAVE_LINUX_KTHREAD_RUN */
460 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
461 afs_warn("kernel_thread failed. afs startup will not complete\n");
462 # endif /* !HAVE_LINUX_KTHREAD_RUN */
466 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
469 DECLARE_COMPLETION(c);
470 # if defined(AFS_LINUX26_ENV)
471 # if defined(INIT_WORK_HAS_DATA)
472 struct work_struct tq;
477 struct afsd_thread_info info;
478 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
483 # if defined(AFS_LINUX26_ENV)
484 # if !defined(INIT_WORK_HAS_DATA)
485 INIT_WORK(&info.tq, afsd_launcher);
486 schedule_work(&info.tq);
488 INIT_WORK(&tq, afsd_launcher, &info);
493 INIT_LIST_HEAD(&tq.list);
494 tq.routine = afsd_launcher;
499 /* we need to wait cause we passed stack pointers around.... */
500 wait_for_completion(&c);
506 struct afs_daemonop_args {
512 afsd_thread(struct afs_daemonop_args *args)
514 long parm = args->parm;
517 cv_signal(&args->cv);
520 case AFSOP_START_RXCALLBACK:
524 while (afs_RX_Running != 2)
525 afs_osi_Sleep(&afs_RX_Running);
526 afs_RXCallBackServer();
529 case AFSOP_START_AFS:
533 while (afs_initState < AFSOP_START_AFS)
534 afs_osi_Sleep(&afs_initState);
535 afs_initState = AFSOP_START_BKG;
536 afs_osi_Wakeup(&afs_initState);
540 case AFSOP_START_BKG:
541 while (afs_initState < AFSOP_START_BKG)
542 afs_osi_Sleep(&afs_initState);
543 if (afs_initState < AFSOP_GO) {
544 afs_initState = AFSOP_GO;
545 afs_osi_Wakeup(&afs_initState);
547 afs_BackgroundDaemon();
550 case AFSOP_START_TRUNCDAEMON:
551 while (afs_initState < AFSOP_GO)
552 afs_osi_Sleep(&afs_initState);
553 afs_CacheTruncateDaemon();
557 afs_CheckServerDaemon();
560 case AFSOP_RXEVENT_DAEMON:
561 while (afs_initState < AFSOP_START_BKG)
562 afs_osi_Sleep(&afs_initState);
563 afs_rxevent_daemon();
566 case AFSOP_RXLISTENER_DAEMON:
567 afs_initState = AFSOP_START_AFS;
568 afs_osi_Wakeup(&afs_initState);
570 afs_osi_Wakeup(&afs_RX_Running);
571 afs_osi_RxkRegister();
577 afs_warn("Unknown op %ld in afsd_thread()\n", parm);
586 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
589 struct afs_daemonop_args args;
591 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
597 cv_init(&args.cv, "AFS DaemonOp cond var", CV_DEFAULT, NULL);
599 if (thread_create(NULL, 0, afsd_thread, &args, 0, &p0, TS_RUN,
600 minclsyspri) == NULL) {
602 afs_warn("thread_create failed: AFS startup will not complete\n");
605 /* we passed &args to the new thread, which is on the stack. wait until
606 * it has read the arguments so it doesn't try to read the args after we
608 cv_wait(&args.cv, &afs_global_lock);
610 cv_destroy(&args.cv);
612 #endif /* AFS_SUN5_ENV */
614 #ifdef AFS_DARWIN100_ENV
615 # define AFSKPTR(X) k ## X
617 afs_syscall_call(long parm, long parm2, long parm3,
618 long parm4, long parm5, long parm6)
620 return afs_syscall64_call(CAST_USER_ADDR_T((parm)),
621 CAST_USER_ADDR_T((parm2)),
622 CAST_USER_ADDR_T((parm3)),
623 CAST_USER_ADDR_T((parm4)),
624 CAST_USER_ADDR_T((parm5)),
625 CAST_USER_ADDR_T((parm6)));
628 # define AFSKPTR(X) ((caddr_t)X)
631 #ifdef AFS_DARWIN100_ENV
632 afs_syscall64_call(user_addr_t kparm, user_addr_t kparm2, user_addr_t kparm3,
633 user_addr_t kparm4, user_addr_t kparm5, user_addr_t kparm6)
635 afs_syscall_call(long parm, long parm2, long parm3,
636 long parm4, long parm5, long parm6)
640 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
642 #else /* AFS_SGI61_ENV */
644 #endif /* AFS_SGI61_ENV */
645 #ifdef AFS_DARWIN100_ENV
646 /* AFSKPTR macro relies on this name format/mapping */
647 afs_uint32 parm = (afs_uint32)kparm;
648 afs_uint32 parm2 = (afs_uint32)kparm2;
649 afs_uint32 parm3 = (afs_uint32)kparm3;
650 afs_uint32 parm4 = (afs_uint32)kparm4;
651 afs_uint32 parm5 = (afs_uint32)kparm5;
652 afs_uint32 parm6 = (afs_uint32)kparm6;
655 AFS_STATCNT(afs_syscall_call);
662 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
663 /* only root can run this code */
664 #if defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
665 # if defined(KERNEL_HAVE_UERROR)
673 #ifdef AFS_DARWIN80_ENV
679 #ifdef AFS_DARWIN80_ENV
682 #ifdef AFS_DAEMONOP_ENV
683 # if defined(AFS_NEW_BKG)
684 if (parm == AFSOP_BKG_HANDLER) {
685 /* if afs_uspc_param grows this should be checked */
686 struct afs_uspc_param *mvParam = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
691 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)mvParam,
692 sizeof(struct afs_uspc_param), code);
693 namebufsz = mvParam->bufSz;
694 param1 = afs_osi_Alloc(namebufsz);
695 osi_Assert(param1 != NULL);
696 param2 = afs_osi_Alloc(namebufsz);
697 osi_Assert(param2 != NULL);
699 while (afs_initState < AFSOP_START_BKG)
700 afs_osi_Sleep(&afs_initState);
701 if (afs_initState < AFSOP_GO) {
702 afs_initState = AFSOP_GO;
703 afs_osi_Wakeup(&afs_initState);
706 code = afs_BackgroundDaemon(mvParam, param1, param2);
710 /* for reqs where pointers are strings: */
711 if (mvParam->reqtype == AFS_USPC_UMV) {
712 /* don't copy out random kernel memory */
713 AFS_COPYOUT(param2, AFSKPTR(parm4),
714 MIN(namebufsz, strlen((char *)param2)+1), code);
715 AFS_COPYOUT(param1, AFSKPTR(parm3),
716 MIN(namebufsz, strlen((char *)param1)+1), code);
718 AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
719 sizeof(struct afs_uspc_param), code);
722 afs_osi_Free(param1, namebufsz);
723 afs_osi_Free(param2, namebufsz);
724 osi_FreeSmallSpace(mvParam);
726 # endif /* AFS_NEW_BKG */
727 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
728 || parm == AFSOP_RXLISTENER_DAEMON) {
729 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
731 #else /* !AFS_DAEMONOP_ENV */
732 if (parm == AFSOP_START_RXCALLBACK) {
736 # ifndef RXK_LISTENER_ENV
737 code = afs_InitSetup(parm2);
739 # endif /* !RXK_LISTENER_ENV */
741 # ifdef RXK_LISTENER_ENV
742 while (afs_RX_Running != 2)
743 afs_osi_Sleep(&afs_RX_Running);
744 # else /* !RXK_LISTENER_ENV */
746 rx_enablePeerRPCStats();
749 rx_enableProcessRPCStats();
751 afs_initState = AFSOP_START_AFS;
752 afs_osi_Wakeup(&afs_initState);
753 # endif /* RXK_LISTENER_ENV */
755 afs_RXCallBackServer();
760 exit(CLD_EXITED, code);
761 # endif /* AFS_SGI_ENV */
763 # ifdef RXK_LISTENER_ENV
764 else if (parm == AFSOP_RXLISTENER_DAEMON) {
768 code = afs_InitSetup(parm2);
770 rx_enablePeerRPCStats();
773 rx_enableProcessRPCStats();
776 afs_initState = AFSOP_START_AFS;
777 afs_osi_Wakeup(&afs_initState);
780 afs_osi_Wakeup(&afs_RX_Running);
782 afs_osi_RxkRegister();
783 # endif /* !UKERNEL */
789 exit(CLD_EXITED, code);
790 # endif /* AFS_SGI_ENV */
792 # endif /* RXK_LISTENER_ENV */
793 else if (parm == AFSOP_START_AFS) {
798 while (afs_initState < AFSOP_START_AFS)
799 afs_osi_Sleep(&afs_initState);
801 afs_initState = AFSOP_START_BKG;
802 afs_osi_Wakeup(&afs_initState);
809 # endif /* AFS_SGI_ENV */
810 } else if (parm == AFSOP_START_CS) {
812 afs_CheckServerDaemon();
817 # endif /* AFS_SGI_ENV */
819 } else if (parm == AFSOP_START_BKG) {
820 while (afs_initState < AFSOP_START_BKG)
821 afs_osi_Sleep(&afs_initState);
822 if (afs_initState < AFSOP_GO) {
823 afs_initState = AFSOP_GO;
824 afs_osi_Wakeup(&afs_initState);
826 /* start the bkg daemon */
828 # ifdef AFS_AIX32_ENV
830 afs_BioDaemon(parm2);
832 # endif /* AFS_AIX32_ENV */
833 afs_BackgroundDaemon();
838 # endif /* AFS_SGI_ENV */
839 # endif /* ! AFS_NEW_BKG */
840 } else if (parm == AFSOP_START_TRUNCDAEMON) {
841 while (afs_initState < AFSOP_GO)
842 afs_osi_Sleep(&afs_initState);
843 /* start the bkg daemon */
845 afs_CacheTruncateDaemon();
850 # endif /* AFS_SGI_ENV */
852 # if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
853 else if (parm == AFSOP_RXEVENT_DAEMON) {
854 while (afs_initState < AFSOP_START_BKG)
855 afs_osi_Sleep(&afs_initState);
857 afs_rxevent_daemon();
862 # endif /* AFS_SGI_ENV */
864 # endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV || RXK_UPCALL_ENV */
865 #endif /* AFS_DAEMONOP_ENV */
866 else if (parm == AFSOP_BASIC_INIT) {
869 while (!afs_InitSetup_done)
870 afs_osi_Sleep(&afs_InitSetup_done);
872 #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)
873 temp = AFS_MINBUFFERS; /* Should fix this soon */
875 /* number of 2k buffers we could get from all of the buffer space */
876 temp = ((afs_bufferpages * NBPG) >> 11);
877 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
878 if (temp < AFS_MINBUFFERS)
879 temp = AFS_MINBUFFERS; /* though we really should have this many */
882 afs_rootFid.Fid.Volume = 0;
884 } else if (parm == AFSOP_BUCKETPCT) {
885 /* need to enable this now, will disable again before GO
886 if we don't have 100% */
896 } else if (parm == AFSOP_ADDCELL) {
897 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
898 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
899 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
900 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
902 osi_Assert(tcell != NULL);
903 code = afs_InitDynroot();
905 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
909 if (parm4 > sizeof(tcell->cellName))
912 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)tcell->cellName, parm4, code);
914 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
918 afs_osi_Free(tcell, sizeof(struct afsop_cell));
919 } else if (parm == AFSOP_ADDCELL2) {
920 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
921 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
922 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
925 osi_Assert(tcell != NULL);
926 osi_Assert(tbuffer != NULL);
927 osi_Assert(tbuffer1 != NULL);
928 code = afs_InitDynroot();
931 /* wait for basic init - XXX can't find any reason we need this? */
932 while (afs_initState < AFSOP_START_BKG)
933 afs_osi_Sleep(&afs_initState);
936 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
940 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
944 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
948 cflags |= CLinkedCell;
956 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
960 afs_osi_Free(tcell, sizeof(struct afsop_cell));
961 osi_FreeSmallSpace(tbuffer);
962 osi_FreeSmallSpace(tbuffer1);
963 } else if (parm == AFSOP_ADDCELLALIAS) {
966 * parm2 is the alias name
967 * parm3 is the real cell name
969 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
970 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
972 code = afs_InitDynroot();
974 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
978 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
981 afs_NewCellAlias(aliasName, cellName);
982 osi_FreeSmallSpace(aliasName);
983 osi_FreeSmallSpace(cellName);
984 } else if (parm == AFSOP_SET_THISCELL) {
987 * parm2 is the primary cell name
989 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
992 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
994 afs_SetPrimaryCell(cell);
995 osi_FreeSmallSpace(cell);
997 code = afs_InitDynroot();
999 } else if (parm == AFSOP_CACHEINIT) {
1000 struct afs_cacheParams cparms;
1002 if (afs_CacheInit_Done)
1005 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
1007 #if defined(KERNEL_HAVE_UERROR)
1013 afs_CacheInit_Done = 1;
1014 code = afs_icl_InitLogs();
1015 if (cparms.setTimeFlag) {
1016 afs_warn("afs: AFSOP_CACHEINIT setTimeFlag ignored; are you "
1017 "running an old afsd?\n");
1021 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
1022 cparms.cacheBlocks, cparms.cacheDcaches,
1023 cparms.cacheVolumes, cparms.chunkSize,
1024 cparms.memCacheFlag, cparms.inodes, cparms.users,
1025 cparms.dynamic_vcaches);
1027 } else if (parm == AFSOP_CACHEINODE) {
1028 ino_t ainode = parm2;
1029 /* wait for basic init */
1030 while (afs_initState < AFSOP_START_BKG)
1031 afs_osi_Sleep(&afs_initState);
1033 #ifdef AFS_DARWIN80_ENV
1036 /* do it by inode */
1037 #ifdef AFS_SGI62_ENV
1038 ainode = (ainode << 32) | (parm3 & 0xffffffff);
1040 code = afs_InitCacheFile(NULL, ainode);
1041 #ifdef AFS_DARWIN80_ENV
1044 } else if (parm == AFSOP_CACHEDIRS) {
1045 afs_numfilesperdir = parm2;
1046 afs_osi_Wakeup(&afs_initState);
1047 } else if (parm == AFSOP_CACHEFILES) {
1048 afs_numcachefiles = parm2;
1049 afs_osi_Wakeup(&afs_initState);
1050 } else if (parm == AFSOP_ROOTVOLUME) {
1051 /* wait for basic init */
1052 while (afs_initState < AFSOP_START_BKG)
1053 afs_osi_Sleep(&afs_initState);
1056 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
1057 sizeof(afs_rootVolumeName), &bufferSize, code);
1058 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
1061 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
1062 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
1063 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
1066 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
1069 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
1070 /* We have the cache dir copied in. Call the cache init routine */
1071 #ifdef AFS_DARWIN80_ENV
1074 if (parm == AFSOP_CACHEFILE) {
1075 code = afs_InitCacheFile(tbuffer, 0);
1076 } else if (parm == AFSOP_CACHEINFO) {
1077 code = afs_InitCacheInfo(tbuffer);
1078 } else if (parm == AFSOP_VOLUMEINFO) {
1079 code = afs_InitVolumeInfo(tbuffer);
1080 } else if (parm == AFSOP_CELLINFO) {
1081 code = afs_InitCellInfo(tbuffer);
1083 #ifdef AFS_DARWIN80_ENV
1087 osi_FreeSmallSpace(tbuffer);
1088 } else if (parm == AFSOP_GO) {
1089 /* the generic initialization calls come here. One parameter: should we do the
1090 * set-time operation on this workstation */
1094 while (afs_initState < AFSOP_GO)
1095 afs_osi_Sleep(&afs_initState);
1096 afs_initState = 101;
1098 /* parm2 used to set afs_setTime */
1099 afs_warn("afs: AFSOP_GO setTime flag ignored; are you running an "
1102 if (afs_tpct1 + afs_tpct2 != 100) {
1109 afs_osi_Wakeup(&afs_initState);
1110 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
1111 afs_nfsclient_init();
1113 if (afs_uuid_create(&afs_cb_interface.uuid) != 0)
1114 memset(&afs_cb_interface.uuid, 0, sizeof(afsUUID));
1116 printf("found %d non-empty cache files (%d%%).\n",
1117 afs_stats_cmperf.cacheFilesReused,
1118 (100 * afs_stats_cmperf.cacheFilesReused) /
1119 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
1120 cacheNumEntries : 1));
1121 } else if (parm == AFSOP_ADVISEADDR) {
1122 /* pass in the host address to the rx package */
1126 afs_int32 count = parm2;
1128 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1129 afs_int32 *maskbuffer =
1130 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1131 afs_int32 *mtubuffer =
1132 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1135 osi_Assert(buffer != NULL);
1136 osi_Assert(maskbuffer != NULL);
1137 osi_Assert(mtubuffer != NULL);
1138 /* This is a refresh */
1139 if (count & 0x40000000) {
1140 count &= ~0x40000000;
1141 /* Can't bind after we start. Fix? */
1142 count &= ~0x80000000;
1146 /* Bind, but only if there's only one address configured */
1147 if ( count & 0x80000000) {
1148 count &= ~0x80000000;
1153 if (count > AFS_MAX_INTERFACE_ADDR) {
1155 count = AFS_MAX_INTERFACE_ADDR;
1158 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
1161 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
1162 count * sizeof(afs_int32), code);
1164 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
1165 count * sizeof(afs_int32), code);
1168 afs_cb_interface.numberOfInterfaces = count;
1169 for (i = 0; i < count; i++) {
1170 afs_cb_interface.addr_in[i] = buffer[i];
1171 #ifdef AFS_USERSPACE_IP_ADDR
1172 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
1173 * machines IP addresses when in the kernel (the in_ifaddr
1174 * struct is not available), so we pass the info in at
1175 * startup. We also pass in the subnetmask and mtu size. The
1176 * subnetmask is used when setting the rank:
1177 * afsi_SetServerIPRank(); and the mtu size is used when
1178 * finding the best mtu size. rxi_FindIfnet() is replaced
1179 * with rxi_Findcbi().
1181 afs_cb_interface.subnetmask[i] =
1182 (parm4 ? maskbuffer[i] : 0xffffffff);
1183 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1186 rxi_setaddr(buffer[0]);
1189 rx_bindhost = buffer[0];
1191 rx_bindhost = htonl(INADDR_ANY);
1197 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1198 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1199 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1202 afs_CheckServers(1, NULL); /* check down servers */
1203 afs_CheckServers(0, NULL); /* check up servers */
1206 else if (parm == AFSOP_SHUTDOWN) {
1207 afs_cold_shutdown = 0;
1209 afs_cold_shutdown = 1;
1210 if (afs_globalVFS != 0) {
1211 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1215 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1217 vfsmount(parm2, parm3, parm4, parm5);
1218 #else /* defined(AFS_HPUX_ENV) */
1219 # if defined(KERNEL_HAVE_UERROR)
1224 #endif /* defined(AFS_HPUX_ENV) */
1225 } else if (parm == AFSOP_CLOSEWAIT) {
1226 afs_SynchronousCloses = 'S';
1227 } else if (parm == AFSOP_GETMTU) {
1229 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1230 # ifdef AFS_USERSPACE_IP_ADDR
1232 i = rxi_Findcbi(parm2);
1233 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1234 # else /* AFS_USERSPACE_IP_ADDR */
1237 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1238 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1239 # endif /* else AFS_USERSPACE_IP_ADDR */
1240 #endif /* !AFS_SUN5_ENV */
1242 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1243 sizeof(afs_int32), code);
1244 #ifdef AFS_AIX32_ENV
1245 /* this is disabled for now because I can't figure out how to get access
1246 * to these kernel variables. It's only for supporting user-mode rx
1247 * programs -- it makes a huge difference on the 220's in my testbed,
1248 * though I don't know why. The bosserver does this with /etc/no, so it's
1249 * being handled a different way for the servers right now. */
1251 static adjusted = 0;
1252 extern u_long sb_max_dflt;
1255 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1256 if (sb_max < 131072) sb_max = 131072;
1259 #endif /* AFS_AIX32_ENV */
1260 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1261 afs_uint32 mask = 0;
1262 #if !defined(AFS_SUN5_ENV)
1263 # ifdef AFS_USERSPACE_IP_ADDR
1265 i = rxi_Findcbi(parm2);
1267 mask = afs_cb_interface.subnetmask[i];
1271 # else /* AFS_USERSPACE_IP_ADDR */
1274 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1277 # endif /* else AFS_USERSPACE_IP_ADDR */
1278 #endif /* !AFS_SUN5_ENV */
1280 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1281 sizeof(afs_int32), code);
1283 else if (parm == AFSOP_AFSDB_HANDLER) {
1284 int sizeArg = (int)parm4;
1285 int kmsgLen = sizeArg & 0xffff;
1286 int cellLen = (sizeArg & 0xffff0000) >> 16;
1287 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1288 char *cellname = afs_osi_Alloc(cellLen);
1290 osi_Assert(kmsg != NULL);
1291 osi_Assert(cellname != NULL);
1293 afs_osi_MaskUserLoop();
1295 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1296 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1298 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1301 if (code == -2) { /* Shutting down? */
1307 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1308 afs_osi_Free(kmsg, kmsgLen);
1309 afs_osi_Free(cellname, cellLen);
1311 else if (parm == AFSOP_SET_DYNROOT) {
1312 code = afs_SetDynrootEnable(parm2);
1313 } else if (parm == AFSOP_SET_FAKESTAT) {
1314 afs_fakestat_enable = parm2;
1316 } else if (parm == AFSOP_SET_BACKUPTREE) {
1317 afs_bkvolpref = parm2;
1318 } else if (parm == AFSOP_SET_RXPCK) {
1319 rx_extraPackets = parm2;
1320 afscall_set_rxpck_received = 1;
1321 } else if (parm == AFSOP_SET_RXMAXMTU) {
1322 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1323 } else if (parm == AFSOP_SET_RXMAXFRAGS) {
1324 rxi_nSendFrags = rxi_nRecvFrags = parm2;
1325 } else if (parm == AFSOP_SET_RMTSYS_FLAG) {
1326 afs_rmtsys_enable = parm2;
1329 } else if (parm == AFSOP_SEED_ENTROPY) {
1330 unsigned char *seedbuf;
1335 seedbuf = afs_osi_Alloc(parm3);
1336 AFS_COPYIN(AFSKPTR(parm2), seedbuf, parm3, code);
1337 RAND_seed(seedbuf, parm3);
1338 memset(seedbuf, 0, parm3);
1339 afs_osi_Free(seedbuf, parm3);
1348 #ifdef AFS_LINUX20_ENV
1356 * Initstate in the range 0 < x < 100 are early initialization states.
1357 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1358 * the cache may be initialized.
1359 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1360 * is done after all the cache initialization has been done.
1361 * Initstate of 200 means that the volume has been looked up once, possibly
1363 * Initstate of 300 means that the volume has been *successfully* looked up.
1370 AFS_STATCNT(afs_CheckInit);
1371 if (afs_initState <= 100)
1372 code = ENXIO; /* never finished init phase */
1373 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1374 while (afs_initState < 200)
1375 afs_osi_Sleep(&afs_initState);
1376 } else if (afs_initState == 200)
1377 code = ETIMEDOUT; /* didn't find root volume */
1381 int afs_shuttingdown = 0;
1385 extern short afs_brsDaemons;
1386 extern afs_int32 afs_CheckServerDaemonStarted;
1387 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1388 extern struct osi_file *afs_cacheInodep;
1390 AFS_STATCNT(afs_shutdown);
1391 if (afs_initState == 0) {
1392 afs_warn("AFS not initialized - not shutting down\n");
1396 if (afs_shuttingdown)
1399 /* Give up all of our callbacks if we can. This must be done before setting
1400 * afs_shuttingdown, since it calls afs_InitReq, which will fail if
1401 * afs_shuttingdown is set. */
1404 afs_shuttingdown = 1;
1406 if (afs_cold_shutdown)
1407 afs_warn("afs: COLD ");
1409 afs_warn("afs: WARM ");
1410 afs_warn("shutting down of: vcaches... ");
1412 #if !defined(AFS_FBSD_ENV)
1413 /* The FBSD afs_unmount() calls vflush(), which reclaims all vnodes
1414 * on the mountpoint, flushing them in the process. In the presence
1415 * of bugs, flushing again here can cause panics. */
1416 afs_FlushAllVCaches();
1419 afs_termState = AFSOP_STOP_BKG;
1421 afs_warn("BkG... ");
1422 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1423 while (afs_termState == AFSOP_STOP_BKG) {
1424 afs_osi_Wakeup(&afs_brsDaemons);
1425 afs_osi_Sleep(&afs_termState);
1430 afs_termState = AFSOP_STOP_RXCALLBACK;
1431 rx_WakeupServerProcs();
1432 #ifdef AFS_AIX51_ENV
1433 shutdown_rxkernel();
1435 /* close rx server connections here? */
1436 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1437 afs_osi_Sleep(&afs_termState);
1439 afs_warn("afs... ");
1440 while (afs_termState == AFSOP_STOP_AFS) {
1441 afs_osi_CancelWait(&AFS_WaitHandler);
1442 afs_osi_Sleep(&afs_termState);
1444 if (afs_CheckServerDaemonStarted) {
1445 while (afs_termState == AFSOP_STOP_CS) {
1446 afs_osi_CancelWait(&AFS_CSWaitHandler);
1447 afs_osi_Sleep(&afs_termState);
1450 afs_warn("CTrunc... ");
1451 /* Cancel cache truncate daemon. */
1452 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1453 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1454 afs_osi_Sleep(&afs_termState);
1456 afs_warn("AFSDB... ");
1458 while (afs_termState == AFSOP_STOP_AFSDB)
1459 afs_osi_Sleep(&afs_termState);
1460 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
1461 afs_warn("RxEvent... ");
1462 /* cancel rx event daemon */
1463 while (afs_termState == AFSOP_STOP_RXEVENT)
1464 afs_osi_Sleep(&afs_termState);
1465 # if defined(RXK_LISTENER_ENV)
1467 afs_warn("UnmaskRxkSignals... ");
1468 afs_osi_UnmaskRxkSignals();
1470 /* cancel rx listener */
1471 afs_warn("RxListener... ");
1472 osi_StopListener(); /* This closes rx_socket. */
1473 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1474 afs_warn("Sleep... ");
1475 afs_osi_Sleep(&afs_termState);
1480 #if defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
1481 afs_warn("NetIfPoller... ");
1482 osi_StopNetIfPoller();
1485 afs_termState = AFSOP_STOP_COMPLETE;
1487 #ifdef AFS_AIX51_ENV
1491 shutdown_bufferpackage();
1495 * Close file only after daemons which can write to it are stopped.
1496 * Need to close before the osinet shutdown to avoid failing check
1497 * for dangling memory allocations.
1499 if (afs_cacheInodep) { /* memcache won't set this */
1500 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1501 afs_cacheInodep = 0;
1504 * Shutdown the ICL logs - needed to free allocated memory space and avoid
1505 * warnings from shutdown_osinet
1510 shutdown_vnodeops();
1511 shutdown_memcache();
1513 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV))
1514 shutdown_exporter();
1519 /* The following hold the cm stats */
1520 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1521 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1522 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1523 afs_warn(" ALL allocated tables... ");
1525 afs_shuttingdown = 0;
1528 return; /* Just kill daemons for now */
1532 shutdown_afstest(void)
1534 AFS_STATCNT(shutdown_afstest);
1535 afs_initState = afs_termState = 0;
1536 AFS_Running = afs_CB_Running = 0;
1537 afs_CacheInit_Done = afs_Go_Done = 0;
1538 if (afs_cold_shutdown) {
1539 *afs_rootVolumeName = 0;