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"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
15 #include "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h"
17 #include "rx/rx_globals.h"
18 #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
21 #include "h/hashing.h"
23 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN_ENV)
24 #include "netinet/in_var.h"
26 #endif /* !defined(UKERNEL) */
32 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV)
33 #define AFS_MINBUFFERS 100
35 #define AFS_MINBUFFERS 50
38 #if (defined(AFS_SUN5_ENV) || (defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)) || defined(AFS_DARWIN80_ENV)) && !defined(UKERNEL)
39 /* If AFS_DAEMONOP_ENV is defined, it indicates we run "daemon" AFS syscalls by
40 * spawning a kernel thread to do the work, instead of running them in the
42 # define AFS_DAEMONOP_ENV
46 afs_int32 hosts[AFS_MAXCELLHOSTS];
50 char afs_zeros[AFS_ZEROS];
51 char afs_rootVolumeName[64] = "";
52 afs_uint32 rx_bindhost;
55 ddi_taskq_t *afs_taskq;
56 krwlock_t afsifinfo_lock;
59 afs_int32 afs_initState = 0;
60 afs_int32 afs_termState = 0;
61 int afs_cold_shutdown = 0;
62 char afs_SynchronousCloses = '\0';
63 static int afs_CB_Running = 0;
64 static int AFS_Running = 0;
65 static int afs_CacheInit_Done = 0;
66 static int afs_Go_Done = 0;
67 extern struct interfaceAddr afs_cb_interface;
68 static int afs_RX_Running = 0;
69 static int afs_InitSetup_done = 0;
70 afs_int32 afs_numcachefiles = -1;
71 afs_int32 afs_numfilesperdir = -1;
72 char afs_cachebasedir[1024];
74 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
75 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
76 afs_int32 afs_rx_idledead = AFS_IDLEDEADTIME;
77 afs_int32 afs_rx_idledead_rep = AFS_IDLEDEADTIME_REP;
79 static int afscall_set_rxpck_received = 0;
81 #if defined(AFS_HPUX_ENV)
82 extern int afs_vfs_mount();
83 #endif /* defined(AFS_HPUX_ENV) */
85 /* This is code which needs to be called once when the first daemon enters
86 * the client. A non-zero return means an error and AFS should not start.
89 afs_InitSetup(int preallocs)
93 if (afs_InitSetup_done)
97 /* Initialize a RW lock for the ifinfo global array */
98 rw_init(&afsifinfo_lock, NULL, RW_DRIVER, NULL);
101 afs_taskq = ddi_taskq_create(NULL, "afs_taskq", 2, TASKQ_DEFAULTPRI, 0);
103 osi_StartNetIfPoller();
108 * Set up all the AFS statistics variables. This should be done
109 * exactly once, and it should be done here, the first resource-setting
110 * routine to be called by the CM/RX.
113 #endif /* AFS_NOSTATS */
115 memset(afs_zeros, 0, AFS_ZEROS);
117 rx_SetBusyChannelError(1); /* turn on busy call error reporting */
120 if(!afscall_set_rxpck_received)
121 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
122 code = rx_InitHost(rx_bindhost, htons(7001));
124 afs_warn("AFS: RX failed to initialize %d).\n", code);
127 rx_SetRxDeadTime(afs_rx_deadtime);
128 /* resource init creates the services */
129 afs_ResourceInit(preallocs);
131 afs_InitSetup_done = 1;
132 afs_osi_Wakeup(&afs_InitSetup_done);
137 #ifdef AFS_DAEMONOP_ENV
139 daemonOp_common(long parm, long parm2, long parm3, long parm4, long parm5,
143 if (parm == AFSOP_START_RXCALLBACK) {
146 # ifdef RXK_LISTENER_ENV
147 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
152 code = afs_InitSetup(parm2);
154 rx_enablePeerRPCStats();
157 rx_enableProcessRPCStats();
161 } else if (parm == AFSOP_START_AFS) {
164 } /* other functions don't need setup in the parent */
167 #endif /* AFS_DAEMONOP_ENV */
169 #if defined(AFS_DARWIN80_ENV)
170 struct afsd_thread_info {
174 afsd_thread(int *rock)
176 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
177 unsigned long parm = arg->parm;
180 case AFSOP_START_RXCALLBACK:
184 #ifndef RXK_LISTENER_ENV
185 afs_initState = AFSOP_START_AFS;
186 afs_osi_Wakeup(&afs_initState);
188 while (afs_RX_Running != 2)
189 afs_osi_Sleep(&afs_RX_Running);
191 afs_RXCallBackServer();
193 thread_terminate(current_thread());
195 case AFSOP_START_AFS:
199 while (afs_initState < AFSOP_START_AFS)
200 afs_osi_Sleep(&afs_initState);
201 afs_initState = AFSOP_START_BKG;
202 afs_osi_Wakeup(&afs_initState);
205 thread_terminate(current_thread());
207 case AFSOP_START_BKG:
208 afs_warn("Install matching afsd! Old background daemons not supported.\n");
209 thread_terminate(current_thread());
211 case AFSOP_START_TRUNCDAEMON:
214 while (afs_initState < AFSOP_GO)
215 afs_osi_Sleep(&afs_initState);
216 afs_CacheTruncateDaemon();
218 thread_terminate(current_thread());
223 afs_CheckServerDaemon();
225 thread_terminate(current_thread());
227 case AFSOP_RXEVENT_DAEMON:
230 while (afs_initState < AFSOP_START_BKG)
231 afs_osi_Sleep(&afs_initState);
232 afs_rxevent_daemon();
234 thread_terminate(current_thread());
236 #ifdef RXK_LISTENER_ENV
237 case AFSOP_RXLISTENER_DAEMON:
240 afs_initState = AFSOP_START_AFS;
241 afs_osi_Wakeup(&afs_initState);
243 afs_osi_Wakeup(&afs_RX_Running);
244 afs_osi_RxkRegister();
247 thread_terminate(current_thread());
251 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
257 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
260 struct afsd_thread_info info;
262 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
266 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
268 /* we need to wait cause we passed stack pointers around.... */
269 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
271 thread_deallocate(thread);
276 #if defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)
277 struct afsd_thread_info {
278 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
279 struct work_struct tq;
282 struct completion *complete;
286 afsd_thread(void *rock)
288 struct afsd_thread_info *arg = rock;
289 unsigned long parm = arg->parm;
290 # ifdef SYS_SETPRIORITY_EXPORTED
291 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
293 # if defined(AFS_LINUX26_ENV)
298 /* doesn't do much, since we were forked from keventd, but
299 * does call mm_release, which wakes up our parent (since it
300 * used CLONE_VFORK) */
301 # if !defined(AFS_LINUX26_ENV)
304 afs_osi_MaskSignals();
306 case AFSOP_START_RXCALLBACK:
307 sprintf(current->comm, "afs_cbstart");
309 complete(arg->complete);
311 #if !defined(RXK_LISTENER_ENV)
312 afs_initState = AFSOP_START_AFS;
313 afs_osi_Wakeup(&afs_initState);
315 while (afs_RX_Running != 2)
316 afs_osi_Sleep(&afs_RX_Running);
318 sprintf(current->comm, "afs_callback");
319 afs_RXCallBackServer();
321 complete_and_exit(0, 0);
323 case AFSOP_START_AFS:
324 sprintf(current->comm, "afs_afsstart");
326 complete(arg->complete);
328 while (afs_initState < AFSOP_START_AFS)
329 afs_osi_Sleep(&afs_initState);
330 afs_initState = AFSOP_START_BKG;
331 afs_osi_Wakeup(&afs_initState);
332 sprintf(current->comm, "afsd");
335 complete_and_exit(0, 0);
337 case AFSOP_START_BKG:
339 afs_warn("Install matching afsd! Old background daemons not supported.\n");
341 sprintf(current->comm, "afs_bkgstart");
343 complete(arg->complete);
344 while (afs_initState < AFSOP_START_BKG)
345 afs_osi_Sleep(&afs_initState);
346 if (afs_initState < AFSOP_GO) {
347 afs_initState = AFSOP_GO;
348 afs_osi_Wakeup(&afs_initState);
350 sprintf(current->comm, "afs_background");
351 afs_BackgroundDaemon();
354 complete_and_exit(0, 0);
356 case AFSOP_START_TRUNCDAEMON:
357 sprintf(current->comm, "afs_trimstart");
359 complete(arg->complete);
360 while (afs_initState < AFSOP_GO)
361 afs_osi_Sleep(&afs_initState);
362 sprintf(current->comm, "afs_cachetrim");
363 afs_CacheTruncateDaemon();
365 complete_and_exit(0, 0);
368 sprintf(current->comm, "afs_checkserver");
370 complete(arg->complete);
371 afs_CheckServerDaemon();
373 complete_and_exit(0, 0);
375 case AFSOP_RXEVENT_DAEMON:
376 sprintf(current->comm, "afs_evtstart");
377 # ifdef SYS_SETPRIORITY_EXPORTED
378 sys_setpriority(PRIO_PROCESS, 0, -10);
380 # ifdef CURRENT_INCLUDES_NICE
385 complete(arg->complete);
386 while (afs_initState < AFSOP_START_BKG)
387 afs_osi_Sleep(&afs_initState);
388 sprintf(current->comm, "afs_rxevent");
389 afs_rxevent_daemon();
391 complete_and_exit(0, 0);
393 #ifdef RXK_LISTENER_ENV
394 case AFSOP_RXLISTENER_DAEMON:
395 sprintf(current->comm, "afs_lsnstart");
396 # ifdef SYS_SETPRIORITY_EXPORTED
397 sys_setpriority(PRIO_PROCESS, 0, -10);
399 # ifdef CURRENT_INCLUDES_NICE
404 complete(arg->complete);
405 afs_initState = AFSOP_START_AFS;
406 afs_osi_Wakeup(&afs_initState);
408 afs_osi_Wakeup(&afs_RX_Running);
409 afs_osi_RxkRegister();
410 sprintf(current->comm, "afs_rxlistener");
413 complete_and_exit(0, 0);
417 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
424 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
425 afsd_launcher(struct work_struct *work)
427 afsd_launcher(void *rock)
430 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
431 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
434 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
435 afs_warn("kernel_thread failed. afs startup will not complete\n");
439 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
442 DECLARE_COMPLETION(c);
443 # if defined(AFS_LINUX26_ENV)
444 # if defined(INIT_WORK_HAS_DATA)
445 struct work_struct tq;
450 struct afsd_thread_info info;
451 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
456 # if defined(AFS_LINUX26_ENV)
457 # if !defined(INIT_WORK_HAS_DATA)
458 INIT_WORK(&info.tq, afsd_launcher);
459 schedule_work(&info.tq);
461 INIT_WORK(&tq, afsd_launcher, &info);
466 INIT_LIST_HEAD(&tq.list);
467 tq.routine = afsd_launcher;
472 /* we need to wait cause we passed stack pointers around.... */
473 wait_for_completion(&c);
479 struct afs_daemonop_args {
485 afsd_thread(struct afs_daemonop_args *args)
487 long parm = args->parm;
490 cv_signal(&args->cv);
493 case AFSOP_START_RXCALLBACK:
497 while (afs_RX_Running != 2)
498 afs_osi_Sleep(&afs_RX_Running);
499 afs_RXCallBackServer();
502 case AFSOP_START_AFS:
506 while (afs_initState < AFSOP_START_AFS)
507 afs_osi_Sleep(&afs_initState);
508 afs_initState = AFSOP_START_BKG;
509 afs_osi_Wakeup(&afs_initState);
513 case AFSOP_START_BKG:
514 while (afs_initState < AFSOP_START_BKG)
515 afs_osi_Sleep(&afs_initState);
516 if (afs_initState < AFSOP_GO) {
517 afs_initState = AFSOP_GO;
518 afs_osi_Wakeup(&afs_initState);
520 afs_BackgroundDaemon();
523 case AFSOP_START_TRUNCDAEMON:
524 while (afs_initState < AFSOP_GO)
525 afs_osi_Sleep(&afs_initState);
526 afs_CacheTruncateDaemon();
530 afs_CheckServerDaemon();
533 case AFSOP_RXEVENT_DAEMON:
534 while (afs_initState < AFSOP_START_BKG)
535 afs_osi_Sleep(&afs_initState);
536 afs_rxevent_daemon();
539 case AFSOP_RXLISTENER_DAEMON:
540 afs_initState = AFSOP_START_AFS;
541 afs_osi_Wakeup(&afs_initState);
543 afs_osi_Wakeup(&afs_RX_Running);
544 afs_osi_RxkRegister();
550 afs_warn("Unknown op %ld in afsd_thread()\n", parm);
559 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
562 struct afs_daemonop_args args;
564 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
570 cv_init(&args.cv, "AFS DaemonOp cond var", CV_DEFAULT, NULL);
572 if (thread_create(NULL, 0, afsd_thread, &args, 0, &p0, TS_RUN,
573 minclsyspri) == NULL) {
575 afs_warn("thread_create failed: AFS startup will not complete\n");
578 /* we passed &args to the new thread, which is on the stack. wait until
579 * it has read the arguments so it doesn't try to read the args after we
581 cv_wait(&args.cv, &afs_global_lock);
583 cv_destroy(&args.cv);
585 #endif /* AFS_SUN5_ENV */
587 #ifdef AFS_DARWIN100_ENV
588 # define AFSKPTR(X) k ## X
590 afs_syscall_call(long parm, long parm2, long parm3,
591 long parm4, long parm5, long parm6)
593 return afs_syscall64_call(CAST_USER_ADDR_T((parm)),
594 CAST_USER_ADDR_T((parm2)),
595 CAST_USER_ADDR_T((parm3)),
596 CAST_USER_ADDR_T((parm4)),
597 CAST_USER_ADDR_T((parm5)),
598 CAST_USER_ADDR_T((parm6)));
601 # define AFSKPTR(X) ((caddr_t)X)
604 #ifdef AFS_DARWIN100_ENV
605 afs_syscall64_call(user_addr_t kparm, user_addr_t kparm2, user_addr_t kparm3,
606 user_addr_t kparm4, user_addr_t kparm5, user_addr_t kparm6)
608 afs_syscall_call(long parm, long parm2, long parm3,
609 long parm4, long parm5, long parm6)
613 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
615 #else /* AFS_SGI61_ENV */
617 #endif /* AFS_SGI61_ENV */
618 #ifdef AFS_DARWIN100_ENV
619 /* AFSKPTR macro relies on this name format/mapping */
620 afs_uint32 parm = (afs_uint32)kparm;
621 afs_uint32 parm2 = (afs_uint32)kparm2;
622 afs_uint32 parm3 = (afs_uint32)kparm3;
623 afs_uint32 parm4 = (afs_uint32)kparm4;
624 afs_uint32 parm5 = (afs_uint32)kparm5;
625 afs_uint32 parm6 = (afs_uint32)kparm6;
628 AFS_STATCNT(afs_syscall_call);
635 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
636 /* only root can run this code */
637 #if defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
638 # if defined(KERNEL_HAVE_UERROR)
646 #ifdef AFS_DARWIN80_ENV
652 #ifdef AFS_DARWIN80_ENV
655 #ifdef AFS_DAEMONOP_ENV
656 # if defined(AFS_NEW_BKG)
657 if (parm == AFSOP_BKG_HANDLER) {
658 /* if afs_uspc_param grows this should be checked */
659 struct afs_uspc_param *mvParam = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
664 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)mvParam,
665 sizeof(struct afs_uspc_param), code);
666 namebufsz = mvParam->bufSz;
667 param1 = afs_osi_Alloc(namebufsz);
668 osi_Assert(param1 != NULL);
669 param2 = afs_osi_Alloc(namebufsz);
670 osi_Assert(param2 != NULL);
672 while (afs_initState < AFSOP_START_BKG)
673 afs_osi_Sleep(&afs_initState);
674 if (afs_initState < AFSOP_GO) {
675 afs_initState = AFSOP_GO;
676 afs_osi_Wakeup(&afs_initState);
679 code = afs_BackgroundDaemon(mvParam, param1, param2);
683 /* for reqs where pointers are strings: */
684 if (mvParam->reqtype == AFS_USPC_UMV) {
685 /* don't copy out random kernel memory */
686 AFS_COPYOUT(param2, AFSKPTR(parm4),
687 MIN(namebufsz, strlen((char *)param2)+1), code);
688 AFS_COPYOUT(param1, AFSKPTR(parm3),
689 MIN(namebufsz, strlen((char *)param1)+1), code);
691 AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
692 sizeof(struct afs_uspc_param), code);
695 afs_osi_Free(param1, namebufsz);
696 afs_osi_Free(param2, namebufsz);
697 osi_FreeSmallSpace(mvParam);
699 # endif /* AFS_NEW_BKG */
700 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
701 || parm == AFSOP_RXLISTENER_DAEMON) {
702 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
704 #else /* !AFS_DAEMONOP_ENV */
705 if (parm == AFSOP_START_RXCALLBACK) {
709 # ifndef RXK_LISTENER_ENV
710 code = afs_InitSetup(parm2);
712 # endif /* !RXK_LISTENER_ENV */
714 # ifdef RXK_LISTENER_ENV
715 while (afs_RX_Running != 2)
716 afs_osi_Sleep(&afs_RX_Running);
717 # else /* !RXK_LISTENER_ENV */
719 rx_enablePeerRPCStats();
722 rx_enableProcessRPCStats();
724 afs_initState = AFSOP_START_AFS;
725 afs_osi_Wakeup(&afs_initState);
726 # endif /* RXK_LISTENER_ENV */
728 afs_RXCallBackServer();
733 exit(CLD_EXITED, code);
734 # endif /* AFS_SGI_ENV */
736 # ifdef RXK_LISTENER_ENV
737 else if (parm == AFSOP_RXLISTENER_DAEMON) {
741 code = afs_InitSetup(parm2);
743 rx_enablePeerRPCStats();
746 rx_enableProcessRPCStats();
749 afs_initState = AFSOP_START_AFS;
750 afs_osi_Wakeup(&afs_initState);
753 afs_osi_Wakeup(&afs_RX_Running);
755 afs_osi_RxkRegister();
756 # endif /* !UKERNEL */
762 exit(CLD_EXITED, code);
763 # endif /* AFS_SGI_ENV */
765 # endif /* RXK_LISTENER_ENV */
766 else if (parm == AFSOP_START_AFS) {
771 while (afs_initState < AFSOP_START_AFS)
772 afs_osi_Sleep(&afs_initState);
774 afs_initState = AFSOP_START_BKG;
775 afs_osi_Wakeup(&afs_initState);
782 # endif /* AFS_SGI_ENV */
783 } else if (parm == AFSOP_START_CS) {
785 afs_CheckServerDaemon();
790 # endif /* AFS_SGI_ENV */
792 } else if (parm == AFSOP_START_BKG) {
793 while (afs_initState < AFSOP_START_BKG)
794 afs_osi_Sleep(&afs_initState);
795 if (afs_initState < AFSOP_GO) {
796 afs_initState = AFSOP_GO;
797 afs_osi_Wakeup(&afs_initState);
799 /* start the bkg daemon */
801 # ifdef AFS_AIX32_ENV
803 afs_BioDaemon(parm2);
805 # endif /* AFS_AIX32_ENV */
806 afs_BackgroundDaemon();
811 # endif /* AFS_SGI_ENV */
812 # endif /* ! AFS_NEW_BKG */
813 } else if (parm == AFSOP_START_TRUNCDAEMON) {
814 while (afs_initState < AFSOP_GO)
815 afs_osi_Sleep(&afs_initState);
816 /* start the bkg daemon */
818 afs_CacheTruncateDaemon();
823 # endif /* AFS_SGI_ENV */
825 # if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
826 else if (parm == AFSOP_RXEVENT_DAEMON) {
827 while (afs_initState < AFSOP_START_BKG)
828 afs_osi_Sleep(&afs_initState);
830 afs_rxevent_daemon();
835 # endif /* AFS_SGI_ENV */
837 # endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV || RXK_UPCALL_ENV */
838 #endif /* AFS_DAEMONOP_ENV */
839 else if (parm == AFSOP_BASIC_INIT) {
842 while (!afs_InitSetup_done)
843 afs_osi_Sleep(&afs_InitSetup_done);
845 #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)
846 temp = AFS_MINBUFFERS; /* Should fix this soon */
848 /* number of 2k buffers we could get from all of the buffer space */
849 temp = ((afs_bufferpages * NBPG) >> 11);
850 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
851 if (temp < AFS_MINBUFFERS)
852 temp = AFS_MINBUFFERS; /* though we really should have this many */
855 afs_rootFid.Fid.Volume = 0;
857 } else if (parm == AFSOP_BUCKETPCT) {
858 /* need to enable this now, will disable again before GO
859 if we don't have 100% */
869 } else if (parm == AFSOP_ADDCELL) {
870 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
871 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
872 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
873 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
875 osi_Assert(tcell != NULL);
876 code = afs_InitDynroot();
878 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
882 if (parm4 > sizeof(tcell->cellName))
885 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)tcell->cellName, parm4, code);
887 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
891 afs_osi_Free(tcell, sizeof(struct afsop_cell));
892 } else if (parm == AFSOP_ADDCELL2) {
893 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
894 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
895 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
898 osi_Assert(tcell != NULL);
899 osi_Assert(tbuffer != NULL);
900 osi_Assert(tbuffer1 != NULL);
901 code = afs_InitDynroot();
904 /* wait for basic init - XXX can't find any reason we need this? */
905 while (afs_initState < AFSOP_START_BKG)
906 afs_osi_Sleep(&afs_initState);
909 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
913 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
917 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
921 cflags |= CLinkedCell;
929 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
933 afs_osi_Free(tcell, sizeof(struct afsop_cell));
934 osi_FreeSmallSpace(tbuffer);
935 osi_FreeSmallSpace(tbuffer1);
936 } else if (parm == AFSOP_ADDCELLALIAS) {
939 * parm2 is the alias name
940 * parm3 is the real cell name
942 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
943 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
945 code = afs_InitDynroot();
947 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
951 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
954 afs_NewCellAlias(aliasName, cellName);
955 osi_FreeSmallSpace(aliasName);
956 osi_FreeSmallSpace(cellName);
957 } else if (parm == AFSOP_SET_THISCELL) {
960 * parm2 is the primary cell name
962 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
965 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
967 afs_SetPrimaryCell(cell);
968 osi_FreeSmallSpace(cell);
970 code = afs_InitDynroot();
972 } else if (parm == AFSOP_CACHEINIT) {
973 struct afs_cacheParams cparms;
975 if (afs_CacheInit_Done)
978 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
980 #if defined(KERNEL_HAVE_UERROR)
986 afs_CacheInit_Done = 1;
987 code = afs_icl_InitLogs();
988 if (cparms.setTimeFlag) {
989 afs_warn("afs: AFSOP_CACHEINIT setTimeFlag ignored; are you "
990 "running an old afsd?\n");
994 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
995 cparms.cacheBlocks, cparms.cacheDcaches,
996 cparms.cacheVolumes, cparms.chunkSize,
997 cparms.memCacheFlag, cparms.inodes, cparms.users,
998 cparms.dynamic_vcaches);
1000 } else if (parm == AFSOP_CACHEINODE) {
1001 ino_t ainode = parm2;
1002 /* wait for basic init */
1003 while (afs_initState < AFSOP_START_BKG)
1004 afs_osi_Sleep(&afs_initState);
1006 #ifdef AFS_DARWIN80_ENV
1009 /* do it by inode */
1010 #ifdef AFS_SGI62_ENV
1011 ainode = (ainode << 32) | (parm3 & 0xffffffff);
1013 code = afs_InitCacheFile(NULL, ainode);
1014 #ifdef AFS_DARWIN80_ENV
1017 } else if (parm == AFSOP_CACHEDIRS) {
1018 afs_numfilesperdir = parm2;
1019 afs_osi_Wakeup(&afs_initState);
1020 } else if (parm == AFSOP_CACHEFILES) {
1021 afs_numcachefiles = parm2;
1022 afs_osi_Wakeup(&afs_initState);
1023 } else if (parm == AFSOP_ROOTVOLUME) {
1024 /* wait for basic init */
1025 while (afs_initState < AFSOP_START_BKG)
1026 afs_osi_Sleep(&afs_initState);
1029 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
1030 sizeof(afs_rootVolumeName), &bufferSize, code);
1031 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
1034 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
1035 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
1036 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
1039 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
1042 osi_FreeSmallSpace(tbuffer);
1046 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
1047 /* We have the cache dir copied in. Call the cache init routine */
1048 #ifdef AFS_DARWIN80_ENV
1051 if (parm == AFSOP_CACHEFILE) {
1052 code = afs_InitCacheFile(tbuffer, 0);
1053 } else if (parm == AFSOP_CACHEINFO) {
1054 code = afs_InitCacheInfo(tbuffer);
1055 } else if (parm == AFSOP_VOLUMEINFO) {
1056 code = afs_InitVolumeInfo(tbuffer);
1057 } else if (parm == AFSOP_CELLINFO) {
1058 code = afs_InitCellInfo(tbuffer);
1060 #ifdef AFS_DARWIN80_ENV
1064 osi_FreeSmallSpace(tbuffer);
1065 } else if (parm == AFSOP_GO) {
1066 /* the generic initialization calls come here. One parameter: should we do the
1067 * set-time operation on this workstation */
1071 while (afs_initState < AFSOP_GO)
1072 afs_osi_Sleep(&afs_initState);
1073 afs_initState = 101;
1075 /* parm2 used to set afs_setTime */
1076 afs_warn("afs: AFSOP_GO setTime flag ignored; are you running an "
1079 if (afs_tpct1 + afs_tpct2 != 100) {
1086 afs_osi_Wakeup(&afs_initState);
1087 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
1088 afs_nfsclient_init();
1090 if (afs_uuid_create(&afs_cb_interface.uuid) != 0)
1091 memset(&afs_cb_interface.uuid, 0, sizeof(afsUUID));
1093 printf("found %d non-empty cache files (%d%%).\n",
1094 afs_stats_cmperf.cacheFilesReused,
1095 (100 * afs_stats_cmperf.cacheFilesReused) /
1096 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
1097 cacheNumEntries : 1));
1098 } else if (parm == AFSOP_ADVISEADDR) {
1099 /* pass in the host address to the rx package */
1103 afs_int32 count = parm2;
1105 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1106 afs_int32 *maskbuffer =
1107 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1108 afs_int32 *mtubuffer =
1109 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1112 osi_Assert(buffer != NULL);
1113 osi_Assert(maskbuffer != NULL);
1114 osi_Assert(mtubuffer != NULL);
1115 /* This is a refresh */
1116 if (count & 0x40000000) {
1117 count &= ~0x40000000;
1118 /* Can't bind after we start. Fix? */
1119 count &= ~0x80000000;
1123 /* Bind, but only if there's only one address configured */
1124 if ( count & 0x80000000) {
1125 count &= ~0x80000000;
1130 if (count > AFS_MAX_INTERFACE_ADDR) {
1132 count = AFS_MAX_INTERFACE_ADDR;
1135 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
1138 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
1139 count * sizeof(afs_int32), code);
1141 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
1142 count * sizeof(afs_int32), code);
1145 afs_cb_interface.numberOfInterfaces = count;
1146 for (i = 0; i < count; i++) {
1147 afs_cb_interface.addr_in[i] = buffer[i];
1148 #ifdef AFS_USERSPACE_IP_ADDR
1149 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
1150 * machines IP addresses when in the kernel (the in_ifaddr
1151 * struct is not available), so we pass the info in at
1152 * startup. We also pass in the subnetmask and mtu size. The
1153 * subnetmask is used when setting the rank:
1154 * afsi_SetServerIPRank(); and the mtu size is used when
1155 * finding the best mtu size. rxi_FindIfnet() is replaced
1156 * with rxi_Findcbi().
1158 afs_cb_interface.subnetmask[i] =
1159 (parm4 ? maskbuffer[i] : 0xffffffff);
1160 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1163 rxi_setaddr(buffer[0]);
1166 rx_bindhost = buffer[0];
1168 rx_bindhost = htonl(INADDR_ANY);
1174 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1175 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1176 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1179 afs_CheckServers(1, NULL); /* check down servers */
1180 afs_CheckServers(0, NULL); /* check up servers */
1183 else if (parm == AFSOP_SHUTDOWN) {
1184 afs_cold_shutdown = 0;
1186 afs_cold_shutdown = 1;
1187 if (afs_globalVFS != 0) {
1188 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1192 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1194 vfsmount(parm2, parm3, parm4, parm5);
1195 #else /* defined(AFS_HPUX_ENV) */
1196 # if defined(KERNEL_HAVE_UERROR)
1201 #endif /* defined(AFS_HPUX_ENV) */
1202 } else if (parm == AFSOP_CLOSEWAIT) {
1203 afs_SynchronousCloses = 'S';
1204 } else if (parm == AFSOP_GETMTU) {
1206 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1207 # ifdef AFS_USERSPACE_IP_ADDR
1209 i = rxi_Findcbi(parm2);
1210 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1211 # else /* AFS_USERSPACE_IP_ADDR */
1214 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1215 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1216 # endif /* else AFS_USERSPACE_IP_ADDR */
1217 #endif /* !AFS_SUN5_ENV */
1219 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1220 sizeof(afs_int32), code);
1221 #ifdef AFS_AIX32_ENV
1222 /* this is disabled for now because I can't figure out how to get access
1223 * to these kernel variables. It's only for supporting user-mode rx
1224 * programs -- it makes a huge difference on the 220's in my testbed,
1225 * though I don't know why. The bosserver does this with /etc/no, so it's
1226 * being handled a different way for the servers right now. */
1228 static adjusted = 0;
1229 extern u_long sb_max_dflt;
1232 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1233 if (sb_max < 131072) sb_max = 131072;
1236 #endif /* AFS_AIX32_ENV */
1237 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1238 afs_uint32 mask = 0;
1239 #if !defined(AFS_SUN5_ENV)
1240 # ifdef AFS_USERSPACE_IP_ADDR
1242 i = rxi_Findcbi(parm2);
1244 mask = afs_cb_interface.subnetmask[i];
1248 # else /* AFS_USERSPACE_IP_ADDR */
1251 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1254 # endif /* else AFS_USERSPACE_IP_ADDR */
1255 #endif /* !AFS_SUN5_ENV */
1257 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1258 sizeof(afs_int32), code);
1260 else if (parm == AFSOP_AFSDB_HANDLER) {
1261 int sizeArg = (int)parm4;
1262 int kmsgLen = sizeArg & 0xffff;
1263 int cellLen = (sizeArg & 0xffff0000) >> 16;
1264 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1265 char *cellname = afs_osi_Alloc(cellLen);
1267 osi_Assert(kmsg != NULL);
1268 osi_Assert(cellname != NULL);
1270 afs_osi_MaskUserLoop();
1272 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1273 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1275 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1278 if (code == -2) { /* Shutting down? */
1284 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1285 afs_osi_Free(kmsg, kmsgLen);
1286 afs_osi_Free(cellname, cellLen);
1288 else if (parm == AFSOP_SET_DYNROOT) {
1289 code = afs_SetDynrootEnable(parm2);
1290 } else if (parm == AFSOP_SET_FAKESTAT) {
1291 afs_fakestat_enable = parm2;
1293 } else if (parm == AFSOP_SET_BACKUPTREE) {
1294 afs_bkvolpref = parm2;
1295 } else if (parm == AFSOP_SET_RXPCK) {
1296 rx_extraPackets = parm2;
1297 afscall_set_rxpck_received = 1;
1298 } else if (parm == AFSOP_SET_RXMAXMTU) {
1299 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1300 } else if (parm == AFSOP_SET_RXMAXFRAGS) {
1301 rxi_nSendFrags = rxi_nRecvFrags = parm2;
1308 #ifdef AFS_LINUX20_ENV
1316 * Initstate in the range 0 < x < 100 are early initialization states.
1317 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1318 * the cache may be initialized.
1319 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1320 * is done after all the cache initialization has been done.
1321 * Initstate of 200 means that the volume has been looked up once, possibly
1323 * Initstate of 300 means that the volume has been *successfully* looked up.
1330 AFS_STATCNT(afs_CheckInit);
1331 if (afs_initState <= 100)
1332 code = ENXIO; /* never finished init phase */
1333 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1334 while (afs_initState < 200)
1335 afs_osi_Sleep(&afs_initState);
1336 } else if (afs_initState == 200)
1337 code = ETIMEDOUT; /* didn't find root volume */
1341 int afs_shuttingdown = 0;
1345 extern short afs_brsDaemons;
1346 extern afs_int32 afs_CheckServerDaemonStarted;
1347 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1348 extern struct osi_file *afs_cacheInodep;
1350 AFS_STATCNT(afs_shutdown);
1351 if (afs_initState == 0) {
1352 afs_warn("AFS not initialized - not shutting down\n");
1356 if (afs_shuttingdown)
1359 /* Give up all of our callbacks if we can. This must be done before setting
1360 * afs_shuttingdown, since it calls afs_InitReq, which will fail if
1361 * afs_shuttingdown is set. */
1364 afs_shuttingdown = 1;
1366 if (afs_cold_shutdown)
1367 afs_warn("afs: COLD ");
1369 afs_warn("afs: WARM ");
1370 afs_warn("shutting down of: vcaches... ");
1372 #if !defined(AFS_FBSD_ENV)
1373 /* The FBSD afs_unmount() calls vflush(), which reclaims all vnodes
1374 * on the mountpoint, flushing them in the process. In the presence
1375 * of bugs, flushing again here can cause panics. */
1376 afs_FlushAllVCaches();
1381 afs_termState = AFSOP_STOP_RXCALLBACK;
1382 rx_WakeupServerProcs();
1383 #ifdef AFS_AIX51_ENV
1384 shutdown_rxkernel();
1386 /* close rx server connections here? */
1387 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1388 afs_osi_Sleep(&afs_termState);
1390 afs_warn("afs... ");
1391 while (afs_termState == AFSOP_STOP_AFS) {
1392 afs_osi_CancelWait(&AFS_WaitHandler);
1393 afs_osi_Sleep(&afs_termState);
1395 if (afs_CheckServerDaemonStarted) {
1396 while (afs_termState == AFSOP_STOP_CS) {
1397 afs_osi_CancelWait(&AFS_CSWaitHandler);
1398 afs_osi_Sleep(&afs_termState);
1401 afs_warn("BkG... ");
1402 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1403 while (afs_termState == AFSOP_STOP_BKG) {
1404 afs_osi_Wakeup(&afs_brsDaemons);
1405 afs_osi_Sleep(&afs_termState);
1407 afs_warn("CTrunc... ");
1408 /* Cancel cache truncate daemon. */
1409 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1410 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1411 afs_osi_Sleep(&afs_termState);
1413 afs_warn("AFSDB... ");
1415 while (afs_termState == AFSOP_STOP_AFSDB)
1416 afs_osi_Sleep(&afs_termState);
1417 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
1418 afs_warn("RxEvent... ");
1419 /* cancel rx event daemon */
1420 while (afs_termState == AFSOP_STOP_RXEVENT)
1421 afs_osi_Sleep(&afs_termState);
1422 # if defined(RXK_LISTENER_ENV)
1424 afs_warn("UnmaskRxkSignals... ");
1425 afs_osi_UnmaskRxkSignals();
1427 /* cancel rx listener */
1428 afs_warn("RxListener... ");
1429 osi_StopListener(); /* This closes rx_socket. */
1430 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1431 afs_warn("Sleep... ");
1432 afs_osi_Sleep(&afs_termState);
1437 #if defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
1438 afs_warn("NetIfPoller... ");
1439 osi_StopNetIfPoller();
1442 afs_termState = AFSOP_STOP_COMPLETE;
1444 #ifdef AFS_AIX51_ENV
1448 shutdown_bufferpackage();
1452 * Close file only after daemons which can write to it are stopped.
1453 * Need to close before the osinet shutdown to avoid failing check
1454 * for dangling memory allocations.
1456 if (afs_cacheInodep) { /* memcache won't set this */
1457 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1458 afs_cacheInodep = 0;
1461 * Shutdown the ICL logs - needed to free allocated memory space and avoid
1462 * warnings from shutdown_osinet
1467 shutdown_vnodeops();
1468 shutdown_memcache();
1470 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV))
1471 shutdown_exporter();
1476 /* The following hold the cm stats */
1477 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1478 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1479 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1480 afs_warn(" ALL allocated tables... ");
1482 afs_shuttingdown = 0;
1485 return; /* Just kill daemons for now */
1489 shutdown_afstest(void)
1491 AFS_STATCNT(shutdown_afstest);
1492 afs_initState = afs_termState = 0;
1493 AFS_Running = afs_CB_Running = 0;
1494 afs_CacheInit_Done = afs_Go_Done = 0;
1495 if (afs_cold_shutdown) {
1496 *afs_rootVolumeName = 0;