Skip to content

Commit 5ccb006

Browse files
Stanislav KinsburskyJ. Bruce Fields
authored andcommitted
LockD: pass actual network namespace to grace period management functions
Passed network namespace replaced hard-coded init_net Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent db9c455 commit 5ccb006

10 files changed

Lines changed: 67 additions & 58 deletions

File tree

‎fs/lockd/grace.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ static DEFINE_SPINLOCK(grace_lock);
2121
*
2222
* This function is called to start a grace period.
2323
*/
24-
void locks_start_grace(struct lock_manager *lm)
24+
void locks_start_grace(struct net *net, struct lock_manager *lm)
2525
{
26-
struct net *net = &init_net;
2726
struct lockd_net *ln = net_generic(net, lockd_net_id);
2827

2928
spin_lock(&grace_lock);
@@ -57,9 +56,8 @@ EXPORT_SYMBOL_GPL(locks_end_grace);
5756
* to answer ordinary lock requests, and when they should accept only
5857
* lock reclaims.
5958
*/
60-
int locks_in_grace(void)
59+
int locks_in_grace(struct net *net)
6160
{
62-
struct net *net = &init_net;
6361
struct lockd_net *ln = net_generic(net, lockd_net_id);
6462

6563
return !list_empty(&ln->grace_list);

‎fs/lockd/svc.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,26 @@ static void grace_ender(struct work_struct *grace)
9797
locks_end_grace(&ln->lockd_manager);
9898
}
9999

100-
static void set_grace_period(void)
100+
static void set_grace_period(struct net *net)
101101
{
102102
unsigned long grace_period = get_lockd_grace_period();
103-
struct lockd_net *ln = net_generic(&init_net, lockd_net_id);
103+
struct lockd_net *ln = net_generic(net, lockd_net_id);
104104

105-
locks_start_grace(&ln->lockd_manager);
105+
locks_start_grace(net, &ln->lockd_manager);
106106
cancel_delayed_work_sync(&ln->grace_period_end);
107107
schedule_delayed_work(&ln->grace_period_end, grace_period);
108108
}
109109

110110
static void restart_grace(void)
111111
{
112112
if (nlmsvc_ops) {
113-
struct lockd_net *ln = net_generic(&init_net, lockd_net_id);
113+
struct net *net = &init_net;
114+
struct lockd_net *ln = net_generic(net, lockd_net_id);
114115

115116
cancel_delayed_work_sync(&ln->grace_period_end);
116117
locks_end_grace(&ln->lockd_manager);
117118
nlmsvc_invalidate_all();
118-
set_grace_period();
119+
set_grace_period(net);
119120
}
120121
}
121122

@@ -127,7 +128,8 @@ lockd(void *vrqstp)
127128
{
128129
int err = 0, preverr = 0;
129130
struct svc_rqst *rqstp = vrqstp;
130-
struct lockd_net *ln = net_generic(&init_net, lockd_net_id);
131+
struct net *net = &init_net;
132+
struct lockd_net *ln = net_generic(net, lockd_net_id);
131133

132134
/* try_to_freeze() is called from svc_recv() */
133135
set_freezable();
@@ -141,7 +143,7 @@ lockd(void *vrqstp)
141143
nlm_timeout = LOCKD_DFLT_TIMEO;
142144
nlmsvc_timeout = nlm_timeout * HZ;
143145

144-
set_grace_period();
146+
set_grace_period(net);
145147

146148
/*
147149
* The main request loop. We don't terminate until the last

‎fs/lockd/svc4proc.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/time.h>
1212
#include <linux/lockd/lockd.h>
1313
#include <linux/lockd/share.h>
14+
#include <linux/sunrpc/svc_xprt.h>
1415

1516
#define NLMDBG_FACILITY NLMDBG_CLIENT
1617

@@ -151,7 +152,7 @@ nlm4svc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp,
151152
resp->cookie = argp->cookie;
152153

153154
/* Don't accept requests during grace period */
154-
if (locks_in_grace()) {
155+
if (locks_in_grace(SVC_NET(rqstp))) {
155156
resp->status = nlm_lck_denied_grace_period;
156157
return rpc_success;
157158
}
@@ -161,7 +162,7 @@ nlm4svc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp,
161162
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
162163

163164
/* Try to cancel request. */
164-
resp->status = nlmsvc_cancel_blocked(file, &argp->lock);
165+
resp->status = nlmsvc_cancel_blocked(SVC_NET(rqstp), file, &argp->lock);
165166

166167
dprintk("lockd: CANCEL status %d\n", ntohl(resp->status));
167168
nlmsvc_release_host(host);
@@ -184,7 +185,7 @@ nlm4svc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp,
184185
resp->cookie = argp->cookie;
185186

186187
/* Don't accept new lock requests during grace period */
187-
if (locks_in_grace()) {
188+
if (locks_in_grace(SVC_NET(rqstp))) {
188189
resp->status = nlm_lck_denied_grace_period;
189190
return rpc_success;
190191
}
@@ -194,7 +195,7 @@ nlm4svc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp,
194195
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
195196

196197
/* Now try to remove the lock */
197-
resp->status = nlmsvc_unlock(file, &argp->lock);
198+
resp->status = nlmsvc_unlock(SVC_NET(rqstp), file, &argp->lock);
198199

199200
dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status));
200201
nlmsvc_release_host(host);
@@ -321,7 +322,7 @@ nlm4svc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp,
321322
resp->cookie = argp->cookie;
322323

323324
/* Don't accept new lock requests during grace period */
324-
if (locks_in_grace() && !argp->reclaim) {
325+
if (locks_in_grace(SVC_NET(rqstp)) && !argp->reclaim) {
325326
resp->status = nlm_lck_denied_grace_period;
326327
return rpc_success;
327328
}
@@ -354,7 +355,7 @@ nlm4svc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp,
354355
resp->cookie = argp->cookie;
355356

356357
/* Don't accept requests during grace period */
357-
if (locks_in_grace()) {
358+
if (locks_in_grace(SVC_NET(rqstp))) {
358359
resp->status = nlm_lck_denied_grace_period;
359360
return rpc_success;
360361
}

‎fs/lockd/svclock.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <linux/kernel.h>
2727
#include <linux/sched.h>
2828
#include <linux/sunrpc/clnt.h>
29-
#include <linux/sunrpc/svc.h>
29+
#include <linux/sunrpc/svc_xprt.h>
3030
#include <linux/lockd/nlm.h>
3131
#include <linux/lockd/lockd.h>
3232
#include <linux/kthread.h>
@@ -447,11 +447,11 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
447447
goto out;
448448
}
449449

450-
if (locks_in_grace() && !reclaim) {
450+
if (locks_in_grace(SVC_NET(rqstp)) && !reclaim) {
451451
ret = nlm_lck_denied_grace_period;
452452
goto out;
453453
}
454-
if (reclaim && !locks_in_grace()) {
454+
if (reclaim && !locks_in_grace(SVC_NET(rqstp))) {
455455
ret = nlm_lck_denied_grace_period;
456456
goto out;
457457
}
@@ -559,7 +559,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
559559
goto out;
560560
}
561561

562-
if (locks_in_grace()) {
562+
if (locks_in_grace(SVC_NET(rqstp))) {
563563
ret = nlm_lck_denied_grace_period;
564564
goto out;
565565
}
@@ -603,7 +603,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
603603
* must be removed.
604604
*/
605605
__be32
606-
nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock)
606+
nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)
607607
{
608608
int error;
609609

@@ -615,7 +615,7 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock)
615615
(long long)lock->fl.fl_end);
616616

617617
/* First, cancel any lock that might be there */
618-
nlmsvc_cancel_blocked(file, lock);
618+
nlmsvc_cancel_blocked(net, file, lock);
619619

620620
lock->fl.fl_type = F_UNLCK;
621621
error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL);
@@ -631,7 +631,7 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock)
631631
* The calling procedure must check whether the file can be closed.
632632
*/
633633
__be32
634-
nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock)
634+
nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *lock)
635635
{
636636
struct nlm_block *block;
637637
int status = 0;
@@ -643,7 +643,7 @@ nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock)
643643
(long long)lock->fl.fl_start,
644644
(long long)lock->fl.fl_end);
645645

646-
if (locks_in_grace())
646+
if (locks_in_grace(net))
647647
return nlm_lck_denied_grace_period;
648648

649649
mutex_lock(&file->f_mutex);

‎fs/lockd/svcproc.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/time.h>
1212
#include <linux/lockd/lockd.h>
1313
#include <linux/lockd/share.h>
14+
#include <linux/sunrpc/svc_xprt.h>
1415

1516
#define NLMDBG_FACILITY NLMDBG_CLIENT
1617

@@ -175,13 +176,14 @@ nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp,
175176
{
176177
struct nlm_host *host;
177178
struct nlm_file *file;
179+
struct net *net = SVC_NET(rqstp);
178180

179181
dprintk("lockd: CANCEL called\n");
180182

181183
resp->cookie = argp->cookie;
182184

183185
/* Don't accept requests during grace period */
184-
if (locks_in_grace()) {
186+
if (locks_in_grace(net)) {
185187
resp->status = nlm_lck_denied_grace_period;
186188
return rpc_success;
187189
}
@@ -191,7 +193,7 @@ nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp,
191193
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
192194

193195
/* Try to cancel request. */
194-
resp->status = cast_status(nlmsvc_cancel_blocked(file, &argp->lock));
196+
resp->status = cast_status(nlmsvc_cancel_blocked(net, file, &argp->lock));
195197

196198
dprintk("lockd: CANCEL status %d\n", ntohl(resp->status));
197199
nlmsvc_release_host(host);
@@ -208,13 +210,14 @@ nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp,
208210
{
209211
struct nlm_host *host;
210212
struct nlm_file *file;
213+
struct net *net = SVC_NET(rqstp);
211214

212215
dprintk("lockd: UNLOCK called\n");
213216

214217
resp->cookie = argp->cookie;
215218

216219
/* Don't accept new lock requests during grace period */
217-
if (locks_in_grace()) {
220+
if (locks_in_grace(net)) {
218221
resp->status = nlm_lck_denied_grace_period;
219222
return rpc_success;
220223
}
@@ -224,7 +227,7 @@ nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp,
224227
return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
225228

226229
/* Now try to remove the lock */
227-
resp->status = cast_status(nlmsvc_unlock(file, &argp->lock));
230+
resp->status = cast_status(nlmsvc_unlock(net, file, &argp->lock));
228231

229232
dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status));
230233
nlmsvc_release_host(host);
@@ -361,7 +364,7 @@ nlmsvc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp,
361364
resp->cookie = argp->cookie;
362365

363366
/* Don't accept new lock requests during grace period */
364-
if (locks_in_grace() && !argp->reclaim) {
367+
if (locks_in_grace(SVC_NET(rqstp)) && !argp->reclaim) {
365368
resp->status = nlm_lck_denied_grace_period;
366369
return rpc_success;
367370
}
@@ -394,7 +397,7 @@ nlmsvc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp,
394397
resp->cookie = argp->cookie;
395398

396399
/* Don't accept requests during grace period */
397-
if (locks_in_grace()) {
400+
if (locks_in_grace(SVC_NET(rqstp))) {
398401
resp->status = nlm_lck_denied_grace_period;
399402
return rpc_success;
400403
}

‎fs/nfsd/nfs4proc.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,10 @@ nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
354354
/* Openowner is now set, so sequence id will get bumped. Now we need
355355
* these checks before we do any creates: */
356356
status = nfserr_grace;
357-
if (locks_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
357+
if (locks_in_grace(SVC_NET(rqstp)) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
358358
goto out;
359359
status = nfserr_no_grace;
360-
if (!locks_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
360+
if (!locks_in_grace(SVC_NET(rqstp)) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
361361
goto out;
362362

363363
switch (open->op_claim_type) {
@@ -686,7 +686,8 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
686686

687687
nfs4_lock_state();
688688
/* check stateid */
689-
if ((status = nfs4_preprocess_stateid_op(cstate, &read->rd_stateid,
689+
if ((status = nfs4_preprocess_stateid_op(SVC_NET(rqstp),
690+
cstate, &read->rd_stateid,
690691
RD_STATE, &read->rd_filp))) {
691692
dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
692693
goto out;
@@ -741,7 +742,7 @@ nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
741742
{
742743
__be32 status;
743744

744-
if (locks_in_grace())
745+
if (locks_in_grace(SVC_NET(rqstp)))
745746
return nfserr_grace;
746747
status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
747748
remove->rm_name, remove->rm_namelen);
@@ -760,8 +761,8 @@ nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
760761

761762
if (!cstate->save_fh.fh_dentry)
762763
return status;
763-
if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags
764-
& NFSEXP_NOSUBTREECHECK))
764+
if (locks_in_grace(SVC_NET(rqstp)) &&
765+
!(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK))
765766
return nfserr_grace;
766767
status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
767768
rename->rn_snamelen, &cstate->current_fh,
@@ -845,7 +846,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
845846

846847
if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
847848
nfs4_lock_state();
848-
status = nfs4_preprocess_stateid_op(cstate,
849+
status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), cstate,
849850
&setattr->sa_stateid, WR_STATE, NULL);
850851
nfs4_unlock_state();
851852
if (status) {
@@ -890,7 +891,8 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
890891
return nfserr_inval;
891892

892893
nfs4_lock_state();
893-
status = nfs4_preprocess_stateid_op(cstate, stateid, WR_STATE, &filp);
894+
status = nfs4_preprocess_stateid_op(SVC_NET(rqstp),
895+
cstate, stateid, WR_STATE, &filp);
894896
if (filp)
895897
get_file(filp);
896898
nfs4_unlock_state();

0 commit comments

Comments
 (0)