Skip to contentSkip to conversation

nfs41: New xs_tcp_read_data()

RFC Labiaga, Ricardo 2 participants 3 messages Jun 5, 2009 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 1244144425.5203.83.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org

#2 lore raw
Quoted 11 lines

-----Original Message-----
From: Myklebust, Trond
Sent: Thursday, June 04, 2009 12:40 PM
To: Benny Halevy
Cc: [email protected]; [email protected]
Subject: Re: [pnfs] [RFC 09/39] nfs41: New xs_tcp_read_data()

Quoted 3 lines · Benny Halevy

From: Ricardo Labiaga <[email protected]>

Handles RPC replies and backchannel callbacks. Traditionally the

NFS

Quoted 39 lines
Quoted 4 lines

client has expected only RPC replies on its open connections. With NFSv4.1, callbacks can arrive over an existing open connection.

This patch refactors the old xs_tcp_read_request() into an RPC reply

handler:

Quoted 1 line

xs_tcp_read_reply(), a new backchannel callback handler:

xs_tcp_read_callback(),

Quoted 1 line

and a common routine to read the data off the transport:

xs_tcp_read_common().

Quoted 1 line

The new xs_tcp_read_callback() queues callback requests onto a queue

where

Quoted 1 line

the callback service (a separate thread) is listening for the

processing.

Quoted 2 lines

This patch incorporates work and suggestions from Rahul Iyer

([email protected])

Quoted 8 lines

and Benny Halevy ([email protected]).

[nfs41: Keep track of RPC call/reply direction with a flag]
[nfs41: Preallocate rpc_rqst receive buffer for handling callbacks]
---
 net/sunrpc/xprtsock.c |  141

++++++++++++++++++++++++++++++++++++++++++------

Quoted 14 lines
 1 files changed, 123 insertions(+), 18 deletions(-)
net/sunrpc/xprtsock.c +3 -0
index 692b517..403ebda 100644
@@ -34,6 +34,9 @@
 #include <linux/sunrpc/sched.h>
 #include <linux/sunrpc/xprtsock.h>
 #include <linux/file.h>
+#ifdef CONFIG_NFS_V4_1
+#include <linux/sunrpc/bc_xprt.h>
+#endif
 
Quoted 3 lines

net/sunrpc/xprtsock.c static inline void

Quoted 3 lines
net/sunrpc/xprtsock.c +0 -0
 #include <net/sock.h>
 #include <net/checksum.h>
@@ -1028,25 +1031,16 @@ static inline void

xs_tcp_read_calldir(struct

Quoted 5 lines

sock_xprt *transport,

Quoted 4 lines
net/sunrpc/xprtsock.c +0 -1
 	xs_tcp_check_fraghdr(transport);
 }
 
-static inline void xs_tcp_read_request(struct rpc_xprt *xprt,

struct

Quoted 6 lines

xdr_skb_reader *desc)

net/sunrpc/xprtsock.c static inline void · line 1033

Quoted 5 lines
net/sunrpc/xprtsock.c +3 -1
+static inline void xs_tcp_read_common(struct rpc_xprt *xprt,
+				     struct xdr_skb_reader *desc,
+				     struct rpc_rqst *req)
 {
-	struct sock_xprt *transport = container_of(xprt, struct

sock_xprt,

Quoted 4 lines

xprt);

net/sunrpc/xprtsock.c static inline void · line 1039

Quoted 3 lines
net/sunrpc/xprtsock.c +2 -1
-	struct rpc_rqst *req;
+	struct sock_xprt *transport =
+				container_of(xprt, struct sock_xprt,

xprt);

Quoted 4 lines
Quoted 4 lines
net/sunrpc/xprtsock.c +0 -0
 	struct xdr_buf *rcvbuf;
 	size_t len;
 	ssize_t r;
 
Quoted 19 lines

net/sunrpc/xprtsock.c static inline void xs_tcp_read_request(struct

Quoted 15 lines
net/sunrpc/xprtsock.c +0 -11
-	/* Find and lock the request corresponding to this xid */
-	spin_lock(&xprt->transport_lock);
-	req = xprt_lookup_rqst(xprt, transport->tcp_xid);
-	if (!req) {
-		transport->tcp_flags &= ~TCP_RCV_COPY_DATA;
-		dprintk("RPC:       XID %08x request not found!\n",
-				ntohl(transport->tcp_xid));
-		spin_unlock(&xprt->transport_lock);
-		return;
-	}
-
 	rcvbuf = &req->rq_private_buf;
 	len = desc->count;
 	if (len > transport->tcp_reclen - transport->tcp_offset) {
@@ -1084,7 +1078,7 @@ static inline void xs_tcp_read_request(struct

rpc_xprt *xprt, struct xdr_skb_rea

Quoted 3 lines
net/sunrpc/xprtsock.c +0 -0
 				"tcp_offset = %u, tcp_reclen = %u\n",
 				xprt, transport->tcp_copied,
 				transport->tcp_offset,

transport->tcp_reclen);

Quoted 6 lines

net/sunrpc/xprtsock.c static inline void

Quoted 6 lines
net/sunrpc/xprtsock.c +1 -1
-		goto out;
+		return;
 	}
 
 	dprintk("RPC:       XID %08x read %Zd bytes\n",
@@ -1100,11 +1094,122 @@ static inline void

xs_tcp_read_request(struct

Quoted 11 lines

rpc_xprt *xprt, struct xdr_skb_rea

net/sunrpc/xprtsock.c static inline void · line 1101

Quoted 9 lines
net/sunrpc/xprtsock.c +5 -1
 			transport->tcp_flags &= ~TCP_RCV_COPY_DATA;
 	}
 
-out:
+	return;
+}
+
+/*
+ * Finds the request corresponding to the RPC xid and invokes the

common

Quoted 7 lines

net/sunrpc/xprtsock.c static inline void · line 1108

Quoted 7 lines
net/sunrpc/xprtsock.c +7 -0
+ * tcp read code to read the data.
+ */
+static inline int xs_tcp_read_reply(struct rpc_xprt *xprt,
+				    struct xdr_skb_reader *desc)
+{
+	struct sock_xprt *transport =
+				container_of(xprt, struct sock_xprt,

xprt);

Quoted 22 lines
Quoted 22 lines
net/sunrpc/xprtsock.c +17 -1
+	struct rpc_rqst *req;
+
+	dprintk("RPC:       read reply XID %08x\n", ntohl(transport-
 tcp_xid));
+
+	/* Find and lock the request corresponding to this xid */
+	spin_lock(&xprt->transport_lock);
+	req = xprt_lookup_rqst(xprt, transport->tcp_xid);
+	if (!req) {
+		dprintk("RPC:       XID %08x request not found!\n",
+				ntohl(transport->tcp_xid));
+		spin_unlock(&xprt->transport_lock);
+		return -1;
+	}
+
+	xs_tcp_read_common(xprt, desc, req);
+
 	if (!(transport->tcp_flags & TCP_RCV_COPY_DATA))
 		xprt_complete_rqst(req->rq_task, transport->tcp_copied);
+
 	spin_unlock(&xprt->transport_lock);
-	xs_tcp_check_fraghdr(transport);
Quoted 10 lines

net/sunrpc/xprtsock.c static inline void · line 1136

Quoted 7 lines
net/sunrpc/xprtsock.c +7 -0
+	return 0;
+}
+
+#if defined(CONFIG_NFS_V4_1)
+/*
+ * Obtains an rpc_rqst previously allocated and invokes the common
+ * tcp read code to read the data.  The result is placed in the

callback

Quoted 2 lines
net/sunrpc/xprtsock.c +2 -0
+ * queue.
+ * If we're unable to obtain the rpc_rqst we schedule the closing

of

Quoted 8 lines

the

net/sunrpc/xprtsock.c static inline void · line 1145

Quoted 7 lines
net/sunrpc/xprtsock.c +7 -0
+ * connection and return -1.
+ */
+static inline int xs_tcp_read_callback(struct rpc_xprt *xprt,
+				       struct xdr_skb_reader *desc)
+{
+	struct sock_xprt *transport =
+				container_of(xprt, struct sock_xprt,

xprt);

Quoted 11 lines

net/sunrpc/xprtsock.c static inline void · line 1156

Quoted 11 lines
net/sunrpc/xprtsock.c +11 -0
+	struct rpc_rqst *req;
+
+	req = xprt_alloc_bc_request(xprt);
+	if (req == NULL) {
+		/*
+		 * Schedule an autoclose RPC call
+		 */
+		printk(KERN_WARNING "Callback slot table overflowed\n");
+		set_bit(XPRT_CLOSE_WAIT, &xprt->state);
+		if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
+			queue_work(rpciod_workqueue,

&xprt->task_cleanup);

Quoted 5 lines

net/sunrpc/xprtsock.c static inline void · line 1161

Quoted 5 lines
net/sunrpc/xprtsock.c +5 -0
+		return -1;
+	}
+
+	req->rq_xid = transport->tcp_xid;
+	dprintk("RPC:       read callback  XID %08x\n",

ntohl(req->rq_xid));

Quoted 18 lines
Quoted 18 lines
net/sunrpc/xprtsock.c +18 -0
+	xs_tcp_read_common(xprt, desc, req);
+
+	if (!(transport->tcp_flags & TCP_RCV_COPY_DATA)) {
+		struct svc_serv *bc_serv = xprt->bc_serv;
+
+		/*
+		 * Add callback request to callback list.  The callback
+		 * service sleeps on the sv_cb_waitq waiting for new
+		 * requests.  Wake it up after adding enqueing the
+		 * request.
+		 */
+		dprintk("RPC:       add callback request to list\n");
+		spin_lock(&bc_serv->sv_cb_lock);
+		list_add(&req->rq_bc_list, &bc_serv->sv_cb_list);
+		spin_unlock(&bc_serv->sv_cb_lock);
+		wake_up(&bc_serv->sv_cb_waitq);
+	}
+
Quoted 8 lines

net/sunrpc/xprtsock.c static inline void · line 1187

Quoted 8 lines
net/sunrpc/xprtsock.c +8 -0
+	req->rq_private_buf.len = transport->tcp_copied;
+
+	return 0;
+}
+#endif /* CONFIG_NFS_V4_1 */
+
+/*
+ * Read data off the transport.  This can be either an RPC_CALL or

an

Quoted 7 lines

net/sunrpc/xprtsock.c static inline void · line 1194

Quoted 7 lines
net/sunrpc/xprtsock.c +7 -0
+ * RPC_REPLY.  Relay the processing to helper functions.
+ */
+static void xs_tcp_read_data(struct rpc_xprt *xprt,
+				    struct xdr_skb_reader *desc)
+{
+	struct sock_xprt *transport =
+				container_of(xprt, struct sock_xprt,

xprt);

Quoted 12 lines

net/sunrpc/xprtsock.c static inline void · line 1203

Quoted 9 lines
net/sunrpc/xprtsock.c +9 -0
+	int status;
+
+#if defined(CONFIG_NFS_V4_1)
+	status = (transport->tcp_flags & TCP_RPC_REPLY) ?
+		xs_tcp_read_reply(xprt, desc) :
+		xs_tcp_read_callback(xprt, desc);
+#else
+	status = xs_tcp_read_reply(xprt, desc);
+#endif /* CONFIG_NFS_V4_1 */

Ugh... Please don't embed ifdefs in functions like this...

OK, so is it okay to use the CONF_NFS_V4_1 code and remove the ifdefs?

- ricardo

Quoted 36 lines
Quoted 12 lines
net/sunrpc/xprtsock.c +10 -0
+
+	if (status == 0)
+		xs_tcp_check_fraghdr(transport);
+	else {
+		/*
+		 * The transport_lock protects the request handling.
+		 * There's no need to hold it to update the tcp_flags.
+		 */
+		transport->tcp_flags &= ~TCP_RCV_COPY_DATA;
+	}
 }
 
Quoted 1 line

static inline void xs_tcp_read_discard(struct sock_xprt *transport,

struct xdr_skb_reader *desc)

net/sunrpc/xprtsock.c static int xs_tcp_data_recv(read_descriptor_t

Quoted 1 line
net/sunrpc/xprtsock.c +0 -0
@@ -1151,7 +1256,7 @@ static int xs_tcp_data_recv(read_descriptor_t

*rd_desc, struct sk_buff *skb, uns

net/sunrpc/xprtsock.c static int xs_tcp_data_recv(read_descriptor_t · line 1262

Quoted 8 lines
net/sunrpc/xprtsock.c +1 -1
 		}
 		/* Read in the request data */
 		if (transport->tcp_flags & TCP_RCV_COPY_DATA) {
-			xs_tcp_read_request(xprt, &desc);
+			xs_tcp_read_data(xprt, &desc);
 			continue;
 		}
 		/* Skip over any trailing bytes on short reads */

--
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com
_______________________________________________
pNFS mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/pnfs

A message that is not in the archive (sent off-list or not yet received): 273FE88A07F5D445824060902F7003440612B810-hX7t0kiaRRpT+ZUat5FNkAK/[email protected]

#4 lore raw
Quoted 231 lines · Ricardo
Quoted 11 lines

-----Original Message-----
From: Myklebust, Trond
Sent: Thursday, June 04, 2009 12:40 PM
To: Benny Halevy
Cc: [email protected]; [email protected]
Subject: Re: [pnfs] [RFC 09/39] nfs41: New xs_tcp_read_data()

Quoted 3 lines · Benny Halevy

From: Ricardo Labiaga <[email protected]>

Handles RPC replies and backchannel callbacks. Traditionally the

NFS

Quoted 39 lines
Quoted 4 lines

client has expected only RPC replies on its open connections. With NFSv4.1, callbacks can arrive over an existing open connection.

This patch refactors the old xs_tcp_read_request() into an RPC reply

handler:

Quoted 1 line

xs_tcp_read_reply(), a new backchannel callback handler:

xs_tcp_read_callback(),

Quoted 1 line

and a common routine to read the data off the transport:

xs_tcp_read_common().

Quoted 1 line

The new xs_tcp_read_callback() queues callback requests onto a queue

where

Quoted 1 line

the callback service (a separate thread) is listening for the

processing.

Quoted 2 lines

This patch incorporates work and suggestions from Rahul Iyer

([email protected])

Quoted 8 lines

and Benny Halevy ([email protected]).

[nfs41: Keep track of RPC call/reply direction with a flag]
[nfs41: Preallocate rpc_rqst receive buffer for handling callbacks]
---
 net/sunrpc/xprtsock.c |  141

++++++++++++++++++++++++++++++++++++++++++------

Quoted 14 lines
 1 files changed, 123 insertions(+), 18 deletions(-)
net/sunrpc/xprtsock.c +3 -0
index 692b517..403ebda 100644
@@ -34,6 +34,9 @@
 #include <linux/sunrpc/sched.h>
 #include <linux/sunrpc/xprtsock.h>
 #include <linux/file.h>
+#ifdef CONFIG_NFS_V4_1
+#include <linux/sunrpc/bc_xprt.h>
+#endif
 
Quoted 3 lines

net/sunrpc/xprtsock.c static inline void

Quoted 3 lines
net/sunrpc/xprtsock.c +0 -0
 #include <net/sock.h>
 #include <net/checksum.h>
@@ -1028,25 +1031,16 @@ static inline void

xs_tcp_read_calldir(struct

Quoted 5 lines

sock_xprt *transport,

Quoted 4 lines
net/sunrpc/xprtsock.c +0 -1
 	xs_tcp_check_fraghdr(transport);
 }
 
-static inline void xs_tcp_read_request(struct rpc_xprt *xprt,

struct

Quoted 6 lines

xdr_skb_reader *desc)

net/sunrpc/xprtsock.c static inline void · line 1033

Quoted 5 lines
net/sunrpc/xprtsock.c +3 -1
+static inline void xs_tcp_read_common(struct rpc_xprt *xprt,
+				     struct xdr_skb_reader *desc,
+				     struct rpc_rqst *req)
 {
-	struct sock_xprt *transport = container_of(xprt, struct

sock_xprt,

Quoted 4 lines

xprt);

net/sunrpc/xprtsock.c static inline void · line 1039

Quoted 3 lines
net/sunrpc/xprtsock.c +2 -1
-	struct rpc_rqst *req;
+	struct sock_xprt *transport =
+				container_of(xprt, struct sock_xprt,

xprt);

Quoted 4 lines
Quoted 4 lines
net/sunrpc/xprtsock.c +0 -0
 	struct xdr_buf *rcvbuf;
 	size_t len;
 	ssize_t r;
 
Quoted 19 lines

net/sunrpc/xprtsock.c static inline void xs_tcp_read_request(struct

Quoted 15 lines
net/sunrpc/xprtsock.c +0 -11
-	/* Find and lock the request corresponding to this xid */
-	spin_lock(&xprt->transport_lock);
-	req = xprt_lookup_rqst(xprt, transport->tcp_xid);
-	if (!req) {
-		transport->tcp_flags &= ~TCP_RCV_COPY_DATA;
-		dprintk("RPC:       XID %08x request not found!\n",
-				ntohl(transport->tcp_xid));
-		spin_unlock(&xprt->transport_lock);
-		return;
-	}
-
 	rcvbuf = &req->rq_private_buf;
 	len = desc->count;
 	if (len > transport->tcp_reclen - transport->tcp_offset) {
@@ -1084,7 +1078,7 @@ static inline void xs_tcp_read_request(struct

rpc_xprt *xprt, struct xdr_skb_rea

Quoted 3 lines
net/sunrpc/xprtsock.c +0 -0
 				"tcp_offset = %u, tcp_reclen = %u\n",
 				xprt, transport->tcp_copied,
 				transport->tcp_offset,

transport->tcp_reclen);

Quoted 6 lines

net/sunrpc/xprtsock.c static inline void

Quoted 6 lines
net/sunrpc/xprtsock.c +1 -1
-		goto out;
+		return;
 	}
 
 	dprintk("RPC:       XID %08x read %Zd bytes\n",
@@ -1100,11 +1094,122 @@ static inline void

xs_tcp_read_request(struct

Quoted 11 lines

rpc_xprt *xprt, struct xdr_skb_rea

net/sunrpc/xprtsock.c static inline void · line 1101

Quoted 9 lines
net/sunrpc/xprtsock.c +5 -1
 			transport->tcp_flags &= ~TCP_RCV_COPY_DATA;
 	}
 
-out:
+	return;
+}
+
+/*
+ * Finds the request corresponding to the RPC xid and invokes the

common

Quoted 7 lines

net/sunrpc/xprtsock.c static inline void · line 1108

Quoted 7 lines
net/sunrpc/xprtsock.c +7 -0
+ * tcp read code to read the data.
+ */
+static inline int xs_tcp_read_reply(struct rpc_xprt *xprt,
+				    struct xdr_skb_reader *desc)
+{
+	struct sock_xprt *transport =
+				container_of(xprt, struct sock_xprt,

xprt);

Quoted 22 lines
Quoted 22 lines
net/sunrpc/xprtsock.c +17 -1
+	struct rpc_rqst *req;
+
+	dprintk("RPC:       read reply XID %08x\n", ntohl(transport-
 tcp_xid));
+
+	/* Find and lock the request corresponding to this xid */
+	spin_lock(&xprt->transport_lock);
+	req = xprt_lookup_rqst(xprt, transport->tcp_xid);
+	if (!req) {
+		dprintk("RPC:       XID %08x request not found!\n",
+				ntohl(transport->tcp_xid));
+		spin_unlock(&xprt->transport_lock);
+		return -1;
+	}
+
+	xs_tcp_read_common(xprt, desc, req);
+
 	if (!(transport->tcp_flags & TCP_RCV_COPY_DATA))
 		xprt_complete_rqst(req->rq_task, transport->tcp_copied);
+
 	spin_unlock(&xprt->transport_lock);
-	xs_tcp_check_fraghdr(transport);
Quoted 10 lines

net/sunrpc/xprtsock.c static inline void · line 1136

Quoted 7 lines
net/sunrpc/xprtsock.c +7 -0
+	return 0;
+}
+
+#if defined(CONFIG_NFS_V4_1)
+/*
+ * Obtains an rpc_rqst previously allocated and invokes the common
+ * tcp read code to read the data.  The result is placed in the

callback

Quoted 2 lines
net/sunrpc/xprtsock.c +2 -0
+ * queue.
+ * If we're unable to obtain the rpc_rqst we schedule the closing

of

Quoted 8 lines

the

net/sunrpc/xprtsock.c static inline void · line 1145

Quoted 7 lines
net/sunrpc/xprtsock.c +7 -0
+ * connection and return -1.
+ */
+static inline int xs_tcp_read_callback(struct rpc_xprt *xprt,
+				       struct xdr_skb_reader *desc)
+{
+	struct sock_xprt *transport =
+				container_of(xprt, struct sock_xprt,

xprt);

Quoted 11 lines

net/sunrpc/xprtsock.c static inline void · line 1156

Quoted 11 lines
net/sunrpc/xprtsock.c +11 -0
+	struct rpc_rqst *req;
+
+	req = xprt_alloc_bc_request(xprt);
+	if (req == NULL) {
+		/*
+		 * Schedule an autoclose RPC call
+		 */
+		printk(KERN_WARNING "Callback slot table overflowed\n");
+		set_bit(XPRT_CLOSE_WAIT, &xprt->state);
+		if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
+			queue_work(rpciod_workqueue,

&xprt->task_cleanup);

Quoted 5 lines

net/sunrpc/xprtsock.c static inline void · line 1161

Quoted 5 lines
net/sunrpc/xprtsock.c +5 -0
+		return -1;
+	}
+
+	req->rq_xid = transport->tcp_xid;
+	dprintk("RPC:       read callback  XID %08x\n",

ntohl(req->rq_xid));

Quoted 18 lines
Quoted 18 lines
net/sunrpc/xprtsock.c +18 -0
+	xs_tcp_read_common(xprt, desc, req);
+
+	if (!(transport->tcp_flags & TCP_RCV_COPY_DATA)) {
+		struct svc_serv *bc_serv = xprt->bc_serv;
+
+		/*
+		 * Add callback request to callback list.  The callback
+		 * service sleeps on the sv_cb_waitq waiting for new
+		 * requests.  Wake it up after adding enqueing the
+		 * request.
+		 */
+		dprintk("RPC:       add callback request to list\n");
+		spin_lock(&bc_serv->sv_cb_lock);
+		list_add(&req->rq_bc_list, &bc_serv->sv_cb_list);
+		spin_unlock(&bc_serv->sv_cb_lock);
+		wake_up(&bc_serv->sv_cb_waitq);
+	}
+
Quoted 8 lines

net/sunrpc/xprtsock.c static inline void · line 1187

Quoted 8 lines
net/sunrpc/xprtsock.c +8 -0
+	req->rq_private_buf.len = transport->tcp_copied;
+
+	return 0;
+}
+#endif /* CONFIG_NFS_V4_1 */
+
+/*
+ * Read data off the transport.  This can be either an RPC_CALL or

an

Quoted 7 lines

net/sunrpc/xprtsock.c static inline void · line 1194

Quoted 7 lines
net/sunrpc/xprtsock.c +7 -0
+ * RPC_REPLY.  Relay the processing to helper functions.
+ */
+static void xs_tcp_read_data(struct rpc_xprt *xprt,
+				    struct xdr_skb_reader *desc)
+{
+	struct sock_xprt *transport =
+				container_of(xprt, struct sock_xprt,

xprt);

Quoted 12 lines

net/sunrpc/xprtsock.c static inline void · line 1203

Quoted 9 lines
net/sunrpc/xprtsock.c +9 -0
+	int status;
+
+#if defined(CONFIG_NFS_V4_1)
+	status = (transport->tcp_flags & TCP_RPC_REPLY) ?
+		xs_tcp_read_reply(xprt, desc) :
+		xs_tcp_read_callback(xprt, desc);
+#else
+	status = xs_tcp_read_reply(xprt, desc);
+#endif /* CONFIG_NFS_V4_1 */

Ugh... Please don't embed ifdefs in functions like this...

Quoted 1 line

OK, so is it okay to use the CONF_NFS_V4_1 code and remove the ifdefs?

Just define a helper function that does one thing in the 4.1 case, and calls xs_tcp_read_reply() in the default case.

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com

A message that is not in the archive (sent off-list or not yet received): 1244220975.5410.47.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org

#6 lore raw
Quoted 7 lines

-----Original Message-----
From: Myklebust, Trond
Sent: Friday, June 05, 2009 9:56 AM
To: Labiaga, Ricardo
Cc: Benny Halevy; [email protected]; [email protected]
Subject: RE: [pnfs] [RFC 09/39] nfs41: New xs_tcp_read_data()

Quoted 12 lines
Quoted 11 lines · Ricardo
Quoted 11 lines

-----Original Message-----
From: Myklebust, Trond
Sent: Thursday, June 04, 2009 12:40 PM
To: Benny Halevy
Cc: [email protected]; [email protected]
Subject: Re: [pnfs] [RFC 09/39] nfs41: New xs_tcp_read_data()

Quoted 3 lines · Benny Halevy

From: Ricardo Labiaga <[email protected]>

Handles RPC replies and backchannel callbacks. Traditionally

the

Quoted 2 lines
Quoted 2 lines

NFS

Quoted 1 line
Quoted 1 line

client has expected only RPC replies on its open connections.

With

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

NFSv4.1, callbacks can arrive over an existing open connection.

This patch refactors the old xs_tcp_read_request() into an RPC

reply

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

handler:

Quoted 1 line

xs_tcp_read_reply(), a new backchannel callback handler:

xs_tcp_read_callback(),

Quoted 1 line

and a common routine to read the data off the transport:

xs_tcp_read_common().

Quoted 1 line

The new xs_tcp_read_callback() queues callback requests onto a

queue

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

where

Quoted 1 line

the callback service (a separate thread) is listening for the

processing.

Quoted 2 lines

This patch incorporates work and suggestions from Rahul Iyer

([email protected])

Quoted 4 lines

and Benny Halevy ([email protected]).

[nfs41: Keep track of RPC call/reply direction with a flag] [nfs41: Preallocate rpc_rqst receive buffer for handling

callbacks]

Quoted 24 lines
Quoted 24 lines
Quoted 19 lines
Quoted 4 lines
---
 net/sunrpc/xprtsock.c |  141

++++++++++++++++++++++++++++++++++++++++++------

Quoted 14 lines
 1 files changed, 123 insertions(+), 18 deletions(-)
net/sunrpc/xprtsock.c +3 -0
index 692b517..403ebda 100644
@@ -34,6 +34,9 @@
 #include <linux/sunrpc/sched.h>
 #include <linux/sunrpc/xprtsock.h>
 #include <linux/file.h>
+#ifdef CONFIG_NFS_V4_1
+#include <linux/sunrpc/bc_xprt.h>
+#endif
 
Quoted 3 lines

net/sunrpc/xprtsock.c static inline void

Quoted 3 lines
net/sunrpc/xprtsock.c +0 -0
 #include <net/sock.h>
 #include <net/checksum.h>
@@ -1028,25 +1031,16 @@ static inline void

xs_tcp_read_calldir(struct

Quoted 1 line

sock_xprt *transport,

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

net/sunrpc/xprtsock.c static inline void · line 1031

Quoted 4 lines
net/sunrpc/xprtsock.c +0 -1
 	xs_tcp_check_fraghdr(transport);
 }
 
-static inline void xs_tcp_read_request(struct rpc_xprt *xprt,

struct

Quoted 3 lines

xdr_skb_reader *desc)

net/sunrpc/xprtsock.c static inline void · line 1035

Quoted 2 lines
net/sunrpc/xprtsock.c +2 -0
+static inline void xs_tcp_read_common(struct rpc_xprt *xprt,
+				     struct xdr_skb_reader

*desc,

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

net/sunrpc/xprtsock.c static inline void · line 1033

Quoted 3 lines
net/sunrpc/xprtsock.c +1 -1
+				     struct rpc_rqst *req)
 {
-	struct sock_xprt *transport = container_of(xprt, struct

sock_xprt,

Quoted 4 lines

xprt);

net/sunrpc/xprtsock.c static inline void · line 1039

Quoted 3 lines
net/sunrpc/xprtsock.c +2 -1
-	struct rpc_rqst *req;
+	struct sock_xprt *transport =
+				container_of(xprt, struct

sock_xprt,

Quoted 6 lines
Quoted 6 lines

xprt);

Quoted 5 lines

net/sunrpc/xprtsock.c static inline void · line 1039

Quoted 5 lines
net/sunrpc/xprtsock.c +0 -1
 	struct xdr_buf *rcvbuf;
 	size_t len;
 	ssize_t r;
 
-	/* Find and lock the request corresponding to this xid

*/

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

net/sunrpc/xprtsock.c static inline void · line 1044

Quoted 5 lines
net/sunrpc/xprtsock.c +0 -5
-	spin_lock(&xprt->transport_lock);
-	req = xprt_lookup_rqst(xprt, transport->tcp_xid);
-	if (!req) {
-		transport->tcp_flags &= ~TCP_RCV_COPY_DATA;
-		dprintk("RPC:       XID %08x request not

found!\n",

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

net/sunrpc/xprtsock.c static inline void · line 1046

Quoted 8 lines
net/sunrpc/xprtsock.c +0 -5
-				ntohl(transport->tcp_xid));
-		spin_unlock(&xprt->transport_lock);
-		return;
-	}
-
 	rcvbuf = &req->rq_private_buf;
 	len = desc->count;
 	if (len > transport->tcp_reclen - transport->tcp_offset)

{

Quoted 1 line
Quoted 1 line
Quoted 1 line

net/sunrpc/xprtsock.c static inline void

Quoted 1 line
net/sunrpc/xprtsock.c +0 -0
@@ -1084,7 +1078,7 @@ static inline void

xs_tcp_read_request(struct

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

rpc_xprt *xprt, struct xdr_skb_rea

Quoted 1 line
net/sunrpc/xprtsock.c +0 -0
 				"tcp_offset = %u, tcp_reclen =

%u\n",

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

net/sunrpc/xprtsock.c static inline void · line 1080

Quoted 2 lines
net/sunrpc/xprtsock.c +0 -0
 				xprt, transport->tcp_copied,
 				transport->tcp_offset,

transport->tcp_reclen);

Quoted 4 lines
Quoted 4 lines
net/sunrpc/xprtsock.c +1 -1
-		goto out;
+		return;
 	}
 
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

net/sunrpc/xprtsock.c static inline void

Quoted 2 lines
net/sunrpc/xprtsock.c +0 -0
 	dprintk("RPC:       XID %08x read %Zd bytes\n",
@@ -1100,11 +1094,122 @@ static inline void

xs_tcp_read_request(struct

Quoted 2 lines

rpc_xprt *xprt, struct xdr_skb_rea

Quoted 1 line
net/sunrpc/xprtsock.c +0 -0
 			transport->tcp_flags &=

~TCP_RCV_COPY_DATA;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

net/sunrpc/xprtsock.c static inline void · line 1101

Quoted 8 lines
net/sunrpc/xprtsock.c +5 -1
 	}
 
-out:
+	return;
+}
+
+/*
+ * Finds the request corresponding to the RPC xid and invokes

the

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

common

net/sunrpc/xprtsock.c static inline void · line 1108

Quoted 7 lines
net/sunrpc/xprtsock.c +7 -0
+ * tcp read code to read the data.
+ */
+static inline int xs_tcp_read_reply(struct rpc_xprt *xprt,
+				    struct xdr_skb_reader *desc)
+{
+	struct sock_xprt *transport =
+				container_of(xprt, struct

sock_xprt,

Quoted 4 lines
Quoted 4 lines

xprt);

Quoted 3 lines

net/sunrpc/xprtsock.c static inline void · line 1111

Quoted 3 lines
net/sunrpc/xprtsock.c +3 -0
+	struct rpc_rqst *req;
+
+	dprintk("RPC:       read reply XID %08x\n",

ntohl(transport-

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

net/sunrpc/xprtsock.c static inline void · line 1114

Quoted 3 lines
net/sunrpc/xprtsock.c +2 -0
 tcp_xid));
+
+	/* Find and lock the request corresponding to this xid

*/

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

net/sunrpc/xprtsock.c static inline void · line 1118

Quoted 4 lines
net/sunrpc/xprtsock.c +4 -0
+	spin_lock(&xprt->transport_lock);
+	req = xprt_lookup_rqst(xprt, transport->tcp_xid);
+	if (!req) {
+		dprintk("RPC:       XID %08x request not

found!\n",

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

net/sunrpc/xprtsock.c static inline void · line 1127

Quoted 9 lines
net/sunrpc/xprtsock.c +7 -0
+				ntohl(transport->tcp_xid));
+		spin_unlock(&xprt->transport_lock);
+		return -1;
+	}
+
+	xs_tcp_read_common(xprt, desc, req);
+
 	if (!(transport->tcp_flags & TCP_RCV_COPY_DATA))
 		xprt_complete_rqst(req->rq_task,

transport->tcp_copied);

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

net/sunrpc/xprtsock.c static inline void · line 1135

Quoted 9 lines
net/sunrpc/xprtsock.c +7 -1
+
 	spin_unlock(&xprt->transport_lock);
-	xs_tcp_check_fraghdr(transport);
+	return 0;
+}
+
+#if defined(CONFIG_NFS_V4_1)
+/*
+ * Obtains an rpc_rqst previously allocated and invokes the

common

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

net/sunrpc/xprtsock.c static inline void · line 1136

Quoted 1 line
net/sunrpc/xprtsock.c +1 -0
+ * tcp read code to read the data.  The result is placed in the

callback

Quoted 2 lines
net/sunrpc/xprtsock.c +2 -0
+ * queue.
+ * If we're unable to obtain the rpc_rqst we schedule the

closing

Quoted 6 lines
Quoted 6 lines

of

Quoted 5 lines

the

net/sunrpc/xprtsock.c static inline void · line 1142

Quoted 4 lines
net/sunrpc/xprtsock.c +4 -0
+ * connection and return -1.
+ */
+static inline int xs_tcp_read_callback(struct rpc_xprt *xprt,
+				       struct xdr_skb_reader

*desc)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

net/sunrpc/xprtsock.c static inline void · line 1145

Quoted 3 lines
net/sunrpc/xprtsock.c +3 -0
+{
+	struct sock_xprt *transport =
+				container_of(xprt, struct

sock_xprt,

Quoted 9 lines
Quoted 9 lines

xprt);

Quoted 8 lines

net/sunrpc/xprtsock.c static inline void · line 1153

Quoted 8 lines
net/sunrpc/xprtsock.c +8 -0
+	struct rpc_rqst *req;
+
+	req = xprt_alloc_bc_request(xprt);
+	if (req == NULL) {
+		/*
+		 * Schedule an autoclose RPC call
+		 */
+		printk(KERN_WARNING "Callback slot table

overflowed\n");

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

net/sunrpc/xprtsock.c static inline void · line 1155

Quoted 2 lines
net/sunrpc/xprtsock.c +2 -0
+		set_bit(XPRT_CLOSE_WAIT, &xprt->state);
+		if (test_and_set_bit(XPRT_LOCKED, &xprt->state)

== 0)

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

net/sunrpc/xprtsock.c static inline void · line 1156

Quoted 1 line
net/sunrpc/xprtsock.c +1 -0
+			queue_work(rpciod_workqueue,

&xprt->task_cleanup);

Quoted 5 lines

net/sunrpc/xprtsock.c static inline void · line 1161

Quoted 5 lines
net/sunrpc/xprtsock.c +5 -0
+		return -1;
+	}
+
+	req->rq_xid = transport->tcp_xid;
+	dprintk("RPC:       read callback  XID %08x\n",

ntohl(req->rq_xid));

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

net/sunrpc/xprtsock.c static inline void · line 1168

Quoted 7 lines
net/sunrpc/xprtsock.c +7 -0
+	xs_tcp_read_common(xprt, desc, req);
+
+	if (!(transport->tcp_flags & TCP_RCV_COPY_DATA)) {
+		struct svc_serv *bc_serv = xprt->bc_serv;
+
+		/*
+		 * Add callback request to callback list.  The

callback

Quoted 1 line
Quoted 1 line
Quoted 1 line

net/sunrpc/xprtsock.c static inline void · line 1169

Quoted 1 line
net/sunrpc/xprtsock.c +1 -0
+		 * service sleeps on the sv_cb_waitq waiting for

new

Quoted 1 line
Quoted 1 line
Quoted 1 line

net/sunrpc/xprtsock.c static inline void · line 1170

Quoted 1 line
net/sunrpc/xprtsock.c +1 -0
+		 * requests.  Wake it up after adding enqueing

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

net/sunrpc/xprtsock.c static inline void · line 1173

Quoted 3 lines
net/sunrpc/xprtsock.c +3 -0
+		 * request.
+		 */
+		dprintk("RPC:       add callback request to

list\n");

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

net/sunrpc/xprtsock.c static inline void · line 1175

Quoted 2 lines
net/sunrpc/xprtsock.c +2 -0
+		spin_lock(&bc_serv->sv_cb_lock);
+		list_add(&req->rq_bc_list,

&bc_serv->sv_cb_list);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
net/sunrpc/xprtsock.c +4 -0
+		spin_unlock(&bc_serv->sv_cb_lock);
+		wake_up(&bc_serv->sv_cb_waitq);
+	}
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

net/sunrpc/xprtsock.c static inline void · line 1187

Quoted 8 lines
net/sunrpc/xprtsock.c +8 -0
+	req->rq_private_buf.len = transport->tcp_copied;
+
+	return 0;
+}
+#endif /* CONFIG_NFS_V4_1 */
+
+/*
+ * Read data off the transport.  This can be either an RPC_CALL

or

Quoted 8 lines
Quoted 8 lines

an

Quoted 7 lines

net/sunrpc/xprtsock.c static inline void · line 1194

Quoted 7 lines
net/sunrpc/xprtsock.c +7 -0
+ * RPC_REPLY.  Relay the processing to helper functions.
+ */
+static void xs_tcp_read_data(struct rpc_xprt *xprt,
+				    struct xdr_skb_reader *desc)
+{
+	struct sock_xprt *transport =
+				container_of(xprt, struct

sock_xprt,

Quoted 14 lines
Quoted 14 lines

xprt);

Quoted 12 lines

net/sunrpc/xprtsock.c static inline void · line 1203

Quoted 9 lines
net/sunrpc/xprtsock.c +9 -0
+	int status;
+
+#if defined(CONFIG_NFS_V4_1)
+	status = (transport->tcp_flags & TCP_RPC_REPLY) ?
+		xs_tcp_read_reply(xprt, desc) :
+		xs_tcp_read_callback(xprt, desc);
+#else
+	status = xs_tcp_read_reply(xprt, desc);
+#endif /* CONFIG_NFS_V4_1 */

Ugh... Please don't embed ifdefs in functions like this...

Quoted 1 line
Quoted 1 line

OK, so is it okay to use the CONF_NFS_V4_1 code and remove the

ifdefs?

Quoted 4 lines

Just define a helper function that does one thing in the 4.1 case, and calls xs_tcp_read_reply() in the default case.

OK. Although I'm reworking this slightly to keep the RPC direction in the XDR buffer - as a result of feedback to a different patch.

- ricardo

Quoted 7 lines

--
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com