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_LINUX26_ENV) || 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;
91 extern afs_int32 afs_md5inum;
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);
126 if(!afscall_set_rxpck_received)
127 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
128 code = rx_InitHost(rx_bindhost, htons(7001));
130 afs_warn("AFS: RX failed to initialize %d).\n", code);
133 rx_SetRxDeadTime(afs_rx_deadtime);
134 /* resource init creates the services */
135 afs_ResourceInit(preallocs);
137 afs_InitSetup_done = 1;
138 afs_osi_Wakeup(&afs_InitSetup_done);
143 #ifdef AFS_DAEMONOP_ENV
145 daemonOp_common(long parm, long parm2, long parm3, long parm4, long parm5,
149 if (parm == AFSOP_START_RXCALLBACK) {
152 # ifdef RXK_LISTENER_ENV
153 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
158 code = afs_InitSetup(parm2);
160 rx_enablePeerRPCStats();
163 rx_enableProcessRPCStats();
167 } else if (parm == AFSOP_START_AFS) {
170 } /* other functions don't need setup in the parent */
173 #endif /* AFS_DAEMONOP_ENV */
175 #if defined(AFS_DARWIN80_ENV)
176 struct afsd_thread_info {
180 afsd_thread(int *rock)
182 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
183 unsigned long parm = arg->parm;
186 case AFSOP_START_RXCALLBACK:
190 #ifndef RXK_LISTENER_ENV
191 afs_initState = AFSOP_START_AFS;
192 afs_osi_Wakeup(&afs_initState);
194 while (afs_RX_Running != 2)
195 afs_osi_Sleep(&afs_RX_Running);
197 afs_RXCallBackServer();
199 thread_terminate(current_thread());
201 case AFSOP_START_AFS:
205 while (afs_initState < AFSOP_START_AFS)
206 afs_osi_Sleep(&afs_initState);
207 afs_initState = AFSOP_START_BKG;
208 afs_osi_Wakeup(&afs_initState);
211 thread_terminate(current_thread());
213 case AFSOP_START_BKG:
214 afs_warn("Install matching afsd! Old background daemons not supported.\n");
215 thread_terminate(current_thread());
217 case AFSOP_START_TRUNCDAEMON:
220 while (afs_initState < AFSOP_GO)
221 afs_osi_Sleep(&afs_initState);
222 afs_CacheTruncateDaemon();
224 thread_terminate(current_thread());
229 afs_CheckServerDaemon();
231 thread_terminate(current_thread());
233 case AFSOP_RXEVENT_DAEMON:
236 while (afs_initState < AFSOP_START_BKG)
237 afs_osi_Sleep(&afs_initState);
238 afs_rxevent_daemon();
240 thread_terminate(current_thread());
242 #ifdef RXK_LISTENER_ENV
243 case AFSOP_RXLISTENER_DAEMON:
246 afs_initState = AFSOP_START_AFS;
247 afs_osi_Wakeup(&afs_initState);
249 afs_osi_Wakeup(&afs_RX_Running);
250 afs_osi_RxkRegister();
253 thread_terminate(current_thread());
257 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
263 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
266 struct afsd_thread_info info;
268 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
272 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
274 /* we need to wait cause we passed stack pointers around.... */
275 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
277 thread_deallocate(thread);
282 #if defined(AFS_LINUX26_ENV)
283 struct afsd_thread_info {
284 # if !defined(INIT_WORK_HAS_DATA)
285 struct work_struct tq;
288 struct completion *complete;
292 afsd_thread(void *rock)
294 struct afsd_thread_info *arg = rock;
295 unsigned long parm = arg->parm;
296 # ifdef SYS_SETPRIORITY_EXPORTED
297 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
299 # if !defined(HAVE_LINUX_KTHREAD_RUN)
300 # if defined(AFS_LINUX26_ENV)
305 # endif /* !HAVE_LINUX_KTHREAD_RUN */
306 /* doesn't do much, since we were forked from keventd, but
307 * does call mm_release, which wakes up our parent (since it
308 * used CLONE_VFORK) */
309 # if !defined(AFS_LINUX26_ENV)
312 afs_osi_MaskSignals();
314 case AFSOP_START_RXCALLBACK:
315 sprintf(current->comm, "afs_cbstart");
317 complete(arg->complete);
319 #if !defined(RXK_LISTENER_ENV)
320 afs_initState = AFSOP_START_AFS;
321 afs_osi_Wakeup(&afs_initState);
323 while (afs_RX_Running != 2)
324 afs_osi_Sleep(&afs_RX_Running);
326 sprintf(current->comm, "afs_callback");
327 afs_RXCallBackServer();
329 complete_and_exit(0, 0);
331 case AFSOP_START_AFS:
332 sprintf(current->comm, "afs_afsstart");
334 complete(arg->complete);
336 while (afs_initState < AFSOP_START_AFS)
337 afs_osi_Sleep(&afs_initState);
338 afs_initState = AFSOP_START_BKG;
339 afs_osi_Wakeup(&afs_initState);
340 sprintf(current->comm, "afsd");
343 complete_and_exit(0, 0);
345 case AFSOP_START_BKG:
347 afs_warn("Install matching afsd! Old background daemons not supported.\n");
349 sprintf(current->comm, "afs_bkgstart");
351 complete(arg->complete);
352 while (afs_initState < AFSOP_START_BKG)
353 afs_osi_Sleep(&afs_initState);
354 if (afs_initState < AFSOP_GO) {
355 afs_initState = AFSOP_GO;
356 afs_osi_Wakeup(&afs_initState);
358 sprintf(current->comm, "afs_background");
359 afs_BackgroundDaemon();
362 complete_and_exit(0, 0);
364 case AFSOP_START_TRUNCDAEMON:
365 sprintf(current->comm, "afs_trimstart");
367 complete(arg->complete);
368 while (afs_initState < AFSOP_GO)
369 afs_osi_Sleep(&afs_initState);
370 sprintf(current->comm, "afs_cachetrim");
371 afs_CacheTruncateDaemon();
373 complete_and_exit(0, 0);
376 sprintf(current->comm, "afs_checkserver");
378 complete(arg->complete);
379 afs_CheckServerDaemon();
381 complete_and_exit(0, 0);
383 case AFSOP_RXEVENT_DAEMON:
384 sprintf(current->comm, "afs_evtstart");
385 # ifdef SYS_SETPRIORITY_EXPORTED
386 sys_setpriority(PRIO_PROCESS, 0, -10);
388 # ifdef CURRENT_INCLUDES_NICE
393 complete(arg->complete);
394 while (afs_initState < AFSOP_START_BKG)
395 afs_osi_Sleep(&afs_initState);
396 sprintf(current->comm, "afs_rxevent");
397 afs_rxevent_daemon();
399 complete_and_exit(0, 0);
401 #ifdef RXK_LISTENER_ENV
402 case AFSOP_RXLISTENER_DAEMON:
403 sprintf(current->comm, "afs_lsnstart");
404 # ifdef SYS_SETPRIORITY_EXPORTED
405 sys_setpriority(PRIO_PROCESS, 0, -10);
407 # ifdef CURRENT_INCLUDES_NICE
412 complete(arg->complete);
413 afs_initState = AFSOP_START_AFS;
414 afs_osi_Wakeup(&afs_initState);
416 afs_osi_Wakeup(&afs_RX_Running);
417 afs_osi_RxkRegister();
418 sprintf(current->comm, "afs_rxlistener");
421 complete_and_exit(0, 0);
425 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
432 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
433 afsd_launcher(struct work_struct *work)
435 afsd_launcher(void *rock)
438 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
439 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
442 # if defined(HAVE_LINUX_KTHREAD_RUN)
443 if (IS_ERR(kthread_run(afsd_thread, (void *)rock, "afsd"))) {
444 afs_warn("kthread_run failed; afs startup will not complete\n");
446 # else /* !HAVE_LINUX_KTHREAD_RUN */
447 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
448 afs_warn("kernel_thread failed. afs startup will not complete\n");
449 # endif /* !HAVE_LINUX_KTHREAD_RUN */
453 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
456 DECLARE_COMPLETION(c);
457 # if defined(AFS_LINUX26_ENV)
458 # if defined(INIT_WORK_HAS_DATA)
459 struct work_struct tq;
464 struct afsd_thread_info info;
465 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
470 # if defined(AFS_LINUX26_ENV)
471 # if !defined(INIT_WORK_HAS_DATA)
472 INIT_WORK(&info.tq, afsd_launcher);
473 schedule_work(&info.tq);
475 INIT_WORK(&tq, afsd_launcher, &info);
480 INIT_LIST_HEAD(&tq.list);
481 tq.routine = afsd_launcher;
486 /* we need to wait cause we passed stack pointers around.... */
487 wait_for_completion(&c);
493 struct afs_daemonop_args {
499 afsd_thread(struct afs_daemonop_args *args)
501 long parm = args->parm;
504 cv_signal(&args->cv);
507 case AFSOP_START_RXCALLBACK:
511 while (afs_RX_Running != 2)
512 afs_osi_Sleep(&afs_RX_Running);
513 afs_RXCallBackServer();
516 case AFSOP_START_AFS:
520 while (afs_initState < AFSOP_START_AFS)
521 afs_osi_Sleep(&afs_initState);
522 afs_initState = AFSOP_START_BKG;
523 afs_osi_Wakeup(&afs_initState);
527 case AFSOP_START_BKG:
528 while (afs_initState < AFSOP_START_BKG)
529 afs_osi_Sleep(&afs_initState);
530 if (afs_initState < AFSOP_GO) {
531 afs_initState = AFSOP_GO;
532 afs_osi_Wakeup(&afs_initState);
534 afs_BackgroundDaemon();
537 case AFSOP_START_TRUNCDAEMON:
538 while (afs_initState < AFSOP_GO)
539 afs_osi_Sleep(&afs_initState);
540 afs_CacheTruncateDaemon();
544 afs_CheckServerDaemon();
547 case AFSOP_RXEVENT_DAEMON:
548 while (afs_initState < AFSOP_START_BKG)
549 afs_osi_Sleep(&afs_initState);
550 afs_rxevent_daemon();
553 case AFSOP_RXLISTENER_DAEMON:
554 afs_initState = AFSOP_START_AFS;
555 afs_osi_Wakeup(&afs_initState);
557 afs_osi_Wakeup(&afs_RX_Running);
558 afs_osi_RxkRegister();
564 afs_warn("Unknown op %ld in afsd_thread()\n", parm);
573 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
576 struct afs_daemonop_args args;
578 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
584 cv_init(&args.cv, "AFS DaemonOp cond var", CV_DEFAULT, NULL);
586 if (thread_create(NULL, 0, afsd_thread, &args, 0, &p0, TS_RUN,
587 minclsyspri) == NULL) {
589 afs_warn("thread_create failed: AFS startup will not complete\n");
592 /* we passed &args to the new thread, which is on the stack. wait until
593 * it has read the arguments so it doesn't try to read the args after we
595 cv_wait(&args.cv, &afs_global_lock);
597 cv_destroy(&args.cv);
599 #endif /* AFS_SUN5_ENV */
601 #ifdef AFS_DARWIN100_ENV
602 # define AFSKPTR(X) k ## X
604 afs_syscall_call(long parm, long parm2, long parm3,
605 long parm4, long parm5, long parm6)
607 return afs_syscall64_call(CAST_USER_ADDR_T((parm)),
608 CAST_USER_ADDR_T((parm2)),
609 CAST_USER_ADDR_T((parm3)),
610 CAST_USER_ADDR_T((parm4)),
611 CAST_USER_ADDR_T((parm5)),
612 CAST_USER_ADDR_T((parm6)));
615 # define AFSKPTR(X) ((caddr_t)X)
618 #ifdef AFS_DARWIN100_ENV
619 afs_syscall64_call(user_addr_t kparm, user_addr_t kparm2, user_addr_t kparm3,
620 user_addr_t kparm4, user_addr_t kparm5, user_addr_t kparm6)
622 afs_syscall_call(long parm, long parm2, long parm3,
623 long parm4, long parm5, long parm6)
627 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
629 #else /* AFS_SGI61_ENV */
631 #endif /* AFS_SGI61_ENV */
632 #ifdef AFS_DARWIN100_ENV
633 /* AFSKPTR macro relies on this name format/mapping */
634 afs_uint32 parm = (afs_uint32)kparm;
635 afs_uint32 parm2 = (afs_uint32)kparm2;
636 afs_uint32 parm3 = (afs_uint32)kparm3;
637 afs_uint32 parm4 = (afs_uint32)kparm4;
638 afs_uint32 parm5 = (afs_uint32)kparm5;
639 afs_uint32 parm6 = (afs_uint32)kparm6;
642 AFS_STATCNT(afs_syscall_call);
649 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
650 /* only root can run this code */
651 #if defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
652 # if defined(KERNEL_HAVE_UERROR)
660 #ifdef AFS_DARWIN80_ENV
666 #ifdef AFS_DARWIN80_ENV
669 #ifdef AFS_DAEMONOP_ENV
670 # if defined(AFS_NEW_BKG)
671 if (parm == AFSOP_BKG_HANDLER) {
672 /* if afs_uspc_param grows this should be checked */
673 struct afs_uspc_param *mvParam = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
678 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)mvParam,
679 sizeof(struct afs_uspc_param), code);
680 namebufsz = mvParam->bufSz;
681 param1 = afs_osi_Alloc(namebufsz);
682 osi_Assert(param1 != NULL);
683 param2 = afs_osi_Alloc(namebufsz);
684 osi_Assert(param2 != NULL);
686 while (afs_initState < AFSOP_START_BKG)
687 afs_osi_Sleep(&afs_initState);
688 if (afs_initState < AFSOP_GO) {
689 afs_initState = AFSOP_GO;
690 afs_osi_Wakeup(&afs_initState);
693 code = afs_BackgroundDaemon(mvParam, param1, param2);
697 /* for reqs where pointers are strings: */
698 if (mvParam->reqtype == AFS_USPC_UMV) {
699 /* don't copy out random kernel memory */
700 AFS_COPYOUT(param2, AFSKPTR(parm4),
701 MIN(namebufsz, strlen((char *)param2)+1), code);
702 AFS_COPYOUT(param1, AFSKPTR(parm3),
703 MIN(namebufsz, strlen((char *)param1)+1), code);
705 AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
706 sizeof(struct afs_uspc_param), code);
709 afs_osi_Free(param1, namebufsz);
710 afs_osi_Free(param2, namebufsz);
711 osi_FreeSmallSpace(mvParam);
713 # endif /* AFS_NEW_BKG */
714 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
715 || parm == AFSOP_RXLISTENER_DAEMON) {
716 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
718 #else /* !AFS_DAEMONOP_ENV */
719 if (parm == AFSOP_START_RXCALLBACK) {
723 # ifndef RXK_LISTENER_ENV
724 code = afs_InitSetup(parm2);
726 # endif /* !RXK_LISTENER_ENV */
728 # ifdef RXK_LISTENER_ENV
729 while (afs_RX_Running != 2)
730 afs_osi_Sleep(&afs_RX_Running);
731 # else /* !RXK_LISTENER_ENV */
733 rx_enablePeerRPCStats();
736 rx_enableProcessRPCStats();
738 afs_initState = AFSOP_START_AFS;
739 afs_osi_Wakeup(&afs_initState);
740 # endif /* RXK_LISTENER_ENV */
742 afs_RXCallBackServer();
747 exit(CLD_EXITED, code);
748 # endif /* AFS_SGI_ENV */
750 # ifdef RXK_LISTENER_ENV
751 else if (parm == AFSOP_RXLISTENER_DAEMON) {
755 code = afs_InitSetup(parm2);
757 rx_enablePeerRPCStats();
760 rx_enableProcessRPCStats();
763 afs_initState = AFSOP_START_AFS;
764 afs_osi_Wakeup(&afs_initState);
767 afs_osi_Wakeup(&afs_RX_Running);
769 afs_osi_RxkRegister();
770 # endif /* !UKERNEL */
776 exit(CLD_EXITED, code);
777 # endif /* AFS_SGI_ENV */
779 # endif /* RXK_LISTENER_ENV */
780 else if (parm == AFSOP_START_AFS) {
785 while (afs_initState < AFSOP_START_AFS)
786 afs_osi_Sleep(&afs_initState);
788 afs_initState = AFSOP_START_BKG;
789 afs_osi_Wakeup(&afs_initState);
796 # endif /* AFS_SGI_ENV */
797 } else if (parm == AFSOP_START_CS) {
799 afs_CheckServerDaemon();
804 # endif /* AFS_SGI_ENV */
806 } else if (parm == AFSOP_START_BKG) {
807 while (afs_initState < AFSOP_START_BKG)
808 afs_osi_Sleep(&afs_initState);
809 if (afs_initState < AFSOP_GO) {
810 afs_initState = AFSOP_GO;
811 afs_osi_Wakeup(&afs_initState);
813 /* start the bkg daemon */
815 # ifdef AFS_AIX32_ENV
817 afs_BioDaemon(parm2);
819 # endif /* AFS_AIX32_ENV */
820 afs_BackgroundDaemon();
825 # endif /* AFS_SGI_ENV */
826 # endif /* ! AFS_NEW_BKG */
827 } else if (parm == AFSOP_START_TRUNCDAEMON) {
828 while (afs_initState < AFSOP_GO)
829 afs_osi_Sleep(&afs_initState);
830 /* start the bkg daemon */
832 afs_CacheTruncateDaemon();
837 # endif /* AFS_SGI_ENV */
839 # if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
840 else if (parm == AFSOP_RXEVENT_DAEMON) {
841 while (afs_initState < AFSOP_START_BKG)
842 afs_osi_Sleep(&afs_initState);
844 afs_rxevent_daemon();
849 # endif /* AFS_SGI_ENV */
851 # endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV || RXK_UPCALL_ENV */
852 #endif /* AFS_DAEMONOP_ENV */
853 else if (parm == AFSOP_BASIC_INIT) {
856 while (!afs_InitSetup_done)
857 afs_osi_Sleep(&afs_InitSetup_done);
859 #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)
860 temp = AFS_MINBUFFERS; /* Should fix this soon */
862 /* number of 2k buffers we could get from all of the buffer space */
863 temp = ((afs_bufferpages * NBPG) >> 11);
864 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
865 if (temp < AFS_MINBUFFERS)
866 temp = AFS_MINBUFFERS; /* though we really should have this many */
869 afs_rootFid.Fid.Volume = 0;
871 } else if (parm == AFSOP_BUCKETPCT) {
872 /* need to enable this now, will disable again before GO
873 if we don't have 100% */
883 } else if (parm == AFSOP_ADDCELL) {
884 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
885 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
886 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
887 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
889 osi_Assert(tcell != NULL);
890 code = afs_InitDynroot();
892 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
896 if (parm4 > sizeof(tcell->cellName))
899 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)tcell->cellName, parm4, code);
901 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
905 afs_osi_Free(tcell, sizeof(struct afsop_cell));
906 } else if (parm == AFSOP_ADDCELL2) {
907 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
908 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
909 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
912 osi_Assert(tcell != NULL);
913 osi_Assert(tbuffer != NULL);
914 osi_Assert(tbuffer1 != NULL);
915 code = afs_InitDynroot();
917 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
921 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
925 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
929 cflags |= CLinkedCell;
937 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
941 afs_osi_Free(tcell, sizeof(struct afsop_cell));
942 osi_FreeSmallSpace(tbuffer);
943 osi_FreeSmallSpace(tbuffer1);
944 } else if (parm == AFSOP_ADDCELLALIAS) {
947 * parm2 is the alias name
948 * parm3 is the real cell name
950 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
951 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
953 code = afs_InitDynroot();
955 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
959 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
962 afs_NewCellAlias(aliasName, cellName);
963 osi_FreeSmallSpace(aliasName);
964 osi_FreeSmallSpace(cellName);
965 } else if (parm == AFSOP_SET_THISCELL) {
968 * parm2 is the primary cell name
970 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
973 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
975 afs_SetPrimaryCell(cell);
976 osi_FreeSmallSpace(cell);
978 code = afs_InitDynroot();
980 } else if (parm == AFSOP_CACHEINIT) {
981 struct afs_cacheParams cparms;
983 if (afs_CacheInit_Done)
986 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
988 #if defined(KERNEL_HAVE_UERROR)
994 afs_CacheInit_Done = 1;
995 code = afs_icl_InitLogs();
996 if (cparms.setTimeFlag) {
997 afs_warn("afs: AFSOP_CACHEINIT setTimeFlag ignored; are you "
998 "running an old afsd?\n");
1002 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
1003 cparms.cacheBlocks, cparms.cacheDcaches,
1004 cparms.cacheVolumes, cparms.chunkSize,
1005 cparms.memCacheFlag, cparms.inodes, cparms.users,
1006 cparms.dynamic_vcaches);
1008 } else if (parm == AFSOP_CACHEINODE) {
1009 ino_t ainode = parm2;
1010 /* wait for basic init */
1011 while (afs_initState < AFSOP_START_BKG)
1012 afs_osi_Sleep(&afs_initState);
1014 #ifdef AFS_DARWIN80_ENV
1017 /* do it by inode */
1018 #ifdef AFS_SGI62_ENV
1019 ainode = (ainode << 32) | (parm3 & 0xffffffff);
1021 code = afs_InitCacheFile(NULL, ainode);
1022 #ifdef AFS_DARWIN80_ENV
1025 } else if (parm == AFSOP_CACHEDIRS) {
1026 afs_numfilesperdir = parm2;
1027 afs_osi_Wakeup(&afs_initState);
1028 } else if (parm == AFSOP_CACHEFILES) {
1029 afs_numcachefiles = parm2;
1030 afs_osi_Wakeup(&afs_initState);
1031 } else if (parm == AFSOP_ROOTVOLUME) {
1032 /* wait for basic init */
1033 while (afs_initState < AFSOP_START_BKG)
1034 afs_osi_Sleep(&afs_initState);
1037 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
1038 sizeof(afs_rootVolumeName), &bufferSize, code);
1039 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
1042 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
1043 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
1044 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
1047 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
1050 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
1051 /* We have the cache dir copied in. Call the cache init routine */
1052 #ifdef AFS_DARWIN80_ENV
1055 if (parm == AFSOP_CACHEFILE) {
1056 code = afs_InitCacheFile(tbuffer, 0);
1057 } else if (parm == AFSOP_CACHEINFO) {
1058 code = afs_InitCacheInfo(tbuffer);
1059 } else if (parm == AFSOP_VOLUMEINFO) {
1060 code = afs_InitVolumeInfo(tbuffer);
1061 } else if (parm == AFSOP_CELLINFO) {
1062 code = afs_InitCellInfo(tbuffer);
1064 #ifdef AFS_DARWIN80_ENV
1068 osi_FreeSmallSpace(tbuffer);
1069 } else if (parm == AFSOP_GO) {
1070 /* the generic initialization calls come here. One parameter: should we do the
1071 * set-time operation on this workstation */
1075 while (afs_initState < AFSOP_GO)
1076 afs_osi_Sleep(&afs_initState);
1077 afs_initState = 101;
1079 /* parm2 used to set afs_setTime */
1080 afs_warn("afs: AFSOP_GO setTime flag ignored; are you running an "
1083 if (afs_tpct1 + afs_tpct2 != 100) {
1090 afs_osi_Wakeup(&afs_initState);
1091 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
1092 afs_nfsclient_init();
1094 if (afs_uuid_create(&afs_cb_interface.uuid) != 0)
1095 memset(&afs_cb_interface.uuid, 0, sizeof(afsUUID));
1097 printf("found %d non-empty cache files (%d%%).\n",
1098 afs_stats_cmperf.cacheFilesReused,
1099 (100 * afs_stats_cmperf.cacheFilesReused) /
1100 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
1101 cacheNumEntries : 1));
1102 } else if (parm == AFSOP_ADVISEADDR) {
1103 /* pass in the host address to the rx package */
1107 afs_int32 count = parm2;
1109 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1110 afs_int32 *maskbuffer =
1111 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1112 afs_int32 *mtubuffer =
1113 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1116 osi_Assert(buffer != NULL);
1117 osi_Assert(maskbuffer != NULL);
1118 osi_Assert(mtubuffer != NULL);
1119 /* This is a refresh */
1120 if (count & 0x40000000) {
1121 count &= ~0x40000000;
1122 /* Can't bind after we start. Fix? */
1123 count &= ~0x80000000;
1127 /* Bind, but only if there's only one address configured */
1128 if ( count & 0x80000000) {
1129 count &= ~0x80000000;
1134 if (count > AFS_MAX_INTERFACE_ADDR) {
1136 count = AFS_MAX_INTERFACE_ADDR;
1139 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
1142 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
1143 count * sizeof(afs_int32), code);
1145 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
1146 count * sizeof(afs_int32), code);
1149 afs_cb_interface.numberOfInterfaces = count;
1150 for (i = 0; i < count; i++) {
1151 afs_cb_interface.addr_in[i] = buffer[i];
1152 #ifdef AFS_USERSPACE_IP_ADDR
1153 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
1154 * machines IP addresses when in the kernel (the in_ifaddr
1155 * struct is not available), so we pass the info in at
1156 * startup. We also pass in the subnetmask and mtu size. The
1157 * subnetmask is used when setting the rank:
1158 * afsi_SetServerIPRank(); and the mtu size is used when
1159 * finding the best mtu size. rxi_FindIfnet() is replaced
1160 * with rxi_Findcbi().
1162 afs_cb_interface.subnetmask[i] =
1163 (parm4 ? maskbuffer[i] : 0xffffffff);
1164 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1167 rxi_setaddr(buffer[0]);
1170 rx_bindhost = buffer[0];
1172 rx_bindhost = htonl(INADDR_ANY);
1178 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1179 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1180 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1183 afs_CheckServers(1, NULL); /* check down servers */
1184 afs_CheckServers(0, NULL); /* check up servers */
1187 else if (parm == AFSOP_SHUTDOWN) {
1188 afs_cold_shutdown = 0;
1190 afs_cold_shutdown = 1;
1191 if (afs_globalVFS != 0) {
1192 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1196 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1198 vfsmount(parm2, parm3, parm4, parm5);
1199 #else /* defined(AFS_HPUX_ENV) */
1200 # if defined(KERNEL_HAVE_UERROR)
1205 #endif /* defined(AFS_HPUX_ENV) */
1206 } else if (parm == AFSOP_CLOSEWAIT) {
1207 afs_SynchronousCloses = 'S';
1208 } else if (parm == AFSOP_GETMTU) {
1210 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1211 # ifdef AFS_USERSPACE_IP_ADDR
1213 i = rxi_Findcbi(parm2);
1214 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1215 # else /* AFS_USERSPACE_IP_ADDR */
1218 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1219 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1220 # endif /* else AFS_USERSPACE_IP_ADDR */
1221 #endif /* !AFS_SUN5_ENV */
1223 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1224 sizeof(afs_int32), code);
1225 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1226 afs_uint32 mask = 0;
1227 #if !defined(AFS_SUN5_ENV)
1228 # ifdef AFS_USERSPACE_IP_ADDR
1230 i = rxi_Findcbi(parm2);
1232 mask = afs_cb_interface.subnetmask[i];
1236 # else /* AFS_USERSPACE_IP_ADDR */
1239 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1242 # endif /* else AFS_USERSPACE_IP_ADDR */
1243 #endif /* !AFS_SUN5_ENV */
1245 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1246 sizeof(afs_int32), code);
1248 else if (parm == AFSOP_AFSDB_HANDLER) {
1249 int sizeArg = (int)parm4;
1250 int kmsgLen = sizeArg & 0xffff;
1251 int cellLen = (sizeArg & 0xffff0000) >> 16;
1252 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1253 char *cellname = afs_osi_Alloc(cellLen);
1255 osi_Assert(kmsg != NULL);
1256 osi_Assert(cellname != NULL);
1258 afs_osi_MaskUserLoop();
1260 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1261 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1263 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1266 if (code == -2) { /* Shutting down? */
1272 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1273 afs_osi_Free(kmsg, kmsgLen);
1274 afs_osi_Free(cellname, cellLen);
1276 else if (parm == AFSOP_SET_DYNROOT) {
1277 code = afs_SetDynrootEnable(parm2);
1278 } else if (parm == AFSOP_SET_FAKESTAT) {
1279 afs_fakestat_enable = parm2;
1281 } else if (parm == AFSOP_SET_BACKUPTREE) {
1282 afs_bkvolpref = parm2;
1283 } else if (parm == AFSOP_SET_RXPCK) {
1284 rx_extraPackets = parm2;
1285 afscall_set_rxpck_received = 1;
1286 } else if (parm == AFSOP_SET_RXMAXMTU) {
1287 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1288 } else if (parm == AFSOP_SET_RXMAXFRAGS) {
1289 rxi_nSendFrags = rxi_nRecvFrags = parm2;
1290 } else if (parm == AFSOP_SET_RMTSYS_FLAG) {
1291 afs_rmtsys_enable = parm2;
1294 } else if (parm == AFSOP_SEED_ENTROPY) {
1295 unsigned char *seedbuf;
1300 seedbuf = afs_osi_Alloc(parm3);
1301 AFS_COPYIN(AFSKPTR(parm2), seedbuf, parm3, code);
1302 RAND_seed(seedbuf, parm3);
1303 memset(seedbuf, 0, parm3);
1304 afs_osi_Free(seedbuf, parm3);
1307 } else if (parm == AFSOP_SET_INUMCALC) {
1309 case AFS_INUMCALC_COMPAT:
1313 case AFS_INUMCALC_MD5:
1326 #ifdef AFS_LINUX20_ENV
1334 * Initstate in the range 0 < x < 100 are early initialization states.
1335 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1336 * the cache may be initialized.
1337 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1338 * is done after all the cache initialization has been done.
1339 * Initstate of 200 means that the volume has been looked up once, possibly
1341 * Initstate of 300 means that the volume has been *successfully* looked up.
1348 AFS_STATCNT(afs_CheckInit);
1349 if (afs_initState <= 100)
1350 code = ENXIO; /* never finished init phase */
1351 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1352 while (afs_initState < 200)
1353 afs_osi_Sleep(&afs_initState);
1354 } else if (afs_initState == 200)
1355 code = ETIMEDOUT; /* didn't find root volume */
1359 enum afs_shutdown_state afs_shuttingdown = AFS_RUNNING;
1363 extern short afs_brsDaemons;
1364 extern afs_int32 afs_CheckServerDaemonStarted;
1365 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1366 extern struct osi_file *afs_cacheInodep;
1368 AFS_STATCNT(afs_shutdown);
1369 if (afs_initState == 0) {
1370 afs_warn("AFS not initialized - not shutting down\n");
1374 if (afs_shuttingdown != AFS_RUNNING)
1377 afs_shuttingdown = AFS_FLUSHING_CB;
1379 /* Give up all of our callbacks if we can. */
1382 afs_shuttingdown = AFS_SHUTDOWN;
1384 if (afs_cold_shutdown)
1385 afs_warn("afs: COLD ");
1387 afs_warn("afs: WARM ");
1388 afs_warn("shutting down of: vcaches... ");
1390 #if !defined(AFS_FBSD_ENV)
1391 /* The FBSD afs_unmount() calls vflush(), which reclaims all vnodes
1392 * on the mountpoint, flushing them in the process. In the presence
1393 * of bugs, flushing again here can cause panics. */
1394 afs_FlushAllVCaches();
1397 afs_termState = AFSOP_STOP_BKG;
1399 afs_warn("BkG... ");
1400 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1401 while (afs_termState == AFSOP_STOP_BKG) {
1402 afs_osi_Wakeup(&afs_brsDaemons);
1403 afs_osi_Sleep(&afs_termState);
1408 afs_termState = AFSOP_STOP_RXCALLBACK;
1409 rx_WakeupServerProcs();
1410 #ifdef AFS_AIX51_ENV
1411 shutdown_rxkernel();
1413 /* close rx server connections here? */
1414 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1415 afs_osi_Sleep(&afs_termState);
1417 afs_warn("afs... ");
1418 while (afs_termState == AFSOP_STOP_AFS) {
1419 afs_osi_CancelWait(&AFS_WaitHandler);
1420 afs_osi_Sleep(&afs_termState);
1422 if (afs_CheckServerDaemonStarted) {
1423 while (afs_termState == AFSOP_STOP_CS) {
1424 afs_osi_CancelWait(&AFS_CSWaitHandler);
1425 afs_osi_Sleep(&afs_termState);
1428 afs_warn("CTrunc... ");
1429 /* Cancel cache truncate daemon. */
1430 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1431 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1432 afs_osi_Sleep(&afs_termState);
1434 afs_warn("AFSDB... ");
1436 while (afs_termState == AFSOP_STOP_AFSDB)
1437 afs_osi_Sleep(&afs_termState);
1438 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
1439 afs_warn("RxEvent... ");
1440 /* cancel rx event daemon */
1441 while (afs_termState == AFSOP_STOP_RXEVENT)
1442 afs_osi_Sleep(&afs_termState);
1443 # if defined(RXK_LISTENER_ENV)
1445 afs_warn("UnmaskRxkSignals... ");
1446 afs_osi_UnmaskRxkSignals();
1448 /* cancel rx listener */
1449 afs_warn("RxListener... ");
1450 osi_StopListener(); /* This closes rx_socket. */
1451 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1452 afs_warn("Sleep... ");
1453 afs_osi_Sleep(&afs_termState);
1458 #if defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
1459 afs_warn("NetIfPoller... ");
1460 osi_StopNetIfPoller();
1462 rxi_FreeAllPackets();
1464 afs_termState = AFSOP_STOP_COMPLETE;
1466 #ifdef AFS_AIX51_ENV
1470 shutdown_bufferpackage();
1474 * Close file only after daemons which can write to it are stopped.
1475 * Need to close before the osinet shutdown to avoid failing check
1476 * for dangling memory allocations.
1478 if (afs_cacheInodep) { /* memcache won't set this */
1479 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1480 afs_cacheInodep = 0;
1483 * Shutdown the ICL logs - needed to free allocated memory space and avoid
1484 * warnings from shutdown_osinet
1489 shutdown_vnodeops();
1490 shutdown_memcache();
1492 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV))
1493 shutdown_exporter();
1498 /* The following hold the cm stats */
1499 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1500 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1501 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1502 afs_warn(" ALL allocated tables... ");
1504 afs_shuttingdown = AFS_RUNNING;
1507 return; /* Just kill daemons for now */
1511 shutdown_afstest(void)
1513 AFS_STATCNT(shutdown_afstest);
1514 afs_initState = afs_termState = 0;
1515 AFS_Running = afs_CB_Running = 0;
1516 afs_CacheInit_Done = afs_Go_Done = 0;
1517 if (afs_cold_shutdown) {
1518 *afs_rootVolumeName = 0;