Skip to contentSkip to conversation

sunrpc: fix typo in svc_udp_recvfrom

PATCH In review Olaf Kirch 3 participants 8 messages Mar 27, 2007 – Mar 28, 2007

Subsystems (3)
lore
Share & tools
lore

Olaf Kirch

author
#0 lore raw

PATCH 1/1 sunrpc: fix typo in svc_udp_recvfrom

I'm not sure whether this has been brought up already - I came across this today when poking around the code...

Olaf

--[ cut here ]--
Fix a typo in svc_udp_recvfrom

This patch corrects a small and hamless typo in svc_udp_recvfrom.

Signed-off-by [email protected]
---
 net/sunrpc/svcsock.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/svcsock.c +1 -1
Index: linux-2.6/net/sunrpc/svcsock.c
===================================================================
@@ -779,7 +779,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
 	}
 
 	clear_bit(SK_DATA, &svsk->sk_flags);
-	while ((err == kernel_recvmsg(svsk->sk_sock, &msg, NULL,
+	while ((err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
 				      0, 0, MSG_PEEK | MSG_DONTWAIT)) < 0 ||
 	       (skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err)) == NULL) {
 		if (err == -EAGAIN) {
Signature · 11 lines
Olaf Kirch  |  --- o --- Nous sommes du soleil we love when we play
[email protected] |    / | \   sol.dhoop.naytheet.ah kin.ir.samse.qurax

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
#1 lore raw
Quoted 20 lines · Olaf Kirch

I'm not sure whether this has been brought up already - I came across this today when poking around the code...

Olaf

--[ cut here ]--
Fix a typo in svc_udp_recvfrom

This patch corrects a small and hamless typo in svc_udp_recvfrom.

Signed-off-by [email protected]
---
 net/sunrpc/svcsock.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6/net/sunrpc/svcsock.c
===================================================================

net/sunrpc/svcsock.c svc_udp_recvfrom(struct svc_rqst *rqstp) · line 785

Quoted 8 lines
net/sunrpc/svcsock.c +1 -1
@@ -779,7 +779,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
 	}
 
 	clear_bit(SK_DATA, &svsk->sk_flags);
-	while ((err == kernel_recvmsg(svsk->sk_sock, &msg, NULL,
+	while ((err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
 				      0, 0, MSG_PEEK | MSG_DONTWAIT)) < 0 ||
 	       (skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err)) == NULL) {
 		if (err == -EAGAIN) {

Could you please rather move those assignments out of the while()? Good coding style dictates that the above should be avoided. One of the benefits is precisely to avoid the above ambiguities.

Something like

	for (;;) {
		err = kernel_recvmsg(svsk->sk_sock, &msg, NULL, 0, 0, MSG_PEEK|MSG_DONTWAIT);
		if (err == 0) {
			skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err);
			if (skb != NULL)
				break;
		}
		if (err == -EAGAIN) {
			svc_sock_received(svsk);
			return err;
		}
		/* possibly an icmp error */
		dprintk("svc: recvfrom returned error %d\n", -err);
	}

Cheers,
Trond

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

author
#2 lore raw

PATCH 1/1 sunrpc: fix typo in svc_udp_recvfrom

Quoted 3 lines · Trond Myklebust

Could you please rather move those assignments out of the while()? Good coding style dictates that the above should be avoided. One of the benefits is precisely to avoid the above ambiguities.

Okay, here we go:
----------------------
Fix a typo in svc_udp_recvfrom

This patch corrects a small and harmless typo in svc_udp_recvfrom.

Signed-off-by [email protected]
---
 net/sunrpc/svcsock.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
net/sunrpc/svcsock.c +8 -3
Index: linux-2.6/net/sunrpc/svcsock.c
===================================================================
@@ -779,9 +779,14 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
 	}
 
 	clear_bit(SK_DATA, &svsk->sk_flags);
-	while ((err == kernel_recvmsg(svsk->sk_sock, &msg, NULL,
-				      0, 0, MSG_PEEK | MSG_DONTWAIT)) < 0 ||
-	       (skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err)) == NULL) {
+	while (1) {
+		err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
+				      0, 0, MSG_PEEK | MSG_DONTWAIT);
+		if (err >= 0) {
+		       	skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err);
+			if (skb)
+				break;
+		}
 		if (err == -EAGAIN) {
 			svc_sock_received(svsk);
 			return err;
Signature · 11 lines
Olaf Kirch  |  --- o --- Nous sommes du soleil we love when we play
[email protected] |    / | \   sol.dhoop.naytheet.ah kin.ir.samse.qurax

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
#3 lore raw
Quoted 29 lines · Olaf Kirch
Quoted 3 lines · Trond Myklebust

Could you please rather move those assignments out of the while()? Good coding style dictates that the above should be avoided. One of the benefits is precisely to avoid the above ambiguities.

Okay, here we go:
----------------------
Fix a typo in svc_udp_recvfrom

This patch corrects a small and harmless typo in svc_udp_recvfrom.

Signed-off-by [email protected]
---
 net/sunrpc/svcsock.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Index: linux-2.6/net/sunrpc/svcsock.c
===================================================================

net/sunrpc/svcsock.c +1 -3
@@ -779,9 +779,14 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
 	}
 
 	clear_bit(SK_DATA, &svsk->sk_flags);
-	while ((err == kernel_recvmsg(svsk->sk_sock, &msg, NULL,
-				      0, 0, MSG_PEEK | MSG_DONTWAIT)) < 0 ||
-	       (skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err)) == NULL) {
+	while (1) {

net/sunrpc/svcsock.c svc_udp_recvfrom(struct svc_rqst *rqstp) · line 792

Quoted 10 lines
net/sunrpc/svcsock.c +7 -0
+		err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
+				      0, 0, MSG_PEEK | MSG_DONTWAIT);
+		if (err >= 0) {
+		       	skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err);
+			if (skb)
+				break;
+		}
 		if (err == -EAGAIN) {
 			svc_sock_received(svsk);
 			return err;

Thanks! That looks good to me.

Trond

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#4 lore raw
In reply to Olaf Kirch
Quoted 8 lines · On Tuesday March 27, [email protected] wrote:
Quoted 3 lines · Trond Myklebust

Could you please rather move those assignments out of the while()? Good coding style dictates that the above should be avoided. One of the benefits is precisely to avoid the above ambiguities.

Okay, here we go:
----------------------
Fix a typo in svc_udp_recvfrom

Thanks...

This is already in -mm : net-sunrpc-svcsockc-fix-a-check.patch Hopefully it will get to -linus soon.
Apparently coverty found it.

While I appreciate that having assignments inside conditionals can hurt readability, I don't find the new version particularly readable... The logic seems to be obscured. Maybe it is just obscure logic?

What about this (on top of current -mm).

NeilBrown

### Diffstat output

 ./net/sunrpc/svcsock.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
net/sunrpc/svcsock.c +13 -8
diff .prev/net/sunrpc/svcsock.c ./net/sunrpc/svcsock.c
@@ -779,15 +779,20 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
 	}
 
 	clear_bit(SK_DATA, &svsk->sk_flags);
-	while ((err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
-				     0, 0, MSG_PEEK | MSG_DONTWAIT)) < 0 ||
-	       (skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err)) == NULL) {
-		if (err == -EAGAIN) {
-			svc_sock_received(svsk);
-			return err;
+	skb = NULL;
+	err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
+			     0, 0, MSG_PEEK | MSG_DONTWAIT);
+	if (err >= 0)
+		skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err);
+
+	if (skb == NULL) {
+		if (err != -EAGAIN) {
+			/* possibly an icmp error */
+			dprintk("svc: recvfrom returned error %d\n", -err);
+			set_bit(SK_DATA, &svsk->sk_flags);
 		}
-		/* possibly an icmp error */
-		dprintk("svc: recvfrom returned error %d\n", -err);
+		svc_sock_received(svsk);
+		return -EAGAIN;
 	}
 	rqstp->rq_addrlen = sizeof(rqstp->rq_addr);
 	if (skb->tstamp.off_sec == 0) {

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

author
#5 lore raw

Hi Neil,

Quoted 1 line · Neil Brown

What about this (on top of current -mm).

Well, you just converted a while loop to an if. The old code would pull any ICMP signalled error condition out of the socket, and then try to get the data. The new code will return if it hits an ICMP error, without reasserting SK_DATA. Any pending UDP request will be stuck until the client retransmits.

So I think you really need the loop here.

Olaf

Quoted 40 lines

### Diffstat output

 ./net/sunrpc/svcsock.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff .prev/net/sunrpc/svcsock.c ./net/sunrpc/svcsock.c

net/sunrpc/svcsock.c +13 -8
@@ -779,15 +779,20 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
 	}
 
 	clear_bit(SK_DATA, &svsk->sk_flags);
-	while ((err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
-				     0, 0, MSG_PEEK | MSG_DONTWAIT)) < 0 ||
-	       (skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err)) == NULL) {
-		if (err == -EAGAIN) {
-			svc_sock_received(svsk);
-			return err;
+	skb = NULL;
+	err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
+			     0, 0, MSG_PEEK | MSG_DONTWAIT);
+	if (err >= 0)
+		skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err);
+
+	if (skb == NULL) {
+		if (err != -EAGAIN) {
+			/* possibly an icmp error */
+			dprintk("svc: recvfrom returned error %d\n", -err);
+			set_bit(SK_DATA, &svsk->sk_flags);
 		}
-		/* possibly an icmp error */
-		dprintk("svc: recvfrom returned error %d\n", -err);
+		svc_sock_received(svsk);
+		return -EAGAIN;
 	}
 	rqstp->rq_addrlen = sizeof(rqstp->rq_addr);
 	if (skb->tstamp.off_sec == 0) {
Signature · 11 lines
Olaf Kirch  |  --- o --- Nous sommes du soleil we love when we play
[email protected] |    / | \   sol.dhoop.naytheet.ah kin.ir.samse.qurax

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
#6 lore raw
Quoted 9 lines · On Wednesday March 28, [email protected] wrote:

Hi Neil,

Quoted 1 line · Neil Brown

What about this (on top of current -mm).

Well, you just converted a while loop to an if. The old code would pull any ICMP signalled error condition out of the socket, and then try to get the data. The new code will return if it hits an ICMP error, without

                                             ^^^^^^^
Quoted 1 line

reasserting SK_DATA. Any pending UDP request will

^^^^^^^^^^^^^^^^^^^

Quoted 16 lines

be stuck until the client retransmits.

So I think you really need the loop here.

Olaf

Quoted 10 lines
net/sunrpc/svcsock.c +3 -6
 	clear_bit(SK_DATA, &svsk->sk_flags);
-	while ((err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
-				     0, 0, MSG_PEEK | MSG_DONTWAIT)) < 0 ||
-	       (skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err)) == NULL) {
-		if (err == -EAGAIN) {
-			svc_sock_received(svsk);
-			return err;
+	skb = NULL;
+	err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
+			     0, 0, MSG_PEEK | MSG_DONTWAIT);
Quoted 8 lines

net/sunrpc/svcsock.c svc_udp_recvfrom(struct svc_rqst *rqstp) · line 792

Quoted 8 lines
net/sunrpc/svcsock.c +8 -0
+	if (err >= 0)
+		skb = skb_recv_datagram(svsk->sk_sk, 0, 1, &err);
+
+	if (skb == NULL) {
+		if (err != -EAGAIN) {
+			/* possibly an icmp error */
+			dprintk("svc: recvfrom returned error %d\n", -err);
+			set_bit(SK_DATA, &svsk->sk_flags);
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

while ((err= get_packet()) && err != -EAGAIN)

	;

works for me, but as the while loop gets bigger it (to me) becomes less obvious why it is there...

Ho hum... maybe I'm aiming for perfection and missing "good" ??

NeilBrown

Quoted 13 lines
Quoted 9 lines
net/sunrpc/svcsock.c +2 -2
 		}
-		/* possibly an icmp error */
-		dprintk("svc: recvfrom returned error %d\n", -err);
+		svc_sock_received(svsk);
+		return -EAGAIN;
 	}
 	rqstp->rq_addrlen = sizeof(rqstp->rq_addr);
 	if (skb->tstamp.off_sec == 0) {
Signature · 2 lines
Olaf Kirch  |  --- o --- Nous sommes du soleil we love when we play
[email protected] |    / | \   sol.dhoop.naytheet.ah kin.ir.samse.qurax

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

author
#7 lore raw
Quoted 6 lines · Neil Brown
Quoted 5 lines

net/sunrpc/svcsock.c svc_udp_recvfrom(struct svc_rqst *rqstp) · line 792

Quoted 5 lines
net/sunrpc/svcsock.c +5 -0
+	if (skb == NULL) {
+		if (err != -EAGAIN) {
+			/* possibly an icmp error */
+			dprintk("svc: recvfrom returned error %d\n", -err);
+			set_bit(SK_DATA, &svsk->sk_flags);
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Okay, you're right - I missed that.

Olaf

Signature · 11 lines
Olaf Kirch  |  --- o --- Nous sommes du soleil we love when we play
[email protected] |    / | \   sol.dhoop.naytheet.ah kin.ir.samse.qurax

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs