nlm:Fix bug nlm cann't process retransmited request correctly
Subsystems (6)
cover nlm:Fix bug nlm cann't process retransmited request correctly
I found a bug when tested NLM. The case likes followed:
client server
| |
step1 | open file |
open |------------------------------->|
| ok |
|<-------------------------------|
| | step2
| -> | <- service nfslock sto=
p
| |
| WL1: write lock request{0, 0} |
step3 |------------------------------->|
fcntl | |=20
| |
| WL1_re: WL1 retransmit |
|------------------------------->|
| |
| WL1.reply ENOLCK |
|<-------------------------------|
| |
| | step4
| -> | <- service nfslock star=
t
| |
| WL2: write lock request{0, 0} |
step5 |------------------------------->|
fcntl | |
| WL1_re.reply OK |
|<-------------------------------|
| WL2.reply EBLOCKD |
|<-------------------------------|client can not acquire for write lock any more after step4.
Reason:
Server reply ENOLCK for WL1 to client because nfslock service stop=
ed, but it can not
distinguish retransmited request with normal request, so it reply O=
K for WL1_re to
client after nfslock service start. But fcntl client called will ret=
urn when it receive
WL1.reply, and WL2 can not get a equal svid to WL1_re=EF=BC=8Cso ser=
ver will reply EBLOCKD for
it.
Suggestion:
I suggest add an DRC for NLM.
There are three patchs followed:
1. add an universal DRC to sunrpc, it will be used by those protocol which be built on sunrpc [0001-Add-an-universal-DRC-to-sunrpc.patch]
2. add DRC to NLM using sunrpc's universal DRC
[0002-Add-DRC-to-NLM-using-sunrpc-s-DRC.patch]
3. modify the nfsd's DRC to use sunrpc's universal DRC
[0003-Modify-the-nfsd-s-DRC-to-use-sunrpc-s-universal-DRC.patch]
--
arch/parisc/kernel/sys_parisc32.c | 2 +- arch/s390/kernel/compat_linux.c | 2 +- arch/sparc/kernel/sys_sparc32.c | 2 +- fs/lockd/svc.c | 66 ++++++++ fs/lockd/svc4proc.c | 52 +++--- fs/nfsd/Makefile | 2 +- fs/nfsd/nfs2acl.c | 2 +- fs/nfsd/nfs3acl.c | 2 +- fs/nfsd/nfs3proc.c | 2 +- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfscache.c | 330 -----------------------------= -------- fs/nfsd/nfsctl.c | 10 +- fs/nfsd/nfsproc.c | 2 +- fs/nfsd/nfssvc.c | 13 +- fs/nfsd/stats.c | 9 +- include/linux/lockd/lockd.h | 6 + include/linux/nfsd/cache.h | 62 ------- include/linux/nfsd/stats.h | 3 - include/linux/sunrpc/drc.h | 97 +++++++++++ net/sunrpc/Makefile | 2 +- net/sunrpc/drc.c | 326 +++++++++++++++++++++++++++++= +++++++ 22 files changed, 553 insertions(+), 443 deletions(-) =20
--=20
Regards
Mi Jinlong
RFC PATCH 1/3 sunrpc:add an universal DRC to sunrpc
Add an universal DRC to sunrpc, it will be used by those protocols which be built on sunrpc
--- include/linux/sunrpc/drc.h | 97 +++++++++++++ net/sunrpc/Makefile | 2 +- net/sunrpc/drc.c | 326 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 424 insertions(+), 1 deletions(-) create mode 100644 include/linux/sunrpc/drc.h create mode 100644 net/sunrpc/drc.c
include/linux/sunrpc/drc.h new file +97 -0
@@ -0,0 +1,97 @@ +/* +* include/linux/sunrpc/drc.h +* +* Request reply cache. This was heavily inspired by the +* implementation in 4.3BSD/4.4BSD. +* +* Copyright (C) 1995, 1996 Olaf Kirch <[email protected]> +*/ + +#ifndef DRC_H +#define DRC_H + +#include <linux/in.h> +#include <linux/uio.h> +#include <linux/spinlock.h> + +/* +* Representation of a reply cache entry. +*/ +struct svc_cacherep { +struct hlist_node c_hash; +struct list_head c_lru; + +unsigned char c_state,/* unused, inprog, done */ + c_type,/* status, buffer */ + c_secure :1 ;/* req came from port < 1024 */ +struct sockaddr_in c_addr; +__be32 c_xid; +u32 c_prot; +u32 c_proc; +u32 c_vers; +unsigned long c_timestamp; +union { +struct kvec u_vec; +__be32 u_status; + } c_u; +}; + +#define c_replvec c_u.u_vec +#define c_replstat c_u.u_status + +struct drc_cache { +struct hlist_head *cache_hash; +struct list_head lru_head; +int cache_disabled; + +/* Record the cache */ +unsigned int rchits;/* repcache hits */ +unsigned int rcmisses;/* repcache misses */ +unsigned int rcnocache;/* uncached reqs */ + +/* +* locking for the reply cache: +* A cache entry is "single use" if c_state == RC_INPROG +* Otherwise, it when accessing _prev or _next, the lock must be held. +*/ +spinlock_t cache_lock; +}; + +/* cache entry states */ +enum { +RC_UNUSED , +RC_INPROG , +RC_DONE +}; + +/* return values */ +enum { +RC_DROPIT , +RC_REPLY , +RC_DOIT , +RC_INTR +}; + +/* +* Cache types. +* We may want to add more types one day, e.g. for diropres and +* attrstat replies. Using cache entries with fixed length instead +* of buffer pointers may be more efficient. +*/ +enum { +RC_NOCACHE , +RC_REPLSTAT , +RC_REPLBUFF , +}; + +/* +* If requests are retransmitted within this interval, they're dropped. +*/ +#define RC_DELAY (HZ/5) + +int drc_reply_cache_init (struct drc_cache *); +void drc_reply_cache_shutdown (struct drc_cache *); +int drc_cache_lookup (struct svc_rqst *,int ,struct drc_cache *); +void drc_cache_update (struct svc_rqst *,int ,__be32 *,struct drc_cache *); + +#endif /* DRC_H */
net/sunrpc/Makefile +1 -1
@@ -12,7 +12,7 @@ sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \ svc.o svcsock.o svcauth.o svcauth_unix.o \ addr.o rpcb_clnt.o timer.o xdr.o \ sunrpc_syms.o cache.o rpc_pipe.o \ - svc_xprt.o + svc_xprt.o drc.o sunrpc-$(CONFIG_NFS_V4_1) += backchannel_rqst.o bc_svc.o sunrpc-$(CONFIG_PROC_FS) += stats.o sunrpc-$(CONFIG_SYSCTL) += sysctl.o
net/sunrpc/drc.c new file +326 -0
326 lines not on this page · raw message
Signature · 1 line
1.6.2
RFC PATCH 2/3 nlm:add DRC to NLM using sunrpc's universal DRC
In reply to Mi JinlongAdd DRC to NLM using sunrpc's DRC.
Add nlm_dispatch function for NLM.
--- fs/lockd/svc.c | 66 +++++++++++++++++++++++++++++++++++++++++++ fs/lockd/svc4proc.c | 52 +++++++++++++++++---------------- include/linux/lockd/lockd.h | 6 ++++ 3 files changed, 99 insertions(+), 25 deletions(-)
fs/lockd/svc.c +66 -0
@@ -32,6 +32,7 @@#include <linux/sunrpc/stats.h> #include <linux/sunrpc/clnt.h> #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/sunrpc/svcsock.h> #include <net/ip.h> #include <linux/lockd/lockd.h>
@@ -76,6 +77,9 @@ static const int nlm_port_min = 0, nlm_port_max = 65535;static struct ctl_table_header * nlm_sysctl_table;#endif +/* DRC for NLM */ +struct drc_cache nlm_dc; +static unsigned long get_lockd_grace_period (void ) {/* Note: nlm_timeout should always be nonzero */
@@ -363,6 +367,63 @@ out: }EXPORT_SYMBOL_GPL (lockd_down); +/* +* DRC for NLM +*/ +int +nlm_dispatch (struct svc_rqst *rqstp,u32 *statp) +{ +struct svc_procedure *proc; +kxdrproc_t xdr; + +dprintk ("nlm_dispatch: vers %d proc %d\n" , + rqstp->rq_vers, rqstp->rq_proc); + proc = rqstp->rq_procinfo; + +/* Check whether we have this call in the cache. */ +switch (drc_cache_lookup (rqstp, proc->pc_cachetype, &nlm_dc)) { +case RC_INTR : +case RC_DROPIT : +return 0 ; +case RC_REPLY : +return 1 ; +case RC_DOIT :; +/* do it */ + } + +/* Decode arguments */ + xdr = proc->pc_decode; +if (xdr && !xdr (rqstp, (u32 *)rqstp->rq_arg.head[0 ].iov_base, + rqstp->rq_argp)) { +dprintk ("nlm: failed to decode arguments!\n" ); +drc_cache_update (rqstp,RC_NOCACHE ,NULL , &nlm_dc); + *statp = rpc_garbage_args; +return 1 ; + } + + *statp = proc->pc_func (rqstp, rqstp->rq_argp, rqstp->rq_resp); + +if (*statp == rpc_drop_reply) { +dprintk ("nlm: Dropping request due to malloc failure!\n" ); +drc_cache_update (rqstp,RC_NOCACHE ,NULL , &nlm_dc); +return 0 ; + } + +if (*statp ==rpc_success && (xdr = proc->pc_encode) && !xdr (rqstp, + (rqstp->rq_res.head[0 ].iov_base + rqstp->rq_res.head[0 ].iov_len), + rqstp->rq_resp)) { +dprintk ("nlm: failed to encode result!\n" ); +drc_cache_update (rqstp,RC_NOCACHE ,NULL , &nlm_dc); + *statp = rpc_system_err; +return 1 ; + } + +/* Store reply in cache */ +drc_cache_update (rqstp, proc->pc_cachetype, statp +1 , &nlm_dc); +return 1 ; + +} +#ifdef CONFIG_SYSCTL /*
@@ -525,6 +586,7 @@ module_param(nlm_max_connections, uint, 0644);static int __init init_nlm (void ) { +drc_reply_cache_init (&nlm_dc);#ifdef CONFIG_SYSCTL nlm_sysctl_table =register_sysctl_table (nlm_sysctl_root);return nlm_sysctl_table ?0 : -ENOMEM ;
@@ -536,6 +598,7 @@ static int __init init_nlm(void) static void __exit exit_nlm(void) {/* FIXME: delete all NLM clients */ +drc_reply_cache_shutdown (&nlm_dc);nlm_shutdown_hosts ();#ifdef CONFIG_SYSCTL unregister_sysctl_table (nlm_sysctl_table);
@@ -552,12 +615,14 @@ static struct svc_version nlmsvc_version1 = { .vs_vers = 1, .vs_nproc = 17, .vs_proc = nlmsvc_procedures, + .vs_dispatch = nlm_dispatch, .vs_xdrsize = NLMSVC_XDRSIZE, };static struct svc_version nlmsvc_version3 = { .vs_vers =3 , .vs_nproc =24 , .vs_proc = nlmsvc_procedures, + .vs_dispatch = nlm_dispatch, .vs_xdrsize =NLMSVC_XDRSIZE , };#ifdef CONFIG_LOCKD_V4
@@ -565,6 +630,7 @@ static struct svc_version nlmsvc_version4 = { .vs_vers = 4, .vs_nproc = 24, .vs_proc = nlmsvc_procedures4, + .vs_dispatch = nlm_dispatch, .vs_xdrsize = NLMSVC_XDRSIZE, };#endif
fs/lockd/svc4proc.c +27 -25
76 lines not on this page · raw message
include/linux/lockd/lockd.h +6 -0
@@ -198,6 +198,12 @@ extern int nsm_use_hostnames;extern u32 nsm_local_state;/* +* DRC for NLM +*/ + +int nlm_dispatch (struct svc_rqst *rqstp,u32 *stap); + +/* * Lockd client functions */ struct nlm_rqst *nlm_alloc_call (struct nlm_host *host);
Signature · 1 line
1.6.2
RFC PATCH 3/3 nfsd:modify the nfsd's DRC to use sunrpc's universal DRC
In reply to Mi JinlongModify the nfsd's DRC to use sunrpc's universal DRC
--- arch/parisc/kernel/sys_parisc32.c | 2 +- arch/s390/kernel/compat_linux.c | 2 +- arch/sparc/kernel/sys_sparc32.c | 2 +- fs/nfsd/Makefile | 2 +- fs/nfsd/nfs2acl.c | 2 +- fs/nfsd/nfs3acl.c | 2 +- fs/nfsd/nfs3proc.c | 2 +- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfscache.c | 330 ------------------------------------- fs/nfsd/nfsctl.c | 10 +- fs/nfsd/nfsproc.c | 2 +- fs/nfsd/nfssvc.c | 13 +- fs/nfsd/stats.c | 9 +- include/linux/nfsd/cache.h | 62 ------- include/linux/nfsd/stats.h | 3 - 16 files changed, 30 insertions(+), 417 deletions(-) delete mode 100644 fs/nfsd/nfscache.c
arch/parisc/kernel/sys_parisc32.c +1 -1
@@ -29,8 +29,8 @@#include <linux/nfs_fs.h> #include <linux/ncp_fs.h> #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/nfsd/nfsd.h> -#include <linux/nfsd/cache.h> #include <linux/nfsd/xdr.h> #include <linux/nfsd/syscall.h> #include <linux/poll.h>
arch/s390/kernel/compat_linux.c +1 -1
@@ -35,8 +35,8 @@#include <linux/quota.h> #include <linux/module.h> #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/nfsd/nfsd.h> -#include <linux/nfsd/cache.h> #include <linux/nfsd/xdr.h> #include <linux/nfsd/syscall.h> #include <linux/poll.h>
arch/sparc/kernel/sys_sparc32.c +1 -1
@@ -27,8 +27,8 @@#include <linux/quota.h> #include <linux/module.h> #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/nfsd/nfsd.h> -#include <linux/nfsd/cache.h> #include <linux/nfsd/xdr.h> #include <linux/nfsd/syscall.h> #include <linux/poll.h>
fs/nfsd/Makefile +1 -1
@@ -5,7 +5,7 @@ obj-$(CONFIG_NFSD) += nfsd.o nfsd-y := nfssvc.o nfsctl.o nfsproc.o nfsfh.o vfs.o \ - export.o auth.o lockd.o nfscache.o nfsxdr.o stats.o + export.o auth.o lockd.o nfsxdr.o stats.o nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o nfsd-$(CONFIG_NFSD_V3) += nfs3proc.o nfs3xdr.o nfsd-$(CONFIG_NFSD_V3_ACL) += nfs3acl.o
fs/nfsd/nfs2acl.c +1 -1
@@ -7,9 +7,9 @@*/ #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/nfs.h> #include <linux/nfsd/nfsd.h> -#include <linux/nfsd/cache.h> #include <linux/nfsd/xdr.h> #include <linux/nfsd/xdr3.h> #include <linux/posix_acl.h>
fs/nfsd/nfs3acl.c +1 -1
@@ -7,9 +7,9 @@*/ #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/nfs3.h> #include <linux/nfsd/nfsd.h> -#include <linux/nfsd/cache.h> #include <linux/nfsd/xdr3.h> #include <linux/posix_acl.h> #include <linux/nfsacl.h>
fs/nfsd/nfs3proc.c +1 -1
@@ -21,8 +21,8 @@#include <linux/magic.h> #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/nfsd/nfsd.h> -#include <linux/nfsd/cache.h> #include <linux/nfsd/xdr3.h> #include <linux/nfs3.h>
fs/nfsd/nfs4proc.c +1 -1
@@ -41,8 +41,8 @@#include <linux/file.h> #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/nfsd/nfsd.h> -#include <linux/nfsd/cache.h> #include <linux/nfs4.h> #include <linux/nfsd/state.h> #include <linux/nfsd/xdr4.h>
fs/nfsd/nfs4state.c +1 -1
@@ -39,8 +39,8 @@#include <linux/slab.h> #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/nfsd/nfsd.h> -#include <linux/nfsd/cache.h> #include <linux/file.h> #include <linux/mount.h> #include <linux/workqueue.h>
fs/nfsd/nfscache.c deleted +0 -330
330 lines not on this page · raw message
fs/nfsd/nfsctl.c +6 -4
@@ -31,9 +31,9 @@#include <linux/nfsd_idmap.h> #include <linux/lockd/bind.h> #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/sunrpc/svcsock.h> #include <linux/nfsd/nfsd.h> -#include <linux/nfsd/cache.h> #include <linux/nfsd/xdr.h> #include <linux/nfsd/syscall.h> #include <linux/lockd/lockd.h>
@@ -42,6 +42,8 @@#include <asm/uaccess.h> #include <net/ipv6.h> +struct drc_cache nfsd_dc; +/* * We have a single directory with 9 nodes in it. */
@@ -1392,7 +1394,7 @@ static int __init init_nfsd(void)if (retval)return retval;nfsd_stat_init ();/* Statistics */ - retval =nfsd_reply_cache_init (); + retval =drc_reply_cache_init (&nfsd_dc);if (retval) goto out_free_stat; retval =nfsd_export_init ();
@@ -1418,7 +1420,7 @@ out_free_lockd:nfsd_lockd_shutdown ();nfsd_export_shutdown (); out_free_cache: -nfsd_reply_cache_shutdown (); +drc_reply_cache_shutdown (&nfsd_dc); out_free_stat:nfsd_stat_shutdown ();nfsd4_free_slabs ();
@@ -1428,7 +1430,7 @@ out_free_stat: static void __exit exit_nfsd(void) {nfsd_export_shutdown (); -nfsd_reply_cache_shutdown (); +drc_reply_cache_shutdown (&nfsd_dc);remove_proc_entry ("fs/nfs/exports" ,NULL );remove_proc_entry ("fs/nfs" ,NULL );nfsd_stat_shutdown ();
fs/nfsd/nfsproc.c +1 -1
@@ -21,8 +21,8 @@#include <linux/sunrpc/clnt.h> #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/nfsd/nfsd.h> -#include <linux/nfsd/cache.h> #include <linux/nfsd/xdr.h> typedef struct svc_rqst svc_rqst ;
fs/nfsd/nfssvc.c +8 -5
@@ -26,6 +26,7 @@#include <linux/sunrpc/types.h> #include <linux/sunrpc/stats.h> #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/sunrpc/svcsock.h> #include <linux/sunrpc/cache.h> #include <linux/nfsd/nfsd.h>
@@ -42,6 +43,8 @@ extern struct svc_program nfsd_program;static int nfsd (void *vrqstp);struct timeval nfssvc_boot; +extern struct drc_cache nfsd_dc; +/* * nfsd_mutex protects nfsd_serv -- both the pointer itself and the members * of the svc_serv struct. In particular, ->sv_nrthreads but also to some
@@ -554,7 +557,7 @@ nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp) proc = rqstp->rq_procinfo;/* Check whether we have this call in the cache. */ -switch (nfsd_cache_lookup (rqstp, proc->pc_cachetype)) { +switch (drc_cache_lookup (rqstp, proc->pc_cachetype, &nfsd_dc)) {case RC_INTR :case RC_DROPIT :return 0 ;
@@ -569,7 +572,7 @@ nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp)if (xdr && !xdr (rqstp, (__be32 *)rqstp->rq_arg.head[0 ].iov_base, rqstp->rq_argp)) {dprintk ("nfsd: failed to decode arguments!\n" ); -nfsd_cache_update (rqstp,RC_NOCACHE ,NULL ); +drc_cache_update (rqstp,RC_NOCACHE ,NULL , &nfsd_dc); *statp = rpc_garbage_args;return 1 ; }
@@ -586,7 +589,7 @@ nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp) nfserr =map_new_errors (rqstp->rq_vers, nfserr);if (nfserr == nfserr_dropit) {dprintk ("nfsd: Dropping request; may be revisited later\n" ); -nfsd_cache_update (rqstp,RC_NOCACHE ,NULL ); +drc_cache_update (rqstp,RC_NOCACHE ,NULL , &nfsd_dc);return 0 ; }
@@ -602,14 +605,14 @@ nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp) rqstp->rq_resp)) {/* Failed to encode result. Release cache entry */ dprintk ("nfsd: failed to encode result!\n" ); -nfsd_cache_update (rqstp,RC_NOCACHE ,NULL ); +drc_cache_update (rqstp,RC_NOCACHE ,NULL , &nfsd_dc); *statp = rpc_system_err;return 1 ; } }/* Store reply in cache. */ -nfsd_cache_update (rqstp, proc->pc_cachetype, statp +1 ); +drc_cache_update (rqstp, proc->pc_cachetype, statp +1 , &nfsd_dc);return 1 ; }
fs/nfsd/stats.c +6 -3
@@ -31,10 +31,13 @@#include <linux/module.h> #include <linux/sunrpc/svc.h> +#include <linux/sunrpc/drc.h> #include <linux/sunrpc/stats.h> #include <linux/nfsd/nfsd.h> #include <linux/nfsd/stats.h> +extern struct drc_cache nfsd_dc; +struct nfsd_stats nfsdstats;struct svc_stat nfsd_svcstats = { .program = &nfsd_program,
@@ -45,9 +48,9 @@ static int nfsd_proc_show(struct seq_file *seq, void *v)int i; seq_printf(seq, "rc %u %u %u\nfh %u %u %u %u %u\nio %u %u\n", - nfsdstats.rchits, - nfsdstats.rcmisses, - nfsdstats.rcnocache, + nfsd_dc.rchits, + nfsd_dc.rcmisses, + nfsd_dc.rcnocache, nfsdstats.fh_stale, nfsdstats.fh_lookup, nfsdstats.fh_anon,
include/linux/nfsd/cache.h +0 -62
68 lines not on this page · raw message
include/linux/nfsd/stats.h +0 -3
@@ -17,9 +17,6 @@ #ifdef __KERNEL__ struct nfsd_stats { - unsigned int rchits; /* repcache hits */ - unsigned int rcmisses; /* repcache hits */ - unsigned int rcnocache; /* uncached reqs */ unsigned int fh_stale; /* FH stale error */ unsigned int fh_lookup; /* dentry cached */ unsigned int fh_anon; /* anon file dentry returned */
Signature · 1 line
1.6.2