Skip to content

Commit f779002

Browse files
Jeff LaytonJ. Bruce Fields
authored andcommitted
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>
1 parent f0c6312 commit f779002

8 files changed

Lines changed: 70 additions & 15 deletions

File tree

‎fs/Kconfig‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,13 @@ if NETWORK_FILESYSTEMS
233233
source "fs/nfs/Kconfig"
234234
source "fs/nfsd/Kconfig"
235235

236+
config GRACE_PERIOD
237+
tristate
238+
236239
config LOCKD
237240
tristate
238241
depends on FILE_LOCKING
242+
select GRACE_PERIOD
239243

240244
config LOCKD_V4
241245
bool
@@ -249,7 +253,7 @@ config NFS_ACL_SUPPORT
249253

250254
config NFS_COMMON
251255
bool
252-
depends on NFSD || NFS_FS
256+
depends on NFSD || NFS_FS || LOCKD
253257
default y
254258

255259
source "net/sunrpc/Kconfig"

‎fs/lockd/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
obj-$(CONFIG_LOCKD) += lockd.o
66

77
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
99
lockd-objs-$(CONFIG_LOCKD_V4) += clnt4xdr.o xdr4.o svc4proc.o
1010
lockd-objs := $(lockd-objs-y)

‎fs/lockd/netns.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ struct lockd_net {
1111

1212
struct delayed_work grace_period_end;
1313
struct lock_manager lockd_manager;
14-
struct list_head grace_list;
1514

1615
spinlock_t nsm_clnt_lock;
1716
unsigned int nsm_users;

‎fs/lockd/svc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ static int lockd_init_net(struct net *net)
586586
struct lockd_net *ln = net_generic(net, lockd_net_id);
587587

588588
INIT_DELAYED_WORK(&ln->grace_period_end, grace_ender);
589-
INIT_LIST_HEAD(&ln->grace_list);
589+
INIT_LIST_HEAD(&ln->lockd_manager.list);
590590
spin_lock_init(&ln->nsm_clnt_lock);
591591
return 0;
592592
}

‎fs/nfs_common/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
#
44

55
obj-$(CONFIG_NFS_ACL_SUPPORT) += nfs_acl.o
6-
76
nfs_acl-objs := nfsacl.o
7+
8+
obj-$(CONFIG_GRACE_PERIOD) += grace.o
Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
/*
22
* Common code for control of lockd and nfsv4 grace periods.
3+
*
4+
* Transplanted from lockd code
35
*/
46

57
#include <linux/module.h>
6-
#include <linux/lockd/bind.h>
78
#include <net/net_namespace.h>
9+
#include <net/netns/generic.h>
10+
#include <linux/fs.h>
811

9-
#include "netns.h"
10-
12+
static int grace_net_id;
1113
static DEFINE_SPINLOCK(grace_lock);
1214

1315
/**
1416
* locks_start_grace
17+
* @net: net namespace that this lock manager belongs to
1518
* @lm: who this grace period is for
1619
*
1720
* A grace period is a period during which locks should not be given
@@ -21,18 +24,20 @@ static DEFINE_SPINLOCK(grace_lock);
2124
*
2225
* This function is called to start a grace period.
2326
*/
24-
void locks_start_grace(struct net *net, struct lock_manager *lm)
27+
void
28+
locks_start_grace(struct net *net, struct lock_manager *lm)
2529
{
26-
struct lockd_net *ln = net_generic(net, lockd_net_id);
30+
struct list_head *grace_list = net_generic(net, grace_net_id);
2731

2832
spin_lock(&grace_lock);
29-
list_add(&lm->list, &ln->grace_list);
33+
list_add(&lm->list, grace_list);
3034
spin_unlock(&grace_lock);
3135
}
3236
EXPORT_SYMBOL_GPL(locks_start_grace);
3337

3438
/**
3539
* locks_end_grace
40+
* @net: net namespace that this lock manager belongs to
3641
* @lm: who this grace period is for
3742
*
3843
* Call this function to state that the given lock manager is ready to
@@ -41,7 +46,8 @@ EXPORT_SYMBOL_GPL(locks_start_grace);
4146
* Note that callers count on it being safe to call this more than once,
4247
* and the second call should be a no-op.
4348
*/
44-
void locks_end_grace(struct lock_manager *lm)
49+
void
50+
locks_end_grace(struct lock_manager *lm)
4551
{
4652
spin_lock(&grace_lock);
4753
list_del_init(&lm->list);
@@ -56,10 +62,52 @@ EXPORT_SYMBOL_GPL(locks_end_grace);
5662
* to answer ordinary lock requests, and when they should accept only
5763
* lock reclaims.
5864
*/
59-
int locks_in_grace(struct net *net)
65+
int
66+
locks_in_grace(struct net *net)
6067
{
61-
struct lockd_net *ln = net_generic(net, lockd_net_id);
68+
struct list_head *grace_list = net_generic(net, grace_net_id);
6269

63-
return !list_empty(&ln->grace_list);
70+
return !list_empty(grace_list);
6471
}
6572
EXPORT_SYMBOL_GPL(locks_in_grace);
73+
74+
static int __net_init
75+
grace_init_net(struct net *net)
76+
{
77+
struct list_head *grace_list = net_generic(net, grace_net_id);
78+
79+
INIT_LIST_HEAD(grace_list);
80+
return 0;
81+
}
82+
83+
static void __net_exit
84+
grace_exit_net(struct net *net)
85+
{
86+
struct list_head *grace_list = net_generic(net, grace_net_id);
87+
88+
BUG_ON(!list_empty(grace_list));
89+
}
90+
91+
static struct pernet_operations grace_net_ops = {
92+
.init = grace_init_net,
93+
.exit = grace_exit_net,
94+
.id = &grace_net_id,
95+
.size = sizeof(struct list_head),
96+
};
97+
98+
static int __init
99+
init_grace(void)
100+
{
101+
return register_pernet_subsys(&grace_net_ops);
102+
}
103+
104+
static void __exit
105+
exit_grace(void)
106+
{
107+
unregister_pernet_subsys(&grace_net_ops);
108+
}
109+
110+
MODULE_AUTHOR("Jeff Layton <jlayton@primarydata.com>");
111+
MODULE_LICENSE("GPL");
112+
module_init(init_grace)
113+
module_exit(exit_grace)

‎fs/nfsd/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ config NFSD_V4
7171
select FS_POSIX_ACL
7272
select SUNRPC_GSS
7373
select CRYPTO
74+
select GRACE_PERIOD
7475
help
7576
This option enables support in your system's NFS server for
7677
version 4 of the NFS protocol (RFC 3530).

‎include/linux/proc_fs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
7474

7575
#endif /* CONFIG_PROC_FS */
7676

77+
struct net;
78+
7779
static inline struct proc_dir_entry *proc_net_mkdir(
7880
struct net *net, const char *name, struct proc_dir_entry *parent)
7981
{

0 commit comments

Comments
 (0)