Skip to contentSkip to conversation

kNFSd - 4 of 6 - Make sure nfs/tcp socket only gets closed once.

PATCH In review NeilBrown 2 participants 3 messages Sep 4, 2003

Subsystems (3)
lore
Share & tools
lore

NeilBrown

author
#0 lore raw

PATCH 1/1 kNFSd - 4 of 6 - Make sure nfs/tcp socket only gets closed once.

It is possible for svc_delete_socket to be called multiple times, which can cause problems. This patch uses SK_DEAD to make sure it only has any effect the first time, and uses SK_DEAD in a few other places to make sure nothing is done on a deleted socket.

net/sunrpc/svcsock.c renamed from net/sunrpc/svcsock.c~current~ +8 -2
diff ./net/sunrpc/svcsock.c~current~ ./net/sunrpc/svcsock.c
@@ -120,6 +120,8 @@ svc_sock_enqueue(struct svc_sock *svsk)
 	if (!(svsk->sk_flags &
 	      ( (1<<SK_CONN)|(1<<SK_DATA)|(1<<SK_CLOSE)) ))
 		return;
+	if (test_bit(SK_DEAD, &svsk->sk_flags))
+		return;
 
 	spin_lock_bh(&serv->sv_lock);
 
@@ -930,6 +932,9 @@ svc_tcp_sendto(struct svc_rqst *rqstp)
 	bufp->iov[0].iov_len  = bufp->len << 2;
 	bufp->base[0] = htonl(0x80000000|((bufp->len << 2) - 4));
 
+	if (test_bit(SK_DEAD, &rqstp->rq_sock->sk_flags))
+		return -ENOTCONN;
+
 	sent = svc_sendto(rqstp, bufp->iov, bufp->nriov);
 	if (sent != bufp->len<<2) {
 		printk(KERN_NOTICE "rpc-srv/tcp: %s: sent only %d bytes of %d - shutting down socket\n",
@@ -1277,6 +1282,9 @@ svc_delete_socket(struct svc_sock *svsk)
 
 	dprintk("svc: svc_delete_socket(%p)\n", svsk);
 
+	if (test_and_set_bit(SK_DEAD, &svsk->sk_flags))
+		return ;
+
 	serv = svsk->sk_server;
 	sk = svsk->sk_sk;
 
@@ -1293,8 +1301,6 @@ svc_delete_socket(struct svc_sock *svsk)
 		list_del(&svsk->sk_ready);
 
 
-	set_bit(SK_DEAD, &svsk->sk_flags);
-
 	if (!svsk->sk_inuse) {
 		spin_unlock_bh(&serv->sv_lock);
 		sock_release(svsk->sk_sock);

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#1 lore raw
Quoted 5 lines · NeilBrown

It is possible for svc_delete_socket to be called multiple times, which can cause problems. This patch uses SK_DEAD to make sure it only has any effect the first time, and uses SK_DEAD in a few other places to make sure nothing is done on a deleted socket.

Can you please send me this patch attached instead inlined? Its not applying correctly due to some issue in email transport.

Thanks

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#2 lore raw
Quoted 5 lines · Marcelo Tosatti
Quoted 1 line · NeilBrown
Quoted 7 lines
Quoted 4 lines

It is possible for svc_delete_socket to be called multiple times, which can cause problems. This patch uses SK_DEAD to make sure it only has any effect the first time, and uses SK_DEAD in a few other places to make sure nothing is done on a deleted socket.

Can you please send me this patch attached instead inlined? Its not applying correctly due to some issue in email transport.

Nevermind, it was a local problem.

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs