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 /* This is code which needs to be called once when the first daemon enters
91 * the client. A non-zero return means an error and AFS should not start.
94 afs_InitSetup(int preallocs)
98 if (afs_InitSetup_done)
101 #ifdef AFS_SUN510_ENV
102 /* Initialize a RW lock for the ifinfo global array */
103 rw_init(&afsifinfo_lock, NULL, RW_DRIVER, NULL);
106 afs_taskq = ddi_taskq_create(NULL, "afs_taskq", 2, TASKQ_DEFAULTPRI, 0);
108 osi_StartNetIfPoller();
113 * Set up all the AFS statistics variables. This should be done
114 * exactly once, and it should be done here, the first resource-setting
115 * routine to be called by the CM/RX.
118 #endif /* AFS_NOSTATS */
120 memset(afs_zeros, 0, AFS_ZEROS);
123 if(!afscall_set_rxpck_received)
124 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
125 code = rx_InitHost(rx_bindhost, htons(7001));
127 afs_warn("AFS: RX failed to initialize %d).\n", code);
130 rx_SetRxDeadTime(afs_rx_deadtime);
131 /* resource init creates the services */
132 afs_ResourceInit(preallocs);
134 afs_InitSetup_done = 1;
135 afs_osi_Wakeup(&afs_InitSetup_done);
140 #ifdef AFS_DAEMONOP_ENV
142 daemonOp_common(long parm, long parm2, long parm3, long parm4, long parm5,
146 if (parm == AFSOP_START_RXCALLBACK) {
149 # ifdef RXK_LISTENER_ENV
150 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
155 code = afs_InitSetup(parm2);
157 rx_enablePeerRPCStats();
160 rx_enableProcessRPCStats();
164 } else if (parm == AFSOP_START_AFS) {
167 } /* other functions don't need setup in the parent */
170 #endif /* AFS_DAEMONOP_ENV */
172 #if defined(AFS_DARWIN80_ENV)
173 struct afsd_thread_info {
177 afsd_thread(int *rock)
179 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
180 unsigned long parm = arg->parm;
183 case AFSOP_START_RXCALLBACK:
187 #ifndef RXK_LISTENER_ENV
188 afs_initState = AFSOP_START_AFS;
189 afs_osi_Wakeup(&afs_initState);
191 while (afs_RX_Running != 2)
192 afs_osi_Sleep(&afs_RX_Running);
194 afs_RXCallBackServer();
196 thread_terminate(current_thread());
198 case AFSOP_START_AFS:
202 while (afs_initState < AFSOP_START_AFS)
203 afs_osi_Sleep(&afs_initState);
204 afs_initState = AFSOP_START_BKG;
205 afs_osi_Wakeup(&afs_initState);
208 thread_terminate(current_thread());
210 case AFSOP_START_BKG:
211 afs_warn("Install matching afsd! Old background daemons not supported.\n");
212 thread_terminate(current_thread());
214 case AFSOP_START_TRUNCDAEMON:
217 while (afs_initState < AFSOP_GO)
218 afs_osi_Sleep(&afs_initState);
219 afs_CacheTruncateDaemon();
221 thread_terminate(current_thread());
226 afs_CheckServerDaemon();
228 thread_terminate(current_thread());
230 case AFSOP_RXEVENT_DAEMON:
233 while (afs_initState < AFSOP_START_BKG)
234 afs_osi_Sleep(&afs_initState);
235 afs_rxevent_daemon();
237 thread_terminate(current_thread());
239 #ifdef RXK_LISTENER_ENV
240 case AFSOP_RXLISTENER_DAEMON:
243 afs_initState = AFSOP_START_AFS;
244 afs_osi_Wakeup(&afs_initState);
246 afs_osi_Wakeup(&afs_RX_Running);
247 afs_osi_RxkRegister();
250 thread_terminate(current_thread());
254 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
260 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
263 struct afsd_thread_info info;
265 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
269 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
271 /* we need to wait cause we passed stack pointers around.... */
272 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
274 thread_deallocate(thread);
279 #if defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)
280 struct afsd_thread_info {
281 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
282 struct work_struct tq;
285 struct completion *complete;
289 afsd_thread(void *rock)
291 struct afsd_thread_info *arg = rock;
292 unsigned long parm = arg->parm;
293 # ifdef SYS_SETPRIORITY_EXPORTED
294 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
296 # if !defined(HAVE_LINUX_KTHREAD_RUN)
297 # if defined(AFS_LINUX26_ENV)
302 # endif /* !HAVE_LINUX_KTHREAD_RUN */
303 /* doesn't do much, since we were forked from keventd, but
304 * does call mm_release, which wakes up our parent (since it
305 * used CLONE_VFORK) */
306 # if !defined(AFS_LINUX26_ENV)
309 afs_osi_MaskSignals();
311 case AFSOP_START_RXCALLBACK:
312 sprintf(current->comm, "afs_cbstart");
314 complete(arg->complete);
316 #if !defined(RXK_LISTENER_ENV)
317 afs_initState = AFSOP_START_AFS;
318 afs_osi_Wakeup(&afs_initState);
320 while (afs_RX_Running != 2)
321 afs_osi_Sleep(&afs_RX_Running);
323 sprintf(current->comm, "afs_callback");
324 afs_RXCallBackServer();
326 complete_and_exit(0, 0);
328 case AFSOP_START_AFS:
329 sprintf(current->comm, "afs_afsstart");
331 complete(arg->complete);
333 while (afs_initState < AFSOP_START_AFS)
334 afs_osi_Sleep(&afs_initState);
335 afs_initState = AFSOP_START_BKG;
336 afs_osi_Wakeup(&afs_initState);
337 sprintf(current->comm, "afsd");
340 complete_and_exit(0, 0);
342 case AFSOP_START_BKG:
344 afs_warn("Install matching afsd! Old background daemons not supported.\n");
346 sprintf(current->comm, "afs_bkgstart");
348 complete(arg->complete);
349 while (afs_initState < AFSOP_START_BKG)
350 afs_osi_Sleep(&afs_initState);
351 if (afs_initState < AFSOP_GO) {
352 afs_initState = AFSOP_GO;
353 afs_osi_Wakeup(&afs_initState);
355 sprintf(current->comm, "afs_background");
356 afs_BackgroundDaemon();
359 complete_and_exit(0, 0);
361 case AFSOP_START_TRUNCDAEMON:
362 sprintf(current->comm, "afs_trimstart");
364 complete(arg->complete);
365 while (afs_initState < AFSOP_GO)
366 afs_osi_Sleep(&afs_initState);
367 sprintf(current->comm, "afs_cachetrim");
368 afs_CacheTruncateDaemon();
370 complete_and_exit(0, 0);
373 sprintf(current->comm, "afs_checkserver");
375 complete(arg->complete);
376 afs_CheckServerDaemon();
378 complete_and_exit(0, 0);
380 case AFSOP_RXEVENT_DAEMON:
381 sprintf(current->comm, "afs_evtstart");
382 # ifdef SYS_SETPRIORITY_EXPORTED
383 sys_setpriority(PRIO_PROCESS, 0, -10);
385 # ifdef CURRENT_INCLUDES_NICE
390 complete(arg->complete);
391 while (afs_initState < AFSOP_START_BKG)
392 afs_osi_Sleep(&afs_initState);
393 sprintf(current->comm, "afs_rxevent");
394 afs_rxevent_daemon();
396 complete_and_exit(0, 0);
398 #ifdef RXK_LISTENER_ENV
399 case AFSOP_RXLISTENER_DAEMON:
400 sprintf(current->comm, "afs_lsnstart");
401 # ifdef SYS_SETPRIORITY_EXPORTED
402 sys_setpriority(PRIO_PROCESS, 0, -10);
404 # ifdef CURRENT_INCLUDES_NICE
409 complete(arg->complete);
410 afs_initState = AFSOP_START_AFS;
411 afs_osi_Wakeup(&afs_initState);
413 afs_osi_Wakeup(&afs_RX_Running);
414 afs_osi_RxkRegister();
415 sprintf(current->comm, "afs_rxlistener");
418 complete_and_exit(0, 0);
422 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
429 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
430 afsd_launcher(struct work_struct *work)
432 afsd_launcher(void *rock)
435 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
436 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
439 # if defined(HAVE_LINUX_KTHREAD_RUN)
440 if (IS_ERR(kthread_run(afsd_thread, (void *)rock, "afsd"))) {
441 afs_warn("kthread_run failed; afs startup will not complete\n");
443 # else /* !HAVE_LINUX_KTHREAD_RUN */
444 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
445 afs_warn("kernel_thread failed. afs startup will not complete\n");
446 # endif /* !HAVE_LINUX_KTHREAD_RUN */
450 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
453 DECLARE_COMPLETION(c);
454 # if defined(AFS_LINUX26_ENV)
455 # if defined(INIT_WORK_HAS_DATA)
456 struct work_struct tq;
461 struct afsd_thread_info info;
462 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
467 # if defined(AFS_LINUX26_ENV)
468 # if !defined(INIT_WORK_HAS_DATA)
469 INIT_WORK(&info.tq, afsd_launcher);
470 schedule_work(&info.tq);
472 INIT_WORK(&tq, afsd_launcher, &info);
477 INIT_LIST_HEAD(&tq.list);
478 tq.routine = afsd_launcher;
483 /* we need to wait cause we passed stack pointers around.... */
484 wait_for_completion(&c);
490 struct afs_daemonop_args {
496 afsd_thread(struct afs_daemonop_args *args)
498 long parm = args->parm;
501 cv_signal(&args->cv);
504 case AFSOP_START_RXCALLBACK:
508 while (afs_RX_Running != 2)
509 afs_osi_Sleep(&afs_RX_Running);
510 afs_RXCallBackServer();
513 case AFSOP_START_AFS:
517 while (afs_initState < AFSOP_START_AFS)
518 afs_osi_Sleep(&afs_initState);
519 afs_initState = AFSOP_START_BKG;
520 afs_osi_Wakeup(&afs_initState);
524 case AFSOP_START_BKG:
525 while (afs_initState < AFSOP_START_BKG)
526 afs_osi_Sleep(&afs_initState);
527 if (afs_initState < AFSOP_GO) {
528 afs_initState = AFSOP_GO;
529 afs_osi_Wakeup(&afs_initState);
531 afs_BackgroundDaemon();
534 case AFSOP_START_TRUNCDAEMON:
535 while (afs_initState < AFSOP_GO)
536 afs_osi_Sleep(&afs_initState);
537 afs_CacheTruncateDaemon();
541 afs_CheckServerDaemon();
544 case AFSOP_RXEVENT_DAEMON:
545 while (afs_initState < AFSOP_START_BKG)
546 afs_osi_Sleep(&afs_initState);
547 afs_rxevent_daemon();
550 case AFSOP_RXLISTENER_DAEMON:
551 afs_initState = AFSOP_START_AFS;
552 afs_osi_Wakeup(&afs_initState);
554 afs_osi_Wakeup(&afs_RX_Running);
555 afs_osi_RxkRegister();
561 afs_warn("Unknown op %ld in afsd_thread()\n", parm);
570 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
573 struct afs_daemonop_args args;
575 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
581 cv_init(&args.cv, "AFS DaemonOp cond var", CV_DEFAULT, NULL);
583 if (thread_create(NULL, 0, afsd_thread, &args, 0, &p0, TS_RUN,
584 minclsyspri) == NULL) {
586 afs_warn("thread_create failed: AFS startup will not complete\n");
589 /* we passed &args to the new thread, which is on the stack. wait until
590 * it has read the arguments so it doesn't try to read the args after we
592 cv_wait(&args.cv, &afs_global_lock);
594 cv_destroy(&args.cv);
596 #endif /* AFS_SUN5_ENV */
598 #ifdef AFS_DARWIN100_ENV
599 # define AFSKPTR(X) k ## X
601 afs_syscall_call(long parm, long parm2, long parm3,
602 long parm4, long parm5, long parm6)
604 return afs_syscall64_call(CAST_USER_ADDR_T((parm)),
605 CAST_USER_ADDR_T((parm2)),
606 CAST_USER_ADDR_T((parm3)),
607 CAST_USER_ADDR_T((parm4)),
608 CAST_USER_ADDR_T((parm5)),
609 CAST_USER_ADDR_T((parm6)));
612 # define AFSKPTR(X) ((caddr_t)X)
615 #ifdef AFS_DARWIN100_ENV
616 afs_syscall64_call(user_addr_t kparm, user_addr_t kparm2, user_addr_t kparm3,
617 user_addr_t kparm4, user_addr_t kparm5, user_addr_t kparm6)
619 afs_syscall_call(long parm, long parm2, long parm3,
620 long parm4, long parm5, long parm6)
624 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
626 #else /* AFS_SGI61_ENV */
628 #endif /* AFS_SGI61_ENV */
629 #ifdef AFS_DARWIN100_ENV
630 /* AFSKPTR macro relies on this name format/mapping */
631 afs_uint32 parm = (afs_uint32)kparm;
632 afs_uint32 parm2 = (afs_uint32)kparm2;
633 afs_uint32 parm3 = (afs_uint32)kparm3;
634 afs_uint32 parm4 = (afs_uint32)kparm4;
635 afs_uint32 parm5 = (afs_uint32)kparm5;
636 afs_uint32 parm6 = (afs_uint32)kparm6;
639 AFS_STATCNT(afs_syscall_call);
646 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
647 /* only root can run this code */
648 #if defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
649 # if defined(KERNEL_HAVE_UERROR)
657 #ifdef AFS_DARWIN80_ENV
663 #ifdef AFS_DARWIN80_ENV
666 #ifdef AFS_DAEMONOP_ENV
667 # if defined(AFS_NEW_BKG)
668 if (parm == AFSOP_BKG_HANDLER) {
669 /* if afs_uspc_param grows this should be checked */
670 struct afs_uspc_param *mvParam = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
675 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)mvParam,
676 sizeof(struct afs_uspc_param), code);
677 namebufsz = mvParam->bufSz;
678 param1 = afs_osi_Alloc(namebufsz);
679 osi_Assert(param1 != NULL);
680 param2 = afs_osi_Alloc(namebufsz);
681 osi_Assert(param2 != NULL);
683 while (afs_initState < AFSOP_START_BKG)
684 afs_osi_Sleep(&afs_initState);
685 if (afs_initState < AFSOP_GO) {
686 afs_initState = AFSOP_GO;
687 afs_osi_Wakeup(&afs_initState);
690 code = afs_BackgroundDaemon(mvParam, param1, param2);
694 /* for reqs where pointers are strings: */
695 if (mvParam->reqtype == AFS_USPC_UMV) {
696 /* don't copy out random kernel memory */
697 AFS_COPYOUT(param2, AFSKPTR(parm4),
698 MIN(namebufsz, strlen((char *)param2)+1), code);
699 AFS_COPYOUT(param1, AFSKPTR(parm3),
700 MIN(namebufsz, strlen((char *)param1)+1), code);
702 AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
703 sizeof(struct afs_uspc_param), code);
706 afs_osi_Free(param1, namebufsz);
707 afs_osi_Free(param2, namebufsz);
708 osi_FreeSmallSpace(mvParam);
710 # endif /* AFS_NEW_BKG */
711 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
712 || parm == AFSOP_RXLISTENER_DAEMON) {
713 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
715 #else /* !AFS_DAEMONOP_ENV */
716 if (parm == AFSOP_START_RXCALLBACK) {
720 # ifndef RXK_LISTENER_ENV
721 code = afs_InitSetup(parm2);
723 # endif /* !RXK_LISTENER_ENV */
725 # ifdef RXK_LISTENER_ENV
726 while (afs_RX_Running != 2)
727 afs_osi_Sleep(&afs_RX_Running);
728 # else /* !RXK_LISTENER_ENV */
730 rx_enablePeerRPCStats();
733 rx_enableProcessRPCStats();
735 afs_initState = AFSOP_START_AFS;
736 afs_osi_Wakeup(&afs_initState);
737 # endif /* RXK_LISTENER_ENV */
739 afs_RXCallBackServer();
744 exit(CLD_EXITED, code);
745 # endif /* AFS_SGI_ENV */
747 # ifdef RXK_LISTENER_ENV
748 else if (parm == AFSOP_RXLISTENER_DAEMON) {
752 code = afs_InitSetup(parm2);
754 rx_enablePeerRPCStats();
757 rx_enableProcessRPCStats();
760 afs_initState = AFSOP_START_AFS;
761 afs_osi_Wakeup(&afs_initState);
764 afs_osi_Wakeup(&afs_RX_Running);
766 afs_osi_RxkRegister();
767 # endif /* !UKERNEL */
773 exit(CLD_EXITED, code);
774 # endif /* AFS_SGI_ENV */
776 # endif /* RXK_LISTENER_ENV */
777 else if (parm == AFSOP_START_AFS) {
782 while (afs_initState < AFSOP_START_AFS)
783 afs_osi_Sleep(&afs_initState);
785 afs_initState = AFSOP_START_BKG;
786 afs_osi_Wakeup(&afs_initState);
793 # endif /* AFS_SGI_ENV */
794 } else if (parm == AFSOP_START_CS) {
796 afs_CheckServerDaemon();
801 # endif /* AFS_SGI_ENV */
803 } else if (parm == AFSOP_START_BKG) {
804 while (afs_initState < AFSOP_START_BKG)
805 afs_osi_Sleep(&afs_initState);
806 if (afs_initState < AFSOP_GO) {
807 afs_initState = AFSOP_GO;
808 afs_osi_Wakeup(&afs_initState);
810 /* start the bkg daemon */
812 # ifdef AFS_AIX32_ENV
814 afs_BioDaemon(parm2);
816 # endif /* AFS_AIX32_ENV */
817 afs_BackgroundDaemon();
822 # endif /* AFS_SGI_ENV */
823 # endif /* ! AFS_NEW_BKG */
824 } else if (parm == AFSOP_START_TRUNCDAEMON) {
825 while (afs_initState < AFSOP_GO)
826 afs_osi_Sleep(&afs_initState);
827 /* start the bkg daemon */
829 afs_CacheTruncateDaemon();
834 # endif /* AFS_SGI_ENV */
836 # if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
837 else if (parm == AFSOP_RXEVENT_DAEMON) {
838 while (afs_initState < AFSOP_START_BKG)
839 afs_osi_Sleep(&afs_initState);
841 afs_rxevent_daemon();
846 # endif /* AFS_SGI_ENV */
848 # endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV || RXK_UPCALL_ENV */
849 #endif /* AFS_DAEMONOP_ENV */
850 else if (parm == AFSOP_BASIC_INIT) {
853 while (!afs_InitSetup_done)
854 afs_osi_Sleep(&afs_InitSetup_done);
856 #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)
857 temp = AFS_MINBUFFERS; /* Should fix this soon */
859 /* number of 2k buffers we could get from all of the buffer space */
860 temp = ((afs_bufferpages * NBPG) >> 11);
861 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
862 if (temp < AFS_MINBUFFERS)
863 temp = AFS_MINBUFFERS; /* though we really should have this many */
866 afs_rootFid.Fid.Volume = 0;
868 } else if (parm == AFSOP_BUCKETPCT) {
869 /* need to enable this now, will disable again before GO
870 if we don't have 100% */
880 } else if (parm == AFSOP_ADDCELL) {
881 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
882 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
883 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
884 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
886 osi_Assert(tcell != NULL);
887 code = afs_InitDynroot();
889 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
893 if (parm4 > sizeof(tcell->cellName))
896 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)tcell->cellName, parm4, code);
898 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
902 afs_osi_Free(tcell, sizeof(struct afsop_cell));
903 } else if (parm == AFSOP_ADDCELL2) {
904 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
905 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
906 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
909 osi_Assert(tcell != NULL);
910 osi_Assert(tbuffer != NULL);
911 osi_Assert(tbuffer1 != NULL);
912 code = afs_InitDynroot();
915 /* wait for basic init - XXX can't find any reason we need this? */
916 while (afs_initState < AFSOP_START_BKG)
917 afs_osi_Sleep(&afs_initState);
920 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
924 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
928 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
932 cflags |= CLinkedCell;
940 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
944 afs_osi_Free(tcell, sizeof(struct afsop_cell));
945 osi_FreeSmallSpace(tbuffer);
946 osi_FreeSmallSpace(tbuffer1);
947 } else if (parm == AFSOP_ADDCELLALIAS) {
950 * parm2 is the alias name
951 * parm3 is the real cell name
953 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
954 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
956 code = afs_InitDynroot();
958 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
962 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
965 afs_NewCellAlias(aliasName, cellName);
966 osi_FreeSmallSpace(aliasName);
967 osi_FreeSmallSpace(cellName);
968 } else if (parm == AFSOP_SET_THISCELL) {
971 * parm2 is the primary cell name
973 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
976 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
978 afs_SetPrimaryCell(cell);
979 osi_FreeSmallSpace(cell);
981 code = afs_InitDynroot();
983 } else if (parm == AFSOP_CACHEINIT) {
984 struct afs_cacheParams cparms;
986 if (afs_CacheInit_Done)
989 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
991 #if defined(KERNEL_HAVE_UERROR)
997 afs_CacheInit_Done = 1;
998 code = afs_icl_InitLogs();
999 if (cparms.setTimeFlag) {
1000 afs_warn("afs: AFSOP_CACHEINIT setTimeFlag ignored; are you "
1001 "running an old afsd?\n");
1005 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
1006 cparms.cacheBlocks, cparms.cacheDcaches,
1007 cparms.cacheVolumes, cparms.chunkSize,
1008 cparms.memCacheFlag, cparms.inodes, cparms.users,
1009 cparms.dynamic_vcaches);
1011 } else if (parm == AFSOP_CACHEINODE) {
1012 ino_t ainode = parm2;
1013 /* wait for basic init */
1014 while (afs_initState < AFSOP_START_BKG)
1015 afs_osi_Sleep(&afs_initState);
1017 #ifdef AFS_DARWIN80_ENV
1020 /* do it by inode */
1021 #ifdef AFS_SGI62_ENV
1022 ainode = (ainode << 32) | (parm3 & 0xffffffff);
1024 code = afs_InitCacheFile(NULL, ainode);
1025 #ifdef AFS_DARWIN80_ENV
1028 } else if (parm == AFSOP_CACHEDIRS) {
1029 afs_numfilesperdir = parm2;
1030 afs_osi_Wakeup(&afs_initState);
1031 } else if (parm == AFSOP_CACHEFILES) {
1032 afs_numcachefiles = parm2;
1033 afs_osi_Wakeup(&afs_initState);
1034 } else if (parm == AFSOP_ROOTVOLUME) {
1035 /* wait for basic init */
1036 while (afs_initState < AFSOP_START_BKG)
1037 afs_osi_Sleep(&afs_initState);
1040 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
1041 sizeof(afs_rootVolumeName), &bufferSize, code);
1042 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
1045 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
1046 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
1047 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
1050 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
1053 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
1054 /* We have the cache dir copied in. Call the cache init routine */
1055 #ifdef AFS_DARWIN80_ENV
1058 if (parm == AFSOP_CACHEFILE) {
1059 code = afs_InitCacheFile(tbuffer, 0);
1060 } else if (parm == AFSOP_CACHEINFO) {
1061 code = afs_InitCacheInfo(tbuffer);
1062 } else if (parm == AFSOP_VOLUMEINFO) {
1063 code = afs_InitVolumeInfo(tbuffer);
1064 } else if (parm == AFSOP_CELLINFO) {
1065 code = afs_InitCellInfo(tbuffer);
1067 #ifdef AFS_DARWIN80_ENV
1071 osi_FreeSmallSpace(tbuffer);
1072 } else if (parm == AFSOP_GO) {
1073 /* the generic initialization calls come here. One parameter: should we do the
1074 * set-time operation on this workstation */
1078 while (afs_initState < AFSOP_GO)
1079 afs_osi_Sleep(&afs_initState);
1080 afs_initState = 101;
1082 /* parm2 used to set afs_setTime */
1083 afs_warn("afs: AFSOP_GO setTime flag ignored; are you running an "
1086 if (afs_tpct1 + afs_tpct2 != 100) {
1093 afs_osi_Wakeup(&afs_initState);
1094 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
1095 afs_nfsclient_init();
1097 if (afs_uuid_create(&afs_cb_interface.uuid) != 0)
1098 memset(&afs_cb_interface.uuid, 0, sizeof(afsUUID));
1100 printf("found %d non-empty cache files (%d%%).\n",
1101 afs_stats_cmperf.cacheFilesReused,
1102 (100 * afs_stats_cmperf.cacheFilesReused) /
1103 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
1104 cacheNumEntries : 1));
1105 } else if (parm == AFSOP_ADVISEADDR) {
1106 /* pass in the host address to the rx package */
1110 afs_int32 count = parm2;
1112 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1113 afs_int32 *maskbuffer =
1114 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1115 afs_int32 *mtubuffer =
1116 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1119 osi_Assert(buffer != NULL);
1120 osi_Assert(maskbuffer != NULL);
1121 osi_Assert(mtubuffer != NULL);
1122 /* This is a refresh */
1123 if (count & 0x40000000) {
1124 count &= ~0x40000000;
1125 /* Can't bind after we start. Fix? */
1126 count &= ~0x80000000;
1130 /* Bind, but only if there's only one address configured */
1131 if ( count & 0x80000000) {
1132 count &= ~0x80000000;
1137 if (count > AFS_MAX_INTERFACE_ADDR) {
1139 count = AFS_MAX_INTERFACE_ADDR;
1142 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
1145 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
1146 count * sizeof(afs_int32), code);
1148 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
1149 count * sizeof(afs_int32), code);
1152 afs_cb_interface.numberOfInterfaces = count;
1153 for (i = 0; i < count; i++) {
1154 afs_cb_interface.addr_in[i] = buffer[i];
1155 #ifdef AFS_USERSPACE_IP_ADDR
1156 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
1157 * machines IP addresses when in the kernel (the in_ifaddr
1158 * struct is not available), so we pass the info in at
1159 * startup. We also pass in the subnetmask and mtu size. The
1160 * subnetmask is used when setting the rank:
1161 * afsi_SetServerIPRank(); and the mtu size is used when
1162 * finding the best mtu size. rxi_FindIfnet() is replaced
1163 * with rxi_Findcbi().
1165 afs_cb_interface.subnetmask[i] =
1166 (parm4 ? maskbuffer[i] : 0xffffffff);
1167 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1170 rxi_setaddr(buffer[0]);
1173 rx_bindhost = buffer[0];
1175 rx_bindhost = htonl(INADDR_ANY);
1181 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1182 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1183 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1186 afs_CheckServers(1, NULL); /* check down servers */
1187 afs_CheckServers(0, NULL); /* check up servers */
1190 else if (parm == AFSOP_SHUTDOWN) {
1191 afs_cold_shutdown = 0;
1193 afs_cold_shutdown = 1;
1194 if (afs_globalVFS != 0) {
1195 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1199 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1201 vfsmount(parm2, parm3, parm4, parm5);
1202 #else /* defined(AFS_HPUX_ENV) */
1203 # if defined(KERNEL_HAVE_UERROR)
1208 #endif /* defined(AFS_HPUX_ENV) */
1209 } else if (parm == AFSOP_CLOSEWAIT) {
1210 afs_SynchronousCloses = 'S';
1211 } else if (parm == AFSOP_GETMTU) {
1213 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1214 # ifdef AFS_USERSPACE_IP_ADDR
1216 i = rxi_Findcbi(parm2);
1217 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1218 # else /* AFS_USERSPACE_IP_ADDR */
1221 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1222 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1223 # endif /* else AFS_USERSPACE_IP_ADDR */
1224 #endif /* !AFS_SUN5_ENV */
1226 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1227 sizeof(afs_int32), code);
1228 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1229 afs_uint32 mask = 0;
1230 #if !defined(AFS_SUN5_ENV)
1231 # ifdef AFS_USERSPACE_IP_ADDR
1233 i = rxi_Findcbi(parm2);
1235 mask = afs_cb_interface.subnetmask[i];
1239 # else /* AFS_USERSPACE_IP_ADDR */
1242 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1245 # endif /* else AFS_USERSPACE_IP_ADDR */
1246 #endif /* !AFS_SUN5_ENV */
1248 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1249 sizeof(afs_int32), code);
1251 else if (parm == AFSOP_AFSDB_HANDLER) {
1252 int sizeArg = (int)parm4;
1253 int kmsgLen = sizeArg & 0xffff;
1254 int cellLen = (sizeArg & 0xffff0000) >> 16;
1255 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1256 char *cellname = afs_osi_Alloc(cellLen);
1258 osi_Assert(kmsg != NULL);
1259 osi_Assert(cellname != NULL);
1261 afs_osi_MaskUserLoop();
1263 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1264 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1266 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1269 if (code == -2) { /* Shutting down? */
1275 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1276 afs_osi_Free(kmsg, kmsgLen);
1277 afs_osi_Free(cellname, cellLen);
1279 else if (parm == AFSOP_SET_DYNROOT) {
1280 code = afs_SetDynrootEnable(parm2);
1281 } else if (parm == AFSOP_SET_FAKESTAT) {
1282 afs_fakestat_enable = parm2;
1284 } else if (parm == AFSOP_SET_BACKUPTREE) {
1285 afs_bkvolpref = parm2;
1286 } else if (parm == AFSOP_SET_RXPCK) {
1287 rx_extraPackets = parm2;
1288 afscall_set_rxpck_received = 1;
1289 } else if (parm == AFSOP_SET_RXMAXMTU) {
1290 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1291 } else if (parm == AFSOP_SET_RXMAXFRAGS) {
1292 rxi_nSendFrags = rxi_nRecvFrags = parm2;
1293 } else if (parm == AFSOP_SET_RMTSYS_FLAG) {
1294 afs_rmtsys_enable = parm2;
1297 } else if (parm == AFSOP_SEED_ENTROPY) {
1298 unsigned char *seedbuf;
1303 seedbuf = afs_osi_Alloc(parm3);
1304 AFS_COPYIN(AFSKPTR(parm2), seedbuf, parm3, code);
1305 RAND_seed(seedbuf, parm3);
1306 memset(seedbuf, 0, parm3);
1307 afs_osi_Free(seedbuf, parm3);
1316 #ifdef AFS_LINUX20_ENV
1324 * Initstate in the range 0 < x < 100 are early initialization states.
1325 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1326 * the cache may be initialized.
1327 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1328 * is done after all the cache initialization has been done.
1329 * Initstate of 200 means that the volume has been looked up once, possibly
1331 * Initstate of 300 means that the volume has been *successfully* looked up.
1338 AFS_STATCNT(afs_CheckInit);
1339 if (afs_initState <= 100)
1340 code = ENXIO; /* never finished init phase */
1341 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1342 while (afs_initState < 200)
1343 afs_osi_Sleep(&afs_initState);
1344 } else if (afs_initState == 200)
1345 code = ETIMEDOUT; /* didn't find root volume */
1349 enum afs_shutdown_state afs_shuttingdown = AFS_RUNNING;
1353 extern short afs_brsDaemons;
1354 extern afs_int32 afs_CheckServerDaemonStarted;
1355 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1356 extern struct osi_file *afs_cacheInodep;
1358 AFS_STATCNT(afs_shutdown);
1359 if (afs_initState == 0) {
1360 afs_warn("AFS not initialized - not shutting down\n");
1364 if (afs_shuttingdown != AFS_RUNNING)
1367 afs_shuttingdown = AFS_FLUSHING_CB;
1369 /* Give up all of our callbacks if we can. */
1372 afs_shuttingdown = AFS_SHUTDOWN;
1374 if (afs_cold_shutdown)
1375 afs_warn("afs: COLD ");
1377 afs_warn("afs: WARM ");
1378 afs_warn("shutting down of: vcaches... ");
1380 #if !defined(AFS_FBSD_ENV)
1381 /* The FBSD afs_unmount() calls vflush(), which reclaims all vnodes
1382 * on the mountpoint, flushing them in the process. In the presence
1383 * of bugs, flushing again here can cause panics. */
1384 afs_FlushAllVCaches();
1387 afs_termState = AFSOP_STOP_BKG;
1389 afs_warn("BkG... ");
1390 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1391 while (afs_termState == AFSOP_STOP_BKG) {
1392 afs_osi_Wakeup(&afs_brsDaemons);
1393 afs_osi_Sleep(&afs_termState);
1398 afs_termState = AFSOP_STOP_RXCALLBACK;
1399 rx_WakeupServerProcs();
1400 #ifdef AFS_AIX51_ENV
1401 shutdown_rxkernel();
1403 /* close rx server connections here? */
1404 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1405 afs_osi_Sleep(&afs_termState);
1407 afs_warn("afs... ");
1408 while (afs_termState == AFSOP_STOP_AFS) {
1409 afs_osi_CancelWait(&AFS_WaitHandler);
1410 afs_osi_Sleep(&afs_termState);
1412 if (afs_CheckServerDaemonStarted) {
1413 while (afs_termState == AFSOP_STOP_CS) {
1414 afs_osi_CancelWait(&AFS_CSWaitHandler);
1415 afs_osi_Sleep(&afs_termState);
1418 afs_warn("CTrunc... ");
1419 /* Cancel cache truncate daemon. */
1420 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1421 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1422 afs_osi_Sleep(&afs_termState);
1424 afs_warn("AFSDB... ");
1426 while (afs_termState == AFSOP_STOP_AFSDB)
1427 afs_osi_Sleep(&afs_termState);
1428 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
1429 afs_warn("RxEvent... ");
1430 /* cancel rx event daemon */
1431 while (afs_termState == AFSOP_STOP_RXEVENT)
1432 afs_osi_Sleep(&afs_termState);
1433 # if defined(RXK_LISTENER_ENV)
1435 afs_warn("UnmaskRxkSignals... ");
1436 afs_osi_UnmaskRxkSignals();
1438 /* cancel rx listener */
1439 afs_warn("RxListener... ");
1440 osi_StopListener(); /* This closes rx_socket. */
1441 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1442 afs_warn("Sleep... ");
1443 afs_osi_Sleep(&afs_termState);
1448 #if defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
1449 afs_warn("NetIfPoller... ");
1450 osi_StopNetIfPoller();
1453 afs_termState = AFSOP_STOP_COMPLETE;
1455 #ifdef AFS_AIX51_ENV
1459 shutdown_bufferpackage();
1463 * Close file only after daemons which can write to it are stopped.
1464 * Need to close before the osinet shutdown to avoid failing check
1465 * for dangling memory allocations.
1467 if (afs_cacheInodep) { /* memcache won't set this */
1468 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1469 afs_cacheInodep = 0;
1472 * Shutdown the ICL logs - needed to free allocated memory space and avoid
1473 * warnings from shutdown_osinet
1478 shutdown_vnodeops();
1479 shutdown_memcache();
1481 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV))
1482 shutdown_exporter();
1487 /* The following hold the cm stats */
1488 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1489 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1490 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1491 afs_warn(" ALL allocated tables... ");
1493 afs_shuttingdown = AFS_RUNNING;
1496 return; /* Just kill daemons for now */
1500 shutdown_afstest(void)
1502 AFS_STATCNT(shutdown_afstest);
1503 afs_initState = afs_termState = 0;
1504 AFS_Running = afs_CB_Running = 0;
1505 afs_CacheInit_Done = afs_Go_Done = 0;
1506 if (afs_cold_shutdown) {
1507 *afs_rootVolumeName = 0;