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 afs_int32 afs_setTime = 0;
62 int afs_cold_shutdown = 0;
63 char afs_SynchronousCloses = '\0';
64 static int afs_CB_Running = 0;
65 static int AFS_Running = 0;
66 static int afs_CacheInit_Done = 0;
67 static int afs_Go_Done = 0;
68 extern struct interfaceAddr afs_cb_interface;
69 static int afs_RX_Running = 0;
70 static int afs_InitSetup_done = 0;
71 afs_int32 afs_numcachefiles = -1;
72 afs_int32 afs_numfilesperdir = -1;
73 char afs_cachebasedir[1024];
75 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
76 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
77 afs_int32 afs_rx_idledead = AFS_IDLEDEADTIME;
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(RX_CALL_TIMEOUT);
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:
338 sprintf(current->comm, "afs_bkgstart");
340 complete(arg->complete);
341 while (afs_initState < AFSOP_START_BKG)
342 afs_osi_Sleep(&afs_initState);
343 if (afs_initState < AFSOP_GO) {
344 afs_initState = AFSOP_GO;
345 afs_osi_Wakeup(&afs_initState);
347 sprintf(current->comm, "afs_background");
348 afs_BackgroundDaemon();
350 complete_and_exit(0, 0);
352 case AFSOP_START_TRUNCDAEMON:
353 sprintf(current->comm, "afs_trimstart");
355 complete(arg->complete);
356 while (afs_initState < AFSOP_GO)
357 afs_osi_Sleep(&afs_initState);
358 sprintf(current->comm, "afs_cachetrim");
359 afs_CacheTruncateDaemon();
361 complete_and_exit(0, 0);
364 sprintf(current->comm, "afs_checkserver");
366 complete(arg->complete);
367 afs_CheckServerDaemon();
369 complete_and_exit(0, 0);
371 case AFSOP_RXEVENT_DAEMON:
372 sprintf(current->comm, "afs_evtstart");
373 # ifdef SYS_SETPRIORITY_EXPORTED
374 sys_setpriority(PRIO_PROCESS, 0, -10);
376 # ifdef CURRENT_INCLUDES_NICE
381 complete(arg->complete);
382 while (afs_initState < AFSOP_START_BKG)
383 afs_osi_Sleep(&afs_initState);
384 sprintf(current->comm, "afs_rxevent");
385 afs_rxevent_daemon();
387 complete_and_exit(0, 0);
389 #ifdef RXK_LISTENER_ENV
390 case AFSOP_RXLISTENER_DAEMON:
391 sprintf(current->comm, "afs_lsnstart");
392 # ifdef SYS_SETPRIORITY_EXPORTED
393 sys_setpriority(PRIO_PROCESS, 0, -10);
395 # ifdef CURRENT_INCLUDES_NICE
400 complete(arg->complete);
401 afs_initState = AFSOP_START_AFS;
402 afs_osi_Wakeup(&afs_initState);
404 afs_osi_Wakeup(&afs_RX_Running);
405 afs_osi_RxkRegister();
406 sprintf(current->comm, "afs_rxlistener");
409 complete_and_exit(0, 0);
413 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
420 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
421 afsd_launcher(struct work_struct *work)
423 afsd_launcher(void *rock)
426 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
427 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
430 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
431 afs_warn("kernel_thread failed. afs startup will not complete\n");
435 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
438 DECLARE_COMPLETION(c);
439 # if defined(AFS_LINUX26_ENV)
440 # if defined(INIT_WORK_HAS_DATA)
441 struct work_struct tq;
446 struct afsd_thread_info info;
447 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
452 # if defined(AFS_LINUX26_ENV)
453 # if !defined(INIT_WORK_HAS_DATA)
454 INIT_WORK(&info.tq, afsd_launcher);
455 schedule_work(&info.tq);
457 INIT_WORK(&tq, afsd_launcher, &info);
462 INIT_LIST_HEAD(&tq.list);
463 tq.routine = afsd_launcher;
468 /* we need to wait cause we passed stack pointers around.... */
469 wait_for_completion(&c);
475 struct afs_daemonop_args {
481 afsd_thread(struct afs_daemonop_args *args)
483 long parm = args->parm;
486 cv_signal(&args->cv);
489 case AFSOP_START_RXCALLBACK:
493 while (afs_RX_Running != 2)
494 afs_osi_Sleep(&afs_RX_Running);
495 afs_RXCallBackServer();
498 case AFSOP_START_AFS:
502 while (afs_initState < AFSOP_START_AFS)
503 afs_osi_Sleep(&afs_initState);
504 afs_initState = AFSOP_START_BKG;
505 afs_osi_Wakeup(&afs_initState);
509 case AFSOP_START_BKG:
510 while (afs_initState < AFSOP_START_BKG)
511 afs_osi_Sleep(&afs_initState);
512 if (afs_initState < AFSOP_GO) {
513 afs_initState = AFSOP_GO;
514 afs_osi_Wakeup(&afs_initState);
516 afs_BackgroundDaemon();
519 case AFSOP_START_TRUNCDAEMON:
520 while (afs_initState < AFSOP_GO)
521 afs_osi_Sleep(&afs_initState);
522 afs_CacheTruncateDaemon();
526 afs_CheckServerDaemon();
529 case AFSOP_RXEVENT_DAEMON:
530 while (afs_initState < AFSOP_START_BKG)
531 afs_osi_Sleep(&afs_initState);
532 afs_rxevent_daemon();
535 case AFSOP_RXLISTENER_DAEMON:
536 afs_initState = AFSOP_START_AFS;
537 afs_osi_Wakeup(&afs_initState);
539 afs_osi_Wakeup(&afs_RX_Running);
540 afs_osi_RxkRegister();
546 afs_warn("Unknown op %ld in afsd_thread()\n", parm);
555 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
558 struct afs_daemonop_args args;
560 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
566 cv_init(&args.cv, "AFS DaemonOp cond var", CV_DEFAULT, NULL);
568 if (thread_create(NULL, 0, afsd_thread, &args, 0, &p0, TS_RUN,
569 minclsyspri) == NULL) {
571 afs_warn("thread_create failed: AFS startup will not complete\n");
574 /* we passed &args to the new thread, which is on the stack. wait until
575 * it has read the arguments so it doesn't try to read the args after we
577 cv_wait(&args.cv, &afs_global_lock);
579 cv_destroy(&args.cv);
581 #endif /* AFS_SUN5_ENV */
583 #ifdef AFS_DARWIN100_ENV
584 # define AFSKPTR(X) k ## X
586 afs_syscall_call(long parm, long parm2, long parm3,
587 long parm4, long parm5, long parm6)
589 return afs_syscall64_call(CAST_USER_ADDR_T((parm)),
590 CAST_USER_ADDR_T((parm2)),
591 CAST_USER_ADDR_T((parm3)),
592 CAST_USER_ADDR_T((parm4)),
593 CAST_USER_ADDR_T((parm5)),
594 CAST_USER_ADDR_T((parm6)));
597 # define AFSKPTR(X) ((caddr_t)X)
600 #ifdef AFS_DARWIN100_ENV
601 afs_syscall64_call(user_addr_t kparm, user_addr_t kparm2, user_addr_t kparm3,
602 user_addr_t kparm4, user_addr_t kparm5, user_addr_t kparm6)
604 afs_syscall_call(long parm, long parm2, long parm3,
605 long parm4, long parm5, long parm6)
609 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
611 #else /* AFS_SGI61_ENV */
613 #endif /* AFS_SGI61_ENV */
614 #ifdef AFS_DARWIN100_ENV
615 /* AFSKPTR macro relies on this name format/mapping */
616 afs_uint32 parm = (afs_uint32)kparm;
617 afs_uint32 parm2 = (afs_uint32)kparm2;
618 afs_uint32 parm3 = (afs_uint32)kparm3;
619 afs_uint32 parm4 = (afs_uint32)kparm4;
620 afs_uint32 parm5 = (afs_uint32)kparm5;
621 afs_uint32 parm6 = (afs_uint32)kparm6;
624 AFS_STATCNT(afs_syscall_call);
631 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
632 /* only root can run this code */
633 #if defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
634 # if defined(KERNEL_HAVE_UERROR)
642 #ifdef AFS_DARWIN80_ENV
648 #ifdef AFS_DARWIN80_ENV
651 #ifdef AFS_DAEMONOP_ENV
652 # if defined(AFS_DARWIN80_ENV)
653 if (parm == AFSOP_BKG_HANDLER) {
654 /* if afs_uspc_param grows this should be checked */
655 struct afs_uspc_param *mvParam = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
660 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)mvParam,
661 sizeof(struct afs_uspc_param), code);
662 namebufsz = mvParam->bufSz;
663 param1 = afs_osi_Alloc(namebufsz);
664 osi_Assert(param1 != NULL);
665 param2 = afs_osi_Alloc(namebufsz);
666 osi_Assert(param2 != NULL);
668 while (afs_initState < AFSOP_START_BKG)
669 afs_osi_Sleep(&afs_initState);
670 if (afs_initState < AFSOP_GO) {
671 afs_initState = AFSOP_GO;
672 afs_osi_Wakeup(&afs_initState);
675 code = afs_BackgroundDaemon(mvParam, param1, param2);
679 /* for reqs where pointers are strings: */
680 if (mvParam->reqtype == AFS_USPC_UMV) {
681 /* don't copy out random kernel memory */
682 AFS_COPYOUT(param2, AFSKPTR(parm4),
683 MIN(namebufsz, strlen((char *)param2)+1), code);
684 AFS_COPYOUT(param1, AFSKPTR(parm3),
685 MIN(namebufsz, strlen((char *)param1)+1), code);
687 AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
688 sizeof(struct afs_uspc_param), code);
691 afs_osi_Free(param1, namebufsz);
692 afs_osi_Free(param2, namebufsz);
693 osi_FreeSmallSpace(mvParam);
695 # endif /* DARWIN80 */
696 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
697 || parm == AFSOP_RXLISTENER_DAEMON) {
698 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
700 #else /* !AFS_DAEMONOP_ENV */
701 if (parm == AFSOP_START_RXCALLBACK) {
705 # ifndef RXK_LISTENER_ENV
706 code = afs_InitSetup(parm2);
708 # endif /* !RXK_LISTENER_ENV */
710 # ifdef RXK_LISTENER_ENV
711 while (afs_RX_Running != 2)
712 afs_osi_Sleep(&afs_RX_Running);
713 # else /* !RXK_LISTENER_ENV */
715 rx_enablePeerRPCStats();
718 rx_enableProcessRPCStats();
720 afs_initState = AFSOP_START_AFS;
721 afs_osi_Wakeup(&afs_initState);
722 # endif /* RXK_LISTENER_ENV */
724 afs_RXCallBackServer();
729 exit(CLD_EXITED, code);
730 # endif /* AFS_SGI_ENV */
732 # ifdef RXK_LISTENER_ENV
733 else if (parm == AFSOP_RXLISTENER_DAEMON) {
737 code = afs_InitSetup(parm2);
739 rx_enablePeerRPCStats();
742 rx_enableProcessRPCStats();
745 afs_initState = AFSOP_START_AFS;
746 afs_osi_Wakeup(&afs_initState);
749 afs_osi_Wakeup(&afs_RX_Running);
751 afs_osi_RxkRegister();
752 # endif /* !UKERNEL */
758 exit(CLD_EXITED, code);
759 # endif /* AFS_SGI_ENV */
761 # endif /* RXK_LISTENER_ENV */
762 else if (parm == AFSOP_START_AFS) {
767 while (afs_initState < AFSOP_START_AFS)
768 afs_osi_Sleep(&afs_initState);
770 afs_initState = AFSOP_START_BKG;
771 afs_osi_Wakeup(&afs_initState);
778 # endif /* AFS_SGI_ENV */
779 } else if (parm == AFSOP_START_CS) {
781 afs_CheckServerDaemon();
786 # endif /* AFS_SGI_ENV */
787 # ifndef AFS_DARWIN80_ENV
788 } else if (parm == AFSOP_START_BKG) {
789 while (afs_initState < AFSOP_START_BKG)
790 afs_osi_Sleep(&afs_initState);
791 if (afs_initState < AFSOP_GO) {
792 afs_initState = AFSOP_GO;
793 afs_osi_Wakeup(&afs_initState);
795 /* start the bkg daemon */
797 # ifdef AFS_AIX32_ENV
799 afs_BioDaemon(parm2);
801 # endif /* AFS_AIX32_ENV */
802 afs_BackgroundDaemon();
807 # endif /* AFS_SGI_ENV */
808 # endif /* ! AFS_DARWIN80_ENV */
809 } else if (parm == AFSOP_START_TRUNCDAEMON) {
810 while (afs_initState < AFSOP_GO)
811 afs_osi_Sleep(&afs_initState);
812 /* start the bkg daemon */
814 afs_CacheTruncateDaemon();
819 # endif /* AFS_SGI_ENV */
821 # if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
822 else if (parm == AFSOP_RXEVENT_DAEMON) {
823 while (afs_initState < AFSOP_START_BKG)
824 afs_osi_Sleep(&afs_initState);
826 afs_rxevent_daemon();
831 # endif /* AFS_SGI_ENV */
833 # endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV || RXK_UPCALL_ENV */
834 #endif /* AFS_DAEMONOP_ENV */
835 else if (parm == AFSOP_BASIC_INIT) {
838 while (!afs_InitSetup_done)
839 afs_osi_Sleep(&afs_InitSetup_done);
841 #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)
842 temp = AFS_MINBUFFERS; /* Should fix this soon */
844 /* number of 2k buffers we could get from all of the buffer space */
845 temp = ((afs_bufferpages * NBPG) >> 11);
846 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
847 if (temp < AFS_MINBUFFERS)
848 temp = AFS_MINBUFFERS; /* though we really should have this many */
851 afs_rootFid.Fid.Volume = 0;
853 } else if (parm == AFSOP_BUCKETPCT) {
854 /* need to enable this now, will disable again before GO
855 if we don't have 100% */
865 } else if (parm == AFSOP_ADDCELL) {
866 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
867 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
868 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
869 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
871 osi_Assert(tcell != NULL);
872 code = afs_InitDynroot();
874 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
878 if (parm4 > sizeof(tcell->cellName))
881 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)tcell->cellName, parm4, code);
883 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
887 afs_osi_Free(tcell, sizeof(struct afsop_cell));
888 } else if (parm == AFSOP_ADDCELL2) {
889 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
890 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
891 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
894 osi_Assert(tcell != NULL);
895 osi_Assert(tbuffer != NULL);
896 osi_Assert(tbuffer1 != NULL);
897 code = afs_InitDynroot();
900 /* wait for basic init - XXX can't find any reason we need this? */
901 while (afs_initState < AFSOP_START_BKG)
902 afs_osi_Sleep(&afs_initState);
905 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
909 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
913 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
917 cflags |= CLinkedCell;
925 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
929 afs_osi_Free(tcell, sizeof(struct afsop_cell));
930 osi_FreeSmallSpace(tbuffer);
931 osi_FreeSmallSpace(tbuffer1);
932 } else if (parm == AFSOP_ADDCELLALIAS) {
935 * parm2 is the alias name
936 * parm3 is the real cell name
938 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
939 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
941 code = afs_InitDynroot();
943 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
947 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
950 afs_NewCellAlias(aliasName, cellName);
951 osi_FreeSmallSpace(aliasName);
952 osi_FreeSmallSpace(cellName);
953 } else if (parm == AFSOP_SET_THISCELL) {
956 * parm2 is the primary cell name
958 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
961 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
963 afs_SetPrimaryCell(cell);
964 osi_FreeSmallSpace(cell);
966 code = afs_InitDynroot();
968 } else if (parm == AFSOP_CACHEINIT) {
969 struct afs_cacheParams cparms;
971 if (afs_CacheInit_Done)
974 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
976 #if defined(KERNEL_HAVE_UERROR)
982 afs_CacheInit_Done = 1;
983 code = afs_icl_InitLogs();
984 afs_setTime = cparms.setTimeFlag;
987 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
988 cparms.cacheBlocks, cparms.cacheDcaches,
989 cparms.cacheVolumes, cparms.chunkSize,
990 cparms.memCacheFlag, cparms.inodes, cparms.users,
991 cparms.dynamic_vcaches);
993 } else if (parm == AFSOP_CACHEINODE) {
994 ino_t ainode = parm2;
995 /* wait for basic init */
996 while (afs_initState < AFSOP_START_BKG)
997 afs_osi_Sleep(&afs_initState);
999 #ifdef AFS_DARWIN80_ENV
1002 /* do it by inode */
1003 #ifdef AFS_SGI62_ENV
1004 ainode = (ainode << 32) | (parm3 & 0xffffffff);
1006 code = afs_InitCacheFile(NULL, ainode);
1007 #ifdef AFS_DARWIN80_ENV
1010 } else if (parm == AFSOP_CACHEDIRS) {
1011 afs_numfilesperdir = parm2;
1012 afs_osi_Wakeup(&afs_initState);
1013 } else if (parm == AFSOP_CACHEFILES) {
1014 afs_numcachefiles = parm2;
1015 afs_osi_Wakeup(&afs_initState);
1016 } else if (parm == AFSOP_ROOTVOLUME) {
1017 /* wait for basic init */
1018 while (afs_initState < AFSOP_START_BKG)
1019 afs_osi_Sleep(&afs_initState);
1022 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
1023 sizeof(afs_rootVolumeName), &bufferSize, code);
1024 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
1027 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
1028 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
1029 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
1032 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
1035 osi_FreeSmallSpace(tbuffer);
1039 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
1040 /* We have the cache dir copied in. Call the cache init routine */
1041 #ifdef AFS_DARWIN80_ENV
1044 if (parm == AFSOP_CACHEFILE) {
1045 code = afs_InitCacheFile(tbuffer, 0);
1046 } else if (parm == AFSOP_CACHEINFO) {
1047 code = afs_InitCacheInfo(tbuffer);
1048 } else if (parm == AFSOP_VOLUMEINFO) {
1049 code = afs_InitVolumeInfo(tbuffer);
1050 } else if (parm == AFSOP_CELLINFO) {
1051 code = afs_InitCellInfo(tbuffer);
1053 #ifdef AFS_DARWIN80_ENV
1057 osi_FreeSmallSpace(tbuffer);
1058 } else if (parm == AFSOP_GO) {
1059 /* the generic initialization calls come here. One parameter: should we do the
1060 * set-time operation on this workstation */
1064 while (afs_initState < AFSOP_GO)
1065 afs_osi_Sleep(&afs_initState);
1066 afs_initState = 101;
1067 afs_setTime = parm2;
1068 if (afs_tpct1 + afs_tpct2 != 100) {
1075 afs_osi_Wakeup(&afs_initState);
1076 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
1077 afs_nfsclient_init();
1079 afs_uuid_create(&afs_cb_interface.uuid);
1080 printf("found %d non-empty cache files (%d%%).\n",
1081 afs_stats_cmperf.cacheFilesReused,
1082 (100 * afs_stats_cmperf.cacheFilesReused) /
1083 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
1084 cacheNumEntries : 1));
1085 } else if (parm == AFSOP_ADVISEADDR) {
1086 /* pass in the host address to the rx package */
1090 afs_int32 count = parm2;
1092 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1093 afs_int32 *maskbuffer =
1094 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1095 afs_int32 *mtubuffer =
1096 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1099 osi_Assert(buffer != NULL);
1100 osi_Assert(maskbuffer != NULL);
1101 osi_Assert(mtubuffer != NULL);
1102 /* This is a refresh */
1103 if (count & 0x40000000) {
1104 count &= ~0x40000000;
1105 /* Can't bind after we start. Fix? */
1106 count &= ~0x80000000;
1110 /* Bind, but only if there's only one address configured */
1111 if ( count & 0x80000000) {
1112 count &= ~0x80000000;
1117 if (count > AFS_MAX_INTERFACE_ADDR) {
1119 count = AFS_MAX_INTERFACE_ADDR;
1122 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
1125 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
1126 count * sizeof(afs_int32), code);
1128 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
1129 count * sizeof(afs_int32), code);
1132 afs_cb_interface.numberOfInterfaces = count;
1133 for (i = 0; i < count; i++) {
1134 afs_cb_interface.addr_in[i] = buffer[i];
1135 #ifdef AFS_USERSPACE_IP_ADDR
1136 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
1137 * machines IP addresses when in the kernel (the in_ifaddr
1138 * struct is not available), so we pass the info in at
1139 * startup. We also pass in the subnetmask and mtu size. The
1140 * subnetmask is used when setting the rank:
1141 * afsi_SetServerIPRank(); and the mtu size is used when
1142 * finding the best mtu size. rxi_FindIfnet() is replaced
1143 * with rxi_Findcbi().
1145 afs_cb_interface.subnetmask[i] =
1146 (parm4 ? maskbuffer[i] : 0xffffffff);
1147 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1150 rxi_setaddr(buffer[0]);
1153 rx_bindhost = buffer[0];
1155 rx_bindhost = htonl(INADDR_ANY);
1161 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1162 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1163 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1166 afs_CheckServers(1, NULL); /* check down servers */
1167 afs_CheckServers(0, NULL); /* check up servers */
1170 #ifdef AFS_SGI53_ENV
1171 else if (parm == AFSOP_NFSSTATICADDR) {
1172 extern int (*nfs_rfsdisptab_v2) ();
1173 nfs_rfsdisptab_v2 = (int (*)())parm2;
1174 } else if (parm == AFSOP_NFSSTATICADDR2) {
1175 extern int (*nfs_rfsdisptab_v2) ();
1177 nfs_rfsdisptab_v2 = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
1178 # else /* _K64U64 */
1179 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
1180 # endif /* _K64U64 */
1182 # if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
1183 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
1184 extern int (*afs_sblockp) ();
1185 extern void (*afs_sbunlockp) ();
1187 afs_sblockp = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
1188 afs_sbunlockp = (void (*)())((parm4 << 32) | (parm5 & 0xffffffff));
1190 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
1191 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
1192 # endif /* _K64U64 */
1194 # endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
1195 #endif /* AFS_SGI53_ENV */
1196 else if (parm == AFSOP_SHUTDOWN) {
1197 afs_cold_shutdown = 0;
1199 afs_cold_shutdown = 1;
1200 if (afs_globalVFS != 0) {
1201 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1205 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1207 vfsmount(parm2, parm3, parm4, parm5);
1208 #else /* defined(AFS_HPUX_ENV) */
1209 # if defined(KERNEL_HAVE_UERROR)
1214 #endif /* defined(AFS_HPUX_ENV) */
1215 } else if (parm == AFSOP_CLOSEWAIT) {
1216 afs_SynchronousCloses = 'S';
1217 } else if (parm == AFSOP_GETMTU) {
1219 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1220 # ifdef AFS_USERSPACE_IP_ADDR
1222 i = rxi_Findcbi(parm2);
1223 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1224 # else /* AFS_USERSPACE_IP_ADDR */
1227 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1228 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1229 # endif /* else AFS_USERSPACE_IP_ADDR */
1230 #endif /* !AFS_SUN5_ENV */
1232 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1233 sizeof(afs_int32), code);
1234 #ifdef AFS_AIX32_ENV
1235 /* this is disabled for now because I can't figure out how to get access
1236 * to these kernel variables. It's only for supporting user-mode rx
1237 * programs -- it makes a huge difference on the 220's in my testbed,
1238 * though I don't know why. The bosserver does this with /etc/no, so it's
1239 * being handled a different way for the servers right now. */
1241 static adjusted = 0;
1242 extern u_long sb_max_dflt;
1245 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1246 if (sb_max < 131072) sb_max = 131072;
1249 #endif /* AFS_AIX32_ENV */
1250 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1251 afs_uint32 mask = 0;
1252 #if !defined(AFS_SUN5_ENV)
1253 # ifdef AFS_USERSPACE_IP_ADDR
1255 i = rxi_Findcbi(parm2);
1257 mask = afs_cb_interface.subnetmask[i];
1261 # else /* AFS_USERSPACE_IP_ADDR */
1264 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1267 # endif /* else AFS_USERSPACE_IP_ADDR */
1268 #endif /* !AFS_SUN5_ENV */
1270 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1271 sizeof(afs_int32), code);
1273 else if (parm == AFSOP_AFSDB_HANDLER) {
1274 int sizeArg = (int)parm4;
1275 int kmsgLen = sizeArg & 0xffff;
1276 int cellLen = (sizeArg & 0xffff0000) >> 16;
1277 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1278 char *cellname = afs_osi_Alloc(cellLen);
1280 osi_Assert(kmsg != NULL);
1281 osi_Assert(cellname != NULL);
1283 afs_osi_MaskUserLoop();
1285 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1286 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1288 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1291 if (code == -2) { /* Shutting down? */
1297 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1298 afs_osi_Free(kmsg, kmsgLen);
1299 afs_osi_Free(cellname, cellLen);
1301 else if (parm == AFSOP_SET_DYNROOT) {
1302 code = afs_SetDynrootEnable(parm2);
1303 } else if (parm == AFSOP_SET_FAKESTAT) {
1304 afs_fakestat_enable = parm2;
1306 } else if (parm == AFSOP_SET_BACKUPTREE) {
1307 afs_bkvolpref = parm2;
1308 } else if (parm == AFSOP_SET_RXPCK) {
1309 rx_extraPackets = parm2;
1310 afscall_set_rxpck_received = 1;
1311 } else if (parm == AFSOP_SET_RXMAXMTU) {
1312 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1319 #ifdef AFS_LINUX20_ENV
1327 * Initstate in the range 0 < x < 100 are early initialization states.
1328 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1329 * the cache may be initialized.
1330 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1331 * is done after all the cache initialization has been done.
1332 * Initstate of 200 means that the volume has been looked up once, possibly
1334 * Initstate of 300 means that the volume has been *successfully* looked up.
1341 AFS_STATCNT(afs_CheckInit);
1342 if (afs_initState <= 100)
1343 code = ENXIO; /* never finished init phase */
1344 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1345 while (afs_initState < 200)
1346 afs_osi_Sleep(&afs_initState);
1347 } else if (afs_initState == 200)
1348 code = ETIMEDOUT; /* didn't find root volume */
1352 int afs_shuttingdown = 0;
1356 extern short afs_brsDaemons;
1357 extern afs_int32 afs_CheckServerDaemonStarted;
1358 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1359 extern struct osi_file *afs_cacheInodep;
1361 AFS_STATCNT(afs_shutdown);
1362 if (afs_initState == 0) {
1363 afs_warn("AFS not initialized - not shutting down\n");
1367 if (afs_shuttingdown)
1370 /* Give up all of our callbacks if we can. This must be done before setting
1371 * afs_shuttingdown, since it calls afs_InitReq, which will fail if
1372 * afs_shuttingdown is set. */
1375 afs_shuttingdown = 1;
1377 if (afs_cold_shutdown)
1378 afs_warn("afs: COLD ");
1380 afs_warn("afs: WARM ");
1381 afs_warn("shutting down of: vcaches... ");
1383 #if !defined(AFS_FBSD_ENV)
1384 /* The FBSD afs_unmount() calls vflush(), which reclaims all vnodes
1385 * on the mountpoint, flushing them in the process. In the presence
1386 * of bugs, flushing again here can cause panics. */
1387 afs_FlushAllVCaches();
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("BkG... ");
1413 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1414 while (afs_termState == AFSOP_STOP_BKG) {
1415 afs_osi_Wakeup(&afs_brsDaemons);
1416 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)
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 = 0;
1496 return; /* Just kill daemons for now */
1500 shutdown_afstest(void)
1502 AFS_STATCNT(shutdown_afstest);
1503 afs_initState = afs_termState = afs_setTime = 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;