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 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV)
39 #define AFS_MINBUFFERS 100
41 #define AFS_MINBUFFERS 50
44 #if (defined(AFS_SUN5_ENV) || (defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)) || defined(AFS_DARWIN80_ENV)) && !defined(UKERNEL)
45 /* If AFS_DAEMONOP_ENV is defined, it indicates we run "daemon" AFS syscalls by
46 * spawning a kernel thread to do the work, instead of running them in the
48 # define AFS_DAEMONOP_ENV
52 afs_int32 hosts[AFS_MAXCELLHOSTS];
56 char afs_zeros[AFS_ZEROS];
57 char afs_rootVolumeName[64] = "";
58 afs_uint32 rx_bindhost;
61 ddi_taskq_t *afs_taskq;
62 krwlock_t afsifinfo_lock;
65 afs_int32 afs_initState = 0;
66 afs_int32 afs_termState = 0;
67 int afs_cold_shutdown = 0;
68 char afs_SynchronousCloses = '\0';
69 static int afs_CB_Running = 0;
70 static int AFS_Running = 0;
71 static int afs_CacheInit_Done = 0;
72 static int afs_Go_Done = 0;
73 extern struct interfaceAddr afs_cb_interface;
74 #ifdef RXK_LISTENER_ENV
75 static int afs_RX_Running = 0;
77 static int afs_InitSetup_done = 0;
78 afs_int32 afs_numcachefiles = -1;
79 afs_int32 afs_numfilesperdir = -1;
80 char afs_cachebasedir[1024];
81 afs_int32 afs_rmtsys_enable = 0;
83 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
84 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
85 afs_int32 afs_rx_idledead = AFS_IDLEDEADTIME;
86 afs_int32 afs_rx_idledead_rep = AFS_IDLEDEADTIME_REP;
88 static int afscall_set_rxpck_received = 0;
90 #if defined(AFS_HPUX_ENV)
91 extern int afs_vfs_mount();
92 #endif /* defined(AFS_HPUX_ENV) */
94 /* This is code which needs to be called once when the first daemon enters
95 * the client. A non-zero return means an error and AFS should not start.
98 afs_InitSetup(int preallocs)
102 if (afs_InitSetup_done)
105 #ifdef AFS_SUN510_ENV
106 /* Initialize a RW lock for the ifinfo global array */
107 rw_init(&afsifinfo_lock, NULL, RW_DRIVER, NULL);
110 afs_taskq = ddi_taskq_create(NULL, "afs_taskq", 2, TASKQ_DEFAULTPRI, 0);
112 osi_StartNetIfPoller();
117 * Set up all the AFS statistics variables. This should be done
118 * exactly once, and it should be done here, the first resource-setting
119 * routine to be called by the CM/RX.
122 #endif /* AFS_NOSTATS */
124 memset(afs_zeros, 0, AFS_ZEROS);
126 rx_SetBusyChannelError(1); /* turn on busy call error reporting */
129 if(!afscall_set_rxpck_received)
130 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
131 code = rx_InitHost(rx_bindhost, htons(7001));
133 afs_warn("AFS: RX failed to initialize %d).\n", code);
136 rx_SetRxDeadTime(afs_rx_deadtime);
137 /* resource init creates the services */
138 afs_ResourceInit(preallocs);
140 afs_InitSetup_done = 1;
141 afs_osi_Wakeup(&afs_InitSetup_done);
146 #ifdef AFS_DAEMONOP_ENV
148 daemonOp_common(long parm, long parm2, long parm3, long parm4, long parm5,
152 if (parm == AFSOP_START_RXCALLBACK) {
155 # ifdef RXK_LISTENER_ENV
156 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
161 code = afs_InitSetup(parm2);
163 rx_enablePeerRPCStats();
166 rx_enableProcessRPCStats();
170 } else if (parm == AFSOP_START_AFS) {
173 } /* other functions don't need setup in the parent */
176 #endif /* AFS_DAEMONOP_ENV */
178 #if defined(AFS_DARWIN80_ENV)
179 struct afsd_thread_info {
183 afsd_thread(int *rock)
185 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
186 unsigned long parm = arg->parm;
189 case AFSOP_START_RXCALLBACK:
193 #ifndef RXK_LISTENER_ENV
194 afs_initState = AFSOP_START_AFS;
195 afs_osi_Wakeup(&afs_initState);
197 while (afs_RX_Running != 2)
198 afs_osi_Sleep(&afs_RX_Running);
200 afs_RXCallBackServer();
202 thread_terminate(current_thread());
204 case AFSOP_START_AFS:
208 while (afs_initState < AFSOP_START_AFS)
209 afs_osi_Sleep(&afs_initState);
210 afs_initState = AFSOP_START_BKG;
211 afs_osi_Wakeup(&afs_initState);
214 thread_terminate(current_thread());
216 case AFSOP_START_BKG:
217 afs_warn("Install matching afsd! Old background daemons not supported.\n");
218 thread_terminate(current_thread());
220 case AFSOP_START_TRUNCDAEMON:
223 while (afs_initState < AFSOP_GO)
224 afs_osi_Sleep(&afs_initState);
225 afs_CacheTruncateDaemon();
227 thread_terminate(current_thread());
232 afs_CheckServerDaemon();
234 thread_terminate(current_thread());
236 case AFSOP_RXEVENT_DAEMON:
239 while (afs_initState < AFSOP_START_BKG)
240 afs_osi_Sleep(&afs_initState);
241 afs_rxevent_daemon();
243 thread_terminate(current_thread());
245 #ifdef RXK_LISTENER_ENV
246 case AFSOP_RXLISTENER_DAEMON:
249 afs_initState = AFSOP_START_AFS;
250 afs_osi_Wakeup(&afs_initState);
252 afs_osi_Wakeup(&afs_RX_Running);
253 afs_osi_RxkRegister();
256 thread_terminate(current_thread());
260 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
266 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
269 struct afsd_thread_info info;
271 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
275 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
277 /* we need to wait cause we passed stack pointers around.... */
278 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
280 thread_deallocate(thread);
285 #if defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)
286 struct afsd_thread_info {
287 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
288 struct work_struct tq;
291 struct completion *complete;
295 afsd_thread(void *rock)
297 struct afsd_thread_info *arg = rock;
298 unsigned long parm = arg->parm;
299 # ifdef SYS_SETPRIORITY_EXPORTED
300 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
302 # if !defined(HAVE_LINUX_KTHREAD_RUN)
303 # if defined(AFS_LINUX26_ENV)
308 # endif /* !HAVE_LINUX_KTHREAD_RUN */
309 /* doesn't do much, since we were forked from keventd, but
310 * does call mm_release, which wakes up our parent (since it
311 * used CLONE_VFORK) */
312 # if !defined(AFS_LINUX26_ENV)
315 afs_osi_MaskSignals();
317 case AFSOP_START_RXCALLBACK:
318 sprintf(current->comm, "afs_cbstart");
320 complete(arg->complete);
322 #if !defined(RXK_LISTENER_ENV)
323 afs_initState = AFSOP_START_AFS;
324 afs_osi_Wakeup(&afs_initState);
326 while (afs_RX_Running != 2)
327 afs_osi_Sleep(&afs_RX_Running);
329 sprintf(current->comm, "afs_callback");
330 afs_RXCallBackServer();
332 complete_and_exit(0, 0);
334 case AFSOP_START_AFS:
335 sprintf(current->comm, "afs_afsstart");
337 complete(arg->complete);
339 while (afs_initState < AFSOP_START_AFS)
340 afs_osi_Sleep(&afs_initState);
341 afs_initState = AFSOP_START_BKG;
342 afs_osi_Wakeup(&afs_initState);
343 sprintf(current->comm, "afsd");
346 complete_and_exit(0, 0);
348 case AFSOP_START_BKG:
350 afs_warn("Install matching afsd! Old background daemons not supported.\n");
352 sprintf(current->comm, "afs_bkgstart");
354 complete(arg->complete);
355 while (afs_initState < AFSOP_START_BKG)
356 afs_osi_Sleep(&afs_initState);
357 if (afs_initState < AFSOP_GO) {
358 afs_initState = AFSOP_GO;
359 afs_osi_Wakeup(&afs_initState);
361 sprintf(current->comm, "afs_background");
362 afs_BackgroundDaemon();
365 complete_and_exit(0, 0);
367 case AFSOP_START_TRUNCDAEMON:
368 sprintf(current->comm, "afs_trimstart");
370 complete(arg->complete);
371 while (afs_initState < AFSOP_GO)
372 afs_osi_Sleep(&afs_initState);
373 sprintf(current->comm, "afs_cachetrim");
374 afs_CacheTruncateDaemon();
376 complete_and_exit(0, 0);
379 sprintf(current->comm, "afs_checkserver");
381 complete(arg->complete);
382 afs_CheckServerDaemon();
384 complete_and_exit(0, 0);
386 case AFSOP_RXEVENT_DAEMON:
387 sprintf(current->comm, "afs_evtstart");
388 # ifdef SYS_SETPRIORITY_EXPORTED
389 sys_setpriority(PRIO_PROCESS, 0, -10);
391 # ifdef CURRENT_INCLUDES_NICE
396 complete(arg->complete);
397 while (afs_initState < AFSOP_START_BKG)
398 afs_osi_Sleep(&afs_initState);
399 sprintf(current->comm, "afs_rxevent");
400 afs_rxevent_daemon();
402 complete_and_exit(0, 0);
404 #ifdef RXK_LISTENER_ENV
405 case AFSOP_RXLISTENER_DAEMON:
406 sprintf(current->comm, "afs_lsnstart");
407 # ifdef SYS_SETPRIORITY_EXPORTED
408 sys_setpriority(PRIO_PROCESS, 0, -10);
410 # ifdef CURRENT_INCLUDES_NICE
415 complete(arg->complete);
416 afs_initState = AFSOP_START_AFS;
417 afs_osi_Wakeup(&afs_initState);
419 afs_osi_Wakeup(&afs_RX_Running);
420 afs_osi_RxkRegister();
421 sprintf(current->comm, "afs_rxlistener");
424 complete_and_exit(0, 0);
428 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
435 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
436 afsd_launcher(struct work_struct *work)
438 afsd_launcher(void *rock)
441 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
442 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
445 # if defined(HAVE_LINUX_KTHREAD_RUN)
446 if (IS_ERR(kthread_run(afsd_thread, (void *)rock, "afsd"))) {
447 afs_warn("kthread_run failed; afs startup will not complete\n");
449 # else /* !HAVE_LINUX_KTHREAD_RUN */
450 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
451 afs_warn("kernel_thread failed. afs startup will not complete\n");
452 # endif /* !HAVE_LINUX_KTHREAD_RUN */
456 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
459 DECLARE_COMPLETION(c);
460 # if defined(AFS_LINUX26_ENV)
461 # if defined(INIT_WORK_HAS_DATA)
462 struct work_struct tq;
467 struct afsd_thread_info info;
468 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
473 # if defined(AFS_LINUX26_ENV)
474 # if !defined(INIT_WORK_HAS_DATA)
475 INIT_WORK(&info.tq, afsd_launcher);
476 schedule_work(&info.tq);
478 INIT_WORK(&tq, afsd_launcher, &info);
483 INIT_LIST_HEAD(&tq.list);
484 tq.routine = afsd_launcher;
489 /* we need to wait cause we passed stack pointers around.... */
490 wait_for_completion(&c);
496 struct afs_daemonop_args {
502 afsd_thread(struct afs_daemonop_args *args)
504 long parm = args->parm;
507 cv_signal(&args->cv);
510 case AFSOP_START_RXCALLBACK:
514 while (afs_RX_Running != 2)
515 afs_osi_Sleep(&afs_RX_Running);
516 afs_RXCallBackServer();
519 case AFSOP_START_AFS:
523 while (afs_initState < AFSOP_START_AFS)
524 afs_osi_Sleep(&afs_initState);
525 afs_initState = AFSOP_START_BKG;
526 afs_osi_Wakeup(&afs_initState);
530 case AFSOP_START_BKG:
531 while (afs_initState < AFSOP_START_BKG)
532 afs_osi_Sleep(&afs_initState);
533 if (afs_initState < AFSOP_GO) {
534 afs_initState = AFSOP_GO;
535 afs_osi_Wakeup(&afs_initState);
537 afs_BackgroundDaemon();
540 case AFSOP_START_TRUNCDAEMON:
541 while (afs_initState < AFSOP_GO)
542 afs_osi_Sleep(&afs_initState);
543 afs_CacheTruncateDaemon();
547 afs_CheckServerDaemon();
550 case AFSOP_RXEVENT_DAEMON:
551 while (afs_initState < AFSOP_START_BKG)
552 afs_osi_Sleep(&afs_initState);
553 afs_rxevent_daemon();
556 case AFSOP_RXLISTENER_DAEMON:
557 afs_initState = AFSOP_START_AFS;
558 afs_osi_Wakeup(&afs_initState);
560 afs_osi_Wakeup(&afs_RX_Running);
561 afs_osi_RxkRegister();
567 afs_warn("Unknown op %ld in afsd_thread()\n", parm);
576 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
579 struct afs_daemonop_args args;
581 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
587 cv_init(&args.cv, "AFS DaemonOp cond var", CV_DEFAULT, NULL);
589 if (thread_create(NULL, 0, afsd_thread, &args, 0, &p0, TS_RUN,
590 minclsyspri) == NULL) {
592 afs_warn("thread_create failed: AFS startup will not complete\n");
595 /* we passed &args to the new thread, which is on the stack. wait until
596 * it has read the arguments so it doesn't try to read the args after we
598 cv_wait(&args.cv, &afs_global_lock);
600 cv_destroy(&args.cv);
602 #endif /* AFS_SUN5_ENV */
604 #ifdef AFS_DARWIN100_ENV
605 # define AFSKPTR(X) k ## X
607 afs_syscall_call(long parm, long parm2, long parm3,
608 long parm4, long parm5, long parm6)
610 return afs_syscall64_call(CAST_USER_ADDR_T((parm)),
611 CAST_USER_ADDR_T((parm2)),
612 CAST_USER_ADDR_T((parm3)),
613 CAST_USER_ADDR_T((parm4)),
614 CAST_USER_ADDR_T((parm5)),
615 CAST_USER_ADDR_T((parm6)));
618 # define AFSKPTR(X) ((caddr_t)X)
621 #ifdef AFS_DARWIN100_ENV
622 afs_syscall64_call(user_addr_t kparm, user_addr_t kparm2, user_addr_t kparm3,
623 user_addr_t kparm4, user_addr_t kparm5, user_addr_t kparm6)
625 afs_syscall_call(long parm, long parm2, long parm3,
626 long parm4, long parm5, long parm6)
630 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
632 #else /* AFS_SGI61_ENV */
634 #endif /* AFS_SGI61_ENV */
635 #ifdef AFS_DARWIN100_ENV
636 /* AFSKPTR macro relies on this name format/mapping */
637 afs_uint32 parm = (afs_uint32)kparm;
638 afs_uint32 parm2 = (afs_uint32)kparm2;
639 afs_uint32 parm3 = (afs_uint32)kparm3;
640 afs_uint32 parm4 = (afs_uint32)kparm4;
641 afs_uint32 parm5 = (afs_uint32)kparm5;
642 afs_uint32 parm6 = (afs_uint32)kparm6;
645 AFS_STATCNT(afs_syscall_call);
652 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
653 /* only root can run this code */
654 #if defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
655 # if defined(KERNEL_HAVE_UERROR)
663 #ifdef AFS_DARWIN80_ENV
669 #ifdef AFS_DARWIN80_ENV
672 #ifdef AFS_DAEMONOP_ENV
673 # if defined(AFS_NEW_BKG)
674 if (parm == AFSOP_BKG_HANDLER) {
675 /* if afs_uspc_param grows this should be checked */
676 struct afs_uspc_param *mvParam = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
681 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)mvParam,
682 sizeof(struct afs_uspc_param), code);
683 namebufsz = mvParam->bufSz;
684 param1 = afs_osi_Alloc(namebufsz);
685 osi_Assert(param1 != NULL);
686 param2 = afs_osi_Alloc(namebufsz);
687 osi_Assert(param2 != NULL);
689 while (afs_initState < AFSOP_START_BKG)
690 afs_osi_Sleep(&afs_initState);
691 if (afs_initState < AFSOP_GO) {
692 afs_initState = AFSOP_GO;
693 afs_osi_Wakeup(&afs_initState);
696 code = afs_BackgroundDaemon(mvParam, param1, param2);
700 /* for reqs where pointers are strings: */
701 if (mvParam->reqtype == AFS_USPC_UMV) {
702 /* don't copy out random kernel memory */
703 AFS_COPYOUT(param2, AFSKPTR(parm4),
704 MIN(namebufsz, strlen((char *)param2)+1), code);
705 AFS_COPYOUT(param1, AFSKPTR(parm3),
706 MIN(namebufsz, strlen((char *)param1)+1), code);
708 AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
709 sizeof(struct afs_uspc_param), code);
712 afs_osi_Free(param1, namebufsz);
713 afs_osi_Free(param2, namebufsz);
714 osi_FreeSmallSpace(mvParam);
716 # endif /* AFS_NEW_BKG */
717 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
718 || parm == AFSOP_RXLISTENER_DAEMON) {
719 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
721 #else /* !AFS_DAEMONOP_ENV */
722 if (parm == AFSOP_START_RXCALLBACK) {
726 # ifndef RXK_LISTENER_ENV
727 code = afs_InitSetup(parm2);
729 # endif /* !RXK_LISTENER_ENV */
731 # ifdef RXK_LISTENER_ENV
732 while (afs_RX_Running != 2)
733 afs_osi_Sleep(&afs_RX_Running);
734 # else /* !RXK_LISTENER_ENV */
736 rx_enablePeerRPCStats();
739 rx_enableProcessRPCStats();
741 afs_initState = AFSOP_START_AFS;
742 afs_osi_Wakeup(&afs_initState);
743 # endif /* RXK_LISTENER_ENV */
745 afs_RXCallBackServer();
750 exit(CLD_EXITED, code);
751 # endif /* AFS_SGI_ENV */
753 # ifdef RXK_LISTENER_ENV
754 else if (parm == AFSOP_RXLISTENER_DAEMON) {
758 code = afs_InitSetup(parm2);
760 rx_enablePeerRPCStats();
763 rx_enableProcessRPCStats();
766 afs_initState = AFSOP_START_AFS;
767 afs_osi_Wakeup(&afs_initState);
770 afs_osi_Wakeup(&afs_RX_Running);
772 afs_osi_RxkRegister();
773 # endif /* !UKERNEL */
779 exit(CLD_EXITED, code);
780 # endif /* AFS_SGI_ENV */
782 # endif /* RXK_LISTENER_ENV */
783 else if (parm == AFSOP_START_AFS) {
788 while (afs_initState < AFSOP_START_AFS)
789 afs_osi_Sleep(&afs_initState);
791 afs_initState = AFSOP_START_BKG;
792 afs_osi_Wakeup(&afs_initState);
799 # endif /* AFS_SGI_ENV */
800 } else if (parm == AFSOP_START_CS) {
802 afs_CheckServerDaemon();
807 # endif /* AFS_SGI_ENV */
809 } else if (parm == AFSOP_START_BKG) {
810 while (afs_initState < AFSOP_START_BKG)
811 afs_osi_Sleep(&afs_initState);
812 if (afs_initState < AFSOP_GO) {
813 afs_initState = AFSOP_GO;
814 afs_osi_Wakeup(&afs_initState);
816 /* start the bkg daemon */
818 # ifdef AFS_AIX32_ENV
820 afs_BioDaemon(parm2);
822 # endif /* AFS_AIX32_ENV */
823 afs_BackgroundDaemon();
828 # endif /* AFS_SGI_ENV */
829 # endif /* ! AFS_NEW_BKG */
830 } else if (parm == AFSOP_START_TRUNCDAEMON) {
831 while (afs_initState < AFSOP_GO)
832 afs_osi_Sleep(&afs_initState);
833 /* start the bkg daemon */
835 afs_CacheTruncateDaemon();
840 # endif /* AFS_SGI_ENV */
842 # if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
843 else if (parm == AFSOP_RXEVENT_DAEMON) {
844 while (afs_initState < AFSOP_START_BKG)
845 afs_osi_Sleep(&afs_initState);
847 afs_rxevent_daemon();
852 # endif /* AFS_SGI_ENV */
854 # endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV || RXK_UPCALL_ENV */
855 #endif /* AFS_DAEMONOP_ENV */
856 else if (parm == AFSOP_BASIC_INIT) {
859 while (!afs_InitSetup_done)
860 afs_osi_Sleep(&afs_InitSetup_done);
862 #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)
863 temp = AFS_MINBUFFERS; /* Should fix this soon */
865 /* number of 2k buffers we could get from all of the buffer space */
866 temp = ((afs_bufferpages * NBPG) >> 11);
867 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
868 if (temp < AFS_MINBUFFERS)
869 temp = AFS_MINBUFFERS; /* though we really should have this many */
872 afs_rootFid.Fid.Volume = 0;
874 } else if (parm == AFSOP_BUCKETPCT) {
875 /* need to enable this now, will disable again before GO
876 if we don't have 100% */
886 } else if (parm == AFSOP_ADDCELL) {
887 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
888 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
889 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
890 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
892 osi_Assert(tcell != NULL);
893 code = afs_InitDynroot();
895 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
899 if (parm4 > sizeof(tcell->cellName))
902 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)tcell->cellName, parm4, code);
904 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
908 afs_osi_Free(tcell, sizeof(struct afsop_cell));
909 } else if (parm == AFSOP_ADDCELL2) {
910 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
911 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
912 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
915 osi_Assert(tcell != NULL);
916 osi_Assert(tbuffer != NULL);
917 osi_Assert(tbuffer1 != NULL);
918 code = afs_InitDynroot();
921 /* wait for basic init - XXX can't find any reason we need this? */
922 while (afs_initState < AFSOP_START_BKG)
923 afs_osi_Sleep(&afs_initState);
926 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
930 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
934 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
938 cflags |= CLinkedCell;
946 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
950 afs_osi_Free(tcell, sizeof(struct afsop_cell));
951 osi_FreeSmallSpace(tbuffer);
952 osi_FreeSmallSpace(tbuffer1);
953 } else if (parm == AFSOP_ADDCELLALIAS) {
956 * parm2 is the alias name
957 * parm3 is the real cell name
959 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
960 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
962 code = afs_InitDynroot();
964 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
968 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
971 afs_NewCellAlias(aliasName, cellName);
972 osi_FreeSmallSpace(aliasName);
973 osi_FreeSmallSpace(cellName);
974 } else if (parm == AFSOP_SET_THISCELL) {
977 * parm2 is the primary cell name
979 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
982 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
984 afs_SetPrimaryCell(cell);
985 osi_FreeSmallSpace(cell);
987 code = afs_InitDynroot();
989 } else if (parm == AFSOP_CACHEINIT) {
990 struct afs_cacheParams cparms;
992 if (afs_CacheInit_Done)
995 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
997 #if defined(KERNEL_HAVE_UERROR)
1003 afs_CacheInit_Done = 1;
1004 code = afs_icl_InitLogs();
1005 if (cparms.setTimeFlag) {
1006 afs_warn("afs: AFSOP_CACHEINIT setTimeFlag ignored; are you "
1007 "running an old afsd?\n");
1011 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
1012 cparms.cacheBlocks, cparms.cacheDcaches,
1013 cparms.cacheVolumes, cparms.chunkSize,
1014 cparms.memCacheFlag, cparms.inodes, cparms.users,
1015 cparms.dynamic_vcaches);
1017 } else if (parm == AFSOP_CACHEINODE) {
1018 ino_t ainode = parm2;
1019 /* wait for basic init */
1020 while (afs_initState < AFSOP_START_BKG)
1021 afs_osi_Sleep(&afs_initState);
1023 #ifdef AFS_DARWIN80_ENV
1026 /* do it by inode */
1027 #ifdef AFS_SGI62_ENV
1028 ainode = (ainode << 32) | (parm3 & 0xffffffff);
1030 code = afs_InitCacheFile(NULL, ainode);
1031 #ifdef AFS_DARWIN80_ENV
1034 } else if (parm == AFSOP_CACHEDIRS) {
1035 afs_numfilesperdir = parm2;
1036 afs_osi_Wakeup(&afs_initState);
1037 } else if (parm == AFSOP_CACHEFILES) {
1038 afs_numcachefiles = parm2;
1039 afs_osi_Wakeup(&afs_initState);
1040 } else if (parm == AFSOP_ROOTVOLUME) {
1041 /* wait for basic init */
1042 while (afs_initState < AFSOP_START_BKG)
1043 afs_osi_Sleep(&afs_initState);
1046 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
1047 sizeof(afs_rootVolumeName), &bufferSize, code);
1048 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
1051 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
1052 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
1053 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
1056 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
1059 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
1060 /* We have the cache dir copied in. Call the cache init routine */
1061 #ifdef AFS_DARWIN80_ENV
1064 if (parm == AFSOP_CACHEFILE) {
1065 code = afs_InitCacheFile(tbuffer, 0);
1066 } else if (parm == AFSOP_CACHEINFO) {
1067 code = afs_InitCacheInfo(tbuffer);
1068 } else if (parm == AFSOP_VOLUMEINFO) {
1069 code = afs_InitVolumeInfo(tbuffer);
1070 } else if (parm == AFSOP_CELLINFO) {
1071 code = afs_InitCellInfo(tbuffer);
1073 #ifdef AFS_DARWIN80_ENV
1077 osi_FreeSmallSpace(tbuffer);
1078 } else if (parm == AFSOP_GO) {
1079 /* the generic initialization calls come here. One parameter: should we do the
1080 * set-time operation on this workstation */
1084 while (afs_initState < AFSOP_GO)
1085 afs_osi_Sleep(&afs_initState);
1086 afs_initState = 101;
1088 /* parm2 used to set afs_setTime */
1089 afs_warn("afs: AFSOP_GO setTime flag ignored; are you running an "
1092 if (afs_tpct1 + afs_tpct2 != 100) {
1099 afs_osi_Wakeup(&afs_initState);
1100 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
1101 afs_nfsclient_init();
1103 if (afs_uuid_create(&afs_cb_interface.uuid) != 0)
1104 memset(&afs_cb_interface.uuid, 0, sizeof(afsUUID));
1106 printf("found %d non-empty cache files (%d%%).\n",
1107 afs_stats_cmperf.cacheFilesReused,
1108 (100 * afs_stats_cmperf.cacheFilesReused) /
1109 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
1110 cacheNumEntries : 1));
1111 } else if (parm == AFSOP_ADVISEADDR) {
1112 /* pass in the host address to the rx package */
1116 afs_int32 count = parm2;
1118 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1119 afs_int32 *maskbuffer =
1120 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1121 afs_int32 *mtubuffer =
1122 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1125 osi_Assert(buffer != NULL);
1126 osi_Assert(maskbuffer != NULL);
1127 osi_Assert(mtubuffer != NULL);
1128 /* This is a refresh */
1129 if (count & 0x40000000) {
1130 count &= ~0x40000000;
1131 /* Can't bind after we start. Fix? */
1132 count &= ~0x80000000;
1136 /* Bind, but only if there's only one address configured */
1137 if ( count & 0x80000000) {
1138 count &= ~0x80000000;
1143 if (count > AFS_MAX_INTERFACE_ADDR) {
1145 count = AFS_MAX_INTERFACE_ADDR;
1148 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
1151 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
1152 count * sizeof(afs_int32), code);
1154 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
1155 count * sizeof(afs_int32), code);
1158 afs_cb_interface.numberOfInterfaces = count;
1159 for (i = 0; i < count; i++) {
1160 afs_cb_interface.addr_in[i] = buffer[i];
1161 #ifdef AFS_USERSPACE_IP_ADDR
1162 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
1163 * machines IP addresses when in the kernel (the in_ifaddr
1164 * struct is not available), so we pass the info in at
1165 * startup. We also pass in the subnetmask and mtu size. The
1166 * subnetmask is used when setting the rank:
1167 * afsi_SetServerIPRank(); and the mtu size is used when
1168 * finding the best mtu size. rxi_FindIfnet() is replaced
1169 * with rxi_Findcbi().
1171 afs_cb_interface.subnetmask[i] =
1172 (parm4 ? maskbuffer[i] : 0xffffffff);
1173 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1176 rxi_setaddr(buffer[0]);
1179 rx_bindhost = buffer[0];
1181 rx_bindhost = htonl(INADDR_ANY);
1187 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1188 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1189 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1192 afs_CheckServers(1, NULL); /* check down servers */
1193 afs_CheckServers(0, NULL); /* check up servers */
1196 else if (parm == AFSOP_SHUTDOWN) {
1197 afs_cold_shutdown = 0;
1199 afs_cold_shutdown = 1;
1200 if (afs_globalVFS != 0) {
1201 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1205 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1207 vfsmount(parm2, parm3, parm4, parm5);
1208 #else /* defined(AFS_HPUX_ENV) */
1209 # if defined(KERNEL_HAVE_UERROR)
1214 #endif /* defined(AFS_HPUX_ENV) */
1215 } else if (parm == AFSOP_CLOSEWAIT) {
1216 afs_SynchronousCloses = 'S';
1217 } else if (parm == AFSOP_GETMTU) {
1219 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1220 # ifdef AFS_USERSPACE_IP_ADDR
1222 i = rxi_Findcbi(parm2);
1223 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1224 # else /* AFS_USERSPACE_IP_ADDR */
1227 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1228 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1229 # endif /* else AFS_USERSPACE_IP_ADDR */
1230 #endif /* !AFS_SUN5_ENV */
1232 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1233 sizeof(afs_int32), code);
1234 #ifdef AFS_AIX32_ENV
1235 /* this is disabled for now because I can't figure out how to get access
1236 * to these kernel variables. It's only for supporting user-mode rx
1237 * programs -- it makes a huge difference on the 220's in my testbed,
1238 * though I don't know why. The bosserver does this with /etc/no, so it's
1239 * being handled a different way for the servers right now. */
1241 static adjusted = 0;
1242 extern u_long sb_max_dflt;
1245 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1246 if (sb_max < 131072) sb_max = 131072;
1249 #endif /* AFS_AIX32_ENV */
1250 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1251 afs_uint32 mask = 0;
1252 #if !defined(AFS_SUN5_ENV)
1253 # ifdef AFS_USERSPACE_IP_ADDR
1255 i = rxi_Findcbi(parm2);
1257 mask = afs_cb_interface.subnetmask[i];
1261 # else /* AFS_USERSPACE_IP_ADDR */
1264 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1267 # endif /* else AFS_USERSPACE_IP_ADDR */
1268 #endif /* !AFS_SUN5_ENV */
1270 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1271 sizeof(afs_int32), code);
1273 else if (parm == AFSOP_AFSDB_HANDLER) {
1274 int sizeArg = (int)parm4;
1275 int kmsgLen = sizeArg & 0xffff;
1276 int cellLen = (sizeArg & 0xffff0000) >> 16;
1277 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1278 char *cellname = afs_osi_Alloc(cellLen);
1280 osi_Assert(kmsg != NULL);
1281 osi_Assert(cellname != NULL);
1283 afs_osi_MaskUserLoop();
1285 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1286 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1288 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1291 if (code == -2) { /* Shutting down? */
1297 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1298 afs_osi_Free(kmsg, kmsgLen);
1299 afs_osi_Free(cellname, cellLen);
1301 else if (parm == AFSOP_SET_DYNROOT) {
1302 code = afs_SetDynrootEnable(parm2);
1303 } else if (parm == AFSOP_SET_FAKESTAT) {
1304 afs_fakestat_enable = parm2;
1306 } else if (parm == AFSOP_SET_BACKUPTREE) {
1307 afs_bkvolpref = parm2;
1308 } else if (parm == AFSOP_SET_RXPCK) {
1309 rx_extraPackets = parm2;
1310 afscall_set_rxpck_received = 1;
1311 } else if (parm == AFSOP_SET_RXMAXMTU) {
1312 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1313 } else if (parm == AFSOP_SET_RXMAXFRAGS) {
1314 rxi_nSendFrags = rxi_nRecvFrags = parm2;
1315 } else if (parm == AFSOP_SET_RMTSYS_FLAG) {
1316 afs_rmtsys_enable = parm2;
1319 } else if (parm == AFSOP_SEED_ENTROPY) {
1320 unsigned char *seedbuf;
1325 seedbuf = afs_osi_Alloc(parm3);
1326 AFS_COPYIN(AFSKPTR(parm2), seedbuf, parm3, code);
1327 RAND_seed(seedbuf, parm3);
1328 memset(seedbuf, 0, parm3);
1329 afs_osi_Free(seedbuf, parm3);
1338 #ifdef AFS_LINUX20_ENV
1346 * Initstate in the range 0 < x < 100 are early initialization states.
1347 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1348 * the cache may be initialized.
1349 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1350 * is done after all the cache initialization has been done.
1351 * Initstate of 200 means that the volume has been looked up once, possibly
1353 * Initstate of 300 means that the volume has been *successfully* looked up.
1360 AFS_STATCNT(afs_CheckInit);
1361 if (afs_initState <= 100)
1362 code = ENXIO; /* never finished init phase */
1363 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1364 while (afs_initState < 200)
1365 afs_osi_Sleep(&afs_initState);
1366 } else if (afs_initState == 200)
1367 code = ETIMEDOUT; /* didn't find root volume */
1371 int afs_shuttingdown = 0;
1375 extern short afs_brsDaemons;
1376 extern afs_int32 afs_CheckServerDaemonStarted;
1377 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1378 extern struct osi_file *afs_cacheInodep;
1380 AFS_STATCNT(afs_shutdown);
1381 if (afs_initState == 0) {
1382 afs_warn("AFS not initialized - not shutting down\n");
1386 if (afs_shuttingdown)
1389 /* Give up all of our callbacks if we can. This must be done before setting
1390 * afs_shuttingdown, since it calls afs_InitReq, which will fail if
1391 * afs_shuttingdown is set. */
1394 afs_shuttingdown = 1;
1396 if (afs_cold_shutdown)
1397 afs_warn("afs: COLD ");
1399 afs_warn("afs: WARM ");
1400 afs_warn("shutting down of: vcaches... ");
1402 #if !defined(AFS_FBSD_ENV)
1403 /* The FBSD afs_unmount() calls vflush(), which reclaims all vnodes
1404 * on the mountpoint, flushing them in the process. In the presence
1405 * of bugs, flushing again here can cause panics. */
1406 afs_FlushAllVCaches();
1409 afs_termState = AFSOP_STOP_BKG;
1411 afs_warn("BkG... ");
1412 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1413 while (afs_termState == AFSOP_STOP_BKG) {
1414 afs_osi_Wakeup(&afs_brsDaemons);
1415 afs_osi_Sleep(&afs_termState);
1420 afs_termState = AFSOP_STOP_RXCALLBACK;
1421 rx_WakeupServerProcs();
1422 #ifdef AFS_AIX51_ENV
1423 shutdown_rxkernel();
1425 /* close rx server connections here? */
1426 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1427 afs_osi_Sleep(&afs_termState);
1429 afs_warn("afs... ");
1430 while (afs_termState == AFSOP_STOP_AFS) {
1431 afs_osi_CancelWait(&AFS_WaitHandler);
1432 afs_osi_Sleep(&afs_termState);
1434 if (afs_CheckServerDaemonStarted) {
1435 while (afs_termState == AFSOP_STOP_CS) {
1436 afs_osi_CancelWait(&AFS_CSWaitHandler);
1437 afs_osi_Sleep(&afs_termState);
1440 afs_warn("CTrunc... ");
1441 /* Cancel cache truncate daemon. */
1442 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1443 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1444 afs_osi_Sleep(&afs_termState);
1446 afs_warn("AFSDB... ");
1448 while (afs_termState == AFSOP_STOP_AFSDB)
1449 afs_osi_Sleep(&afs_termState);
1450 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
1451 afs_warn("RxEvent... ");
1452 /* cancel rx event daemon */
1453 while (afs_termState == AFSOP_STOP_RXEVENT)
1454 afs_osi_Sleep(&afs_termState);
1455 # if defined(RXK_LISTENER_ENV)
1457 afs_warn("UnmaskRxkSignals... ");
1458 afs_osi_UnmaskRxkSignals();
1460 /* cancel rx listener */
1461 afs_warn("RxListener... ");
1462 osi_StopListener(); /* This closes rx_socket. */
1463 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1464 afs_warn("Sleep... ");
1465 afs_osi_Sleep(&afs_termState);
1470 #if defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
1471 afs_warn("NetIfPoller... ");
1472 osi_StopNetIfPoller();
1475 afs_termState = AFSOP_STOP_COMPLETE;
1477 #ifdef AFS_AIX51_ENV
1481 shutdown_bufferpackage();
1485 * Close file only after daemons which can write to it are stopped.
1486 * Need to close before the osinet shutdown to avoid failing check
1487 * for dangling memory allocations.
1489 if (afs_cacheInodep) { /* memcache won't set this */
1490 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1491 afs_cacheInodep = 0;
1494 * Shutdown the ICL logs - needed to free allocated memory space and avoid
1495 * warnings from shutdown_osinet
1500 shutdown_vnodeops();
1501 shutdown_memcache();
1503 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV))
1504 shutdown_exporter();
1509 /* The following hold the cm stats */
1510 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1511 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1512 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1513 afs_warn(" ALL allocated tables... ");
1515 afs_shuttingdown = 0;
1518 return; /* Just kill daemons for now */
1522 shutdown_afstest(void)
1524 AFS_STATCNT(shutdown_afstest);
1525 afs_initState = afs_termState = 0;
1526 AFS_Running = afs_CB_Running = 0;
1527 afs_CacheInit_Done = afs_Go_Done = 0;
1528 if (afs_cold_shutdown) {
1529 *afs_rootVolumeName = 0;