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) */
27 #ifdef AFS_LINUX22_ENV
28 #include "h/smp_lock.h"
35 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV)
36 #define AFS_MINBUFFERS 100
38 #define AFS_MINBUFFERS 50
42 afs_int32 hosts[AFS_MAXCELLHOSTS];
46 char afs_zeros[AFS_ZEROS];
47 char afs_rootVolumeName[64] = "";
48 afs_uint32 rx_bindhost;
51 ddi_taskq_t *afs_taskq;
52 krwlock_t afsifinfo_lock;
55 afs_int32 afs_initState = 0;
56 afs_int32 afs_termState = 0;
57 afs_int32 afs_setTime = 0;
58 int afs_cold_shutdown = 0;
59 char afs_SynchronousCloses = '\0';
60 static int afs_CB_Running = 0;
61 static int AFS_Running = 0;
62 static int afs_CacheInit_Done = 0;
63 static int afs_Go_Done = 0;
64 extern struct interfaceAddr afs_cb_interface;
65 static int afs_RX_Running = 0;
66 static int afs_InitSetup_done = 0;
67 afs_int32 afs_numcachefiles = -1;
68 afs_int32 afs_numfilesperdir = -1;
69 char afs_cachebasedir[1024];
71 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
72 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
73 afs_int32 afs_rx_idledead = AFS_IDLEDEADTIME;
75 static int afscall_set_rxpck_received = 0;
77 #if defined(AFS_HPUX_ENV)
78 extern int afs_vfs_mount();
79 #endif /* defined(AFS_HPUX_ENV) */
81 /* This is code which needs to be called once when the first daemon enters
82 * the client. A non-zero return means an error and AFS should not start.
85 afs_InitSetup(int preallocs)
89 if (afs_InitSetup_done)
93 /* Initialize a RW lock for the ifinfo global array */
94 rw_init(&afsifinfo_lock, NULL, RW_DRIVER, NULL);
97 afs_taskq = ddi_taskq_create(NULL, "afs_taskq", 2, TASKQ_DEFAULTPRI, 0);
99 osi_StartNetIfPoller();
104 * Set up all the AFS statistics variables. This should be done
105 * exactly once, and it should be done here, the first resource-setting
106 * routine to be called by the CM/RX.
109 #endif /* AFS_NOSTATS */
111 memset(afs_zeros, 0, AFS_ZEROS);
114 if(!afscall_set_rxpck_received)
115 rx_extraPackets = AFS_NRXPACKETS; /* smaller # of packets */
116 code = rx_InitHost(rx_bindhost, htons(7001));
118 afs_warn("AFS: RX failed to initialize %d).\n", code);
121 rx_SetRxDeadTime(afs_rx_deadtime);
122 /* resource init creates the services */
123 afs_ResourceInit(preallocs);
125 afs_InitSetup_done = 1;
126 afs_osi_Wakeup(&afs_InitSetup_done);
130 #if defined(AFS_DARWIN80_ENV)
131 struct afsd_thread_info {
135 afsd_thread(int *rock)
137 struct afsd_thread_info *arg = (struct afsd_thread_info *)rock;
138 unsigned long parm = arg->parm;
141 case AFSOP_START_RXCALLBACK:
145 while (afs_RX_Running != 2)
146 afs_osi_Sleep(&afs_RX_Running);
147 afs_RXCallBackServer();
149 thread_terminate(current_thread());
151 case AFSOP_START_AFS:
155 while (afs_initState < AFSOP_START_AFS)
156 afs_osi_Sleep(&afs_initState);
157 afs_initState = AFSOP_START_BKG;
158 afs_osi_Wakeup(&afs_initState);
161 thread_terminate(current_thread());
163 case AFSOP_START_BKG:
164 afs_warn("Install matching afsd! Old background daemons not supported.\n");
165 thread_terminate(current_thread());
167 case AFSOP_START_TRUNCDAEMON:
170 while (afs_initState < AFSOP_GO)
171 afs_osi_Sleep(&afs_initState);
172 afs_CacheTruncateDaemon();
174 thread_terminate(current_thread());
179 afs_CheckServerDaemon();
181 thread_terminate(current_thread());
183 case AFSOP_RXEVENT_DAEMON:
186 while (afs_initState < AFSOP_START_BKG)
187 afs_osi_Sleep(&afs_initState);
188 afs_rxevent_daemon();
190 thread_terminate(current_thread());
192 case AFSOP_RXLISTENER_DAEMON:
195 afs_initState = AFSOP_START_AFS;
196 afs_osi_Wakeup(&afs_initState);
198 afs_osi_Wakeup(&afs_RX_Running);
199 afs_osi_RxkRegister();
202 thread_terminate(current_thread());
205 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
211 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
215 struct afsd_thread_info info;
217 if (parm == AFSOP_START_RXCALLBACK) {
220 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
224 code = afs_InitSetup(parm2);
226 rx_enablePeerRPCStats();
229 rx_enableProcessRPCStats();
233 } else if (parm == AFSOP_START_AFS) {
236 } /* other functions don't need setup in the parent */
238 kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
240 /* we need to wait cause we passed stack pointers around.... */
241 msleep(&info, NULL, PVFS, "afs_DaemonOp", NULL);
243 thread_deallocate(thread);
248 #if defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)
249 struct afsd_thread_info {
250 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
251 struct work_struct tq;
254 struct completion *complete;
258 afsd_thread(void *rock)
260 struct afsd_thread_info *arg = rock;
261 unsigned long parm = arg->parm;
262 #ifdef SYS_SETPRIORITY_EXPORTED
263 int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
265 #if defined(AFS_LINUX26_ENV)
270 /* doesn't do much, since we were forked from keventd, but
271 * does call mm_release, which wakes up our parent (since it
272 * used CLONE_VFORK) */
273 #if !defined(AFS_LINUX26_ENV)
276 afs_osi_MaskSignals();
278 case AFSOP_START_RXCALLBACK:
279 sprintf(current->comm, "afs_cbstart");
281 complete(arg->complete);
283 while (afs_RX_Running != 2)
284 afs_osi_Sleep(&afs_RX_Running);
285 sprintf(current->comm, "afs_callback");
286 afs_RXCallBackServer();
288 complete_and_exit(0, 0);
290 case AFSOP_START_AFS:
291 sprintf(current->comm, "afs_afsstart");
293 complete(arg->complete);
295 while (afs_initState < AFSOP_START_AFS)
296 afs_osi_Sleep(&afs_initState);
297 afs_initState = AFSOP_START_BKG;
298 afs_osi_Wakeup(&afs_initState);
299 sprintf(current->comm, "afsd");
302 complete_and_exit(0, 0);
304 case AFSOP_START_BKG:
305 sprintf(current->comm, "afs_bkgstart");
307 complete(arg->complete);
308 while (afs_initState < AFSOP_START_BKG)
309 afs_osi_Sleep(&afs_initState);
310 if (afs_initState < AFSOP_GO) {
311 afs_initState = AFSOP_GO;
312 afs_osi_Wakeup(&afs_initState);
314 sprintf(current->comm, "afs_background");
315 afs_BackgroundDaemon();
317 complete_and_exit(0, 0);
319 case AFSOP_START_TRUNCDAEMON:
320 sprintf(current->comm, "afs_trimstart");
322 complete(arg->complete);
323 while (afs_initState < AFSOP_GO)
324 afs_osi_Sleep(&afs_initState);
325 sprintf(current->comm, "afs_cachetrim");
326 afs_CacheTruncateDaemon();
328 complete_and_exit(0, 0);
331 sprintf(current->comm, "afs_checkserver");
333 complete(arg->complete);
334 afs_CheckServerDaemon();
336 complete_and_exit(0, 0);
338 case AFSOP_RXEVENT_DAEMON:
339 sprintf(current->comm, "afs_evtstart");
340 #ifdef SYS_SETPRIORITY_EXPORTED
341 sys_setpriority(PRIO_PROCESS, 0, -10);
343 #ifdef CURRENT_INCLUDES_NICE
348 complete(arg->complete);
349 while (afs_initState < AFSOP_START_BKG)
350 afs_osi_Sleep(&afs_initState);
351 sprintf(current->comm, "afs_rxevent");
352 afs_rxevent_daemon();
354 complete_and_exit(0, 0);
356 case AFSOP_RXLISTENER_DAEMON:
357 sprintf(current->comm, "afs_lsnstart");
358 #ifdef SYS_SETPRIORITY_EXPORTED
359 sys_setpriority(PRIO_PROCESS, 0, -10);
361 #ifdef CURRENT_INCLUDES_NICE
366 complete(arg->complete);
367 afs_initState = AFSOP_START_AFS;
368 afs_osi_Wakeup(&afs_initState);
370 afs_osi_Wakeup(&afs_RX_Running);
371 afs_osi_RxkRegister();
372 sprintf(current->comm, "afs_rxlistener");
375 complete_and_exit(0, 0);
378 afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
385 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
386 afsd_launcher(struct work_struct *work)
388 afsd_launcher(void *rock)
391 #if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
392 struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
395 if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
396 afs_warn("kernel_thread failed. afs startup will not complete\n");
400 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
404 DECLARE_COMPLETION(c);
405 #if defined(AFS_LINUX26_ENV)
406 #if defined(INIT_WORK_HAS_DATA)
407 struct work_struct tq;
412 struct afsd_thread_info info;
413 if (parm == AFSOP_START_RXCALLBACK) {
416 } else if (parm == AFSOP_RXLISTENER_DAEMON) {
420 code = afs_InitSetup(parm2);
422 rx_enablePeerRPCStats();
425 rx_enableProcessRPCStats();
429 } else if (parm == AFSOP_START_AFS) {
432 } /* other functions don't need setup in the parent */
435 #if defined(AFS_LINUX26_ENV)
436 #if !defined(INIT_WORK_HAS_DATA)
437 INIT_WORK(&info.tq, afsd_launcher);
438 schedule_work(&info.tq);
440 INIT_WORK(&tq, afsd_launcher, &info);
445 INIT_LIST_HEAD(&tq.list);
446 tq.routine = afsd_launcher;
451 /* we need to wait cause we passed stack pointers around.... */
452 wait_for_completion(&c);
457 #ifdef AFS_DARWIN100_ENV
458 #define AFSKPTR(X) k ## X
460 afs_syscall_call(long parm, long parm2, long parm3,
461 long parm4, long parm5, long parm6)
463 return afs_syscall64_call(CAST_USER_ADDR_T((parm)),
464 CAST_USER_ADDR_T((parm2)),
465 CAST_USER_ADDR_T((parm3)),
466 CAST_USER_ADDR_T((parm4)),
467 CAST_USER_ADDR_T((parm5)),
468 CAST_USER_ADDR_T((parm6)));
471 #define AFSKPTR(X) ((caddr_t)X)
474 #ifdef AFS_DARWIN100_ENV
475 afs_syscall64_call(user_addr_t kparm, user_addr_t kparm2, user_addr_t kparm3,
476 user_addr_t kparm4, user_addr_t kparm5, user_addr_t kparm6)
478 afs_syscall_call(long parm, long parm2, long parm3,
479 long parm4, long parm5, long parm6)
483 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
485 #else /* AFS_SGI61_ENV */
487 #endif /* AFS_SGI61_ENV */
488 #ifdef AFS_DARWIN100_ENV
489 /* AFSKPTR macro relies on this name format/mapping */
490 afs_uint32 parm = (afs_uint32)kparm;
491 afs_uint32 parm2 = (afs_uint32)kparm2;
492 afs_uint32 parm3 = (afs_uint32)kparm3;
493 afs_uint32 parm4 = (afs_uint32)kparm4;
494 afs_uint32 parm5 = (afs_uint32)kparm5;
495 afs_uint32 parm6 = (afs_uint32)kparm6;
498 AFS_STATCNT(afs_syscall_call);
505 && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
506 /* only root can run this code */
507 #if defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
508 #if defined(KERNEL_HAVE_UERROR)
516 #ifdef AFS_DARWIN80_ENV
522 #ifdef AFS_DARWIN80_ENV
525 #if ((defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)) || defined(AFS_DARWIN80_ENV)) && !defined(UKERNEL)
526 #if defined(AFS_DARWIN80_ENV)
527 if (parm == AFSOP_BKG_HANDLER) {
528 /* if afs_uspc_param grows this should be checked */
529 struct afs_uspc_param *mvParam = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
534 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)mvParam,
535 sizeof(struct afs_uspc_param), code);
536 namebufsz = mvParam->bufSz;
537 param1 = afs_osi_Alloc(namebufsz);
538 param2 = afs_osi_Alloc(namebufsz);
540 while (afs_initState < AFSOP_START_BKG)
541 afs_osi_Sleep(&afs_initState);
542 if (afs_initState < AFSOP_GO) {
543 afs_initState = AFSOP_GO;
544 afs_osi_Wakeup(&afs_initState);
547 code = afs_BackgroundDaemon(mvParam, param1, param2);
551 /* for reqs where pointers are strings: */
552 if (mvParam->reqtype == AFS_USPC_UMV) {
553 /* don't copy out random kernel memory */
554 AFS_COPYOUT(param2, AFSKPTR(parm4),
555 MIN(namebufsz, strlen((char *)param2)+1), code);
556 AFS_COPYOUT(param1, AFSKPTR(parm3),
557 MIN(namebufsz, strlen((char *)param1)+1), code);
559 AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
560 sizeof(struct afs_uspc_param), code);
563 afs_osi_Free(param1, namebufsz);
564 afs_osi_Free(param2, namebufsz);
565 osi_FreeSmallSpace(mvParam);
567 #endif /* DARWIN80 */
568 if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
569 || parm == AFSOP_RXLISTENER_DAEMON) {
570 afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
572 #else /* !(AFS_LINUX24_ENV && !UKERNEL) */
573 if (parm == AFSOP_START_RXCALLBACK) {
577 #ifndef RXK_LISTENER_ENV
578 code = afs_InitSetup(parm2);
580 #endif /* !RXK_LISTENER_ENV */
582 #ifdef RXK_LISTENER_ENV
583 while (afs_RX_Running != 2)
584 afs_osi_Sleep(&afs_RX_Running);
585 #else /* !RXK_LISTENER_ENV */
586 afs_initState = AFSOP_START_AFS;
587 afs_osi_Wakeup(&afs_initState);
588 #endif /* RXK_LISTENER_ENV */
590 afs_RXCallBackServer();
595 exit(CLD_EXITED, code);
596 #endif /* AFS_SGI_ENV */
598 #ifdef RXK_LISTENER_ENV
599 else if (parm == AFSOP_RXLISTENER_DAEMON) {
603 code = afs_InitSetup(parm2);
605 rx_enablePeerRPCStats();
608 rx_enableProcessRPCStats();
611 afs_initState = AFSOP_START_AFS;
612 afs_osi_Wakeup(&afs_initState);
615 afs_osi_Wakeup(&afs_RX_Running);
617 afs_osi_RxkRegister();
618 #endif /* !UKERNEL */
624 exit(CLD_EXITED, code);
625 #endif /* AFS_SGI_ENV */
627 #endif /* RXK_LISTENER_ENV */
628 else if (parm == AFSOP_START_AFS) {
633 while (afs_initState < AFSOP_START_AFS)
634 afs_osi_Sleep(&afs_initState);
636 afs_initState = AFSOP_START_BKG;
637 afs_osi_Wakeup(&afs_initState);
644 #endif /* AFS_SGI_ENV */
645 } else if (parm == AFSOP_START_CS) {
647 afs_CheckServerDaemon();
652 #endif /* AFS_SGI_ENV */
653 #ifndef AFS_DARWIN80_ENV
654 } else if (parm == AFSOP_START_BKG) {
655 while (afs_initState < AFSOP_START_BKG)
656 afs_osi_Sleep(&afs_initState);
657 if (afs_initState < AFSOP_GO) {
658 afs_initState = AFSOP_GO;
659 afs_osi_Wakeup(&afs_initState);
661 /* start the bkg daemon */
663 # ifdef AFS_AIX32_ENV
665 afs_BioDaemon(parm2);
667 # endif /* AFS_AIX32_ENV */
668 afs_BackgroundDaemon();
673 # endif /* AFS_SGI_ENV */
674 #endif /* ! AFS_DARWIN80_ENV */
675 } else if (parm == AFSOP_START_TRUNCDAEMON) {
676 while (afs_initState < AFSOP_GO)
677 afs_osi_Sleep(&afs_initState);
678 /* start the bkg daemon */
680 afs_CacheTruncateDaemon();
685 #endif /* AFS_SGI_ENV */
687 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
688 else if (parm == AFSOP_RXEVENT_DAEMON) {
689 while (afs_initState < AFSOP_START_BKG)
690 afs_osi_Sleep(&afs_initState);
692 afs_rxevent_daemon();
697 #endif /* AFS_SGI_ENV */
699 #endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
700 #endif /* AFS_LINUX24_ENV && !UKERNEL */
701 else if (parm == AFSOP_BASIC_INIT) {
704 while (!afs_InitSetup_done)
705 afs_osi_Sleep(&afs_InitSetup_done);
707 #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)
708 temp = AFS_MINBUFFERS; /* Should fix this soon */
710 /* number of 2k buffers we could get from all of the buffer space */
711 temp = ((afs_bufferpages * NBPG) >> 11);
712 temp = temp >> 2; /* don't take more than 25% (our magic parameter) */
713 if (temp < AFS_MINBUFFERS)
714 temp = AFS_MINBUFFERS; /* though we really should have this many */
717 afs_rootFid.Fid.Volume = 0;
719 } else if (parm == AFSOP_BUCKETPCT) {
720 /* need to enable this now, will disable again before GO
721 if we don't have 100% */
731 } else if (parm == AFSOP_ADDCELL) {
732 /* add a cell. Parameter 2 is 8 hosts (in net order), parm 3 is the null-terminated
733 * name. Parameter 4 is the length of the name, including the null. Parm 5 is the
734 * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
735 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
737 code = afs_InitDynroot();
739 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
743 if (parm4 > sizeof(tcell->cellName))
746 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)tcell->cellName, parm4, code);
748 afs_NewCell(tcell->cellName, tcell->hosts, parm5, NULL, 0,
752 afs_osi_Free(tcell, sizeof(struct afsop_cell));
753 } else if (parm == AFSOP_ADDCELL2) {
754 struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
755 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ), *lcnamep = 0;
756 char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
759 code = afs_InitDynroot();
762 /* wait for basic init - XXX can't find any reason we need this? */
763 while (afs_initState < AFSOP_START_BKG)
764 afs_osi_Sleep(&afs_initState);
767 AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
771 AFS_COPYINSTR(AFSKPTR(parm3), tbuffer1, AFS_SMALLOCSIZ,
775 AFS_COPYINSTR(AFSKPTR(parm5), tbuffer, AFS_SMALLOCSIZ,
779 cflags |= CLinkedCell;
787 afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
791 afs_osi_Free(tcell, sizeof(struct afsop_cell));
792 osi_FreeSmallSpace(tbuffer);
793 osi_FreeSmallSpace(tbuffer1);
794 } else if (parm == AFSOP_ADDCELLALIAS) {
797 * parm2 is the alias name
798 * parm3 is the real cell name
800 char *aliasName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
801 char *cellName = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
803 code = afs_InitDynroot();
805 AFS_COPYINSTR(AFSKPTR(parm2), aliasName, AFS_SMALLOCSIZ, &bufferSize,
809 AFS_COPYINSTR(AFSKPTR(parm3), cellName, AFS_SMALLOCSIZ,
812 afs_NewCellAlias(aliasName, cellName);
813 osi_FreeSmallSpace(aliasName);
814 osi_FreeSmallSpace(cellName);
815 } else if (parm == AFSOP_SET_THISCELL) {
818 * parm2 is the primary cell name
820 char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
823 AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
825 afs_SetPrimaryCell(cell);
826 osi_FreeSmallSpace(cell);
828 code = afs_InitDynroot();
830 } else if (parm == AFSOP_CACHEINIT) {
831 struct afs_cacheParams cparms;
833 if (afs_CacheInit_Done)
836 AFS_COPYIN(AFSKPTR(parm2), (caddr_t) & cparms, sizeof(cparms), code);
838 #if defined(KERNEL_HAVE_UERROR)
844 afs_CacheInit_Done = 1;
845 code = afs_icl_InitLogs();
846 afs_setTime = cparms.setTimeFlag;
849 afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
850 cparms.cacheBlocks, cparms.cacheDcaches,
851 cparms.cacheVolumes, cparms.chunkSize,
852 cparms.memCacheFlag, cparms.inodes, cparms.users,
853 cparms.dynamic_vcaches);
855 } else if (parm == AFSOP_CACHEINODE) {
856 ino_t ainode = parm2;
857 /* wait for basic init */
858 while (afs_initState < AFSOP_START_BKG)
859 afs_osi_Sleep(&afs_initState);
861 #ifdef AFS_DARWIN80_ENV
866 ainode = (ainode << 32) | (parm3 & 0xffffffff);
868 code = afs_InitCacheFile(NULL, ainode);
869 #ifdef AFS_DARWIN80_ENV
872 } else if (parm == AFSOP_CACHEDIRS) {
873 afs_numfilesperdir = parm2;
874 afs_osi_Wakeup(&afs_initState);
875 } else if (parm == AFSOP_CACHEFILES) {
876 afs_numcachefiles = parm2;
877 afs_osi_Wakeup(&afs_initState);
878 } else if (parm == AFSOP_ROOTVOLUME) {
879 /* wait for basic init */
880 while (afs_initState < AFSOP_START_BKG)
881 afs_osi_Sleep(&afs_initState);
884 AFS_COPYINSTR(AFSKPTR(parm2), afs_rootVolumeName,
885 sizeof(afs_rootVolumeName), &bufferSize, code);
886 afs_rootVolumeName[sizeof(afs_rootVolumeName) - 1] = 0;
889 } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
890 || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
891 char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
894 AFS_COPYINSTR(AFSKPTR(parm2), tbuffer, AFS_SMALLOCSIZ, &bufferSize,
897 osi_FreeSmallSpace(tbuffer);
901 tbuffer[AFS_SMALLOCSIZ - 1] = '\0'; /* null-terminate the name */
902 /* We have the cache dir copied in. Call the cache init routine */
903 #ifdef AFS_DARWIN80_ENV
906 if (parm == AFSOP_CACHEFILE) {
907 code = afs_InitCacheFile(tbuffer, 0);
908 } else if (parm == AFSOP_CACHEINFO) {
909 code = afs_InitCacheInfo(tbuffer);
910 } else if (parm == AFSOP_VOLUMEINFO) {
911 code = afs_InitVolumeInfo(tbuffer);
912 } else if (parm == AFSOP_CELLINFO) {
913 code = afs_InitCellInfo(tbuffer);
915 #ifdef AFS_DARWIN80_ENV
919 osi_FreeSmallSpace(tbuffer);
920 } else if (parm == AFSOP_GO) {
921 /* the generic initialization calls come here. One parameter: should we do the
922 * set-time operation on this workstation */
926 while (afs_initState < AFSOP_GO)
927 afs_osi_Sleep(&afs_initState);
930 if (afs_tpct1 + afs_tpct2 != 100) {
937 afs_osi_Wakeup(&afs_initState);
938 #if (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
939 afs_nfsclient_init();
941 afs_uuid_create(&afs_cb_interface.uuid);
942 printf("found %d non-empty cache files (%d%%).\n",
943 afs_stats_cmperf.cacheFilesReused,
944 (100 * afs_stats_cmperf.cacheFilesReused) /
945 (afs_stats_cmperf.cacheNumEntries ? afs_stats_cmperf.
946 cacheNumEntries : 1));
947 } else if (parm == AFSOP_ADVISEADDR) {
948 /* pass in the host address to the rx package */
952 afs_int32 count = parm2;
954 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
955 afs_int32 *maskbuffer =
956 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
957 afs_int32 *mtubuffer =
958 afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
961 /* This is a refresh */
962 if (count & 0x40000000) {
963 count &= ~0x40000000;
964 /* Can't bind after we start. Fix? */
965 count &= ~0x80000000;
969 /* Bind, but only if there's only one address configured */
970 if ( count & 0x80000000) {
971 count &= ~0x80000000;
976 if (count > AFS_MAX_INTERFACE_ADDR) {
978 count = AFS_MAX_INTERFACE_ADDR;
981 AFS_COPYIN(AFSKPTR(parm3), (caddr_t)buffer, count * sizeof(afs_int32),
984 AFS_COPYIN(AFSKPTR(parm4), (caddr_t)maskbuffer,
985 count * sizeof(afs_int32), code);
987 AFS_COPYIN(AFSKPTR(parm5), (caddr_t)mtubuffer,
988 count * sizeof(afs_int32), code);
991 afs_cb_interface.numberOfInterfaces = count;
992 for (i = 0; i < count; i++) {
993 afs_cb_interface.addr_in[i] = buffer[i];
994 #ifdef AFS_USERSPACE_IP_ADDR
995 /* AFS_USERSPACE_IP_ADDR means we have no way of finding the
996 * machines IP addresses when in the kernel (the in_ifaddr
997 * struct is not available), so we pass the info in at
998 * startup. We also pass in the subnetmask and mtu size. The
999 * subnetmask is used when setting the rank:
1000 * afsi_SetServerIPRank(); and the mtu size is used when
1001 * finding the best mtu size. rxi_FindIfnet() is replaced
1002 * with rxi_Findcbi().
1004 afs_cb_interface.subnetmask[i] =
1005 (parm4 ? maskbuffer[i] : 0xffffffff);
1006 afs_cb_interface.mtu[i] = (parm5 ? mtubuffer[i] : htonl(1500));
1009 rxi_setaddr(buffer[0]);
1012 rx_bindhost = buffer[0];
1014 rx_bindhost = htonl(INADDR_ANY);
1020 afs_osi_Free(buffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1021 afs_osi_Free(maskbuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1022 afs_osi_Free(mtubuffer, sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
1025 afs_CheckServers(1, NULL); /* check down servers */
1026 afs_CheckServers(0, NULL); /* check down servers */
1029 #ifdef AFS_SGI53_ENV
1030 else if (parm == AFSOP_NFSSTATICADDR) {
1031 extern int (*nfs_rfsdisptab_v2) ();
1032 nfs_rfsdisptab_v2 = (int (*)())parm2;
1033 } else if (parm == AFSOP_NFSSTATICADDR2) {
1034 extern int (*nfs_rfsdisptab_v2) ();
1036 nfs_rfsdisptab_v2 = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
1038 nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
1039 #endif /* _K64U64 */
1041 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
1042 else if (parm == AFSOP_SBLOCKSTATICADDR2) {
1043 extern int (*afs_sblockp) ();
1044 extern void (*afs_sbunlockp) ();
1046 afs_sblockp = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
1047 afs_sbunlockp = (void (*)())((parm4 << 32) | (parm5 & 0xffffffff));
1049 afs_sblockp = (int (*)())(parm3 & 0xffffffff);
1050 afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
1051 #endif /* _K64U64 */
1053 #endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
1054 #endif /* AFS_SGI53_ENV */
1055 else if (parm == AFSOP_SHUTDOWN) {
1056 afs_cold_shutdown = 0;
1058 afs_cold_shutdown = 1;
1059 if (afs_globalVFS != 0) {
1060 afs_warn("AFS isn't unmounted yet! Call aborted\n");
1064 } else if (parm == AFSOP_AFS_VFSMOUNT) {
1066 vfsmount(parm2, parm3, parm4, parm5);
1067 #else /* defined(AFS_HPUX_ENV) */
1068 #if defined(KERNEL_HAVE_UERROR)
1073 #endif /* defined(AFS_HPUX_ENV) */
1074 } else if (parm == AFSOP_CLOSEWAIT) {
1075 afs_SynchronousCloses = 'S';
1076 } else if (parm == AFSOP_GETMTU) {
1078 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
1079 #ifdef AFS_USERSPACE_IP_ADDR
1081 i = rxi_Findcbi(parm2);
1082 mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
1083 #else /* AFS_USERSPACE_IP_ADDR */
1086 tifnp = rxi_FindIfnet(parm2, NULL); /* make iterative */
1087 mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
1088 #endif /* else AFS_USERSPACE_IP_ADDR */
1089 #endif /* !AFS_SUN5_ENV */
1091 AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
1092 sizeof(afs_int32), code);
1093 #ifdef AFS_AIX32_ENV
1094 /* this is disabled for now because I can't figure out how to get access
1095 * to these kernel variables. It's only for supporting user-mode rx
1096 * programs -- it makes a huge difference on the 220's in my testbed,
1097 * though I don't know why. The bosserver does this with /etc/no, so it's
1098 * being handled a different way for the servers right now. */
1100 static adjusted = 0;
1101 extern u_long sb_max_dflt;
1104 if (sb_max_dflt < 131072) sb_max_dflt = 131072;
1105 if (sb_max < 131072) sb_max = 131072;
1108 #endif /* AFS_AIX32_ENV */
1109 } else if (parm == AFSOP_GETMASK) { /* parm2 == addr in net order */
1110 afs_uint32 mask = 0;
1111 #if !defined(AFS_SUN5_ENV)
1112 #ifdef AFS_USERSPACE_IP_ADDR
1114 i = rxi_Findcbi(parm2);
1116 mask = afs_cb_interface.subnetmask[i];
1120 #else /* AFS_USERSPACE_IP_ADDR */
1123 tifnp = rxi_FindIfnet(parm2, &mask); /* make iterative */
1126 #endif /* else AFS_USERSPACE_IP_ADDR */
1127 #endif /* !AFS_SUN5_ENV */
1129 AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
1130 sizeof(afs_int32), code);
1132 else if (parm == AFSOP_AFSDB_HANDLER) {
1133 int sizeArg = (int)parm4;
1134 int kmsgLen = sizeArg & 0xffff;
1135 int cellLen = (sizeArg & 0xffff0000) >> 16;
1136 afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
1137 char *cellname = afs_osi_Alloc(cellLen);
1140 afs_osi_MaskUserLoop();
1142 AFS_COPYIN(AFSKPTR(parm2), cellname, cellLen, code);
1143 AFS_COPYIN(AFSKPTR(parm3), kmsg, kmsgLen, code);
1145 code = afs_AFSDBHandler(cellname, cellLen, kmsg);
1148 if (code == -2) { /* Shutting down? */
1154 AFS_COPYOUT(cellname, AFSKPTR(parm2), cellLen, code);
1155 afs_osi_Free(kmsg, kmsgLen);
1156 afs_osi_Free(cellname, cellLen);
1158 else if (parm == AFSOP_SET_DYNROOT) {
1159 code = afs_SetDynrootEnable(parm2);
1160 } else if (parm == AFSOP_SET_FAKESTAT) {
1161 afs_fakestat_enable = parm2;
1163 } else if (parm == AFSOP_SET_BACKUPTREE) {
1164 afs_bkvolpref = parm2;
1165 } else if (parm == AFSOP_SET_RXPCK) {
1166 rx_extraPackets = parm2;
1167 afscall_set_rxpck_received = 1;
1168 } else if (parm == AFSOP_SET_RXMAXMTU) {
1169 rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
1176 #ifdef AFS_LINUX20_ENV
1184 * Initstate in the range 0 < x < 100 are early initialization states.
1185 * Initstate of 100 means a AFSOP_START operation has been done. After this,
1186 * the cache may be initialized.
1187 * Initstate of 101 means a AFSOP_GO operation has been done. This operation
1188 * is done after all the cache initialization has been done.
1189 * Initstate of 200 means that the volume has been looked up once, possibly
1191 * Initstate of 300 means that the volume has been *successfully* looked up.
1198 AFS_STATCNT(afs_CheckInit);
1199 if (afs_initState <= 100)
1200 code = ENXIO; /* never finished init phase */
1201 else if (afs_initState == 101) { /* init done, wait for afs_daemon */
1202 while (afs_initState < 200)
1203 afs_osi_Sleep(&afs_initState);
1204 } else if (afs_initState == 200)
1205 code = ETIMEDOUT; /* didn't find root volume */
1209 int afs_shuttingdown = 0;
1213 extern short afs_brsDaemons;
1214 extern afs_int32 afs_CheckServerDaemonStarted;
1215 extern struct afs_osi_WaitHandle AFS_WaitHandler, AFS_CSWaitHandler;
1216 extern struct osi_file *afs_cacheInodep;
1218 AFS_STATCNT(afs_shutdown);
1219 if (afs_initState == 0) {
1220 afs_warn("AFS not initialized - not shutting down\n");
1224 if (afs_shuttingdown)
1226 afs_FlushVCBs(2); /* Reasonable effort to free dynamically allocated callback returns */
1228 afs_shuttingdown = 1;
1229 if (afs_cold_shutdown)
1230 afs_warn("afs: COLD ");
1232 afs_warn("afs: WARM ");
1233 afs_warn("shutting down of: CB... ");
1235 afs_termState = AFSOP_STOP_RXCALLBACK;
1236 rx_WakeupServerProcs();
1237 #ifdef AFS_AIX51_ENV
1238 shutdown_rxkernel();
1240 /* close rx server connections here? */
1241 while (afs_termState == AFSOP_STOP_RXCALLBACK)
1242 afs_osi_Sleep(&afs_termState);
1244 afs_warn("afs... ");
1245 while (afs_termState == AFSOP_STOP_AFS) {
1246 afs_osi_CancelWait(&AFS_WaitHandler);
1247 afs_osi_Sleep(&afs_termState);
1249 if (afs_CheckServerDaemonStarted) {
1250 while (afs_termState == AFSOP_STOP_CS) {
1251 afs_osi_CancelWait(&AFS_CSWaitHandler);
1252 afs_osi_Sleep(&afs_termState);
1255 afs_warn("BkG... ");
1256 /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
1257 while (afs_termState == AFSOP_STOP_BKG) {
1258 afs_osi_Wakeup(&afs_brsDaemons);
1259 afs_osi_Sleep(&afs_termState);
1261 afs_warn("CTrunc... ");
1262 /* Cancel cache truncate daemon. */
1263 while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
1264 afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
1265 afs_osi_Sleep(&afs_termState);
1267 afs_warn("AFSDB... ");
1269 while (afs_termState == AFSOP_STOP_AFSDB)
1270 afs_osi_Sleep(&afs_termState);
1271 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1272 afs_warn("RxEvent... ");
1273 /* cancel rx event daemon */
1274 while (afs_termState == AFSOP_STOP_RXEVENT)
1275 afs_osi_Sleep(&afs_termState);
1276 #if defined(RXK_LISTENER_ENV)
1278 afs_warn("UnmaskRxkSignals... ");
1279 afs_osi_UnmaskRxkSignals();
1281 /* cancel rx listener */
1282 afs_warn("RxListener... ");
1283 osi_StopListener(); /* This closes rx_socket. */
1284 while (afs_termState == AFSOP_STOP_RXK_LISTENER) {
1285 afs_warn("Sleep... ");
1286 afs_osi_Sleep(&afs_termState);
1291 #ifdef AFS_SUN510_ENV
1292 afs_warn("NetIfPoller... ");
1293 osi_StopNetIfPoller();
1296 afs_termState = AFSOP_STOP_COMPLETE;
1298 #ifdef AFS_AIX51_ENV
1302 shutdown_bufferpackage();
1306 * Close file only after daemons which can write to it are stopped.
1307 * Need to close before the osinet shutdown to avoid failing check
1308 * for dangling memory allocations.
1310 if (afs_cacheInodep) { /* memcache won't set this */
1311 osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */
1312 afs_cacheInodep = 0;
1315 * Shutdown the ICL logs - needed to free allocated memory space and avoid
1316 * warnings from shutdown_osinet
1321 shutdown_vnodeops();
1322 shutdown_memcache();
1324 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV))
1325 shutdown_exporter();
1330 /* The following hold the cm stats */
1331 memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
1332 memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
1333 memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
1334 afs_warn(" ALL allocated tables... ");
1336 afs_shuttingdown = 0;
1339 return; /* Just kill daemons for now */
1343 shutdown_afstest(void)
1345 AFS_STATCNT(shutdown_afstest);
1346 afs_initState = afs_termState = afs_setTime = 0;
1347 AFS_Running = afs_CB_Running = 0;
1348 afs_CacheInit_Done = afs_Go_Done = 0;
1349 if (afs_cold_shutdown) {
1350 *afs_rootVolumeName = 0;