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) */
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
43 #if (defined(AFS_SUN5_ENV) || (defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)) || defined(AFS_DARWIN80_ENV)) && !defined(UKERNEL)
44 /* If AFS_DAEMONOP_ENV is defined, it indicates we run "daemon" AFS syscalls by
45 * spawning a kernel thread to do the work, instead of running them in the
47 # define AFS_DAEMONOP_ENV
51 afs_int32 hosts[AFS_MAXCELLHOSTS];
55 char afs_zeros[AFS_ZEROS];
56 char afs_rootVolumeName[64] = "";
57 afs_uint32 rx_bindhost;
60 ddi_taskq_t *afs_taskq;
61 krwlock_t afsifinfo_lock;
64 afs_int32 afs_initState = 0;
65 afs_int32 afs_termState = 0;
66 int afs_cold_shutdown = 0;
67 char afs_SynchronousCloses = '\0';
68 static int afs_CB_Running = 0;
69 static int AFS_Running = 0;
70 static int afs_CacheInit_Done = 0;
71 static int afs_Go_Done = 0;
72 extern struct interfaceAddr afs_cb_interface;
73 #ifdef RXK_LISTENER_ENV
74 static int afs_RX_Running = 0;
76 static int afs_InitSetup_done = 0;
77 afs_int32 afs_numcachefiles = -1;
78 afs_int32 afs_numfilesperdir = -1;
79 char afs_cachebasedir[1024];
81 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
82 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
83 afs_int32 afs_rx_idledead = AFS_IDLEDEADTIME;
84 afs_int32 afs_rx_idledead_rep = AFS_IDLEDEADTIME_REP;
86 static int afscall_set_rxpck_received = 0;
88 #if defined(AFS_HPUX_ENV)
89 extern int afs_vfs_mount();
90 #endif /* defined(AFS_HPUX_ENV) */
92 /* This is code which needs to be called once when the first daemon enters
93 * the client. A non-zero return means an error and AFS should not start.
96 afs_InitSetup(int preallocs)
100 if (afs_InitSetup_done)
103 #ifdef AFS_SUN510_ENV
104 /* Initialize a RW lock for the ifinfo global array */
105 rw_init(&afsifinfo_lock, NULL, RW_DRIVER, NULL);
108 afs_taskq = ddi_taskq_create(NULL, "afs_taskq", 2, TASKQ_DEFAULTPRI, 0);
110 osi_StartNetIfPoller();
115 * Set up all the AFS statistics variables. This should be done
116 * exactly once, and it should be done here, the first resource-setting
117 * routine to be called by the CM/RX.
120 #endif /* AFS_NOSTATS */
122 memset(afs_zeros, 0, AFS_ZEROS);
124 rx_SetBusyChannelError(1); /* turn on busy call error reporting */
127 if(!afscall_set_rxpck_received)
128 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
129 code = rx_InitHost(rx_bindhost, htons(7001));
131 afs_warn("AFS: RX failed to initialize %d).\n", code);
134 rx_SetRxDeadTime(afs_rx_deadtime);
135 /* resource init creates the services */
136 afs_ResourceInit(preallocs);
138 afs_InitSetup_done = 1;
139 afs_osi_Wakeup(&afs_InitSetup_done);
144 #ifdef AFS_DAEMONOP_ENV
146 daemonOp_common(long parm, long parm2, long parm3, long parm4, long parm5,
150 if (parm == AFSOP_START_RXCALLBACK) {
153 # ifdef RXK_LISTENER_ENV
154 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
159 code = afs_InitSetup(parm2);
161 rx_enablePeerRPCStats();
164 rx_enableProcessRPCStats();
168 } else if (parm == AFSOP_START_AFS) {
171 } /* other functions don't need setup in the parent */
174 #endif /* AFS_DAEMONOP_ENV */
176 #if defined(AFS_DARWIN80_ENV)
177 struct afsd_thread_info {
181 afsd_thread(int *rock)
183 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
184 unsigned long parm = arg->parm;
187 case AFSOP_START_RXCALLBACK:
191 #ifndef RXK_LISTENER_ENV
192 afs_initState = AFSOP_START_AFS;
193 afs_osi_Wakeup(&afs_initState);
195 while (afs_RX_Running != 2)
196 afs_osi_Sleep(&afs_RX_Running);
198 afs_RXCallBackServer();
200 thread_terminate(current_thread());
202 case AFSOP_START_AFS:
206 while (afs_initState < AFSOP_START_AFS)
207 afs_osi_Sleep(&afs_initState);
208 afs_initState = AFSOP_START_BKG;
209 afs_osi_Wakeup(&afs_initState);
212 thread_terminate(current_thread());
214 case AFSOP_START_BKG:
215 afs_warn("Install matching afsd! Old background daemons not supported.\n");
216 thread_terminate(current_thread());
218 case AFSOP_START_TRUNCDAEMON:
221 while (afs_initState < AFSOP_GO)
222 afs_osi_Sleep(&afs_initState);
223 afs_CacheTruncateDaemon();
225 thread_terminate(current_thread());
230 afs_CheckServerDaemon();
232 thread_terminate(current_thread());
234 case AFSOP_RXEVENT_DAEMON:
237 while (afs_initState < AFSOP_START_BKG)
238 afs_osi_Sleep(&afs_initState);
239 afs_rxevent_daemon();
241 thread_terminate(current_thread());
243 #ifdef RXK_LISTENER_ENV
244 case AFSOP_RXLISTENER_DAEMON:
247 afs_initState = AFSOP_START_AFS;
248 afs_osi_Wakeup(&afs_initState);
250 afs_osi_Wakeup(&afs_RX_Running);
251 afs_osi_RxkRegister();
254 thread_terminate(current_thread());
258 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
264 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
267 struct afsd_thread_info info;
269 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
273 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
275 /* we need to wait cause we passed stack pointers around.... */
276 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
278 thread_deallocate(thread);
283 #if defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)
284 struct afsd_thread_info {
285 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
286 struct work_struct tq;
289 struct completion *complete;
293 afsd_thread(void *rock)
295 struct afsd_thread_info *arg = rock;
296 unsigned long parm = arg->parm;
297 # ifdef SYS_SETPRIORITY_EXPORTED
298 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
300 # if !defined(HAVE_LINUX_KTHREAD_RUN)
301 # if defined(AFS_LINUX26_ENV)
306 # endif /* !HAVE_LINUX_KTHREAD_RUN */
307 /* doesn't do much, since we were forked from keventd, but
308 * does call mm_release, which wakes up our parent (since it
309 * used CLONE_VFORK) */
310 # if !defined(AFS_LINUX26_ENV)
313 afs_osi_MaskSignals();
315 case AFSOP_START_RXCALLBACK:
316 sprintf(current->comm, "afs_cbstart");
318 complete(arg->complete);
320 #if !defined(RXK_LISTENER_ENV)
321 afs_initState = AFSOP_START_AFS;
322 afs_osi_Wakeup(&afs_initState);
324 while (afs_RX_Running != 2)
325 afs_osi_Sleep(&afs_RX_Running);
327 sprintf(current->comm, "afs_callback");
328 afs_RXCallBackServer();
330 complete_and_exit(0, 0);
332 case AFSOP_START_AFS:
333 sprintf(current->comm, "afs_afsstart");
335 complete(arg->complete);
337 while (afs_initState < AFSOP_START_AFS)
338 afs_osi_Sleep(&afs_initState);
339 afs_initState = AFSOP_START_BKG;
340 afs_osi_Wakeup(&afs_initState);
341 sprintf(current->comm, "afsd");
344 complete_and_exit(0, 0);
346 case AFSOP_START_BKG:
348 afs_warn("Install matching afsd! Old background daemons not supported.\n");
350 sprintf(current->comm, "afs_bkgstart");
352 complete(arg->complete);
353 while (afs_initState < AFSOP_START_BKG)
354 afs_osi_Sleep(&afs_initState);
355 if (afs_initState < AFSOP_GO) {
356 afs_initState = AFSOP_GO;
357 afs_osi_Wakeup(&afs_initState);
359 sprintf(current->comm, "afs_background");
360 afs_BackgroundDaemon();
363 complete_and_exit(0, 0);
365 case AFSOP_START_TRUNCDAEMON:
366 sprintf(current->comm, "afs_trimstart");
368 complete(arg->complete);
369 while (afs_initState < AFSOP_GO)
370 afs_osi_Sleep(&afs_initState);
371 sprintf(current->comm, "afs_cachetrim");
372 afs_CacheTruncateDaemon();
374 complete_and_exit(0, 0);
377 sprintf(current->comm, "afs_checkserver");
379 complete(arg->complete);
380 afs_CheckServerDaemon();
382 complete_and_exit(0, 0);
384 case AFSOP_RXEVENT_DAEMON:
385 sprintf(current->comm, "afs_evtstart");
386 # ifdef SYS_SETPRIORITY_EXPORTED
387 sys_setpriority(PRIO_PROCESS, 0, -10);
389 # ifdef CURRENT_INCLUDES_NICE
394 complete(arg->complete);
395 while (afs_initState < AFSOP_START_BKG)
396 afs_osi_Sleep(&afs_initState);
397 sprintf(current->comm, "afs_rxevent");
398 afs_rxevent_daemon();
400 complete_and_exit(0, 0);
402 #ifdef RXK_LISTENER_ENV
403 case AFSOP_RXLISTENER_DAEMON:
404 sprintf(current->comm, "afs_lsnstart");
405 # ifdef SYS_SETPRIORITY_EXPORTED
406 sys_setpriority(PRIO_PROCESS, 0, -10);
408 # ifdef CURRENT_INCLUDES_NICE
413 complete(arg->complete);
414 afs_initState = AFSOP_START_AFS;
415 afs_osi_Wakeup(&afs_initState);
417 afs_osi_Wakeup(&afs_RX_Running);
418 afs_osi_RxkRegister();
419 sprintf(current->comm, "afs_rxlistener");
422 complete_and_exit(0, 0);
426 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
433 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
434 afsd_launcher(struct work_struct *work)
436 afsd_launcher(void *rock)
439 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
440 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
443 # if defined(HAVE_LINUX_KTHREAD_RUN)
444 if (IS_ERR(kthread_run(afsd_thread, (void *)rock, "afsd"))) {
445 afs_warn("kthread_run failed; afs startup will not complete\n");
447 # else /* !HAVE_LINUX_KTHREAD_RUN */
448 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
449 afs_warn("kernel_thread failed. afs startup will not complete\n");
450 # endif /* !HAVE_LINUX_KTHREAD_RUN */
454 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
457 DECLARE_COMPLETION(c);
458 # if defined(AFS_LINUX26_ENV)
459 # if defined(INIT_WORK_HAS_DATA)
460 struct work_struct tq;
465 struct afsd_thread_info info;
466 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
471 # if defined(AFS_LINUX26_ENV)
472 # if !defined(INIT_WORK_HAS_DATA)
473 INIT_WORK(&info.tq, afsd_launcher);
474 schedule_work(&info.tq);
476 INIT_WORK(&tq, afsd_launcher, &info);
481 INIT_LIST_HEAD(&tq.list);
482 tq.routine = afsd_launcher;
487 /* we need to wait cause we passed stack pointers around.... */
488 wait_for_completion(&c);
494 struct afs_daemonop_args {
500 afsd_thread(struct afs_daemonop_args *args)
502 long parm = args->parm;
505 cv_signal(&args->cv);
508 case AFSOP_START_RXCALLBACK:
512 while (afs_RX_Running != 2)
513 afs_osi_Sleep(&afs_RX_Running);
514 afs_RXCallBackServer();
517 case AFSOP_START_AFS:
521 while (afs_initState < AFSOP_START_AFS)
522 afs_osi_Sleep(&afs_initState);
523 afs_initState = AFSOP_START_BKG;
524 afs_osi_Wakeup(&afs_initState);
528 case AFSOP_START_BKG:
529 while (afs_initState < AFSOP_START_BKG)
530 afs_osi_Sleep(&afs_initState);
531 if (afs_initState < AFSOP_GO) {
532 afs_initState = AFSOP_GO;
533 afs_osi_Wakeup(&afs_initState);
535 afs_BackgroundDaemon();
538 case AFSOP_START_TRUNCDAEMON:
539 while (afs_initState < AFSOP_GO)
540 afs_osi_Sleep(&afs_initState);
541 afs_CacheTruncateDaemon();
545 afs_CheckServerDaemon();
548 case AFSOP_RXEVENT_DAEMON:
549 while (afs_initState < AFSOP_START_BKG)
550 afs_osi_Sleep(&afs_initState);
551 afs_rxevent_daemon();
554 case AFSOP_RXLISTENER_DAEMON:
555 afs_initState = AFSOP_START_AFS;
556 afs_osi_Wakeup(&afs_initState);
558 afs_osi_Wakeup(&afs_RX_Running);
559 afs_osi_RxkRegister();
565 afs_warn("Unknown op %ld in afsd_thread()\n", parm);
574 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
577 struct afs_daemonop_args args;
579 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
585 cv_init(&args.cv, "AFS DaemonOp cond var", CV_DEFAULT, NULL);
587 if (thread_create(NULL, 0, afsd_thread, &args, 0, &p0, TS_RUN,
588 minclsyspri) == NULL) {
590 afs_warn("thread_create failed: AFS startup will not complete\n");
593 /* we passed &args to the new thread, which is on the stack. wait until
594 * it has read the arguments so it doesn't try to read the args after we
596 cv_wait(&args.cv, &afs_global_lock);
598 cv_destroy(&args.cv);
600 #endif /* AFS_SUN5_ENV */
602 #ifdef AFS_DARWIN100_ENV
603 # define AFSKPTR(X) k ## X
605 afs_syscall_call(long parm, long parm2, long parm3,
606 long parm4, long parm5, long parm6)
608 return afs_syscall64_call(CAST_USER_ADDR_T((parm)),
609 CAST_USER_ADDR_T((parm2)),
610 CAST_USER_ADDR_T((parm3)),
611 CAST_USER_ADDR_T((parm4)),
612 CAST_USER_ADDR_T((parm5)),
613 CAST_USER_ADDR_T((parm6)));
616 # define AFSKPTR(X) ((caddr_t)X)
619 #ifdef AFS_DARWIN100_ENV
620 afs_syscall64_call(user_addr_t kparm, user_addr_t kparm2, user_addr_t kparm3,
621 user_addr_t kparm4, user_addr_t kparm5, user_addr_t kparm6)
623 afs_syscall_call(long parm, long parm2, long parm3,
624 long parm4, long parm5, long parm6)
628 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
630 #else /* AFS_SGI61_ENV */
632 #endif /* AFS_SGI61_ENV */
633 #ifdef AFS_DARWIN100_ENV
634 /* AFSKPTR macro relies on this name format/mapping */
635 afs_uint32 parm = (afs_uint32)kparm;
636 afs_uint32 parm2 = (afs_uint32)kparm2;
637 afs_uint32 parm3 = (afs_uint32)kparm3;
638 afs_uint32 parm4 = (afs_uint32)kparm4;
639 afs_uint32 parm5 = (afs_uint32)kparm5;
640 afs_uint32 parm6 = (afs_uint32)kparm6;
643 AFS_STATCNT(afs_syscall_call);
650 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
651 /* only root can run this code */
652 #if defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
653 # if defined(KERNEL_HAVE_UERROR)
661 #ifdef AFS_DARWIN80_ENV
667 #ifdef AFS_DARWIN80_ENV
670 #ifdef AFS_DAEMONOP_ENV
671 # if defined(AFS_NEW_BKG)
672 if (parm == AFSOP_BKG_HANDLER) {
673 /* if afs_uspc_param grows this should be checked */
674 struct afs_uspc_param *mvParam = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
679 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)mvParam,
680 sizeof(struct afs_uspc_param), code);
681 namebufsz = mvParam->bufSz;
682 param1 = afs_osi_Alloc(namebufsz);
683 osi_Assert(param1 != NULL);
684 param2 = afs_osi_Alloc(namebufsz);
685 osi_Assert(param2 != NULL);
687 while (afs_initState < AFSOP_START_BKG)
688 afs_osi_Sleep(&afs_initState);
689 if (afs_initState < AFSOP_GO) {
690 afs_initState = AFSOP_GO;
691 afs_osi_Wakeup(&afs_initState);
694 code = afs_BackgroundDaemon(mvParam, param1, param2);
698 /* for reqs where pointers are strings: */
699 if (mvParam->reqtype == AFS_USPC_UMV) {
700 /* don't copy out random kernel memory */
701 AFS_COPYOUT(param2, AFSKPTR(parm4),
702 MIN(namebufsz, strlen((char *)param2)+1), code);
703 AFS_COPYOUT(param1, AFSKPTR(parm3),
704 MIN(namebufsz, strlen((char *)param1)+1), code);
706 AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
707 sizeof(struct afs_uspc_param), code);
710 afs_osi_Free(param1, namebufsz);
711 afs_osi_Free(param2, namebufsz);
712 osi_FreeSmallSpace(mvParam);
714 # endif /* AFS_NEW_BKG */
715 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
716 || parm == AFSOP_RXLISTENER_DAEMON) {
717 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
719 #else /* !AFS_DAEMONOP_ENV */
720 if (parm == AFSOP_START_RXCALLBACK) {
724 # ifndef RXK_LISTENER_ENV
725 code = afs_InitSetup(parm2);
727 # endif /* !RXK_LISTENER_ENV */
729 # ifdef RXK_LISTENER_ENV
730 while (afs_RX_Running != 2)
731 afs_osi_Sleep(&afs_RX_Running);
732 # else /* !RXK_LISTENER_ENV */
734 rx_enablePeerRPCStats();
737 rx_enableProcessRPCStats();
739 afs_initState = AFSOP_START_AFS;
740 afs_osi_Wakeup(&afs_initState);
741 # endif /* RXK_LISTENER_ENV */
743 afs_RXCallBackServer();
748 exit(CLD_EXITED, code);
749 # endif /* AFS_SGI_ENV */
751 # ifdef RXK_LISTENER_ENV
752 else if (parm == AFSOP_RXLISTENER_DAEMON) {
756 code = afs_InitSetup(parm2);
758 rx_enablePeerRPCStats();
761 rx_enableProcessRPCStats();
764 afs_initState = AFSOP_START_AFS;
765 afs_osi_Wakeup(&afs_initState);
768 afs_osi_Wakeup(&afs_RX_Running);
770 afs_osi_RxkRegister();
771 # endif /* !UKERNEL */
777 exit(CLD_EXITED, code);
778 # endif /* AFS_SGI_ENV */
780 # endif /* RXK_LISTENER_ENV */
781 else if (parm == AFSOP_START_AFS) {
786 while (afs_initState < AFSOP_START_AFS)
787 afs_osi_Sleep(&afs_initState);
789 afs_initState = AFSOP_START_BKG;
790 afs_osi_Wakeup(&afs_initState);
797 # endif /* AFS_SGI_ENV */
798 } else if (parm == AFSOP_START_CS) {
800 afs_CheckServerDaemon();
805 # endif /* AFS_SGI_ENV */
807 } else if (parm == AFSOP_START_BKG) {
808 while (afs_initState < AFSOP_START_BKG)
809 afs_osi_Sleep(&afs_initState);
810 if (afs_initState < AFSOP_GO) {
811 afs_initState = AFSOP_GO;
812 afs_osi_Wakeup(&afs_initState);
814 /* start the bkg daemon */
816 # ifdef AFS_AIX32_ENV
818 afs_BioDaemon(parm2);
820 # endif /* AFS_AIX32_ENV */
821 afs_BackgroundDaemon();
826 # endif /* AFS_SGI_ENV */
827 # endif /* ! AFS_NEW_BKG */
828 } else if (parm == AFSOP_START_TRUNCDAEMON) {
829 while (afs_initState < AFSOP_GO)
830 afs_osi_Sleep(&afs_initState);
831 /* start the bkg daemon */
833 afs_CacheTruncateDaemon();
838 # endif /* AFS_SGI_ENV */
840 # if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
841 else if (parm == AFSOP_RXEVENT_DAEMON) {
842 while (afs_initState < AFSOP_START_BKG)
843 afs_osi_Sleep(&afs_initState);
845 afs_rxevent_daemon();
850 # endif /* AFS_SGI_ENV */
852 # endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV || RXK_UPCALL_ENV */
853 #endif /* AFS_DAEMONOP_ENV */
854 else if (parm == AFSOP_BASIC_INIT) {
857 while (!afs_InitSetup_done)
858 afs_osi_Sleep(&afs_InitSetup_done);
860 #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)
861 temp = AFS_MINBUFFERS; /* Should fix this soon */
863 /* number of 2k buffers we could get from all of the buffer space */
864 temp = ((afs_bufferpages * NBPG) >> 11);
865 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
866 if (temp < AFS_MINBUFFERS)
867 temp = AFS_MINBUFFERS; /* though we really should have this many */
870 afs_rootFid.Fid.Volume = 0;
872 } else if (parm == AFSOP_BUCKETPCT) {
873 /* need to enable this now, will disable again before GO
874 if we don't have 100% */
884 } else if (parm == AFSOP_ADDCELL) {
885 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
886 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
887 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
888 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
890 osi_Assert(tcell != NULL);
891 code = afs_InitDynroot();
893 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
897 if (parm4 > sizeof(tcell->cellName))
900 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)tcell->cellName, parm4, code);
902 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
906 afs_osi_Free(tcell, sizeof(struct afsop_cell));
907 } else if (parm == AFSOP_ADDCELL2) {
908 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
909 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
910 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
913 osi_Assert(tcell != NULL);
914 osi_Assert(tbuffer != NULL);
915 osi_Assert(tbuffer1 != NULL);
916 code = afs_InitDynroot();
919 /* wait for basic init - XXX can't find any reason we need this? */
920 while (afs_initState < AFSOP_START_BKG)
921 afs_osi_Sleep(&afs_initState);
924 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
928 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
932 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
936 cflags |= CLinkedCell;
944 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
948 afs_osi_Free(tcell, sizeof(struct afsop_cell));
949 osi_FreeSmallSpace(tbuffer);
950 osi_FreeSmallSpace(tbuffer1);
951 } else if (parm == AFSOP_ADDCELLALIAS) {
954 * parm2 is the alias name
955 * parm3 is the real cell name
957 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
958 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
960 code = afs_InitDynroot();
962 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
966 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
969 afs_NewCellAlias(aliasName, cellName);
970 osi_FreeSmallSpace(aliasName);
971 osi_FreeSmallSpace(cellName);
972 } else if (parm == AFSOP_SET_THISCELL) {
975 * parm2 is the primary cell name
977 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
980 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
982 afs_SetPrimaryCell(cell);
983 osi_FreeSmallSpace(cell);
985 code = afs_InitDynroot();
987 } else if (parm == AFSOP_CACHEINIT) {
988 struct afs_cacheParams cparms;
990 if (afs_CacheInit_Done)
993 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
995 #if defined(KERNEL_HAVE_UERROR)
1001 afs_CacheInit_Done = 1;
1002 code = afs_icl_InitLogs();
1003 if (cparms.setTimeFlag) {
1004 afs_warn("afs: AFSOP_CACHEINIT setTimeFlag ignored; are you "
1005 "running an old afsd?\n");
1009 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
1010 cparms.cacheBlocks, cparms.cacheDcaches,
1011 cparms.cacheVolumes, cparms.chunkSize,
1012 cparms.memCacheFlag, cparms.inodes, cparms.users,
1013 cparms.dynamic_vcaches);
1015 } else if (parm == AFSOP_CACHEINODE) {
1016 ino_t ainode = parm2;
1017 /* wait for basic init */
1018 while (afs_initState < AFSOP_START_BKG)
1019 afs_osi_Sleep(&afs_initState);
1021 #ifdef AFS_DARWIN80_ENV
1024 /* do it by inode */
1025 #ifdef AFS_SGI62_ENV
1026 ainode = (ainode << 32) | (parm3 & 0xffffffff);
1028 code = afs_InitCacheFile(NULL, ainode);
1029 #ifdef AFS_DARWIN80_ENV
1032 } else if (parm == AFSOP_CACHEDIRS) {
1033 afs_numfilesperdir = parm2;
1034 afs_osi_Wakeup(&afs_initState);
1035 } else if (parm == AFSOP_CACHEFILES) {
1036 afs_numcachefiles = parm2;
1037 afs_osi_Wakeup(&afs_initState);
1038 } else if (parm == AFSOP_ROOTVOLUME) {
1039 /* wait for basic init */
1040 while (afs_initState < AFSOP_START_BKG)
1041 afs_osi_Sleep(&afs_initState);
1044 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
1045 sizeof(afs_rootVolumeName), &bufferSize, code);
1046 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
1049 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
1050 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
1051 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
1054 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
1057 osi_FreeSmallSpace(tbuffer);
1061 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
1062 /* We have the cache dir copied in. Call the cache init routine */
1063 #ifdef AFS_DARWIN80_ENV
1066 if (parm == AFSOP_CACHEFILE) {
1067 code = afs_InitCacheFile(tbuffer, 0);
1068 } else if (parm == AFSOP_CACHEINFO) {
1069 code = afs_InitCacheInfo(tbuffer);
1070 } else if (parm == AFSOP_VOLUMEINFO) {
1071 code = afs_InitVolumeInfo(tbuffer);
1072 } else if (parm == AFSOP_CELLINFO) {
1073 code = afs_InitCellInfo(tbuffer);
1075 #ifdef AFS_DARWIN80_ENV
1079 osi_FreeSmallSpace(tbuffer);
1080 } else if (parm == AFSOP_GO) {
1081 /* the generic initialization calls come here. One parameter: should we do the
1082 * set-time operation on this workstation */
1086 while (afs_initState < AFSOP_GO)
1087 afs_osi_Sleep(&afs_initState);
1088 afs_initState = 101;
1090 /* parm2 used to set afs_setTime */
1091 afs_warn("afs: AFSOP_GO setTime flag ignored; are you running an "
1094 if (afs_tpct1 + afs_tpct2 != 100) {
1101 afs_osi_Wakeup(&afs_initState);
1102 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
1103 afs_nfsclient_init();
1105 if (afs_uuid_create(&afs_cb_interface.uuid) != 0)
1106 memset(&afs_cb_interface.uuid, 0, sizeof(afsUUID));
1108 printf("found %d non-empty cache files (%d%%).\n",
1109 afs_stats_cmperf.cacheFilesReused,
1110 (100 * afs_stats_cmperf.cacheFilesReused) /
1111 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
1112 cacheNumEntries : 1));
1113 } else if (parm == AFSOP_ADVISEADDR) {
1114 /* pass in the host address to the rx package */
1118 afs_int32 count = parm2;
1120 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1121 afs_int32 *maskbuffer =
1122 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1123 afs_int32 *mtubuffer =
1124 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1127 osi_Assert(buffer != NULL);
1128 osi_Assert(maskbuffer != NULL);
1129 osi_Assert(mtubuffer != NULL);
1130 /* This is a refresh */
1131 if (count & 0x40000000) {
1132 count &= ~0x40000000;
1133 /* Can't bind after we start. Fix? */
1134 count &= ~0x80000000;
1138 /* Bind, but only if there's only one address configured */
1139 if ( count & 0x80000000) {
1140 count &= ~0x80000000;
1145 if (count > AFS_MAX_INTERFACE_ADDR) {
1147 count = AFS_MAX_INTERFACE_ADDR;
1150 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
1153 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
1154 count * sizeof(afs_int32), code);
1156 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
1157 count * sizeof(afs_int32), code);
1160 afs_cb_interface.numberOfInterfaces = count;
1161 for (i = 0; i < count; i++) {
1162 afs_cb_interface.addr_in[i] = buffer[i];
1163 #ifdef AFS_USERSPACE_IP_ADDR
1164 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
1165 * machines IP addresses when in the kernel (the in_ifaddr
1166 * struct is not available), so we pass the info in at
1167 * startup. We also pass in the subnetmask and mtu size. The
1168 * subnetmask is used when setting the rank:
1169 * afsi_SetServerIPRank(); and the mtu size is used when
1170 * finding the best mtu size. rxi_FindIfnet() is replaced
1171 * with rxi_Findcbi().
1173 afs_cb_interface.subnetmask[i] =
1174 (parm4 ? maskbuffer[i] : 0xffffffff);
1175 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1178 rxi_setaddr(buffer[0]);
1181 rx_bindhost = buffer[0];
1183 rx_bindhost = htonl(INADDR_ANY);
1189 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1190 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1191 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1194 afs_CheckServers(1, NULL); /* check down servers */
1195 afs_CheckServers(0, NULL); /* check up servers */
1198 else if (parm == AFSOP_SHUTDOWN) {
1199 afs_cold_shutdown = 0;
1201 afs_cold_shutdown = 1;
1202 if (afs_globalVFS != 0) {
1203 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1207 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1209 vfsmount(parm2, parm3, parm4, parm5);
1210 #else /* defined(AFS_HPUX_ENV) */
1211 # if defined(KERNEL_HAVE_UERROR)
1216 #endif /* defined(AFS_HPUX_ENV) */
1217 } else if (parm == AFSOP_CLOSEWAIT) {
1218 afs_SynchronousCloses = 'S';
1219 } else if (parm == AFSOP_GETMTU) {
1221 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1222 # ifdef AFS_USERSPACE_IP_ADDR
1224 i = rxi_Findcbi(parm2);
1225 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1226 # else /* AFS_USERSPACE_IP_ADDR */
1229 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1230 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1231 # endif /* else AFS_USERSPACE_IP_ADDR */
1232 #endif /* !AFS_SUN5_ENV */
1234 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1235 sizeof(afs_int32), code);
1236 #ifdef AFS_AIX32_ENV
1237 /* this is disabled for now because I can't figure out how to get access
1238 * to these kernel variables. It's only for supporting user-mode rx
1239 * programs -- it makes a huge difference on the 220's in my testbed,
1240 * though I don't know why. The bosserver does this with /etc/no, so it's
1241 * being handled a different way for the servers right now. */
1243 static adjusted = 0;
1244 extern u_long sb_max_dflt;
1247 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1248 if (sb_max < 131072) sb_max = 131072;
1251 #endif /* AFS_AIX32_ENV */
1252 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1253 afs_uint32 mask = 0;
1254 #if !defined(AFS_SUN5_ENV)
1255 # ifdef AFS_USERSPACE_IP_ADDR
1257 i = rxi_Findcbi(parm2);
1259 mask = afs_cb_interface.subnetmask[i];
1263 # else /* AFS_USERSPACE_IP_ADDR */
1266 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1269 # endif /* else AFS_USERSPACE_IP_ADDR */
1270 #endif /* !AFS_SUN5_ENV */
1272 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1273 sizeof(afs_int32), code);
1275 else if (parm == AFSOP_AFSDB_HANDLER) {
1276 int sizeArg = (int)parm4;
1277 int kmsgLen = sizeArg & 0xffff;
1278 int cellLen = (sizeArg & 0xffff0000) >> 16;
1279 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1280 char *cellname = afs_osi_Alloc(cellLen);
1282 osi_Assert(kmsg != NULL);
1283 osi_Assert(cellname != NULL);
1285 afs_osi_MaskUserLoop();
1287 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1288 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1290 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1293 if (code == -2) { /* Shutting down? */
1299 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1300 afs_osi_Free(kmsg, kmsgLen);
1301 afs_osi_Free(cellname, cellLen);
1303 else if (parm == AFSOP_SET_DYNROOT) {
1304 code = afs_SetDynrootEnable(parm2);
1305 } else if (parm == AFSOP_SET_FAKESTAT) {
1306 afs_fakestat_enable = parm2;
1308 } else if (parm == AFSOP_SET_BACKUPTREE) {
1309 afs_bkvolpref = parm2;
1310 } else if (parm == AFSOP_SET_RXPCK) {
1311 rx_extraPackets = parm2;
1312 afscall_set_rxpck_received = 1;
1313 } else if (parm == AFSOP_SET_RXMAXMTU) {
1314 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1315 } else if (parm == AFSOP_SET_RXMAXFRAGS) {
1316 rxi_nSendFrags = rxi_nRecvFrags = parm2;
1323 #ifdef AFS_LINUX20_ENV
1331 * Initstate in the range 0 < x < 100 are early initialization states.
1332 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1333 * the cache may be initialized.
1334 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1335 * is done after all the cache initialization has been done.
1336 * Initstate of 200 means that the volume has been looked up once, possibly
1338 * Initstate of 300 means that the volume has been *successfully* looked up.
1345 AFS_STATCNT(afs_CheckInit);
1346 if (afs_initState <= 100)
1347 code = ENXIO; /* never finished init phase */
1348 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1349 while (afs_initState < 200)
1350 afs_osi_Sleep(&afs_initState);
1351 } else if (afs_initState == 200)
1352 code = ETIMEDOUT; /* didn't find root volume */
1356 int afs_shuttingdown = 0;
1360 extern short afs_brsDaemons;
1361 extern afs_int32 afs_CheckServerDaemonStarted;
1362 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1363 extern struct osi_file *afs_cacheInodep;
1365 AFS_STATCNT(afs_shutdown);
1366 if (afs_initState == 0) {
1367 afs_warn("AFS not initialized - not shutting down\n");
1371 if (afs_shuttingdown)
1374 /* Give up all of our callbacks if we can. This must be done before setting
1375 * afs_shuttingdown, since it calls afs_InitReq, which will fail if
1376 * afs_shuttingdown is set. */
1379 afs_shuttingdown = 1;
1381 if (afs_cold_shutdown)
1382 afs_warn("afs: COLD ");
1384 afs_warn("afs: WARM ");
1385 afs_warn("shutting down of: vcaches... ");
1387 #if !defined(AFS_FBSD_ENV)
1388 /* The FBSD afs_unmount() calls vflush(), which reclaims all vnodes
1389 * on the mountpoint, flushing them in the process. In the presence
1390 * of bugs, flushing again here can cause panics. */
1391 afs_FlushAllVCaches();
1394 afs_termState = AFSOP_STOP_BKG;
1396 afs_warn("BkG... ");
1397 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1398 while (afs_termState == AFSOP_STOP_BKG) {
1399 afs_osi_Wakeup(&afs_brsDaemons);
1400 afs_osi_Sleep(&afs_termState);
1405 afs_termState = AFSOP_STOP_RXCALLBACK;
1406 rx_WakeupServerProcs();
1407 #ifdef AFS_AIX51_ENV
1408 shutdown_rxkernel();
1410 /* close rx server connections here? */
1411 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1412 afs_osi_Sleep(&afs_termState);
1414 afs_warn("afs... ");
1415 while (afs_termState == AFSOP_STOP_AFS) {
1416 afs_osi_CancelWait(&AFS_WaitHandler);
1417 afs_osi_Sleep(&afs_termState);
1419 if (afs_CheckServerDaemonStarted) {
1420 while (afs_termState == AFSOP_STOP_CS) {
1421 afs_osi_CancelWait(&AFS_CSWaitHandler);
1422 afs_osi_Sleep(&afs_termState);
1425 afs_warn("CTrunc... ");
1426 /* Cancel cache truncate daemon. */
1427 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1428 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1429 afs_osi_Sleep(&afs_termState);
1431 afs_warn("AFSDB... ");
1433 while (afs_termState == AFSOP_STOP_AFSDB)
1434 afs_osi_Sleep(&afs_termState);
1435 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
1436 afs_warn("RxEvent... ");
1437 /* cancel rx event daemon */
1438 while (afs_termState == AFSOP_STOP_RXEVENT)
1439 afs_osi_Sleep(&afs_termState);
1440 # if defined(RXK_LISTENER_ENV)
1442 afs_warn("UnmaskRxkSignals... ");
1443 afs_osi_UnmaskRxkSignals();
1445 /* cancel rx listener */
1446 afs_warn("RxListener... ");
1447 osi_StopListener(); /* This closes rx_socket. */
1448 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1449 afs_warn("Sleep... ");
1450 afs_osi_Sleep(&afs_termState);
1455 #if defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
1456 afs_warn("NetIfPoller... ");
1457 osi_StopNetIfPoller();
1460 afs_termState = AFSOP_STOP_COMPLETE;
1462 #ifdef AFS_AIX51_ENV
1466 shutdown_bufferpackage();
1470 * Close file only after daemons which can write to it are stopped.
1471 * Need to close before the osinet shutdown to avoid failing check
1472 * for dangling memory allocations.
1474 if (afs_cacheInodep) { /* memcache won't set this */
1475 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1476 afs_cacheInodep = 0;
1479 * Shutdown the ICL logs - needed to free allocated memory space and avoid
1480 * warnings from shutdown_osinet
1485 shutdown_vnodeops();
1486 shutdown_memcache();
1488 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV))
1489 shutdown_exporter();
1494 /* The following hold the cm stats */
1495 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1496 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1497 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1498 afs_warn(" ALL allocated tables... ");
1500 afs_shuttingdown = 0;
1503 return; /* Just kill daemons for now */
1507 shutdown_afstest(void)
1509 AFS_STATCNT(shutdown_afstest);
1510 afs_initState = afs_termState = 0;
1511 AFS_Running = afs_CB_Running = 0;
1512 afs_CacheInit_Done = afs_Go_Done = 0;
1513 if (afs_cold_shutdown) {
1514 *afs_rootVolumeName = 0;