All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC,PATCH 4/14] knfsd: has_wspace per transport
@ 2007-05-16 19:22 Greg Banks
  2007-05-16 21:10 ` J. Bruce Fields
  0 siblings, 1 reply; 20+ messages in thread
From: Greg Banks @ 2007-05-16 19:22 UTC (permalink / raw)
  To: Tom Tucker; +Cc: Linux NFS Mailing List, Thomas Talpey, Peter Leckie


Move the code in svc_sock_enqueue() that checks for available
write space on the socket, into a new sko_has_wspace method
in svc_sock_ops.

Signed-off-by: Greg Banks <gnb@melbourne.sgi.com>
Signed-off-by: Peter Leckie <pleckie@melbourne.sgi.com>
---

 include/linux/sunrpc/svcsock.h |    4 +
 net/sunrpc/svcsock.c           |   74 +++++++++++++++++-------------
 2 files changed, 48 insertions(+), 30 deletions(-)

Index: linux/net/sunrpc/svcsock.c
===================================================================
--- linux.orig/net/sunrpc/svcsock.c	2007-05-17 00:36:20.381217499 +1000
+++ linux/net/sunrpc/svcsock.c	2007-05-17 00:49:50.820303639 +1000
@@ -204,22 +204,6 @@ svc_release_skb(struct svc_rqst *rqstp)
 }
 
 /*
- * Any space to write?
- */
-static inline unsigned long
-svc_sock_wspace(struct svc_sock *svsk)
-{
-	int wspace;
-
-	if (svsk->sk_sock->type == SOCK_STREAM)
-		wspace = sk_stream_wspace(svsk->sk_sk);
-	else
-		wspace = sock_wspace(svsk->sk_sk);
-
-	return wspace;
-}
-
-/*
  * Queue up a socket with data pending. If there are idle nfsd
  * processes, wake 'em up.
  *
@@ -268,21 +252,15 @@ svc_sock_enqueue(struct svc_sock *svsk)
 	BUG_ON(svsk->sk_pool != NULL);
 	svsk->sk_pool = pool;
 
-	set_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
-	if (((atomic_read(&svsk->sk_reserved) + serv->sv_max_mesg)*2
-	     > svc_sock_wspace(svsk))
+	if (svsk->sk_ops->sko_has_wspace
 	    && !test_bit(SK_CLOSE, &svsk->sk_flags)
 	    && !test_bit(SK_CONN, &svsk->sk_flags)) {
-		/* Don't enqueue while not enough space for reply */
-		dprintk("svc: socket %p  no space, %d*2 > %ld, not enqueued\n",
-			svsk->sk_sk, atomic_read(&svsk->sk_reserved)+serv->sv_max_mesg,
-			svc_sock_wspace(svsk));
-		svsk->sk_pool = NULL;
-		clear_bit(SK_BUSY, &svsk->sk_flags);
-		goto out_unlock;
+		if (!svsk->sk_ops->sko_has_wspace(svsk)) {
+			svsk->sk_pool = NULL;
+			clear_bit(SK_BUSY, &svsk->sk_flags);
+			goto out_unlock;
+		}
 	}
-	clear_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
-
 
 	if (!list_empty(&pool->sp_threads)) {
 		rqstp = list_entry(pool->sp_threads.next,
@@ -904,13 +882,42 @@ svc_tcpip_prepare_reply(struct svc_rqst 
 	return 0;
 }
 
+/**
+ * svc_sock_has_write_space - Checks if there is enough space
+ * to send the reply on the socket.
+ * @svsk: the svc_sock to write on
+ * @wspace: the number of bytes available for writing
+ */
+static int svc_sock_has_write_space(struct svc_sock *svsk, int wspace)
+{
+	struct svc_serv	*serv = svsk->sk_server;
+	int required = atomic_read(&svsk->sk_reserved) + serv->sv_max_mesg;
+
+	set_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
+	if (required*2 > wspace) {
+		/* Don't enqueue while not enough space for reply */
+		dprintk("svc: socket %p  no space, %d*2 > %d, not enqueued\n",
+			svsk->sk_sk, required, wspace);
+		return 0;
+	}
+	clear_bit(SOCK_NOSPACE, &svsk->sk_sock->flags);
+	return 1;
+}
+
+static int
+svc_udp_has_wspace(struct svc_sock *svsk)
+{
+	return svc_sock_has_write_space(svsk, sock_wspace(svsk->sk_sk));
+}
+
 static const struct svc_sock_ops svc_udp_ops = {
 	.sko_name = "udp",
 	.sko_recvfrom = svc_udp_recvfrom,
 	.sko_sendto = svc_udp_sendto,
 	.sko_detach = svc_tcpip_detach,
 	.sko_free = svc_tcpip_free,
-	.sko_prepare_reply = svc_tcpip_prepare_reply
+	.sko_prepare_reply = svc_tcpip_prepare_reply,
+	.sko_has_wspace = svc_udp_has_wspace
 };
 
 static void
@@ -1365,13 +1372,20 @@ svc_tcp_prepare_reply(struct svc_rqst *r
 	return 0;
 }
 
+static int
+svc_tcp_has_wspace(struct svc_sock *svsk)
+{
+	return svc_sock_has_write_space(svsk, sk_stream_wspace(svsk->sk_sk));
+}
+
 static const struct svc_sock_ops svc_tcp_ops = {
 	.sko_name = "tcp",
 	.sko_recvfrom = svc_tcp_recvfrom,
 	.sko_sendto = svc_tcp_sendto,
 	.sko_detach = svc_tcpip_detach,
 	.sko_free = svc_tcpip_free,
-	.sko_prepare_reply = svc_tcp_prepare_reply
+	.sko_prepare_reply = svc_tcp_prepare_reply,
+	.sko_has_wspace = svc_tcp_has_wspace
 };
 
 static void
Index: linux/include/linux/sunrpc/svcsock.h
===================================================================
--- linux.orig/include/linux/sunrpc/svcsock.h	2007-05-17 00:36:20.553194321 +1000
+++ linux/include/linux/sunrpc/svcsock.h	2007-05-17 00:46:47.944827892 +1000
@@ -33,6 +33,10 @@ struct svc_sock_ops {
 	 * fail, e.g. due to memory allocation.
 	 */
 	int                     (*sko_prepare_reply)(struct svc_rqst *);
+	/*
+	 * Return 1 if sufficient space to write reply to network.
+	 */
+	int			(*sko_has_wspace)(struct svc_sock *);
 };
 
 /*
-- 
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
Apparently, I'm Bedevere.  Which MPHG character are you?
I don't speak for SGI.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2007-05-23 20:12 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-16 19:22 [RFC,PATCH 4/14] knfsd: has_wspace per transport Greg Banks
2007-05-16 21:10 ` J. Bruce Fields
2007-05-17  7:12   ` Greg Banks
2007-05-17 10:30     ` Neil Brown
2007-05-17 12:39       ` Talpey, Thomas
2007-05-18  0:30         ` Neil Brown
2007-05-18  4:05       ` Greg Banks
2007-05-18 13:33         ` Tom Tucker
2007-05-18 13:39           ` Tom Tucker
2007-05-22 11:16           ` Greg Banks
2007-05-22 17:34             ` Tom Tucker
2007-05-23  2:32               ` Greg Banks
2007-05-23  5:22                 ` Tom Tucker
2007-05-23  6:41                   ` Greg Banks
2007-05-23 13:36                     ` Chuck Lever
2007-05-23 14:39                       ` Greg Banks
2007-05-23 20:11                         ` Chuck Lever
2007-05-18 13:44         ` Talpey, Thomas
2007-05-18  6:21       ` Greg Banks
2007-05-18  6:38         ` Neil Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.