client: flag in cachemanager if rmtsys is enabled
[openafs.git] / src / afs / afs_call.c
index d438b21..cdafe0f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include "afs/param.h"
 
+#if defined(HAVE_LINUX_KTHREAD_RUN) && !defined(UKERNEL)
+#  include "h/kthread.h"
+#endif
 
 #include "afs/sysincludes.h"   /* Standard vendor system headers */
 #include "afsincludes.h"       /* Afs-based standard headers */
 #include "afs/afs_stats.h"
 #include "rx/rx_globals.h"
-#if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
-#include "net/if.h"
-#ifdef AFS_SGI62_ENV
-#include "h/hashing.h"
-#endif
-#if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN60_ENV)
-#include "netinet/in_var.h"
-#endif
+#if !defined(UKERNEL)
+# if !defined(AFS_LINUX20_ENV)
+#  include "net/if.h"
+#  ifdef AFS_SGI62_ENV
+#   include "h/hashing.h"
+#  endif
+#  if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN_ENV)
+#   include "netinet/in_var.h"
+#  endif
+# endif
 #endif /* !defined(UKERNEL) */
-#ifdef AFS_LINUX22_ENV
-#include "h/smp_lock.h"
-#endif
 #ifdef AFS_SUN510_ENV
 #include "h/ksynch.h"
 #include "h/sunddi.h"
 #define        AFS_MINBUFFERS  50
 #endif
 
+#if (defined(AFS_SUN5_ENV) || (defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)) || defined(AFS_DARWIN80_ENV)) && !defined(UKERNEL)
+/* If AFS_DAEMONOP_ENV is defined, it indicates we run "daemon" AFS syscalls by
+ * spawning a kernel thread to do the work, instead of running them in the
+ * calling process. */
+# define AFS_DAEMONOP_ENV
+#endif
+
 struct afsop_cell {
-    afs_int32 hosts[MAXCELLHOSTS];
+    afs_int32 hosts[AFS_MAXCELLHOSTS];
     char cellName[100];
 };
 
@@ -54,7 +63,6 @@ krwlock_t afsifinfo_lock;
 
 afs_int32 afs_initState = 0;
 afs_int32 afs_termState = 0;
-afs_int32 afs_setTime = 0;
 int afs_cold_shutdown = 0;
 char afs_SynchronousCloses = '\0';
 static int afs_CB_Running = 0;
@@ -62,15 +70,19 @@ static int AFS_Running = 0;
 static int afs_CacheInit_Done = 0;
 static int afs_Go_Done = 0;
 extern struct interfaceAddr afs_cb_interface;
+#ifdef RXK_LISTENER_ENV
 static int afs_RX_Running = 0;
+#endif
 static int afs_InitSetup_done = 0;
 afs_int32 afs_numcachefiles = -1;
 afs_int32 afs_numfilesperdir = -1;
 char afs_cachebasedir[1024];
+afs_int32 afs_rmtsys_enable = 0;
 
 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
 afs_int32 afs_rx_idledead = AFS_IDLEDEADTIME;
+afs_int32 afs_rx_idledead_rep = AFS_IDLEDEADTIME_REP;
 
 static int afscall_set_rxpck_received = 0;
 
@@ -110,12 +122,14 @@ afs_InitSetup(int preallocs)
 
     memset(afs_zeros, 0, AFS_ZEROS);
 
+    rx_SetBusyChannelError(1);  /* turn on busy call error reporting */
+
     /* start RX */
     if(!afscall_set_rxpck_received)
     rx_extraPackets = AFS_NRXPACKETS;  /* smaller # of packets */
     code = rx_InitHost(rx_bindhost, htons(7001));
     if (code) {
-       printf("AFS: RX failed to initialize %d).\n", code);
+       afs_warn("AFS: RX failed to initialize %d).\n", code);
        return code;
     }
     rx_SetRxDeadTime(afs_rx_deadtime);
@@ -127,6 +141,39 @@ afs_InitSetup(int preallocs)
 
     return code;
 }
+
+#ifdef AFS_DAEMONOP_ENV
+static int
+daemonOp_common(long parm, long parm2, long parm3, long parm4, long parm5,
+                long parm6)
+{
+    int code;
+    if (parm == AFSOP_START_RXCALLBACK) {
+       if (afs_CB_Running)
+           return -1;
+# ifdef RXK_LISTENER_ENV
+    } else if (parm == AFSOP_RXLISTENER_DAEMON) {
+       if (afs_RX_Running)
+           return -1;
+       afs_RX_Running = 1;
+# endif
+       code = afs_InitSetup(parm2);
+       if (parm3) {
+           rx_enablePeerRPCStats();
+       }
+       if (parm4) {
+           rx_enableProcessRPCStats();
+       }
+       if (code)
+           return -1;
+    } else if (parm == AFSOP_START_AFS) {
+       if (AFS_Running)
+           return -1;
+    }                          /* other functions don't need setup in the parent */
+    return 0;
+}
+#endif /* AFS_DAEMONOP_ENV */
+
 #if defined(AFS_DARWIN80_ENV)
 struct afsd_thread_info {
     unsigned long parm;
@@ -142,8 +189,13 @@ afsd_thread(int *rock)
        AFS_GLOCK();
        wakeup(arg);
        afs_CB_Running = 1;
+#ifndef RXK_LISTENER_ENV
+       afs_initState = AFSOP_START_AFS;
+       afs_osi_Wakeup(&afs_initState);
+#else
        while (afs_RX_Running != 2)
            afs_osi_Sleep(&afs_RX_Running);
+#endif
        afs_RXCallBackServer();
        AFS_GUNLOCK();
        thread_terminate(current_thread());
@@ -161,16 +213,7 @@ afsd_thread(int *rock)
        thread_terminate(current_thread());
        break;
     case AFSOP_START_BKG:
-       AFS_GLOCK();
-       wakeup(arg);
-       while (afs_initState < AFSOP_START_BKG)
-           afs_osi_Sleep(&afs_initState);
-       if (afs_initState < AFSOP_GO) {
-           afs_initState = AFSOP_GO;
-           afs_osi_Wakeup(&afs_initState);
-       }
-       afs_BackgroundDaemon();
-       AFS_GUNLOCK();
+       afs_warn("Install matching afsd! Old background daemons not supported.\n");
        thread_terminate(current_thread());
        break;
     case AFSOP_START_TRUNCDAEMON:
@@ -198,6 +241,7 @@ afsd_thread(int *rock)
        AFS_GUNLOCK();
        thread_terminate(current_thread());
        break;
+#ifdef RXK_LISTENER_ENV
     case AFSOP_RXLISTENER_DAEMON:
        AFS_GLOCK();
        wakeup(arg);
@@ -210,8 +254,9 @@ afsd_thread(int *rock)
        AFS_GUNLOCK();
        thread_terminate(current_thread());
        break;
+#endif
     default:
-       printf("Unknown op %ld in StartDaemon()\n", (long)parm);
+       afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
        break;
     }
 }
@@ -220,30 +265,11 @@ void
 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
             long parm6)
 {
-    int code;
     struct afsd_thread_info info;
     thread_t thread;
-
-    if (parm == AFSOP_START_RXCALLBACK) {
-       if (afs_CB_Running)
-           return;
-    } else if (parm == AFSOP_RXLISTENER_DAEMON) {
-       if (afs_RX_Running)
-           return;
-       afs_RX_Running = 1;
-       code = afs_InitSetup(parm2);
-       if (parm3) {
-           rx_enablePeerRPCStats();
-       }
-       if (parm4) {
-           rx_enableProcessRPCStats();
-       }
-       if (code)
-           return;
-    } else if (parm == AFSOP_START_AFS) {
-       if (AFS_Running)
-           return;
-    }                          /* other functions don't need setup in the parent */
+    if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
+       return;
+    }
     info.parm = parm;
     kernel_thread_start((thread_continue_t)afsd_thread, &info, &thread);
     AFS_GUNLOCK();
@@ -255,11 +281,11 @@ afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
 #endif
 
 
-#if defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)
+#if defined(AFS_LINUX24_ENV) && defined(HAVE_LINUX_COMPLETION_H)
 struct afsd_thread_info {
-#if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
+# if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
     struct work_struct tq;
-#endif
+# endif
     unsigned long parm;
     struct completion *complete;
 };
@@ -269,20 +295,22 @@ afsd_thread(void *rock)
 {
     struct afsd_thread_info *arg = rock;
     unsigned long parm = arg->parm;
-#ifdef SYS_SETPRIORITY_EXPORTED
+# ifdef SYS_SETPRIORITY_EXPORTED
     int (*sys_setpriority) (int, int, int) = sys_call_table[__NR_setpriority];
-#endif
-#if defined(AFS_LINUX26_ENV)
+# endif
+# if !defined(HAVE_LINUX_KTHREAD_RUN)
+#  if defined(AFS_LINUX26_ENV)
     daemonize("afsd");
-#else
+#  else
     daemonize();
-#endif
+#  endif
+# endif /* !HAVE_LINUX_KTHREAD_RUN */
                                /* doesn't do much, since we were forked from keventd, but
                                 * does call mm_release, which wakes up our parent (since it
                                 * used CLONE_VFORK) */
-#if !defined(AFS_LINUX26_ENV)
+# if !defined(AFS_LINUX26_ENV)
     reparent_to_init();
-#endif
+# endif
     afs_osi_MaskSignals();
     switch (parm) {
     case AFSOP_START_RXCALLBACK:
@@ -290,8 +318,13 @@ afsd_thread(void *rock)
        AFS_GLOCK();
        complete(arg->complete);
        afs_CB_Running = 1;
+#if !defined(RXK_LISTENER_ENV)
+       afs_initState = AFSOP_START_AFS;
+       afs_osi_Wakeup(&afs_initState);
+#else
        while (afs_RX_Running != 2)
            afs_osi_Sleep(&afs_RX_Running);
+#endif
        sprintf(current->comm, "afs_callback");
        afs_RXCallBackServer();
        AFS_GUNLOCK();
@@ -312,6 +345,9 @@ afsd_thread(void *rock)
        complete_and_exit(0, 0);
        break;
     case AFSOP_START_BKG:
+#ifdef AFS_NEW_BKG
+       afs_warn("Install matching afsd! Old background daemons not supported.\n");
+#else
        sprintf(current->comm, "afs_bkgstart");
        AFS_GLOCK();
        complete(arg->complete);
@@ -324,6 +360,7 @@ afsd_thread(void *rock)
        sprintf(current->comm, "afs_background");
        afs_BackgroundDaemon();
        AFS_GUNLOCK();
+#endif
        complete_and_exit(0, 0);
        break;
     case AFSOP_START_TRUNCDAEMON:
@@ -347,13 +384,13 @@ afsd_thread(void *rock)
        break;
     case AFSOP_RXEVENT_DAEMON:
        sprintf(current->comm, "afs_evtstart");
-#ifdef SYS_SETPRIORITY_EXPORTED
+# ifdef SYS_SETPRIORITY_EXPORTED
        sys_setpriority(PRIO_PROCESS, 0, -10);
-#else
-#ifdef CURRENT_INCLUDES_NICE
+# else
+#  ifdef CURRENT_INCLUDES_NICE
        current->nice = -10;
-#endif
-#endif
+#  endif
+# endif
        AFS_GLOCK();
        complete(arg->complete);
        while (afs_initState < AFSOP_START_BKG)
@@ -363,15 +400,16 @@ afsd_thread(void *rock)
        AFS_GUNLOCK();
        complete_and_exit(0, 0);
        break;
+#ifdef RXK_LISTENER_ENV
     case AFSOP_RXLISTENER_DAEMON:
        sprintf(current->comm, "afs_lsnstart");
-#ifdef SYS_SETPRIORITY_EXPORTED
+# ifdef SYS_SETPRIORITY_EXPORTED
        sys_setpriority(PRIO_PROCESS, 0, -10);
-#else
-#ifdef CURRENT_INCLUDES_NICE
+# else
+#  ifdef CURRENT_INCLUDES_NICE
        current->nice = -10;
-#endif
-#endif
+#  endif
+# endif
        AFS_GLOCK();
        complete(arg->complete);
        afs_initState = AFSOP_START_AFS;
@@ -384,79 +422,68 @@ afsd_thread(void *rock)
        AFS_GUNLOCK();
        complete_and_exit(0, 0);
        break;
+#endif
     default:
-       printf("Unknown op %ld in StartDaemon()\n", (long)parm);
+       afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
        break;
     }
     return 0;
 }
 
 void
-#if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
+# if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
 afsd_launcher(struct work_struct *work)
-#else
+# else
 afsd_launcher(void *rock)
-#endif
+# endif
 {
-#if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
+# if defined(AFS_LINUX26_ENV) && !defined(INIT_WORK_HAS_DATA)
     struct afsd_thread_info *rock = container_of(work, struct afsd_thread_info, tq);
-#endif
+# endif
 
+# if defined(HAVE_LINUX_KTHREAD_RUN)
+    if (IS_ERR(kthread_run(afsd_thread, (void *)rock, "afsd"))) {
+       afs_warn("kthread_run failed; afs startup will not complete\n");
+    }
+# else /* !HAVE_LINUX_KTHREAD_RUN */
     if (!kernel_thread(afsd_thread, (void *)rock, CLONE_VFORK | SIGCHLD))
-       printf("kernel_thread failed. afs startup will not complete\n");
+       afs_warn("kernel_thread failed. afs startup will not complete\n");
+# endif /* !HAVE_LINUX_KTHREAD_RUN */
 }
 
 void
 afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
             long parm6)
 {
-    int code;
     DECLARE_COMPLETION(c);
-#if defined(AFS_LINUX26_ENV) 
-#if defined(INIT_WORK_HAS_DATA)
+# if defined(AFS_LINUX26_ENV)
+#  if defined(INIT_WORK_HAS_DATA)
     struct work_struct tq;
-#endif
-#else
+#  endif
+# else
     struct tq_struct tq;
-#endif
+# endif
     struct afsd_thread_info info;
-    if (parm == AFSOP_START_RXCALLBACK) {
-       if (afs_CB_Running)
-           return;
-    } else if (parm == AFSOP_RXLISTENER_DAEMON) {
-       if (afs_RX_Running)
-           return;
-       afs_RX_Running = 1;
-       code = afs_InitSetup(parm2);
-       if (parm3) {
-           rx_enablePeerRPCStats();
-       }
-       if (parm4) {
-           rx_enableProcessRPCStats();
-       }
-       if (code)
-           return;
-    } else if (parm == AFSOP_START_AFS) {
-       if (AFS_Running)
-           return;
-    }                          /* other functions don't need setup in the parent */
+    if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
+       return;
+    }
     info.complete = &c;
     info.parm = parm;
-#if defined(AFS_LINUX26_ENV)
-#if !defined(INIT_WORK_HAS_DATA)
+# if defined(AFS_LINUX26_ENV)
+#  if !defined(INIT_WORK_HAS_DATA)
     INIT_WORK(&info.tq, afsd_launcher);
     schedule_work(&info.tq);
-#else
+#  else
     INIT_WORK(&tq, afsd_launcher, &info);
     schedule_work(&tq);
-#endif
-#else
+#  endif
+# else
     tq.sync = 0;
     INIT_LIST_HEAD(&tq.list);
     tq.routine = afsd_launcher;
     tq.data = &info;
     schedule_task(&tq);
-#endif
+# endif
     AFS_GUNLOCK();
     /* we need to wait cause we passed stack pointers around.... */
     wait_for_completion(&c);
@@ -464,20 +491,117 @@ afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
 }
 #endif
 
+#ifdef AFS_SUN5_ENV
+struct afs_daemonop_args {
+    kcondvar_t cv;
+    long parm;
+};
+
 static void
-wait_for_cachedefs(void) {
-#ifdef AFS_CACHE_VNODE_PATH
-    if (cacheDiskType != AFS_FCACHE_TYPE_MEM) 
-       while ((afs_numcachefiles < 1) || (afs_numfilesperdir < 1) ||
-              (afs_cachebasedir[0] != '/')) {
-           printf("afs: waiting for cache parameter definitions\n");
+afsd_thread(struct afs_daemonop_args *args)
+{
+    long parm = args->parm;
+
+    AFS_GLOCK();
+    cv_signal(&args->cv);
+
+    switch (parm) {
+    case AFSOP_START_RXCALLBACK:
+       if (afs_CB_Running)
+           goto out;
+       afs_CB_Running = 1;
+       while (afs_RX_Running != 2)
+           afs_osi_Sleep(&afs_RX_Running);
+       afs_RXCallBackServer();
+       AFS_GUNLOCK();
+       return;
+    case AFSOP_START_AFS:
+       if (AFS_Running)
+           goto out;
+       AFS_Running = 1;
+       while (afs_initState < AFSOP_START_AFS)
+           afs_osi_Sleep(&afs_initState);
+       afs_initState = AFSOP_START_BKG;
+       afs_osi_Wakeup(&afs_initState);
+       afs_Daemon();
+       AFS_GUNLOCK();
+       return;
+    case AFSOP_START_BKG:
+       while (afs_initState < AFSOP_START_BKG)
            afs_osi_Sleep(&afs_initState);
+       if (afs_initState < AFSOP_GO) {
+           afs_initState = AFSOP_GO;
+           afs_osi_Wakeup(&afs_initState);
        }
-#endif
+       afs_BackgroundDaemon();
+       AFS_GUNLOCK();
+       return;
+    case AFSOP_START_TRUNCDAEMON:
+       while (afs_initState < AFSOP_GO)
+           afs_osi_Sleep(&afs_initState);
+       afs_CacheTruncateDaemon();
+       AFS_GUNLOCK();
+       return;
+    case AFSOP_START_CS:
+       afs_CheckServerDaemon();
+       AFS_GUNLOCK();
+       return;
+    case AFSOP_RXEVENT_DAEMON:
+       while (afs_initState < AFSOP_START_BKG)
+           afs_osi_Sleep(&afs_initState);
+       afs_rxevent_daemon();
+       AFS_GUNLOCK();
+       return;
+    case AFSOP_RXLISTENER_DAEMON:
+       afs_initState = AFSOP_START_AFS;
+       afs_osi_Wakeup(&afs_initState);
+       afs_RX_Running = 2;
+       afs_osi_Wakeup(&afs_RX_Running);
+       afs_osi_RxkRegister();
+       rxk_Listener();
+       AFS_GUNLOCK();
+       return;
+    default:
+       AFS_GUNLOCK();
+       afs_warn("Unknown op %ld in afsd_thread()\n", parm);
+       return;
+    }
+ out:
+    AFS_GUNLOCK();
+    return;
 }
 
+static void
+afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
+            long parm6)
+{
+    struct afs_daemonop_args args;
+
+    if (daemonOp_common(parm, parm2, parm3, parm4, parm5, parm6)) {
+       return;
+    }
+
+    args.parm = parm;
+
+    cv_init(&args.cv, "AFS DaemonOp cond var", CV_DEFAULT, NULL);
+
+    if (thread_create(NULL, 0, afsd_thread, &args, 0, &p0, TS_RUN,
+        minclsyspri) == NULL) {
+
+       afs_warn("thread_create failed: AFS startup will not complete\n");
+    }
+
+    /* we passed &args to the new thread, which is on the stack. wait until
+     * it has read the arguments so it doesn't try to read the args after we
+     * have returned */
+    cv_wait(&args.cv, &afs_global_lock);
+
+    cv_destroy(&args.cv);
+}
+#endif /* AFS_SUN5_ENV */
+
 #ifdef AFS_DARWIN100_ENV
-#define AFSKPTR(X) k ## X
+# define AFSKPTR(X) k ## X
 int
 afs_syscall_call(long parm, long parm2, long parm3,
                 long parm4, long parm5, long parm6)
@@ -490,7 +614,7 @@ afs_syscall_call(long parm, long parm2, long parm3,
                              CAST_USER_ADDR_T((parm6)));
 }
 #else
-#define AFSKPTR(X) ((caddr_t)X)
+# define AFSKPTR(X) ((caddr_t)X)
 #endif
 int
 #ifdef AFS_DARWIN100_ENV
@@ -502,7 +626,7 @@ afs_syscall_call(long parm, long parm2, long parm3,
 #endif
 {
     afs_int32 code = 0;
-#if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+#if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
     size_t bufferSize;
 #else /* AFS_SGI61_ENV */
     u_int bufferSize;
@@ -527,9 +651,9 @@ afs_syscall_call(long parm, long parm2, long parm3,
                    && (parm != AFSOP_GETMTU) && (parm != AFSOP_GETMASK)) {
        /* only root can run this code */
 #if defined(AFS_SUN5_ENV) || defined(KERNEL_HAVE_UERROR)
-#if defined(KERNEL_HAVE_UERROR)
+# if defined(KERNEL_HAVE_UERROR)
        setuerror(EACCES);
-#endif
+# endif
        code = EACCES;
 #else
        code = EPERM;
@@ -544,38 +668,88 @@ afs_syscall_call(long parm, long parm2, long parm3,
 #ifdef AFS_DARWIN80_ENV
     put_vfs_context();
 #endif
-#if ((defined(AFS_LINUX24_ENV) && defined(COMPLETION_H_EXISTS)) || defined(AFS_DARWIN80_ENV)) && !defined(UKERNEL)
+#ifdef AFS_DAEMONOP_ENV
+# if defined(AFS_NEW_BKG)
+    if (parm == AFSOP_BKG_HANDLER) {
+       /* if afs_uspc_param grows this should be checked */
+       struct afs_uspc_param *mvParam = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
+       void *param2;
+       void *param1;
+       int namebufsz;
+
+       AFS_COPYIN(AFSKPTR(parm2), (caddr_t)mvParam,
+                  sizeof(struct afs_uspc_param), code);
+       namebufsz = mvParam->bufSz;
+       param1 = afs_osi_Alloc(namebufsz);
+       osi_Assert(param1 != NULL);
+       param2 = afs_osi_Alloc(namebufsz);
+       osi_Assert(param2 != NULL);
+
+       while (afs_initState < AFSOP_START_BKG)
+           afs_osi_Sleep(&afs_initState);
+       if (afs_initState < AFSOP_GO) {
+           afs_initState = AFSOP_GO;
+           afs_osi_Wakeup(&afs_initState);
+       }
+
+       code = afs_BackgroundDaemon(mvParam, param1, param2);
+
+       if (!code) {
+           mvParam->retval = 0;
+           /* for reqs where pointers are strings: */
+           if (mvParam->reqtype == AFS_USPC_UMV) {
+               /* don't copy out random kernel memory */
+               AFS_COPYOUT(param2, AFSKPTR(parm4),
+                           MIN(namebufsz, strlen((char *)param2)+1), code);
+               AFS_COPYOUT(param1, AFSKPTR(parm3),
+                           MIN(namebufsz, strlen((char *)param1)+1), code);
+           }
+           AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
+                      sizeof(struct afs_uspc_param), code);
+       }
+
+       afs_osi_Free(param1, namebufsz);
+       afs_osi_Free(param2, namebufsz);
+       osi_FreeSmallSpace(mvParam);
+    } else
+# endif /* AFS_NEW_BKG */
     if (parm < AFSOP_ADDCELL || parm == AFSOP_RXEVENT_DAEMON
        || parm == AFSOP_RXLISTENER_DAEMON) {
        afs_DaemonOp(parm, parm2, parm3, parm4, parm5, parm6);
     }
-#else /* !(AFS_LINUX24_ENV && !UKERNEL) */
+#else /* !AFS_DAEMONOP_ENV */
     if (parm == AFSOP_START_RXCALLBACK) {
        if (afs_CB_Running)
            goto out;
        afs_CB_Running = 1;
-#ifndef RXK_LISTENER_ENV
+# ifndef RXK_LISTENER_ENV
        code = afs_InitSetup(parm2);
        if (!code)
-#endif /* !RXK_LISTENER_ENV */
+# endif /* !RXK_LISTENER_ENV */
        {
-#ifdef RXK_LISTENER_ENV
+# ifdef RXK_LISTENER_ENV
            while (afs_RX_Running != 2)
                afs_osi_Sleep(&afs_RX_Running);
-#else /* !RXK_LISTENER_ENV */
+# else /* !RXK_LISTENER_ENV */
+           if (parm3) {
+               rx_enablePeerRPCStats();
+           }
+           if (parm4) {
+               rx_enableProcessRPCStats();
+           }
            afs_initState = AFSOP_START_AFS;
            afs_osi_Wakeup(&afs_initState);
-#endif /* RXK_LISTENER_ENV */
+# endif /* RXK_LISTENER_ENV */
            afs_osi_Invisible();
            afs_RXCallBackServer();
            afs_osi_Visible();
        }
-#ifdef AFS_SGI_ENV
+# ifdef AFS_SGI_ENV
        AFS_GUNLOCK();
        exit(CLD_EXITED, code);
-#endif /* AFS_SGI_ENV */
+# endif /* AFS_SGI_ENV */
     }
-#ifdef RXK_LISTENER_ENV
+# ifdef RXK_LISTENER_ENV
     else if (parm == AFSOP_RXLISTENER_DAEMON) {
        if (afs_RX_Running)
            goto out;
@@ -593,18 +767,18 @@ afs_syscall_call(long parm, long parm2, long parm3,
            afs_osi_Invisible();
            afs_RX_Running = 2;
            afs_osi_Wakeup(&afs_RX_Running);
-#ifndef UKERNEL
+#  ifndef UKERNEL
            afs_osi_RxkRegister();
-#endif /* !UKERNEL */
+#  endif /* !UKERNEL */
            rxk_Listener();
            afs_osi_Visible();
        }
-#ifdef AFS_SGI_ENV
+#  ifdef       AFS_SGI_ENV
        AFS_GUNLOCK();
        exit(CLD_EXITED, code);
-#endif /* AFS_SGI_ENV */
+#  endif /* AFS_SGI_ENV */
     }
-#endif /* RXK_LISTENER_ENV */
+# endif /* RXK_LISTENER_ENV */
     else if (parm == AFSOP_START_AFS) {
        /* afs daemon */
        if (AFS_Running)
@@ -618,18 +792,19 @@ afs_syscall_call(long parm, long parm2, long parm3,
        afs_osi_Invisible();
        afs_Daemon();
        afs_osi_Visible();
-#ifdef AFS_SGI_ENV
+# ifdef AFS_SGI_ENV
        AFS_GUNLOCK();
        exit(CLD_EXITED, 0);
-#endif /* AFS_SGI_ENV */
+# endif /* AFS_SGI_ENV */
     } else if (parm == AFSOP_START_CS) {
        afs_osi_Invisible();
        afs_CheckServerDaemon();
        afs_osi_Visible();
-#ifdef AFS_SGI_ENV
+# ifdef AFS_SGI_ENV
        AFS_GUNLOCK();
        exit(CLD_EXITED, 0);
-#endif /* AFS_SGI_ENV */
+# endif /* AFS_SGI_ENV */
+# ifndef AFS_NEW_BKG
     } else if (parm == AFSOP_START_BKG) {
        while (afs_initState < AFSOP_START_BKG)
            afs_osi_Sleep(&afs_initState);
@@ -639,17 +814,18 @@ afs_syscall_call(long parm, long parm2, long parm3,
        }
        /* start the bkg daemon */
        afs_osi_Invisible();
-#ifdef AFS_AIX32_ENV
+#  ifdef AFS_AIX32_ENV
        if (parm2)
            afs_BioDaemon(parm2);
        else
-#endif /* AFS_AIX32_ENV */
+#  endif /* AFS_AIX32_ENV */
            afs_BackgroundDaemon();
        afs_osi_Visible();
-#ifdef AFS_SGI_ENV
+#  ifdef AFS_SGI_ENV
        AFS_GUNLOCK();
        exit(CLD_EXITED, 0);
-#endif /* AFS_SGI_ENV */
+#  endif /* AFS_SGI_ENV */
+# endif /* ! AFS_NEW_BKG */
     } else if (parm == AFSOP_START_TRUNCDAEMON) {
        while (afs_initState < AFSOP_GO)
            afs_osi_Sleep(&afs_initState);
@@ -657,25 +833,25 @@ afs_syscall_call(long parm, long parm2, long parm3,
        afs_osi_Invisible();
        afs_CacheTruncateDaemon();
        afs_osi_Visible();
-#ifdef AFS_SGI_ENV
+# ifdef        AFS_SGI_ENV
        AFS_GUNLOCK();
        exit(CLD_EXITED, 0);
-#endif /* AFS_SGI_ENV */
+# endif /* AFS_SGI_ENV */
     }
-#if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
+# if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
     else if (parm == AFSOP_RXEVENT_DAEMON) {
        while (afs_initState < AFSOP_START_BKG)
            afs_osi_Sleep(&afs_initState);
        afs_osi_Invisible();
        afs_rxevent_daemon();
        afs_osi_Visible();
-#ifdef AFS_SGI_ENV
+#  ifdef AFS_SGI_ENV
        AFS_GUNLOCK();
        exit(CLD_EXITED, 0);
-#endif /* AFS_SGI_ENV */
+#  endif /* AFS_SGI_ENV */
     }
-#endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV */
-#endif /* AFS_LINUX24_ENV && !UKERNEL */
+# endif /* AFS_SUN5_ENV || RXK_LISTENER_ENV || RXK_UPCALL_ENV */
+#endif /* AFS_DAEMONOP_ENV */
     else if (parm == AFSOP_BASIC_INIT) {
        afs_int32 temp;
 
@@ -705,13 +881,14 @@ afs_syscall_call(long parm, long parm2, long parm3,
        case 2:
            afs_tpct2 = parm3;
            break;
-       }           
+       }
     } else if (parm == AFSOP_ADDCELL) {
        /* add a cell.  Parameter 2 is 8 hosts (in net order),  parm 3 is the null-terminated
         * name.  Parameter 4 is the length of the name, including the null.  Parm 5 is the
         * home cell flag (0x1 bit) and the nosuid flag (0x2 bit) */
        struct afsop_cell *tcell = afs_osi_Alloc(sizeof(struct afsop_cell));
 
+       osi_Assert(tcell != NULL);
        code = afs_InitDynroot();
        if (!code) {
            AFS_COPYIN(AFSKPTR(parm2), (caddr_t)tcell->hosts, sizeof(tcell->hosts),
@@ -734,6 +911,9 @@ afs_syscall_call(long parm, long parm2, long parm3,
        char *tbuffer1 = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
        int cflags = parm4;
 
+       osi_Assert(tcell != NULL);
+       osi_Assert(tbuffer != NULL);
+       osi_Assert(tbuffer1 != NULL);
        code = afs_InitDynroot();
        if (!code) {
 #if 0
@@ -757,6 +937,9 @@ afs_syscall_call(long parm, long parm2, long parm3,
                        cflags |= CLinkedCell;
                    }
                }
+               if (parm4 & 8) {
+                   cflags |= CHush;
+               }
                if (!code)
                    code =
                        afs_NewCell(tbuffer1, tcell->hosts, cflags, lcnamep,
@@ -794,13 +977,14 @@ afs_syscall_call(long parm, long parm2, long parm3,
         */
        char *cell = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
 
-       code = afs_InitDynroot();
-       if (!code) {
-           AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
-       }
+       afs_CellInit();
+       AFS_COPYINSTR(AFSKPTR(parm2), cell, AFS_SMALLOCSIZ, &bufferSize, code);
        if (!code)
            afs_SetPrimaryCell(cell);
        osi_FreeSmallSpace(cell);
+       if (!code) {
+           code = afs_InitDynroot();
+       }
     } else if (parm == AFSOP_CACHEINIT) {
        struct afs_cacheParams cparms;
 
@@ -817,13 +1001,16 @@ afs_syscall_call(long parm, long parm2, long parm3,
        }
        afs_CacheInit_Done = 1;
         code = afs_icl_InitLogs();
-       afs_setTime = cparms.setTimeFlag;
+       if (cparms.setTimeFlag) {
+           afs_warn("afs: AFSOP_CACHEINIT setTimeFlag ignored; are you "
+                    "running an old afsd?\n");
+       }
 
        code =
            afs_CacheInit(cparms.cacheScaches, cparms.cacheFiles,
                          cparms.cacheBlocks, cparms.cacheDcaches,
                          cparms.cacheVolumes, cparms.chunkSize,
-                         cparms.memCacheFlag, cparms.inodes, cparms.users, 
+                         cparms.memCacheFlag, cparms.inodes, cparms.users,
                          cparms.dynamic_vcaches);
 
     } else if (parm == AFSOP_CACHEINODE) {
@@ -861,8 +1048,7 @@ afs_syscall_call(long parm, long parm2, long parm3,
        } else
            code = 0;
     } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
-              || parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG
-              || parm == AFSOP_CELLINFO || parm == AFSOP_CACHEBASEDIR) {
+              || parm == AFSOP_VOLUMEINFO || parm == AFSOP_CELLINFO) {
        char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
 
        code = 0;
@@ -878,21 +1064,13 @@ afs_syscall_call(long parm, long parm2, long parm3,
 #ifdef AFS_DARWIN80_ENV
            get_vfs_context();
 #endif
-           if (parm == AFSOP_CACHEBASEDIR) {
-               strncpy(afs_cachebasedir, tbuffer, 1024);
-               afs_cachebasedir[1023] = '\0';
-               afs_osi_Wakeup(&afs_initState);
-           } else if (parm == AFSOP_CACHEFILE) {
-               wait_for_cachedefs();
+           if (parm == AFSOP_CACHEFILE) {
                code = afs_InitCacheFile(tbuffer, 0);
            } else if (parm == AFSOP_CACHEINFO) {
-               wait_for_cachedefs();
                code = afs_InitCacheInfo(tbuffer);
            } else if (parm == AFSOP_VOLUMEINFO) {
-               wait_for_cachedefs();
                code = afs_InitVolumeInfo(tbuffer);
            } else if (parm == AFSOP_CELLINFO) {
-               wait_for_cachedefs();
                code = afs_InitCellInfo(tbuffer);
            }
 #ifdef AFS_DARWIN80_ENV
@@ -901,26 +1079,6 @@ afs_syscall_call(long parm, long parm2, long parm3,
        }
        osi_FreeSmallSpace(tbuffer);
     } else if (parm == AFSOP_GO) {
-#ifdef AFS_CACHE_VNODE_PATH
-       if (cacheDiskType != AFS_FCACHE_TYPE_MEM) {
-           afs_int32 dummy;
-           
-           wait_for_cachedefs();
-           
-#ifdef AFS_DARWIN80_ENV
-           get_vfs_context();
-#endif
-           if ((afs_numcachefiles > 0) && (afs_numfilesperdir > 0) && 
-               (afs_cachebasedir[0] == '/')) {
-               for (dummy = 0; dummy < afs_numcachefiles; dummy++) {
-                   code = afs_InitCacheFile(NULL, dummy);
-               }
-           }
-#ifdef AFS_DARWIN80_ENV
-           put_vfs_context();
-#endif
-       }
-#endif
        /* the generic initialization calls come here.  One parameter: should we do the
         * set-time operation on this workstation */
        if (afs_Go_Done)
@@ -929,19 +1087,25 @@ afs_syscall_call(long parm, long parm2, long parm3,
        while (afs_initState < AFSOP_GO)
            afs_osi_Sleep(&afs_initState);
        afs_initState = 101;
-       afs_setTime = parm2;
+       if (parm2) {
+           /* parm2 used to set afs_setTime */
+           afs_warn("afs: AFSOP_GO setTime flag ignored; are you running an "
+                    "old afsd?\n");
+       }
        if (afs_tpct1 + afs_tpct2 != 100) {
            afs_tpct1 = 0;
            afs_tpct2 = 0;
            splitdcache = 0;
-       } else {        
+       } else {
            splitdcache = 1;
        }
        afs_osi_Wakeup(&afs_initState);
 #if    (!defined(AFS_NONFSTRANS)) || defined(AFS_AIX_IAUTH_ENV)
        afs_nfsclient_init();
 #endif
-       afs_uuid_create(&afs_cb_interface.uuid);
+       if (afs_uuid_create(&afs_cb_interface.uuid) != 0)
+           memset(&afs_cb_interface.uuid, 0, sizeof(afsUUID));
+
        printf("found %d non-empty cache files (%d%%).\n",
               afs_stats_cmperf.cacheFilesReused,
               (100 * afs_stats_cmperf.cacheFilesReused) /
@@ -961,6 +1125,9 @@ afs_syscall_call(long parm, long parm2, long parm3,
            afs_osi_Alloc(sizeof(afs_int32) * AFS_MAX_INTERFACE_ADDR);
        int i;
 
+       osi_Assert(buffer != NULL);
+       osi_Assert(maskbuffer != NULL);
+       osi_Assert(mtubuffer != NULL);
        /* This is a refresh */
        if (count & 0x40000000) {
            count &= ~0x40000000;
@@ -969,7 +1136,7 @@ afs_syscall_call(long parm, long parm2, long parm3,
            refresh = 1;
        }
 
-       /* Bind, but only if there's only one address configured */ 
+       /* Bind, but only if there's only one address configured */
        if ( count & 0x80000000) {
            count &= ~0x80000000;
            if (count == 1)
@@ -1026,71 +1193,43 @@ afs_syscall_call(long parm, long parm2, long parm3,
 
        if (refresh) {
            afs_CheckServers(1, NULL);     /* check down servers */
-           afs_CheckServers(0, NULL);     /* check down servers */
+           afs_CheckServers(0, NULL);     /* check up servers */
        }
     }
-#ifdef AFS_SGI53_ENV
-    else if (parm == AFSOP_NFSSTATICADDR) {
-       extern int (*nfs_rfsdisptab_v2) ();
-       nfs_rfsdisptab_v2 = (int (*)())parm2;
-    } else if (parm == AFSOP_NFSSTATICADDR2) {
-       extern int (*nfs_rfsdisptab_v2) ();
-#ifdef _K64U64
-       nfs_rfsdisptab_v2 = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
-#else /* _K64U64 */
-       nfs_rfsdisptab_v2 = (int (*)())(parm3 & 0xffffffff);
-#endif /* _K64U64 */
-    }
-#if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
-    else if (parm == AFSOP_SBLOCKSTATICADDR2) {
-       extern int (*afs_sblockp) ();
-       extern void (*afs_sbunlockp) ();
-#ifdef _K64U64
-       afs_sblockp = (int (*)())((parm2 << 32) | (parm3 & 0xffffffff));
-       afs_sbunlockp = (void (*)())((parm4 << 32) | (parm5 & 0xffffffff));
-#else
-       afs_sblockp = (int (*)())(parm3 & 0xffffffff);
-       afs_sbunlockp = (void (*)())(parm5 & 0xffffffff);
-#endif /* _K64U64 */
-    }
-#endif /* AFS_SGI62_ENV && !AFS_SGI65_ENV */
-#endif /* AFS_SGI53_ENV */
     else if (parm == AFSOP_SHUTDOWN) {
        afs_cold_shutdown = 0;
        if (parm2 == 1)
            afs_cold_shutdown = 1;
-#ifndef AFS_DARWIN_ENV
        if (afs_globalVFS != 0) {
            afs_warn("AFS isn't unmounted yet! Call aborted\n");
            code = EACCES;
        } else
-#endif
            afs_shutdown();
     } else if (parm == AFSOP_AFS_VFSMOUNT) {
 #ifdef AFS_HPUX_ENV
        vfsmount(parm2, parm3, parm4, parm5);
 #else /* defined(AFS_HPUX_ENV) */
-#if defined(KERNEL_HAVE_UERROR)
+# if defined(KERNEL_HAVE_UERROR)
        setuerror(EINVAL);
-#else
+# else
        code = EINVAL;
-#endif
+# endif
 #endif /* defined(AFS_HPUX_ENV) */
     } else if (parm == AFSOP_CLOSEWAIT) {
        afs_SynchronousCloses = 'S';
     } else if (parm == AFSOP_GETMTU) {
        afs_uint32 mtu = 0;
 #if    !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
-#ifdef AFS_USERSPACE_IP_ADDR
+# ifdef AFS_USERSPACE_IP_ADDR
        afs_int32 i;
        i = rxi_Findcbi(parm2);
        mtu = ((i == -1) ? htonl(1500) : afs_cb_interface.mtu[i]);
-#else /* AFS_USERSPACE_IP_ADDR */
-       AFS_IFNET_T tifnp;
+# else /* AFS_USERSPACE_IP_ADDR */
+       rx_ifnet_t tifnp;
 
        tifnp = rxi_FindIfnet(parm2, NULL);     /*  make iterative */
-       mtu = (tifnp ? ifnet_mtu(tifnp) : htonl(1500));
-#endif /* else AFS_USERSPACE_IP_ADDR */
+       mtu = (tifnp ? rx_ifnet_mtu(tifnp) : htonl(1500));
+# endif /* else AFS_USERSPACE_IP_ADDR */
 #endif /* !AFS_SUN5_ENV */
        if (!code)
            AFS_COPYOUT((caddr_t) & mtu, AFSKPTR(parm3),
@@ -1106,15 +1245,15 @@ afs_syscall_call(long parm, long parm2, long parm3,
        extern u_long sb_max_dflt;
        if (!adjusted) {
          adjusted = 1;
-         if (sb_max_dflt < 131072) sb_max_dflt = 131072; 
-         if (sb_max < 131072) sb_max = 131072; 
+         if (sb_max_dflt < 131072) sb_max_dflt = 131072;
+         if (sb_max < 131072) sb_max = 131072;
        }
       } */
 #endif /* AFS_AIX32_ENV */
     } else if (parm == AFSOP_GETMASK) {        /* parm2 == addr in net order */
        afs_uint32 mask = 0;
 #if    !defined(AFS_SUN5_ENV)
-#ifdef AFS_USERSPACE_IP_ADDR
+# ifdef AFS_USERSPACE_IP_ADDR
        afs_int32 i;
        i = rxi_Findcbi(parm2);
        if (i != -1) {
@@ -1122,19 +1261,18 @@ afs_syscall_call(long parm, long parm2, long parm3,
        } else {
            code = -1;
        }
-#else /* AFS_USERSPACE_IP_ADDR */
-       AFS_IFNET_T tifnp;
+# else /* AFS_USERSPACE_IP_ADDR */
+       rx_ifnet_t tifnp;
 
        tifnp = rxi_FindIfnet(parm2, &mask);    /* make iterative */
        if (!tifnp)
            code = -1;
-#endif /* else AFS_USERSPACE_IP_ADDR */
+# endif /* else AFS_USERSPACE_IP_ADDR */
 #endif /* !AFS_SUN5_ENV */
        if (!code)
            AFS_COPYOUT((caddr_t) & mask, AFSKPTR(parm3),
                        sizeof(afs_int32), code);
     }
-#ifdef AFS_AFSDB_ENV
     else if (parm == AFSOP_AFSDB_HANDLER) {
        int sizeArg = (int)parm4;
        int kmsgLen = sizeArg & 0xffff;
@@ -1142,6 +1280,8 @@ afs_syscall_call(long parm, long parm2, long parm3,
        afs_int32 *kmsg = afs_osi_Alloc(kmsgLen);
        char *cellname = afs_osi_Alloc(cellLen);
 
+       osi_Assert(kmsg != NULL);
+       osi_Assert(cellname != NULL);
 #ifndef UKERNEL
        afs_osi_MaskUserLoop();
 #endif
@@ -1161,7 +1301,6 @@ afs_syscall_call(long parm, long parm2, long parm3,
        afs_osi_Free(kmsg, kmsgLen);
        afs_osi_Free(cellname, cellLen);
     }
-#endif
     else if (parm == AFSOP_SET_DYNROOT) {
        code = afs_SetDynrootEnable(parm2);
     } else if (parm == AFSOP_SET_FAKESTAT) {
@@ -1174,6 +1313,11 @@ afs_syscall_call(long parm, long parm2, long parm3,
        afscall_set_rxpck_received = 1;
     } else if (parm == AFSOP_SET_RXMAXMTU) {
        rx_MyMaxSendSize = rx_maxReceiveSizeUser = rx_maxReceiveSize = parm2;
+    } else if (parm == AFSOP_SET_RXMAXFRAGS) {
+       rxi_nSendFrags = rxi_nRecvFrags = parm2;
+    } else if (parm == AFSOP_SET_RMTSYS_FLAG) {
+       afs_rmtsys_enable = parm2;
+       code = 0;
     } else {
        code = EINVAL;
     }
@@ -1200,7 +1344,7 @@ afs_syscall_call(long parm, long parm2, long parm3,
 int
 afs_CheckInit(void)
 {
-    register int code = 0;
+    int code = 0;
 
     AFS_STATCNT(afs_CheckInit);
     if (afs_initState <= 100)
@@ -1230,19 +1374,44 @@ afs_shutdown(void)
 
     if (afs_shuttingdown)
        return;
+
+    /* Give up all of our callbacks if we can. This must be done before setting
+     * afs_shuttingdown, since it calls afs_InitReq, which will fail if
+     * afs_shuttingdown is set. */
+    afs_FlushVCBs(2);
+
     afs_shuttingdown = 1;
+
     if (afs_cold_shutdown)
-       afs_warn("COLD ");
+       afs_warn("afs: COLD ");
     else
-       afs_warn("WARM ");
-    afs_warn("shutting down of: CB... ");
+       afs_warn("afs: WARM ");
+    afs_warn("shutting down of: vcaches... ");
+
+#if !defined(AFS_FBSD_ENV)
+    /* The FBSD afs_unmount() calls vflush(), which reclaims all vnodes
+     * on the mountpoint, flushing them in the process.  In the presence
+     * of bugs, flushing again here can cause panics. */
+    afs_FlushAllVCaches();
+#endif
+
+    afs_termState = AFSOP_STOP_BKG;
+
+    afs_warn("BkG... ");
+    /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
+    while (afs_termState == AFSOP_STOP_BKG) {
+       afs_osi_Wakeup(&afs_brsDaemons);
+       afs_osi_Sleep(&afs_termState);
+    }
+
+    afs_warn("CB... ");
 
     afs_termState = AFSOP_STOP_RXCALLBACK;
     rx_WakeupServerProcs();
 #ifdef AFS_AIX51_ENV
     shutdown_rxkernel();
 #endif
-    /* shutdown_rxkernel(); */
+    /* close rx server connections here? */
     while (afs_termState == AFSOP_STOP_RXCALLBACK)
        afs_osi_Sleep(&afs_termState);
 
@@ -1257,34 +1426,26 @@ afs_shutdown(void)
            afs_osi_Sleep(&afs_termState);
        }
     }
-    afs_warn("BkG... ");
-    /* Wake-up afs_brsDaemons so that we don't have to wait for a bkg job! */
-    while (afs_termState == AFSOP_STOP_BKG) {
-       afs_osi_Wakeup(&afs_brsDaemons);
-       afs_osi_Sleep(&afs_termState);
-    }
     afs_warn("CTrunc... ");
     /* Cancel cache truncate daemon. */
     while (afs_termState == AFSOP_STOP_TRUNCDAEMON) {
        afs_osi_Wakeup((char *)&afs_CacheTruncateDaemon);
        afs_osi_Sleep(&afs_termState);
     }
-#ifdef AFS_AFSDB_ENV
     afs_warn("AFSDB... ");
     afs_StopAFSDB();
     while (afs_termState == AFSOP_STOP_AFSDB)
        afs_osi_Sleep(&afs_termState);
-#endif
-#if    defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
+#if    defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
     afs_warn("RxEvent... ");
     /* cancel rx event daemon */
     while (afs_termState == AFSOP_STOP_RXEVENT)
        afs_osi_Sleep(&afs_termState);
-#if defined(RXK_LISTENER_ENV)
-#ifndef UKERNEL
+# if defined(RXK_LISTENER_ENV)
+#  ifndef UKERNEL
     afs_warn("UnmaskRxkSignals... ");
     afs_osi_UnmaskRxkSignals();
-#endif
+#  endif
     /* cancel rx listener */
     afs_warn("RxListener... ");
     osi_StopListener();                /* This closes rx_socket. */
@@ -1292,24 +1453,20 @@ afs_shutdown(void)
        afs_warn("Sleep... ");
        afs_osi_Sleep(&afs_termState);
     }
+# endif
 #endif
-#else
-    afs_termState = AFSOP_STOP_COMPLETE;
+
+#if defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
+    afs_warn("NetIfPoller... ");
+    osi_StopNetIfPoller();
 #endif
-    afs_warn("\n");
+
+    afs_termState = AFSOP_STOP_COMPLETE;
 
 #ifdef AFS_AIX51_ENV
     shutdown_daemons();
 #endif
-
-#ifdef notdef
     shutdown_CB();
-    shutdown_AFS();
-    shutdown_rxkernel();
-    shutdown_rxevent();
-    shutdown_rx();
-    afs_shutdown_BKG();
-#endif
     shutdown_bufferpackage();
     shutdown_cache();
     shutdown_osi();
@@ -1331,20 +1488,21 @@ afs_shutdown(void)
     shutdown_osifile();
     shutdown_vnodeops();
     shutdown_memcache();
+    shutdown_xscache();
 #if (!defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV))
     shutdown_exporter();
     shutdown_nfsclnt();
 #endif
     shutdown_afstest();
+    shutdown_AFS();
     /* The following hold the cm stats */
-/*
     memset(&afs_cmstats, 0, sizeof(struct afs_CMStats));
     memset(&afs_stats_cmperf, 0, sizeof(struct afs_stats_CMPerf));
     memset(&afs_stats_cmfullperf, 0, sizeof(struct afs_stats_CMFullPerf));
-*/
-    afs_warn(" ALL allocated tables\n");
+    afs_warn(" ALL allocated tables... ");
 
     afs_shuttingdown = 0;
+    afs_warn("done\n");
 
     return;                    /* Just kill daemons for now */
 }
@@ -1353,18 +1511,10 @@ void
 shutdown_afstest(void)
 {
     AFS_STATCNT(shutdown_afstest);
-    afs_initState = afs_termState = afs_setTime = 0;
+    afs_initState = afs_termState = 0;
     AFS_Running = afs_CB_Running = 0;
     afs_CacheInit_Done = afs_Go_Done = 0;
     if (afs_cold_shutdown) {
        *afs_rootVolumeName = 0;
     }
 }
-
-
-/* In case there is a bunch of dynamically build bkg daemons to free */
-void
-afs_shutdown_BKG(void)
-{
-    AFS_STATCNT(shutdown_BKG);
-}