EXPERIMENTAL: soft connect semantics for rpcbind
Subsystems (3)
cover EXPERIMENTAL: soft connect semantics for rpcbind
These need further refinement, but I'm posting now to spark some discussion.
To address manifold reports of svc_unregister() hanging (either at shutdown or if rpcbind simply wasn't ever started), these patches add a new per-request soft connect semantic, and update the kernel's rpcbind client to use a connection-oriented transport for local queries. This should cause the kernel's local rpcbind queries to fail immediately if rpcbind isn't reachable.
This can work with either TCP or connected UDP. I used TCP here merely as an example.
The final two patches have not been tested, but provide a taste of other uses for the soft connect semantic. One possible use is to address Ian's NFSv4 mount hang problems by making rpc_ping() fail if it cannot connect to the server.
We can also make use of this new feature to do proper "hangless" NFS v2/v3 version and transport negotiation in the kernel, although that is beyond the scope of the current patch set.
---
Chuck Lever (7):
SUNRPC: Use soft connect semantics when performing RPC ping
SUNRPC: Use soft connects for autobinding over TCP
SUNRPC: Use TCP for local rpcbind upcalls
SUNRPC: maintain a single transport for rpcbind upcalls
SUNRPC: Clean up call_transmit_status()
SUNRPC: Allow RPCs to fail quickly if the server is unreachable
SUNRPC: Don't report a connect delay of 0 seconds
include/linux/sunrpc/sched.h | 2 + net/sunrpc/clnt.c | 45 ++++++++++++++++++++-------- net/sunrpc/rpcb_clnt.c | 68 ++++++++++++++++++++++++++++++++---------- net/sunrpc/sunrpc_syms.c | 5 +++ net/sunrpc/xprtsock.c | 9 +++--- 5 files changed, 96 insertions(+), 33 deletions(-)
Signature · 1 line
Chuck Lever <[email protected]>
A message that is not in the archive (sent off-list or not yet received): 20091007215019.1844.17414.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org
PATCH 1/7 SUNRPC: Don't report a connect delay of 0 seconds
Reduce debugging noise.
---
net/sunrpc/xprtsock.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
net/sunrpc/xprtsock.c +4 -3
@@ -2034,9 +2034,10 @@ static void xs_connect(struct rpc_task *task)return ;if (transport->sock !=NULL ) { -dprintk ("RPC: xs_connect delayed xprt %p for %lu " -"seconds\n" , - xprt, xprt->reestablish_timeout /HZ ); +if (xprt->reestablish_timeout !=0 ) +dprintk ("RPC: xs_connect delayed xprt %p " +"for %lu seconds\n" , + xprt, xprt->reestablish_timeout /HZ );queue_delayed_work (rpciod_workqueue, &transport->connect_worker, xprt->reestablish_timeout);
PATCH 2/7 SUNRPC: Allow RPCs to fail quickly if the server is unreachable
In reply to a message not in the archiveThe kernel sometimes makes RPC calls to services that aren't running. Because the kernel's RPC client always assumes the hard retry semantic when reconnecting a connection-oriented RPC transport, the underlying reconnect logic takes a long while to time out, even though the remote may have responded immediately with ECONNREFUSED.
In certain cases, like upcalls to our local rpcbind daemon, or for NFS mount requests, we'd like the kernel to fail immediately if the remote service isn't reachable, so that another transport can be tried or the pending request can be abandoned quickly.
Introduce a per-request flag which controls how call_transmit_status() behaves when transmitting the request fails because the server cannot be reached. The transport's connection re-establishment timeout is also ignored for such requests.
We don't want soft connection semantics to apply to other errors, nor when the RPC was successfully transmitted. The default case of the switch statement in call_transmit_status() no longer falls through; the fall through code is copied to the default case, and a "break;" is added.
---
include/linux/sunrpc/sched.h | 2 ++ net/sunrpc/clnt.c | 7 +++++++ net/sunrpc/xprtsock.c | 2 +- 3 files changed, 10 insertions(+), 1 deletions(-)
include/linux/sunrpc/sched.h +2 -0
@@ -130,12 +130,14 @@ struct rpc_task_setup {#define RPC_TASK_DYNAMIC 0x0080/* task was kmalloc'ed */ #define RPC_TASK_KILLED 0x0100/* task was killed */ #define RPC_TASK_SOFT 0x0200/* Use soft timeouts */ +#define RPC_TASK_SOFTCONN 0x0400/* Fail if can't connect */ #define RPC_IS_ASYNC (t) ((t)->tk_flags & RPC_TASK_ASYNC)#define RPC_IS_SWAPPER (t) ((t)->tk_flags & RPC_TASK_SWAPPER)#define RPC_DO_ROOTOVERRIDE (t) ((t)->tk_flags & RPC_TASK_ROOTCREDS)#define RPC_ASSASSINATED (t) ((t)->tk_flags & RPC_TASK_KILLED)#define RPC_IS_SOFT (t) ((t)->tk_flags & RPC_TASK_SOFT) +#define RPC_IS_SOFTCONN (t) ((t)->tk_flags & RPC_TASK_SOFTCONN)#define RPC_TASK_RUNNING 0#define RPC_TASK_QUEUED 1
net/sunrpc/clnt.c +7 -0
@@ -1185,6 +1185,8 @@ call_transmit_status(struct rpc_task *task)break ;default :xprt_end_transmit (task); +rpc_task_force_reencode (task); +break ;/* * Special cases: if we've been waiting on the * socket's write_space() callback, or if the
@@ -1198,6 +1200,11 @@ call_transmit_status(struct rpc_task *task)case -EHOSTUNREACH :case -ENETUNREACH :case -EPIPE : +if (RPC_IS_SOFTCONN (task)) { +xprt_end_transmit (task); +rpc_exit (task, task->tk_status); +break ; + }rpc_task_force_reencode (task); } }
net/sunrpc/xprtsock.c +1 -1
@@ -2033,7 +2033,7 @@ static void xs_connect(struct rpc_task *task)if (xprt_test_and_set_connecting (xprt))return ; -if (transport->sock !=NULL ) { +if (transport->sock !=NULL && !RPC_IS_SOFTCONN (task)) {if (xprt->reestablish_timeout !=0 ) dprintk("RPC: xs_connect delayed xprt %p " "for %lu seconds\n",
A message that is not in the archive (sent off-list or not yet received): 20091007220232.1844.62559.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org
Re: [PATCH 2/7] SUNRPC: Allow RPCs to fail quickly if the server is unreachable
Quoted 63 lines · Chuck Lever
The kernel sometimes makes RPC calls to services that aren't running. Because the kernel's RPC client always assumes the hard retry semantic when reconnecting a connection-oriented RPC transport, the underlying reconnect logic takes a long while to time out, even though the remote may have responded immediately with ECONNREFUSED.
In certain cases, like upcalls to our local rpcbind daemon, or for NFS mount requests, we'd like the kernel to fail immediately if the remote service isn't reachable, so that another transport can be tried or the pending request can be abandoned quickly.
Introduce a per-request flag which controls how
call_transmit_status()behaves when transmitting the request fails because the server cannot be reached. The transport's connection re-establishment timeout is also ignored for such requests.We don't want soft connection semantics to apply to other errors, nor when the RPC was successfully transmitted. The default case of the switch statement in
call_transmit_status()no longer falls through; the fall through code is copied to the default case, and a "break;" is added.Signed-off-by Chuck Lever <[email protected]>---
include/linux/sunrpc/sched.h | 2 ++ net/sunrpc/clnt.c | 7 +++++++ net/sunrpc/xprtsock.c | 2 +- 3 files changed, 10 insertions(+), 1 deletions(-)include/linux/sunrpc/sched.h +2
-0@@ -130,12 +130,14 @@ struct rpc_task_setup {#define RPC_TASK_DYNAMIC 0x0080/* task was kmalloc'ed */ #define RPC_TASK_KILLED 0x0100/* task was killed */ #define RPC_TASK_SOFT 0x0200/* Use soft timeouts */ +#define RPC_TASK_SOFTCONN 0x0400/* Fail if can't connect */ #define RPC_IS_ASYNC (t) ((t)->tk_flags & RPC_TASK_ASYNC)#define RPC_IS_SWAPPER (t) ((t)->tk_flags & RPC_TASK_SWAPPER)#define RPC_DO_ROOTOVERRIDE (t) ((t)->tk_flags & RPC_TASK_ROOTCREDS)#define RPC_ASSASSINATED (t) ((t)->tk_flags & RPC_TASK_KILLED)#define RPC_IS_SOFT (t) ((t)->tk_flags & RPC_TASK_SOFT) +#define RPC_IS_SOFTCONN (t) ((t)->tk_flags & RPC_TASK_SOFTCONN)#define RPC_TASK_RUNNING 0#define RPC_TASK_QUEUED 1net/sunrpc/clnt.c +2
-0@@ -1185,6 +1185,8 @@ call_transmit_status(struct rpc_task *task)break ;default :xprt_end_transmit (task); +rpc_task_force_reencode (task); +break ;/* * Special cases: if we've been waiting on the * socket's write_space() callback, or if the
net/sunrpc/clnt.c call_transmit_status(struct rpc_task *task) · line 1207
Quoted 8 lines
net/sunrpc/clnt.c +5
-0@@ -1198,6 +1200,11 @@ call_transmit_status(struct rpc_task *task)case -EHOSTUNREACH :case -ENETUNREACH :case -EPIPE : +if (RPC_IS_SOFTCONN (task)) { +xprt_end_transmit (task); +rpc_exit (task, task->tk_status); +break ; + }
This doesn't look robust. The EPIPE error may mean that the socket got closed as a result of server action, or a previous RPC call. Don't forget that we might want to reuse SOFTCONN for NFSv4.1 session binding semantics.
Quoted 21 lines
net/sunrpc/clnt.c +0
-0rpc_task_force_reencode (task); } }net/sunrpc/xprtsock.c +1
-2@@ -2033,7 +2033,7 @@ static void xs_connect(struct rpc_task *task)if (xprt_test_and_set_connecting (xprt))return ; -if (transport->sock !=NULL ) { +if (transport->sock !=NULL && !RPC_IS_SOFTCONN (task)) {if (xprt->reestablish_timeout !=0 ) dprintk("RPC: xs_connect delayed xprt %p " "for %lu seconds\n", --To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
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): 1254954039.7045.31.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org
Re: [PATCH 2/7] SUNRPC: Allow RPCs to fail quickly if the server is unreachable
Quoted 69 lines · Trond Myklebust
Quoted 68 lines · Chuck Lever
The kernel sometimes makes RPC calls to services that aren't running. Because the kernel's RPC client always assumes the hard retry semantic when reconnecting a connection-oriented RPC transport, the underlying reconnect logic takes a long while to time out, even though the remote may have responded immediately with ECONNREFUSED.
In certain cases, like upcalls to our local rpcbind daemon, or for NFS mount requests, we'd like the kernel to fail immediately if the remote service isn't reachable, so that another transport can be tried or the pending request can be abandoned quickly.
Introduce a per-request flag which controls how
call_transmit_status()behaves when transmitting the request fails because the server cannot be reached. The transport's connection re-establishment timeout is also ignored for such requests.We don't want soft connection semantics to apply to other errors, nor when the RPC was successfully transmitted. The default case of the switch statement in
call_transmit_status()no longer falls through; the fall through code is copied to the default case, and a "break;" is added.Signed-off-by Chuck Lever <[email protected]>---
include/linux/sunrpc/sched.h | 2 ++ net/sunrpc/clnt.c | 7 +++++++ net/sunrpc/xprtsock.c | 2 +- 3 files changed, 10 insertions(+), 1 deletions(-)include/linux/sunrpc/sched.h +2
-0@@ -130,12 +130,14 @@ struct rpc_task_setup {#define RPC_TASK_DYNAMIC 0x0080/* task was kmalloc'ed */ #define RPC_TASK_KILLED 0x0100/* task was killed */ #define RPC_TASK_SOFT 0x0200/* Use soft timeouts */ +#define RPC_TASK_SOFTCONN 0x0400/* Fail if can't connect */ #define RPC_IS_ASYNC (t) ((t)->tk_flags & RPC_TASK_ASYNC)#define RPC_IS_SWAPPER (t) ((t)->tk_flags & RPC_TASK_SWAPPER)#define RPC_DO_ROOTOVERRIDE (t) ((t)->tk_flags & RPC_TASK_ROOTCREDS)#define RPC_ASSASSINATED (t) ((t)->tk_flags & RPC_TASK_KILLED)#define RPC_IS_SOFT (t) ((t)->tk_flags & RPC_TASK_SOFT) +#define RPC_IS_SOFTCONN (t) ((t)->tk_flags & RPC_TASK_SOFTCONN)#define RPC_TASK_RUNNING 0#define RPC_TASK_QUEUED 1net/sunrpc/clnt.c +4
-0@@ -1185,6 +1185,8 @@ call_transmit_status(struct rpc_task *task)break ;default :xprt_end_transmit (task); +rpc_task_force_reencode (task); +break ;/* * Special cases: if we've been waiting on the * socket's write_space() callback, or if the @@ -1198,6 +1200,11 @@ call_transmit_status(struct rpc_task *task)case -EHOSTUNREACH :case -ENETUNREACH :case -EPIPE : +if (RPC_IS_SOFTCONN (task)) { +xprt_end_transmit (task);
Quoted 8 lines
net/sunrpc/clnt.c call_transmit_status(struct rpc_task *task) · line 1207
Quoted 3 lines
net/sunrpc/clnt.c +3
-0+rpc_exit (task, task->tk_status); +break ; + }This doesn't look robust. The EPIPE error may mean that the socket got closed as a result of server action, or a previous RPC call. Don't forget that we might want to reuse SOFTCONN for NFSv4.1 session binding semantics.
EPIPE can easily be handled in a separate case that doesn't have soft connect.
If you're going to bring up NFSv4.1, though, we'll need to see some use cases to understand what is needed. I assumed this type of connect behavior would be useful for single requests (like rpcbind) or for the first request sent when contacting a new service. You'll have to educate me about other potential uses.
Quoted 17 lines
Quoted 17 lines
net/sunrpc/clnt.c +0
-0rpc_task_force_reencode (task); } }net/sunrpc/xprtsock.c +1
-1@@ -2033,7 +2033,7 @@ static void xs_connect(struct rpc_task *task)if (xprt_test_and_set_connecting (xprt))return ; -if (transport->sock !=NULL ) { +if (transport->sock !=NULL && !RPC_IS_SOFTCONN (task)) {if (xprt->reestablish_timeout !=0 ) dprintk("RPC: xs_connect delayed xprt %p " "for %lu seconds\n",
Quoted 12 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmlSignature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
Re: [PATCH 2/7] SUNRPC: Allow RPCs to fail quickly if the server is unreachable
Quoted 20 lines · Chuck Lever
Quoted 10 lines · Trond Myklebust
Quoted 9 lines · Chuck Lever
* Special cases: if we've been waiting on the
* socket'swrite_space()callback, or if thenet/sunrpc/clnt.c +3
-0@@ -1198,6 +1200,11 @@ call_transmit_status(struct rpc_task *task)case -EHOSTUNREACH :case -ENETUNREACH :case -EPIPE : +if (RPC_IS_SOFTCONN (task)) { +xprt_end_transmit (task); +rpc_exit (task, task->tk_status);Quoted 8 lines
net/sunrpc/clnt.c call_transmit_status(struct rpc_task *task) · line 1207
Quoted 2 lines
net/sunrpc/clnt.c +2
-0+break ; + }This doesn't look robust. The EPIPE error may mean that the socket got closed as a result of server action, or a previous RPC call. Don't forget that we might want to reuse SOFTCONN for NFSv4.1 session binding
semantics.
Quoted 2 lines
EPIPE can easily be handled in a separate case that doesn't have soft connect.
It directly affects rpcbind when you cache the rpc client, as you do in later patches. If one RPC call fails with EPIPE, then so will all the subsequent ones...
IOW: I'd suggest moving EPIPE _below_ your above SOFTCONN special case. You might want to do the same for ENOTCONN...
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): 1254955658.7045.46.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org
Re: [PATCH 2/7] SUNRPC: Allow RPCs to fail quickly if the server is unreachable
Quoted 24 lines · Trond Myklebust
Quoted 20 lines · Chuck Lever
Quoted 10 lines · Trond Myklebust
Quoted 9 lines · Chuck Lever
* Special cases: if we've been waiting on the
* socket'swrite_space()callback, or if the(quoted diff) +3
-0@@ -1198,6 +1200,11 @@ call_transmit_status(struct rpc_task *task) case -EHOSTUNREACH: case -ENETUNREACH: case -EPIPE: + if (RPC_IS_SOFTCONN(task)) { + xprt_end_transmit(task); + rpc_exit(task, task->tk_status);Quoted 8 lines
Review call_transmit_status(struct rpc_task *task) · line 1207
Quoted 2 lines
(quoted diff) +2
-0+ break; + }This doesn't look robust. The EPIPE error may mean that the socket got closed as a result of server action, or a previous RPC call. Don't forget that we might want to reuse SOFTCONN for NFSv4.1 session binding
semantics.Quoted 2 lines
EPIPE can easily be handled in a separate case that doesn't have soft connect.
Quoted 6 lines
It directly affects rpcbind when you cache the rpc client, as you do in later patches. If one RPC call fails with EPIPE, then so will all the subsequent ones...
IOW: I'd suggest moving EPIPE _below_ your above SOFTCONN special case. You might want to do the same for ENOTCONN...
Already done. :-)
Quoted 8 lines
Signature · 7 lines
-- Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
PATCH 3/7 SUNRPC: Clean up call_transmit_status()
In reply to a message not in the archiveClean up: re-arrange the cases in call_transmit_status() to make the code easier to read.
---
net/sunrpc/clnt.c | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-)
net/sunrpc/clnt.c +12 -12
@@ -1175,25 +1175,21 @@ call_transmit(struct rpc_task *task)/* * 5a. Handle cleanup after a transmission +* If we've been waiting on the socket's write_space() +* callback, or if the server is temporarily unreachable, +* continue holding the transport lock. */ static void call_transmit_status (struct rpc_task *task) { +dprint_status (task); + task->tk_action = call_status; +switch (task->tk_status) { -case -EAGAIN : -break ; -default : -xprt_end_transmit (task); -rpc_task_force_reencode (task); +case -EAGAIN :/* no write space */ break ; -/* -* Special cases: if we've been waiting on the -* socket's write_space() callback, or if the -* socket just returned a connection error, -* then hold onto the transport lock. -*/ -case -ECONNREFUSED : +case -ECONNREFUSED :/* connection problems */ case -ECONNRESET :case -ENOTCONN :case -EHOSTDOWN :
@@ -1206,6 +1202,10 @@ call_transmit_status(struct rpc_task *task)break ; }rpc_task_force_reencode (task); +break ; +default :/* success, or some other error */ +xprt_end_transmit (task); +rpc_task_force_reencode (task); } }
A message that is not in the archive (sent off-list or not yet received): 20091007220239.1844.1995.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org
Re: [PATCH 3/7] SUNRPC: Clean up call_transmit_status()
Quoted 48 lines · Chuck Lever
Clean up: re-arrange the cases in
call_transmit_status()to make the code easier to read.Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/clnt.c | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-)net/sunrpc/clnt.c +8
-12@@ -1175,25 +1175,21 @@ call_transmit(struct rpc_task *task)/* * 5a. Handle cleanup after a transmission +* If we've been waiting on the socket's write_space() +* callback, or if the server is temporarily unreachable, +* continue holding the transport lock. */ static void call_transmit_status (struct rpc_task *task) { +dprint_status (task); + task->tk_action = call_status; +switch (task->tk_status) { -case -EAGAIN : -break ; -default : -xprt_end_transmit (task); -rpc_task_force_reencode (task); +case -EAGAIN :/* no write space */ break ; -/* -* Special cases: if we've been waiting on the -* socket's write_space() callback, or if the -* socket just returned a connection error, -* then hold onto the transport lock. -*/ -case -ECONNREFUSED : +case -ECONNREFUSED :/* connection problems */ case -ECONNRESET :case -ENOTCONN :case -EHOSTDOWN :
net/sunrpc/clnt.c call_transmit_status(struct rpc_task *task) · line 1210
Quoted 9 lines
net/sunrpc/clnt.c +4
-0@@ -1206,6 +1202,10 @@ call_transmit_status(struct rpc_task *task)break ; }rpc_task_force_reencode (task); +break ; +default :/* success, or some other error */ +xprt_end_transmit (task); +rpc_task_force_reencode (task); } }
This puts the most common case (success) at the very end of the switch statement. Most compilers will generate the most efficient code when it is at the very beginning...
Trond
A message that is not in the archive (sent off-list or not yet received): 1254954158.7045.33.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org
Re: [PATCH 3/7] SUNRPC: Clean up call_transmit_status()
Quoted 54 lines · Trond Myklebust
Quoted 53 lines · Chuck Lever
Clean up: re-arrange the cases in
call_transmit_status()to make the code easier to read.Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/clnt.c| 24 ++++++++++++------------1 files changed, 12 insertions(+), 12 deletions(-)net/sunrpc/clnt.c +3
-0@@ -1175,25 +1175,21 @@ call_transmit(struct rpc_task *task)/* * 5a. Handle cleanup after a transmission +* If we've been waiting on the socket's write_space() +* callback, or if the server is temporarily unreachable, +* continue holding the transport lock. */ static void
call_transmit_status(struct rpc_task *task)
{net/sunrpc/clnt.c +2
-0+dprint_status (task); +task->tk_action = call_status; + switch (task->tk_status) {net/sunrpc/clnt.c +1
-5-case -EAGAIN : -break ; -default : -xprt_end_transmit (task); -rpc_task_force_reencode (task); +case -EAGAIN :/* no write space */ break;net/sunrpc/clnt.c +1
-7-/* -* Special cases: if we've been waiting on the -* socket's write_space() callback, or if the -* socket just returned a connection error, -* then hold onto the transport lock. -*/ -case -ECONNREFUSED : +case -ECONNREFUSED :/* connection problems */ case
-ECONNRESET:
case-ENOTCONN:
case-EHOSTDOWN:net/sunrpc/clnt.c +2
-0@@ -1206,6 +1202,10 @@ call_transmit_status(struct rpc_task *task)break ; }rpc_task_force_reencode (task); +break ; +default :/* success, or some other error */
Quoted 8 lines
net/sunrpc/clnt.c call_transmit_status(struct rpc_task *task) · line 1210
Quoted 4 lines
net/sunrpc/clnt.c +2
-0+xprt_end_transmit (task); +rpc_task_force_reencode (task); } }This puts the most common case (success) at the very end of the switch statement. Most compilers will generate the most efficient code when it is at the very beginning...
I dropped this one, since it's not that important.
But I wouldn't expect the compiler could optimize the default: case the way you described. No matter what order you write these in, the code has to check each of the other cases first before deciding to execute the default: arm. If it's that important, maybe we should add a "case 0:" arm?
Quoted 3 lines
Trond
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
Re: [PATCH 3/7] SUNRPC: Clean up call_transmit_status()
Quoted 65 lines · Chuck Lever
Quoted 55 lines · Trond Myklebust
Quoted 54 lines · Chuck Lever
Clean up: re-arrange the cases in
call_transmit_status()to make the code easier to read.Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/clnt.c| 24 ++++++++++++------------1 files changed, 12 insertions(+), 12 deletions(-)net/sunrpc/clnt.c +3
-0@@ -1175,25 +1175,21 @@ call_transmit(struct rpc_task *task)/* * 5a. Handle cleanup after a transmission +* If we've been waiting on the socket's write_space() +* callback, or if the server is temporarily unreachable, +* continue holding the transport lock. */ static void
call_transmit_status(struct rpc_task *task)
{net/sunrpc/clnt.c +2
-0+dprint_status (task); +task->tk_action = call_status; + switch (task->tk_status) {net/sunrpc/clnt.c +1
-5-case -EAGAIN : -break ; -default : -xprt_end_transmit (task); -rpc_task_force_reencode (task); +case -EAGAIN :/* no write space */ break;net/sunrpc/clnt.c +1
-7-/* -* Special cases: if we've been waiting on the -* socket's write_space() callback, or if the -* socket just returned a connection error, -* then hold onto the transport lock. -*/ -case -ECONNREFUSED : +case -ECONNREFUSED :/* connection problems */ case
-ECONNRESET:
case-ENOTCONN:
case-EHOSTDOWN:net/sunrpc/clnt.c +3
-0@@ -1206,6 +1202,10 @@ call_transmit_status(struct rpc_task *task)break ; }rpc_task_force_reencode (task); +break ; +default :/* success, or some other error */ +xprt_end_transmit (task);Quoted 8 lines
net/sunrpc/clnt.c call_transmit_status(struct rpc_task *task) · line 1210
Quoted 3 lines
net/sunrpc/clnt.c +1
-0+rpc_task_force_reencode (task); } }This puts the most common case (success) at the very end of the switch statement. Most compilers will generate the most efficient code when it
is at the very beginning...
Quoted 7 lines
I dropped this one, since it's not that important.
But I wouldn't expect the compiler could optimize the default: case the way you described. No matter what order you write these in, the code has to check each of the other cases first before deciding to execute the default: arm. If it's that important, maybe we should add a "case 0:" arm?
Yes. That's probably a good idea...
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): 1254959009.7045.47.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org
Re: [PATCH 3/7] SUNRPC: Clean up call_transmit_status()
Quoted 68 lines · Trond Myklebust
Quoted 67 lines · Chuck Lever
Quoted 55 lines · Trond Myklebust
Quoted 54 lines · Chuck Lever
Clean up: re-arrange the cases in
call_transmit_status()to make the code easier to read.Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/clnt.c| 24 ++++++++++++------------1 files changed, 12 insertions(+), 12 deletions(-)net/sunrpc/clnt.c +3
-0@@ -1175,25 +1175,21 @@ call_transmit(struct rpc_task *task)/* * 5a. Handle cleanup after a transmission +* If we've been waiting on the socket's write_space() +* callback, or if the server is temporarily unreachable, +* continue holding the transport lock. */ static void
call_transmit_status(struct rpc_task *task)
{net/sunrpc/clnt.c +2
-0+dprint_status (task); +task->tk_action = call_status; + switch (task->tk_status) {net/sunrpc/clnt.c +1
-5-case -EAGAIN : -break ; -default : -xprt_end_transmit (task); -rpc_task_force_reencode (task); +case -EAGAIN :/* no write space */ break;net/sunrpc/clnt.c +1
-7-/* -* Special cases: if we've been waiting on the -* socket's write_space() callback, or if the -* socket just returned a connection error, -* then hold onto the transport lock. -*/ -case -ECONNREFUSED : +case -ECONNREFUSED :/* connection problems */ case
-ECONNRESET:
case-ENOTCONN:
case-EHOSTDOWN:net/sunrpc/clnt.c +3
-0@@ -1206,6 +1202,10 @@ call_transmit_status(struct rpc_task *task)break ; }rpc_task_force_reencode (task); +break ; +default :/* success, or some other error */ +xprt_end_transmit (task);Quoted 8 lines
net/sunrpc/clnt.c call_transmit_status(struct rpc_task *task) · line 1210
Quoted 3 lines
net/sunrpc/clnt.c +1
-0+rpc_task_force_reencode (task); } }This puts the most common case (success) at the very end of the switch statement. Most compilers will generate the most efficient code when it
is at the very beginning...I dropped this one, since it's not that important.
Quoted 7 lines
Quoted 5 lines
But I wouldn't expect the compiler could optimize the default: case the way you described. No matter what order you write these in, the code has to check each of the other cases first before deciding to execute the default: arm. If it's that important, maybe we should add a "case 0:" arm?
Yes. That's probably a good idea...
Well, after looking at the actual evidence (ie objdump output)...
Unfortunately, adding "case 0:" doesn't seem to change the object code. Nothing I tried seemed to prevent the compiler from placing the zero case at the end of the function. I had to add
if (task->tk_status == 0) {
xprt_end_transmit(task);
rpc_task_force_reencode(task);
return;
}
switch (task->tk_status) {...
before the compiler would put the check for zero status first. Hopefully, open coding it would make the arrangement permanent, regardless of any compiler optimizations.
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
PATCH 4/7 SUNRPC: maintain a single transport for rpcbind upcalls
In reply to a message not in the archiveThe kernel's rpcbind client creates and deletes an rpc_clnt and its underlying transport socket for every upcall to the local rpcbind daemon. Instead, let's create an rpc_clnt for rpcbind upcalls when sunrpc.ko is loaded, and use it until sunrpc.ko is unloaded. This saves the overhead of creating and destroying an rpc_clnt and a socket for every upcall.
When starting a typical NFS server on IPv4 and IPv6, this reduces the number of rpcbind sockets created from one per upcall to just one. The NFS service itself does three upcalls (one per version) times two upcalls (one per transport) times two upcalls (one per address family), making 12, plus another one for the initial call to unregister previous NFS services. Starting the NLM service adds an additional 13 upcalls, for similar reasons.
Note that at the moment, lockd supports IPv6, but the kernel's NFS service does not, so the NFS service does only six registrations on current systems.
---
net/sunrpc/rpcb_clnt.c | 64 +++++++++++++++++++++++++++++++++++----------- net/sunrpc/sunrpc_syms.c | 5 ++++ 2 files changed, 54 insertions(+), 15 deletions(-)
net/sunrpc/rpcb_clnt.c +49 -15
@@ -110,6 +110,9 @@ static void rpcb_getport_done(struct rpc_task *, void *);static void rpcb_map_release (void *data);static struct rpc_program rpcb_program; +static struct rpc_clnt * rpcb_local_clnt; +static struct rpc_clnt * rpcb_local_clnt4; +struct rpcbind_args {struct rpc_xprt * r_xprt;
@@ -209,22 +212,13 @@ static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr,return rpc_create (&args); } -static int rpcb_register_call (const u32 version,struct rpc_message *msg) +static int rpcb_register_call (struct rpc_clnt *clnt,struct rpc_message *msg) { -struct sockaddr *addr = (struct sockaddr *)&rpcb_inaddr_loopback; -size_t addrlen =sizeof (rpcb_inaddr_loopback); -struct rpc_clnt *rpcb_clnt;int result, error =0 ; msg->rpc_resp = &result; - rpcb_clnt =rpcb_create_local (addr, addrlen, version); -if (!IS_ERR (rpcb_clnt)) { - error =rpc_call_sync (rpcb_clnt, msg,0 ); -rpc_shutdown_client (rpcb_clnt); - }else - error =PTR_ERR (rpcb_clnt); - + error =rpc_call_sync (clnt, msg,0 );if (error <0 ) {dprintk ("RPC: failed to contact local rpcbind " "server (errno %d).\n" , -error);
@@ -288,7 +282,7 @@ int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port)if (port) msg.rpc_proc = &rpcb_procedures2[RPCBPROC_SET ]; -return rpcb_register_call (RPCBVERS_2 , &msg); +return rpcb_register_call (rpcb_local_clnt, &msg); }/*
@@ -313,7 +307,7 @@ static int rpcb_register_inet4(const struct sockaddr *sap,if (port) msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET ]; - result =rpcb_register_call (RPCBVERS_4 , msg); + result =rpcb_register_call (rpcb_local_clnt4, msg);kfree (map->r_addr);return result; }
@@ -340,7 +334,7 @@ static int rpcb_register_inet6(const struct sockaddr *sap,if (port) msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET ]; - result =rpcb_register_call (RPCBVERS_4 , msg); + result =rpcb_register_call (rpcb_local_clnt4, msg);kfree (map->r_addr);return result; }
@@ -356,7 +350,7 @@ static int rpcb_unregister_all_protofamilies(struct rpc_message *msg) map->r_addr ="" ; msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET ]; -return rpcb_register_call (RPCBVERS_4 , msg); +return rpcb_register_call (rpcb_local_clnt4, msg); }/**
@@ -1027,3 +1021,43 @@ static struct rpc_program rpcb_program = { .version = rpcb_version, .stats = &rpcb_stats, }; + +/** +* init_rpcb_clnt - set up kernel's rpcbind client +* +*/ +int init_rpcb_clnt (void ) +{ +struct sockaddr *addr = (struct sockaddr *)&rpcb_inaddr_loopback; +size_t addrlen =sizeof (rpcb_inaddr_loopback); + + rpcb_local_clnt =rpcb_create_local (addr, addrlen,RPCBVERS_2 ); +if (IS_ERR (rpcb_local_clnt)) { +printk (KERN_ERR "failed to create local rpcbind " +"client (errno %ld).\n" , + -PTR_ERR (rpcb_local_clnt)); +return -1 ; + } + rpcb_local_clnt4 =rpc_bind_new_program (rpcb_local_clnt, + &rpcb_program, +RPCBVERS_4 ); +if (IS_ERR (rpcb_local_clnt4)) { +printk (KERN_ERR "failed to duplicate local rpcbind " +"client (errno %ld).\n" , + -PTR_ERR (rpcb_local_clnt4)); +rpc_shutdown_client (rpcb_local_clnt); +return -1 ; + } + +return 0 ; +} + +/** +* cleanup_rpcb_clnt - remove xprtsock's sysctls, unregister +* +*/ +void cleanup_rpcb_clnt (void ) +{ +rpc_shutdown_client (rpcb_local_clnt4); +rpc_shutdown_client (rpcb_local_clnt); +}
net/sunrpc/sunrpc_syms.c +5 -0
@@ -24,6 +24,9 @@extern struct cache_detail ip_map_cache, unix_gid_cache; +extern int init_rpcb_clnt (void ); +extern void cleanup_rpcb_clnt (void ); +static int __init init_sunrpc (void ) {
@@ -46,6 +49,7 @@ init_sunrpc(void)svc_init_xprt_sock ();/* svc sock transport */ init_socket_xprt ();/* clnt sock transport */ rpcauth_init_module (); +init_rpcb_clnt (); out:return err; }
@@ -53,6 +57,7 @@ out: static void __exitcleanup_sunrpc (void ) { +cleanup_rpcb_clnt ();rpcauth_remove_module ();cleanup_socket_xprt ();svc_cleanup_xprt_sock ();
PATCH 5/7 SUNRPC: Use TCP for local rpcbind upcalls
In reply to a message not in the archiveUse TCP with the soft connect semantic for local rpcbind upcalls so the kernel can detect immediately if the local rpcbind daemon is not running.
---
net/sunrpc/rpcb_clnt.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
net/sunrpc/rpcb_clnt.c +2 -2
@@ -170,7 +170,7 @@ static struct rpc_clnt *rpcb_create_local(struct sockaddr *addr, size_t addrlen, u32 version) {struct rpc_create_args args = { - .protocol =XPRT_TRANSPORT_UDP , + .protocol =XPRT_TRANSPORT_TCP , .address = addr, .addrsize = addrlen, .servername ="localhost" ,
@@ -218,7 +218,7 @@ static int rpcb_register_call(struct rpc_clnt *clnt, struct rpc_message *msg) msg->rpc_resp = &result; - error =rpc_call_sync (clnt, msg,0 ); + error =rpc_call_sync (clnt, msg,RPC_TASK_SOFTCONN );if (error <0 ) {dprintk ("RPC: failed to contact local rpcbind " "server (errno %d).\n" , -error);
PATCH 6/7 SUNRPC: Use soft connects for autobinding over TCP
In reply to a message not in the archiveAutobinding is handled by the rpciod process, not in user processes that are generating regular RPC requests. Thus autobinding is usually not affected by signals targetting user processes, such as KILL or timer expiration events.
In addition, an RPC request generated by a user process that has RPC_TASK_SOFTCONN set and needs to perform an autobind will hang if the remote rpcbind service is not available.
For rpcbind queries on connection-oriented transports, let's use the new soft connect semantic to return control to the user's process quickly, if the kernel's rpcbind client can't connect to the remote rpcbind service.
Logic is introduced in call_bind_status() to handle connection errors that occurred during an asynchronous rpcbind query. The logic abandons the rpcbind query if the RPC request has SOFTCONN set, and retries after a few seconds in the normal case.
---
net/sunrpc/clnt.c | 16 +++++++++++++++- net/sunrpc/rpcb_clnt.c | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-)
net/sunrpc/clnt.c +15 -1
@@ -1060,7 +1060,7 @@ call_bind_status(struct rpc_task *task) goto retry_timeout;case -EPFNOSUPPORT :/* server doesn't support any rpcbind version we know of */ -dprintk ("RPC: %5u remote rpcbind service unavailable\n" , +dprintk ("RPC: %5u unrecognized remote rpcbind service\n" , task->tk_pid);break ;case -EPROTONOSUPPORT :
@@ -1069,6 +1069,20 @@ call_bind_status(struct rpc_task *task) task->tk_status =0 ; task->tk_action = call_bind;return ; +case -ECONNREFUSED :/* connection problems */ +case -ECONNRESET : +case -ENOTCONN : +case -EHOSTDOWN : +case -EHOSTUNREACH : +case -ENETUNREACH : +case -EPIPE : +dprintk ("RPC: %5u remote rpcbind unreachable: %d\n" , + task->tk_pid, task->tk_status); +if (!RPC_IS_SOFTCONN (task)) { +rpc_delay (task,5 *HZ ); + goto retry_timeout; + } +break ;default :dprintk ("RPC: %5u unrecognized rpcbind error (%d)\n" , task->tk_pid, -task->tk_status);
net/sunrpc/rpcb_clnt.c +1 -1
@@ -485,7 +485,7 @@ static struct rpc_task *rpcb_call_async(struct rpc_clnt *rpcb_clnt, struct rpcbi .rpc_message = &msg, .callback_ops = &rpcb_getport_ops, .callback_data = map, - .flags = RPC_TASK_ASYNC, + .flags = RPC_TASK_ASYNC | RPC_TASK_SOFTCONN, };return rpc_run_task (&task_setup_data);
PATCH 7/7 SUNRPC: Use soft connect semantics when performing RPC ping
In reply to a message not in the archiveCurrently, if a remote RPC service is unreachable, an RPC ping will hang until the underlying transport connect attempt times out. A more desirable behavior might be to have the ping fail immediately so upper layers can recover appropriately.
In the case of an NFS mount, for instance, this would mean the mount(2) system call could fail immediately if the server isn't listening, rather than hanging uninterruptibly for more than 3 minutes.
With the new soft connect flag, we can get this behavior. After this patch, rpc_create() with TCP will fail immediately if an RPC ping was requested and the server is not reachable.
---
net/sunrpc/clnt.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/sunrpc/clnt.c +1 -1
@@ -1703,7 +1703,7 @@ static int rpc_ping(struct rpc_clnt *clnt, int flags) };int err; msg.rpc_cred = authnull_ops.lookup_cred (NULL ,NULL ,0 ); - err =rpc_call_sync (clnt, &msg, flags); + err =rpc_call_sync (clnt, &msg, flags |RPC_TASK_SOFTCONN );put_rpccred (msg.rpc_cred);return err; }
A message that is not in the archive (sent off-list or not yet received): 20091007220310.1844.39266.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org
Re: [PATCH 7/7] SUNRPC: Use soft connect semantics when performing RPC ping
Quoted 25 lines · Chuck Lever
Currently, if a remote RPC service is unreachable, an RPC ping will hang until the underlying transport connect attempt times out. A more desirable behavior might be to have the ping fail immediately so upper layers can recover appropriately.
In the case of an NFS mount, for instance, this would mean the mount(2) system call could fail immediately if the server isn't listening, rather than hanging uninterruptibly for more than 3 minutes.
With the new soft connect flag, we can get this behavior. After this patch,
rpc_create()with TCP will fail immediately if an RPC ping was requested and the server is not reachable.Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/clnt.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)net/sunrpc/clnt.c +0
-0
net/sunrpc/clnt.c static int rpc_ping(struct rpc_clnt *clnt, int flags) · line 1709
Quoted 8 lines
net/sunrpc/clnt.c +1
-1@@ -1703,7 +1703,7 @@ static int rpc_ping(struct rpc_clnt *clnt, int flags) };int err; msg.rpc_cred = authnull_ops.lookup_cred (NULL ,NULL ,0 ); - err =rpc_call_sync (clnt, &msg, flags); + err =rpc_call_sync (clnt, &msg, flags |RPC_TASK_SOFTCONN );put_rpccred (msg.rpc_cred);return err; }
Currently, all callers already set RPC_TASK_SOFT. Why not move that too into rpc_ping at the same time?
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com