svc: SVC Transport Switch
Subsystems (3)
cover svc: SVC Transport Switch
The Server Side Transport switch implements a pluggable transport provider layer for RPC servers. This switch allows network transport drivers to be dynamically loaded and registered, thereby extending the set of transports that can carry RPC. This patchset includes a transport provider driver for TCP and UDP sockets.
This version of the patchset includes the following updates to the original patch series:
- Changed transport hdr len fields and computations to use size_t
- Matched local variables to sign of socket specific write-space functions in xpo_wspace transport functions.
- Modified tcp_has_wspace function to include min_wspace consideration
- Changed address length functions to size_t
- Changed port helper function return types to unsigned short
- Changed error return from svc_addr_len to EAFNOSUPPORT from ENOTSUPP
- When modifying function prototypes or adding new functions adhered to convention of keeping signature on a single line.
- Removed debug printk from svc_send
- Created separate patch for change that moves the call to svc_xprt_received to common code for the accept path
- Combined the portlist update patches into a single patch and updated the error codes to give more helpful perror strings when writing garbage to the portlist file.
This patchset is based on 2.6.24-rc5 and has been tested on V2, V3 and V4 over the UDP, TCP and RDMA transports.
Signature · 1 line
Signed-off-by: Tom Tucker <[email protected]>
A message that is not in the archive (sent off-list or not yet received): 20071211233150.15718.40579.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org
PATCH 1/38 svc: Add an svc transport class
The transport class (svc_xprt_class) represents a type of transport, e.g. udp, tcp, rdma. A transport class has a unique name and a set of transport operations kept in the svc_xprt_ops structure.
A transport class can be dynamically registered and unregisterd. The svc_xprt_class represents the module that implements the transport type and keeps reference counts on the module to avoid unloading while there are active users.
The endpoint (svc_xprt) is a generic, transport independent endpoint that can be used to send and receive data for an RPC service. It inherits it's operations from the transport class.
A transport driver module registers and unregisters itself with svc sunrpc by calling svc_reg_xprt_class, and svc_unreg_xprt_class respectively.
---
include/linux/sunrpc/debug.h | 1 include/linux/sunrpc/svc_xprt.h | 31 +++++++++++++ net/sunrpc/Makefile | 3 + net/sunrpc/svc_xprt.c | 95 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 1 deletions(-)
include/linux/sunrpc/debug.h +1 -0
@@ -21,6 +21,7 @@#define RPCDBG_SCHED 0x0040#define RPCDBG_TRANS 0x0080#define RPCDBG_SVCSOCK 0x0100 +#define RPCDBG_SVCXPRT 0x0100#define RPCDBG_SVCDSP 0x0200#define RPCDBG_MISC 0x0400#define RPCDBG_CACHE 0x0800
include/linux/sunrpc/svc_xprt.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* linux/include/linux/sunrpc/svc_xprt.h +* +* RPC server transport I/O +*/ + +#ifndef SUNRPC_SVC_XPRT_H +#define SUNRPC_SVC_XPRT_H + +#include <linux/sunrpc/svc.h> + +struct svc_xprt_ops { +}; + +struct svc_xprt_class { +const char *xcl_name; +struct module *xcl_owner; +struct svc_xprt_ops *xcl_ops; +struct list_head xcl_list; +}; + +struct svc_xprt { +struct svc_xprt_class *xpt_class; +struct svc_xprt_ops *xpt_ops; +}; + +int svc_reg_xprt_class (struct svc_xprt_class *); +int svc_unreg_xprt_class (struct svc_xprt_class *); +void svc_xprt_init (struct svc_xprt_class *,struct svc_xprt *); + +#endif /* SUNRPC_SVC_XPRT_H */
net/sunrpc/Makefile +2 -1
@@ -11,6 +11,7 @@ sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \ auth.o auth_null.o auth_unix.o \ svc.o svcsock.o svcauth.o svcauth_unix.o \ rpcb_clnt.o timer.o xdr.o \ - sunrpc_syms.o cache.o rpc_pipe.o + sunrpc_syms.o cache.o rpc_pipe.o \ + svc_xprt.o sunrpc-$(CONFIG_PROC_FS) += stats.o sunrpc-$(CONFIG_SYSCTL) += sysctl.o
net/sunrpc/svc_xprt.c new file +95 -0
95 lines not on this page · raw message
A message that is not in the archive (sent off-list or not yet received): 20071211233152.15718.44241.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org
Re: [PATCH 01/38] svc: Add an svc transport class
Sorry for joining in a little late....
Quoted 1 line · Tom Tucker
+int
svc_reg_xprt_class(struct svc_xprt_class *xcl)
None of the callers appear to check the return value, so this should probably be a void return.
net/sunrpc/svc_xprt.c line 50
Quoted 8 lines
net/sunrpc/svc_xprt.c new file +8
-0+{ +struct svc_xprt_class *cl; +int res = -EEXIST ; + +dprintk ("svc: Adding svc transport class '%s'\n" , + xcl->xcl_name); + +INIT_LIST_HEAD (&xcl->xcl_list);
Unless we care how xcl_list is set in the error case, this is unnecessary.
net/sunrpc/svc_xprt.c line 54
Quoted 4 lines
net/sunrpc/svc_xprt.c new file +4
-0+spin_lock (&svc_xprt_class_lock); +list_for_each_entry (cl, &svc_xprt_class_list, xcl_list) { +if (xcl == cl) + goto out;
Is this even worth checking? Accidentally registering the identical struct svc_xprt_class * seems an unlikely mistake for a transport-class coder to make, given that they only need call this function once per transport, in the module initialization. Maybe make this a BUG()? Or check for duplicate xcl_name's if that seems a more likely error?
Quoted 14 lines
net/sunrpc/svc_xprt.c new file +14
-0+ } +list_add_tail (&xcl->xcl_list, &svc_xprt_class_list); + res =0 ; +out: +spin_unlock (&svc_xprt_class_lock); +return res; +} +EXPORT_SYMBOL_GPL (svc_reg_xprt_class); + +int svc_unreg_xprt_class (struct svc_xprt_class *xcl) +{ +struct svc_xprt_class *cl; +int res =0 ; +
net/sunrpc/svc_xprt.c line 78
Quoted 10 lines
net/sunrpc/svc_xprt.c new file +10
-0+dprintk ("svc: Removing svc transport class '%s'\n" , xcl->xcl_name); + +spin_lock (&svc_xprt_class_lock); +list_for_each_entry (cl, &svc_xprt_class_list, xcl_list) { +if (xcl == cl) { +list_del_init (&cl->xcl_list); + goto out; + } + } + res = -ENOENT ;
Again, nobody checks this error return, and it seems like an unlikely programmer error anyway. If we really need the check I'd be inclined just to ditche the for loop and BUG_ON(list_empty(&cl->xcl_list)), which will catch double-unregistrations (thanks to the list_del_init()).
Quoted 7 lines
+ out:
net/sunrpc/svc_xprt.c new file +6
-0+spin_unlock (&svc_xprt_class_lock); +return res; +} +EXPORT_SYMBOL_GPL (svc_unreg_xprt_class); + +/*
net/sunrpc/svc_xprt.c line 95
Quoted 10 lines
net/sunrpc/svc_xprt.c new file +10
-0+* Called by transport drivers to initialize the transport independent +* portion of the transport instance. +*/ +void svc_xprt_init (struct svc_xprt_class *xcl,struct svc_xprt *xprt) +{ +memset (xprt,0 ,sizeof (*xprt)); + xprt->xpt_class = xcl; + xprt->xpt_ops = xcl->xcl_ops; +} +EXPORT_SYMBOL_GPL (svc_xprt_init);
Seems fine otherwise.
--b.
Re: [PATCH 01/38] svc: Add an svc transport class
Quoted 8 lines · J. Bruce Fields
Sorry for joining in a little late....
Quoted 1 line · Tom Tucker
+int
svc_reg_xprt_class(struct svc_xprt_class *xcl)None of the callers appear to check the return value, so this should probably be a void return.
I don't feel strongly about this, but what I was trying to catch was two different transports accidentally colliding on the same name. I doubt there will be a run on new transports, but it would at least fail the module load with a reasonable error.
Quoted 12 lines
net/sunrpc/svc_xprt.c line 50
Quoted 8 lines
net/sunrpc/svc_xprt.c new file +8
-0+{ +struct svc_xprt_class *cl; +int res = -EEXIST ; + +dprintk ("svc: Adding svc transport class '%s'\n" , + xcl->xcl_name); + +INIT_LIST_HEAD (&xcl->xcl_list);Unless we care how
xcl_listis set in the error case, this is unnecessary.
I'll leave this and clean up the un-register path as you suggest below.
Quoted 10 lines
Review
Quoted 4 lines
+
spin_lock(&svc_xprt_class_lock);
+list_for_each_entry(cl, &svc_xprt_class_list, xcl_list){(quoted diff) +2
-0+ if (xcl == cl) + goto out;Is this even worth checking? Accidentally registering the identical struct
svc_xprt_class* seems an unlikely mistake for a transport-class coder to make, given that they only need call this function once per transport, in the module initialization. Maybe make this aBUG()? Or check for duplicate xcl_name's if that seems a more likely error?
What I really wanted to check was name == name, not necessarily ptr == ptr. I should fix this to fail if strcmp(xcl->name, cl->name)==0.
Quoted 22 lines
Quoted 22 lines
+ }
+list_add_tail(&xcl->xcl_list, &svc_xprt_class_list);
+ res = 0;net/sunrpc/svc_xprt.c new file +18
-0+out: +spin_unlock (&svc_xprt_class_lock); +return res; +} +EXPORT_SYMBOL_GPL (svc_reg_xprt_class); + +int svc_unreg_xprt_class (struct svc_xprt_class *xcl) +{ +struct svc_xprt_class *cl; +int res =0 ; + +dprintk ("svc: Removing svc transport class '%s'\n" , xcl->xcl_name); + +spin_lock (&svc_xprt_class_lock); +list_for_each_entry (cl, &svc_xprt_class_list, xcl_list) { +if (xcl == cl) { +list_del_init (&cl->xcl_list); + goto out;
Quoted 9 lines
Quoted 3 lines
+ }
+ }
+ res =-ENOENT;Again, nobody checks this error return, and it seems like an unlikely programmer error anyway. If we really need the check I'd be inclined just to ditche the for loop and BUG_ON(list_empty(&cl->xcl_list)), which will catch double-unregistrations (thanks to the
list_del_init()).
Yeah, the loop is dumb. I agree with your error assessment, how about if I change the return type to void and list_del_init(...) sans loop.
Quoted 21 lines
Quoted 7 lines
+ out:
+spin_unlock(&svc_xprt_class_lock);
+ return res;net/sunrpc/svc_xprt.c new file +4
-0+} +EXPORT_SYMBOL_GPL (svc_unreg_xprt_class); + +/* net/sunrpc/svc_xprt.c line 95
Quoted 10 lines
net/sunrpc/svc_xprt.c new file +10
-0+* Called by transport drivers to initialize the transport independent +* portion of the transport instance. +*/ +void svc_xprt_init (struct svc_xprt_class *xcl,struct svc_xprt *xprt) +{ +memset (xprt,0 ,sizeof (*xprt)); + xprt->xpt_class = xcl; + xprt->xpt_ops = xcl->xcl_ops; +} +EXPORT_SYMBOL_GPL (svc_xprt_init);Seems fine otherwise.
--b.
Re: [PATCH 01/38] svc: Add an svc transport class
Quoted 10 lines · Tom Tucker
Quoted 5 lines · J. Bruce Fields
Sorry for joining in a little late....
Quoted 1 line · Tom Tucker
+int
svc_reg_xprt_class(struct svc_xprt_class *xcl)
Quoted 8 lines
Quoted 3 lines
None of the callers appear to check the return value, so this should probably be a void return.
I don't feel strongly about this, but what I was trying to catch was two different transports accidentally colliding on the same name. I doubt there will be a run on new transports, but it would at least fail the module load with a reasonable error.
Sounds fine.
Thanks!--b.
Re: [PATCH 01/38] svc: Add an svc transport class
Quoted 15 lines · J. Bruce Fields
Quoted 14 lines · Tom Tucker
Quoted 8 lines · J. Bruce Fields
Sorry for joining in a little late....
Quoted 1 line · Tom Tucker
+int
svc_reg_xprt_class(struct svc_xprt_class *xcl)None of the callers appear to check the return value, so this should probably be a void return.
Quoted 6 lines
Quoted 4 lines
I don't feel strongly about this, but what I was trying to catch was two different transports accidentally colliding on the same name. I doubt there will be a run on new transports, but it would at least fail the module load with a reasonable error.
Sounds fine.
Great, done.
I've coded all of the changes that you suggested and built a new patchset. Besides the tests I outlined in my "test matrix" are there any other tests you would like to see performed?
I could not reproduce the BUG_ON from Bull. I'm wondering if it's a PPC issue :-\
After the testing, I'll publish the revised patchset.
Quoted 2 lines
Thanks!--b.
A message that is not in the archive (sent off-list or not yet received): 1197937584.13463.44.camel-SMNkleLxa3ZimH42XvhXlA@public.gmane.org
Re: [PATCH 01/38] svc: Add an svc transport class
Quoted 3 lines · Tom Tucker
I've coded all of the changes that you suggested and built a new patchset. Besides the tests I outlined in my "test matrix" are there any other tests you would like to see performed?
krb5p testing might still be interesting.
Quoted 3 lines
I could not reproduce the
BUG_ONfrom Bull. I'm wondering if it's a PPC issue :-\
Hm, too bad, I'd like to understand that one.
Quoted 3 lines
After the testing, I'll publish the revised patchset.
OK, thanks.--b.
Re: [PATCH 01/38] svc: Add an svc transport class
Quoted 7 lines · J. Bruce Fields
Quoted 3 lines · Tom Tucker
I've coded all of the changes that you suggested and built a new patchset. Besides the tests I outlined in my "test matrix" are there any other tests you would like to see performed?
krb5p testing might still be interesting.
I'll add it to my matrix. It will take some time to set up though since I don't have a KDC or anything set up. Are we under any time constraints?
Quoted 6 lines
Quoted 3 lines
I could not reproduce the
BUG_ONfrom Bull. I'm wondering if it's a PPC issue :-\Hm, too bad, I'd like to understand that one.
Yeah, and I'm having a hard time believing it's PPC related. I think I'm missing something, I'll keep looking.
Quoted 5 lines
Quoted 3 lines
After the testing, I'll publish the revised patchset.
OK, thanks.--b.
A message that is not in the archive (sent off-list or not yet received): 1197990256.13463.54.camel-SMNkleLxa3ZimH42XvhXlA@public.gmane.org
Re: [PATCH 01/38] svc: Add an svc transport class
Quoted 7 lines · Tom Tucker
Quoted 5 lines · J. Bruce Fields
Quoted 3 lines · Tom Tucker
I've coded all of the changes that you suggested and built a new patchset. Besides the tests I outlined in my "test matrix" are there any other tests you would like to see performed?
Quoted 6 lines
Quoted 2 lines
krb5p testing might still be interesting.
I'll add it to my matrix. It will take some time to set up though since I don't have a KDC or anything set up. Are we under any time constraints?
For krb5p, I don't think it's terifically urgent.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I could not reproduce the
BUG_ONfrom Bull. I'm wondering if it's a PPC issue :-\Hm, too bad, I'd like to understand that one.
Yeah, and I'm having a hard time believing it's PPC related. I think I'm missing something, I'll keep looking.
Thanks!
--b.
Re: [PATCH 01/38] svc: Add an svc transport class
In reply to a message not in the archiveQuoted 6 lines · Tom Tucker
Quoted 5 lines · J. Bruce Fields
Quoted 3 lines · Tom Tucker
I've coded all of the changes that you suggested and built a new patchset. Besides the tests I outlined in my "test matrix" are there any other tests you would like to see performed?
Quoted 13 lines
Quoted 2 lines
krb5p testing might still be interesting.
I'll add it to my matrix. It will take some time to set up though since I don't have a KDC or anything set up. Are we under any time constraints?
Quoted 6 lines
Quoted 3 lines
I could not reproduce the
BUG_ONfrom Bull. I'm wondering if it's a PPC issue :-\Hm, too bad, I'd like to understand that one.
FYI, I have now reproduced this bug on an AMD64 box with the CITI_NFS4_ALL-1 tree.
I am regression testing it on the new build have been running it about 2hrs without failure.
Quoted 14 lines
Yeah, and I'm having a hard time believing it's PPC related. I think I'm missing something, I'll keep looking.
Quoted 5 lines
Quoted 3 lines
After the testing, I'll publish the revised patchset.
OK, thanks.--b.
-
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
A message that is not in the archive (sent off-list or not yet received): 1198006238.13463.79.camel-SMNkleLxa3ZimH42XvhXlA@public.gmane.org
Re: [PATCH 01/38] svc: Add an svc transport class
Quoted 19 lines · Tom Tucker
Quoted 17 lines · Tom Tucker
Quoted 7 lines · J. Bruce Fields
Quoted 3 lines · Tom Tucker
I've coded all of the changes that you suggested and built a new patchset. Besides the tests I outlined in my "test matrix" are there any other tests you would like to see performed?
krb5p testing might still be interesting.
I'll add it to my matrix. It will take some time to set up though since I don't have a KDC or anything set up. Are we under any time constraints?
Quoted 4 lines
Quoted 3 lines
I could not reproduce the
BUG_ONfrom Bull. I'm wondering if it's a PPC issue :-\
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Hm, too bad, I'd like to understand that one.
FYI, I have now reproduced this bug on an AMD64 box with the CITI_NFS4_ALL-1 tree.
I am regression testing it on the new build have been running it about 2hrs without failure.
OK, so probably either something got fixed in the server-xprt-switch patches since then, or something got fixed in mainline, or the problem was in one of the other CITI_NFS4_ALL patches. Hm.
--b.
Re: [PATCH 01/38] svc: Add an svc transport class
In reply to J. Bruce FieldsBy the way, I'm leaving town tommorow, on vacation till the end of the month. I might still be online occasionally, but it's hard to predict.
Thanks to everyone for a good 2007, and best wishes for the new year!
--b.
PATCH 2/38 svc: Make svc_sock the tcp/udp transport
In reply to a message not in the archiveMake TCP and UDP svc_sock transports, and register them with the svc transport core.
A transport type (svc_sock) has an svc_xprt as its first member, and calls svc_xprt_init to initialize this field.
---
include/linux/sunrpc/debug.h | 1 - include/linux/sunrpc/svcsock.h | 4 ++++ net/sunrpc/sunrpc_syms.c | 4 +++- net/sunrpc/svcsock.c | 33 ++++++++++++++++++++++++++++++++- 4 files changed, 39 insertions(+), 3 deletions(-)
include/linux/sunrpc/debug.h +0 -1
@@ -20,7 +20,6 @@#define RPCDBG_BIND 0x0020#define RPCDBG_SCHED 0x0040#define RPCDBG_TRANS 0x0080 -#define RPCDBG_SVCSOCK 0x0100#define RPCDBG_SVCXPRT 0x0100#define RPCDBG_SVCDSP 0x0200#define RPCDBG_MISC 0x0400
include/linux/sunrpc/svcsock.h +4 -0
@@ -10,11 +10,13 @@#define SUNRPC_SVCSOCK_H #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/svc_xprt.h> /* * RPC server socket. */ struct svc_sock { +struct svc_xprt sk_xprt;struct list_head sk_ready;/* list of ready sockets */ struct list_head sk_list;/* list of all sockets */ struct socket * sk_sock;/* berkeley socket layer */
@@ -78,6 +80,8 @@ int svc_addsock(struct svc_serv *serv,int fd, char *name_return, int *proto); +void svc_init_xprt_sock (void ); +void svc_cleanup_xprt_sock (void );/* * svc_makesock socket characteristics
net/sunrpc/sunrpc_syms.c +3 -1
@@ -151,7 +151,8 @@ init_sunrpc(void)#endif cache_register (&ip_map_cache);cache_register (&unix_gid_cache); -init_socket_xprt (); +svc_init_xprt_sock ();/* svc sock transport */ +init_socket_xprt ();/* clnt sock transport */ rpcauth_init_module (); out:return err;
@@ -162,6 +163,7 @@ cleanup_sunrpc(void) {rpcauth_remove_module ();cleanup_socket_xprt (); +svc_cleanup_xprt_sock ();unregister_rpc_pipefs ();rpc_destroy_mempool ();if (cache_unregister (&ip_map_cache))
net/sunrpc/svcsock.c +32 -1
@@ -75,7 +75,7 @@* */ -#define RPCDBG_FACILITY RPCDBG_SVCSOCK +#define RPCDBG_FACILITY RPCDBG_SVCXPRT static struct svc_sock *svc_setup_socket(struct svc_serv *, struct socket *,
@@ -900,12 +900,21 @@ svc_udp_sendto(struct svc_rqst *rqstp)return error; } +static struct svc_xprt_ops svc_udp_ops = { +}; + +static struct svc_xprt_class svc_udp_class = { + .xcl_name ="udp" , + .xcl_ops = &svc_udp_ops, +}; +static void svc_udp_init (struct svc_sock *svsk) {int one =1 ;mm_segment_t oldfs; +svc_xprt_init (&svc_udp_class, &svsk->sk_xprt); svsk->sk_sk->sk_data_ready = svc_udp_data_ready; svsk->sk_sk->sk_write_space = svc_write_space; svsk->sk_recvfrom = svc_udp_recvfrom;
@@ -1344,12 +1353,33 @@ svc_tcp_sendto(struct svc_rqst *rqstp)return sent; } +static struct svc_xprt_ops svc_tcp_ops = { +}; + +static struct svc_xprt_class svc_tcp_class = { + .xcl_name ="tcp" , + .xcl_ops = &svc_tcp_ops, +}; + +void svc_init_xprt_sock (void ) +{ +svc_reg_xprt_class (&svc_tcp_class); +svc_reg_xprt_class (&svc_udp_class); +} + +void svc_cleanup_xprt_sock (void ) +{ +svc_unreg_xprt_class (&svc_tcp_class); +svc_unreg_xprt_class (&svc_udp_class); +} +static void svc_tcp_init (struct svc_sock *svsk) {struct sock *sk = svsk->sk_sk;struct tcp_sock *tp =tcp_sk (sk); +svc_xprt_init (&svc_tcp_class, &svsk->sk_xprt); svsk->sk_recvfrom = svc_tcp_recvfrom; svsk->sk_sendto = svc_tcp_sendto;
@@ -1965,3 +1995,4 @@ static struct svc_deferred_req *svc_deferred_dequeue(struct svc_sock *svsk)spin_unlock (&svsk->sk_lock);return dr; } +
A message that is not in the archive (sent off-list or not yet received): 20071211233156.15718.7813.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org
Re: [PATCH 02/38] svc: Make svc_sock the tcp/udp transport
net/sunrpc/svcsock.c static struct svc_deferred_req *svc_deferred_dequeue(struct svc_sock *svsk) · line 1998
Quoted 5 lines · Tom Tucker
net/sunrpc/svcsock.c +1
-0@@ -1965,3 +1995,4 @@ static struct svc_deferred_req *svc_deferred_dequeue(struct svc_sock *svsk)spin_unlock (&svsk->sk_lock);return dr; } +
??
--b.
Re: [PATCH 02/38] svc: Make svc_sock the tcp/udp transport
Quoted 9 lines · J. Bruce Fields
net/sunrpc/svcsock.c static struct svc_deferred_req · line 1998
Quoted 6 lines · Tom Tucker
net/sunrpc/svcsock.c +1
-0@@ -1965,3 +1995,4 @@ static struct svc_deferred_req *svc_deferred_dequeue(struct svc_sock *svsk)spin_unlock (&svsk->sk_lock);return dr; } +??
Oops. Fixed.
Quoted 2 lines
--b.
PATCH 3/38 svc: Change the svc_sock in the rqstp structure to a transport
In reply to a message not in the archiveThe rqstp structure contains a pointer to the transport for the RPC request. This functionaly trivial patch adds an unamed union with pointers to both svc_sock and svc_xprt. Ultimately the union will be removed and only the rq_xprt field will remain. This allows incrementally extracting transport independent interfaces without one gigundo patch.
---
include/linux/sunrpc/svc.h | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
include/linux/sunrpc/svc.h +4 -1
@@ -204,7 +204,10 @@ union svc_addr_u {struct svc_rqst {struct list_head rq_list;/* idle list */ struct list_head rq_all;/* all threads list */ -struct svc_sock * rq_sock;/* socket */ +union { +struct svc_xprt * rq_xprt;/* transport ptr */ +struct svc_sock * rq_sock;/* socket ptr */ + };struct sockaddr_storage rq_addr;/* peer address */ size_t rq_addrlen;
PATCH 4/38 svc: Add a max payload value to the transport
In reply to a message not in the archiveThe svc_max_payload function currently looks at the socket type to determine the max payload. Add a max payload value to svc_xprt_class so it can be returned directly.
---
include/linux/sunrpc/svc_xprt.h | 1 + net/sunrpc/svc.c | 4 +--- net/sunrpc/svcsock.c | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-)
include/linux/sunrpc/svc_xprt.h +1 -0
@@ -17,6 +17,7 @@ struct svc_xprt_class {struct module *xcl_owner;struct svc_xprt_ops *xcl_ops;struct list_head xcl_list; +u32 xcl_max_payload; };struct svc_xprt {
net/sunrpc/svc.c +1 -3
@@ -1054,10 +1054,8 @@ err_bad:*/ u32 svc_max_payload (const struct svc_rqst *rqstp) { -int max =RPCSVC_MAXPAYLOAD_TCP ; +u32 max = rqstp->rq_xprt->xpt_class->xcl_max_payload; -if (rqstp->rq_sock->sk_sock->type ==SOCK_DGRAM ) - max =RPCSVC_MAXPAYLOAD_UDP ;if (rqstp->rq_server->sv_max_payload < max) max = rqstp->rq_server->sv_max_payload;return max;
net/sunrpc/svcsock.c +2 -0
@@ -906,6 +906,7 @@ static struct svc_xprt_ops svc_udp_ops = {static struct svc_xprt_class svc_udp_class = { .xcl_name ="udp" , .xcl_ops = &svc_udp_ops, + .xcl_max_payload =RPCSVC_MAXPAYLOAD_UDP , }; static void
@@ -1359,6 +1360,7 @@ static struct svc_xprt_ops svc_tcp_ops = {static struct svc_xprt_class svc_tcp_class = { .xcl_name ="tcp" , .xcl_ops = &svc_tcp_ops, + .xcl_max_payload =RPCSVC_MAXPAYLOAD_TCP , };void svc_init_xprt_sock (void )
PATCH 5/38 svc: Move sk_sendto and sk_recvfrom to svc_xprt_class
In reply to a message not in the archiveThe sk_sendto and sk_recvfrom are function pointers that allow svc_sock to be used for both UDP and TCP. Move these function pointers to the svc_xprt_ops structure.
---
include/linux/sunrpc/svc_xprt.h | 2 ++ include/linux/sunrpc/svcsock.h | 3 --- net/sunrpc/svcsock.c | 12 ++++++------ 3 files changed, 8 insertions(+), 9 deletions(-)
include/linux/sunrpc/svc_xprt.h +2 -0
@@ -10,6 +10,8 @@#include <linux/sunrpc/svc.h> struct svc_xprt_ops { +int (*xpo_recvfrom)(struct svc_rqst *); +int (*xpo_sendto)(struct svc_rqst *); };struct svc_xprt_class {
include/linux/sunrpc/svcsock.h +0 -3
@@ -45,9 +45,6 @@ struct svc_sock {* be revisted */ struct mutex sk_mutex;/* to serialize sending data */ -int (*sk_recvfrom)(struct svc_rqst *rqstp); -int (*sk_sendto)(struct svc_rqst *rqstp); -/* We keep the old state_change and data_ready CB's here */ void (*sk_ostate)(struct sock *);void (*sk_odata)(struct sock *,int bytes);
net/sunrpc/svcsock.c +6 -6
@@ -901,6 +901,8 @@ svc_udp_sendto(struct svc_rqst *rqstp) }static struct svc_xprt_ops svc_udp_ops = { + .xpo_recvfrom = svc_udp_recvfrom, + .xpo_sendto = svc_udp_sendto, };static struct svc_xprt_class svc_udp_class = {
@@ -918,8 +920,6 @@ svc_udp_init(struct svc_sock *svsk)svc_xprt_init (&svc_udp_class, &svsk->sk_xprt); svsk->sk_sk->sk_data_ready = svc_udp_data_ready; svsk->sk_sk->sk_write_space = svc_write_space; - svsk->sk_recvfrom = svc_udp_recvfrom; - svsk->sk_sendto = svc_udp_sendto;/* initialise setting must have enough space to * receive and respond to one request.
@@ -1355,6 +1355,8 @@ svc_tcp_sendto(struct svc_rqst *rqstp) }static struct svc_xprt_ops svc_tcp_ops = { + .xpo_recvfrom = svc_tcp_recvfrom, + .xpo_sendto = svc_tcp_sendto, };static struct svc_xprt_class svc_tcp_class = {
@@ -1382,8 +1384,6 @@ svc_tcp_init(struct svc_sock *svsk)struct tcp_sock *tp =tcp_sk (sk);svc_xprt_init (&svc_tcp_class, &svsk->sk_xprt); - svsk->sk_recvfrom = svc_tcp_recvfrom; - svsk->sk_sendto = svc_tcp_sendto;if (sk->sk_state ==TCP_LISTEN ) {dprintk ("setting up TCP socket for listening\n" );
@@ -1531,7 +1531,7 @@ svc_recv(struct svc_rqst *rqstp, long timeout)dprintk ("svc: server %p, pool %u, socket %p, inuse=%d\n" , rqstp, pool->sp_id, svsk,atomic_read (&svsk->sk_inuse)); - len = svsk->sk_recvfrom (rqstp); + len = svsk->sk_xprt.xpt_ops->xpo_recvfrom (rqstp);dprintk ("svc: got len=%d\n" , len);/* No data, incomplete (TCP) read, or accept() */
@@ -1591,7 +1591,7 @@ svc_send(struct svc_rqst *rqstp)if (test_bit (SK_DEAD , &svsk->sk_flags)) len = -ENOTCONN ;else - len = svsk->sk_sendto (rqstp); + len = svsk->sk_xprt.xpt_ops->xpo_sendto (rqstp);mutex_unlock (&svsk->sk_mutex);svc_sock_release (rqstp);
PATCH 6/38 svc: Add transport specific xpo_release function
In reply to a message not in the archiveThe svc_sock_release function releases pages allocated to a thread. For UDP, this also returns the receive skb to the stack. For RDMA it will post a receive WR and bump the client credit count.
---
include/linux/sunrpc/svc.h | 2 +- include/linux/sunrpc/svc_xprt.h | 1 + net/sunrpc/svcsock.c | 17 +++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-)
include/linux/sunrpc/svc.h +1 -1
@@ -217,7 +217,7 @@ struct svc_rqst {struct auth_ops * rq_authop;/* authentication flavour */ u32 rq_flavor;/* pseudoflavor */ struct svc_cred rq_cred;/* auth info */ -struct sk_buff * rq_skbuff;/* fast recv inet buffer */ +void * rq_xprt_ctxt;/* transport specific context ptr */ struct svc_deferred_req *rq_deferred;/* deferred request we are replaying */ struct xdr_buf rq_arg;
include/linux/sunrpc/svc_xprt.h +1 -0
@@ -12,6 +12,7 @@struct svc_xprt_ops {int (*xpo_recvfrom)(struct svc_rqst *);int (*xpo_sendto)(struct svc_rqst *); +void (*xpo_release_rqst)(struct svc_rqst *); };struct svc_xprt_class {
net/sunrpc/svcsock.c +9 -8
@@ -185,14 +185,13 @@ svc_thread_dequeue(struct svc_pool *pool, struct svc_rqst *rqstp)/* * Release an skbuff after use */ -static inline void -svc_release_skb (struct svc_rqst *rqstp) +static void svc_release_skb (struct svc_rqst *rqstp) { -struct sk_buff *skb = rqstp->rq_skbuff; +struct sk_buff *skb = rqstp->rq_xprt_ctxt;struct svc_deferred_req *dr = rqstp->rq_deferred;if (skb) { - rqstp->rq_skbuff =NULL ; + rqstp->rq_xprt_ctxt =NULL ;dprintk ("svc: service %p, releasing skb %p\n" , rqstp, skb);skb_free_datagram (rqstp->rq_sock->sk_sk, skb);
@@ -395,7 +394,7 @@ svc_sock_release(struct svc_rqst *rqstp) {struct svc_sock *svsk = rqstp->rq_sock; -svc_release_skb (rqstp); + rqstp->rq_xprt->xpt_ops->xpo_release_rqst (rqstp);svc_free_res_pages (rqstp); rqstp->rq_res.page_len =0 ;
@@ -867,7 +866,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)skb_free_datagram (svsk->sk_sk, skb);return 0 ; } - rqstp->rq_skbuff = skb; + rqstp->rq_xprt_ctxt = skb; } rqstp->rq_arg.page_base =0 ;
@@ -903,6 +902,7 @@ svc_udp_sendto(struct svc_rqst *rqstp)static struct svc_xprt_ops svc_udp_ops = { .xpo_recvfrom = svc_udp_recvfrom, .xpo_sendto = svc_udp_sendto, + .xpo_release_rqst = svc_release_skb, };static struct svc_xprt_class svc_udp_class = {
@@ -1291,7 +1291,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp) rqstp->rq_arg.page_len = len - rqstp->rq_arg.head[0 ].iov_len; } - rqstp->rq_skbuff =NULL ; + rqstp->rq_xprt_ctxt =NULL ; rqstp->rq_prot =IPPROTO_TCP ;/* Reset TCP read info */
@@ -1357,6 +1357,7 @@ svc_tcp_sendto(struct svc_rqst *rqstp)static struct svc_xprt_ops svc_tcp_ops = { .xpo_recvfrom = svc_tcp_recvfrom, .xpo_sendto = svc_tcp_sendto, + .xpo_release_rqst = svc_release_skb, };static struct svc_xprt_class svc_tcp_class = {
@@ -1578,7 +1579,7 @@ svc_send(struct svc_rqst *rqstp) }/* release the receive skb before sending the reply */ -svc_release_skb (rqstp); + rqstp->rq_xprt->xpt_ops->xpo_release_rqst (rqstp);/* calculate over-all length */ xb = & rqstp->rq_res;
A message that is not in the archive (sent off-list or not yet received): 20071211233206.15718.73282.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org
Re: [PATCH 06/38] svc: Add transport specific xpo_release function
Quoted 3 lines · Tom Tucker
The
svc_sock_releasefunction releases pages allocated to a thread. For UDP, this also returns the receive skb to the stack.
The stack? How about just "frees the receive skb"?
Quoted 110 lines
For RDMA it will
post a receive WR and bump the client credit count.Signed-off-by Tom Tucker <[email protected]>---
include/linux/sunrpc/svc.h | 2 +- include/linux/sunrpc/svc_xprt.h | 1 + net/sunrpc/svcsock.c | 17 +++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-)include/linux/sunrpc/svc.h +1
-1@@ -217,7 +217,7 @@ struct svc_rqst {struct auth_ops * rq_authop;/* authentication flavour */ u32 rq_flavor;/* pseudoflavor */ struct svc_cred rq_cred;/* auth info */ -struct sk_buff * rq_skbuff;/* fast recv inet buffer */ +void * rq_xprt_ctxt;/* transport specific context ptr */ struct svc_deferred_req *rq_deferred;/* deferred request we are replaying */ struct xdr_buf rq_arg;include/linux/sunrpc/svc_xprt.h +1
-0@@ -12,6 +12,7 @@struct svc_xprt_ops {int (*xpo_recvfrom)(struct svc_rqst *);int (*xpo_sendto)(struct svc_rqst *); +void (*xpo_release_rqst)(struct svc_rqst *); };struct svc_xprt_class {net/sunrpc/svcsock.c +9
-8@@ -185,14 +185,13 @@ svc_thread_dequeue(struct svc_pool *pool, struct svc_rqst *rqstp)/* * Release an skbuff after use */ -static inline void -svc_release_skb (struct svc_rqst *rqstp) +static void svc_release_skb (struct svc_rqst *rqstp) { -struct sk_buff *skb = rqstp->rq_skbuff; +struct sk_buff *skb = rqstp->rq_xprt_ctxt;struct svc_deferred_req *dr = rqstp->rq_deferred;if (skb) { - rqstp->rq_skbuff =NULL ; + rqstp->rq_xprt_ctxt =NULL ;dprintk ("svc: service %p, releasing skb %p\n" , rqstp, skb);skb_free_datagram (rqstp->rq_sock->sk_sk, skb);@@ -395,7 +394,7 @@ svc_sock_release(struct svc_rqst *rqstp) {struct svc_sock *svsk = rqstp->rq_sock; -svc_release_skb (rqstp); + rqstp->rq_xprt->xpt_ops->xpo_release_rqst (rqstp);svc_free_res_pages (rqstp); rqstp->rq_res.page_len =0 ;@@ -867,7 +866,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)skb_free_datagram (svsk->sk_sk, skb);return 0 ; } - rqstp->rq_skbuff = skb; + rqstp->rq_xprt_ctxt = skb; } rqstp->rq_arg.page_base =0 ;@@ -903,6 +902,7 @@ svc_udp_sendto(struct svc_rqst *rqstp)static struct svc_xprt_ops svc_udp_ops = { .xpo_recvfrom = svc_udp_recvfrom, .xpo_sendto = svc_udp_sendto, + .xpo_release_rqst = svc_release_skb, };static struct svc_xprt_class svc_udp_class = {@@ -1291,7 +1291,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp) rqstp->rq_arg.page_len = len - rqstp->rq_arg.head[0 ].iov_len; } - rqstp->rq_skbuff =NULL ; + rqstp->rq_xprt_ctxt =NULL ; rqstp->rq_prot =IPPROTO_TCP ;/* Reset TCP read info */ @@ -1357,6 +1357,7 @@ svc_tcp_sendto(struct svc_rqst *rqstp)static struct svc_xprt_ops svc_tcp_ops = { .xpo_recvfrom = svc_tcp_recvfrom, .xpo_sendto = svc_tcp_sendto, + .xpo_release_rqst = svc_release_skb, };static struct svc_xprt_class svc_tcp_class = {@@ -1578,7 +1579,7 @@ svc_send(struct svc_rqst *rqstp) }/* release the receive skb before sending the reply */ -svc_release_skb (rqstp); + rqstp->rq_xprt->xpt_ops->xpo_release_rqst (rqstp);/* calculate over-all length */ xb = & rqstp->rq_res;
Re: [PATCH 06/38] svc: Add transport specific xpo_release function
Quoted 7 lines · J. Bruce Fields
Quoted 3 lines · Tom Tucker
The
svc_sock_releasefunction releases pages allocated to a thread. For UDP, this also returns the receive skb to the stack.The stack? How about just "frees the receive skb"?
Ok.
Quoted 112 lines
Quoted 112 lines
For RDMA it will
post a receive WR and bump the client credit count.Signed-off-by Tom Tucker <[email protected]>---
include/linux/sunrpc/svc.h | 2 +- include/linux/sunrpc/svc_xprt.h | 1 + net/sunrpc/svcsock.c | 17 +++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-)include/linux/sunrpc/svc.h +0
-0@@ -217,7 +217,7 @@ struct svc_rqst {struct
auth_ops*rq_authop; /* authentication flavour */
u32rq_flavor; /* pseudoflavor */
structsvc_credrq_cred; /* auth info */
- structsk_buff*rq_skbuff; /* fast recv inet buffer */
+ void *rq_xprt_ctxt; /* transport specific context ptr */
struct svc_deferred_req*rq_deferred; /* deferred request we are replaying */struct
xdr_bufrq_arg;include/linux/sunrpc/svc_xprt.h +1
-0@@ -12,6 +12,7 @@struct svc_xprt_ops {int (*xpo_recvfrom)(struct svc_rqst *);int (*xpo_sendto)(struct svc_rqst *); +void (*xpo_release_rqst)(struct svc_rqst *); };struct svc_xprt_class {net/sunrpc/svcsock.c +3
-4@@ -185,14 +185,13 @@ svc_thread_dequeue(struct svc_pool *pool, struct svc_rqst *rqstp)/* * Release an skbuff after use */ -static inline void -svc_release_skb (struct svc_rqst *rqstp) +static void svc_release_skb (struct svc_rqst *rqstp) { -struct sk_buff *skb = rqstp->rq_skbuff; +struct sk_buff *skb = rqstp->rq_xprt_ctxt;struct svc_deferred_req *dr = rqstp->rq_deferred;if (skb) { - rqstp->rq_skbuff =NULL ; + rqstp->rq_xprt_ctxt =NULL ;dprintk ("svc: service %p, releasing skb %p\n" , rqstp, skb);
skb_free_datagram(rqstp->rq_sock->sk_sk, skb);net/sunrpc/svcsock.c +6
-4@@ -395,7 +394,7 @@ svc_sock_release(struct svc_rqst *rqstp) {struct svc_sock *svsk = rqstp->rq_sock; -svc_release_skb (rqstp); + rqstp->rq_xprt->xpt_ops->xpo_release_rqst (rqstp);svc_free_res_pages (rqstp); rqstp->rq_res.page_len =0 ;@@ -867,7 +866,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)skb_free_datagram (svsk->sk_sk, skb);return 0 ; } - rqstp->rq_skbuff = skb; + rqstp->rq_xprt_ctxt = skb; } rqstp->rq_arg.page_base =0 ;@@ -903,6 +902,7 @@ svc_udp_sendto(struct svc_rqst *rqstp)static struct svc_xprt_ops svc_udp_ops = { .xpo_recvfrom = svc_udp_recvfrom, .xpo_sendto = svc_udp_sendto, + .xpo_release_rqst = svc_release_skb, };static struct svc_xprt_class svc_udp_class = {@@ -1291,7 +1291,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp) rqstp->rq_arg.page_len = len - rqstp->rq_arg.head[0 ].iov_len; } - rqstp->rq_skbuff =NULL ; + rqstp->rq_xprt_ctxt =NULL ; rqstp->rq_prot =IPPROTO_TCP ;/* Reset TCP read info */ @@ -1357,6 +1357,7 @@ svc_tcp_sendto(struct svc_rqst *rqstp)static struct svc_xprt_ops svc_tcp_ops = { .xpo_recvfrom = svc_tcp_recvfrom, .xpo_sendto = svc_tcp_sendto, + .xpo_release_rqst = svc_release_skb, };static struct svc_xprt_class svc_tcp_class = {@@ -1578,7 +1579,7 @@ svc_send(struct svc_rqst *rqstp) }/* release the receive skb before sending the reply */ -svc_release_skb (rqstp); + rqstp->rq_xprt->xpt_ops->xpo_release_rqst (rqstp);/* calculate over-all length */ xb = & rqstp->rq_res;
PATCH 7/38 svc: Add per-transport delete functions
In reply to a message not in the archiveAdd transport specific xpo_detach and xpo_free functions. The xpo_detach function causes the transport to stop delivering data-ready events and enqueing the transport for I/O.
The xpo_free function frees all resources associated with the particular transport instance.
---
include/linux/sunrpc/svc_xprt.h | 2 + net/sunrpc/svcsock.c | 56 ++++++++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 13 deletions(-)
include/linux/sunrpc/svc_xprt.h +2 -0
@@ -13,6 +13,8 @@ struct svc_xprt_ops {int (*xpo_recvfrom)(struct svc_rqst *);int (*xpo_sendto)(struct svc_rqst *);void (*xpo_release_rqst)(struct svc_rqst *); +void (*xpo_detach)(struct svc_xprt *); +void (*xpo_free)(struct svc_xprt *); };struct svc_xprt_class {
net/sunrpc/svcsock.c +43 -13
92 lines not on this page · raw message
PATCH 8/38 svc: Add xpo_prep_reply_hdr
In reply to a message not in the archiveSome transports add fields to the RPC header for replies, e.g. the TCP record length. This function is called when preparing the reply header to allow each transport to add whatever fields it requires.
---
include/linux/sunrpc/svc_xprt.h | 1 + net/sunrpc/svc.c | 6 +++--- net/sunrpc/svcsock.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-)
include/linux/sunrpc/svc_xprt.h +1 -0
@@ -11,6 +11,7 @@struct svc_xprt_ops {int (*xpo_recvfrom)(struct svc_rqst *); +void (*xpo_prep_reply_hdr)(struct svc_rqst *);int (*xpo_sendto)(struct svc_rqst *);void (*xpo_release_rqst)(struct svc_rqst *);void (*xpo_detach)(struct svc_xprt *);
net/sunrpc/svc.c +3 -3
@@ -839,9 +839,9 @@ svc_process(struct svc_rqst *rqstp) rqstp->rq_res.tail[0 ].iov_len =0 ;/* Will be turned off only in gss privacy case: */ rqstp->rq_splice_ok =1 ; -/* tcp needs a space for the record length... */ -if (rqstp->rq_prot ==IPPROTO_TCP ) -svc_putnl (resv,0 ); + +/* Setup reply header */ + rqstp->rq_xprt->xpt_ops->xpo_prep_reply_hdr (rqstp); rqstp->rq_xid =svc_getu32 (argv);svc_putu32 (resv, rqstp->rq_xid);
net/sunrpc/svcsock.c +17 -0
@@ -893,12 +893,17 @@ svc_udp_sendto(struct svc_rqst *rqstp)return error; } +static void svc_udp_prep_reply_hdr (struct svc_rqst *rqstp) +{ +} +static struct svc_xprt_ops svc_udp_ops = { .xpo_recvfrom = svc_udp_recvfrom, .xpo_sendto = svc_udp_sendto, .xpo_release_rqst = svc_release_skb, .xpo_detach = svc_sock_detach, .xpo_free = svc_sock_free, + .xpo_prep_reply_hdr = svc_udp_prep_reply_hdr, };static struct svc_xprt_class svc_udp_class = {
@@ -1350,12 +1355,24 @@ svc_tcp_sendto(struct svc_rqst *rqstp)return sent; } +/* +* Setup response header. TCP has a 4B record length field. +*/ +static void svc_tcp_prep_reply_hdr (struct svc_rqst *rqstp) +{ +struct kvec *resv = &rqstp->rq_res.head[0 ]; + +/* tcp needs a space for the record length... */ +svc_putnl (resv,0 ); +} +static struct svc_xprt_ops svc_tcp_ops = { .xpo_recvfrom = svc_tcp_recvfrom, .xpo_sendto = svc_tcp_sendto, .xpo_release_rqst = svc_release_skb, .xpo_detach = svc_sock_detach, .xpo_free = svc_sock_free, + .xpo_prep_reply_hdr = svc_tcp_prep_reply_hdr, };static struct svc_xprt_class svc_tcp_class = {
PATCH 9/38 svc: Add a transport function that checks for write space
In reply to a message not in the archiveIn order to avoid blocking a service thread, the receive side checks to see if there is sufficient write space to reply to the request. Each transport has a different mechanism for determining if there is enough write space to reply.
The code that checked for write space was coupled with code that checked for CLOSE and CONN. These checks have been broken out into separate statements to make the code easier to read.
---
include/linux/sunrpc/svc_xprt.h | 1 net/sunrpc/svcsock.c | 82 +++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 26 deletions(-)
include/linux/sunrpc/svc_xprt.h +1 -0
@@ -10,6 +10,7 @@#include <linux/sunrpc/svc.h> struct svc_xprt_ops { +int (*xpo_has_wspace)(struct svc_xprt *);int (*xpo_recvfrom)(struct svc_rqst *);void (*xpo_prep_reply_hdr)(struct svc_rqst *);int (*xpo_sendto)(struct svc_rqst *);
net/sunrpc/svcsock.c +56 -26
124 lines not on this page · raw message
A message that is not in the archive (sent off-list or not yet received): 20071211233212.15718.69282.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org
Re: [PATCH 09/38] svc: Add a transport function that checks for write space
Hi Tom-
Quoted 142 lines · Tom Tucker
In order to avoid blocking a service thread, the receive side checks to see if there is sufficient write space to reply to the request. Each transport has a different mechanism for determining if there is enough write space to reply.
The code that checked for write space was coupled with code that checked for CLOSE and CONN. These checks have been broken out into separate statements to make the code easier to read.
Signed-off-by Tom Tucker <[email protected]>---
include/linux/sunrpc/svc_xprt.h | 1 net/sunrpc/svcsock.c | 82 ++++++++++++++++++++++++++ +------------ 2 files changed, 57 insertions(+), 26 deletions(-)include/linux/sunrpc/svc_xprt.h +1
-0@@ -10,6 +10,7 @@#include <linux/sunrpc/svc.h> struct svc_xprt_ops { +int (*xpo_has_wspace)(struct svc_xprt *);int (*xpo_recvfrom)(struct svc_rqst *);void (*xpo_prep_reply_hdr)(struct svc_rqst *);int (*xpo_sendto)(struct svc_rqst *);net/sunrpc/svcsock.c +0
-16@@ -205,22 +205,6 @@ static void 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. *
net/sunrpc/svcsock.c +30
-10@@ -269,22 +253,24 @@ 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)) - && !test_bit (SK_CLOSE , &svsk->sk_flags) - && !test_bit (SK_CONN , &svsk->sk_flags)) { +/* Handle pending connection */ +if (test_bit (SK_CONN , &svsk->sk_flags)) + goto process; + +/* Handle close in-progress */ +if (test_bit (SK_CLOSE , &svsk->sk_flags)) + goto process; + +/* Check if we have space to reply to a request */ +if (!svsk->sk_xprt.xpt_ops->xpo_has_wspace (&svsk->sk_xprt)) {/* 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)); +dprintk ("svc: no write space, socket %p not enqueued\n" , svsk); svsk->sk_pool =NULL ;clear_bit (SK_BUSY , &svsk->sk_flags); goto out_unlock; } -clear_bit (SOCK_NOSPACE , &svsk->sk_sock->flags); - + process:if (!list_empty (&pool->sp_threads)) { rqstp = list_entry(pool->sp_threads.next, struct svc_rqst,@@ -897,6 +883,24 @@ static void svc_udp_prep_reply_hdr(struct svc_rqst *rqstp) { } +static int svc_udp_has_wspace (struct svc_xprt *xprt) +{ + struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); +struct svc_serv *serv = svsk->sk_server; +unsigned long required; + +/* +* Set the SOCK_NOSPACE flag before checking the available +* sock space. +*/ +set_bit (SOCK_NOSPACE , &svsk->sk_sock->flags); + required =atomic_read (&svsk->sk_reserved) + serv->sv_max_mesg; +if (required*2 >sock_wspace (svsk->sk_sk)) +return 0 ; +clear_bit (SOCK_NOSPACE , &svsk->sk_sock->flags); +return 1 ; +} +static struct svc_xprt_ops svc_udp_ops = {net/sunrpc/svcsock.c +10
-0.xpo_recvfrom = svc_udp_recvfrom, .xpo_sendto = svc_udp_sendto,@@ -904,6 +908,7 @@ static struct svc_xprt_ops svc_udp_ops = { .xpo_detach = svc_sock_detach, .xpo_free = svc_sock_free, .xpo_prep_reply_hdr = svc_udp_prep_reply_hdr, + .xpo_has_wspace = svc_udp_has_wspace, };static struct svc_xprt_class svc_udp_class = {@@ -1366,6 +1371,30 @@ static void svc_tcp_prep_reply_hdr(struct svc_rqst *rqstp) svc_putnl(resv, 0); } +static int svc_tcp_has_wspace (struct svc_xprt *xprt) +{ + struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); +struct svc_serv *serv = svsk->sk_server; +int required; +int wspace; + +/* +* Set the SOCK_NOSPACE flag before checking the available
net/sunrpc/svcsock.c static void svc_tcp_prep_reply_hdr(struct · line 1394
Quoted 10 lines
net/sunrpc/svcsock.c +10
-0+* sock space. +*/ +set_bit (SOCK_NOSPACE , &svsk->sk_sock->flags); + required =atomic_read (&svsk->sk_reserved) + serv->sv_max_mesg; + wspace =sk_stream_wspace (svsk->sk_sk); + +if (wspace <sk_stream_min_wspace (svsk->sk_sk)) +return 0 ; +if (required *2 > wspace) +return 0 ;
Since "required" is an int, this test can behave differently than the one it replaces.
What's the test plan to ensure the new test works reasonably? (Actually that's a question for the Maintainers too).
Quoted 9 lines
net/sunrpc/svcsock.c +5
-0+ +clear_bit (SOCK_NOSPACE , &svsk->sk_sock->flags); +return 1 ; +} +static struct svc_xprt_ops svc_tcp_ops = {net/sunrpc/svcsock.c +0
-0.xpo_recvfrom = svc_tcp_recvfrom, .xpo_sendto = svc_tcp_sendto,
net/sunrpc/svcsock.c static struct svc_xprt_ops svc_tcp_ops = { · line 1408
Quoted 7 lines
net/sunrpc/svcsock.c +1
-0@@ -1373,6 +1402,7 @@ static struct svc_xprt_ops svc_tcp_ops = { .xpo_detach = svc_sock_detach, .xpo_free = svc_sock_free, .xpo_prep_reply_hdr = svc_tcp_prep_reply_hdr, + .xpo_has_wspace = svc_tcp_has_wspace, };static struct svc_xprt_class svc_tcp_class = {
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
Re: [PATCH 09/38] svc: Add a transport function that checks for write space
Quoted 4 lines · Chuck Lever
Hi Tom-
Quoted 1 line · Tom Tucker
In order to avoid blocking a service thread, the receive side checks
[...snip...]
Quoted 24 lines
Quoted 10 lines
net/sunrpc/svcsock.c +3
-0+static int svc_tcp_has_wspace (struct svc_xprt *xprt) +{ + struct svc_sock *svsk = container_of(xprt, struct svc_sock,
sk_xprt);net/sunrpc/svcsock.c +6
-0+struct svc_serv *serv = svsk->sk_server; +int required; +int wspace; + +/* +* Set the SOCK_NOSPACE flag before checking the available net/sunrpc/svcsock.c static void svc_tcp_prep_reply_hdr(struct svc_rqst *rqstp) · line 1392
Quoted 10 lines
net/sunrpc/svcsock.c +10
-0+* sock space. +*/ +set_bit (SOCK_NOSPACE , &svsk->sk_sock->flags); + required =atomic_read (&svsk->sk_reserved) + serv->sv_max_mesg; + wspace =sk_stream_wspace (svsk->sk_sk); + +if (wspace <sk_stream_min_wspace (svsk->sk_sk)) +return 0 ; +if (required *2 > wspace) +return 0 ;Since "required" is an int, this test can behave differently than the one it replaces.
Quoted 3 lines
What's the test plan to ensure the new test works reasonably? (Actually that's a question for the Maintainers too).
Here's my matrix:
Connectathon iozone Kernel build
V2 udp,tcp
V3 tcp,rdma tcp,rdma tcp,rdma
V4 tcp,rdma tcp,rdma tcp,rdma
I also kill tests to test the signal race paths, and I run multiple tests concurrently (e.g. a couple iozones plus a kernel build).
I guess none of these tests explicitly test the path in question though.
Quoted 24 lines
Quoted 9 lines
net/sunrpc/svcsock.c +5
-0+ +clear_bit (SOCK_NOSPACE , &svsk->sk_sock->flags); +return 1 ; +} +static struct svc_xprt_ops svc_tcp_ops = { .xpo_recvfrom = svc_tcp_recvfrom, .xpo_sendto = svc_tcp_sendto,net/sunrpc/svcsock.c static struct svc_xprt_ops svc_tcp_ops = { · line 1408
Quoted 7 lines
net/sunrpc/svcsock.c +1
-0@@ -1373,6 +1402,7 @@ static struct svc_xprt_ops svc_tcp_ops = { .xpo_detach = svc_sock_detach, .xpo_free = svc_sock_free, .xpo_prep_reply_hdr = svc_tcp_prep_reply_hdr, + .xpo_has_wspace = svc_tcp_has_wspace, };static struct svc_xprt_class svc_tcp_class = {--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
-
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
Re: [PATCH 09/38] svc: Add a transport function that checks for write space
In reply to Chuck LeverQuoted 11 lines · Chuck Lever
net/sunrpc/svcsock.c static void svc_tcp_prep_reply_hdr(struct svc_rqst *rqstp) · line 1392
Quoted 7 lines · Tom Tucker
net/sunrpc/svcsock.c +7
-0+ required =atomic_read (&svsk->sk_reserved) + serv->sv_max_mesg; + wspace =sk_stream_wspace (svsk->sk_sk); + +if (wspace <sk_stream_min_wspace (svsk->sk_sk)) +return 0 ; +if (required *2 > wspace) +return 0 ;Since "required" is an int, this test can behave differently than the one it replaces.
If sk_reserved can approach half of 2^31, for example, then surely we have bigger problems?
--b.
Re: [PATCH 09/38] svc: Add a transport function that checks for write space
Quoted 13 lines · J. Bruce Fields
Quoted 11 lines · Chuck Lever
net/sunrpc/svcsock.c static void svc_tcp_prep_reply_hdr(struct svc_rqst *rqstp) · line 1392
Quoted 7 lines · Tom Tucker
net/sunrpc/svcsock.c +7
-0+ required =atomic_read (&svsk->sk_reserved) + serv->sv_max_mesg; + wspace =sk_stream_wspace (svsk->sk_sk); + +if (wspace <sk_stream_min_wspace (svsk->sk_sk)) +return 0 ; +if (required *2 > wspace) +return 0 ;Since "required" is an int, this test can behave differently than the one it replaces.
Quoted 2 lines
If
sk_reservedcan approach half of 2^31, for example, then surely we have bigger problems?
What stops sk_reserved from going negative?
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
Re: [PATCH 09/38] svc: Add a transport function that checks for write space
Quoted 15 lines · Chuck Lever
Quoted 14 lines · J. Bruce Fields
Quoted 12 lines · Chuck Lever
net/sunrpc/svcsock.c static void svc_tcp_prep_reply_hdr(struct svc_rqst *rqstp) · line 1392
Quoted 7 lines · Tom Tucker
net/sunrpc/svcsock.c +7
-0+ required =atomic_read (&svsk->sk_reserved) + serv->sv_max_mesg; + wspace =sk_stream_wspace (svsk->sk_sk); + +if (wspace <sk_stream_min_wspace (svsk->sk_sk)) +return 0 ; +if (required *2 > wspace) +return 0 ;Since "required" is an int, this test can behave differently than the one
it replaces.
Quoted 5 lines
Quoted 2 lines
If
sk_reservedcan approach half of 2^31, for example, then surely we have bigger problems?What stops
sk_reservedfrom going negative?
Nothing actively _stops_ it from going negative. Indirectly it is prevented by the "fact" that sv_max_mesg is always greater than the amount returned by any read on the socket. If this is not true, then sk_reserved can go negative. That would occur in svc_recv when the difference between the amount currently reserved (worst case sv_max_mesg) and the amount read is subtracted from the amount reserved. If the amount read were greater than sv_max_mesg then the result would be negative (both meanings intended).
I could add a BUG_ON and run some tests.
Quoted 4 lines
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 09/38] svc: Add a transport function that checks for write space
Quoted 32 lines · Tom Tucker
Quoted 15 lines · Chuck Lever
Quoted 14 lines · J. Bruce Fields
Quoted 12 lines · Chuck Lever
Review
Quoted 7 lines · Tom Tucker
(quoted diff) +7
-0+ required = atomic_read(&svsk->sk_reserved) + serv->sv_max_mesg; + wspace = sk_stream_wspace(svsk->sk_sk); + + if (wspace < sk_stream_min_wspace(svsk->sk_sk)) + return 0; + if (required * 2 > wspace) + return 0;Since "required" is an int, this test can behave differently than the one
it replaces.Quoted 5 lines
Quoted 2 lines
If
sk_reservedcan approach half of 2^31, for example, then surely we have bigger problems?What stops
sk_reservedfrom going negative?Nothing actively _stops_ it from going negative. Indirectly it is prevented by the "fact" that
sv_max_mesgis always greater than the amount returned by any read on the socket. If this is not true, thensk_reservedcan go negative. That would occur insvc_recvwhen the difference between the amount currently reserved (worst casesv_max_mesg) and the amount read is subtracted from the amount reserved. If the amount read were greater thansv_max_mesgthen the result would be negative (both meanings intended).
Quoted 1 line
I could add a
BUG_ONand run some tests.
I have to admit, I'm completely and utterly lost here. Chuck, could you explain exactly, in detail, how you think this change could cause a bug?
--b.
Re: [PATCH 09/38] svc: Add a transport function that checks for write space
Quoted 33 lines · J. Bruce Fields
Quoted 32 lines · Tom Tucker
Quoted 15 lines · Chuck Lever
Quoted 14 lines · J. Bruce Fields
Quoted 12 lines · Chuck Lever
Review
Quoted 7 lines · Tom Tucker
(quoted diff) +7
-0+ required = atomic_read(&svsk->sk_reserved) + serv->sv_max_mesg; + wspace = sk_stream_wspace(svsk->sk_sk); + + if (wspace < sk_stream_min_wspace(svsk->sk_sk)) + return 0; + if (required * 2 > wspace) + return 0;Since "required" is an int, this test can behave differently than the one
it replaces.Quoted 5 lines
Quoted 2 lines
If
sk_reservedcan approach half of 2^31, for example, then surely we have bigger problems?What stops
sk_reservedfrom going negative?Nothing actively _stops_ it from going negative. Indirectly it is prevented by the "fact" that
sv_max_mesgis always greater than the amount returned by any read on the socket. If this is not true, thensk_reservedcan go negative. That would occur insvc_recvwhen the difference between the amount currently reserved (worst casesv_max_mesg) and the amount read is subtracted from the amount reserved. If the amount read were greater thansv_max_mesgthen the result would be negative (both meanings intended).
Quoted 4 lines
Quoted 1 line
I could add a
BUG_ONand run some tests.I have to admit, I'm completely and utterly lost here. Chuck, could you explain exactly, in detail, how you think this change could cause a bug?
The original code has this:
static inline unsigned longsvc_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;
}...
if (((atomic_read(&svsk->sk_reserved) + serv->sv_max_mesg)*2 > svc_sock_wspace(svsk))
Since svc_sock_wspace() returns an unsigned long, that means the sum above is always converted to unsigned long. If sk_reserved goes negative, then the sum becomes a large positive.
Note that in the TCP case, sk_stream_wspace() returns an int, which is also converted to an unsigned long by svc_sock_wspace(). sk_stream_wspace() can return a negative if sk_wmem_queued happens to become larger than sk_sndbuf.
In all the other wspace callbacks I checked, the result of sk_stream_wspace() is compared to sk_stream_min_space() -- comparing an int to an int -- which means if sk_stream_wspace()'s result *does* go negative, those comparisons will catch it and do the right thing.
In the original RPC server implementation, though, sk_stream_wspace()'s result is converted to unsigned long; negative return values thus become large positives.
In both of these scenarios, the large positives make the comparison behave in exactly the opposite way we might expect it to. Tom's code fixes this by making "required" an int for the TCP case so we still get an int-to-int comparison.
Because the original is coded the way it is, however, it's difficult to tell whether the signedness of these variables was intended for some clever effect, or whether it was an oversight. If this was intentional, the new wspace check for TCP could have unintended performance consequences.
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
Re: [PATCH 09/38] svc: Add a transport function that checks for write space
In reply to a message not in the archiveQuoted 31 lines · Tom Tucker
Quoted 15 lines · Chuck Lever
Quoted 14 lines · J. Bruce Fields
Quoted 12 lines · Chuck Lever
Review
Quoted 7 lines · Tom Tucker
(quoted diff) +7
-0+ required = atomic_read(&svsk->sk_reserved) + serv->sv_max_mesg; + wspace = sk_stream_wspace(svsk->sk_sk); + + if (wspace < sk_stream_min_wspace(svsk->sk_sk)) + return 0; + if (required * 2 > wspace) + return 0;Since "required" is an int, this test can behave differently than the one
it replaces.Quoted 5 lines
Quoted 2 lines
If
sk_reservedcan approach half of 2^31, for example, then surely we have bigger problems?What stops
sk_reservedfrom going negative?Nothing actively _stops_ it from going negative. Indirectly it is prevented by the "fact" that
sv_max_mesgis always greater than the amount returned by any read on the socket. If this is not true, thensk_reservedcan go negative. That would occur insvc_recvwhen the difference between the amount currently reserved (worst casesv_max_mesg) and the amount read is subtracted from the amount reserved. If the amount read were greater thansv_max_mesgthen the result would be negative (both meanings intended).
Quoted 1 line
I could add a
BUG_ONand run some tests.
My (limited) understanding is that the amount of socket output buffer space the server thinks it needs for sending a reply is subtracted from sk_reserved. So it seems like svc_reserve() would be the place to assert that sk_reserved does not go negative.
As this is used mostly by svc_reserve_auth(), that suggests that a reasonable test case would be running a read/write intensive workload with some security flavor that uses large authenticators.
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
PATCH 10/38 svc: Move close processing to a single place
In reply to a message not in the archiveClose handling was duplicated in the UDP and TCP recvfrom methods. This code has been moved to the transport independent svc_recv function.
---
net/sunrpc/svcsock.c | 24 ++++++++++-------------- 1 files changed, 10 insertions(+), 14 deletions(-)
net/sunrpc/svcsock.c +10 -14
@@ -776,11 +776,6 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)return svc_deferred_recv (rqstp); } -if (test_bit (SK_CLOSE , &svsk->sk_flags)) { -svc_delete_socket (svsk); -return 0 ; - } -clear_bit (SK_DATA , &svsk->sk_flags); skb =NULL ; err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
@@ -1181,11 +1176,6 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)return svc_deferred_recv (rqstp); } -if (test_bit (SK_CLOSE , &svsk->sk_flags)) { -svc_delete_socket (svsk); -return 0 ; - } -if (svsk->sk_sk->sk_state ==TCP_LISTEN ) {svc_tcp_accept (svsk);svc_sock_received (svsk);
@@ -1575,10 +1565,16 @@ svc_recv(struct svc_rqst *rqstp, long timeout) }spin_unlock_bh (&pool->sp_lock); -dprintk ("svc: server %p, pool %u, socket %p, inuse=%d\n" , - rqstp, pool->sp_id, svsk,atomic_read (&svsk->sk_inuse)); - len = svsk->sk_xprt.xpt_ops->xpo_recvfrom (rqstp); -dprintk ("svc: got len=%d\n" , len); + len =0 ; +if (test_bit (SK_CLOSE , &svsk->sk_flags)) { +dprintk ("svc_recv: found SK_CLOSE\n" ); +svc_delete_socket (svsk); + }else { +dprintk ("svc: server %p, pool %u, socket %p, inuse=%d\n" , + rqstp, pool->sp_id, svsk,atomic_read (&svsk->sk_inuse)); + len = svsk->sk_xprt.xpt_ops->xpo_recvfrom (rqstp); +dprintk ("svc: got len=%d\n" , len); + }/* No data, incomplete (TCP) read, or accept() */ if (len ==0 || len == -EAGAIN ) {
PATCH 11/38 svc: Add xpo_accept transport function
In reply to a message not in the archivePreviously, the accept logic looked into the socket state to determine whether to call accept or recv when data-ready was indicated on an endpoint. Since some transports don't use sockets, this logic was changed to use a flag bit (SK_LISTENER) to identify listening endpoints. A transport function (xpo_accept) was added to allow each transport to define its own accept processing. A transport's initialization logic is reponsible for setting the SK_LISTENER bit. I didn't see any way to do this in transport independent logic since the passive side of a UDP connection doesn't listen and always recv's.
In the svc_recv function, if the SK_LISTENER bit is set, the transport xpo_accept function is called to handle accept processing.
Note that all functions are defined even if they don't make sense for a given transport. For example, accept doesn't mean anything for UDP. The function is defined anyway and bug checks if called. The UDP transport should never set the SK_LISTENER bit.
The code that poaches connections when the connection limit is hit was moved to a subroutine to make the accept logic path easier to follow. Since this is in the new connection path, it should not be a performance issue.
---
include/linux/sunrpc/svc_xprt.h | 1 include/linux/sunrpc/svcsock.h | 1 net/sunrpc/svcsock.c | 128 +++++++++++++++++++++------------------ 3 files changed, 72 insertions(+), 58 deletions(-)
include/linux/sunrpc/svc_xprt.h +1 -0
@@ -10,6 +10,7 @@#include <linux/sunrpc/svc.h> struct svc_xprt_ops { +struct svc_xprt *(*xpo_accept)(struct svc_xprt *);int (*xpo_has_wspace)(struct svc_xprt *);int (*xpo_recvfrom)(struct svc_rqst *);void (*xpo_prep_reply_hdr)(struct svc_rqst *);
include/linux/sunrpc/svcsock.h +1 -0
@@ -36,6 +36,7 @@ struct svc_sock {#define SK_DEFERRED 8/* request on sk_deferred */ #define SK_OLD 9/* used for temp socket aging mark+sweep */ #define SK_DETACHED 10/* detached from tempsocks list */ +#define SK_LISTENER 11/* listening endpoint */ atomic_t sk_reserved;/* space on outq that is reserved */
net/sunrpc/svcsock.c +70 -58
204 lines not on this page · raw message
A message that is not in the archive (sent off-list or not yet received): 20071211233217.15718.14380.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org
Re: [PATCH 11/38] svc: Add xpo_accept transport function
Quoted 7 lines · Tom Tucker
Previously, the accept logic looked into the socket state to determine whether to call accept or recv when data-ready was indicated on an endpoint. Since some transports don't use sockets, this logic was changed to use a flag bit (
SK_LISTENER) to identify listening endpoints. A transport function (xpo_accept) was added to allow each transport to define its own accept processing.
Nit: I'd put description of what this patch does in the present tense.
...
Quoted 4 lines
The code that poaches connections when the connection limit is hit was moved to a subroutine to make the accept logic path easier to follow. Since this is in the new connection path, it should not be a performance issue.
Makes sense. I'd have done that in a separate patch.
Quoted 7 lines
net/sunrpc/svcsock.c +7
-0+static void svc_check_conn_limits (struct svc_serv *serv) +{ +char buf[RPC_MAX_ADDRBUFLEN ]; + +if (serv->sv_tmpcnt > (serv->sv_nrthreads+3 )*20 ) { +struct svc_sock *svsk =NULL ; +spin_lock_bh (&serv->sv_lock);
net/sunrpc/svcsock.c svc_sock_update_bufs(struct svc_serv *serv) · line 1462
Quoted 10 lines
net/sunrpc/svcsock.c +10
-0+if (!list_empty (&serv->sv_tempsocks)) { +if (net_ratelimit ()) { +/* Try to help the admin */ +printk (KERN_NOTICE "%s: too many open TCP " +"sockets, consider increasing the " +"number of nfsd threads\n" , + serv->sv_name); +printk (KERN_NOTICE +"%s: last TCP connect from %s\n" , + serv->sv_name, buf);
It looks like the content of "buf" is unitialized here?
--b.
Quoted 21 lines
net/sunrpc/svcsock.c +21
-0+ } +/* +* Always select the oldest socket. It's not fair, +* but so is life +*/ + svsk =list_entry (serv->sv_tempsocks.prev, + struct svc_sock, + sk_list); +set_bit (SK_CLOSE , &svsk->sk_flags); +atomic_inc (&svsk->sk_inuse); + } +spin_unlock_bh (&serv->sv_lock); + +if (svsk) { +svc_sock_enqueue (svsk); +svc_sock_put (svsk); + } + } +} + +/*
Re: [PATCH 11/38] svc: Add xpo_accept transport function
Quoted 11 lines · J. Bruce Fields
Quoted 7 lines · Tom Tucker
Previously, the accept logic looked into the socket state to determine whether to call accept or recv when data-ready was indicated on an endpoint. Since some transports don't use sockets, this logic was changed to use a flag bit (
SK_LISTENER) to identify listening endpoints. A transport function (xpo_accept) was added to allow each transport to define its own accept processing.Nit: I'd put description of what this patch does in the present tense.
ok.
Quoted 19 lines
...
Quoted 4 lines
The code that poaches connections when the connection limit is hit was moved to a subroutine to make the accept logic path easier to follow. Since this is in the new connection path, it should not be a performance issue.
Makes sense. I'd have done that in a separate patch.
Quoted 11 lines
net/sunrpc/svcsock.c +11
-0+static void svc_check_conn_limits (struct svc_serv *serv) +{ +char buf[RPC_MAX_ADDRBUFLEN ]; + +if (serv->sv_tmpcnt > (serv->sv_nrthreads+3 )*20 ) { +struct svc_sock *svsk =NULL ; +spin_lock_bh (&serv->sv_lock); +if (!list_empty (&serv->sv_tempsocks)) { +if (net_ratelimit ()) { +/* Try to help the admin */ + printk(KERN_NOTICE "%s: too many open TCP "
Quoted 8 lines
net/sunrpc/svcsock.c svc_sock_update_bufs(struct svc_serv *serv) · line 1462
Quoted 6 lines
net/sunrpc/svcsock.c +6
-0+"sockets, consider increasing the " +"number of nfsd threads\n" , + serv->sv_name); +printk (KERN_NOTICE +"%s: last TCP connect from %s\n" , + serv->sv_name, buf);It looks like the content of "buf" is unitialized here?
This is a bug I introduced. How about if I break this into a separate patch (like you suggest above) with the appropriate __svc_print_addr that fills in buf.
Quoted 24 lines
--b.
Quoted 21 lines
net/sunrpc/svcsock.c +21
-0+ } +/* +* Always select the oldest socket. It's not fair, +* but so is life +*/ + svsk =list_entry (serv->sv_tempsocks.prev, + struct svc_sock, + sk_list); +set_bit (SK_CLOSE , &svsk->sk_flags); +atomic_inc (&svsk->sk_inuse); + } +spin_unlock_bh (&serv->sv_lock); + +if (svsk) { +svc_sock_enqueue (svsk); +svc_sock_put (svsk); + } + } +} + +/*
Re: [PATCH 11/38] svc: Add xpo_accept transport function
In reply to J. Bruce FieldsQuoted 11 lines · J. Bruce Fields
Quoted 7 lines · Tom Tucker
Previously, the accept logic looked into the socket state to determine whether to call accept or recv when data-ready was indicated on an endpoint. Since some transports don't use sockets, this logic was changed to use a flag bit (
SK_LISTENER) to identify listening endpoints. A transport function (xpo_accept) was added to allow each transport to define its own accept processing.Nit: I'd put description of what this patch does in the present tense.
Ok,
Quoted 8 lines
...
Quoted 4 lines
The code that poaches connections when the connection limit is hit was moved to a subroutine to make the accept logic path easier to follow. Since this is in the new connection path, it should not be a performance issue.
Makes sense. I'd have done that in a separate patch.
Ok,
Quoted 11 lines
Quoted 11 lines
net/sunrpc/svcsock.c +11
-0+static void svc_check_conn_limits (struct svc_serv *serv) +{ +char buf[RPC_MAX_ADDRBUFLEN ]; + +if (serv->sv_tmpcnt > (serv->sv_nrthreads+3 )*20 ) { +struct svc_sock *svsk =NULL ; +spin_lock_bh (&serv->sv_lock); +if (!list_empty (&serv->sv_tempsocks)) { +if (net_ratelimit ()) { +/* Try to help the admin */ + printk(KERN_NOTICE "%s: too many open TCP "
Quoted 9 lines
net/sunrpc/svcsock.c svc_sock_update_bufs(struct svc_serv *serv) · line 1462
Quoted 6 lines
net/sunrpc/svcsock.c +6
-0+"sockets, consider increasing the " +"number of nfsd threads\n" , + serv->sv_name); +printk (KERN_NOTICE +"%s: last TCP connect from %s\n" , + serv->sv_name, buf);It looks like the content of "buf" is unitialized here?
Bug, fixed.
Quoted 23 lines
--b.
Quoted 21 lines
net/sunrpc/svcsock.c +21
-0+ } +/* +* Always select the oldest socket. It's not fair, +* but so is life +*/ + svsk =list_entry (serv->sv_tempsocks.prev, + struct svc_sock, + sk_list); +set_bit (SK_CLOSE , &svsk->sk_flags); +atomic_inc (&svsk->sk_inuse); + } +spin_unlock_bh (&serv->sv_lock); + +if (svsk) { +svc_sock_enqueue (svsk); +svc_sock_put (svsk); + } + } +} + +/*
Re: [PATCH 11/38] svc: Add xpo_accept transport function
In reply to a message not in the archivenet/sunrpc/svcsock.c svc_tcp_accept(struct svc_sock *svsk) · line 1069
Quoted 13 lines · Tom Tucker
net/sunrpc/svcsock.c +1
-2@@ -1053,11 +1060,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 NULL ; }set_bit (SK_CONN , &svsk->sk_flags); -svc_sock_enqueue (svsk); err =kernel_getpeername (newsock, sin, &slen);if (err <0 ) {
Why did we need that svc_sock_enqueue here, and why don't we any more? (And if we don't, but we still need the set_bit, then we need to fix the comment at the top of the file claiming the svc_sock_enqueue() is always required after setting SK_CONN.)
--b.
Re: [PATCH 11/38] svc: Add xpo_accept transport function
Quoted 9 lines · J. Bruce Fields
Quoted 8 lines · Tom Tucker
net/sunrpc/svcsock.c +1
-1@@ -1053,11 +1060,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 NULL ; }
Quoted 7 lines
net/sunrpc/svcsock.c svc_tcp_accept(struct svc_sock *svsk) · line 1069
Quoted 5 lines
net/sunrpc/svcsock.c +0
-1set_bit (SK_CONN , &svsk->sk_flags); -svc_sock_enqueue (svsk); err =kernel_getpeername (newsock, sin, &slen);if (err <0 ) {Why did we need that
svc_sock_enqueuehere, and why don't we any more?
Calling svc_sock_enqueue while holding the BUSY bit is a no-op. We can certainly break this out and update the comment.
Quoted 3 lines
(And if we don't, but we still need the
set_bit, then we need to fix the comment at the top of the file claiming thesvc_sock_enqueue()is always required after settingSK_CONN.)
We need to call svc_sock_enqueue, but it is done indirectly through svc_sock_received -- that calls svc_sock_enqueue after clearing the BUSY bit.
Quoted 2 lines
--b.
Re: [PATCH 11/38] svc: Add xpo_accept transport function
In reply to J. Bruce FieldsQuoted 12 lines · J. Bruce Fields
Quoted 11 lines · Tom Tucker
net/sunrpc/svcsock.c +1
-2@@ -1053,11 +1060,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 NULL ; }set_bit (SK_CONN , &svsk->sk_flags); -svc_sock_enqueue (svsk);
Quoted 7 lines
net/sunrpc/svcsock.c svc_tcp_accept(struct svc_sock *svsk) · line 1069
Quoted 2 lines
net/sunrpc/svcsock.c +0
-0err =kernel_getpeername (newsock, sin, &slen);if (err <0 ) {Why did we need that
svc_sock_enqueuehere, and why don't we any more? (And if we don't, but we still need theset_bit, then we need to fix the comment at the top of the file claiming thesvc_sock_enqueue()is always required after settingSK_CONN.)
I moved this to it's own patch with a description of why it was removed.
Quoted 6 lines
--b.
-
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
PATCH 12/38 svc: Add a generic transport svc_create_xprt function
In reply to a message not in the archiveThe svc_create_xprt function is a transport independent version of the svc_makesock function.
Since transport instance creation contains transport dependent and independent components, add an xpo_create transport function. The transport implementation of this function allocates the memory for the endpoint, implements the transport dependent initialization logic, and calls svc_xprt_init to initialize the transport independent field (svc_xprt) in it's data structure.
---
include/linux/sunrpc/svc_xprt.h | 4 +++ net/sunrpc/svc_xprt.c | 37 ++++++++++++++++++++++++ net/sunrpc/svcsock.c | 59 +++++++++++++++++++++++++++++---------- 3 files changed, 85 insertions(+), 15 deletions(-)
include/linux/sunrpc/svc_xprt.h +4 -0
@@ -10,6 +10,9 @@#include <linux/sunrpc/svc.h> struct svc_xprt_ops { +struct svc_xprt *(*xpo_create)(struct svc_serv *, +struct sockaddr *,int , +int );struct svc_xprt *(*xpo_accept)(struct svc_xprt *);int (*xpo_has_wspace)(struct svc_xprt *);int (*xpo_recvfrom)(struct svc_rqst *);
@@ -36,5 +39,6 @@ struct svc_xprt {int svc_reg_xprt_class (struct svc_xprt_class *);int svc_unreg_xprt_class (struct svc_xprt_class *);void svc_xprt_init (struct svc_xprt_class *,struct svc_xprt *); +int svc_create_xprt (struct svc_serv *,char *,unsigned short ,int );#endif /* SUNRPC_SVC_XPRT_H */
net/sunrpc/svc_xprt.c +37 -0
@@ -93,3 +93,40 @@ void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt) xprt->xpt_ops = xcl->xcl_ops; }EXPORT_SYMBOL_GPL (svc_xprt_init); + +int svc_create_xprt (struct svc_serv *serv,char *xprt_name,unsigned short port, +int flags) +{ +struct svc_xprt_class *xcl; +int ret = -ENOENT ; +struct sockaddr_in sin = { + .sin_family =AF_INET , + .sin_addr.s_addr =INADDR_ANY , + .sin_port =htons (port), + }; +dprintk ("svc: creating transport %s[%d]\n" , xprt_name, port); +spin_lock (&svc_xprt_class_lock); +list_for_each_entry (xcl, &svc_xprt_class_list, xcl_list) { +if (strcmp (xprt_name, xcl->xcl_name) ==0 ) { +spin_unlock (&svc_xprt_class_lock); +if (try_module_get (xcl->xcl_owner)) { +struct svc_xprt *newxprt; + ret =0 ; + newxprt = xcl->xcl_ops->xpo_create + (serv, + (struct sockaddr *)&sin,sizeof (sin), + flags); +if (IS_ERR (newxprt)) { +module_put (xcl->xcl_owner); + ret =PTR_ERR (newxprt); + } + } + goto out; + } + } +spin_unlock (&svc_xprt_class_lock); +dprintk ("svc: transport %s not found\n" , xprt_name); + out: +return ret; +} +EXPORT_SYMBOL_GPL (svc_create_xprt);
net/sunrpc/svcsock.c +44 -15
139 lines not on this page · raw message
PATCH 13/38 svc: Change services to use new svc_create_xprt service
In reply to a message not in the archiveModify the various kernel RPC svcs to use the svc_create_xprt service.
---
fs/lockd/svc.c | 17 ++++++++--------- fs/nfs/callback.c | 4 ++-- fs/nfsd/nfssvc.c | 4 ++-- include/linux/sunrpc/svcsock.h | 1 - net/sunrpc/sunrpc_syms.c | 1 - net/sunrpc/svcsock.c | 22 ---------------------- 6 files changed, 12 insertions(+), 37 deletions(-)
fs/lockd/svc.c +8 -9
@@ -219,13 +219,12 @@ lockd(struct svc_rqst *rqstp)module_put_and_exit (0 ); } - -static int find_socket (struct svc_serv *serv,int proto) +static int find_xprt (struct svc_serv *serv,char *proto) {struct svc_sock *svsk;int found =0 ;list_for_each_entry (svsk, &serv->sv_permsocks, sk_list) -if (svsk->sk_sk->sk_protocol == proto) { +if (strcmp (svsk->sk_xprt.xpt_class->xcl_name, proto) ==0 ) { found =1 ;break ; }
@@ -243,13 +242,13 @@ static int make_socks(struct svc_serv *serv, int proto)int err =0 ;if (proto ==IPPROTO_UDP || nlm_udpport) -if (!find_socket (serv,IPPROTO_UDP )) - err =svc_makesock (serv,IPPROTO_UDP , nlm_udpport, -SVC_SOCK_DEFAULTS ); +if (!find_xprt (serv,"udp" )) + err =svc_create_xprt (serv,"udp" , nlm_udpport, +SVC_SOCK_DEFAULTS );if (err >=0 && (proto ==IPPROTO_TCP || nlm_tcpport)) -if (!find_socket (serv,IPPROTO_TCP )) - err =svc_makesock (serv,IPPROTO_TCP , nlm_tcpport, -SVC_SOCK_DEFAULTS ); +if (!find_xprt (serv,"tcp" )) + err =svc_create_xprt (serv,"tcp" , nlm_tcpport, +SVC_SOCK_DEFAULTS );if (err >=0 ) { warned =0 ;
fs/nfs/callback.c +2 -2
@@ -123,8 +123,8 @@ int nfs_callback_up(void)if (!serv) goto out_err; - ret =svc_makesock (serv,IPPROTO_TCP , nfs_callback_set_tcpport, -SVC_SOCK_ANONYMOUS ); + ret =svc_create_xprt (serv,"tcp" , nfs_callback_set_tcpport, +SVC_SOCK_ANONYMOUS );if (ret <=0 ) goto out_destroy; nfs_callback_tcpport = ret;
fs/nfsd/nfssvc.c +2 -2
@@ -236,7 +236,7 @@ static int nfsd_init_socks(int port) error =lockd_up (IPPROTO_UDP );if (error >=0 ) { - error =svc_makesock (nfsd_serv,IPPROTO_UDP , port, + error =svc_create_xprt (nfsd_serv,"udp" , port,SVC_SOCK_DEFAULTS );if (error <0 )lockd_down ();
@@ -247,7 +247,7 @@ static int nfsd_init_socks(int port)#ifdef CONFIG_NFSD_TCP error =lockd_up (IPPROTO_TCP );if (error >=0 ) { - error =svc_makesock (nfsd_serv,IPPROTO_TCP , port, + error =svc_create_xprt (nfsd_serv,"tcp" , port,SVC_SOCK_DEFAULTS );if (error <0 )lockd_down ();
include/linux/sunrpc/svcsock.h +0 -1
@@ -67,7 +67,6 @@ struct svc_sock {/* * Function prototypes. */ -int svc_makesock (struct svc_serv *,int ,unsigned short ,int flags);void svc_force_close_socket (struct svc_sock *);int svc_recv (struct svc_rqst *,long );int svc_send (struct svc_rqst *);
net/sunrpc/sunrpc_syms.c +0 -1
@@ -72,7 +72,6 @@ EXPORT_SYMBOL(svc_drop);EXPORT_SYMBOL (svc_process);EXPORT_SYMBOL (svc_recv);EXPORT_SYMBOL (svc_wake_up); -EXPORT_SYMBOL (svc_makesock);EXPORT_SYMBOL (svc_reserve);EXPORT_SYMBOL (svc_auth_register);EXPORT_SYMBOL (auth_domain_lookup);
net/sunrpc/svcsock.c +0 -22
@@ -1993,28 +1993,6 @@ void svc_force_close_socket(struct svc_sock *svsk)svc_close_socket (svsk); } -/** -* svc_makesock - Make a socket for nfsd and lockd -* @serv: RPC server structure -* @protocol: transport protocol to use -* @port: port to use -* @flags: requested socket characteristics -* -*/ -int svc_makesock (struct svc_serv *serv,int protocol,unsigned short port, -int flags) -{ -dprintk ("svc: creating socket proto = %d\n" , protocol); -switch (protocol) { -case IPPROTO_TCP : -return svc_create_xprt (serv,"tcp" , port, flags); -case IPPROTO_UDP : -return svc_create_xprt (serv,"udp" , port, flags); -default : -return -EINVAL ; - } -} -/* * Handle defer and revisit of requests */
PATCH 14/38 svc: Change sk_inuse to a kref
In reply to a message not in the archiveChange the atomic_t reference count to a kref and move it to the transport indepenent svc_xprt structure. Change the reference count wrapper names to be generic.
---
include/linux/sunrpc/svc_xprt.h | 8 ++++++ include/linux/sunrpc/svcsock.h | 1 - net/sunrpc/svc_xprt.c | 17 ++++++++++++ net/sunrpc/svcsock.c | 54 +++++++++++++++------------------------ 4 files changed, 46 insertions(+), 34 deletions(-)
include/linux/sunrpc/svc_xprt.h +8 -0
@@ -8,6 +8,7 @@#define SUNRPC_SVC_XPRT_H #include <linux/sunrpc/svc.h> +#include <linux/module.h> struct svc_xprt_ops { struct svc_xprt *(*xpo_create)(struct svc_serv *,
@@ -34,11 +35,18 @@ struct svc_xprt_class {struct svc_xprt {struct svc_xprt_class *xpt_class;struct svc_xprt_ops *xpt_ops; +struct kref xpt_ref; };int svc_reg_xprt_class (struct svc_xprt_class *);int svc_unreg_xprt_class (struct svc_xprt_class *);void svc_xprt_init (struct svc_xprt_class *,struct svc_xprt *);int svc_create_xprt (struct svc_serv *,char *,unsigned short ,int ); +void svc_xprt_put (struct svc_xprt *xprt); + +static inline void svc_xprt_get (struct svc_xprt *xprt) +{ +kref_get (&xprt->xpt_ref); +}#endif /* SUNRPC_SVC_XPRT_H */
include/linux/sunrpc/svcsock.h +0 -1
@@ -24,7 +24,6 @@ struct svc_sock {struct svc_pool * sk_pool;/* current pool iff queued */ struct svc_serv * sk_server;/* service for this socket */ -atomic_t sk_inuse;/* use count */ unsigned long sk_flags;#define SK_BUSY 0/* enqueued/receiving */ #define SK_CONN 1/* conn pending */
net/sunrpc/svc_xprt.c +17 -0
@@ -82,6 +82,22 @@ int svc_unreg_xprt_class(struct svc_xprt_class *xcl) }EXPORT_SYMBOL_GPL (svc_unreg_xprt_class); +static void svc_xprt_free (struct kref *kref) +{ +struct svc_xprt *xprt = + container_of(kref, struct svc_xprt, xpt_ref); +struct module *owner = xprt->xpt_class->xcl_owner; +BUG_ON (atomic_read (&kref->refcount)); + xprt->xpt_ops->xpo_free (xprt); +module_put (owner); +} + +void svc_xprt_put (struct svc_xprt *xprt) +{ +kref_put (&xprt->xpt_ref, svc_xprt_free); +} +EXPORT_SYMBOL_GPL (svc_xprt_put); +/* * Called by transport drivers to initialize the transport independent * portion of the transport instance.
@@ -91,6 +107,7 @@ void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt)memset (xprt,0 ,sizeof (*xprt)); xprt->xpt_class = xcl; xprt->xpt_ops = xcl->xcl_ops; +kref_init (&xprt->xpt_ref); }EXPORT_SYMBOL_GPL (svc_xprt_init);
net/sunrpc/svcsock.c +21 -33
158 lines not on this page · raw message
A message that is not in the archive (sent off-list or not yet received): 20071211233224.15718.91339.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org
Re: [PATCH 14/38] svc: Change sk_inuse to a kref
Quoted 62 lines · Tom Tucker
Change the
atomic_treference count to a kref and move it to the transport indepenentsvc_xprtstructure. Change the reference count wrapper names to be generic.Signed-off-by Tom Tucker <[email protected]>---
include/linux/sunrpc/svc_xprt.h | 8 ++++++ include/linux/sunrpc/svcsock.h | 1 - net/sunrpc/svc_xprt.c | 17 ++++++++++++ net/sunrpc/svcsock.c | 54 +++++++++++++++------------------------ 4 files changed, 46 insertions(+), 34 deletions(-)include/linux/sunrpc/svc_xprt.h +8
-0@@ -8,6 +8,7 @@#define SUNRPC_SVC_XPRT_H #include <linux/sunrpc/svc.h> +#include <linux/module.h> struct svc_xprt_ops { struct svc_xprt *(*xpo_create)(struct svc_serv *,@@ -34,11 +35,18 @@ struct svc_xprt_class {struct svc_xprt {struct svc_xprt_class *xpt_class;struct svc_xprt_ops *xpt_ops; +struct kref xpt_ref; };int svc_reg_xprt_class (struct svc_xprt_class *);int svc_unreg_xprt_class (struct svc_xprt_class *);void svc_xprt_init (struct svc_xprt_class *,struct svc_xprt *);int svc_create_xprt (struct svc_serv *,char *,unsigned short ,int ); +void svc_xprt_put (struct svc_xprt *xprt); + +static inline void svc_xprt_get (struct svc_xprt *xprt) +{ +kref_get (&xprt->xpt_ref); +}#endif /* SUNRPC_SVC_XPRT_H */ include/linux/sunrpc/svcsock.h +0
-1@@ -24,7 +24,6 @@ struct svc_sock {struct svc_pool * sk_pool;/* current pool iff queued */ struct svc_serv * sk_server;/* service for this socket */ -atomic_t sk_inuse;/* use count */ unsigned long sk_flags;#define SK_BUSY 0/* enqueued/receiving */ #define SK_CONN 1/* conn pending */ net/sunrpc/svc_xprt.c +0
-0
net/sunrpc/svc_xprt.c int svc_unreg_xprt_class(struct svc_xprt_class *xcl) · line 90
Quoted 9 lines
net/sunrpc/svc_xprt.c +6
-0@@ -82,6 +82,22 @@ int svc_unreg_xprt_class(struct svc_xprt_class *xcl) }EXPORT_SYMBOL_GPL (svc_unreg_xprt_class); +static void svc_xprt_free (struct kref *kref) +{ +struct svc_xprt *xprt = + container_of(kref, struct svc_xprt, xpt_ref); +struct module *owner = xprt->xpt_class->xcl_owner; +BUG_ON (atomic_read (&kref->refcount));
All this BUG_ON() is doing is checking for what looks like a bizarrely unlikely bug in kref_put(). The BUG_ON from the original code is:
BUG_ON(!test_bit(SK_DEAD, &svsk->sk_flags));
But I don't have any strong feelings as to whether that's necessary.
--b.
Re: [PATCH 14/38] svc: Change sk_inuse to a kref
Quoted 76 lines · J. Bruce Fields
Quoted 62 lines · Tom Tucker
Change the
atomic_treference count to a kref and move it to the transport indepenentsvc_xprtstructure. Change the reference count wrapper names to be generic.Signed-off-by Tom Tucker <[email protected]>---
include/linux/sunrpc/svc_xprt.h | 8 ++++++ include/linux/sunrpc/svcsock.h | 1 - net/sunrpc/svc_xprt.c | 17 ++++++++++++ net/sunrpc/svcsock.c | 54 +++++++++++++++------------------------ 4 files changed, 46 insertions(+), 34 deletions(-)include/linux/sunrpc/svc_xprt.h +8
-0@@ -8,6 +8,7 @@#define SUNRPC_SVC_XPRT_H #include <linux/sunrpc/svc.h> +#include <linux/module.h> struct svc_xprt_ops { struct svc_xprt *(*xpo_create)(struct svc_serv *,@@ -34,11 +35,18 @@ struct svc_xprt_class {struct svc_xprt {struct svc_xprt_class *xpt_class;struct svc_xprt_ops *xpt_ops; +struct kref xpt_ref; };int svc_reg_xprt_class (struct svc_xprt_class *);int svc_unreg_xprt_class (struct svc_xprt_class *);void svc_xprt_init (struct svc_xprt_class *,struct svc_xprt *);int svc_create_xprt (struct svc_serv *,char *,unsigned short ,int ); +void svc_xprt_put (struct svc_xprt *xprt); + +static inline void svc_xprt_get (struct svc_xprt *xprt) +{ +kref_get (&xprt->xpt_ref); +}#endif /* SUNRPC_SVC_XPRT_H */ include/linux/sunrpc/svcsock.h +0
-1@@ -24,7 +24,6 @@ struct svc_sock {struct svc_pool * sk_pool;/* current pool iff queued */ struct svc_serv * sk_server;/* service for this socket */ -atomic_t sk_inuse;/* use count */ unsigned long sk_flags;#define SK_BUSY 0/* enqueued/receiving */ #define SK_CONN 1/* conn pending */ net/sunrpc/svc_xprt.c +0
-0net/sunrpc/svc_xprt.c int svc_unreg_xprt_class(struct svc_xprt_class *xcl) · line 90
Quoted 9 lines
net/sunrpc/svc_xprt.c +6
-0@@ -82,6 +82,22 @@ int svc_unreg_xprt_class(struct svc_xprt_class *xcl) }EXPORT_SYMBOL_GPL (svc_unreg_xprt_class); +static void svc_xprt_free (struct kref *kref) +{ +struct svc_xprt *xprt = + container_of(kref, struct svc_xprt, xpt_ref); +struct module *owner = xprt->xpt_class->xcl_owner; +BUG_ON (atomic_read (&kref->refcount));All this
BUG_ON()is doing is checking for what looks like a bizarrely unlikely bug inkref_put(). TheBUG_ONfrom the original code is:
Quoted 4 lines
BUG_ON(!test_bit(SK_DEAD, &svsk->sk_flags));But I don't have any strong feelings as to whether that's necessary.
It's not.
Quoted 1 line
--b.
PATCH 15/38 svc: Move sk_flags to the svc_xprt structure
In reply to a message not in the archiveThis functionally trivial change moves the transport independent sk_flags field to the transport independent svc_xprt structure.
---
include/linux/sunrpc/svc_xprt.h | 12 +++ include/linux/sunrpc/svcsock.h | 13 --- net/sunrpc/svcsock.c | 149 ++++++++++++++++++++------------------- 3 files changed, 87 insertions(+), 87 deletions(-)
include/linux/sunrpc/svc_xprt.h +12 -0
@@ -36,6 +36,18 @@ struct svc_xprt {struct svc_xprt_class *xpt_class;struct svc_xprt_ops *xpt_ops;struct kref xpt_ref; +unsigned long xpt_flags; +#define XPT_BUSY 0/* enqueued/receiving */ +#define XPT_CONN 1/* conn pending */ +#define XPT_CLOSE 2/* dead or dying */ +#define XPT_DATA 3/* data pending */ +#define XPT_TEMP 4/* connected transport */ +#define XPT_DEAD 6/* transport closed */ +#define XPT_CHNGBUF 7/* need to change snd/rcv buf sizes */ +#define XPT_DEFERRED 8/* deferred request pending */ +#define XPT_OLD 9/* used for xprt aging mark+sweep */ +#define XPT_DETACHED 10/* detached from tempsocks list */ +#define XPT_LISTENER 11/* listening endpoint */ };int svc_reg_xprt_class (struct svc_xprt_class *);
include/linux/sunrpc/svcsock.h +0 -13
@@ -24,19 +24,6 @@ struct svc_sock {struct svc_pool * sk_pool;/* current pool iff queued */ struct svc_serv * sk_server;/* service for this socket */ -unsigned long sk_flags; -#define SK_BUSY 0/* enqueued/receiving */ -#define SK_CONN 1/* conn pending */ -#define SK_CLOSE 2/* dead or dying */ -#define SK_DATA 3/* data pending */ -#define SK_TEMP 4/* temp (TCP) socket */ -#define SK_DEAD 6/* socket closed */ -#define SK_CHNGBUF 7/* need to change snd/rcv buffer sizes */ -#define SK_DEFERRED 8/* request on sk_deferred */ -#define SK_OLD 9/* used for temp socket aging mark+sweep */ -#define SK_DETACHED 10/* detached from tempsocks list */ -#define SK_LISTENER 11/* listening endpoint */ -atomic_t sk_reserved;/* space on outq that is reserved */ spinlock_t sk_lock;/* protects sk_deferred and
net/sunrpc/svcsock.c +75 -74
457 lines not on this page · raw message
PATCH 16/38 svc: Move sk_server and sk_pool to svc_xprt
In reply to a message not in the archiveThis is another incremental change that moves transport independent fields from svc_sock to the svc_xprt structure. The changes should be functionally null.
---
include/linux/sunrpc/svc_xprt.h | 6 +++- include/linux/sunrpc/svcsock.h | 2 - net/sunrpc/svc_xprt.c | 4 ++- net/sunrpc/svcsock.c | 57 ++++++++++++++++++--------------------- 4 files changed, 35 insertions(+), 34 deletions(-)
include/linux/sunrpc/svc_xprt.h +5 -1
@@ -48,11 +48,15 @@ struct svc_xprt {#define XPT_OLD 9/* used for xprt aging mark+sweep */ #define XPT_DETACHED 10/* detached from tempsocks list */ #define XPT_LISTENER 11/* listening endpoint */ + +struct svc_pool *xpt_pool;/* current pool iff queued */ +struct svc_serv *xpt_server;/* service for transport */ };int svc_reg_xprt_class (struct svc_xprt_class *);int svc_unreg_xprt_class (struct svc_xprt_class *); -void svc_xprt_init (struct svc_xprt_class *,struct svc_xprt *); +void svc_xprt_init (struct svc_xprt_class *,struct svc_xprt *, +struct svc_serv *);int svc_create_xprt (struct svc_serv *,char *,unsigned short ,int );void svc_xprt_put (struct svc_xprt *xprt);
include/linux/sunrpc/svcsock.h +0 -2
@@ -22,8 +22,6 @@ struct svc_sock {struct socket * sk_sock;/* berkeley socket layer */ struct sock * sk_sk;/* INET layer */ -struct svc_pool * sk_pool;/* current pool iff queued */ -struct svc_serv * sk_server;/* service for this socket */ atomic_t sk_reserved;/* space on outq that is reserved */ spinlock_t sk_lock;/* protects sk_deferred and
net/sunrpc/svc_xprt.c +3 -1
@@ -102,12 +102,14 @@ EXPORT_SYMBOL_GPL(svc_xprt_put);* Called by transport drivers to initialize the transport independent * portion of the transport instance. */ -void svc_xprt_init (struct svc_xprt_class *xcl,struct svc_xprt *xprt) +void svc_xprt_init (struct svc_xprt_class *xcl,struct svc_xprt *xprt, +struct svc_serv *serv) {memset (xprt,0 ,sizeof (*xprt)); xprt->xpt_class = xcl; xprt->xpt_ops = xcl->xcl_ops;kref_init (&xprt->xpt_ref); + xprt->xpt_server = serv; }EXPORT_SYMBOL_GPL (svc_xprt_init);
net/sunrpc/svcsock.c +27 -30
196 lines not on this page · raw message
PATCH 17/38 svc: Make close transport independent
In reply to a message not in the archiveMove sk_list and sk_ready to svc_xprt. This involves close because these lists are walked by svcs when closing all their transports. So I combined the moving of these lists to svc_xprt with making close transport independent.
The svc_force_sock_close has been changed to svc_close_all and takes a list as an argument. This removes some svc internals knowledge from the svcs.
This code races with module removal and transport addition.
---
fs/lockd/svc.c | 6 +- fs/nfsd/nfssvc.c | 4 + include/linux/sunrpc/svc_xprt.h | 2 + include/linux/sunrpc/svcsock.h | 4 - net/sunrpc/svc.c | 9 +-- net/sunrpc/svc_xprt.c | 2 + net/sunrpc/svcsock.c | 106 +++++++++++++++++++-------------------- 7 files changed, 63 insertions(+), 70 deletions(-)
fs/lockd/svc.c +3 -3
@@ -221,10 +221,10 @@ lockd(struct svc_rqst *rqstp)static int find_xprt (struct svc_serv *serv,char *proto) { -struct svc_sock *svsk; +struct svc_xprt *xprt;int found =0 ; -list_for_each_entry (svsk, &serv->sv_permsocks, sk_list) -if (strcmp (svsk->sk_xprt.xpt_class->xcl_name, proto) ==0 ) { +list_for_each_entry (xprt, &serv->sv_permsocks, xpt_list) +if (strcmp (xprt->xpt_class->xcl_name, proto) ==0 ) { found =1 ;break ; }
fs/nfsd/nfssvc.c +2 -2
@@ -155,8 +155,8 @@ static int killsig; /* signal that was used to kill last nfsd */static void nfsd_last_thread (struct svc_serv *serv) {/* When last nfsd thread exits we need to do some clean-up */ -struct svc_sock *svsk; -list_for_each_entry (svsk, &serv->sv_permsocks, sk_list) +struct svc_xprt *xprt; +list_for_each_entry (xprt, &serv->sv_permsocks, xpt_list)lockd_down (); nfsd_serv =NULL ;nfsd_racache_shutdown ();
include/linux/sunrpc/svc_xprt.h +2 -0
@@ -36,6 +36,8 @@ struct svc_xprt {struct svc_xprt_class *xpt_class;struct svc_xprt_ops *xpt_ops;struct kref xpt_ref; +struct list_head xpt_list; +struct list_head xpt_ready;unsigned long xpt_flags;#define XPT_BUSY 0/* enqueued/receiving */ #define XPT_CONN 1/* conn pending */
include/linux/sunrpc/svcsock.h +1 -3
@@ -17,8 +17,6 @@*/ struct svc_sock {struct svc_xprt sk_xprt; -struct list_head sk_ready;/* list of ready sockets */ -struct list_head sk_list;/* list of all sockets */ struct socket * sk_sock;/* berkeley socket layer */ struct sock * sk_sk;/* INET layer */
@@ -51,7 +49,7 @@ struct svc_sock {/* * Function prototypes. */ -void svc_force_close_socket (struct svc_sock *); +void svc_close_all (struct list_head *);int svc_recv (struct svc_rqst *,long );int svc_send (struct svc_rqst *);void svc_drop (struct svc_rqst *);
net/sunrpc/svc.c +2 -7
@@ -458,9 +458,6 @@ svc_create_pooled(struct svc_program *prog, unsigned int bufsize,void svc_destroy (struct svc_serv *serv) { -struct svc_sock *svsk; -struct svc_sock *tmp; -dprintk ("svc: svc_destroy(%s, %d)\n" , serv->sv_program->pg_name, serv->sv_nrthreads);
@@ -475,14 +472,12 @@ svc_destroy(struct svc_serv *serv)del_timer_sync (&serv->sv_temptimer); -list_for_each_entry_safe (svsk, tmp, &serv->sv_tempsocks, sk_list) -svc_force_close_socket (svsk); +svc_close_all (&serv->sv_tempsocks);if (serv->sv_shutdown) serv->sv_shutdown (serv); -list_for_each_entry_safe (svsk, tmp, &serv->sv_permsocks, sk_list) -svc_force_close_socket (svsk); +svc_close_all (&serv->sv_permsocks);BUG_ON (!list_empty (&serv->sv_permsocks));BUG_ON (!list_empty (&serv->sv_tempsocks));
net/sunrpc/svc_xprt.c +2 -0
@@ -110,6 +110,8 @@ void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt, xprt->xpt_ops = xcl->xcl_ops;kref_init (&xprt->xpt_ref); xprt->xpt_server = serv; +INIT_LIST_HEAD (&xprt->xpt_list); +INIT_LIST_HEAD (&xprt->xpt_ready); }EXPORT_SYMBOL_GPL (svc_xprt_init);
net/sunrpc/svcsock.c +51 -55
227 lines not on this page · raw message
PATCH 18/38 svc: Move sk_reserved to svc_xprt
In reply to a message not in the archiveThis functionally trivial patch moves the sk_reserved field to the transport independent svc_xprt structure.
---
include/linux/sunrpc/svc_xprt.h | 1 + include/linux/sunrpc/svcsock.h | 2 -- net/sunrpc/svcsock.c | 10 +++++----- 3 files changed, 6 insertions(+), 7 deletions(-)
include/linux/sunrpc/svc_xprt.h +1 -0
@@ -53,6 +53,7 @@ struct svc_xprt {struct svc_pool *xpt_pool;/* current pool iff queued */ struct svc_serv *xpt_server;/* service for transport */ +atomic_t xpt_reserved;/* space on outq that is rsvd */ };int svc_reg_xprt_class (struct svc_xprt_class *);
include/linux/sunrpc/svcsock.h +0 -2
@@ -20,8 +20,6 @@ struct svc_sock {struct socket * sk_sock;/* berkeley socket layer */ struct sock * sk_sk;/* INET layer */ -atomic_t sk_reserved;/* space on outq that is reserved */ -spinlock_t sk_lock;/* protects sk_deferred and * sk_info_authunix */ struct list_head sk_deferred;/* deferred requests that need to
net/sunrpc/svcsock.c +5 -5
@@ -288,7 +288,7 @@ svc_sock_enqueue(struct svc_sock *svsk) rqstp->rq_sock = svsk;svc_xprt_get (&svsk->sk_xprt); rqstp->rq_reserved = serv->sv_max_mesg; -atomic_add (rqstp->rq_reserved, &svsk->sk_reserved); +atomic_add (rqstp->rq_reserved, &svsk->sk_xprt.xpt_reserved);BUG_ON (svsk->sk_xprt.xpt_pool != pool);wake_up (&rqstp->rq_wait); }else {
@@ -353,7 +353,7 @@ void svc_reserve(struct svc_rqst *rqstp, int space)if (space < rqstp->rq_reserved) {struct svc_sock *svsk = rqstp->rq_sock; -atomic_sub ((rqstp->rq_reserved - space), &svsk->sk_reserved); +atomic_sub ((rqstp->rq_reserved - space), &svsk->sk_xprt.xpt_reserved); rqstp->rq_reserved = space;svc_sock_enqueue (svsk);
@@ -881,7 +881,7 @@ static int svc_udp_has_wspace(struct svc_xprt *xprt)* sock space. */ set_bit (SOCK_NOSPACE , &svsk->sk_sock->flags); - required =atomic_read (&svsk->sk_reserved) + serv->sv_max_mesg; + required =atomic_read (&svsk->sk_xprt.xpt_reserved) + serv->sv_max_mesg;if (required*2 >sock_wspace (svsk->sk_sk))return 0 ;clear_bit (SOCK_NOSPACE , &svsk->sk_sock->flags);
@@ -1327,7 +1327,7 @@ static int svc_tcp_has_wspace(struct svc_xprt *xprt)* sock space. */ set_bit (SOCK_NOSPACE , &svsk->sk_sock->flags); - required =atomic_read (&svsk->sk_reserved) + serv->sv_max_mesg; + required =atomic_read (&svsk->sk_xprt.xpt_reserved) + serv->sv_max_mesg; wspace =sk_stream_wspace (svsk->sk_sk);if (wspace <sk_stream_min_wspace (svsk->sk_sk))
@@ -1549,7 +1549,7 @@ svc_recv(struct svc_rqst *rqstp, long timeout) rqstp->rq_sock = svsk;svc_xprt_get (&svsk->sk_xprt); rqstp->rq_reserved = serv->sv_max_mesg; -atomic_add (rqstp->rq_reserved, &svsk->sk_reserved); +atomic_add (rqstp->rq_reserved, &svsk->sk_xprt.xpt_reserved); }else {/* No data pending. Go to sleep */ svc_thread_enqueue (pool, rqstp);
PATCH 19/38 svc: Make the enqueue service transport neutral and export it.
In reply to a message not in the archiveThe svc_sock_enqueue function is now transport independent since all of the fields it touches have been moved to the transport independent svc_xprt structure. Change the function to use the svc_xprt structure directly instead of the transport specific svc_sock structure.
Transport specific data-ready handlers need to call this function, so export it.
---
net/sunrpc/svcsock.c | 94 ++++++++++++++++++++++++++------------------------ 1 files changed, 48 insertions(+), 46 deletions(-)
net/sunrpc/svcsock.c +48 -46
@@ -5,7 +5,7 @@* * The server scheduling algorithm does not always distribute the load * evenly when servicing a single client. May need to modify the -* svc_sock_enqueue procedure... +* svc_xprt_enqueue procedure... * * TCP support is largely untested and may be a little slow. The problem * is that we currently do two separate recvfrom's, one for the 4-byte
@@ -63,7 +63,7 @@* providing that certain rules are followed: * * XPT_CONN, XPT_DATA, can be set or cleared at any time. -* after a set, svc_sock_enqueue must be called. +* after a set, svc_xprt_enqueue must be called. * after a clear, the socket must be read/accepted * if this succeeds, it must be set again. * XPT_CLOSE can set at any time. It is never cleared.
@@ -212,22 +212,21 @@ static void svc_release_skb(struct svc_rqst *rqstp)* processes, wake 'em up. * */ -static void -svc_sock_enqueue (struct svc_sock *svsk) +void svc_xprt_enqueue (struct svc_xprt *xprt) { -struct svc_serv *serv = svsk->sk_xprt.xpt_server; +struct svc_serv *serv = xprt->xpt_server;struct svc_pool *pool;struct svc_rqst *rqstp;int cpu; -if (!(svsk->sk_xprt.xpt_flags & +if (!(xprt->xpt_flags & ((1 <<XPT_CONN )|(1 <<XPT_DATA )|(1 <<XPT_CLOSE )|(1 <<XPT_DEFERRED ))))return ; -if (test_bit (XPT_DEAD , &svsk->sk_xprt.xpt_flags)) +if (test_bit (XPT_DEAD , &xprt->xpt_flags))return ; cpu =get_cpu (); - pool =svc_pool_for_cpu (svsk->sk_xprt.xpt_server, cpu); + pool =svc_pool_for_cpu (xprt->xpt_server, cpu);put_cpu ();spin_lock_bh (&pool->sp_lock);
@@ -235,11 +234,12 @@ svc_sock_enqueue(struct svc_sock *svsk)if (!list_empty (&pool->sp_threads) && !list_empty (&pool->sp_sockets))printk (KERN_ERR -"svc_sock_enqueue: threads and sockets both waiting??\n" ); +"svc_xprt_enqueue: " +"threads and transports both waiting??\n" ); -if (test_bit (XPT_DEAD , &svsk->sk_xprt.xpt_flags)) { +if (test_bit (XPT_DEAD , &xprt->xpt_flags)) {/* Don't enqueue dead sockets */ -dprintk ("svc: socket %p is dead, not enqueued\n" , svsk->sk_sk); +dprintk ("svc: transport %p is dead, not enqueued\n" , xprt); goto out_unlock; }
@@ -248,28 +248,29 @@ svc_sock_enqueue(struct svc_sock *svsk)* on the idle list. We update XPT_BUSY atomically because * it also guards against trying to enqueue the svc_sock twice. */ -if (test_and_set_bit (XPT_BUSY , &svsk->sk_xprt.xpt_flags)) { +if (test_and_set_bit (XPT_BUSY , &xprt->xpt_flags)) {/* Don't enqueue socket while already enqueued */ -dprintk ("svc: socket %p busy, not enqueued\n" , svsk->sk_sk); +dprintk ("svc: transport %p busy, not enqueued\n" , xprt); goto out_unlock; } -BUG_ON (svsk->sk_xprt.xpt_pool !=NULL ); - svsk->sk_xprt.xpt_pool = pool; +BUG_ON (xprt->xpt_pool !=NULL ); + xprt->xpt_pool = pool;/* Handle pending connection */ -if (test_bit (XPT_CONN , &svsk->sk_xprt.xpt_flags)) +if (test_bit (XPT_CONN , &xprt->xpt_flags)) goto process;/* Handle close in-progress */ -if (test_bit (XPT_CLOSE , &svsk->sk_xprt.xpt_flags)) +if (test_bit (XPT_CLOSE , &xprt->xpt_flags)) goto process;/* Check if we have space to reply to a request */ -if (!svsk->sk_xprt.xpt_ops->xpo_has_wspace (&svsk->sk_xprt)) { +if (!xprt->xpt_ops->xpo_has_wspace (xprt)) {/* Don't enqueue while not enough space for reply */ -dprintk ("svc: no write space, socket %p not enqueued\n" , svsk); - svsk->sk_xprt.xpt_pool =NULL ; -clear_bit (XPT_BUSY , &svsk->sk_xprt.xpt_flags); +dprintk ("svc: no write space, transport %p not enqueued\n" , + xprt); + xprt->xpt_pool =NULL ; +clear_bit (XPT_BUSY , &xprt->xpt_flags); goto out_unlock; }
@@ -278,28 +279,29 @@ svc_sock_enqueue(struct svc_sock *svsk) rqstp =list_entry (pool->sp_threads.next, struct svc_rqst, rq_list); -dprintk ("svc: socket %p served by daemon %p\n" , - svsk->sk_sk, rqstp); +dprintk ("svc: transport %p served by daemon %p\n" , + xprt, rqstp);svc_thread_dequeue (pool, rqstp); -if (rqstp->rq_sock) +if (rqstp->rq_xprt)printk (KERN_ERR -"svc_sock_enqueue: server %p, rq_sock=%p!\n" , - rqstp, rqstp->rq_sock); - rqstp->rq_sock = svsk; -svc_xprt_get (&svsk->sk_xprt); +"svc_xprt_enqueue: server %p, rq_xprt=%p!\n" , + rqstp, rqstp->rq_xprt); + rqstp->rq_xprt = xprt; +svc_xprt_get (xprt); rqstp->rq_reserved = serv->sv_max_mesg; -atomic_add (rqstp->rq_reserved, &svsk->sk_xprt.xpt_reserved); -BUG_ON (svsk->sk_xprt.xpt_pool != pool); +atomic_add (rqstp->rq_reserved, &xprt->xpt_reserved); +BUG_ON (xprt->xpt_pool != pool);wake_up (&rqstp->rq_wait); }else { -dprintk ("svc: socket %p put into queue\n" , svsk->sk_sk); -list_add_tail (&svsk->sk_xprt.xpt_ready, &pool->sp_sockets); -BUG_ON (svsk->sk_xprt.xpt_pool != pool); +dprintk ("svc: transport %p put into queue\n" , xprt); +list_add_tail (&xprt->xpt_ready, &pool->sp_sockets); +BUG_ON (xprt->xpt_pool != pool); } out_unlock:spin_unlock_bh (&pool->sp_lock); } +EXPORT_SYMBOL_GPL (svc_xprt_enqueue);/* * Dequeue the first socket. Must be called with the pool->sp_lock held.
@@ -333,7 +335,7 @@ svc_sock_received(struct svc_sock *svsk) { svsk->sk_xprt.xpt_pool =NULL ;clear_bit (XPT_BUSY , &svsk->sk_xprt.xpt_flags); -svc_sock_enqueue (svsk); +svc_xprt_enqueue (&svsk->sk_xprt); }
@@ -352,11 +354,11 @@ void svc_reserve(struct svc_rqst *rqstp, int space) space += rqstp->rq_res.head[0 ].iov_len;if (space < rqstp->rq_reserved) { -struct svc_sock *svsk = rqstp->rq_sock; -atomic_sub ((rqstp->rq_reserved - space), &svsk->sk_xprt.xpt_reserved); +struct svc_xprt *xprt = rqstp->rq_xprt; +atomic_sub ((rqstp->rq_reserved - space), &xprt->xpt_reserved); rqstp->rq_reserved = space; -svc_sock_enqueue (svsk); +svc_xprt_enqueue (xprt); } }
@@ -684,7 +686,7 @@ svc_udp_data_ready(struct sock *sk, int count) svsk, sk, count, test_bit(XPT_BUSY, &svsk->sk_xprt.xpt_flags));set_bit (XPT_DATA , &svsk->sk_xprt.xpt_flags); -svc_sock_enqueue (svsk); +svc_xprt_enqueue (&svsk->sk_xprt); }if (sk->sk_sleep &&waitqueue_active (sk->sk_sleep))wake_up_interruptible (sk->sk_sleep);
@@ -701,7 +703,7 @@ svc_write_space(struct sock *sk)if (svsk) {dprintk ("svc: socket %p(inet %p), write_space busy=%d\n" , svsk, sk,test_bit (XPT_BUSY , &svsk->sk_xprt.xpt_flags)); -svc_sock_enqueue (svsk); +svc_xprt_enqueue (&svsk->sk_xprt); }if (sk->sk_sleep &&waitqueue_active (sk->sk_sleep)) {
@@ -973,7 +975,7 @@ svc_tcp_listen_data_ready(struct sock *sk, int count_unused)if (sk->sk_state ==TCP_LISTEN ) {if (svsk) {set_bit (XPT_CONN , &svsk->sk_xprt.xpt_flags); -svc_sock_enqueue (svsk); +svc_xprt_enqueue (&svsk->sk_xprt); }else printk ("svc: socket %p: no user data\n" , sk); }
@@ -997,7 +999,7 @@ svc_tcp_state_change(struct sock *sk)printk ("svc: socket %p: no user data\n" , sk); else {set_bit (XPT_CLOSE , &svsk->sk_xprt.xpt_flags); -svc_sock_enqueue (svsk); +svc_xprt_enqueue (&svsk->sk_xprt); }if (sk->sk_sleep &&waitqueue_active (sk->sk_sleep))wake_up_interruptible_all (sk->sk_sleep);
@@ -1012,7 +1014,7 @@ svc_tcp_data_ready(struct sock *sk, int count) sk, sk->sk_user_data);if (svsk) {set_bit (XPT_DATA , &svsk->sk_xprt.xpt_flags); -svc_sock_enqueue (svsk); +svc_xprt_enqueue (&svsk->sk_xprt); }if (sk->sk_sleep &&waitqueue_active (sk->sk_sleep))wake_up_interruptible (sk->sk_sleep);
@@ -1298,7 +1300,7 @@ svc_tcp_sendto(struct svc_rqst *rqstp) (sent<0 )?"got error" :"sent only" , sent, xbufp->len);set_bit (XPT_CLOSE , &rqstp->rq_sock->sk_xprt.xpt_flags); -svc_sock_enqueue (rqstp->rq_sock); +svc_xprt_enqueue (rqstp->rq_xprt); sent = -EAGAIN ; }return sent;
@@ -1481,7 +1483,7 @@ static void svc_check_conn_limits(struct svc_serv *serv)spin_unlock_bh (&serv->sv_lock);if (svsk) { -svc_sock_enqueue (svsk); +svc_xprt_enqueue (&svsk->sk_xprt);svc_xprt_put (&svsk->sk_xprt); } }
@@ -1714,7 +1716,7 @@ svc_age_temp_sockets(unsigned long closure) svsk, get_seconds() - svsk->sk_lastrecv);/* a thread will dequeue and close it soon */ -svc_sock_enqueue (svsk); +svc_xprt_enqueue (&svsk->sk_xprt);svc_xprt_put (&svsk->sk_xprt); }
@@ -1996,7 +1998,7 @@ static void svc_revisit(struct cache_deferred_req *dreq, int too_many)list_add (&dr->handle.recent, &svsk->sk_deferred);spin_unlock (&svsk->sk_lock);set_bit (XPT_DEFERRED , &svsk->sk_xprt.xpt_flags); -svc_sock_enqueue (svsk); +svc_xprt_enqueue (&svsk->sk_xprt);svc_xprt_put (&svsk->sk_xprt); }
PATCH 20/38 svc: Make svc_send transport neutral
In reply to a message not in the archiveMove the sk_mutex field to the transport independent svc_xprt structure. Now all the fields that svc_send touches are transport neutral. Change the svc_send function to use the transport independent svc_xprt directly instead of the transport dependent svc_sock structure.
---
include/linux/sunrpc/svc_xprt.h | 1 + include/linux/sunrpc/svcsock.h | 1 - net/sunrpc/svc_xprt.c | 1 + net/sunrpc/svcsock.c | 19 ++++++++----------- 4 files changed, 10 insertions(+), 12 deletions(-)
include/linux/sunrpc/svc_xprt.h +1 -0
@@ -54,6 +54,7 @@ struct svc_xprt {struct svc_pool *xpt_pool;/* current pool iff queued */ struct svc_serv *xpt_server;/* service for transport */ atomic_t xpt_reserved;/* space on outq that is rsvd */ +struct mutex xpt_mutex;/* to serialize sending data */ };int svc_reg_xprt_class (struct svc_xprt_class *);
include/linux/sunrpc/svcsock.h +0 -1
@@ -24,7 +24,6 @@ struct svc_sock {* sk_info_authunix */ struct list_head sk_deferred;/* deferred requests that need to * be revisted */ -struct mutex sk_mutex;/* to serialize sending data */ /* We keep the old state_change and data_ready CB's here */ void (*sk_ostate)(struct sock *);
net/sunrpc/svc_xprt.c +1 -0
@@ -112,6 +112,7 @@ void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt, xprt->xpt_server = serv;INIT_LIST_HEAD (&xprt->xpt_list);INIT_LIST_HEAD (&xprt->xpt_ready); +mutex_init (&xprt->xpt_mutex); }EXPORT_SYMBOL_GPL (svc_xprt_init);
net/sunrpc/svcsock.c +8 -11
@@ -1637,15 +1637,13 @@ svc_drop(struct svc_rqst *rqstp)int svc_send (struct svc_rqst *rqstp) { -struct svc_sock *svsk; +struct svc_xprt *xprt;int len;struct xdr_buf *xb; -if ((svsk = rqstp->rq_sock) ==NULL ) { -printk (KERN_WARNING "NULL socket pointer in %s:%d\n" , - __FILE__, __LINE__); + xprt = rqstp->rq_xprt; +if (!xprt)return -EFAULT ; - }/* release the receive skb before sending the reply */ rqstp->rq_xprt->xpt_ops->xpo_release_rqst (rqstp);
@@ -1656,13 +1654,13 @@ svc_send(struct svc_rqst *rqstp) xb->page_len + xb->tail[0 ].iov_len; -/* Grab svsk->sk_mutex to serialize outgoing data. */ -mutex_lock (&svsk->sk_mutex); -if (test_bit (XPT_DEAD , &svsk->sk_xprt.xpt_flags)) +/* Grab mutex to serialize outgoing data. */ +mutex_lock (&xprt->xpt_mutex); +if (test_bit (XPT_DEAD , &xprt->xpt_flags)) len = -ENOTCONN ;else - len = svsk->sk_xprt.xpt_ops->xpo_sendto (rqstp); -mutex_unlock (&svsk->sk_mutex); + len = xprt->xpt_ops->xpo_sendto (rqstp); +mutex_unlock (&xprt->xpt_mutex);svc_sock_release (rqstp);if (len == -ECONNREFUSED || len == -ENOTCONN || len == -EAGAIN )
@@ -1764,7 +1762,6 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv, svsk->sk_lastrecv =get_seconds ();spin_lock_init (&svsk->sk_lock);INIT_LIST_HEAD (&svsk->sk_deferred); -mutex_init (&svsk->sk_mutex);/* Initialize the socket */ if (sock->type ==SOCK_DGRAM )
PATCH 21/38 svc: Change svc_sock_received to svc_xprt_received and export it
In reply to a message not in the archiveAll fields touched by svc_sock_received are now transport independent. Change it to use svc_xprt directly. This function is called from transport dependent code, so export it.
---
include/linux/sunrpc/svc_xprt.h | 2 +- net/sunrpc/svcsock.c | 35 +++++++++++++++++------------------ 2 files changed, 18 insertions(+), 19 deletions(-)
include/linux/sunrpc/svc_xprt.h +1 -1
@@ -62,8 +62,8 @@ int svc_unreg_xprt_class(struct svc_xprt_class *);void svc_xprt_init (struct svc_xprt_class *,struct svc_xprt *,struct svc_serv *);int svc_create_xprt (struct svc_serv *,char *,unsigned short ,int ); +void svc_xprt_received (struct svc_xprt *);void svc_xprt_put (struct svc_xprt *xprt); -static inline void svc_xprt_get (struct svc_xprt *xprt) {kref_get (&xprt->xpt_ref);
net/sunrpc/svcsock.c +17 -18
@@ -330,14 +330,13 @@ svc_sock_dequeue(struct svc_pool *pool)* Note: XPT_DATA only gets cleared when a read-attempt finds * no (or insufficient) data. */ -static inline void -svc_sock_received (struct svc_sock *svsk) +void svc_xprt_received (struct svc_xprt *xprt) { - svsk->sk_xprt.xpt_pool =NULL ; -clear_bit (XPT_BUSY , &svsk->sk_xprt.xpt_flags); -svc_xprt_enqueue (&svsk->sk_xprt); + xprt->xpt_pool =NULL ; +clear_bit (XPT_BUSY , &xprt->xpt_flags); +svc_xprt_enqueue (xprt); } - +EXPORT_SYMBOL_GPL (svc_xprt_received);/** * svc_reserve - change the space reserved for the reply to a request.
@@ -766,7 +765,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp) (serv->sv_nrthreads+3) * serv->sv_max_mesg);if ((rqstp->rq_deferred =svc_deferred_dequeue (svsk))) { -svc_sock_received (svsk); +svc_xprt_received (&svsk->sk_xprt);return svc_deferred_recv (rqstp); }
@@ -783,7 +782,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)dprintk ("svc: recvfrom returned error %d\n" , -err);set_bit (XPT_DATA , &svsk->sk_xprt.xpt_flags); } -svc_sock_received (svsk); +svc_xprt_received (&svsk->sk_xprt);return -EAGAIN ; } rqstp->rq_addrlen =sizeof (rqstp->rq_addr);
@@ -798,7 +797,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)/* * Maybe more packets - kick another thread ASAP. */ -svc_sock_received (svsk); +svc_xprt_received (&svsk->sk_xprt); len = skb->len -sizeof (struct udphdr ); rqstp->rq_arg.len = len;
@@ -1104,7 +1103,7 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt) }memcpy (&newsvsk->sk_local, sin, slen); -svc_sock_received (newsvsk); +svc_xprt_received (&newsvsk->sk_xprt);if (serv->sv_stats) serv->sv_stats->nettcpconn++;
@@ -1134,7 +1133,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp) test_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags));if ((rqstp->rq_deferred =svc_deferred_dequeue (svsk))) { -svc_sock_received (svsk); +svc_xprt_received (&svsk->sk_xprt);return svc_deferred_recv (rqstp); }
@@ -1174,7 +1173,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)if (len < want) {dprintk ("svc: short recvfrom while reading record length (%d of %lu)\n" , len, want); -svc_sock_received (svsk); +svc_xprt_received (&svsk->sk_xprt);return -EAGAIN ;/* record header not complete */ }
@@ -1210,7 +1209,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)if (len < svsk->sk_reclen) {dprintk ("svc: incomplete TCP record (%d of %d)\n" , len, svsk->sk_reclen); -svc_sock_received (svsk); +svc_xprt_received (&svsk->sk_xprt);return -EAGAIN ;/* record not complete */ } len = svsk->sk_reclen;
@@ -1250,7 +1249,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp) svsk->sk_reclen =0 ; svsk->sk_tcplen =0 ; -svc_sock_received (svsk); +svc_xprt_received (&svsk->sk_xprt);if (serv->sv_stats) serv->sv_stats->nettcpcnt++;
@@ -1263,7 +1262,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp) error:if (len == -EAGAIN ) {dprintk ("RPC: TCP recvfrom got EAGAIN\n" ); -svc_sock_received (svsk); +svc_xprt_received (&svsk->sk_xprt); }else {printk (KERN_NOTICE "%s: recvfrom returned errno %d\n" , svsk->sk_xprt.xpt_server->sv_name, -len);
@@ -1595,7 +1594,7 @@ svc_recv(struct svc_rqst *rqstp, long timeout)__module_get (newxpt->xpt_class->xcl_owner);svc_check_conn_limits (svsk->sk_xprt.xpt_server); } -svc_sock_received (svsk); +svc_xprt_received (&svsk->sk_xprt); }else { dprintk("svc: server %p, pool %u, socket %p, inuse=%d\n", rqstp, pool->sp_id, svsk,
@@ -1814,7 +1813,7 @@ int svc_addsock(struct svc_serv *serv,else { svsk =svc_setup_socket (serv, so, &err,SVC_SOCK_DEFAULTS );if (svsk) { -svc_sock_received (svsk); +svc_xprt_received (&svsk->sk_xprt); err =0 ; } }
@@ -1870,7 +1869,7 @@ static struct svc_xprt *svc_create_socket(struct svc_serv *serv, }if ((svsk =svc_setup_socket (serv, sock, &error, flags)) !=NULL ) { -svc_sock_received (svsk); +svc_xprt_received (&svsk->sk_xprt);return (struct svc_xprt *)svsk; }
PATCH 22/38 svc: Move accept call to svc_xprt_received to common code
In reply to a message not in the archiveNow that the svc_xprt_received function handles transports, the call to svc_xprt_received in the xpo_tcp_accept function can be moved to common code.
---
net/sunrpc/svcsock.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
net/sunrpc/svcsock.c +1 -2
@@ -1103,8 +1103,6 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt) }memcpy (&newsvsk->sk_local, sin, slen); -svc_xprt_received (&newsvsk->sk_xprt); -if (serv->sv_stats) serv->sv_stats->nettcpconn++;
@@ -1593,6 +1591,7 @@ svc_recv(struct svc_rqst *rqstp, long timeout)*/ __module_get (newxpt->xpt_class->xcl_owner);svc_check_conn_limits (svsk->sk_xprt.xpt_server); +svc_xprt_received (newxpt); }svc_xprt_received (&svsk->sk_xprt); }else {
PATCH 23/38 svc: Remove sk_lastrecv
In reply to a message not in the archiveWith the implementation of the new mark and sweep algorithm for shutting down old connections, the sk_lastrecv field is no longer needed.
---
include/linux/sunrpc/svcsock.h | 1 - net/sunrpc/svcsock.c | 5 +---- 2 files changed, 1 insertions(+), 5 deletions(-)
include/linux/sunrpc/svcsock.h +0 -1
@@ -33,7 +33,6 @@ struct svc_sock {/* private TCP part */ int sk_reclen;/* length of record */ int sk_tcplen;/* current read length */ -time_t sk_lastrecv;/* time of last received request */ /* cache of various info for TCP sockets */ void *sk_info_authunix;
net/sunrpc/svcsock.c +1 -4
@@ -1608,7 +1608,6 @@ svc_recv(struct svc_rqst *rqstp, long timeout)svc_sock_release (rqstp);return -EAGAIN ; } - svsk->sk_lastrecv =get_seconds ();clear_bit (XPT_OLD , &svsk->sk_xprt.xpt_flags); rqstp->rq_secure =svc_port_is_privileged (svc_addr (rqstp));
@@ -1708,8 +1707,7 @@ svc_age_temp_sockets(unsigned long closure)list_del_init (le); svsk = list_entry(le, struct svc_sock, sk_xprt.xpt_list); -dprintk ("queuing svsk %p for closing, %lu seconds old\n" , - svsk,get_seconds () - svsk->sk_lastrecv); +dprintk ("queuing svsk %p for closing\n" , svsk);/* a thread will dequeue and close it soon */ svc_xprt_enqueue (&svsk->sk_xprt);
@@ -1757,7 +1755,6 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv, svsk->sk_ostate = inet->sk_state_change; svsk->sk_odata = inet->sk_data_ready; svsk->sk_owspace = inet->sk_write_space; - svsk->sk_lastrecv =get_seconds ();spin_lock_init (&svsk->sk_lock);INIT_LIST_HEAD (&svsk->sk_deferred);
PATCH 24/38 svc: Move the authinfo cache to svc_xprt.
In reply to a message not in the archiveMove the authinfo cache to svc_xprt. This allows both the TCP and RDMA transports to share this logic. A flag bit is used to determine if auth information is to be cached or not. Previously, this code looked at the transport protocol.
I've also changed the spin_lock/unlock logic so that a lock is not taken for transports that are not caching auth info.
---
include/linux/sunrpc/svc_xprt.h | 4 +++ include/linux/sunrpc/svcsock.h | 5 ---- net/sunrpc/svc_xprt.c | 4 +++ net/sunrpc/svcauth_unix.c | 54 +++++++++++++++++++++------------------ net/sunrpc/svcsock.c | 22 +++++++++------- 5 files changed, 49 insertions(+), 40 deletions(-)
include/linux/sunrpc/svc_xprt.h +4 -0
@@ -50,11 +50,15 @@ struct svc_xprt {#define XPT_OLD 9/* used for xprt aging mark+sweep */ #define XPT_DETACHED 10/* detached from tempsocks list */ #define XPT_LISTENER 11/* listening endpoint */ +#define XPT_CACHE_AUTH 12/* cache auth info */ struct svc_pool *xpt_pool;/* current pool iff queued */ struct svc_serv *xpt_server;/* service for transport */ atomic_t xpt_reserved;/* space on outq that is rsvd */ struct mutex xpt_mutex;/* to serialize sending data */ +spinlock_t xpt_lock;/* protects sk_deferred +* and xpt_auth_cache */ +void *xpt_auth_cache;/* auth cache */ };int svc_reg_xprt_class (struct svc_xprt_class *);
include/linux/sunrpc/svcsock.h +0 -5
@@ -20,8 +20,6 @@ struct svc_sock {struct socket * sk_sock;/* berkeley socket layer */ struct sock * sk_sk;/* INET layer */ -spinlock_t sk_lock;/* protects sk_deferred and -* sk_info_authunix */ struct list_head sk_deferred;/* deferred requests that need to * be revisted */
@@ -34,9 +32,6 @@ struct svc_sock {int sk_reclen;/* length of record */ int sk_tcplen;/* current read length */ -/* cache of various info for TCP sockets */ -void *sk_info_authunix; -struct sockaddr_storage sk_local;/* local address */ struct sockaddr_storage sk_remote;/* remote peer's address */ int sk_remotelen;/* length of address */
net/sunrpc/svc_xprt.c +4 -0
@@ -88,6 +88,9 @@ static void svc_xprt_free(struct kref *kref) container_of(kref, struct svc_xprt, xpt_ref);struct module *owner = xprt->xpt_class->xcl_owner;BUG_ON (atomic_read (&kref->refcount)); +if (test_bit (XPT_CACHE_AUTH , &xprt->xpt_flags) + && xprt->xpt_auth_cache !=NULL ) +svcauth_unix_info_release (xprt->xpt_auth_cache); xprt->xpt_ops->xpo_free (xprt);module_put (owner); }
@@ -113,6 +116,7 @@ void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt,INIT_LIST_HEAD (&xprt->xpt_list);INIT_LIST_HEAD (&xprt->xpt_ready);mutex_init (&xprt->xpt_mutex); +spin_lock_init (&xprt->xpt_lock); }EXPORT_SYMBOL_GPL (svc_xprt_init);
net/sunrpc/svcauth_unix.c +29 -25
70 lines not on this page · raw message
net/sunrpc/svcsock.c +12 -10
@@ -113,12 +113,16 @@ static inline void svc_reclassify_socket(struct socket *sock)switch (sk->sk_family) {case AF_INET :sock_lock_init_class_and_name (sk,"slock-AF_INET-NFSD" , - &svc_slock_key[0 ],"sk_lock-AF_INET-NFSD" , &svc_key[0 ]); + &svc_slock_key[0 ], +"sk_xprt.xpt_lock-AF_INET-NFSD" , + &svc_key[0 ]);break ;case AF_INET6 :sock_lock_init_class_and_name (sk,"slock-AF_INET6-NFSD" , - &svc_slock_key[1 ],"sk_lock-AF_INET6-NFSD" , &svc_key[1 ]); + &svc_slock_key[1 ], +"sk_xprt.xpt_lock-AF_INET6-NFSD" , + &svc_key[1 ]);break ;default :
@@ -927,6 +931,7 @@ static void svc_udp_init(struct svc_sock *svsk, struct svc_serv *serv)mm_segment_t oldfs;svc_xprt_init (&svc_udp_class, &svsk->sk_xprt, serv); +clear_bit (XPT_CACHE_AUTH , &svsk->sk_xprt.xpt_flags); svsk->sk_sk->sk_data_ready = svc_udp_data_ready; svsk->sk_sk->sk_write_space = svc_write_space;
@@ -1382,7 +1387,7 @@ static void svc_tcp_init(struct svc_sock *svsk, struct svc_serv *serv)struct tcp_sock *tp =tcp_sk (sk);svc_xprt_init (&svc_tcp_class, &svsk->sk_xprt, serv); - +set_bit (XPT_CACHE_AUTH , &svsk->sk_xprt.xpt_flags);if (sk->sk_state ==TCP_LISTEN ) {dprintk ("setting up TCP socket for listening\n" );set_bit (XPT_LISTENER , &svsk->sk_xprt.xpt_flags);
@@ -1755,7 +1760,6 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv, svsk->sk_ostate = inet->sk_state_change; svsk->sk_odata = inet->sk_data_ready; svsk->sk_owspace = inet->sk_write_space; -spin_lock_init (&svsk->sk_lock);INIT_LIST_HEAD (&svsk->sk_deferred);/* Initialize the socket */
@@ -1900,8 +1904,6 @@ static void svc_sock_free(struct svc_xprt *xprt) struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);dprintk ("svc: svc_sock_free(%p)\n" , svsk); -if (svsk->sk_info_authunix !=NULL ) -svcauth_unix_info_release (svsk->sk_info_authunix);if (svsk->sk_sock->file)sockfd_put (svsk->sk_sock);else
@@ -1986,9 +1988,9 @@ static void svc_revisit(struct cache_deferred_req *dreq, int too_many)dprintk ("revisit queued\n" ); svsk = dr->svsk; dr->svsk =NULL ; -spin_lock (&svsk->sk_lock); +spin_lock (&svsk->sk_xprt.xpt_lock);list_add (&dr->handle.recent, &svsk->sk_deferred); -spin_unlock (&svsk->sk_lock); +spin_unlock (&svsk->sk_xprt.xpt_lock);set_bit (XPT_DEFERRED , &svsk->sk_xprt.xpt_flags);svc_xprt_enqueue (&svsk->sk_xprt);svc_xprt_put (&svsk->sk_xprt);
@@ -2054,7 +2056,7 @@ static struct svc_deferred_req *svc_deferred_dequeue(struct svc_sock *svsk)if (!test_bit (XPT_DEFERRED , &svsk->sk_xprt.xpt_flags))return NULL ; -spin_lock (&svsk->sk_lock); +spin_lock (&svsk->sk_xprt.xpt_lock);clear_bit (XPT_DEFERRED , &svsk->sk_xprt.xpt_flags);if (!list_empty (&svsk->sk_deferred)) { dr = list_entry(svsk->sk_deferred.next,
@@ -2063,7 +2065,7 @@ static struct svc_deferred_req *svc_deferred_dequeue(struct svc_sock *svsk)list_del_init (&dr->handle.recent);set_bit (XPT_DEFERRED , &svsk->sk_xprt.xpt_flags); } -spin_unlock (&svsk->sk_lock); +spin_unlock (&svsk->sk_xprt.xpt_lock);return dr; }
PATCH 25/38 svc: Make deferral processing xprt independent
In reply to a message not in the archiveThis patch moves the transport independent sk_deferred list to the svc_xprt structure and updates the svc_deferred_req structure to keep pointers to svc_xprt's directly. The deferral processing code is also moved out of the transport dependent recvfrom functions and into the generic svc_recv path.
---
include/linux/sunrpc/svc.h | 2 + include/linux/sunrpc/svc_xprt.h | 2 + include/linux/sunrpc/svcsock.h | 3 -- net/sunrpc/svc_xprt.c | 1 + net/sunrpc/svcsock.c | 58 +++++++++++++++++---------------------- 5 files changed, 29 insertions(+), 37 deletions(-)
include/linux/sunrpc/svc.h +1 -1
@@ -320,7 +320,7 @@ static inline void svc_free_res_pages(struct svc_rqst *rqstp)struct svc_deferred_req {u32 prot;/* protocol (UDP or TCP) */ -struct svc_sock *svsk; +struct svc_xprt *xprt;struct sockaddr_storage addr;/* where reply must go */ size_t addrlen;union svc_addr_u daddr;/* where reply must come from */
include/linux/sunrpc/svc_xprt.h +2 -0
@@ -59,6 +59,8 @@ struct svc_xprt {spinlock_t xpt_lock;/* protects sk_deferred * and xpt_auth_cache */ void *xpt_auth_cache;/* auth cache */ +struct list_head xpt_deferred;/* deferred requests that need +* to be revisted */ };int svc_reg_xprt_class (struct svc_xprt_class *);
include/linux/sunrpc/svcsock.h +0 -3
@@ -20,9 +20,6 @@ struct svc_sock {struct socket * sk_sock;/* berkeley socket layer */ struct sock * sk_sk;/* INET layer */ -struct list_head sk_deferred;/* deferred requests that need to -* be revisted */ -/* We keep the old state_change and data_ready CB's here */ void (*sk_ostate)(struct sock *);void (*sk_odata)(struct sock *,int bytes);
net/sunrpc/svc_xprt.c +1 -0
@@ -115,6 +115,7 @@ void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt, xprt->xpt_server = serv;INIT_LIST_HEAD (&xprt->xpt_list);INIT_LIST_HEAD (&xprt->xpt_ready); +INIT_LIST_HEAD (&xprt->xpt_deferred);mutex_init (&xprt->xpt_mutex);spin_lock_init (&xprt->xpt_lock); }
net/sunrpc/svcsock.c +25 -33
119 lines not on this page · raw message
PATCH 26/38 svc: Move the sockaddr information to svc_xprt
In reply to a message not in the archiveThis patch moves the transport sockaddr to the svc_xprt structure. Convenience functions are added to set and get the local and remote addresses of a transport from the transport provider as well as determine the length of a sockaddr.
A transport is responsible for setting the xpt_local and xpt_remote addresses in the svc_xprt structure as part of transport creation and xpo_accept processing. This cannot be done in a generic way and in fact varies between TCP, UDP and RDMA. A set of xpo_ functions (e.g. getlocalname, getremotename) could have been added but this would have resulted in additional caching and copying of the addresses around. Note that the xpt_local address should also be set on listening endpoints; for TCP/RDMA this is done as part of endpoint creation.
For connected transports like TCP and RDMA, the addresses never change and can be set once and copied into the rqstp structure for each request. For UDP, however, the local and remote addresses may change for each request. In this case, the address information is obtained from the UDP recvmsg info and copied into the rqstp structure from there.
A svc_xprt_local_port function was also added that returns the local port given a transport. This is used by svc_create_xprt when returning the port associated with a newly created transport, and later when creating a generic find transport service to check if a service is already listening on a given port.
---
include/linux/sunrpc/svc_xprt.h | 51 ++++++++++++++++++++++++++++++++++++ include/linux/sunrpc/svcsock.h | 4 --- net/sunrpc/svc_xprt.c | 31 ++++++++++++++++++++-- net/sunrpc/svcsock.c | 56 +++++++++++++++++++++------------------ 4 files changed, 110 insertions(+), 32 deletions(-)
include/linux/sunrpc/svc_xprt.h +51 -0
@@ -61,6 +61,10 @@ struct svc_xprt {void *xpt_auth_cache;/* auth cache */ struct list_head xpt_deferred;/* deferred requests that need * to be revisted */ +struct sockaddr_storage xpt_local;/* local address */ +size_t xpt_locallen;/* length of address */ +struct sockaddr_storage xpt_remote;/* remote peer's address */ +size_t xpt_remotelen;/* length of address */ };int svc_reg_xprt_class (struct svc_xprt_class *);
@@ -70,9 +74,56 @@ void svc_xprt_init(struct svc_xprt_class *, struct svc_xprt *,int svc_create_xprt (struct svc_serv *,char *,unsigned short ,int );void svc_xprt_received (struct svc_xprt *);void svc_xprt_put (struct svc_xprt *xprt); +void svc_xprt_copy_addrs (struct svc_rqst *rqstp,struct svc_xprt *xprt);static inline void svc_xprt_get (struct svc_xprt *xprt) {kref_get (&xprt->xpt_ref); } +static inline void svc_xprt_set_local (struct svc_xprt *xprt, +struct sockaddr *sa,int salen) +{ +memcpy (&xprt->xpt_local, sa, salen); + xprt->xpt_locallen = salen; +} +static inline void svc_xprt_set_remote (struct svc_xprt *xprt, +struct sockaddr *sa,int salen) +{ +memcpy (&xprt->xpt_remote, sa, salen); + xprt->xpt_remotelen = salen; +} +static inline unsigned short svc_addr_port (struct sockaddr *sa) +{ +unsigned short ret =0 ; +switch (sa->sa_family) { +case AF_INET : + ret =ntohs (((struct sockaddr_in *)sa)->sin_port); +break ; +case AF_INET6 : + ret =ntohs (((struct sockaddr_in6 *)sa)->sin6_port); +break ; + } +return ret; +} + +static inline size_t svc_addr_len (struct sockaddr *sa) +{ +switch (sa->sa_family) { +case AF_INET : +return sizeof (struct sockaddr_in ); +case AF_INET6 : +return sizeof (struct sockaddr_in6 ); + } +return -EAFNOSUPPORT ; +} + +static inline unsigned short svc_xprt_local_port (struct svc_xprt *xprt) +{ +return svc_addr_port ((struct sockaddr *)&xprt->xpt_local); +} + +static inline unsigned short svc_xprt_remote_port (struct svc_xprt *xprt) +{ +return svc_addr_port ((struct sockaddr *)&xprt->xpt_remote); +}#endif /* SUNRPC_SVC_XPRT_H */
include/linux/sunrpc/svcsock.h +0 -4
@@ -28,10 +28,6 @@ struct svc_sock {/* private TCP part */ int sk_reclen;/* length of record */ int sk_tcplen;/* current read length */ - -struct sockaddr_storage sk_local;/* local address */ -struct sockaddr_storage sk_remote;/* remote peer's address */ -int sk_remotelen;/* length of address */ };/*
net/sunrpc/svc_xprt.c +29 -2
@@ -138,7 +138,6 @@ int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port,spin_unlock (&svc_xprt_class_lock);if (try_module_get (xcl->xcl_owner)) {struct svc_xprt *newxprt; - ret =0 ; newxprt = xcl->xcl_ops->xpo_create (serv, (struct sockaddr *)&sin, sizeof(sin),
@@ -146,7 +145,8 @@ int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port,if (IS_ERR (newxprt)) {module_put (xcl->xcl_owner); ret =PTR_ERR (newxprt); - } + }else + ret =svc_xprt_local_port (newxprt); } goto out; }
@@ -157,3 +157,30 @@ int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port,return ret; }EXPORT_SYMBOL_GPL (svc_create_xprt); + +/* +* Copy the local and remote xprt addresses to the rqstp structure +*/ +void svc_xprt_copy_addrs (struct svc_rqst *rqstp,struct svc_xprt *xprt) +{ +struct sockaddr *sin; + +memcpy (&rqstp->rq_addr, &xprt->xpt_remote, xprt->xpt_remotelen); + rqstp->rq_addrlen = xprt->xpt_remotelen; + +/* +* Destination address in request is needed for binding the +* source address in RPC replies/callbacks later. +*/ + sin = (struct sockaddr *)&xprt->xpt_local; +switch (sin->sa_family) { +case AF_INET : + rqstp->rq_daddr.addr = ((struct sockaddr_in *)sin)->sin_addr; +break ; +case AF_INET6 : + rqstp->rq_daddr.addr6 = ((struct sockaddr_in6 *)sin)->sin6_addr; +break ; + } +} +EXPORT_SYMBOL_GPL (svc_xprt_copy_addrs); +
net/sunrpc/svcsock.c +30 -26
122 lines not on this page · raw message
PATCH 27/38 svc: Make svc_sock_release svc_xprt_release
In reply to a message not in the archiveThe svc_sock_release function only touches transport independent fields. Change the function to manipulate svc_xprt directly instead of the transport dependent svc_sock structure.
---
net/sunrpc/svcsock.c | 16 +++++++--------- 1 files changed, 7 insertions(+), 9 deletions(-)
net/sunrpc/svcsock.c +7 -9
@@ -365,10 +365,9 @@ void svc_reserve(struct svc_rqst *rqstp, int space) } } -static void -svc_sock_release (struct svc_rqst *rqstp) +static void svc_xprt_release (struct svc_rqst *rqstp) { -struct svc_sock *svsk = rqstp->rq_sock; +struct svc_xprt *xprt = rqstp->rq_xprt; rqstp->rq_xprt->xpt_ops->xpo_release_rqst (rqstp);
@@ -376,7 +375,6 @@ svc_sock_release(struct svc_rqst *rqstp) rqstp->rq_res.page_len =0 ; rqstp->rq_res.page_base =0 ; -/* Reset response buffer and release * the reservation. * But first, check that enough space was reserved
@@ -389,9 +387,9 @@ svc_sock_release(struct svc_rqst *rqstp) rqstp->rq_res.head[0 ].iov_len =0 ;svc_reserve (rqstp,0 ); - rqstp->rq_sock =NULL ; + rqstp->rq_xprt =NULL ; -svc_xprt_put (&svsk->sk_xprt); +svc_xprt_put (xprt); }/*
@@ -1595,7 +1593,7 @@ svc_recv(struct svc_rqst *rqstp, long timeout)/* No data, incomplete (TCP) read, or accept() */ if (len ==0 || len == -EAGAIN ) { rqstp->rq_res.len =0 ; -svc_sock_release (rqstp); +svc_xprt_release (rqstp);return -EAGAIN ; }clear_bit (XPT_OLD , &svsk->sk_xprt.xpt_flags);
@@ -1615,7 +1613,7 @@ void svc_drop(struct svc_rqst *rqstp) {dprintk ("svc: socket %p dropped request\n" , rqstp->rq_sock); -svc_sock_release (rqstp); +svc_xprt_release (rqstp); }/*
@@ -1648,7 +1646,7 @@ svc_send(struct svc_rqst *rqstp)else len = xprt->xpt_ops->xpo_sendto (rqstp);mutex_unlock (&xprt->xpt_mutex); -svc_sock_release (rqstp); +svc_xprt_release (rqstp);if (len == -ECONNREFUSED || len == -ENOTCONN || len == -EAGAIN )return 0 ;
PATCH 28/38 svc: Make svc_recv transport neutral
In reply to a message not in the archiveAll of the transport field and functions used by svc_recv are now transport independent. Change the svc_recv function to use the svc_xprt structure directly instead of the transport specific svc_sock structure.
---
net/sunrpc/svcsock.c | 61 +++++++++++++++++++++++++------------------------- 1 files changed, 31 insertions(+), 30 deletions(-)
net/sunrpc/svcsock.c +31 -30
@@ -310,22 +310,21 @@ EXPORT_SYMBOL_GPL(svc_xprt_enqueue);/* * Dequeue the first socket. Must be called with the pool->sp_lock held. */ -static inline struct svc_sock * -svc_sock_dequeue (struct svc_pool *pool) +static struct svc_xprt *svc_xprt_dequeue (struct svc_pool *pool) { -struct svc_sock *svsk; +struct svc_xprt *xprt;if (list_empty (&pool->sp_sockets))return NULL ; - svsk =list_entry (pool->sp_sockets.next, - struct svc_sock, sk_xprt.xpt_ready); -list_del_init (&svsk->sk_xprt.xpt_ready); + xprt =list_entry (pool->sp_sockets.next, + struct svc_xprt, xpt_ready); +list_del_init (&xprt->xpt_ready); -dprintk ("svc: socket %p dequeued, inuse=%d\n" , - svsk->sk_sk,atomic_read (&svsk->sk_xprt.xpt_ref.refcount)); +dprintk ("svc: transport %p dequeued, inuse=%d\n" , + xprt,atomic_read (&xprt->xpt_ref.refcount)); -return svsk; +return xprt; }/*
@@ -1477,20 +1476,20 @@ static void svc_check_conn_limits(struct svc_serv *serv)int svc_recv (struct svc_rqst *rqstp,long timeout) { -struct svc_sock *svsk =NULL ; +struct svc_xprt *xprt =NULL ;struct svc_serv *serv = rqstp->rq_server;struct svc_pool *pool = rqstp->rq_pool;int len, i; -int pages; +int pages;struct xdr_buf *arg;DECLARE_WAITQUEUE (wait, current);dprintk ("svc: server %p waiting for data (to = %ld)\n" , rqstp, timeout); -if (rqstp->rq_sock) +if (rqstp->rq_xprt)printk (KERN_ERR -"svc_recv: service %p, socket not NULL!\n" , +"svc_recv: service %p, transport not NULL!\n" , rqstp);if (waitqueue_active (&rqstp->rq_wait)) printk(KERN_ERR
@@ -1527,11 +1526,12 @@ svc_recv(struct svc_rqst *rqstp, long timeout)return -EINTR ;spin_lock_bh (&pool->sp_lock); -if ((svsk =svc_sock_dequeue (pool)) !=NULL ) { - rqstp->rq_sock = svsk; -svc_xprt_get (&svsk->sk_xprt); + xprt =svc_xprt_dequeue (pool); +if (xprt) { + rqstp->rq_xprt = xprt; +svc_xprt_get (xprt); rqstp->rq_reserved = serv->sv_max_mesg; -atomic_add (rqstp->rq_reserved, &svsk->sk_xprt.xpt_reserved); +atomic_add (rqstp->rq_reserved, &xprt->xpt_reserved); }else {/* No data pending. Go to sleep */ svc_thread_enqueue (pool, rqstp);
@@ -1551,7 +1551,8 @@ svc_recv(struct svc_rqst *rqstp, long timeout)spin_lock_bh (&pool->sp_lock);remove_wait_queue (&rqstp->rq_wait, &wait); -if (!(svsk = rqstp->rq_sock)) { + xprt = rqstp->rq_xprt; +if (!xprt) {svc_thread_dequeue (pool, rqstp);spin_unlock_bh (&pool->sp_lock);dprintk ("svc: server %p, no data yet\n" , rqstp);
@@ -1561,12 +1562,12 @@ svc_recv(struct svc_rqst *rqstp, long timeout)spin_unlock_bh (&pool->sp_lock); len =0 ; -if (test_bit (XPT_CLOSE , &svsk->sk_xprt.xpt_flags)) { +if (test_bit (XPT_CLOSE , &xprt->xpt_flags)) {dprintk ("svc_recv: found XPT_CLOSE\n" ); -svc_delete_xprt (&svsk->sk_xprt); - }else if (test_bit (XPT_LISTENER , &svsk->sk_xprt.xpt_flags)) { +svc_delete_xprt (xprt); + }else if (test_bit (XPT_LISTENER , &xprt->xpt_flags)) {struct svc_xprt *newxpt; - newxpt = svsk->sk_xprt.xpt_ops->xpo_accept (&svsk->sk_xprt); + newxpt = xprt->xpt_ops->xpo_accept (xprt);if (newxpt) {/* * We know this module_get will succeed because the
@@ -1576,17 +1577,17 @@ svc_recv(struct svc_rqst *rqstp, long timeout)svc_check_conn_limits (svsk->sk_xprt.xpt_server);svc_xprt_received (newxpt); } -svc_xprt_received (&svsk->sk_xprt); +svc_xprt_received (xprt); }else { -dprintk ("svc: server %p, pool %u, socket %p, inuse=%d\n" , - rqstp, pool->sp_id, svsk, -atomic_read (&svsk->sk_xprt.xpt_ref.refcount)); - rqstp->rq_deferred =svc_deferred_dequeue (&svsk->sk_xprt); +dprintk ("svc: server %p, pool %u, transport %p, inuse=%d\n" , + rqstp, pool->sp_id, xprt, +atomic_read (&xprt->xpt_ref.refcount)); + rqstp->rq_deferred =svc_deferred_dequeue (xprt);if (rqstp->rq_deferred) { -svc_xprt_received (&svsk->sk_xprt); +svc_xprt_received (xprt); len =svc_deferred_recv (rqstp); }else - len = svsk->sk_xprt.xpt_ops->xpo_recvfrom (rqstp); + len = xprt->xpt_ops->xpo_recvfrom (rqstp);dprintk ("svc: got len=%d\n" , len); }
@@ -1596,7 +1597,7 @@ svc_recv(struct svc_rqst *rqstp, long timeout)svc_xprt_release (rqstp);return -EAGAIN ; } -clear_bit (XPT_OLD , &svsk->sk_xprt.xpt_flags); +clear_bit (XPT_OLD , &xprt->xpt_flags); rqstp->rq_secure =svc_port_is_privileged (svc_addr (rqstp)); rqstp->rq_chandle.defer = svc_defer;
PATCH 29/38 svc: Make svc_age_temp_sockets svc_age_temp_transports
In reply to a message not in the archiveThis function is transport independent. Change it to use svc_xprt directly and change it's name to reflect this.
---
net/sunrpc/svcsock.c | 37 +++++++++++++++++++------------------ 1 files changed, 19 insertions(+), 18 deletions(-)
net/sunrpc/svcsock.c +19 -18
@@ -1658,49 +1658,50 @@ svc_send(struct svc_rqst *rqstp)* Timer function to close old temporary sockets, using * a mark-and-sweep algorithm. */ -static void -svc_age_temp_sockets (unsigned long closure) +static void svc_age_temp_xprts (unsigned long closure) {struct svc_serv *serv = (struct svc_serv *)closure; -struct svc_sock *svsk; +struct svc_xprt *xprt;struct list_head *le, *next;LIST_HEAD (to_be_aged); -dprintk ("svc_age_temp_sockets\n" ); +dprintk ("svc_age_temp_xprts\n" );if (!spin_trylock_bh (&serv->sv_lock)) {/* busy, try again 1 sec later */ -dprintk ("svc_age_temp_sockets: busy\n" ); +dprintk ("svc_age_temp_xprts: busy\n" );mod_timer (&serv->sv_temptimer, jiffies +HZ );return ; }list_for_each_safe (le, next, &serv->sv_tempsocks) { - svsk = list_entry(le, struct svc_sock, sk_xprt.xpt_list); + xprt = list_entry(le, struct svc_xprt, xpt_list); -if (!test_and_set_bit (XPT_OLD , &svsk->sk_xprt.xpt_flags)) +/* First time through, just mark it OLD. Second time +* through, close it. */ +if (!test_and_set_bit (XPT_OLD , &xprt->xpt_flags))continue ; -if (atomic_read (&svsk->sk_xprt.xpt_ref.refcount) >1 - ||test_bit (XPT_BUSY , &svsk->sk_xprt.xpt_flags)) +if (atomic_read (&xprt->xpt_ref.refcount) >1 + ||test_bit (XPT_BUSY , &xprt->xpt_flags))continue ; -svc_xprt_get (&svsk->sk_xprt); +svc_xprt_get (xprt);list_move (le, &to_be_aged); -set_bit (XPT_CLOSE , &svsk->sk_xprt.xpt_flags); -set_bit (XPT_DETACHED , &svsk->sk_xprt.xpt_flags); +set_bit (XPT_CLOSE , &xprt->xpt_flags); +set_bit (XPT_DETACHED , &xprt->xpt_flags); }spin_unlock_bh (&serv->sv_lock);while (!list_empty (&to_be_aged)) { le = to_be_aged.next; -/* fiddling the sk_xprt.xpt_list node is safe 'cos we're XPT_DETACHED */ +/* fiddling the xpt_list node is safe 'cos we're XPT_DETACHED */ list_del_init (le); - svsk = list_entry(le, struct svc_sock, sk_xprt.xpt_list); + xprt = list_entry(le, struct svc_xprt, xpt_list); -dprintk ("queuing svsk %p for closing\n" , svsk); +dprintk ("queuing xprt %p for closing\n" , xprt);/* a thread will dequeue and close it soon */ -svc_xprt_enqueue (&svsk->sk_xprt); -svc_xprt_put (&svsk->sk_xprt); +svc_xprt_enqueue (xprt); +svc_xprt_put (xprt); }mod_timer (&serv->sv_temptimer, jiffies + svc_conn_age_period *HZ );
@@ -1758,7 +1759,7 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv, serv->sv_tmpcnt++;if (serv->sv_temptimer.function ==NULL ) {/* setup timer to age temp sockets */ -setup_timer (&serv->sv_temptimer, svc_age_temp_sockets, +setup_timer (&serv->sv_temptimer, svc_age_temp_xprts, (unsigned long )serv);mod_timer (&serv->sv_temptimer, jiffies + svc_conn_age_period *HZ );
PATCH 30/38 svc: Move common create logic to common code
In reply to a message not in the archiveMove the code that adds a transport instance to the sv_tempsocks and sv_permsocks lists out of the transport specific functions and into core logic.
---
net/sunrpc/svc_xprt.c | 9 ++++++++- net/sunrpc/svcsock.c | 39 +++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 21 deletions(-)
net/sunrpc/svc_xprt.c +8 -1
@@ -145,8 +145,15 @@ int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port,if (IS_ERR (newxprt)) {module_put (xcl->xcl_owner); ret =PTR_ERR (newxprt); - }else + }else { +clear_bit (XPT_TEMP , + &newxprt->xpt_flags); +spin_lock_bh (&serv->sv_lock); +list_add (&newxprt->xpt_list, + &serv->sv_permsocks); +spin_unlock_bh (&serv->sv_lock); ret =svc_xprt_local_port (newxprt); + } } goto out; }
net/sunrpc/svcsock.c +19 -20
@@ -94,6 +94,7 @@ static int svc_deferred_recv(struct svc_rqst *rqstp);static struct cache_deferred_req *svc_defer (struct cache_req *req);static struct svc_xprt *svc_create_socket (struct svc_serv *,int ,struct sockaddr *,int ,int ); +static void svc_age_temp_xprts (unsigned long closure);/* apparently the "standard" is that clients close * idle connections after 5 minutes, servers after
@@ -1574,7 +1575,20 @@ svc_recv(struct svc_rqst *rqstp, long timeout)* listener holds a reference too */ __module_get (newxpt->xpt_class->xcl_owner); -svc_check_conn_limits (svsk->sk_xprt.xpt_server); +svc_check_conn_limits (xprt->xpt_server); +spin_lock_bh (&serv->sv_lock); +set_bit (XPT_TEMP , &newxpt->xpt_flags); +list_add (&newxpt->xpt_list, &serv->sv_tempsocks); + serv->sv_tmpcnt++; +if (serv->sv_temptimer.function ==NULL ) { +/* setup timer to age temp sockets */ +setup_timer (&serv->sv_temptimer, + svc_age_temp_xprts, + (unsigned long )serv); +mod_timer (&serv->sv_temptimer, + jiffies + svc_conn_age_period *HZ ); + } +spin_unlock_bh (&serv->sv_lock);svc_xprt_received (newxpt); }svc_xprt_received (xprt);
@@ -1718,7 +1732,6 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,struct svc_sock *svsk;struct sock *inet;int pmap_register = !(flags &SVC_SOCK_ANONYMOUS ); -int is_temporary = flags &SVC_SOCK_TEMPORARY ;dprintk ("svc: svc_setup_socket %p\n" , sock);if (!(svsk =kzalloc (sizeof (*svsk),GFP_KERNEL ))) {
@@ -1752,24 +1765,6 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,else svc_tcp_init (svsk, serv); -spin_lock_bh (&serv->sv_lock); -if (is_temporary) { -set_bit (XPT_TEMP , &svsk->sk_xprt.xpt_flags); -list_add (&svsk->sk_xprt.xpt_list, &serv->sv_tempsocks); - serv->sv_tmpcnt++; -if (serv->sv_temptimer.function ==NULL ) { -/* setup timer to age temp sockets */ -setup_timer (&serv->sv_temptimer, svc_age_temp_xprts, - (unsigned long )serv); -mod_timer (&serv->sv_temptimer, - jiffies + svc_conn_age_period *HZ ); - } - }else { -clear_bit (XPT_TEMP , &svsk->sk_xprt.xpt_flags); -list_add (&svsk->sk_xprt.xpt_list, &serv->sv_permsocks); - } -spin_unlock_bh (&serv->sv_lock); -dprintk ("svc: svc_setup_socket created %p (inet %p)\n" , svsk, svsk->sk_sk);
@@ -1805,6 +1800,10 @@ int svc_addsock(struct svc_serv *serv,svc_xprt_received (&svsk->sk_xprt); err =0 ; } +clear_bit (XPT_TEMP , &svsk->sk_xprt.xpt_flags); +spin_lock_bh (&serv->sv_lock); +list_add (&svsk->sk_xprt.xpt_list, &serv->sv_permsocks); +spin_unlock_bh (&serv->sv_lock); }if (err) {sockfd_put (so);
A message that is not in the archive (sent off-list or not yet received): 20071211233300.15718.30136.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org
Re: [PATCH 30/38] svc: Move common create logic to common code
Quoted 23 lines · Tom Tucker
Move the code that adds a transport instance to the
sv_tempsocksandsv_permsockslists out of the transport specific functions and into core logic.Signed-off-by Tom Tucker <[email protected]>---
net/sunrpc/svc_xprt.c | 9 ++++++++- net/sunrpc/svcsock.c | 39 +++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 21 deletions(-)net/sunrpc/svc_xprt.c +2
-1@@ -145,8 +145,15 @@ int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port,if (IS_ERR (newxprt)) {module_put (xcl->xcl_owner); ret =PTR_ERR (newxprt); - }else + }else { + clear_bit(XPT_TEMP,
net/sunrpc/svc_xprt.c int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port, · line 159
Quoted 10 lines
net/sunrpc/svc_xprt.c +6
-0+ &newxprt->xpt_flags); +spin_lock_bh (&serv->sv_lock); +list_add (&newxprt->xpt_list, + &serv->sv_permsocks); +spin_unlock_bh (&serv->sv_lock); ret =svc_xprt_local_port (newxprt); + } } goto out; }
The nesting here is getting kind of deep.
A bit more idiomatic for kernel code would be (untested) something like:
list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list) {
struct svc_xprt *newxprt;
if (strcmp(xprt_name, xcl->xcl_name) != 0)
continue;
spin_unlock(&svc_xprt_class_lock);
if (!try_module_get(xcl->xcl_owner))
goto out;
# (assuming that's the right order)
newxprt = xcl->xcl_ops->xpo_create (serv,
(struct sockaddr *)&sin, sizeof(sin), flags);
if (IS_ERR(newxprt)) {
module_put(xcl->xcl_owner);
ret = PTR_ERR(newxprt);
goto out;
}
clear_bit(XPT_TEMP, &newxprt->xpt_flags);
spin_lock_bh(&serv->sv_lock);
list_add(&newxprt->xpt_list, &serv->sv_permsocks);
spin_unlock_bh(&serv->sv_lock);
ret = svc_xprt_local_port(newxprt);
goto out;
}At least to my eyes, that also makes it a lot easier to see what the important (succesful) case is, since that's the code that stays unindented all the way to the end.
I'd also be inclined to replace those "got out"'s by "returns". I don't really see the point of the label when it's leads to something that's literally just a return.
--b.
Re: [PATCH 30/38] svc: Move common create logic to common code
Quoted 38 lines · J. Bruce Fields
Quoted 33 lines · Tom Tucker
Move the code that adds a transport instance to the
sv_tempsocksandsv_permsockslists out of the transport specific functions and into core logic.Signed-off-by Tom Tucker <[email protected]>---
net/sunrpc/svc_xprt.c | 9 ++++++++- net/sunrpc/svcsock.c | 39 +++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 21 deletions(-)net/sunrpc/svc_xprt.c +8
-1@@ -145,8 +145,15 @@ int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port, if (IS_ERR(newxprt)) {module_put (xcl->xcl_owner); ret =PTR_ERR (newxprt); - } else + } else { +clear_bit (XPT_TEMP , + &newxprt->xpt_flags); +spin_lock_bh (&serv->sv_lock); +list_add (&newxprt->xpt_list, + &serv->sv_permsocks); +spin_unlock_bh (&serv->sv_lock); ret =svc_xprt_local_port (newxprt); + } } goto out;Quoted 1 line
}
The nesting here is getting kind of deep.
Quoted 2 lines
A bit more idiomatic for kernel code would be (untested) something like:
I agree. I'll look at refactoring this.
Quoted 37 lines
list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list){ structsvc_xprt*newxprt;if (
strcmp(xprt_name, xcl->xcl_name)!= 0) continue;spin_unlock(&svc_xprt_class_lock);
if (!try_module_get(xcl->xcl_owner))
goto out;
# (assuming that's the right order) newxprt =xcl->xcl_ops->xpo_create(serv, (struct sockaddr *)&sin, sizeof(sin), flags); if (IS_ERR(newxprt)) {module_put(xcl->xcl_owner);
ret =PTR_ERR(newxprt);
goto out;
}clear_bit(XPT_TEMP, &newxprt->xpt_flags);spin_lock_bh(&serv->sv_lock);list_add(&newxprt->xpt_list, &serv->sv_permsocks);spin_unlock_bh(&serv->sv_lock);
ret =svc_xprt_local_port(newxprt);
goto out;
}At least to my eyes, that also makes it a lot easier to see what the important (succesful) case is, since that's the code that stays unindented all the way to the end.
I'd also be inclined to replace those "got out"'s by "returns". I don't really see the point of the label when it's leads to something that's literally just a return.
--b.
-
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
Re: [PATCH 30/38] svc: Move common create logic to common code
In reply to J. Bruce FieldsQuoted 64 lines · J. Bruce Fields
Quoted 33 lines · Tom Tucker
Move the code that adds a transport instance to the
sv_tempsocksandsv_permsockslists out of the transport specific functions and into core logic.Signed-off-by Tom Tucker <[email protected]>---
net/sunrpc/svc_xprt.c | 9 ++++++++- net/sunrpc/svcsock.c | 39 +++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 21 deletions(-)net/sunrpc/svc_xprt.c +8
-1@@ -145,8 +145,15 @@ int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port, if (IS_ERR(newxprt)) {module_put (xcl->xcl_owner); ret =PTR_ERR (newxprt); - } else + } else { +clear_bit (XPT_TEMP , + &newxprt->xpt_flags); +spin_lock_bh (&serv->sv_lock); +list_add (&newxprt->xpt_list, + &serv->sv_permsocks); +spin_unlock_bh (&serv->sv_lock); ret =svc_xprt_local_port (newxprt); + } } goto out;Quoted 1 line
}
The nesting here is getting kind of deep.
A bit more idiomatic for kernel code would be (untested) something like:
list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list){ structsvc_xprt*newxprt;if (
strcmp(xprt_name, xcl->xcl_name)!= 0) continue;spin_unlock(&svc_xprt_class_lock);
if (!try_module_get(xcl->xcl_owner))
goto out;
# (assuming that's the right order) newxprt =xcl->xcl_ops->xpo_create(serv, (struct sockaddr *)&sin, sizeof(sin), flags); if (IS_ERR(newxprt)) {module_put(xcl->xcl_owner);
ret =PTR_ERR(newxprt);
goto out;
}clear_bit(XPT_TEMP, &newxprt->xpt_flags);spin_lock_bh(&serv->sv_lock);list_add(&newxprt->xpt_list, &serv->sv_permsocks);spin_unlock_bh(&serv->sv_lock);
ret =svc_xprt_local_port(newxprt);
goto out;
}
Quoted 8 lines
At least to my eyes, that also makes it a lot easier to see what the important (succesful) case is, since that's the code that stays unindented all the way to the end.
I'd also be inclined to replace those "got out"'s by "returns". I don't really see the point of the label when it's leads to something that's literally just a return.
Agree. Fixed.
Quoted 5 lines
--b.
-
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
PATCH 31/38 svc: Removing remaining references to rq_sock in rqstp
In reply to a message not in the archiveThis functionally empty patch removes rq_sock and unamed union from rqstp structure.
---
include/linux/sunrpc/svc.h | 5 +---- net/sunrpc/svcsock.c | 38 ++++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 18 deletions(-)
include/linux/sunrpc/svc.h +1 -4
@@ -204,10 +204,7 @@ union svc_addr_u {struct svc_rqst {struct list_head rq_list;/* idle list */ struct list_head rq_all;/* all threads list */ -union { -struct svc_xprt * rq_xprt;/* transport ptr */ -struct svc_sock * rq_sock;/* socket ptr */ - }; +struct svc_xprt * rq_xprt;/* transport ptr */ struct sockaddr_storage rq_addr;/* peer address */ size_t rq_addrlen;
net/sunrpc/svcsock.c +24 -14
@@ -201,10 +201,12 @@ static void svc_release_skb(struct svc_rqst *rqstp)struct svc_deferred_req *dr = rqstp->rq_deferred;if (skb) { +struct svc_sock *svsk = + container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt); rqstp->rq_xprt_ctxt =NULL ;dprintk ("svc: service %p, releasing skb %p\n" , rqstp, skb); -skb_free_datagram (rqstp->rq_sock->sk_sk, skb); +skb_free_datagram (svsk->sk_sk, skb); }if (dr) { rqstp->rq_deferred =NULL ;
@@ -415,7 +417,7 @@ svc_wake_up(struct svc_serv *serv)dprintk ("svc: daemon %p woken up.\n" , rqstp);/* svc_thread_dequeue(pool, rqstp); -rqstp->rq_sock = NULL; +rqstp->rq_xprt = NULL; */ wake_up (&rqstp->rq_wait); }
@@ -432,7 +434,9 @@ union svc_pktinfo_u {static void svc_set_cmsg_data (struct svc_rqst *rqstp,struct cmsghdr *cmh) { -switch (rqstp->rq_sock->sk_sk->sk_family) { +struct svc_sock *svsk = + container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt); +switch (svsk->sk_sk->sk_family) {case AF_INET : {struct in_pktinfo *pki =CMSG_DATA (cmh);
@@ -465,7 +469,8 @@ static void svc_set_cmsg_data(struct svc_rqst *rqstp, struct cmsghdr *cmh)static int svc_sendto (struct svc_rqst *rqstp,struct xdr_buf *xdr) { -struct svc_sock *svsk = rqstp->rq_sock; +struct svc_sock *svsk = + container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);struct socket *sock = svsk->sk_sock;int slen;union {
@@ -538,7 +543,7 @@ svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr) } out:dprintk ("svc: socket %p sendto([%p %Zu... ], %d) = %d (addr %s)\n" , - rqstp->rq_sock, xdr->head[0 ].iov_base, xdr->head[0 ].iov_len, + svsk, xdr->head[0 ].iov_base, xdr->head[0 ].iov_len, xdr->len, len,svc_print_addr (rqstp, buf,sizeof (buf)));return len;
@@ -614,7 +619,8 @@ svc_recv_available(struct svc_sock *svsk)static int svc_recvfrom (struct svc_rqst *rqstp,struct kvec *iov,int nr,int buflen) { -struct svc_sock *svsk = rqstp->rq_sock; +struct svc_sock *svsk = + container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);struct msghdr msg = { .msg_flags =MSG_DONTWAIT , };
@@ -704,7 +710,9 @@ svc_write_space(struct sock *sk)static void svc_udp_get_dest_address (struct svc_rqst *rqstp,struct cmsghdr *cmh) { -switch (rqstp->rq_sock->sk_sk->sk_family) { +struct svc_sock *svsk = + container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt); +switch (svsk->sk_sk->sk_family) {case AF_INET : {struct in_pktinfo *pki =CMSG_DATA (cmh); rqstp->rq_daddr.addr.s_addr = pki->ipi_spec_dst.s_addr;
@@ -724,7 +732,8 @@ static void svc_udp_get_dest_address(struct svc_rqst *rqstp,static int svc_udp_recvfrom (struct svc_rqst *rqstp) { -struct svc_sock *svsk = rqstp->rq_sock; +struct svc_sock *svsk = + container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);struct svc_serv *serv = svsk->sk_xprt.xpt_server;struct sk_buff *skb;union {
@@ -1106,7 +1115,8 @@ failed:static int svc_tcp_recvfrom (struct svc_rqst *rqstp) { -struct svc_sock *svsk = rqstp->rq_sock; +struct svc_sock *svsk = + container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);struct svc_serv *serv = svsk->sk_xprt.xpt_server;int len;struct kvec *vec;
@@ -1270,16 +1280,16 @@ svc_tcp_sendto(struct svc_rqst *rqstp) reclen =htonl (0x80000000 |((xbufp->len ) -4 ));memcpy (xbufp->head[0 ].iov_base, &reclen,4 ); -if (test_bit (XPT_DEAD , &rqstp->rq_sock->sk_xprt.xpt_flags)) +if (test_bit (XPT_DEAD , &rqstp->rq_xprt->xpt_flags))return -ENOTCONN ; sent =svc_sendto (rqstp, &rqstp->rq_res);if (sent != xbufp->len) {printk (KERN_NOTICE "rpc-srv/tcp: %s: %s %d when sending %d bytes - shutting down socket\n" , - rqstp->rq_sock->sk_xprt.xpt_server->sv_name, + rqstp->rq_xprt->xpt_server->sv_name, (sent<0 )?"got error" :"sent only" , sent, xbufp->len); -set_bit (XPT_CLOSE , &rqstp->rq_sock->sk_xprt.xpt_flags); +set_bit (XPT_CLOSE , &rqstp->rq_xprt->xpt_flags);svc_xprt_enqueue (rqstp->rq_xprt); sent = -EAGAIN ; }
@@ -1299,7 +1309,7 @@ static void svc_tcp_prep_reply_hdr(struct svc_rqst *rqstp)static int svc_tcp_has_wspace (struct svc_xprt *xprt) { - struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); + struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);struct svc_serv *serv = svsk->sk_xprt.xpt_server;int required;int wspace;
@@ -1627,7 +1637,7 @@ svc_recv(struct svc_rqst *rqstp, long timeout)void svc_drop (struct svc_rqst *rqstp) { -dprintk ("svc: socket %p dropped request\n" , rqstp->rq_sock); +dprintk ("svc: xprt %p dropped request\n" , rqstp->rq_xprt);svc_xprt_release (rqstp); }
PATCH 32/38 svc: Make svc_check_conn_limits xprt independent
In reply to a message not in the archiveThe svc_check_conn_limits function only manipulates xprt fields. Change references to svc_sock->sk_xprt to svc_xprt directly.
---
net/sunrpc/svcsock.c | 28 ++++++++++++++-------------- 1 files changed, 14 insertions(+), 14 deletions(-)
net/sunrpc/svcsock.c +14 -14
@@ -1447,34 +1447,34 @@ static void svc_check_conn_limits(struct svc_serv *serv)char buf[RPC_MAX_ADDRBUFLEN ];if (serv->sv_tmpcnt > (serv->sv_nrthreads+3 )*20 ) { -struct svc_sock *svsk =NULL ; +struct svc_xprt *xprt =NULL ;spin_lock_bh (&serv->sv_lock);if (!list_empty (&serv->sv_tempsocks)) {if (net_ratelimit ()) {/* Try to help the admin */ -printk (KERN_NOTICE "%s: too many open TCP " -"sockets, consider increasing the " +printk (KERN_NOTICE "%s: too many open " +"connections, consider increasing the " "number of nfsd threads\n" , - serv->sv_name); + serv->sv_name);printk (KERN_NOTICE -"%s: last TCP connect from %s\n" , +"%s: last connection from %s\n" , serv->sv_name, buf); }/* -* Always select the oldest socket. It's not fair, +* Always select the oldest connection. It's not fair, * but so is life */ - svsk =list_entry (serv->sv_tempsocks.prev, - struct svc_sock, - sk_xprt.xpt_list); -set_bit (XPT_CLOSE , &svsk->sk_xprt.xpt_flags); -svc_xprt_get (&svsk->sk_xprt); + xprt =list_entry (serv->sv_tempsocks.prev, + struct svc_xprt, + xpt_list); +set_bit (XPT_CLOSE , &xprt->xpt_flags); +svc_xprt_get (xprt); }spin_unlock_bh (&serv->sv_lock); -if (svsk) { -svc_xprt_enqueue (&svsk->sk_xprt); -svc_xprt_put (&svsk->sk_xprt); +if (xprt) { +svc_xprt_enqueue (xprt); +svc_xprt_put (xprt); } } }
PATCH 33/38 svc: Move the xprt independent code to the svc_xprt.c file
In reply to a message not in the archiveThis functionally trivial patch moves all of the transport independent functions from the svcsock.c file to the transport independent svc_xprt.c file.
---
include/linux/sunrpc/svc_xprt.h | 27 + net/sunrpc/svc_xprt.c | 726 +++++++++++++++++++++++++++++++++++ net/sunrpc/svcsock.c | 809 +-------------------------------------- 3 files changed, 776 insertions(+), 786 deletions(-)
include/linux/sunrpc/svc_xprt.h +27 -0
@@ -72,9 +72,13 @@ int svc_unreg_xprt_class(struct svc_xprt_class *);void svc_xprt_init (struct svc_xprt_class *,struct svc_xprt *,struct svc_serv *);int svc_create_xprt (struct svc_serv *,char *,unsigned short ,int ); +void svc_xprt_enqueue (struct svc_xprt *xprt);void svc_xprt_received (struct svc_xprt *);void svc_xprt_put (struct svc_xprt *xprt);void svc_xprt_copy_addrs (struct svc_rqst *rqstp,struct svc_xprt *xprt); +void svc_close_xprt (struct svc_xprt *xprt); +void svc_delete_xprt (struct svc_xprt *xprt); +int svc_port_is_privileged (struct sockaddr *sin);static inline void svc_xprt_get (struct svc_xprt *xprt) {kref_get (&xprt->xpt_ref);
@@ -126,4 +130,27 @@ static inline unsigned short svc_xprt_remote_port(struct svc_xprt *xprt)return svc_addr_port ((struct sockaddr *)&xprt->xpt_remote); } +static inline char *__svc_print_addr (struct sockaddr *addr, +char *buf,size_t len) +{ +switch (addr->sa_family) { +case AF_INET : +snprintf (buf, len,"%u.%u.%u.%u, port=%u" , +NIPQUAD (((struct sockaddr_in *) addr)->sin_addr), +ntohs (((struct sockaddr_in *) addr)->sin_port)); +break ; + +case AF_INET6 : +snprintf (buf, len,"%x:%x:%x:%x:%x:%x:%x:%x, port=%u" , +NIP6 (((struct sockaddr_in6 *) addr)->sin6_addr), +ntohs (((struct sockaddr_in6 *) addr)->sin6_port)); +break ; + +default : +snprintf (buf, len,"unknown address type: %d" , addr->sa_family); +break ; + } +return buf; +} +#endif /* SUNRPC_SVC_XPRT_H */
net/sunrpc/svc_xprt.c +726 -0
735 lines not on this page · raw message
net/sunrpc/svcsock.c +23 -786
961 lines not on this page · raw message
PATCH 34/38 svc: Add transport hdr size for defer/revisit
In reply to a message not in the archiveSome transports have a header in front of the RPC header. The current defer/revisit processing considers only the iov_len and arg_len to determine how much to back up when saving the original request to revisit. Add a field to the rqstp structure to save the size of the transport header so svc_defer can correctly compute the start of a request.
---
include/linux/sunrpc/svc.h | 2 ++ net/sunrpc/svc_xprt.c | 36 +++++++++++++++++++++++++++--------- net/sunrpc/svcsock.c | 2 ++ 3 files changed, 31 insertions(+), 9 deletions(-)
include/linux/sunrpc/svc.h +2 -0
@@ -217,6 +217,7 @@ struct svc_rqst {void * rq_xprt_ctxt;/* transport specific context ptr */ struct svc_deferred_req *rq_deferred;/* deferred request we are replaying */ +size_t rq_xprt_hlen;/* xprt header len */ struct xdr_buf rq_arg;struct xdr_buf rq_res;struct page * rq_pages[RPCSVC_MAXPAGES ];
@@ -322,6 +323,7 @@ struct svc_deferred_req {size_t addrlen;union svc_addr_u daddr;/* where reply must come from */ struct cache_deferred_req handle; +size_t xprt_hlen;int argslen;__be32 args[0 ]; };
net/sunrpc/svc_xprt.c +27 -9
@@ -29,7 +29,6 @@#include <linux/sunrpc/types.h> #include <linux/sunrpc/clnt.h> #include <linux/sunrpc/xdr.h> -#include <linux/sunrpc/svcsock.h> #include <linux/sunrpc/stats.h> #include <linux/sunrpc/svc_xprt.h>
@@ -844,10 +843,18 @@ static void svc_revisit(struct cache_deferred_req *dreq, int too_many)svc_xprt_put (xprt); } +/* +* Save the request off for later processing. The request buffer looks +* like this: +* +* <xprt-header><rpc-header><rpc-pagelist><rpc-tail> +* +* This code can only handle requests that consist of an xprt-header +* and rpc-header. +*/ static struct cache_deferred_req *svc_defer (struct cache_req *req) { struct svc_rqst *rqstp = container_of(req, struct svc_rqst, rq_chandle); -int size =sizeof (struct svc_deferred_req ) + (rqstp->rq_arg.len);struct svc_deferred_req *dr;if (rqstp->rq_arg.page_len)
@@ -856,8 +863,10 @@ static struct cache_deferred_req *svc_defer(struct cache_req *req) dr = rqstp->rq_deferred; rqstp->rq_deferred =NULL ; }else { -int skip = rqstp->rq_arg.len - rqstp->rq_arg.head[0 ].iov_len; +size_t skip; +size_t size;/* FIXME maybe discard if size too large */ + size =sizeof (struct svc_deferred_req ) + rqstp->rq_arg.len; dr =kmalloc (size,GFP_KERNEL );if (dr ==NULL )return NULL ;
@@ -868,8 +877,12 @@ static struct cache_deferred_req *svc_defer(struct cache_req *req) dr->addrlen = rqstp->rq_addrlen; dr->daddr = rqstp->rq_daddr; dr->argslen = rqstp->rq_arg.len >>2 ; -memcpy (dr->args, rqstp->rq_arg.head[0 ].iov_base-skip, - dr->argslen<<2 ); + dr->xprt_hlen = rqstp->rq_xprt_hlen; + +/* back up head to the start of the buffer and copy */ + skip = rqstp->rq_arg.len - rqstp->rq_arg.head[0 ].iov_len; +memcpy (dr->args, rqstp->rq_arg.head[0 ].iov_base - skip, + dr->argslen <<2 ); }svc_xprt_get (rqstp->rq_xprt); dr->xprt = rqstp->rq_xprt;
@@ -885,16 +898,21 @@ static int svc_deferred_recv(struct svc_rqst *rqstp) {struct svc_deferred_req *dr = rqstp->rq_deferred; - rqstp->rq_arg.head[0 ].iov_base = dr->args; - rqstp->rq_arg.head[0 ].iov_len = dr->argslen<<2 ; +/* setup iov_base past transport header */ + rqstp->rq_arg.head[0 ].iov_base = dr->args + (dr->xprt_hlen>>2 ); +/* The iov_len does not include the transport header bytes */ + rqstp->rq_arg.head[0 ].iov_len = (dr->argslen<<2 ) - dr->xprt_hlen; rqstp->rq_arg.page_len =0 ; - rqstp->rq_arg.len = dr->argslen<<2 ; +/* The rq_arg.len includes the transport header bytes */ + rqstp->rq_arg.len = dr->argslen<<2 ; rqstp->rq_prot = dr->prot;memcpy (&rqstp->rq_addr, &dr->addr, dr->addrlen); rqstp->rq_addrlen = dr->addrlen; +/* Save off transport header len in case we get deferred again */ + rqstp->rq_xprt_hlen = dr->xprt_hlen; rqstp->rq_daddr = dr->daddr; rqstp->rq_respages = rqstp->rq_pages; -return dr->argslen<<2 ; +return (dr->argslen<<2 ) - dr->xprt_hlen; }
net/sunrpc/svcsock.c +2 -0
@@ -343,6 +343,8 @@ static int svc_recvfrom(struct svc_rqst *rqstp, struct kvec *iov, int nr, };int len; + rqstp->rq_xprt_hlen =0 ; + len =kernel_recvmsg (svsk->sk_sock, &msg, iov, nr, buflen, msg.msg_flags);
A message that is not in the archive (sent off-list or not yet received): 20071211233309.15718.84852.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org
Re: [PATCH 34/38] svc: Add transport hdr size for defer/revisit
Quoted 7 lines · Tom Tucker
Some transports have a header in front of the RPC header. The current defer/revisit processing considers only the
iov_lenandarg_lento determine how much to back up when saving the original request to revisit. Add a field to the rqstp structure to save the size of the transport header sosvc_defercan correctly compute the start of a request.
I know I asked before, and can't remember what happened: has this been tested with krb5p? (I know nobody cares much whether krb5p/rdma works, I just want to make sure krb5p/rdma doesn't oops, and that krb5p/{tcp,udp} are unchanged.)
I'll try it eventually if you don't....
--b.
Re: [PATCH 34/38] svc: Add transport hdr size for defer/revisit
Quoted 9 lines · J. Bruce Fields
Quoted 7 lines · Tom Tucker
Some transports have a header in front of the RPC header. The current defer/revisit processing considers only the
iov_lenandarg_lento determine how much to back up when saving the original request to revisit. Add a field to the rqstp structure to save the size of the transport header sosvc_defercan correctly compute the start of a request.
Quoted 4 lines
I know I asked before, and can't remember what happened: has this been tested with krb5p? (I know nobody cares much whether krb5p/rdma works, I just want to make sure krb5p/rdma doesn't oops, and that krb5p/{tcp,udp} are unchanged.)
I haven't tested this combination. I definitely don't have a kerberos setup, but I guess I need to sooner or later...
Quoted 4 lines
I'll try it eventually if you don't....
--b.
PATCH 35/38 svc: Add /proc/sys/sunrpc/transport files
In reply to a message not in the archiveAdd a file that when read lists the set of registered svc transports.
---
include/linux/sunrpc/svc_xprt.h | 1 + net/sunrpc/svc_xprt.c | 28 ++++++++++++++++++++++++++++ net/sunrpc/sysctl.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 0 deletions(-)
include/linux/sunrpc/svc_xprt.h +1 -0
@@ -79,6 +79,7 @@ void svc_xprt_copy_addrs(struct svc_rqst *rqstp, struct svc_xprt *xprt);void svc_close_xprt (struct svc_xprt *xprt);void svc_delete_xprt (struct svc_xprt *xprt);int svc_port_is_privileged (struct sockaddr *sin); +int svc_print_xprts (char *buf,int maxlen);static inline void svc_xprt_get (struct svc_xprt *xprt) {kref_get (&xprt->xpt_ref);
net/sunrpc/svc_xprt.c +28 -0
@@ -93,6 +93,34 @@ int svc_unreg_xprt_class(struct svc_xprt_class *xcl) }EXPORT_SYMBOL_GPL (svc_unreg_xprt_class); +/* +* Format the transport list for printing +*/ +int svc_print_xprts (char *buf,int maxlen) +{ +struct list_head *le; +char tmpstr[80 ]; +int len =0 ; + buf[0 ] ='\0' ; + +spin_lock (&svc_xprt_class_lock); +list_for_each (le, &svc_xprt_class_list) { +int slen; +struct svc_xprt_class *xcl = + list_entry(le, struct svc_xprt_class, xcl_list); + +sprintf (tmpstr,"%s %d\n" , xcl->xcl_name, xcl->xcl_max_payload); + slen =strlen (tmpstr); +if (len + slen > maxlen) +break ; + len += slen; +strcat (buf, tmpstr); + } +spin_unlock (&svc_xprt_class_lock); + +return len; +} +static void svc_xprt_free (struct kref *kref) { struct svc_xprt *xprt =
net/sunrpc/sysctl.c +31 -0
@@ -18,6 +18,7 @@#include <linux/sunrpc/types.h> #include <linux/sunrpc/sched.h> #include <linux/sunrpc/stats.h> +#include <linux/sunrpc/svc_xprt.h> /* * Declare the debug flags here
@@ -48,6 +49,30 @@ rpc_unregister_sysctl(void) } } +static int proc_do_xprt (ctl_table *table,int write,struct file *file, +void __user *buffer,size_t *lenp,loff_t *ppos) +{ +char tmpbuf[256 ]; +int len; +if ((*ppos && !write) || !*lenp) { + *lenp =0 ; +return 0 ; + } +if (write) +return -EINVAL ; +else { + len =svc_print_xprts (tmpbuf,sizeof (tmpbuf)); +if (!access_ok (VERIFY_WRITE , buffer, len)) +return -EFAULT ; + +if (__copy_to_user (buffer, tmpbuf, len)) +return -EFAULT ; + } + *lenp -= len; + *ppos += len; +return 0 ; +} +static int proc_dodebug (ctl_table *table,int write,struct file *file,void __user *buffer,size_t *lenp,loff_t *ppos)
@@ -140,6 +165,12 @@ static ctl_table debug_table[] = { .mode = 0644, .proc_handler = &proc_dodebug }, + { + .procname = "transports", + .maxlen = 256, + .mode = 0444, + .proc_handler = &proc_do_xprt, + }, { .ctl_name = 0 } };
PATCH 36/38 svc: Add svc API that queries for a transport instance
In reply to a message not in the archiveAdd a new svc function that allows a service to query whether a transport instance has already been created. This is used in lockd to determine whether or not a transport needs to be created when a lockd instance is brought up.
Specifying 0 for the address family or port is effectively a wild-card, and will result in matching the first transport in the service's list that has a matching class name.
---
fs/lockd/svc.c | 16 ++-------------- include/linux/sunrpc/svc_xprt.h | 1 + net/sunrpc/svc_xprt.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 14 deletions(-)
fs/lockd/svc.c +2 -14
@@ -219,18 +219,6 @@ lockd(struct svc_rqst *rqstp)module_put_and_exit (0 ); } -static int find_xprt (struct svc_serv *serv,char *proto) -{ -struct svc_xprt *xprt; -int found =0 ; -list_for_each_entry (xprt, &serv->sv_permsocks, xpt_list) -if (strcmp (xprt->xpt_class->xcl_name, proto) ==0 ) { - found =1 ; -break ; - } -return found; -} -/* * Make any sockets that are needed but not present. * If nlm_udpport or nlm_tcpport were set as module
@@ -242,11 +230,11 @@ static int make_socks(struct svc_serv *serv, int proto)int err =0 ;if (proto ==IPPROTO_UDP || nlm_udpport) -if (!find_xprt (serv,"udp" )) +if (!svc_find_xprt (serv,"udp" ,0 ,0 )) err =svc_create_xprt (serv,"udp" , nlm_udpport,SVC_SOCK_DEFAULTS );if (err >=0 && (proto ==IPPROTO_TCP || nlm_tcpport)) -if (!find_xprt (serv,"tcp" )) +if (!svc_find_xprt (serv,"tcp" ,0 ,0 )) err =svc_create_xprt (serv,"tcp" , nlm_tcpport,SVC_SOCK_DEFAULTS );
include/linux/sunrpc/svc_xprt.h +1 -0
@@ -80,6 +80,7 @@ void svc_close_xprt(struct svc_xprt *xprt);void svc_delete_xprt (struct svc_xprt *xprt);int svc_port_is_privileged (struct sockaddr *sin);int svc_print_xprts (char *buf,int maxlen); +struct svc_xprt *svc_find_xprt (struct svc_serv *,char *,int ,int );static inline void svc_xprt_get (struct svc_xprt *xprt) {kref_get (&xprt->xpt_ref);
net/sunrpc/svc_xprt.c +34 -0
@@ -963,3 +963,37 @@ static struct svc_deferred_req *svc_deferred_dequeue(struct svc_xprt *xprt)return dr; } +/* +* Return the transport instance pointer for the endpoint accepting +* connections/peer traffic from the specified transport class, +* address family and port. +* +* Specifying 0 for the address family or port is effectively a +* wild-card, and will result in matching the first transport in the +* service's list that has a matching class name. +*/ +struct svc_xprt *svc_find_xprt (struct svc_serv *serv,char *xcl_name, +int af,int port) +{ +struct svc_xprt *xprt; +struct svc_xprt *found =NULL ; + +/* Sanity check the args */ +if (!serv || !xcl_name) +return found; + +spin_lock_bh (&serv->sv_lock); +list_for_each_entry (xprt, &serv->sv_permsocks, xpt_list) { +if (strcmp (xprt->xpt_class->xcl_name, xcl_name)) +continue ; +if (af !=AF_UNSPEC && af != xprt->xpt_local.ss_family) +continue ; +if (port && port !=svc_xprt_local_port (xprt)) +continue ; + found = xprt; +break ; + } +spin_unlock_bh (&serv->sv_lock); +return found; +} +EXPORT_SYMBOL_GPL (svc_find_xprt);
PATCH 37/38 knfsd: Support adding transports by writing portlist file
In reply to a message not in the archiveUpdate the write handler for the portlist file to allow creating new listening endpoints on a transport. The general form of the string is:
<transport_name><space><port number>
For example:
echo "tcp 2049" > /proc/fs/nfsd/portlist
This is intended to support the creation of a listening endpoint for RDMA transports without adding #ifdef code to the nfssvc.c file.
Transports can also be removed as follows:
'-'<transport_name><space><port number>
For example:
echo "-tcp 2049" > /proc/fs/nfsd/portlist
Attempting to add a listener with an invalid transport string results in EPROTONOSUPPORT and a perror string of "Protocol not supported".
Attempting to remove an non-existent listener (.e.g. bad proto or port) results in ENOTCONN and a perror string of
"Transport endpoint is not connected"
---
fs/nfsd/nfsctl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- net/sunrpc/svc_xprt.c | 1 + 2 files changed, 52 insertions(+), 1 deletions(-)
fs/nfsd/nfsctl.c +51 -1
@@ -540,7 +540,7 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size) }return err <0 ? err :0 ; } -if (buf[0 ] =='-' ) { +if (buf[0 ] =='-' &&isdigit (buf[1 ])) {char *toclose =kstrdup (buf+1 ,GFP_KERNEL );int len =0 ;if (!toclose)
@@ -554,6 +554,56 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size)kfree (toclose);return len; } +/* +* Add a transport listener by writing it's transport name +*/ +if (isalpha (buf[0 ])) { +int err; +char transport[16 ]; +int port; +if (sscanf (buf,"%15s %4d" , transport, &port) ==2 ) { + err =nfsd_create_serv (); +if (!err) { +if (svc_find_xprt (nfsd_serv, transport, +AF_UNSPEC , port)) +return -EADDRINUSE ; + + err =svc_create_xprt (nfsd_serv, + transport, port, +SVC_SOCK_ANONYMOUS ); +if (err == -ENOENT ) +/* Give a reasonable perror msg for +* bad transport string */ + err = -EPROTONOSUPPORT ; + } +return err <0 ? err :0 ; + } + } +/* +* Remove a transport by writing it's transport name and port number +*/ +if (buf[0 ] =='-' &&isalpha (buf[1 ])) { +struct svc_xprt *xprt; +int err = -EINVAL ; +char transport[16 ]; +int port; +if (sscanf (&buf[1 ],"%15s %4d" , transport, &port) ==2 ) { +if (port ==0 ) +return -EINVAL ; +lock_kernel (); +if (nfsd_serv) { + xprt =svc_find_xprt (nfsd_serv, transport, +AF_UNSPEC , port); +if (xprt) { +svc_close_xprt (xprt); + err =0 ; + }else + err = -ENOTCONN ; + } +unlock_kernel (); +return err <0 ? err :0 ; + } + }return -EINVAL ; }
net/sunrpc/svc_xprt.c +1 -0
@@ -827,6 +827,7 @@ void svc_close_xprt(struct svc_xprt *xprt)clear_bit (XPT_BUSY , &xprt->xpt_flags);svc_xprt_put (xprt); } +EXPORT_SYMBOL_GPL (svc_close_xprt);void svc_close_all (struct list_head *xprt_list) {
A message that is not in the archive (sent off-list or not yet received): 20071211233316.15718.85089.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org
Re: [PATCH 37/38] knfsd: Support adding transports by writing portlist file
Quoted 55 lines · Tom Tucker
Update the write handler for the portlist file to allow creating new listening endpoints on a transport. The general form of the string is:
<transport_name><space><port number>
For example:
echo "tcp 2049" >
/proc/fs/nfsd/portlistThis is intended to support the creation of a listening endpoint for RDMA transports without adding #ifdef code to the
nfssvc.cfile.Transports can also be removed as follows:
'-'<transport_name><space><port number>
For example:
echo "-tcp 2049" >
/proc/fs/nfsd/portlistAttempting to add a listener with an invalid transport string results in EPROTONOSUPPORT and a perror string of "Protocol not supported".
Attempting to remove an non-existent listener (.e.g. bad proto or port) results in ENOTCONN and a perror string of
"Transport endpoint is not connected"Signed-off-by Tom Tucker <[email protected]>---
fs/nfsd/nfsctl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- net/sunrpc/svc_xprt.c | 1 + 2 files changed, 52 insertions(+), 1 deletions(-)fs/nfsd/nfsctl.c +4
-1@@ -540,7 +540,7 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size) }return err <0 ? err :0 ; } -if (buf[0 ] =='-' ) { +if (buf[0 ] =='-' &&isdigit (buf[1 ])) {char *toclose =kstrdup (buf+1 ,GFP_KERNEL );int len =0 ;if (!toclose)@@ -554,6 +554,56 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size)kfree (toclose);return len; } +/* +* Add a transport listener by writing it's transport name +*/
fs/nfsd/nfsctl.c static ssize_t write_ports(struct file *file, char *buf, size_t size) · line 569
Quoted 10 lines
fs/nfsd/nfsctl.c +10
-0+if (isalpha (buf[0 ])) { +int err; +char transport[16 ]; +int port; +if (sscanf (buf,"%15s %4d" , transport, &port) ==2 ) { + err =nfsd_create_serv (); +if (!err) { +if (svc_find_xprt (nfsd_serv, transport, +AF_UNSPEC , port)) +return -EADDRINUSE ;
Shouldn't svc_create_xprt do this check for us itself? (And if it doesn't, isn't there some minor race between two writers both checking, finding nothing, and then both svc_create_xprt()ing?)
Quoted 20 lines
fs/nfsd/nfsctl.c +20
-0+ + err =svc_create_xprt (nfsd_serv, + transport, port, +SVC_SOCK_ANONYMOUS ); +if (err == -ENOENT ) +/* Give a reasonable perror msg for +* bad transport string */ + err = -EPROTONOSUPPORT ; + } +return err <0 ? err :0 ; + } + } +/* +* Remove a transport by writing it's transport name and port number +*/ +if (buf[0 ] =='-' &&isalpha (buf[1 ])) { +struct svc_xprt *xprt; +int err = -EINVAL ; +char transport[16 ]; +int port;
fs/nfsd/nfsctl.c static ssize_t write_ports(struct file *file, char *buf, size_t size) · line 599
Quoted 10 lines
fs/nfsd/nfsctl.c +10
-0+if (sscanf (&buf[1 ],"%15s %4d" , transport, &port) ==2 ) { +if (port ==0 ) +return -EINVAL ; +lock_kernel (); +if (nfsd_serv) { + xprt =svc_find_xprt (nfsd_serv, transport, +AF_UNSPEC , port); +if (xprt) { +svc_close_xprt (xprt); + err =0 ;
Hm, also: I'd have thought that svc_find_xprt should be incrementing the reference count on the returned xprt, if we're expecting the caller to do anything with it other than check it against NULL.
--b.
Quoted 22 lines
fs/nfsd/nfsctl.c +7
-0+ }else + err = -ENOTCONN ; + } +unlock_kernel (); +return err <0 ? err :0 ; + } + }return -EINVAL ; }net/sunrpc/svc_xprt.c +1
-0@@ -827,6 +827,7 @@ void svc_close_xprt(struct svc_xprt *xprt)clear_bit (XPT_BUSY , &xprt->xpt_flags);svc_xprt_put (xprt); } +EXPORT_SYMBOL_GPL (svc_close_xprt);void svc_close_all (struct list_head *xprt_list) {
Re: [PATCH 37/38] knfsd: Support adding transports by writing portlist file
Quoted 62 lines · J. Bruce Fields
Quoted 61 lines · Tom Tucker
Update the write handler for the portlist file to allow creating new listening endpoints on a transport. The general form of the string is:
<transport_name><space><port number>
For example:
echo "tcp 2049" >
/proc/fs/nfsd/portlistThis is intended to support the creation of a listening endpoint for RDMA transports without adding #ifdef code to the
nfssvc.cfile.Transports can also be removed as follows:
'-'<transport_name><space><port number>
For example:
echo "-tcp 2049" >
/proc/fs/nfsd/portlistAttempting to add a listener with an invalid transport string results in EPROTONOSUPPORT and a perror string of "Protocol not supported".
Attempting to remove an non-existent listener (.e.g. bad proto or port) results in ENOTCONN and a perror string of
"Transport endpoint is not connected"Signed-off-by Tom Tucker <[email protected]>---
fs/nfsd/nfsctl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- net/sunrpc/svc_xprt.c | 1 + 2 files changed, 52 insertions(+), 1 deletions(-)fs/nfsd/nfsctl.c +10
-1@@ -540,7 +540,7 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size) }return err <0 ? err :0 ; } -if (buf[0 ] =='-' ) { +if (buf[0 ] =='-' &&isdigit (buf[1 ])) {char *toclose =kstrdup (buf+1 ,GFP_KERNEL );int len =0 ;if (!toclose)@@ -554,6 +554,56 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size)kfree (toclose);return len; } +/* +* Add a transport listener by writing it's transport name +*/ +if (isalpha (buf[0 ])) { +int err; +char transport[16 ]; +int port; +if (sscanf (buf,"%15s %4d" , transport, &port) ==2 ) { + err =nfsd_create_serv ();
Quoted 9 lines
fs/nfsd/nfsctl.c static ssize_t write_ports(struct file *file, char *buf, size_t size) · line 569
Quoted 4 lines
fs/nfsd/nfsctl.c +4
-0+if (!err) { +if (svc_find_xprt (nfsd_serv, transport, +AF_UNSPEC , port)) +return -EADDRINUSE ;Shouldn't
svc_create_xprtdo this check for us itself? (And if it doesn't, isn't there some minor race between two writers both checking, finding nothing, and then both svc_create_xprt()ing?)
You're right. fixed.
Quoted 64 lines
Quoted 20 lines
fs/nfsd/nfsctl.c +20
-0+ + err =svc_create_xprt (nfsd_serv, + transport, port, +SVC_SOCK_ANONYMOUS ); +if (err == -ENOENT ) +/* Give a reasonable perror msg for +* bad transport string */ + err = -EPROTONOSUPPORT ; + } +return err <0 ? err :0 ; + } + } +/* +* Remove a transport by writing it's transport name and port number +*/ +if (buf[0 ] =='-' &&isalpha (buf[1 ])) { +struct svc_xprt *xprt; +int err = -EINVAL ; +char transport[16 ]; +int port;fs/nfsd/nfsctl.c static ssize_t write_ports(struct file *file, char *buf, size_t size) · line 599
Quoted 10 lines
fs/nfsd/nfsctl.c +10
-0+if (sscanf (&buf[1 ],"%15s %4d" , transport, &port) ==2 ) { +if (port ==0 ) +return -EINVAL ; +lock_kernel (); +if (nfsd_serv) { + xprt =svc_find_xprt (nfsd_serv, transport, +AF_UNSPEC , port); +if (xprt) { +svc_close_xprt (xprt); + err =0 ;Hm, also: I'd have thought that
svc_find_xprtshould be incrementing the reference count on the returned xprt, if we're expecting the caller to do anything with it other than check it against NULL.--b.
Quoted 15 lines
fs/nfsd/nfsctl.c +7
-0+ }else + err = -ENOTCONN ; + } +unlock_kernel (); +return err <0 ? err :0 ; + } + }return -EINVAL ; }net/sunrpc/svc_xprt.c +0
-0net/sunrpc/svc_xprt.c void svc_close_xprt(struct svc_xprt *xprt) · line 833
Quoted 7 lines
net/sunrpc/svc_xprt.c +1
-0@@ -827,6 +827,7 @@ void svc_close_xprt(struct svc_xprt *xprt)clear_bit (XPT_BUSY , &xprt->xpt_flags);svc_xprt_put (xprt); } +EXPORT_SYMBOL_GPL (svc_close_xprt);void svc_close_all (struct list_head *xprt_list) {-
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
A message that is not in the archive (sent off-list or not yet received): 1198259550.14237.33.camel-SMNkleLxa3ZimH42XvhXlA@public.gmane.org
Re: [PATCH 37/38] knfsd: Support adding transports by writing portlist file
Quoted 74 lines · Tom Tucker
Quoted 62 lines · J. Bruce Fields
Quoted 61 lines · Tom Tucker
Update the write handler for the portlist file to allow creating new listening endpoints on a transport. The general form of the string is:
<transport_name><space><port number>
For example:
echo "tcp 2049" >
/proc/fs/nfsd/portlistThis is intended to support the creation of a listening endpoint for RDMA transports without adding #ifdef code to the
nfssvc.cfile.Transports can also be removed as follows:
'-'<transport_name><space><port number>
For example:
echo "-tcp 2049" >
/proc/fs/nfsd/portlistAttempting to add a listener with an invalid transport string results in EPROTONOSUPPORT and a perror string of "Protocol not supported".
Attempting to remove an non-existent listener (.e.g. bad proto or port) results in ENOTCONN and a perror string of
"Transport endpoint is not connected"Signed-off-by Tom Tucker <[email protected]>---
fs/nfsd/nfsctl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- net/sunrpc/svc_xprt.c | 1 + 2 files changed, 52 insertions(+), 1 deletions(-)fs/nfsd/nfsctl.c +10
-1@@ -540,7 +540,7 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size) }return err <0 ? err :0 ; } -if (buf[0 ] =='-' ) { +if (buf[0 ] =='-' &&isdigit (buf[1 ])) {char *toclose =kstrdup (buf+1 ,GFP_KERNEL );int len =0 ;if (!toclose)@@ -554,6 +554,56 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size)kfree (toclose);return len; } +/* +* Add a transport listener by writing it's transport name +*/ +if (isalpha (buf[0 ])) { +int err; +char transport[16 ]; +int port; +if (sscanf (buf,"%15s %4d" , transport, &port) ==2 ) { + err =nfsd_create_serv ();Quoted 9 lines
fs/nfsd/nfsctl.c static ssize_t write_ports(struct file *file, char *buf, size_t size) · line 569
Quoted 4 lines
fs/nfsd/nfsctl.c +4
-0+if (!err) { +if (svc_find_xprt (nfsd_serv, transport, +AF_UNSPEC , port)) +return -EADDRINUSE ;Shouldn't
svc_create_xprtdo this check for us itself? (And if it doesn't, isn't there some minor race between two writers both checking, finding nothing, and then both svc_create_xprt()ing?)
Quoted 1 line
You're right. fixed.
Thanks! But:
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
fs/nfsd/nfsctl.c +26
-0+ + err =svc_create_xprt (nfsd_serv, + transport, port, +SVC_SOCK_ANONYMOUS ); +if (err == -ENOENT ) +/* Give a reasonable perror msg for +* bad transport string */ + err = -EPROTONOSUPPORT ; + } +return err <0 ? err :0 ; + } + } +/* +* Remove a transport by writing it's transport name and port number +*/ +if (buf[0 ] =='-' &&isalpha (buf[1 ])) { +struct svc_xprt *xprt; +int err = -EINVAL ; +char transport[16 ]; +int port; +if (sscanf (&buf[1 ],"%15s %4d" , transport, &port) ==2 ) { +if (port ==0 ) +return -EINVAL ; +lock_kernel (); +if (nfsd_serv) { + xprt = svc_find_xprt(nfsd_serv, transport,
Quoted 8 lines
Quoted 8 lines
fs/nfsd/nfsctl.c static ssize_t write_ports(struct file *file, char *buf, size_t size) · line 599
Quoted 4 lines
fs/nfsd/nfsctl.c +4
-0+ AF_UNSPEC, port); +if (xprt) { +svc_close_xprt (xprt); + err =0 ;Hm, also: I'd have thought that
svc_find_xprtshould be incrementing the reference count on the returned xprt, if we're expecting the caller to do anything with it other than check it against NULL.
... there's still a race here, isn't there?
--b.
Re: [PATCH 37/38] knfsd: Support adding transports by writing portlist file
Quoted 1 line · J. Bruce Fields
On Fri, Dec 21, 2007 at 11:52:30AM -0600, Tom Tucker wrote:
[...snip...]
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines
fs/nfsd/nfsctl.c static ssize_t write_ports(struct file *file, char *buf, size_t size) · line 599
Quoted 4 lines
fs/nfsd/nfsctl.c +4
-0+ AF_UNSPEC, port); +if (xprt) { +svc_close_xprt (xprt); + err =0 ;Hm, also: I'd have thought that
svc_find_xprtshould be incrementing the reference count on the returned xprt, if we're expecting the caller to do anything with it other than check it against NULL.... there's still a race here, isn't there?
I think it's a good idea to have the svc_find_xprt service take a reference. I'll code this up....
Quoted 1 line
--b.
PATCH 38/38 svc: Add svc_xprt_names service to replace svc_sock_names
In reply to a message not in the archiveCreate a transport independent version of the svc_sock_names function.
The toclose capability of the svc_sock_names service can be implemented using the svc_xprt_find and svc_xprt_close services.
---
fs/nfsd/nfsctl.c | 2 +- include/linux/sunrpc/svc_xprt.h | 1 + net/sunrpc/svc_xprt.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletions(-)
fs/nfsd/nfsctl.c +1 -1
@@ -503,7 +503,7 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size)int len =0 ;lock_kernel ();if (nfsd_serv) - len =svc_sock_names (buf, nfsd_serv,NULL ); + len =svc_xprt_names (nfsd_serv, buf,0 );unlock_kernel ();return len; }
include/linux/sunrpc/svc_xprt.h +1 -0
@@ -81,6 +81,7 @@ void svc_delete_xprt(struct svc_xprt *xprt);int svc_port_is_privileged (struct sockaddr *sin);int svc_print_xprts (char *buf,int maxlen);struct svc_xprt *svc_find_xprt (struct svc_serv *,char *,int ,int ); +int svc_xprt_names (struct svc_serv *serv,char *buf,int buflen);static inline void svc_xprt_get (struct svc_xprt *xprt) {kref_get (&xprt->xpt_ref);
net/sunrpc/svc_xprt.c +35 -0
@@ -998,3 +998,38 @@ struct svc_xprt *svc_find_xprt(struct svc_serv *serv, char *xcl_name,return found; }EXPORT_SYMBOL_GPL (svc_find_xprt); + +/* +* Format a buffer with a list of the active transports. A zero for +* the buflen parameter disables target buffer overflow checking. +*/ +int svc_xprt_names (struct svc_serv *serv,char *buf,int buflen) +{ +struct svc_xprt *xprt; +char xprt_str[64 ]; +int totlen =0 ; +int len; + +/* Sanity check args */ +if (!serv) +return 0 ; + +spin_lock_bh (&serv->sv_lock); +list_for_each_entry (xprt, &serv->sv_permsocks, xpt_list) { + len =snprintf (xprt_str,sizeof (xprt_str), +"%s %d\n" , xprt->xpt_class->xcl_name, +svc_xprt_local_port (xprt)); +/* If the string was truncated, replace with error string */ +if (len >=sizeof (xprt_str)) +strcpy (xprt_str,"name-too-long\n" ); +/* Don't overflow buffer */ + len =strlen (xprt_str); +if (buflen && (len + totlen >= buflen)) +break ; +strcpy (buf+totlen, xprt_str); + totlen += len; + } +spin_unlock_bh (&serv->sv_lock); +return totlen; +} +EXPORT_SYMBOL_GPL (svc_xprt_names);
A message that is not in the archive (sent off-list or not yet received): 20071211233318.15718.11614.stgit-gUwIgmpLGaKNDNWfRnPdfg@public.gmane.org
Re: [PATCH 38/38] svc: Add svc_xprt_names service to replace svc_sock_names
Quoted 5 lines · Tom Tucker
Create a transport independent version of the
svc_sock_namesfunction.The toclose capability of the
svc_sock_namesservice can be implemented using thesvc_xprt_findandsvc_xprt_closeservices.
Should we delete the toclose checks from svc_sock_names(), then, under the assumption it's always called with toclose non-NULL now?
And why can't we just completely replace svc_sock_names() at this point?
--b.
Quoted 77 lines
Signed-off-by Tom Tucker <[email protected]>---
fs/nfsd/nfsctl.c | 2 +- include/linux/sunrpc/svc_xprt.h | 1 + net/sunrpc/svc_xprt.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletions(-)fs/nfsd/nfsctl.c +1
-1@@ -503,7 +503,7 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size)int len =0 ;lock_kernel ();if (nfsd_serv) - len =svc_sock_names (buf, nfsd_serv,NULL ); + len =svc_xprt_names (nfsd_serv, buf,0 );unlock_kernel ();return len; }include/linux/sunrpc/svc_xprt.h +1
-0@@ -81,6 +81,7 @@ void svc_delete_xprt(struct svc_xprt *xprt);int svc_port_is_privileged (struct sockaddr *sin);int svc_print_xprts (char *buf,int maxlen);struct svc_xprt *svc_find_xprt (struct svc_serv *,char *,int ,int ); +int svc_xprt_names (struct svc_serv *serv,char *buf,int buflen);static inline void svc_xprt_get (struct svc_xprt *xprt) {kref_get (&xprt->xpt_ref);net/sunrpc/svc_xprt.c +35
-0@@ -998,3 +998,38 @@ struct svc_xprt *svc_find_xprt(struct svc_serv *serv, char *xcl_name,return found; }EXPORT_SYMBOL_GPL (svc_find_xprt); + +/* +* Format a buffer with a list of the active transports. A zero for +* the buflen parameter disables target buffer overflow checking. +*/ +int svc_xprt_names (struct svc_serv *serv,char *buf,int buflen) +{ +struct svc_xprt *xprt; +char xprt_str[64 ]; +int totlen =0 ; +int len; + +/* Sanity check args */ +if (!serv) +return 0 ; + +spin_lock_bh (&serv->sv_lock); +list_for_each_entry (xprt, &serv->sv_permsocks, xpt_list) { + len =snprintf (xprt_str,sizeof (xprt_str), +"%s %d\n" , xprt->xpt_class->xcl_name, +svc_xprt_local_port (xprt)); +/* If the string was truncated, replace with error string */ +if (len >=sizeof (xprt_str)) +strcpy (xprt_str,"name-too-long\n" ); +/* Don't overflow buffer */ + len =strlen (xprt_str); +if (buflen && (len + totlen >= buflen)) +break ; +strcpy (buf+totlen, xprt_str); + totlen += len; + } +spin_unlock_bh (&serv->sv_lock); +return totlen; +} +EXPORT_SYMBOL_GPL (svc_xprt_names);
Re: [PATCH 38/38] svc: Add svc_xprt_names service to replace svc_sock_names
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Tom Tucker
Create a transport independent version of the
svc_sock_namesfunction.
Quoted 8 lines
Quoted 2 lines
The toclose capability of the
svc_sock_namesservice can be implemented using thesvc_xprt_findandsvc_xprt_closeservices.Should we delete the toclose checks from
svc_sock_names(), then, under the assumption it's always called with toclose non-NULL now?And why can't we just completely replace
svc_sock_names()at this point?
IMO we could, but there is currently a difference in behavior between svc_sock_names and svc_find_xprt/close. svc_find_xprt doesn't care what the IP address is, it only compares transport name, address family and port.
Presently in NFS, we only ever listen on zero, but you can destroy an endpoint on a particular interface (IP address). Can anyone shed some light on why this is?
Quoted 83 lines
--b.
Quoted 67 lines
Signed-off-by Tom Tucker <[email protected]>---
fs/nfsd/nfsctl.c | 2 +- include/linux/sunrpc/svc_xprt.h | 1 + net/sunrpc/svc_xprt.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletions(-)fs/nfsd/nfsctl.c +1
-1@@ -503,7 +503,7 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size)int len =0 ;lock_kernel ();if (nfsd_serv) - len =svc_sock_names (buf, nfsd_serv,NULL ); + len =svc_xprt_names (nfsd_serv, buf,0 );unlock_kernel ();return len; }include/linux/sunrpc/svc_xprt.h +1
-0@@ -81,6 +81,7 @@ void svc_delete_xprt(struct svc_xprt *xprt);int svc_port_is_privileged (struct sockaddr *sin);int svc_print_xprts (char *buf,int maxlen);struct svc_xprt *svc_find_xprt (struct svc_serv *,char *,int ,int ); +int svc_xprt_names (struct svc_serv *serv,char *buf,int buflen);static inline void svc_xprt_get (struct svc_xprt *xprt) {kref_get (&xprt->xpt_ref);net/sunrpc/svc_xprt.c +25
-0@@ -998,3 +998,38 @@ struct svc_xprt *svc_find_xprt(struct svc_serv *serv, char *xcl_name,return found; }EXPORT_SYMBOL_GPL (svc_find_xprt); + +/* +* Format a buffer with a list of the active transports. A zero for +* the buflen parameter disables target buffer overflow checking. +*/ +int svc_xprt_names (struct svc_serv *serv,char *buf,int buflen) +{ +struct svc_xprt *xprt; +char xprt_str[64 ]; +int totlen =0 ; +int len; + +/* Sanity check args */ +if (!serv) +return 0 ; + +spin_lock_bh (&serv->sv_lock); +list_for_each_entry (xprt, &serv->sv_permsocks, xpt_list) { + len =snprintf (xprt_str,sizeof (xprt_str), +"%s %d\n" , xprt->xpt_class->xcl_name, +svc_xprt_local_port (xprt)); +/* If the string was truncated, replace with error string */ +if (len >=sizeof (xprt_str)) +strcpy (xprt_str,"name-too-long\n" ); +/* Don't overflow buffer */ net/sunrpc/svc_xprt.c struct svc_xprt *svc_find_xprt(struct svc_serv *serv, char *xcl_name, · line 1035
Quoted 10 lines
net/sunrpc/svc_xprt.c +10
-0+ len =strlen (xprt_str); +if (buflen && (len + totlen >= buflen)) +break ; +strcpy (buf+totlen, xprt_str); + totlen += len; + } +spin_unlock_bh (&serv->sv_lock); +return totlen; +} +EXPORT_SYMBOL_GPL (svc_xprt_names);-
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
A message that is not in the archive (sent off-list or not yet received): 1198259507.14237.31.camel-SMNkleLxa3ZimH42XvhXlA@public.gmane.org
Re: [PATCH 38/38] svc: Add svc_xprt_names service to replace svc_sock_names
Quoted 15 lines · Tom Tucker
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Tom Tucker
Create a transport independent version of the
svc_sock_namesfunction.Quoted 8 lines
Quoted 2 lines
The toclose capability of the
svc_sock_namesservice can be implemented using thesvc_xprt_findandsvc_xprt_closeservices.Should we delete the toclose checks from
svc_sock_names(), then, under the assumption it's always called with toclose non-NULL now?And why can't we just completely replace
svc_sock_names()at this point?
Quoted 8 lines
IMO we could, but there is currently a difference in behavior between
svc_sock_namesand svc_find_xprt/close.svc_find_xprtdoesn't care what the IP address is, it only compares transport name, address family and port.Presently in NFS, we only ever listen on zero, but you can destroy an endpoint on a particular interface (IP address). Can anyone shed some light on why this is?
Dunno. Neil?
--b.
Re: [PATCH 38/38] svc: Add svc_xprt_names service to replace svc_sock_names
Quoted 21 lines · On Thursday January 3, [email protected] wrote:
Quoted 20 lines · Tom Tucker
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Tom Tucker
Create a transport independent version of the
svc_sock_namesfunction.Quoted 8 lines
Quoted 2 lines
The toclose capability of the
svc_sock_namesservice can be implemented using thesvc_xprt_findandsvc_xprt_closeservices.Should we delete the toclose checks from
svc_sock_names(), then, under the assumption it's always called with toclose non-NULL now?And why can't we just completely replace
svc_sock_names()at this point?IMO we could, but there is currently a difference in behavior between
svc_sock_namesand svc_find_xprt/close.svc_find_xprtdoesn't care what the IP address is, it only compares transport name, address family and port.
Quoted 5 lines
Quoted 3 lines
Presently in NFS, we only ever listen on zero, but you can destroy an endpoint on a particular interface (IP address). Can anyone shed some light on why this is?
Dunno. Neil?
The "-H" option to "rpc.nfsd" allow you to bind nfsd to a specific interface.
I don't think any user-space tools current allow you to unbind a specific interface, but I wouldn't want to lose that functionality.
Why are we changing this. Clear the toclose functionality of the svc_sock_names service can *NOT* be impletemented using svc_xprt_find and svc_xprt_close as _find_ doesn't check the port - so just leave things the way they are??? I haven't really been following this update much so maybe there is something I'm missing....
NeilBrown
A message that is not in the archive (sent off-list or not yet received): 18301.33306.486417.193770-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org
Re: [PATCH 38/38] svc: Add svc_xprt_names service to replace svc_sock_names
Sorry for the delay...
Quoted 33 lines · Neil Brown
Quoted 21 lines · On Thursday January 3, [email protected] wrote:
Quoted 20 lines · Tom Tucker
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Tom Tucker
Create a transport independent version of the
svc_sock_namesfunction.Quoted 8 lines
Quoted 2 lines
The toclose capability of the
svc_sock_namesservice can be implemented using thesvc_xprt_findandsvc_xprt_closeservices.Should we delete the toclose checks from
svc_sock_names(), then, under the assumption it's always called with toclose non-NULL now?And why can't we just completely replace
svc_sock_names()at this point?IMO we could, but there is currently a difference in behavior between
svc_sock_namesand svc_find_xprt/close.svc_find_xprtdoesn't care what the IP address is, it only compares transport name, address family and port.Quoted 5 lines
Quoted 3 lines
Presently in NFS, we only ever listen on zero, but you can destroy an endpoint on a particular interface (IP address). Can anyone shed some light on why this is?
Dunno. Neil?
The "-H" option to "rpc.nfsd" allow you to bind nfsd to a specific interface.
I don't think any user-space tools current allow you to unbind a specific interface, but I wouldn't want to lose that functionality.
Quoted 4 lines
Why are we changing this. Clear the toclose functionality of the
svc_sock_namesservice can *NOT* be impletemented usingsvc_xprt_findandsvc_xprt_closeas _find_ doesn't check the port - so just leave things the way they are???
I think you mean check the IP address ... Correct?
Quoted 2 lines
I haven't really been following this update
much so maybe there is something I'm missing....
I don't think you're missing anything, however, I think there are two pieces to this: a) what should the new API support, and b) should we move the existing code to the new API.
The new API (svc_xprt_find) does not currently search based on IP address and therefore cannot be used for b). I think it should, however, since svc_xprt_create can be used to create a listener on a specific IP address/interface.
Quoted 6 lines
NeilBrown
-
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