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 #ifdef RXK_LISTENER_ENV
69 static int afs_RX_Running = 0;
71 static int afs_InitSetup_done = 0;
72 afs_int32 afs_numcachefiles = -1;
73 afs_int32 afs_numfilesperdir = -1;
74 char afs_cachebasedir[1024];
76 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
77 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
78 afs_int32 afs_rx_idledead = AFS_IDLEDEADTIME;
79 afs_int32 afs_rx_idledead_rep = AFS_IDLEDEADTIME_REP;
81 static int afscall_set_rxpck_received = 0;
83 #if defined(AFS_HPUX_ENV)
84 extern int afs_vfs_mount();
85 #endif /* defined(AFS_HPUX_ENV) */
87 /* This is code which needs to be called once when the first daemon enters
88 * the client. A non-zero return means an error and AFS should not start.
91 afs_InitSetup(int preallocs)
95 if (afs_InitSetup_done)
99 /* Initialize a RW lock for the ifinfo global array */
100 rw_init(&afsifinfo_lock, NULL, RW_DRIVER, NULL);
103 afs_taskq = ddi_taskq_create(NULL, "afs_taskq", 2, TASKQ_DEFAULTPRI, 0);
105 osi_StartNetIfPoller();
110 * Set up all the AFS statistics variables. This should be done
111 * exactly once, and it should be done here, the first resource-setting
112 * routine to be called by the CM/RX.
115 #endif /* AFS_NOSTATS */
117 memset(afs_zeros, 0, AFS_ZEROS);
119 rx_SetBusyChannelError(1); /* turn on busy call error reporting */
122 if(!afscall_set_rxpck_received)
123 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
124 code = rx_InitHost(rx_bindhost, htons(7001));
126 afs_warn("AFS: RX failed to initialize %d).\n", code);
129 rx_SetRxDeadTime(afs_rx_deadtime);
130 /* resource init creates the services */
131 afs_ResourceInit(preallocs);
133 afs_InitSetup_done = 1;
134 afs_osi_Wakeup(&afs_InitSetup_done);
139 #ifdef AFS_DAEMONOP_ENV
141 daemonOp_common(long parm, long parm2, long parm3, long parm4, long parm5,
145 if (parm == AFSOP_START_RXCALLBACK) {
148 # ifdef RXK_LISTENER_ENV
149 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
154 code = afs_InitSetup(parm2);
156 rx_enablePeerRPCStats();
159 rx_enableProcessRPCStats();
163 } else if (parm == AFSOP_START_AFS) {
166 } /* other functions don't need setup in the parent */
169 #endif /* AFS_DAEMONOP_ENV */
171 #if defined(AFS_DARWIN80_ENV)
172 struct afsd_thread_info {
176 afsd_thread(int *rock)
178 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
179 unsigned long parm = arg->parm;
182 case AFSOP_START_RXCALLBACK:
186 #ifndef RXK_LISTENER_ENV
187 afs_initState = AFSOP_START_AFS;
188 afs_osi_Wakeup(&afs_initState);
190 while (afs_RX_Running != 2)
191 afs_osi_Sleep(&afs_RX_Running);
193 afs_RXCallBackServer();
195 thread_terminate(current_thread());
197 case AFSOP_START_AFS:
201 while (afs_initState < AFSOP_START_AFS)
202 afs_osi_Sleep(&afs_initState);
203 afs_initState = AFSOP_START_BKG;
204 afs_osi_Wakeup(&afs_initState);
207 thread_terminate(current_thread());
209 case AFSOP_START_BKG:
210 afs_warn("Install matching afsd! Old background daemons not supported.\n");
211 thread_terminate(current_thread());
213 case AFSOP_START_TRUNCDAEMON:
216 while (afs_initState < AFSOP_GO)
217 afs_osi_Sleep(&afs_initState);
218 afs_CacheTruncateDaemon();
220 thread_terminate(current_thread());
225 afs_CheckServerDaemon();
227 thread_terminate(current_thread());
229 case AFSOP_RXEVENT_DAEMON:
232 while (afs_initState < AFSOP_START_BKG)
233 afs_osi_Sleep(&afs_initState);
234 afs_rxevent_daemon();
236 thread_terminate(current_thread());
238 #ifdef RXK_LISTENER_ENV
239 case AFSOP_RXLISTENER_DAEMON:
242 afs_initState = AFSOP_START_AFS;
243 afs_osi_Wakeup(&afs_initState);
245 afs_osi_Wakeup(&afs_RX_Running);
246 afs_osi_RxkRegister();
249 thread_terminate(current_thread());
253 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
259 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
262 struct afsd_thread_info info;
264 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
268 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
270 /* we need to wait cause we passed stack pointers around.... */
271 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
273 thread_deallocate(thread);
278 #if defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)
279 struct afsd_thread_info {
280 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
281 struct work_struct tq;
284 struct completion *complete;
288 afsd_thread(void *rock)
290 struct afsd_thread_info *arg = rock;
291 unsigned long parm = arg->parm;
292 # ifdef SYS_SETPRIORITY_EXPORTED
293 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
295 # if defined(AFS_LINUX26_ENV)
300 /* doesn't do much, since we were forked from keventd, but
301 * does call mm_release, which wakes up our parent (since it
302 * used CLONE_VFORK) */
303 # if !defined(AFS_LINUX26_ENV)
306 afs_osi_MaskSignals();
308 case AFSOP_START_RXCALLBACK:
309 sprintf(current->comm, "afs_cbstart");
311 complete(arg->complete);
313 #if !defined(RXK_LISTENER_ENV)
314 afs_initState = AFSOP_START_AFS;
315 afs_osi_Wakeup(&afs_initState);
317 while (afs_RX_Running != 2)
318 afs_osi_Sleep(&afs_RX_Running);
320 sprintf(current->comm, "afs_callback");
321 afs_RXCallBackServer();
323 complete_and_exit(0, 0);
325 case AFSOP_START_AFS:
326 sprintf(current->comm, "afs_afsstart");
328 complete(arg->complete);
330 while (afs_initState < AFSOP_START_AFS)
331 afs_osi_Sleep(&afs_initState);
332 afs_initState = AFSOP_START_BKG;
333 afs_osi_Wakeup(&afs_initState);
334 sprintf(current->comm, "afsd");
337 complete_and_exit(0, 0);
339 case AFSOP_START_BKG:
341 afs_warn("Install matching afsd! Old background daemons not supported.\n");
343 sprintf(current->comm, "afs_bkgstart");
345 complete(arg->complete);
346 while (afs_initState < AFSOP_START_BKG)
347 afs_osi_Sleep(&afs_initState);
348 if (afs_initState < AFSOP_GO) {
349 afs_initState = AFSOP_GO;
350 afs_osi_Wakeup(&afs_initState);
352 sprintf(current->comm, "afs_background");
353 afs_BackgroundDaemon();
356 complete_and_exit(0, 0);
358 case AFSOP_START_TRUNCDAEMON:
359 sprintf(current->comm, "afs_trimstart");
361 complete(arg->complete);
362 while (afs_initState < AFSOP_GO)
363 afs_osi_Sleep(&afs_initState);
364 sprintf(current->comm, "afs_cachetrim");
365 afs_CacheTruncateDaemon();
367 complete_and_exit(0, 0);
370 sprintf(current->comm, "afs_checkserver");
372 complete(arg->complete);
373 afs_CheckServerDaemon();
375 complete_and_exit(0, 0);
377 case AFSOP_RXEVENT_DAEMON:
378 sprintf(current->comm, "afs_evtstart");
379 # ifdef SYS_SETPRIORITY_EXPORTED
380 sys_setpriority(PRIO_PROCESS, 0, -10);
382 # ifdef CURRENT_INCLUDES_NICE
387 complete(arg->complete);
388 while (afs_initState < AFSOP_START_BKG)
389 afs_osi_Sleep(&afs_initState);
390 sprintf(current->comm, "afs_rxevent");
391 afs_rxevent_daemon();
393 complete_and_exit(0, 0);
395 #ifdef RXK_LISTENER_ENV
396 case AFSOP_RXLISTENER_DAEMON:
397 sprintf(current->comm, "afs_lsnstart");
398 # ifdef SYS_SETPRIORITY_EXPORTED
399 sys_setpriority(PRIO_PROCESS, 0, -10);
401 # ifdef CURRENT_INCLUDES_NICE
406 complete(arg->complete);
407 afs_initState = AFSOP_START_AFS;
408 afs_osi_Wakeup(&afs_initState);
410 afs_osi_Wakeup(&afs_RX_Running);
411 afs_osi_RxkRegister();
412 sprintf(current->comm, "afs_rxlistener");
415 complete_and_exit(0, 0);
419 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
426 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
427 afsd_launcher(struct work_struct *work)
429 afsd_launcher(void *rock)
432 # if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
433 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
436 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
437 afs_warn("kernel_thread failed. afs startup will not complete\n");
441 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
444 DECLARE_COMPLETION(c);
445 # if defined(AFS_LINUX26_ENV)
446 # if defined(INIT_WORK_HAS_DATA)
447 struct work_struct tq;
452 struct afsd_thread_info info;
453 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
458 # if defined(AFS_LINUX26_ENV)
459 # if !defined(INIT_WORK_HAS_DATA)
460 INIT_WORK(&info.tq, afsd_launcher);
461 schedule_work(&info.tq);
463 INIT_WORK(&tq, afsd_launcher, &info);
468 INIT_LIST_HEAD(&tq.list);
469 tq.routine = afsd_launcher;
474 /* we need to wait cause we passed stack pointers around.... */
475 wait_for_completion(&c);
481 struct afs_daemonop_args {
487 afsd_thread(struct afs_daemonop_args *args)
489 long parm = args->parm;
492 cv_signal(&args->cv);
495 case AFSOP_START_RXCALLBACK:
499 while (afs_RX_Running != 2)
500 afs_osi_Sleep(&afs_RX_Running);
501 afs_RXCallBackServer();
504 case AFSOP_START_AFS:
508 while (afs_initState < AFSOP_START_AFS)
509 afs_osi_Sleep(&afs_initState);
510 afs_initState = AFSOP_START_BKG;
511 afs_osi_Wakeup(&afs_initState);
515 case AFSOP_START_BKG:
516 while (afs_initState < AFSOP_START_BKG)
517 afs_osi_Sleep(&afs_initState);
518 if (afs_initState < AFSOP_GO) {
519 afs_initState = AFSOP_GO;
520 afs_osi_Wakeup(&afs_initState);
522 afs_BackgroundDaemon();
525 case AFSOP_START_TRUNCDAEMON:
526 while (afs_initState < AFSOP_GO)
527 afs_osi_Sleep(&afs_initState);
528 afs_CacheTruncateDaemon();
532 afs_CheckServerDaemon();
535 case AFSOP_RXEVENT_DAEMON:
536 while (afs_initState < AFSOP_START_BKG)
537 afs_osi_Sleep(&afs_initState);
538 afs_rxevent_daemon();
541 case AFSOP_RXLISTENER_DAEMON:
542 afs_initState = AFSOP_START_AFS;
543 afs_osi_Wakeup(&afs_initState);
545 afs_osi_Wakeup(&afs_RX_Running);
546 afs_osi_RxkRegister();
552 afs_warn("Unknown op %ld in afsd_thread()\n", parm);
561 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
564 struct afs_daemonop_args args;
566 if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
572 cv_init(&args.cv, "AFS DaemonOp cond var", CV_DEFAULT, NULL);
574 if (thread_create(NULL, 0, afsd_thread, &args, 0, &p0, TS_RUN,
575 minclsyspri) == NULL) {
577 afs_warn("thread_create failed: AFS startup will not complete\n");
580 /* we passed &args to the new thread, which is on the stack. wait until
581 * it has read the arguments so it doesn't try to read the args after we
583 cv_wait(&args.cv, &afs_global_lock);
585 cv_destroy(&args.cv);
587 #endif /* AFS_SUN5_ENV */
589 #ifdef AFS_DARWIN100_ENV
590 # define AFSKPTR(X) k ## X
592 afs_syscall_call(long parm, long parm2, long parm3,
593 long parm4, long parm5, long parm6)
595 return afs_syscall64_call(CAST_USER_ADDR_T((parm)),
596 CAST_USER_ADDR_T((parm2)),
597 CAST_USER_ADDR_T((parm3)),
598 CAST_USER_ADDR_T((parm4)),
599 CAST_USER_ADDR_T((parm5)),
600 CAST_USER_ADDR_T((parm6)));
603 # define AFSKPTR(X) ((caddr_t)X)
606 #ifdef AFS_DARWIN100_ENV
607 afs_syscall64_call(user_addr_t kparm, user_addr_t kparm2, user_addr_t kparm3,
608 user_addr_t kparm4, user_addr_t kparm5, user_addr_t kparm6)
610 afs_syscall_call(long parm, long parm2, long parm3,
611 long parm4, long parm5, long parm6)
615 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
617 #else /* AFS_SGI61_ENV */
619 #endif /* AFS_SGI61_ENV */
620 #ifdef AFS_DARWIN100_ENV
621 /* AFSKPTR macro relies on this name format/mapping */
622 afs_uint32 parm = (afs_uint32)kparm;
623 afs_uint32 parm2 = (afs_uint32)kparm2;
624 afs_uint32 parm3 = (afs_uint32)kparm3;
625 afs_uint32 parm4 = (afs_uint32)kparm4;
626 afs_uint32 parm5 = (afs_uint32)kparm5;
627 afs_uint32 parm6 = (afs_uint32)kparm6;
630 AFS_STATCNT(afs_syscall_call);
637 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
638 /* only root can run this code */
639 #if defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
640 # if defined(KERNEL_HAVE_UERROR)
648 #ifdef AFS_DARWIN80_ENV
654 #ifdef AFS_DARWIN80_ENV
657 #ifdef AFS_DAEMONOP_ENV
658 # if defined(AFS_NEW_BKG)
659 if (parm == AFSOP_BKG_HANDLER) {
660 /* if afs_uspc_param grows this should be checked */
661 struct afs_uspc_param *mvParam = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
666 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)mvParam,
667 sizeof(struct afs_uspc_param), code);
668 namebufsz = mvParam->bufSz;
669 param1 = afs_osi_Alloc(namebufsz);
670 osi_Assert(param1 != NULL);
671 param2 = afs_osi_Alloc(namebufsz);
672 osi_Assert(param2 != NULL);
674 while (afs_initState < AFSOP_START_BKG)
675 afs_osi_Sleep(&afs_initState);
676 if (afs_initState < AFSOP_GO) {
677 afs_initState = AFSOP_GO;
678 afs_osi_Wakeup(&afs_initState);
681 code = afs_BackgroundDaemon(mvParam, param1, param2);
685 /* for reqs where pointers are strings: */
686 if (mvParam->reqtype == AFS_USPC_UMV) {
687 /* don't copy out random kernel memory */
688 AFS_COPYOUT(param2, AFSKPTR(parm4),
689 MIN(namebufsz, strlen((char *)param2)+1), code);
690 AFS_COPYOUT(param1, AFSKPTR(parm3),
691 MIN(namebufsz, strlen((char *)param1)+1), code);
693 AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
694 sizeof(struct afs_uspc_param), code);
697 afs_osi_Free(param1, namebufsz);
698 afs_osi_Free(param2, namebufsz);
699 osi_FreeSmallSpace(mvParam);
701 # endif /* AFS_NEW_BKG */
702 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
703 || parm == AFSOP_RXLISTENER_DAEMON) {
704 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
706 #else /* !AFS_DAEMONOP_ENV */
707 if (parm == AFSOP_START_RXCALLBACK) {
711 # ifndef RXK_LISTENER_ENV
712 code = afs_InitSetup(parm2);
714 # endif /* !RXK_LISTENER_ENV */
716 # ifdef RXK_LISTENER_ENV
717 while (afs_RX_Running != 2)
718 afs_osi_Sleep(&afs_RX_Running);
719 # else /* !RXK_LISTENER_ENV */
721 rx_enablePeerRPCStats();
724 rx_enableProcessRPCStats();
726 afs_initState = AFSOP_START_AFS;
727 afs_osi_Wakeup(&afs_initState);
728 # endif /* RXK_LISTENER_ENV */
730 afs_RXCallBackServer();
735 exit(CLD_EXITED, code);
736 # endif /* AFS_SGI_ENV */
738 # ifdef RXK_LISTENER_ENV
739 else if (parm == AFSOP_RXLISTENER_DAEMON) {
743 code = afs_InitSetup(parm2);
745 rx_enablePeerRPCStats();
748 rx_enableProcessRPCStats();
751 afs_initState = AFSOP_START_AFS;
752 afs_osi_Wakeup(&afs_initState);
755 afs_osi_Wakeup(&afs_RX_Running);
757 afs_osi_RxkRegister();
758 # endif /* !UKERNEL */
764 exit(CLD_EXITED, code);
765 # endif /* AFS_SGI_ENV */
767 # endif /* RXK_LISTENER_ENV */
768 else if (parm == AFSOP_START_AFS) {
773 while (afs_initState < AFSOP_START_AFS)
774 afs_osi_Sleep(&afs_initState);
776 afs_initState = AFSOP_START_BKG;
777 afs_osi_Wakeup(&afs_initState);
784 # endif /* AFS_SGI_ENV */
785 } else if (parm == AFSOP_START_CS) {
787 afs_CheckServerDaemon();
792 # endif /* AFS_SGI_ENV */
794 } else if (parm == AFSOP_START_BKG) {
795 while (afs_initState < AFSOP_START_BKG)
796 afs_osi_Sleep(&afs_initState);
797 if (afs_initState < AFSOP_GO) {
798 afs_initState = AFSOP_GO;
799 afs_osi_Wakeup(&afs_initState);
801 /* start the bkg daemon */
803 # ifdef AFS_AIX32_ENV
805 afs_BioDaemon(parm2);
807 # endif /* AFS_AIX32_ENV */
808 afs_BackgroundDaemon();
813 # endif /* AFS_SGI_ENV */
814 # endif /* ! AFS_NEW_BKG */
815 } else if (parm == AFSOP_START_TRUNCDAEMON) {
816 while (afs_initState < AFSOP_GO)
817 afs_osi_Sleep(&afs_initState);
818 /* start the bkg daemon */
820 afs_CacheTruncateDaemon();
825 # endif /* AFS_SGI_ENV */
827 # if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
828 else if (parm == AFSOP_RXEVENT_DAEMON) {
829 while (afs_initState < AFSOP_START_BKG)
830 afs_osi_Sleep(&afs_initState);
832 afs_rxevent_daemon();
837 # endif /* AFS_SGI_ENV */
839 # endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV || RXK_UPCALL_ENV */
840 #endif /* AFS_DAEMONOP_ENV */
841 else if (parm == AFSOP_BASIC_INIT) {
844 while (!afs_InitSetup_done)
845 afs_osi_Sleep(&afs_InitSetup_done);
847 #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)
848 temp = AFS_MINBUFFERS; /* Should fix this soon */
850 /* number of 2k buffers we could get from all of the buffer space */
851 temp = ((afs_bufferpages * NBPG) >> 11);
852 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
853 if (temp < AFS_MINBUFFERS)
854 temp = AFS_MINBUFFERS; /* though we really should have this many */
857 afs_rootFid.Fid.Volume = 0;
859 } else if (parm == AFSOP_BUCKETPCT) {
860 /* need to enable this now, will disable again before GO
861 if we don't have 100% */
871 } else if (parm == AFSOP_ADDCELL) {
872 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
873 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
874 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
875 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
877 osi_Assert(tcell != NULL);
878 code = afs_InitDynroot();
880 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
884 if (parm4 > sizeof(tcell->cellName))
887 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)tcell->cellName, parm4, code);
889 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
893 afs_osi_Free(tcell, sizeof(struct afsop_cell));
894 } else if (parm == AFSOP_ADDCELL2) {
895 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
896 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
897 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
900 osi_Assert(tcell != NULL);
901 osi_Assert(tbuffer != NULL);
902 osi_Assert(tbuffer1 != NULL);
903 code = afs_InitDynroot();
906 /* wait for basic init - XXX can't find any reason we need this? */
907 while (afs_initState < AFSOP_START_BKG)
908 afs_osi_Sleep(&afs_initState);
911 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
915 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
919 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
923 cflags |= CLinkedCell;
931 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
935 afs_osi_Free(tcell, sizeof(struct afsop_cell));
936 osi_FreeSmallSpace(tbuffer);
937 osi_FreeSmallSpace(tbuffer1);
938 } else if (parm == AFSOP_ADDCELLALIAS) {
941 * parm2 is the alias name
942 * parm3 is the real cell name
944 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
945 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
947 code = afs_InitDynroot();
949 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
953 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
956 afs_NewCellAlias(aliasName, cellName);
957 osi_FreeSmallSpace(aliasName);
958 osi_FreeSmallSpace(cellName);
959 } else if (parm == AFSOP_SET_THISCELL) {
962 * parm2 is the primary cell name
964 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
967 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
969 afs_SetPrimaryCell(cell);
970 osi_FreeSmallSpace(cell);
972 code = afs_InitDynroot();
974 } else if (parm == AFSOP_CACHEINIT) {
975 struct afs_cacheParams cparms;
977 if (afs_CacheInit_Done)
980 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
982 #if defined(KERNEL_HAVE_UERROR)
988 afs_CacheInit_Done = 1;
989 code = afs_icl_InitLogs();
990 if (cparms.setTimeFlag) {
991 afs_warn("afs: AFSOP_CACHEINIT setTimeFlag ignored; are you "
992 "running an old afsd?\n");
996 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
997 cparms.cacheBlocks, cparms.cacheDcaches,
998 cparms.cacheVolumes, cparms.chunkSize,
999 cparms.memCacheFlag, cparms.inodes, cparms.users,
1000 cparms.dynamic_vcaches);
1002 } else if (parm == AFSOP_CACHEINODE) {
1003 ino_t ainode = parm2;
1004 /* wait for basic init */
1005 while (afs_initState < AFSOP_START_BKG)
1006 afs_osi_Sleep(&afs_initState);
1008 #ifdef AFS_DARWIN80_ENV
1011 /* do it by inode */
1012 #ifdef AFS_SGI62_ENV
1013 ainode = (ainode << 32) | (parm3 & 0xffffffff);
1015 code = afs_InitCacheFile(NULL, ainode);
1016 #ifdef AFS_DARWIN80_ENV
1019 } else if (parm == AFSOP_CACHEDIRS) {
1020 afs_numfilesperdir = parm2;
1021 afs_osi_Wakeup(&afs_initState);
1022 } else if (parm == AFSOP_CACHEFILES) {
1023 afs_numcachefiles = parm2;
1024 afs_osi_Wakeup(&afs_initState);
1025 } else if (parm == AFSOP_ROOTVOLUME) {
1026 /* wait for basic init */
1027 while (afs_initState < AFSOP_START_BKG)
1028 afs_osi_Sleep(&afs_initState);
1031 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
1032 sizeof(afs_rootVolumeName), &bufferSize, code);
1033 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
1036 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
1037 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
1038 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
1041 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
1044 osi_FreeSmallSpace(tbuffer);
1048 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
1049 /* We have the cache dir copied in. Call the cache init routine */
1050 #ifdef AFS_DARWIN80_ENV
1053 if (parm == AFSOP_CACHEFILE) {
1054 code = afs_InitCacheFile(tbuffer, 0);
1055 } else if (parm == AFSOP_CACHEINFO) {
1056 code = afs_InitCacheInfo(tbuffer);
1057 } else if (parm == AFSOP_VOLUMEINFO) {
1058 code = afs_InitVolumeInfo(tbuffer);
1059 } else if (parm == AFSOP_CELLINFO) {
1060 code = afs_InitCellInfo(tbuffer);
1062 #ifdef AFS_DARWIN80_ENV
1066 osi_FreeSmallSpace(tbuffer);
1067 } else if (parm == AFSOP_GO) {
1068 /* the generic initialization calls come here. One parameter: should we do the
1069 * set-time operation on this workstation */
1073 while (afs_initState < AFSOP_GO)
1074 afs_osi_Sleep(&afs_initState);
1075 afs_initState = 101;
1077 /* parm2 used to set afs_setTime */
1078 afs_warn("afs: AFSOP_GO setTime flag ignored; are you running an "
1081 if (afs_tpct1 + afs_tpct2 != 100) {
1088 afs_osi_Wakeup(&afs_initState);
1089 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
1090 afs_nfsclient_init();
1092 if (afs_uuid_create(&afs_cb_interface.uuid) != 0)
1093 memset(&afs_cb_interface.uuid, 0, sizeof(afsUUID));
1095 printf("found %d non-empty cache files (%d%%).\n",
1096 afs_stats_cmperf.cacheFilesReused,
1097 (100 * afs_stats_cmperf.cacheFilesReused) /
1098 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
1099 cacheNumEntries : 1));
1100 } else if (parm == AFSOP_ADVISEADDR) {
1101 /* pass in the host address to the rx package */
1105 afs_int32 count = parm2;
1107 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1108 afs_int32 *maskbuffer =
1109 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1110 afs_int32 *mtubuffer =
1111 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1114 osi_Assert(buffer != NULL);
1115 osi_Assert(maskbuffer != NULL);
1116 osi_Assert(mtubuffer != NULL);
1117 /* This is a refresh */
1118 if (count & 0x40000000) {
1119 count &= ~0x40000000;
1120 /* Can't bind after we start. Fix? */
1121 count &= ~0x80000000;
1125 /* Bind, but only if there's only one address configured */
1126 if ( count & 0x80000000) {
1127 count &= ~0x80000000;
1132 if (count > AFS_MAX_INTERFACE_ADDR) {
1134 count = AFS_MAX_INTERFACE_ADDR;
1137 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
1140 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
1141 count * sizeof(afs_int32), code);
1143 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
1144 count * sizeof(afs_int32), code);
1147 afs_cb_interface.numberOfInterfaces = count;
1148 for (i = 0; i < count; i++) {
1149 afs_cb_interface.addr_in[i] = buffer[i];
1150 #ifdef AFS_USERSPACE_IP_ADDR
1151 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
1152 * machines IP addresses when in the kernel (the in_ifaddr
1153 * struct is not available), so we pass the info in at
1154 * startup. We also pass in the subnetmask and mtu size. The
1155 * subnetmask is used when setting the rank:
1156 * afsi_SetServerIPRank(); and the mtu size is used when
1157 * finding the best mtu size. rxi_FindIfnet() is replaced
1158 * with rxi_Findcbi().
1160 afs_cb_interface.subnetmask[i] =
1161 (parm4 ? maskbuffer[i] : 0xffffffff);
1162 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1165 rxi_setaddr(buffer[0]);
1168 rx_bindhost = buffer[0];
1170 rx_bindhost = htonl(INADDR_ANY);
1176 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1177 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1178 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1181 afs_CheckServers(1, NULL); /* check down servers */
1182 afs_CheckServers(0, NULL); /* check up servers */
1185 else if (parm == AFSOP_SHUTDOWN) {
1186 afs_cold_shutdown = 0;
1188 afs_cold_shutdown = 1;
1189 if (afs_globalVFS != 0) {
1190 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1194 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1196 vfsmount(parm2, parm3, parm4, parm5);
1197 #else /* defined(AFS_HPUX_ENV) */
1198 # if defined(KERNEL_HAVE_UERROR)
1203 #endif /* defined(AFS_HPUX_ENV) */
1204 } else if (parm == AFSOP_CLOSEWAIT) {
1205 afs_SynchronousCloses = 'S';
1206 } else if (parm == AFSOP_GETMTU) {
1208 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1209 # ifdef AFS_USERSPACE_IP_ADDR
1211 i = rxi_Findcbi(parm2);
1212 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1213 # else /* AFS_USERSPACE_IP_ADDR */
1216 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1217 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1218 # endif /* else AFS_USERSPACE_IP_ADDR */
1219 #endif /* !AFS_SUN5_ENV */
1221 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1222 sizeof(afs_int32), code);
1223 #ifdef AFS_AIX32_ENV
1224 /* this is disabled for now because I can't figure out how to get access
1225 * to these kernel variables. It's only for supporting user-mode rx
1226 * programs -- it makes a huge difference on the 220's in my testbed,
1227 * though I don't know why. The bosserver does this with /etc/no, so it's
1228 * being handled a different way for the servers right now. */
1230 static adjusted = 0;
1231 extern u_long sb_max_dflt;
1234 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1235 if (sb_max < 131072) sb_max = 131072;
1238 #endif /* AFS_AIX32_ENV */
1239 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1240 afs_uint32 mask = 0;
1241 #if !defined(AFS_SUN5_ENV)
1242 # ifdef AFS_USERSPACE_IP_ADDR
1244 i = rxi_Findcbi(parm2);
1246 mask = afs_cb_interface.subnetmask[i];
1250 # else /* AFS_USERSPACE_IP_ADDR */
1253 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1256 # endif /* else AFS_USERSPACE_IP_ADDR */
1257 #endif /* !AFS_SUN5_ENV */
1259 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1260 sizeof(afs_int32), code);
1262 else if (parm == AFSOP_AFSDB_HANDLER) {
1263 int sizeArg = (int)parm4;
1264 int kmsgLen = sizeArg & 0xffff;
1265 int cellLen = (sizeArg & 0xffff0000) >> 16;
1266 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1267 char *cellname = afs_osi_Alloc(cellLen);
1269 osi_Assert(kmsg != NULL);
1270 osi_Assert(cellname != NULL);
1272 afs_osi_MaskUserLoop();
1274 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1275 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1277 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1280 if (code == -2) { /* Shutting down? */
1286 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1287 afs_osi_Free(kmsg, kmsgLen);
1288 afs_osi_Free(cellname, cellLen);
1290 else if (parm == AFSOP_SET_DYNROOT) {
1291 code = afs_SetDynrootEnable(parm2);
1292 } else if (parm == AFSOP_SET_FAKESTAT) {
1293 afs_fakestat_enable = parm2;
1295 } else if (parm == AFSOP_SET_BACKUPTREE) {
1296 afs_bkvolpref = parm2;
1297 } else if (parm == AFSOP_SET_RXPCK) {
1298 rx_extraPackets = parm2;
1299 afscall_set_rxpck_received = 1;
1300 } else if (parm == AFSOP_SET_RXMAXMTU) {
1301 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1302 } else if (parm == AFSOP_SET_RXMAXFRAGS) {
1303 rxi_nSendFrags = rxi_nRecvFrags = parm2;
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 int afs_shuttingdown = 0;
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)
1361 /* Give up all of our callbacks if we can. This must be done before setting
1362 * afs_shuttingdown, since it calls afs_InitReq, which will fail if
1363 * afs_shuttingdown is set. */
1366 afs_shuttingdown = 1;
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 = 0;
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;