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;
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_LINUX26_ENV)
280 struct afsd_thread_info {
281 # if !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();
914 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
918 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
922 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
926 cflags |= CLinkedCell;
934 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
938 afs_osi_Free(tcell, sizeof(struct afsop_cell));
939 osi_FreeSmallSpace(tbuffer);
940 osi_FreeSmallSpace(tbuffer1);
941 } else if (parm == AFSOP_ADDCELLALIAS) {
944 * parm2 is the alias name
945 * parm3 is the real cell name
947 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
948 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
950 code = afs_InitDynroot();
952 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
956 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
959 afs_NewCellAlias(aliasName, cellName);
960 osi_FreeSmallSpace(aliasName);
961 osi_FreeSmallSpace(cellName);
962 } else if (parm == AFSOP_SET_THISCELL) {
965 * parm2 is the primary cell name
967 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
970 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
972 afs_SetPrimaryCell(cell);
973 osi_FreeSmallSpace(cell);
975 code = afs_InitDynroot();
977 } else if (parm == AFSOP_CACHEINIT) {
978 struct afs_cacheParams cparms;
980 if (afs_CacheInit_Done)
983 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
985 #if defined(KERNEL_HAVE_UERROR)
991 afs_CacheInit_Done = 1;
992 code = afs_icl_InitLogs();
993 if (cparms.setTimeFlag) {
994 afs_warn("afs: AFSOP_CACHEINIT setTimeFlag ignored; are you "
995 "running an old afsd?\n");
999 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
1000 cparms.cacheBlocks, cparms.cacheDcaches,
1001 cparms.cacheVolumes, cparms.chunkSize,
1002 cparms.memCacheFlag, cparms.inodes, cparms.users,
1003 cparms.dynamic_vcaches);
1005 } else if (parm == AFSOP_CACHEINODE) {
1006 ino_t ainode = parm2;
1007 /* wait for basic init */
1008 while (afs_initState < AFSOP_START_BKG)
1009 afs_osi_Sleep(&afs_initState);
1011 #ifdef AFS_DARWIN80_ENV
1014 /* do it by inode */
1015 #ifdef AFS_SGI62_ENV
1016 ainode = (ainode << 32) | (parm3 & 0xffffffff);
1018 code = afs_InitCacheFile(NULL, ainode);
1019 #ifdef AFS_DARWIN80_ENV
1022 } else if (parm == AFSOP_CACHEDIRS) {
1023 afs_numfilesperdir = parm2;
1024 afs_osi_Wakeup(&afs_initState);
1025 } else if (parm == AFSOP_CACHEFILES) {
1026 afs_numcachefiles = parm2;
1027 afs_osi_Wakeup(&afs_initState);
1028 } else if (parm == AFSOP_ROOTVOLUME) {
1029 /* wait for basic init */
1030 while (afs_initState < AFSOP_START_BKG)
1031 afs_osi_Sleep(&afs_initState);
1034 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
1035 sizeof(afs_rootVolumeName), &bufferSize, code);
1036 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
1039 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
1040 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
1041 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
1044 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
1047 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
1048 /* We have the cache dir copied in. Call the cache init routine */
1049 #ifdef AFS_DARWIN80_ENV
1052 if (parm == AFSOP_CACHEFILE) {
1053 code = afs_InitCacheFile(tbuffer, 0);
1054 } else if (parm == AFSOP_CACHEINFO) {
1055 code = afs_InitCacheInfo(tbuffer);
1056 } else if (parm == AFSOP_VOLUMEINFO) {
1057 code = afs_InitVolumeInfo(tbuffer);
1058 } else if (parm == AFSOP_CELLINFO) {
1059 code = afs_InitCellInfo(tbuffer);
1061 #ifdef AFS_DARWIN80_ENV
1065 osi_FreeSmallSpace(tbuffer);
1066 } else if (parm == AFSOP_GO) {
1067 /* the generic initialization calls come here. One parameter: should we do the
1068 * set-time operation on this workstation */
1072 while (afs_initState < AFSOP_GO)
1073 afs_osi_Sleep(&afs_initState);
1074 afs_initState = 101;
1076 /* parm2 used to set afs_setTime */
1077 afs_warn("afs: AFSOP_GO setTime flag ignored; are you running an "
1080 if (afs_tpct1 + afs_tpct2 != 100) {
1087 afs_osi_Wakeup(&afs_initState);
1088 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
1089 afs_nfsclient_init();
1091 if (afs_uuid_create(&afs_cb_interface.uuid) != 0)
1092 memset(&afs_cb_interface.uuid, 0, sizeof(afsUUID));
1094 printf("found %d non-empty cache files (%d%%).\n",
1095 afs_stats_cmperf.cacheFilesReused,
1096 (100 * afs_stats_cmperf.cacheFilesReused) /
1097 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
1098 cacheNumEntries : 1));
1099 } else if (parm == AFSOP_ADVISEADDR) {
1100 /* pass in the host address to the rx package */
1104 afs_int32 count = parm2;
1106 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1107 afs_int32 *maskbuffer =
1108 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1109 afs_int32 *mtubuffer =
1110 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1113 osi_Assert(buffer != NULL);
1114 osi_Assert(maskbuffer != NULL);
1115 osi_Assert(mtubuffer != NULL);
1116 /* This is a refresh */
1117 if (count & 0x40000000) {
1118 count &= ~0x40000000;
1119 /* Can't bind after we start. Fix? */
1120 count &= ~0x80000000;
1124 /* Bind, but only if there's only one address configured */
1125 if ( count & 0x80000000) {
1126 count &= ~0x80000000;
1131 if (count > AFS_MAX_INTERFACE_ADDR) {
1133 count = AFS_MAX_INTERFACE_ADDR;
1136 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
1139 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
1140 count * sizeof(afs_int32), code);
1142 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
1143 count * sizeof(afs_int32), code);
1146 afs_cb_interface.numberOfInterfaces = count;
1147 for (i = 0; i < count; i++) {
1148 afs_cb_interface.addr_in[i] = buffer[i];
1149 #ifdef AFS_USERSPACE_IP_ADDR
1150 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
1151 * machines IP addresses when in the kernel (the in_ifaddr
1152 * struct is not available), so we pass the info in at
1153 * startup. We also pass in the subnetmask and mtu size. The
1154 * subnetmask is used when setting the rank:
1155 * afsi_SetServerIPRank(); and the mtu size is used when
1156 * finding the best mtu size. rxi_FindIfnet() is replaced
1157 * with rxi_Findcbi().
1159 afs_cb_interface.subnetmask[i] =
1160 (parm4 ? maskbuffer[i] : 0xffffffff);
1161 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1164 rxi_setaddr(buffer[0]);
1167 rx_bindhost = buffer[0];
1169 rx_bindhost = htonl(INADDR_ANY);
1175 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1176 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1177 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1180 afs_CheckServers(1, NULL); /* check down servers */
1181 afs_CheckServers(0, NULL); /* check up servers */
1184 else if (parm == AFSOP_SHUTDOWN) {
1185 afs_cold_shutdown = 0;
1187 afs_cold_shutdown = 1;
1188 if (afs_globalVFS != 0) {
1189 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1193 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1195 vfsmount(parm2, parm3, parm4, parm5);
1196 #else /* defined(AFS_HPUX_ENV) */
1197 # if defined(KERNEL_HAVE_UERROR)
1202 #endif /* defined(AFS_HPUX_ENV) */
1203 } else if (parm == AFSOP_CLOSEWAIT) {
1204 afs_SynchronousCloses = 'S';
1205 } else if (parm == AFSOP_GETMTU) {
1207 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1208 # ifdef AFS_USERSPACE_IP_ADDR
1210 i = rxi_Findcbi(parm2);
1211 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1212 # else /* AFS_USERSPACE_IP_ADDR */
1215 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1216 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1217 # endif /* else AFS_USERSPACE_IP_ADDR */
1218 #endif /* !AFS_SUN5_ENV */
1220 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1221 sizeof(afs_int32), code);
1222 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1223 afs_uint32 mask = 0;
1224 #if !defined(AFS_SUN5_ENV)
1225 # ifdef AFS_USERSPACE_IP_ADDR
1227 i = rxi_Findcbi(parm2);
1229 mask = afs_cb_interface.subnetmask[i];
1233 # else /* AFS_USERSPACE_IP_ADDR */
1236 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1239 # endif /* else AFS_USERSPACE_IP_ADDR */
1240 #endif /* !AFS_SUN5_ENV */
1242 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1243 sizeof(afs_int32), code);
1245 else if (parm == AFSOP_AFSDB_HANDLER) {
1246 int sizeArg = (int)parm4;
1247 int kmsgLen = sizeArg & 0xffff;
1248 int cellLen = (sizeArg & 0xffff0000) >> 16;
1249 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1250 char *cellname = afs_osi_Alloc(cellLen);
1252 osi_Assert(kmsg != NULL);
1253 osi_Assert(cellname != NULL);
1255 afs_osi_MaskUserLoop();
1257 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1258 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1260 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1263 if (code == -2) { /* Shutting down? */
1269 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1270 afs_osi_Free(kmsg, kmsgLen);
1271 afs_osi_Free(cellname, cellLen);
1273 else if (parm == AFSOP_SET_DYNROOT) {
1274 code = afs_SetDynrootEnable(parm2);
1275 } else if (parm == AFSOP_SET_FAKESTAT) {
1276 afs_fakestat_enable = parm2;
1278 } else if (parm == AFSOP_SET_BACKUPTREE) {
1279 afs_bkvolpref = parm2;
1280 } else if (parm == AFSOP_SET_RXPCK) {
1281 rx_extraPackets = parm2;
1282 afscall_set_rxpck_received = 1;
1283 } else if (parm == AFSOP_SET_RXMAXMTU) {
1284 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1285 } else if (parm == AFSOP_SET_RXMAXFRAGS) {
1286 rxi_nSendFrags = rxi_nRecvFrags = parm2;
1287 } else if (parm == AFSOP_SET_RMTSYS_FLAG) {
1288 afs_rmtsys_enable = parm2;
1291 } else if (parm == AFSOP_SEED_ENTROPY) {
1292 unsigned char *seedbuf;
1297 seedbuf = afs_osi_Alloc(parm3);
1298 AFS_COPYIN(AFSKPTR(parm2), seedbuf, parm3, code);
1299 RAND_seed(seedbuf, parm3);
1300 memset(seedbuf, 0, parm3);
1301 afs_osi_Free(seedbuf, parm3);
1310 #ifdef AFS_LINUX20_ENV
1318 * Initstate in the range 0 < x < 100 are early initialization states.
1319 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1320 * the cache may be initialized.
1321 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1322 * is done after all the cache initialization has been done.
1323 * Initstate of 200 means that the volume has been looked up once, possibly
1325 * Initstate of 300 means that the volume has been *successfully* looked up.
1332 AFS_STATCNT(afs_CheckInit);
1333 if (afs_initState <= 100)
1334 code = ENXIO; /* never finished init phase */
1335 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1336 while (afs_initState < 200)
1337 afs_osi_Sleep(&afs_initState);
1338 } else if (afs_initState == 200)
1339 code = ETIMEDOUT; /* didn't find root volume */
1343 enum afs_shutdown_state afs_shuttingdown = AFS_RUNNING;
1347 extern short afs_brsDaemons;
1348 extern afs_int32 afs_CheckServerDaemonStarted;
1349 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1350 extern struct osi_file *afs_cacheInodep;
1352 AFS_STATCNT(afs_shutdown);
1353 if (afs_initState == 0) {
1354 afs_warn("AFS not initialized - not shutting down\n");
1358 if (afs_shuttingdown != AFS_RUNNING)
1361 afs_shuttingdown = AFS_FLUSHING_CB;
1363 /* Give up all of our callbacks if we can. */
1366 afs_shuttingdown = AFS_SHUTDOWN;
1368 if (afs_cold_shutdown)
1369 afs_warn("afs: COLD ");
1371 afs_warn("afs: WARM ");
1372 afs_warn("shutting down of: vcaches... ");
1374 #if !defined(AFS_FBSD_ENV)
1375 /* The FBSD afs_unmount() calls vflush(), which reclaims all vnodes
1376 * on the mountpoint, flushing them in the process. In the presence
1377 * of bugs, flushing again here can cause panics. */
1378 afs_FlushAllVCaches();
1381 afs_termState = AFSOP_STOP_BKG;
1383 afs_warn("BkG... ");
1384 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1385 while (afs_termState == AFSOP_STOP_BKG) {
1386 afs_osi_Wakeup(&afs_brsDaemons);
1387 afs_osi_Sleep(&afs_termState);
1392 afs_termState = AFSOP_STOP_RXCALLBACK;
1393 rx_WakeupServerProcs();
1394 #ifdef AFS_AIX51_ENV
1395 shutdown_rxkernel();
1397 /* close rx server connections here? */
1398 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1399 afs_osi_Sleep(&afs_termState);
1401 afs_warn("afs... ");
1402 while (afs_termState == AFSOP_STOP_AFS) {
1403 afs_osi_CancelWait(&AFS_WaitHandler);
1404 afs_osi_Sleep(&afs_termState);
1406 if (afs_CheckServerDaemonStarted) {
1407 while (afs_termState == AFSOP_STOP_CS) {
1408 afs_osi_CancelWait(&AFS_CSWaitHandler);
1409 afs_osi_Sleep(&afs_termState);
1412 afs_warn("CTrunc... ");
1413 /* Cancel cache truncate daemon. */
1414 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1415 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1416 afs_osi_Sleep(&afs_termState);
1418 afs_warn("AFSDB... ");
1420 while (afs_termState == AFSOP_STOP_AFSDB)
1421 afs_osi_Sleep(&afs_termState);
1422 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
1423 afs_warn("RxEvent... ");
1424 /* cancel rx event daemon */
1425 while (afs_termState == AFSOP_STOP_RXEVENT)
1426 afs_osi_Sleep(&afs_termState);
1427 # if defined(RXK_LISTENER_ENV)
1429 afs_warn("UnmaskRxkSignals... ");
1430 afs_osi_UnmaskRxkSignals();
1432 /* cancel rx listener */
1433 afs_warn("RxListener... ");
1434 osi_StopListener(); /* This closes rx_socket. */
1435 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1436 afs_warn("Sleep... ");
1437 afs_osi_Sleep(&afs_termState);
1442 #if defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
1443 afs_warn("NetIfPoller... ");
1444 osi_StopNetIfPoller();
1447 afs_termState = AFSOP_STOP_COMPLETE;
1449 #ifdef AFS_AIX51_ENV
1453 shutdown_bufferpackage();
1457 * Close file only after daemons which can write to it are stopped.
1458 * Need to close before the osinet shutdown to avoid failing check
1459 * for dangling memory allocations.
1461 if (afs_cacheInodep) { /* memcache won't set this */
1462 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1463 afs_cacheInodep = 0;
1466 * Shutdown the ICL logs - needed to free allocated memory space and avoid
1467 * warnings from shutdown_osinet
1472 shutdown_vnodeops();
1473 shutdown_memcache();
1475 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV))
1476 shutdown_exporter();
1481 /* The following hold the cm stats */
1482 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1483 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1484 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1485 afs_warn(" ALL allocated tables... ");
1487 afs_shuttingdown = AFS_RUNNING;
1490 return; /* Just kill daemons for now */
1494 shutdown_afstest(void)
1496 AFS_STATCNT(shutdown_afstest);
1497 afs_initState = afs_termState = 0;
1498 AFS_Running = afs_CB_Running = 0;
1499 afs_CacheInit_Done = afs_Go_Done = 0;
1500 if (afs_cold_shutdown) {
1501 *afs_rootVolumeName = 0;