Skip to contentSkip to conversation

kNFSd - 4 of 4 - Make sure an early close on a nfs/tcp connection is handled properly.

PATCH In review NeilBrown 1 participant 2 messages Jun 18, 2003

Subsystems (3)
lore
Share & tools
lore

NeilBrown

author
#0 lore raw

PATCH 1/1 kNFSd - 4 of 4 - Make sure an early close on a nfs/tcp connection is handled properly.

From: Hirokazu Takahashi <[email protected]>

In svc_tcp_listen_data_ready we should be waiting for TCP_LISTEN, not TCP_ESTABLISHED. The later only worked by accident.
Also, if a socket is closed as soon as we accept it, we must shut it down straight away as we will never get a 'close' event.

net/sunrpc/svcsock.c renamed from net/sunrpc/svcsock.c~current~ +13 -2
diff ./net/sunrpc/svcsock.c~current~ ./net/sunrpc/svcsock.c
@@ -595,8 +595,17 @@ svc_tcp_listen_data_ready(struct sock *s
 	dprintk("svc: socket %p TCP (listen) state change %d\n",
 			sk, sk->state);
 
-	if  (sk->state != TCP_ESTABLISHED) {
-		/* Aborted connection, SYN_RECV or whatever... */
+	if  (sk->state != TCP_LISTEN) {
+		/*
+		 * This callback may called twice when a new connection
+		 * is established as a child socket inherits everything
+		 * from a parent LISTEN socket.
+		 * 1) data_ready method of the parent socket will be called
+		 *    when one of child sockets become ESTABLISHED.
+		 * 2) data_ready method of the child socket may be called
+		 *    when it receives data before the socket is accepted.
+		 * In case of 2, we should ignore it silently.
+		 */
 		goto out;
 	}
 	if (!(svsk = (struct svc_sock *) sk->user_data)) {
@@ -964,6 +973,8 @@ svc_tcp_init(struct svc_sock *svsk)
 				    3 * svsk->sk_server->sv_bufsz);
 
 		set_bit(SK_CHNGBUF, &svsk->sk_flags);
+		if (sk->sk_state != TCP_ESTABLISHED) 
+			set_bit(SK_CLOSE, &svsk->sk_flags);
 	}
 
 	return 0;

-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

author
#1 lore raw

Review

Quoted 2 lines · On Wednesday June 18, [email protected] wrote:
(quoted diff) +2 -0
+		if (sk->sk_state != TCP_ESTABLISHED) 
+			set_bit(SK_CLOSE, &svsk->sk_flags);

Whoops. sk_state is in 2.5. It is state in 2.4. Please add following patch.

net/sunrpc/svcsock.c renamed from net/sunrpc/svcsock.c~current~ +2 -2
diff ./net/sunrpc/svcsock.c~current~ ./net/sunrpc/svcsock.c
@@ -826,7 +826,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
 			goto error;
 		svsk->sk_tcplen += len;
 		if (len < want) {
-			dprintk("svc: short recvfrom while reading record length (%d of %d)\n",
+			dprintk("svc: short recvfrom while reading record length (%d of %ld)\n",
 			        len, want);
 			svc_sock_received(svsk);
 			return -EAGAIN; /* record header not complete */
@@ -973,7 +973,7 @@ svc_tcp_init(struct svc_sock *svsk)
 				    3 * svsk->sk_server->sv_bufsz);
 
 		set_bit(SK_CHNGBUF, &svsk->sk_flags);
-		if (sk->sk_state != TCP_ESTABLISHED) 
+		if (sk->state != TCP_ESTABLISHED) 
 			set_bit(SK_CLOSE, &svsk->sk_flags);
 	}
 

-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs