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];
80 afs_int32 afs_rmtsys_enable = 0;
82 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
83 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
84 afs_int32 afs_rx_idledead = AFS_IDLEDEADTIME;
85 afs_int32 afs_rx_idledead_rep = AFS_IDLEDEADTIME_REP;
87 static int afscall_set_rxpck_received = 0;
89 #if defined(AFS_HPUX_ENV)
90 extern int afs_vfs_mount();
91 #endif /* defined(AFS_HPUX_ENV) */
93 /* This is code which needs to be called once when the first daemon enters
94 * the client. A non-zero return means an error and AFS should not start.
97 afs_InitSetup(int preallocs)
101 if (afs_InitSetup_done)
104 #ifdef AFS_SUN510_ENV
105 /* Initialize a RW lock for the ifinfo global array */
106 rw_init(&afsifinfo_lock, NULL, RW_DRIVER, NULL);
109 afs_taskq = ddi_taskq_create(NULL, "afs_taskq", 2, TASKQ_DEFAULTPRI, 0);
111 osi_StartNetIfPoller();
116 * Set up all the AFS statistics variables. This should be done
117 * exactly once, and it should be done here, the first resource-setting
118 * routine to be called by the CM/RX.
121 #endif /* AFS_NOSTATS */
123 memset(afs_zeros, 0, AFS_ZEROS);
125 rx_SetBusyChannelError(1); /* turn on busy call error reporting */
128 if(!afscall_set_rxpck_received)
129 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
130 code = rx_InitHost(rx_bindhost, htons(7001));
132 afs_warn("AFS: RX failed to initialize %d).\n", code);
135 rx_SetRxDeadTime(afs_rx_deadtime);
136 /* resource init creates the services */
137 afs_ResourceInit(preallocs);
139 afs_InitSetup_done = 1;
140 afs_osi_Wakeup(&afs_InitSetup_done);
145 #ifdef AFS_DAEMONOP_ENV
147 daemonOp_common(long parm, long parm2, long parm3, long parm4, long parm5,
151 if (parm == AFSOP_START_RXCALLBACK) {
154 # ifdef RXK_LISTENER_ENV
155 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
160 code = afs_InitSetup(parm2);
162 rx_enablePeerRPCStats();
165 rx_enableProcessRPCStats();
169 } else if (parm == AFSOP_START_AFS) {
172 } /* other functions don't need setup in the parent */
175 #endif /* AFS_DAEMONOP_ENV */
177 #if defined(AFS_DARWIN80_ENV)
178 struct afsd_thread_info {
182 afsd_thread(int *rock)
184 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
185 unsigned long parm = arg->parm;
188 case AFSOP_START_RXCALLBACK:
192 #ifndef RXK_LISTENER_ENV
193 afs_initState = AFSOP_START_AFS;
194 afs_osi_Wakeup(&afs_initState);
196 while (afs_RX_Running != 2)
197 afs_osi_Sleep(&afs_RX_Running);
199 afs_RXCallBackServer();
201 thread_terminate(current_thread());
203 case AFSOP_START_AFS:
207 while (afs_initState < AFSOP_START_AFS)
208 afs_osi_Sleep(&afs_initState);
209 afs_initState = AFSOP_START_BKG;
210 afs_osi_Wakeup(&afs_initState);
213 thread_terminate(current_thread());
215 case AFSOP_START_BKG:
216 afs_warn("Install matching afsd! Old background daemons not supported.\n");
217 thread_terminate(current_thread());
219 case AFSOP_START_TRUNCDAEMON:
222 while (afs_initState < AFSOP_GO)
223 afs_osi_Sleep(&afs_initState);
224 afs_CacheTruncateDaemon();
226 thread_terminate(current_thread());
231 afs_CheckServerDaemon();
233 thread_terminate(current_thread());
235 case AFSOP_RXEVENT_DAEMON:
238 while (afs_initState < AFSOP_START_BKG)
239 afs_osi_Sleep(&afs_initState);
240 afs_rxevent_daemon();
242 thread_terminate(current_thread());
244 #ifdef RXK_LISTENER_ENV
245 case AFSOP_RXLISTENER_DAEMON:
248 afs_initState = AFSOP_START_AFS;
249 afs_osi_Wakeup(&afs_initState);
251 afs_osi_Wakeup(&afs_RX_Running);
252 afs_osi_RxkRegister();
255 thread_terminate(current_thread());
259 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
265 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
268 struct afsd_thread_info info;
270 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
274 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
276 /* we need to wait cause we passed stack pointers around.... */
277 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
279 thread_deallocate(thread);
284 #if defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)
285 struct afsd_thread_info {
286 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
287 struct work_struct tq;
290 struct completion *complete;
294 afsd_thread(void *rock)
296 struct afsd_thread_info *arg = rock;
297 unsigned long parm = arg->parm;
298 # ifdef SYS_SETPRIORITY_EXPORTED
299 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
301 # if !defined(HAVE_LINUX_KTHREAD_RUN)
302 # if defined(AFS_LINUX26_ENV)
307 # endif /* !HAVE_LINUX_KTHREAD_RUN */
308 /* doesn't do much, since we were forked from keventd, but
309 * does call mm_release, which wakes up our parent (since it
310 * used CLONE_VFORK) */
311 # if !defined(AFS_LINUX26_ENV)
314 afs_osi_MaskSignals();
316 case AFSOP_START_RXCALLBACK:
317 sprintf(current->comm, "afs_cbstart");
319 complete(arg->complete);
321 #if !defined(RXK_LISTENER_ENV)
322 afs_initState = AFSOP_START_AFS;
323 afs_osi_Wakeup(&afs_initState);
325 while (afs_RX_Running != 2)
326 afs_osi_Sleep(&afs_RX_Running);
328 sprintf(current->comm, "afs_callback");
329 afs_RXCallBackServer();
331 complete_and_exit(0, 0);
333 case AFSOP_START_AFS:
334 sprintf(current->comm, "afs_afsstart");
336 complete(arg->complete);
338 while (afs_initState < AFSOP_START_AFS)
339 afs_osi_Sleep(&afs_initState);
340 afs_initState = AFSOP_START_BKG;
341 afs_osi_Wakeup(&afs_initState);
342 sprintf(current->comm, "afsd");
345 complete_and_exit(0, 0);
347 case AFSOP_START_BKG:
349 afs_warn("Install matching afsd! Old background daemons not supported.\n");
351 sprintf(current->comm, "afs_bkgstart");
353 complete(arg->complete);
354 while (afs_initState < AFSOP_START_BKG)
355 afs_osi_Sleep(&afs_initState);
356 if (afs_initState < AFSOP_GO) {
357 afs_initState = AFSOP_GO;
358 afs_osi_Wakeup(&afs_initState);
360 sprintf(current->comm, "afs_background");
361 afs_BackgroundDaemon();
364 complete_and_exit(0, 0);
366 case AFSOP_START_TRUNCDAEMON:
367 sprintf(current->comm, "afs_trimstart");
369 complete(arg->complete);
370 while (afs_initState < AFSOP_GO)
371 afs_osi_Sleep(&afs_initState);
372 sprintf(current->comm, "afs_cachetrim");
373 afs_CacheTruncateDaemon();
375 complete_and_exit(0, 0);
378 sprintf(current->comm, "afs_checkserver");
380 complete(arg->complete);
381 afs_CheckServerDaemon();
383 complete_and_exit(0, 0);
385 case AFSOP_RXEVENT_DAEMON:
386 sprintf(current->comm, "afs_evtstart");
387 # ifdef SYS_SETPRIORITY_EXPORTED
388 sys_setpriority(PRIO_PROCESS, 0, -10);
390 # ifdef CURRENT_INCLUDES_NICE
395 complete(arg->complete);
396 while (afs_initState < AFSOP_START_BKG)
397 afs_osi_Sleep(&afs_initState);
398 sprintf(current->comm, "afs_rxevent");
399 afs_rxevent_daemon();
401 complete_and_exit(0, 0);
403 #ifdef RXK_LISTENER_ENV
404 case AFSOP_RXLISTENER_DAEMON:
405 sprintf(current->comm, "afs_lsnstart");
406 # ifdef SYS_SETPRIORITY_EXPORTED
407 sys_setpriority(PRIO_PROCESS, 0, -10);
409 # ifdef CURRENT_INCLUDES_NICE
414 complete(arg->complete);
415 afs_initState = AFSOP_START_AFS;
416 afs_osi_Wakeup(&afs_initState);
418 afs_osi_Wakeup(&afs_RX_Running);
419 afs_osi_RxkRegister();
420 sprintf(current->comm, "afs_rxlistener");
423 complete_and_exit(0, 0);
427 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
434 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
435 afsd_launcher(struct work_struct *work)
437 afsd_launcher(void *rock)
440 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
441 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
444 # if defined(HAVE_LINUX_KTHREAD_RUN)
445 if (IS_ERR(kthread_run(afsd_thread, (void *)rock, "afsd"))) {
446 afs_warn("kthread_run failed; afs startup will not complete\n");
448 # else /* !HAVE_LINUX_KTHREAD_RUN */
449 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
450 afs_warn("kernel_thread failed. afs startup will not complete\n");
451 # endif /* !HAVE_LINUX_KTHREAD_RUN */
455 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
458 DECLARE_COMPLETION(c);
459 # if defined(AFS_LINUX26_ENV)
460 # if defined(INIT_WORK_HAS_DATA)
461 struct work_struct tq;
466 struct afsd_thread_info info;
467 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
472 # if defined(AFS_LINUX26_ENV)
473 # if !defined(INIT_WORK_HAS_DATA)
474 INIT_WORK(&info.tq, afsd_launcher);
475 schedule_work(&info.tq);
477 INIT_WORK(&tq, afsd_launcher, &info);
482 INIT_LIST_HEAD(&tq.list);
483 tq.routine = afsd_launcher;
488 /* we need to wait cause we passed stack pointers around.... */
489 wait_for_completion(&c);
495 struct afs_daemonop_args {
501 afsd_thread(struct afs_daemonop_args *args)
503 long parm = args->parm;
506 cv_signal(&args->cv);
509 case AFSOP_START_RXCALLBACK:
513 while (afs_RX_Running != 2)
514 afs_osi_Sleep(&afs_RX_Running);
515 afs_RXCallBackServer();
518 case AFSOP_START_AFS:
522 while (afs_initState < AFSOP_START_AFS)
523 afs_osi_Sleep(&afs_initState);
524 afs_initState = AFSOP_START_BKG;
525 afs_osi_Wakeup(&afs_initState);
529 case AFSOP_START_BKG:
530 while (afs_initState < AFSOP_START_BKG)
531 afs_osi_Sleep(&afs_initState);
532 if (afs_initState < AFSOP_GO) {
533 afs_initState = AFSOP_GO;
534 afs_osi_Wakeup(&afs_initState);
536 afs_BackgroundDaemon();
539 case AFSOP_START_TRUNCDAEMON:
540 while (afs_initState < AFSOP_GO)
541 afs_osi_Sleep(&afs_initState);
542 afs_CacheTruncateDaemon();
546 afs_CheckServerDaemon();
549 case AFSOP_RXEVENT_DAEMON:
550 while (afs_initState < AFSOP_START_BKG)
551 afs_osi_Sleep(&afs_initState);
552 afs_rxevent_daemon();
555 case AFSOP_RXLISTENER_DAEMON:
556 afs_initState = AFSOP_START_AFS;
557 afs_osi_Wakeup(&afs_initState);
559 afs_osi_Wakeup(&afs_RX_Running);
560 afs_osi_RxkRegister();
566 afs_warn("Unknown op %ld in afsd_thread()\n", parm);
575 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
578 struct afs_daemonop_args args;
580 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
586 cv_init(&args.cv, "AFS DaemonOp cond var", CV_DEFAULT, NULL);
588 if (thread_create(NULL, 0, afsd_thread, &args, 0, &p0, TS_RUN,
589 minclsyspri) == NULL) {
591 afs_warn("thread_create failed: AFS startup will not complete\n");
594 /* we passed &args to the new thread, which is on the stack. wait until
595 * it has read the arguments so it doesn't try to read the args after we
597 cv_wait(&args.cv, &afs_global_lock);
599 cv_destroy(&args.cv);
601 #endif /* AFS_SUN5_ENV */
603 #ifdef AFS_DARWIN100_ENV
604 # define AFSKPTR(X) k ## X
606 afs_syscall_call(long parm, long parm2, long parm3,
607 long parm4, long parm5, long parm6)
609 return afs_syscall64_call(CAST_USER_ADDR_T((parm)),
610 CAST_USER_ADDR_T((parm2)),
611 CAST_USER_ADDR_T((parm3)),
612 CAST_USER_ADDR_T((parm4)),
613 CAST_USER_ADDR_T((parm5)),
614 CAST_USER_ADDR_T((parm6)));
617 # define AFSKPTR(X) ((caddr_t)X)
620 #ifdef AFS_DARWIN100_ENV
621 afs_syscall64_call(user_addr_t kparm, user_addr_t kparm2, user_addr_t kparm3,
622 user_addr_t kparm4, user_addr_t kparm5, user_addr_t kparm6)
624 afs_syscall_call(long parm, long parm2, long parm3,
625 long parm4, long parm5, long parm6)
629 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
631 #else /* AFS_SGI61_ENV */
633 #endif /* AFS_SGI61_ENV */
634 #ifdef AFS_DARWIN100_ENV
635 /* AFSKPTR macro relies on this name format/mapping */
636 afs_uint32 parm = (afs_uint32)kparm;
637 afs_uint32 parm2 = (afs_uint32)kparm2;
638 afs_uint32 parm3 = (afs_uint32)kparm3;
639 afs_uint32 parm4 = (afs_uint32)kparm4;
640 afs_uint32 parm5 = (afs_uint32)kparm5;
641 afs_uint32 parm6 = (afs_uint32)kparm6;
644 AFS_STATCNT(afs_syscall_call);
651 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
652 /* only root can run this code */
653 #if defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
654 # if defined(KERNEL_HAVE_UERROR)
662 #ifdef AFS_DARWIN80_ENV
668 #ifdef AFS_DARWIN80_ENV
671 #ifdef AFS_DAEMONOP_ENV
672 # if defined(AFS_NEW_BKG)
673 if (parm == AFSOP_BKG_HANDLER) {
674 /* if afs_uspc_param grows this should be checked */
675 struct afs_uspc_param *mvParam = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
680 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)mvParam,
681 sizeof(struct afs_uspc_param), code);
682 namebufsz = mvParam->bufSz;
683 param1 = afs_osi_Alloc(namebufsz);
684 osi_Assert(param1 != NULL);
685 param2 = afs_osi_Alloc(namebufsz);
686 osi_Assert(param2 != NULL);
688 while (afs_initState < AFSOP_START_BKG)
689 afs_osi_Sleep(&afs_initState);
690 if (afs_initState < AFSOP_GO) {
691 afs_initState = AFSOP_GO;
692 afs_osi_Wakeup(&afs_initState);
695 code = afs_BackgroundDaemon(mvParam, param1, param2);
699 /* for reqs where pointers are strings: */
700 if (mvParam->reqtype == AFS_USPC_UMV) {
701 /* don't copy out random kernel memory */
702 AFS_COPYOUT(param2, AFSKPTR(parm4),
703 MIN(namebufsz, strlen((char *)param2)+1), code);
704 AFS_COPYOUT(param1, AFSKPTR(parm3),
705 MIN(namebufsz, strlen((char *)param1)+1), code);
707 AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
708 sizeof(struct afs_uspc_param), code);
711 afs_osi_Free(param1, namebufsz);
712 afs_osi_Free(param2, namebufsz);
713 osi_FreeSmallSpace(mvParam);
715 # endif /* AFS_NEW_BKG */
716 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
717 || parm == AFSOP_RXLISTENER_DAEMON) {
718 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
720 #else /* !AFS_DAEMONOP_ENV */
721 if (parm == AFSOP_START_RXCALLBACK) {
725 # ifndef RXK_LISTENER_ENV
726 code = afs_InitSetup(parm2);
728 # endif /* !RXK_LISTENER_ENV */
730 # ifdef RXK_LISTENER_ENV
731 while (afs_RX_Running != 2)
732 afs_osi_Sleep(&afs_RX_Running);
733 # else /* !RXK_LISTENER_ENV */
735 rx_enablePeerRPCStats();
738 rx_enableProcessRPCStats();
740 afs_initState = AFSOP_START_AFS;
741 afs_osi_Wakeup(&afs_initState);
742 # endif /* RXK_LISTENER_ENV */
744 afs_RXCallBackServer();
749 exit(CLD_EXITED, code);
750 # endif /* AFS_SGI_ENV */
752 # ifdef RXK_LISTENER_ENV
753 else if (parm == AFSOP_RXLISTENER_DAEMON) {
757 code = afs_InitSetup(parm2);
759 rx_enablePeerRPCStats();
762 rx_enableProcessRPCStats();
765 afs_initState = AFSOP_START_AFS;
766 afs_osi_Wakeup(&afs_initState);
769 afs_osi_Wakeup(&afs_RX_Running);
771 afs_osi_RxkRegister();
772 # endif /* !UKERNEL */
778 exit(CLD_EXITED, code);
779 # endif /* AFS_SGI_ENV */
781 # endif /* RXK_LISTENER_ENV */
782 else if (parm == AFSOP_START_AFS) {
787 while (afs_initState < AFSOP_START_AFS)
788 afs_osi_Sleep(&afs_initState);
790 afs_initState = AFSOP_START_BKG;
791 afs_osi_Wakeup(&afs_initState);
798 # endif /* AFS_SGI_ENV */
799 } else if (parm == AFSOP_START_CS) {
801 afs_CheckServerDaemon();
806 # endif /* AFS_SGI_ENV */
808 } else if (parm == AFSOP_START_BKG) {
809 while (afs_initState < AFSOP_START_BKG)
810 afs_osi_Sleep(&afs_initState);
811 if (afs_initState < AFSOP_GO) {
812 afs_initState = AFSOP_GO;
813 afs_osi_Wakeup(&afs_initState);
815 /* start the bkg daemon */
817 # ifdef AFS_AIX32_ENV
819 afs_BioDaemon(parm2);
821 # endif /* AFS_AIX32_ENV */
822 afs_BackgroundDaemon();
827 # endif /* AFS_SGI_ENV */
828 # endif /* ! AFS_NEW_BKG */
829 } else if (parm == AFSOP_START_TRUNCDAEMON) {
830 while (afs_initState < AFSOP_GO)
831 afs_osi_Sleep(&afs_initState);
832 /* start the bkg daemon */
834 afs_CacheTruncateDaemon();
839 # endif /* AFS_SGI_ENV */
841 # if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
842 else if (parm == AFSOP_RXEVENT_DAEMON) {
843 while (afs_initState < AFSOP_START_BKG)
844 afs_osi_Sleep(&afs_initState);
846 afs_rxevent_daemon();
851 # endif /* AFS_SGI_ENV */
853 # endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV || RXK_UPCALL_ENV */
854 #endif /* AFS_DAEMONOP_ENV */
855 else if (parm == AFSOP_BASIC_INIT) {
858 while (!afs_InitSetup_done)
859 afs_osi_Sleep(&afs_InitSetup_done);
861 #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)
862 temp = AFS_MINBUFFERS; /* Should fix this soon */
864 /* number of 2k buffers we could get from all of the buffer space */
865 temp = ((afs_bufferpages * NBPG) >> 11);
866 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
867 if (temp < AFS_MINBUFFERS)
868 temp = AFS_MINBUFFERS; /* though we really should have this many */
871 afs_rootFid.Fid.Volume = 0;
873 } else if (parm == AFSOP_BUCKETPCT) {
874 /* need to enable this now, will disable again before GO
875 if we don't have 100% */
885 } else if (parm == AFSOP_ADDCELL) {
886 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
887 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
888 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
889 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
891 osi_Assert(tcell != NULL);
892 code = afs_InitDynroot();
894 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
898 if (parm4 > sizeof(tcell->cellName))
901 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)tcell->cellName, parm4, code);
903 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
907 afs_osi_Free(tcell, sizeof(struct afsop_cell));
908 } else if (parm == AFSOP_ADDCELL2) {
909 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
910 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
911 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
914 osi_Assert(tcell != NULL);
915 osi_Assert(tbuffer != NULL);
916 osi_Assert(tbuffer1 != NULL);
917 code = afs_InitDynroot();
920 /* wait for basic init - XXX can't find any reason we need this? */
921 while (afs_initState < AFSOP_START_BKG)
922 afs_osi_Sleep(&afs_initState);
925 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
929 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
933 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
937 cflags |= CLinkedCell;
945 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
949 afs_osi_Free(tcell, sizeof(struct afsop_cell));
950 osi_FreeSmallSpace(tbuffer);
951 osi_FreeSmallSpace(tbuffer1);
952 } else if (parm == AFSOP_ADDCELLALIAS) {
955 * parm2 is the alias name
956 * parm3 is the real cell name
958 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
959 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
961 code = afs_InitDynroot();
963 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
967 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
970 afs_NewCellAlias(aliasName, cellName);
971 osi_FreeSmallSpace(aliasName);
972 osi_FreeSmallSpace(cellName);
973 } else if (parm == AFSOP_SET_THISCELL) {
976 * parm2 is the primary cell name
978 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
981 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
983 afs_SetPrimaryCell(cell);
984 osi_FreeSmallSpace(cell);
986 code = afs_InitDynroot();
988 } else if (parm == AFSOP_CACHEINIT) {
989 struct afs_cacheParams cparms;
991 if (afs_CacheInit_Done)
994 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
996 #if defined(KERNEL_HAVE_UERROR)
1002 afs_CacheInit_Done = 1;
1003 code = afs_icl_InitLogs();
1004 if (cparms.setTimeFlag) {
1005 afs_warn("afs: AFSOP_CACHEINIT setTimeFlag ignored; are you "
1006 "running an old afsd?\n");
1010 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
1011 cparms.cacheBlocks, cparms.cacheDcaches,
1012 cparms.cacheVolumes, cparms.chunkSize,
1013 cparms.memCacheFlag, cparms.inodes, cparms.users,
1014 cparms.dynamic_vcaches);
1016 } else if (parm == AFSOP_CACHEINODE) {
1017 ino_t ainode = parm2;
1018 /* wait for basic init */
1019 while (afs_initState < AFSOP_START_BKG)
1020 afs_osi_Sleep(&afs_initState);
1022 #ifdef AFS_DARWIN80_ENV
1025 /* do it by inode */
1026 #ifdef AFS_SGI62_ENV
1027 ainode = (ainode << 32) | (parm3 & 0xffffffff);
1029 code = afs_InitCacheFile(NULL, ainode);
1030 #ifdef AFS_DARWIN80_ENV
1033 } else if (parm == AFSOP_CACHEDIRS) {
1034 afs_numfilesperdir = parm2;
1035 afs_osi_Wakeup(&afs_initState);
1036 } else if (parm == AFSOP_CACHEFILES) {
1037 afs_numcachefiles = parm2;
1038 afs_osi_Wakeup(&afs_initState);
1039 } else if (parm == AFSOP_ROOTVOLUME) {
1040 /* wait for basic init */
1041 while (afs_initState < AFSOP_START_BKG)
1042 afs_osi_Sleep(&afs_initState);
1045 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
1046 sizeof(afs_rootVolumeName), &bufferSize, code);
1047 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
1050 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
1051 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
1052 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
1055 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
1058 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
1059 /* We have the cache dir copied in. Call the cache init routine */
1060 #ifdef AFS_DARWIN80_ENV
1063 if (parm == AFSOP_CACHEFILE) {
1064 code = afs_InitCacheFile(tbuffer, 0);
1065 } else if (parm == AFSOP_CACHEINFO) {
1066 code = afs_InitCacheInfo(tbuffer);
1067 } else if (parm == AFSOP_VOLUMEINFO) {
1068 code = afs_InitVolumeInfo(tbuffer);
1069 } else if (parm == AFSOP_CELLINFO) {
1070 code = afs_InitCellInfo(tbuffer);
1072 #ifdef AFS_DARWIN80_ENV
1076 osi_FreeSmallSpace(tbuffer);
1077 } else if (parm == AFSOP_GO) {
1078 /* the generic initialization calls come here. One parameter: should we do the
1079 * set-time operation on this workstation */
1083 while (afs_initState < AFSOP_GO)
1084 afs_osi_Sleep(&afs_initState);
1085 afs_initState = 101;
1087 /* parm2 used to set afs_setTime */
1088 afs_warn("afs: AFSOP_GO setTime flag ignored; are you running an "
1091 if (afs_tpct1 + afs_tpct2 != 100) {
1098 afs_osi_Wakeup(&afs_initState);
1099 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
1100 afs_nfsclient_init();
1102 if (afs_uuid_create(&afs_cb_interface.uuid) != 0)
1103 memset(&afs_cb_interface.uuid, 0, sizeof(afsUUID));
1105 printf("found %d non-empty cache files (%d%%).\n",
1106 afs_stats_cmperf.cacheFilesReused,
1107 (100 * afs_stats_cmperf.cacheFilesReused) /
1108 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
1109 cacheNumEntries : 1));
1110 } else if (parm == AFSOP_ADVISEADDR) {
1111 /* pass in the host address to the rx package */
1115 afs_int32 count = parm2;
1117 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1118 afs_int32 *maskbuffer =
1119 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1120 afs_int32 *mtubuffer =
1121 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1124 osi_Assert(buffer != NULL);
1125 osi_Assert(maskbuffer != NULL);
1126 osi_Assert(mtubuffer != NULL);
1127 /* This is a refresh */
1128 if (count & 0x40000000) {
1129 count &= ~0x40000000;
1130 /* Can't bind after we start. Fix? */
1131 count &= ~0x80000000;
1135 /* Bind, but only if there's only one address configured */
1136 if ( count & 0x80000000) {
1137 count &= ~0x80000000;
1142 if (count > AFS_MAX_INTERFACE_ADDR) {
1144 count = AFS_MAX_INTERFACE_ADDR;
1147 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
1150 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
1151 count * sizeof(afs_int32), code);
1153 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
1154 count * sizeof(afs_int32), code);
1157 afs_cb_interface.numberOfInterfaces = count;
1158 for (i = 0; i < count; i++) {
1159 afs_cb_interface.addr_in[i] = buffer[i];
1160 #ifdef AFS_USERSPACE_IP_ADDR
1161 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
1162 * machines IP addresses when in the kernel (the in_ifaddr
1163 * struct is not available), so we pass the info in at
1164 * startup. We also pass in the subnetmask and mtu size. The
1165 * subnetmask is used when setting the rank:
1166 * afsi_SetServerIPRank(); and the mtu size is used when
1167 * finding the best mtu size. rxi_FindIfnet() is replaced
1168 * with rxi_Findcbi().
1170 afs_cb_interface.subnetmask[i] =
1171 (parm4 ? maskbuffer[i] : 0xffffffff);
1172 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1175 rxi_setaddr(buffer[0]);
1178 rx_bindhost = buffer[0];
1180 rx_bindhost = htonl(INADDR_ANY);
1186 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1187 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1188 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1191 afs_CheckServers(1, NULL); /* check down servers */
1192 afs_CheckServers(0, NULL); /* check up servers */
1195 else if (parm == AFSOP_SHUTDOWN) {
1196 afs_cold_shutdown = 0;
1198 afs_cold_shutdown = 1;
1199 if (afs_globalVFS != 0) {
1200 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1204 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1206 vfsmount(parm2, parm3, parm4, parm5);
1207 #else /* defined(AFS_HPUX_ENV) */
1208 # if defined(KERNEL_HAVE_UERROR)
1213 #endif /* defined(AFS_HPUX_ENV) */
1214 } else if (parm == AFSOP_CLOSEWAIT) {
1215 afs_SynchronousCloses = 'S';
1216 } else if (parm == AFSOP_GETMTU) {
1218 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1219 # ifdef AFS_USERSPACE_IP_ADDR
1221 i = rxi_Findcbi(parm2);
1222 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1223 # else /* AFS_USERSPACE_IP_ADDR */
1226 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1227 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1228 # endif /* else AFS_USERSPACE_IP_ADDR */
1229 #endif /* !AFS_SUN5_ENV */
1231 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1232 sizeof(afs_int32), code);
1233 #ifdef AFS_AIX32_ENV
1234 /* this is disabled for now because I can't figure out how to get access
1235 * to these kernel variables. It's only for supporting user-mode rx
1236 * programs -- it makes a huge difference on the 220's in my testbed,
1237 * though I don't know why. The bosserver does this with /etc/no, so it's
1238 * being handled a different way for the servers right now. */
1240 static adjusted = 0;
1241 extern u_long sb_max_dflt;
1244 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1245 if (sb_max < 131072) sb_max = 131072;
1248 #endif /* AFS_AIX32_ENV */
1249 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1250 afs_uint32 mask = 0;
1251 #if !defined(AFS_SUN5_ENV)
1252 # ifdef AFS_USERSPACE_IP_ADDR
1254 i = rxi_Findcbi(parm2);
1256 mask = afs_cb_interface.subnetmask[i];
1260 # else /* AFS_USERSPACE_IP_ADDR */
1263 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1266 # endif /* else AFS_USERSPACE_IP_ADDR */
1267 #endif /* !AFS_SUN5_ENV */
1269 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1270 sizeof(afs_int32), code);
1272 else if (parm == AFSOP_AFSDB_HANDLER) {
1273 int sizeArg = (int)parm4;
1274 int kmsgLen = sizeArg & 0xffff;
1275 int cellLen = (sizeArg & 0xffff0000) >> 16;
1276 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1277 char *cellname = afs_osi_Alloc(cellLen);
1279 osi_Assert(kmsg != NULL);
1280 osi_Assert(cellname != NULL);
1282 afs_osi_MaskUserLoop();
1284 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1285 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1287 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1290 if (code == -2) { /* Shutting down? */
1296 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1297 afs_osi_Free(kmsg, kmsgLen);
1298 afs_osi_Free(cellname, cellLen);
1300 else if (parm == AFSOP_SET_DYNROOT) {
1301 code = afs_SetDynrootEnable(parm2);
1302 } else if (parm == AFSOP_SET_FAKESTAT) {
1303 afs_fakestat_enable = parm2;
1305 } else if (parm == AFSOP_SET_BACKUPTREE) {
1306 afs_bkvolpref = parm2;
1307 } else if (parm == AFSOP_SET_RXPCK) {
1308 rx_extraPackets = parm2;
1309 afscall_set_rxpck_received = 1;
1310 } else if (parm == AFSOP_SET_RXMAXMTU) {
1311 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1312 } else if (parm == AFSOP_SET_RXMAXFRAGS) {
1313 rxi_nSendFrags = rxi_nRecvFrags = parm2;
1314 } else if (parm == AFSOP_SET_RMTSYS_FLAG) {
1315 afs_rmtsys_enable = 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;