Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lockd: move lockd's grace period handling into its own module

Currently, all of the grace period handling is part of lockd. Eventually
though we'd like to be able to build v4-only servers, at which point
we'll need to put all of this elsewhere.

Move the code itself into fs/nfs_common and have it build a grace.ko
module. Then, rejigger the Kconfig options so that both nfsd and lockd
enable it automatically.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>

authored by

Jeff Layton and committed by
J. Bruce Fields
f7790029 f0c63124

+70 -15
+5 -1
fs/Kconfig
··· 233 233 source "fs/nfs/Kconfig" 234 234 source "fs/nfsd/Kconfig" 235 235 236 + config GRACE_PERIOD 237 + tristate 238 + 236 239 config LOCKD 237 240 tristate 238 241 depends on FILE_LOCKING 242 + select GRACE_PERIOD 239 243 240 244 config LOCKD_V4 241 245 bool ··· 253 249 254 250 config NFS_COMMON 255 251 bool 256 - depends on NFSD || NFS_FS 252 + depends on NFSD || NFS_FS || LOCKD 257 253 default y 258 254 259 255 source "net/sunrpc/Kconfig"
+1 -1
fs/lockd/Makefile
··· 5 5 obj-$(CONFIG_LOCKD) += lockd.o 6 6 7 7 lockd-objs-y := clntlock.o clntproc.o clntxdr.o host.o svc.o svclock.o \ 8 - svcshare.o svcproc.o svcsubs.o mon.o xdr.o grace.o 8 + svcshare.o svcproc.o svcsubs.o mon.o xdr.o 9 9 lockd-objs-$(CONFIG_LOCKD_V4) += clnt4xdr.o xdr4.o svc4proc.o 10 10 lockd-objs := $(lockd-objs-y)
+58 -10
fs/lockd/grace.c fs/nfs_common/grace.c
··· 1 1 /* 2 2 * Common code for control of lockd and nfsv4 grace periods. 3 + * 4 + * Transplanted from lockd code 3 5 */ 4 6 5 7 #include <linux/module.h> 6 - #include <linux/lockd/bind.h> 7 8 #include <net/net_namespace.h> 9 + #include <net/netns/generic.h> 10 + #include <linux/fs.h> 8 11 9 - #include "netns.h" 10 - 12 + static int grace_net_id; 11 13 static DEFINE_SPINLOCK(grace_lock); 12 14 13 15 /** 14 16 * locks_start_grace 17 + * @net: net namespace that this lock manager belongs to 15 18 * @lm: who this grace period is for 16 19 * 17 20 * A grace period is a period during which locks should not be given ··· 24 21 * 25 22 * This function is called to start a grace period. 26 23 */ 27 - void locks_start_grace(struct net *net, struct lock_manager *lm) 24 + void 25 + locks_start_grace(struct net *net, struct lock_manager *lm) 28 26 { 29 - struct lockd_net *ln = net_generic(net, lockd_net_id); 27 + struct list_head *grace_list = net_generic(net, grace_net_id); 30 28 31 29 spin_lock(&grace_lock); 32 - list_add(&lm->list, &ln->grace_list); 30 + list_add(&lm->list, grace_list); 33 31 spin_unlock(&grace_lock); 34 32 } 35 33 EXPORT_SYMBOL_GPL(locks_start_grace); 36 34 37 35 /** 38 36 * locks_end_grace 37 + * @net: net namespace that this lock manager belongs to 39 38 * @lm: who this grace period is for 40 39 * 41 40 * Call this function to state that the given lock manager is ready to ··· 46 41 * Note that callers count on it being safe to call this more than once, 47 42 * and the second call should be a no-op. 48 43 */ 49 - void locks_end_grace(struct lock_manager *lm) 44 + void 45 + locks_end_grace(struct lock_manager *lm) 50 46 { 51 47 spin_lock(&grace_lock); 52 48 list_del_init(&lm->list); ··· 62 56 * to answer ordinary lock requests, and when they should accept only 63 57 * lock reclaims. 64 58 */ 65 - int locks_in_grace(struct net *net) 59 + int 60 + locks_in_grace(struct net *net) 66 61 { 67 - struct lockd_net *ln = net_generic(net, lockd_net_id); 62 + struct list_head *grace_list = net_generic(net, grace_net_id); 68 63 69 - return !list_empty(&ln->grace_list); 64 + return !list_empty(grace_list); 70 65 } 71 66 EXPORT_SYMBOL_GPL(locks_in_grace); 67 + 68 + static int __net_init 69 + grace_init_net(struct net *net) 70 + { 71 + struct list_head *grace_list = net_generic(net, grace_net_id); 72 + 73 + INIT_LIST_HEAD(grace_list); 74 + return 0; 75 + } 76 + 77 + static void __net_exit 78 + grace_exit_net(struct net *net) 79 + { 80 + struct list_head *grace_list = net_generic(net, grace_net_id); 81 + 82 + BUG_ON(!list_empty(grace_list)); 83 + } 84 + 85 + static struct pernet_operations grace_net_ops = { 86 + .init = grace_init_net, 87 + .exit = grace_exit_net, 88 + .id = &grace_net_id, 89 + .size = sizeof(struct list_head), 90 + }; 91 + 92 + static int __init 93 + init_grace(void) 94 + { 95 + return register_pernet_subsys(&grace_net_ops); 96 + } 97 + 98 + static void __exit 99 + exit_grace(void) 100 + { 101 + unregister_pernet_subsys(&grace_net_ops); 102 + } 103 + 104 + MODULE_AUTHOR("Jeff Layton <jlayton@primarydata.com>"); 105 + MODULE_LICENSE("GPL"); 106 + module_init(init_grace) 107 + module_exit(exit_grace)
-1
fs/lockd/netns.h
··· 11 11 12 12 struct delayed_work grace_period_end; 13 13 struct lock_manager lockd_manager; 14 - struct list_head grace_list; 15 14 16 15 spinlock_t nsm_clnt_lock; 17 16 unsigned int nsm_users;
+1 -1
fs/lockd/svc.c
··· 586 586 struct lockd_net *ln = net_generic(net, lockd_net_id); 587 587 588 588 INIT_DELAYED_WORK(&ln->grace_period_end, grace_ender); 589 - INIT_LIST_HEAD(&ln->grace_list); 589 + INIT_LIST_HEAD(&ln->lockd_manager.list); 590 590 spin_lock_init(&ln->nsm_clnt_lock); 591 591 return 0; 592 592 }
+2 -1
fs/nfs_common/Makefile
··· 3 3 # 4 4 5 5 obj-$(CONFIG_NFS_ACL_SUPPORT) += nfs_acl.o 6 - 7 6 nfs_acl-objs := nfsacl.o 7 + 8 + obj-$(CONFIG_GRACE_PERIOD) += grace.o
+1
fs/nfsd/Kconfig
··· 71 71 select FS_POSIX_ACL 72 72 select SUNRPC_GSS 73 73 select CRYPTO 74 + select GRACE_PERIOD 74 75 help 75 76 This option enables support in your system's NFS server for 76 77 version 4 of the NFS protocol (RFC 3530).
+2
include/linux/proc_fs.h
··· 74 74 75 75 #endif /* CONFIG_PROC_FS */ 76 76 77 + struct net; 78 + 77 79 static inline struct proc_dir_entry *proc_net_mkdir( 78 80 struct net *net, const char *name, struct proc_dir_entry *parent) 79 81 {