macos: kernel socket upcall
[openafs.git] / src / afs / afs_call.c
index 64ae436..49f253b 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
@@ -110,6 +110,8 @@ afs_InitSetup(int preallocs)
 
     memset(afs_zeros, 0, AFS_ZEROS);
 
+    rx_SetBusyChannelError(RX_CALL_TIMEOUT);
+
     /* start RX */
     if(!afscall_set_rxpck_received)
     rx_extraPackets = AFS_NRXPACKETS;  /* smaller # of packets */
@@ -142,8 +144,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());
@@ -189,6 +196,7 @@ afsd_thread(int *rock)
        AFS_GUNLOCK();
        thread_terminate(current_thread());
        break;
+#ifdef RXK_LISTENER_ENV
     case AFSOP_RXLISTENER_DAEMON:
        AFS_GLOCK();
        wakeup(arg);
@@ -201,6 +209,7 @@ afsd_thread(int *rock)
        AFS_GUNLOCK();
        thread_terminate(current_thread());
        break;
+#endif
     default:
        afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
        break;
@@ -214,14 +223,15 @@ afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
     int code;
     struct afsd_thread_info info;
     thread_t thread;
-
     if (parm == AFSOP_START_RXCALLBACK) {
        if (afs_CB_Running)
            return;
+#ifdef RXK_LISTENER_ENV
     } else if (parm == AFSOP_RXLISTENER_DAEMON) {
        if (afs_RX_Running)
            return;
        afs_RX_Running = 1;
+#endif
        code = afs_InitSetup(parm2);
        if (parm3) {
            rx_enablePeerRPCStats();
@@ -281,8 +291,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();
@@ -354,6 +369,7 @@ 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
@@ -375,6 +391,7 @@ afsd_thread(void *rock)
        AFS_GUNLOCK();
        complete_and_exit(0, 0);
        break;
+#endif
     default:
        afs_warn("Unknown op %ld in StartDaemon()\n", (long)parm);
        break;
@@ -403,7 +420,7 @@ afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
 {
     int code;
     DECLARE_COMPLETION(c);
-#if defined(AFS_LINUX26_ENV) 
+#if defined(AFS_LINUX26_ENV)
 #if defined(INIT_WORK_HAS_DATA)
     struct work_struct tq;
 #endif
@@ -414,10 +431,12 @@ afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
     if (parm == AFSOP_START_RXCALLBACK) {
        if (afs_CB_Running)
            return;
+#ifdef RXK_LISTENER_ENV
     } else if (parm == AFSOP_RXLISTENER_DAEMON) {
        if (afs_RX_Running)
            return;
        afs_RX_Running = 1;
+#endif
        code = afs_InitSetup(parm2);
        if (parm3) {
            rx_enablePeerRPCStats();
@@ -536,7 +555,9 @@ afs_syscall_call(long parm, long parm2, long parm3,
                   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);
@@ -584,6 +605,12 @@ afs_syscall_call(long parm, long parm2, long parm3,
            while (afs_RX_Running != 2)
                afs_osi_Sleep(&afs_RX_Running);
 #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 */
@@ -728,13 +755,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),
@@ -757,6 +785,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
@@ -780,6 +811,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,
@@ -817,13 +851,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;
 
@@ -846,7 +881,7 @@ afs_syscall_call(long parm, long parm2, long parm3,
            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) {
@@ -928,7 +963,7 @@ afs_syscall_call(long parm, long parm2, long parm3,
            afs_tpct1 = 0;
            afs_tpct2 = 0;
            splitdcache = 0;
-       } else {        
+       } else {
            splitdcache = 1;
        }
        afs_osi_Wakeup(&afs_initState);
@@ -955,6 +990,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;
@@ -963,7 +1001,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)
@@ -1098,8 +1136,8 @@ 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 */
@@ -1133,6 +1171,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
@@ -1190,7 +1230,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)
@@ -1220,6 +1260,8 @@ afs_shutdown(void)
 
     if (afs_shuttingdown)
        return;
+    afs_FlushVCBs(2);       /* Reasonable effort to free dynamically allocated callback returns */
+
     afs_shuttingdown = 1;
     if (afs_cold_shutdown)
        afs_warn("afs: COLD ");
@@ -1281,10 +1323,15 @@ afs_shutdown(void)
        afs_osi_Sleep(&afs_termState);
     }
 #endif
-#else
-    afs_termState = AFSOP_STOP_COMPLETE;
 #endif
 
+#if defined(AFS_SUN510_ENV) || defined(RXK_UPCALL_ENV)
+    afs_warn("NetIfPoller... ");
+    osi_StopNetIfPoller();
+#endif
+
+    afs_termState = AFSOP_STOP_COMPLETE;
+
 #ifdef AFS_AIX51_ENV
     shutdown_daemons();
 #endif