From: Greg Banks <gnb@sgi.com>
To: Tom Tucker <tom@opengridcomputing.com>
Cc: Linux NFS Mailing List <nfs@lists.sourceforge.net>,
Thomas Talpey <Thomas.Talpey@netapp.com>,
Peter Leckie <pleckie@melbourne.sgi.com>
Subject: [RFC,PATCH 9/14] knfsd: centralise SK_CONN handling
Date: Thu, 17 May 2007 05:25:54 +1000 [thread overview]
Message-ID: <20070516192554.GO9626@sgi.com> (raw)
Centralise the handling of the SK_CONN bit to that future
sunrpc server transport implementations will be easier to
write correctly. The bit should now not be manipulated
directly, inline exist to wrap that. Also, the sko_recvfrom
method does not need to check for SK_CONN anymore, that's
handled in core code which calls a new sko_accept method.
Signed-off-by: Greg Banks <gnb@melbourne.sgi.com>
Signed-off-by: Peter Leckie <pleckie@melbourne.sgi.com>
---
include/linux/sunrpc/svcsock.h | 24 +++++++++++++++++++++
net/sunrpc/svcsock.c | 34 +++++++++++++++---------------
2 files changed, 41 insertions(+), 17 deletions(-)
Index: linux/include/linux/sunrpc/svcsock.h
===================================================================
--- linux.orig/include/linux/sunrpc/svcsock.h 2007-05-17 03:00:56.550481700 +1000
+++ linux/include/linux/sunrpc/svcsock.h 2007-05-17 03:04:33.479451764 +1000
@@ -43,6 +43,10 @@ struct svc_sock_ops {
* svc_sock.
*/
u32 (*sko_max_payload)(struct svc_sock *);
+ /*
+ * Accept a pending connection, for connection-oriented transports
+ */
+ int (*sko_accept)(struct svc_sock *svsk);
};
/*
@@ -147,4 +151,24 @@ static inline void svc_sock_delete_bh(st
svc_sock_enqueue(svsk);
}
+/*
+ * For transport-specific code, to be called to clear the
+ * state that would otherwise result in a call to sko_accept.
+ */
+static inline void svc_sock_clear_connection_ready(struct svc_sock *svsk)
+{
+ clear_bit(SK_CONN, &svsk->sk_flags);
+}
+
+/*
+ * For transport-specific code, to be called on asynchronous
+ * notification of a connection attempt on a rendezvous socket.
+ * svc_sock_enqueue() should be called to enqueue the svc_sock
+ * so that an nfsd will eventually come along and call sko_accept.
+ */
+static inline void svc_sock_set_connection_ready(struct svc_sock *svsk)
+{
+ set_bit(SK_CONN, &svsk->sk_flags);
+}
+
#endif /* SUNRPC_SVCSOCK_H */
Index: linux/net/sunrpc/svcsock.c
===================================================================
--- linux.orig/net/sunrpc/svcsock.c 2007-05-17 03:01:15.048179452 +1000
+++ linux/net/sunrpc/svcsock.c 2007-05-17 03:04:33.479451764 +1000
@@ -919,6 +919,7 @@ static const struct svc_sock_ops svc_udp
.sko_prepare_reply = svc_tcpip_prepare_reply,
.sko_has_wspace = svc_udp_has_wspace,
.sko_max_payload = svc_udp_max_payload
+ /* no .sko_accept, obviously */
};
static void
@@ -974,7 +975,7 @@ svc_tcp_listen_data_ready(struct sock *s
*/
if (sk->sk_state == TCP_LISTEN) {
if (svsk) {
- set_bit(SK_CONN, &svsk->sk_flags);
+ svc_sock_set_connection_ready(svsk);
svc_sock_enqueue(svsk);
} else
printk("svc: socket %p: no user data\n", sk);
@@ -1036,7 +1037,7 @@ static inline int svc_port_is_privileged
/*
* Accept a TCP connection
*/
-static void
+static int
svc_tcp_accept(struct svc_sock *svsk)
{
struct sockaddr_storage addr;
@@ -1045,14 +1046,14 @@ svc_tcp_accept(struct svc_sock *svsk)
struct socket *sock = svsk->sk_sock;
struct socket *newsock;
struct svc_sock *newsvsk;
- int err, slen;
+ int err = 0, slen;
char buf[RPC_MAX_ADDRBUFLEN];
dprintk("svc: tcp_accept %p sock %p\n", svsk, sock);
if (!sock)
- return;
+ return -EINVAL;
- clear_bit(SK_CONN, &svsk->sk_flags);
+ svc_sock_clear_connection_ready(svsk);
err = kernel_accept(sock, &newsock, O_NONBLOCK);
if (err < 0) {
if (err == -ENOMEM)
@@ -1061,10 +1062,10 @@ svc_tcp_accept(struct svc_sock *svsk)
else if (err != -EAGAIN && net_ratelimit())
printk(KERN_WARNING "%s: accept failed (err %d)!\n",
serv->sv_name, -err);
- return;
+ return err;
}
- set_bit(SK_CONN, &svsk->sk_flags);
+ svc_sock_clear_connection_ready(svsk);
svc_sock_enqueue(svsk);
err = kernel_getpeername(newsock, sin, &slen);
@@ -1151,11 +1152,11 @@ svc_tcp_accept(struct svc_sock *svsk)
if (serv->sv_stats)
serv->sv_stats->nettcpconn++;
- return;
+ return 0;
failed:
sock_release(newsock);
- return;
+ return err;
}
/*
@@ -1180,12 +1181,6 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
return svc_deferred_recv(rqstp);
}
- if (svsk->sk_sk->sk_state == TCP_LISTEN) {
- svc_tcp_accept(svsk);
- svc_sock_received(svsk);
- return 0;
- }
-
if (test_and_clear_bit(SK_CHNGBUF, &svsk->sk_flags))
/* sndbuf needs to have room for one request
* per thread, otherwise we can stall even when the
@@ -1389,7 +1384,8 @@ static const struct svc_sock_ops svc_tcp
.sko_free = svc_tcpip_free,
.sko_prepare_reply = svc_tcp_prepare_reply,
.sko_has_wspace = svc_tcp_has_wspace,
- .sko_max_payload = svc_tcp_max_payload
+ .sko_max_payload = svc_tcp_max_payload,
+ .sko_accept = svc_tcp_accept
};
static void
@@ -1403,7 +1399,7 @@ svc_tcp_init(struct svc_sock *svsk)
if (sk->sk_state == TCP_LISTEN) {
dprintk("setting up TCP socket for listening\n");
sk->sk_data_ready = svc_tcp_listen_data_ready;
- set_bit(SK_CONN, &svsk->sk_flags);
+ svc_sock_set_connection_ready(svsk);
} else {
dprintk("setting up TCP socket for reading\n");
sk->sk_state_change = svc_tcp_state_change;
@@ -1550,6 +1546,9 @@ svc_recv(struct svc_rqst *rqstp, long ti
if (test_bit(SK_CLOSE, &svsk->sk_flags)) {
dprintk("svc_recv: found SK_CLOSE\n");
svc_delete_socket(svsk);
+ } else if (svsk->sk_sk->sk_state == TCP_LISTEN) {
+ svsk->sk_ops->sko_accept(svsk);
+ svc_sock_received(svsk);
} else {
dprintk("svc: server %p, pool %u, socket %p, inuse=%d\n",
rqstp, pool->sp_id, svsk, atomic_read(&svsk->sk_inuse));
@@ -1689,6 +1688,7 @@ static struct svc_sock *svc_setup_socket
int is_temporary = flags & SVC_SOCK_TEMPORARY;
dprintk("svc: svc_setup_socket %p\n", sock);
+ *errp = 0;
if (!(svsk = kzalloc(sizeof(*svsk), GFP_KERNEL))) {
*errp = -ENOMEM;
return NULL;
--
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
next reply other threads:[~2007-05-16 19:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-16 19:25 Greg Banks [this message]
2007-05-17 11:03 ` [RFC,PATCH 9/14] knfsd: centralise SK_CONN handling Neil Brown
2007-05-18 7:50 ` Greg Banks
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070516192554.GO9626@sgi.com \
--to=gnb@sgi.com \
--cc=Thomas.Talpey@netapp.com \
--cc=nfs@lists.sourceforge.net \
--cc=pleckie@melbourne.sgi.com \
--cc=tom@opengridcomputing.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.