ukernel: Fix AFS_GUNLOCK panic in rx_ServerProc
[openafs.git] / src / rx / UKERNEL / rx_knet.c
index 082ff68..66f6f01 100644 (file)
 
 
 #include "rx/rx_kcommon.h"
-
+#include "rx_atomic.h"
+#include "rx_internal.h"
 
 #define SECONDS_TO_SLEEP       0
 #define NANO_SECONDS_TO_SLEEP  100000000       /* 100 milliseconds */
 #define LOOPS_PER_WAITCHECK    10      /* once per second */
 
+struct usr_socket {
+    int sock;
+    short port;
+};
+
 unsigned short usr_rx_port = 0;
 
 struct usr_ifnet *usr_ifnet = NULL;
@@ -73,6 +79,9 @@ rxi_ListenerProc(osi_socket usockp, int *tnop, struct rx_call **newcallp)
      * for processing.
      */
     while (1) {
+        /* See if a check for additional packets was issued */
+        rx_CheckPackets();
+
        tp = rxi_AllocPacket(RX_PACKET_CLASS_RECEIVE);
        usr_assert(tp != NULL);
        rc = rxi_ReadPacket(usockp, tp, &host, &port);
@@ -146,7 +155,6 @@ rx_ServerProc(void *unused)
      * number of threads handling incoming calls */
     threadID = rxi_availProcs++;
 
-    AFS_GUNLOCK();
     while (1) {
        sock = OSI_NULLSOCKET;
        rxi_ServerProc(threadID, newcall, &sock);
@@ -159,7 +167,6 @@ rx_ServerProc(void *unused)
        /* assert(threadID != -1); */
        /* assert(newcall != NULL); */
     }
-    AFS_GLOCK();
     return NULL;
 }
 
@@ -174,7 +181,7 @@ rxk_NewSocketHost(afs_uint32 ahost, short aport)
 {
     struct usr_socket *usockp;
 
-    usockp = (struct usr_socket *)afs_osi_Alloc(sizeof(struct usr_socket));
+    usockp = afs_osi_Alloc(sizeof(struct usr_socket));
     usr_assert(usockp != NULL);
 
     usockp->sock = -1;
@@ -210,7 +217,6 @@ rxk_InitializeSocket(void)
     usr_assert(rx_socket != NULL);
     usockp = (struct usr_socket *)rx_socket;
 
-#undef socket
     sock = socket(PF_INET, SOCK_DGRAM, 0);
     usr_assert(sock >= 0);
 
@@ -223,7 +229,7 @@ rxk_InitializeSocket(void)
     len = sizeof(struct sockaddr_in);
     rc = getsockname(sock, (struct sockaddr *)&lcladdr, &len);
     usr_assert(rc >= 0);
-#ifdef AFS_USR_LINUX22_ENV
+#ifdef AFS_USR_LINUX_ENV
     optval0 = 131070;
 #else
     optval0 = 131072;
@@ -236,7 +242,7 @@ rxk_InitializeSocket(void)
     rc = getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (void *)&optval, &optlen);
     usr_assert(rc == 0);
     /* usr_assert(optval == optval0); */
-#ifdef AFS_USR_LINUX22_ENV
+#ifdef AFS_USR_LINUX_ENV
     optval0 = 131070;
 #else
     optval0 = 131072;
@@ -337,9 +343,10 @@ rx_Finalize(void)
 int
 rxi_Recvmsg(osi_socket socket, struct msghdr *msg_p, int flags)
 {
+    struct usr_socket *usock = (struct usr_socket *)socket;
     int ret;
     do {
-       ret = recvmsg(socket->sock, msg_p, flags);
+       ret = recvmsg(usock->sock, msg_p, flags);
     } while (ret == -1 && errno == EAGAIN);
     return ret;
 }