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);
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 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
1058 /* We have the cache dir copied in. Call the cache init routine */
1059 #ifdef AFS_DARWIN80_ENV
1062 if (parm == AFSOP_CACHEFILE) {
1063 code = afs_InitCacheFile(tbuffer, 0);
1064 } else if (parm == AFSOP_CACHEINFO) {
1065 code = afs_InitCacheInfo(tbuffer);
1066 } else if (parm == AFSOP_VOLUMEINFO) {
1067 code = afs_InitVolumeInfo(tbuffer);
1068 } else if (parm == AFSOP_CELLINFO) {
1069 code = afs_InitCellInfo(tbuffer);
1071 #ifdef AFS_DARWIN80_ENV
1075 osi_FreeSmallSpace(tbuffer);
1076 } else if (parm == AFSOP_GO) {
1077 /* the generic initialization calls come here. One parameter: should we do the
1078 * set-time operation on this workstation */
1082 while (afs_initState < AFSOP_GO)
1083 afs_osi_Sleep(&afs_initState);
1084 afs_initState = 101;
1086 /* parm2 used to set afs_setTime */
1087 afs_warn("afs: AFSOP_GO setTime flag ignored; are you running an "
1090 if (afs_tpct1 + afs_tpct2 != 100) {
1097 afs_osi_Wakeup(&afs_initState);
1098 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
1099 afs_nfsclient_init();
1101 if (afs_uuid_create(&afs_cb_interface.uuid) != 0)
1102 memset(&afs_cb_interface.uuid, 0, sizeof(afsUUID));
1104 printf("found %d non-empty cache files (%d%%).\n",
1105 afs_stats_cmperf.cacheFilesReused,
1106 (100 * afs_stats_cmperf.cacheFilesReused) /
1107 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
1108 cacheNumEntries : 1));
1109 } else if (parm == AFSOP_ADVISEADDR) {
1110 /* pass in the host address to the rx package */
1114 afs_int32 count = parm2;
1116 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1117 afs_int32 *maskbuffer =
1118 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1119 afs_int32 *mtubuffer =
1120 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1123 osi_Assert(buffer != NULL);
1124 osi_Assert(maskbuffer != NULL);
1125 osi_Assert(mtubuffer != NULL);
1126 /* This is a refresh */
1127 if (count & 0x40000000) {
1128 count &= ~0x40000000;
1129 /* Can't bind after we start. Fix? */
1130 count &= ~0x80000000;
1134 /* Bind, but only if there's only one address configured */
1135 if ( count & 0x80000000) {
1136 count &= ~0x80000000;
1141 if (count > AFS_MAX_INTERFACE_ADDR) {
1143 count = AFS_MAX_INTERFACE_ADDR;
1146 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
1149 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
1150 count * sizeof(afs_int32), code);
1152 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
1153 count * sizeof(afs_int32), code);
1156 afs_cb_interface.numberOfInterfaces = count;
1157 for (i = 0; i < count; i++) {
1158 afs_cb_interface.addr_in[i] = buffer[i];
1159 #ifdef AFS_USERSPACE_IP_ADDR
1160 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
1161 * machines IP addresses when in the kernel (the in_ifaddr
1162 * struct is not available), so we pass the info in at
1163 * startup. We also pass in the subnetmask and mtu size. The
1164 * subnetmask is used when setting the rank:
1165 * afsi_SetServerIPRank(); and the mtu size is used when
1166 * finding the best mtu size. rxi_FindIfnet() is replaced
1167 * with rxi_Findcbi().
1169 afs_cb_interface.subnetmask[i] =
1170 (parm4 ? maskbuffer[i] : 0xffffffff);
1171 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1174 rxi_setaddr(buffer[0]);
1177 rx_bindhost = buffer[0];
1179 rx_bindhost = htonl(INADDR_ANY);
1185 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1186 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1187 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1190 afs_CheckServers(1, NULL); /* check down servers */
1191 afs_CheckServers(0, NULL); /* check up servers */
1194 else if (parm == AFSOP_SHUTDOWN) {
1195 afs_cold_shutdown = 0;
1197 afs_cold_shutdown = 1;
1198 if (afs_globalVFS != 0) {
1199 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1203 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1205 vfsmount(parm2, parm3, parm4, parm5);
1206 #else /* defined(AFS_HPUX_ENV) */
1207 # if defined(KERNEL_HAVE_UERROR)
1212 #endif /* defined(AFS_HPUX_ENV) */
1213 } else if (parm == AFSOP_CLOSEWAIT) {
1214 afs_SynchronousCloses = 'S';
1215 } else if (parm == AFSOP_GETMTU) {
1217 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1218 # ifdef AFS_USERSPACE_IP_ADDR
1220 i = rxi_Findcbi(parm2);
1221 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1222 # else /* AFS_USERSPACE_IP_ADDR */
1225 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1226 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1227 # endif /* else AFS_USERSPACE_IP_ADDR */
1228 #endif /* !AFS_SUN5_ENV */
1230 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1231 sizeof(afs_int32), code);
1232 #ifdef AFS_AIX32_ENV
1233 /* this is disabled for now because I can't figure out how to get access
1234 * to these kernel variables. It's only for supporting user-mode rx
1235 * programs -- it makes a huge difference on the 220's in my testbed,
1236 * though I don't know why. The bosserver does this with /etc/no, so it's
1237 * being handled a different way for the servers right now. */
1239 static adjusted = 0;
1240 extern u_long sb_max_dflt;
1243 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1244 if (sb_max < 131072) sb_max = 131072;
1247 #endif /* AFS_AIX32_ENV */
1248 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1249 afs_uint32 mask = 0;
1250 #if !defined(AFS_SUN5_ENV)
1251 # ifdef AFS_USERSPACE_IP_ADDR
1253 i = rxi_Findcbi(parm2);
1255 mask = afs_cb_interface.subnetmask[i];
1259 # else /* AFS_USERSPACE_IP_ADDR */
1262 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1265 # endif /* else AFS_USERSPACE_IP_ADDR */
1266 #endif /* !AFS_SUN5_ENV */
1268 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1269 sizeof(afs_int32), code);
1271 else if (parm == AFSOP_AFSDB_HANDLER) {
1272 int sizeArg = (int)parm4;
1273 int kmsgLen = sizeArg & 0xffff;
1274 int cellLen = (sizeArg & 0xffff0000) >> 16;
1275 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1276 char *cellname = afs_osi_Alloc(cellLen);
1278 osi_Assert(kmsg != NULL);
1279 osi_Assert(cellname != NULL);
1281 afs_osi_MaskUserLoop();
1283 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1284 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1286 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1289 if (code == -2) { /* Shutting down? */
1295 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1296 afs_osi_Free(kmsg, kmsgLen);
1297 afs_osi_Free(cellname, cellLen);
1299 else if (parm == AFSOP_SET_DYNROOT) {
1300 code = afs_SetDynrootEnable(parm2);
1301 } else if (parm == AFSOP_SET_FAKESTAT) {
1302 afs_fakestat_enable = parm2;
1304 } else if (parm == AFSOP_SET_BACKUPTREE) {
1305 afs_bkvolpref = parm2;
1306 } else if (parm == AFSOP_SET_RXPCK) {
1307 rx_extraPackets = parm2;
1308 afscall_set_rxpck_received = 1;
1309 } else if (parm == AFSOP_SET_RXMAXMTU) {
1310 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1311 } else if (parm == AFSOP_SET_RXMAXFRAGS) {
1312 rxi_nSendFrags = rxi_nRecvFrags = parm2;
1313 } else if (parm == AFSOP_SET_RMTSYS_FLAG) {
1314 afs_rmtsys_enable = parm2;
1317 } else if (parm == AFSOP_SEED_ENTROPY) {
1318 unsigned char *seedbuf;
1323 seedbuf = afs_osi_Alloc(parm3);
1324 AFS_COPYIN(AFSKPTR(parm2), seedbuf, parm3, code);
1325 RAND_seed(seedbuf, parm3);
1326 memset(seedbuf, 0, parm3);
1327 afs_osi_Free(seedbuf, parm3);
1336 #ifdef AFS_LINUX20_ENV
1344 * Initstate in the range 0 < x < 100 are early initialization states.
1345 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1346 * the cache may be initialized.
1347 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1348 * is done after all the cache initialization has been done.
1349 * Initstate of 200 means that the volume has been looked up once, possibly
1351 * Initstate of 300 means that the volume has been *successfully* looked up.
1358 AFS_STATCNT(afs_CheckInit);
1359 if (afs_initState <= 100)
1360 code = ENXIO; /* never finished init phase */
1361 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1362 while (afs_initState < 200)
1363 afs_osi_Sleep(&afs_initState);
1364 } else if (afs_initState == 200)
1365 code = ETIMEDOUT; /* didn't find root volume */
1369 enum afs_shutdown_state afs_shuttingdown = AFS_RUNNING;
1373 extern short afs_brsDaemons;
1374 extern afs_int32 afs_CheckServerDaemonStarted;
1375 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1376 extern struct osi_file *afs_cacheInodep;
1378 AFS_STATCNT(afs_shutdown);
1379 if (afs_initState == 0) {
1380 afs_warn("AFS not initialized - not shutting down\n");
1384 if (afs_shuttingdown != AFS_RUNNING)
1387 afs_shuttingdown = AFS_FLUSHING_CB;
1389 /* Give up all of our callbacks if we can. */
1392 afs_shuttingdown = AFS_SHUTDOWN;
1394 if (afs_cold_shutdown)
1395 afs_warn("afs: COLD ");
1397 afs_warn("afs: WARM ");
1398 afs_warn("shutting down of: vcaches... ");
1400 #if !defined(AFS_FBSD_ENV)
1401 /* The FBSD afs_unmount() calls vflush(), which reclaims all vnodes
1402 * on the mountpoint, flushing them in the process. In the presence
1403 * of bugs, flushing again here can cause panics. */
1404 afs_FlushAllVCaches();
1407 afs_termState = AFSOP_STOP_BKG;
1409 afs_warn("BkG... ");
1410 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1411 while (afs_termState == AFSOP_STOP_BKG) {
1412 afs_osi_Wakeup(&afs_brsDaemons);
1413 afs_osi_Sleep(&afs_termState);
1418 afs_termState = AFSOP_STOP_RXCALLBACK;
1419 rx_WakeupServerProcs();
1420 #ifdef AFS_AIX51_ENV
1421 shutdown_rxkernel();
1423 /* close rx server connections here? */
1424 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1425 afs_osi_Sleep(&afs_termState);
1427 afs_warn("afs... ");
1428 while (afs_termState == AFSOP_STOP_AFS) {
1429 afs_osi_CancelWait(&AFS_WaitHandler);
1430 afs_osi_Sleep(&afs_termState);
1432 if (afs_CheckServerDaemonStarted) {
1433 while (afs_termState == AFSOP_STOP_CS) {
1434 afs_osi_CancelWait(&AFS_CSWaitHandler);
1435 afs_osi_Sleep(&afs_termState);
1438 afs_warn("CTrunc... ");
1439 /* Cancel cache truncate daemon. */
1440 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1441 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1442 afs_osi_Sleep(&afs_termState);
1444 afs_warn("AFSDB... ");
1446 while (afs_termState == AFSOP_STOP_AFSDB)
1447 afs_osi_Sleep(&afs_termState);
1448 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
1449 afs_warn("RxEvent... ");
1450 /* cancel rx event daemon */
1451 while (afs_termState == AFSOP_STOP_RXEVENT)
1452 afs_osi_Sleep(&afs_termState);
1453 # if defined(RXK_LISTENER_ENV)
1455 afs_warn("UnmaskRxkSignals... ");
1456 afs_osi_UnmaskRxkSignals();
1458 /* cancel rx listener */
1459 afs_warn("RxListener... ");
1460 osi_StopListener(); /* This closes rx_socket. */
1461 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1462 afs_warn("Sleep... ");
1463 afs_osi_Sleep(&afs_termState);
1468 #if defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
1469 afs_warn("NetIfPoller... ");
1470 osi_StopNetIfPoller();
1473 afs_termState = AFSOP_STOP_COMPLETE;
1475 #ifdef AFS_AIX51_ENV
1479 shutdown_bufferpackage();
1483 * Close file only after daemons which can write to it are stopped.
1484 * Need to close before the osinet shutdown to avoid failing check
1485 * for dangling memory allocations.
1487 if (afs_cacheInodep) { /* memcache won't set this */
1488 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1489 afs_cacheInodep = 0;
1492 * Shutdown the ICL logs - needed to free allocated memory space and avoid
1493 * warnings from shutdown_osinet
1498 shutdown_vnodeops();
1499 shutdown_memcache();
1501 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV))
1502 shutdown_exporter();
1507 /* The following hold the cm stats */
1508 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1509 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1510 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1511 afs_warn(" ALL allocated tables... ");
1513 afs_shuttingdown = AFS_RUNNING;
1516 return; /* Just kill daemons for now */
1520 shutdown_afstest(void)
1522 AFS_STATCNT(shutdown_afstest);
1523 afs_initState = afs_termState = 0;
1524 AFS_Running = afs_CB_Running = 0;
1525 afs_CacheInit_Done = afs_Go_Done = 0;
1526 if (afs_cold_shutdown) {
1527 *afs_rootVolumeName = 0;