Commit 5ccb0066f2d561549cc4d73d7f56b4ce3ca7a8a1

Authored by Stanislav Kinsbursky
Committed by J. Bruce Fields
1 parent db9c455341

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>

Showing 10 changed files with 67 additions and 58 deletions Side-by-side Diff

... ... @@ -21,9 +21,8 @@
21 21 *
22 22 * This function is called to start a grace period.
23 23 */
24   -void locks_start_grace(struct lock_manager *lm)
  24 +void locks_start_grace(struct net *net, struct lock_manager *lm)
25 25 {
26   - struct net *net = &init_net;
27 26 struct lockd_net *ln = net_generic(net, lockd_net_id);
28 27  
29 28 spin_lock(&grace_lock);
30 29  
... ... @@ -57,9 +56,8 @@
57 56 * to answer ordinary lock requests, and when they should accept only
58 57 * lock reclaims.
59 58 */
60   -int locks_in_grace(void)
  59 +int locks_in_grace(struct net *net)
61 60 {
62   - struct net *net = &init_net;
63 61 struct lockd_net *ln = net_generic(net, lockd_net_id);
64 62  
65 63 return !list_empty(&ln->grace_list);
... ... @@ -97,12 +97,12 @@
97 97 locks_end_grace(&ln->lockd_manager);
98 98 }
99 99  
100   -static void set_grace_period(void)
  100 +static void set_grace_period(struct net *net)
101 101 {
102 102 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);
104 104  
105   - locks_start_grace(&ln->lockd_manager);
  105 + locks_start_grace(net, &ln->lockd_manager);
106 106 cancel_delayed_work_sync(&ln->grace_period_end);
107 107 schedule_delayed_work(&ln->grace_period_end, grace_period);
108 108 }
109 109  
... ... @@ -110,12 +110,13 @@
110 110 static void restart_grace(void)
111 111 {
112 112 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);
114 115  
115 116 cancel_delayed_work_sync(&ln->grace_period_end);
116 117 locks_end_grace(&ln->lockd_manager);
117 118 nlmsvc_invalidate_all();
118   - set_grace_period();
  119 + set_grace_period(net);
119 120 }
120 121 }
121 122  
... ... @@ -127,7 +128,8 @@
127 128 {
128 129 int err = 0, preverr = 0;
129 130 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);
131 133  
132 134 /* try_to_freeze() is called from svc_recv() */
133 135 set_freezable();
... ... @@ -141,7 +143,7 @@
141 143 nlm_timeout = LOCKD_DFLT_TIMEO;
142 144 nlmsvc_timeout = nlm_timeout * HZ;
143 145  
144   - set_grace_period();
  146 + set_grace_period(net);
145 147  
146 148 /*
147 149 * The main request loop. We don't terminate until the last
... ... @@ -11,6 +11,7 @@
11 11 #include <linux/time.h>
12 12 #include <linux/lockd/lockd.h>
13 13 #include <linux/lockd/share.h>
  14 +#include <linux/sunrpc/svc_xprt.h>
14 15  
15 16 #define NLMDBG_FACILITY NLMDBG_CLIENT
16 17  
... ... @@ -151,7 +152,7 @@
151 152 resp->cookie = argp->cookie;
152 153  
153 154 /* Don't accept requests during grace period */
154   - if (locks_in_grace()) {
  155 + if (locks_in_grace(SVC_NET(rqstp))) {
155 156 resp->status = nlm_lck_denied_grace_period;
156 157 return rpc_success;
157 158 }
... ... @@ -161,7 +162,7 @@
161 162 return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
162 163  
163 164 /* 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);
165 166  
166 167 dprintk("lockd: CANCEL status %d\n", ntohl(resp->status));
167 168 nlmsvc_release_host(host);
... ... @@ -184,7 +185,7 @@
184 185 resp->cookie = argp->cookie;
185 186  
186 187 /* Don't accept new lock requests during grace period */
187   - if (locks_in_grace()) {
  188 + if (locks_in_grace(SVC_NET(rqstp))) {
188 189 resp->status = nlm_lck_denied_grace_period;
189 190 return rpc_success;
190 191 }
... ... @@ -194,7 +195,7 @@
194 195 return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
195 196  
196 197 /* 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);
198 199  
199 200 dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status));
200 201 nlmsvc_release_host(host);
... ... @@ -321,7 +322,7 @@
321 322 resp->cookie = argp->cookie;
322 323  
323 324 /* 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) {
325 326 resp->status = nlm_lck_denied_grace_period;
326 327 return rpc_success;
327 328 }
... ... @@ -354,7 +355,7 @@
354 355 resp->cookie = argp->cookie;
355 356  
356 357 /* Don't accept requests during grace period */
357   - if (locks_in_grace()) {
  358 + if (locks_in_grace(SVC_NET(rqstp))) {
358 359 resp->status = nlm_lck_denied_grace_period;
359 360 return rpc_success;
360 361 }
... ... @@ -26,7 +26,7 @@
26 26 #include <linux/kernel.h>
27 27 #include <linux/sched.h>
28 28 #include <linux/sunrpc/clnt.h>
29   -#include <linux/sunrpc/svc.h>
  29 +#include <linux/sunrpc/svc_xprt.h>
30 30 #include <linux/lockd/nlm.h>
31 31 #include <linux/lockd/lockd.h>
32 32 #include <linux/kthread.h>
33 33  
... ... @@ -447,11 +447,11 @@
447 447 goto out;
448 448 }
449 449  
450   - if (locks_in_grace() && !reclaim) {
  450 + if (locks_in_grace(SVC_NET(rqstp)) && !reclaim) {
451 451 ret = nlm_lck_denied_grace_period;
452 452 goto out;
453 453 }
454   - if (reclaim && !locks_in_grace()) {
  454 + if (reclaim && !locks_in_grace(SVC_NET(rqstp))) {
455 455 ret = nlm_lck_denied_grace_period;
456 456 goto out;
457 457 }
... ... @@ -559,7 +559,7 @@
559 559 goto out;
560 560 }
561 561  
562   - if (locks_in_grace()) {
  562 + if (locks_in_grace(SVC_NET(rqstp))) {
563 563 ret = nlm_lck_denied_grace_period;
564 564 goto out;
565 565 }
... ... @@ -603,7 +603,7 @@
603 603 * must be removed.
604 604 */
605 605 __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)
607 607 {
608 608 int error;
609 609  
... ... @@ -615,7 +615,7 @@
615 615 (long long)lock->fl.fl_end);
616 616  
617 617 /* First, cancel any lock that might be there */
618   - nlmsvc_cancel_blocked(file, lock);
  618 + nlmsvc_cancel_blocked(net, file, lock);
619 619  
620 620 lock->fl.fl_type = F_UNLCK;
621 621 error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL);
... ... @@ -631,7 +631,7 @@
631 631 * The calling procedure must check whether the file can be closed.
632 632 */
633 633 __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)
635 635 {
636 636 struct nlm_block *block;
637 637 int status = 0;
... ... @@ -643,7 +643,7 @@
643 643 (long long)lock->fl.fl_start,
644 644 (long long)lock->fl.fl_end);
645 645  
646   - if (locks_in_grace())
  646 + if (locks_in_grace(net))
647 647 return nlm_lck_denied_grace_period;
648 648  
649 649 mutex_lock(&file->f_mutex);
... ... @@ -11,6 +11,7 @@
11 11 #include <linux/time.h>
12 12 #include <linux/lockd/lockd.h>
13 13 #include <linux/lockd/share.h>
  14 +#include <linux/sunrpc/svc_xprt.h>
14 15  
15 16 #define NLMDBG_FACILITY NLMDBG_CLIENT
16 17  
17 18  
... ... @@ -175,13 +176,14 @@
175 176 {
176 177 struct nlm_host *host;
177 178 struct nlm_file *file;
  179 + struct net *net = SVC_NET(rqstp);
178 180  
179 181 dprintk("lockd: CANCEL called\n");
180 182  
181 183 resp->cookie = argp->cookie;
182 184  
183 185 /* Don't accept requests during grace period */
184   - if (locks_in_grace()) {
  186 + if (locks_in_grace(net)) {
185 187 resp->status = nlm_lck_denied_grace_period;
186 188 return rpc_success;
187 189 }
... ... @@ -191,7 +193,7 @@
191 193 return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
192 194  
193 195 /* 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));
195 197  
196 198 dprintk("lockd: CANCEL status %d\n", ntohl(resp->status));
197 199 nlmsvc_release_host(host);
198 200  
... ... @@ -208,13 +210,14 @@
208 210 {
209 211 struct nlm_host *host;
210 212 struct nlm_file *file;
  213 + struct net *net = SVC_NET(rqstp);
211 214  
212 215 dprintk("lockd: UNLOCK called\n");
213 216  
214 217 resp->cookie = argp->cookie;
215 218  
216 219 /* Don't accept new lock requests during grace period */
217   - if (locks_in_grace()) {
  220 + if (locks_in_grace(net)) {
218 221 resp->status = nlm_lck_denied_grace_period;
219 222 return rpc_success;
220 223 }
... ... @@ -224,7 +227,7 @@
224 227 return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
225 228  
226 229 /* 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));
228 231  
229 232 dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status));
230 233 nlmsvc_release_host(host);
... ... @@ -361,7 +364,7 @@
361 364 resp->cookie = argp->cookie;
362 365  
363 366 /* 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) {
365 368 resp->status = nlm_lck_denied_grace_period;
366 369 return rpc_success;
367 370 }
... ... @@ -394,7 +397,7 @@
394 397 resp->cookie = argp->cookie;
395 398  
396 399 /* Don't accept requests during grace period */
397   - if (locks_in_grace()) {
  400 + if (locks_in_grace(SVC_NET(rqstp))) {
398 401 resp->status = nlm_lck_denied_grace_period;
399 402 return rpc_success;
400 403 }
... ... @@ -354,10 +354,10 @@
354 354 /* Openowner is now set, so sequence id will get bumped. Now we need
355 355 * these checks before we do any creates: */
356 356 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)
358 358 goto out;
359 359 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)
361 361 goto out;
362 362  
363 363 switch (open->op_claim_type) {
... ... @@ -686,7 +686,8 @@
686 686  
687 687 nfs4_lock_state();
688 688 /* 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,
690 691 RD_STATE, &read->rd_filp))) {
691 692 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
692 693 goto out;
... ... @@ -741,7 +742,7 @@
741 742 {
742 743 __be32 status;
743 744  
744   - if (locks_in_grace())
  745 + if (locks_in_grace(SVC_NET(rqstp)))
745 746 return nfserr_grace;
746 747 status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
747 748 remove->rm_name, remove->rm_namelen);
... ... @@ -760,8 +761,8 @@
760 761  
761 762 if (!cstate->save_fh.fh_dentry)
762 763 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))
765 766 return nfserr_grace;
766 767 status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
767 768 rename->rn_snamelen, &cstate->current_fh,
... ... @@ -845,7 +846,7 @@
845 846  
846 847 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
847 848 nfs4_lock_state();
848   - status = nfs4_preprocess_stateid_op(cstate,
  849 + status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), cstate,
849 850 &setattr->sa_stateid, WR_STATE, NULL);
850 851 nfs4_unlock_state();
851 852 if (status) {
... ... @@ -890,7 +891,8 @@
890 891 return nfserr_inval;
891 892  
892 893 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);
894 896 if (filp)
895 897 get_file(filp);
896 898 nfs4_unlock_state();
... ... @@ -2885,7 +2885,8 @@
2885 2885 * Attempt to hand out a delegation.
2886 2886 */
2887 2887 static void
2888   -nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_ol_stateid *stp)
  2888 +nfs4_open_delegation(struct net *net, struct svc_fh *fh,
  2889 + struct nfsd4_open *open, struct nfs4_ol_stateid *stp)
2889 2890 {
2890 2891 struct nfs4_delegation *dp;
2891 2892 struct nfs4_openowner *oo = container_of(stp->st_stateowner, struct nfs4_openowner, oo_owner);
... ... @@ -2906,7 +2907,7 @@
2906 2907 case NFS4_OPEN_CLAIM_NULL:
2907 2908 /* Let's not give out any delegations till everyone's
2908 2909 * had the chance to reclaim theirs.... */
2909   - if (locks_in_grace())
  2910 + if (locks_in_grace(net))
2910 2911 goto out;
2911 2912 if (!cb_up || !(oo->oo_flags & NFS4_OO_CONFIRMED))
2912 2913 goto out;
... ... @@ -3040,7 +3041,7 @@
3040 3041 * Attempt to hand out a delegation. No error return, because the
3041 3042 * OPEN succeeds even if we fail.
3042 3043 */
3043   - nfs4_open_delegation(current_fh, open, stp);
  3044 + nfs4_open_delegation(SVC_NET(rqstp), current_fh, open, stp);
3044 3045 nodeleg:
3045 3046 status = nfs_ok;
3046 3047  
3047 3048  
... ... @@ -3279,11 +3280,11 @@
3279 3280 }
3280 3281  
3281 3282 static inline __be32
3282   -check_special_stateids(svc_fh *current_fh, stateid_t *stateid, int flags)
  3283 +check_special_stateids(struct net *net, svc_fh *current_fh, stateid_t *stateid, int flags)
3283 3284 {
3284 3285 if (ONE_STATEID(stateid) && (flags & RD_STATE))
3285 3286 return nfs_ok;
3286   - else if (locks_in_grace()) {
  3287 + else if (locks_in_grace(net)) {
3287 3288 /* Answer in remaining cases depends on existence of
3288 3289 * conflicting state; so we must wait out the grace period. */
3289 3290 return nfserr_grace;
3290 3291  
... ... @@ -3300,9 +3301,9 @@
3300 3301 * that are not able to provide mandatory locking.
3301 3302 */
3302 3303 static inline int
3303   -grace_disallows_io(struct inode *inode)
  3304 +grace_disallows_io(struct net *net, struct inode *inode)
3304 3305 {
3305   - return locks_in_grace() && mandatory_lock(inode);
  3306 + return locks_in_grace(net) && mandatory_lock(inode);
3306 3307 }
3307 3308  
3308 3309 /* Returns true iff a is later than b: */
... ... @@ -3393,7 +3394,7 @@
3393 3394 * Checks for stateid operations
3394 3395 */
3395 3396 __be32
3396   -nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
  3397 +nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
3397 3398 stateid_t *stateid, int flags, struct file **filpp)
3398 3399 {
3399 3400 struct nfs4_stid *s;
3400 3401  
... ... @@ -3406,11 +3407,11 @@
3406 3407 if (filpp)
3407 3408 *filpp = NULL;
3408 3409  
3409   - if (grace_disallows_io(ino))
  3410 + if (grace_disallows_io(net, ino))
3410 3411 return nfserr_grace;
3411 3412  
3412 3413 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
3413   - return check_special_stateids(current_fh, stateid, flags);
  3414 + return check_special_stateids(net, current_fh, stateid, flags);
3414 3415  
3415 3416 status = nfsd4_lookup_stateid(stateid, NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID, &s);
3416 3417 if (status)
3417 3418  
... ... @@ -4107,10 +4108,10 @@
4107 4108 goto out;
4108 4109  
4109 4110 status = nfserr_grace;
4110   - if (locks_in_grace() && !lock->lk_reclaim)
  4111 + if (locks_in_grace(SVC_NET(rqstp)) && !lock->lk_reclaim)
4111 4112 goto out;
4112 4113 status = nfserr_no_grace;
4113   - if (!locks_in_grace() && lock->lk_reclaim)
  4114 + if (!locks_in_grace(SVC_NET(rqstp)) && lock->lk_reclaim)
4114 4115 goto out;
4115 4116  
4116 4117 locks_init_lock(&file_lock);
... ... @@ -4210,7 +4211,7 @@
4210 4211 struct nfs4_lockowner *lo;
4211 4212 __be32 status;
4212 4213  
4213   - if (locks_in_grace())
  4214 + if (locks_in_grace(SVC_NET(rqstp)))
4214 4215 return nfserr_grace;
4215 4216  
4216 4217 if (check_lock_length(lockt->lt_offset, lockt->lt_length))
... ... @@ -4703,7 +4704,7 @@
4703 4704 get_net(net);
4704 4705 nfsd4_client_tracking_init(net);
4705 4706 boot_time = get_seconds();
4706   - locks_start_grace(&nn->nfsd4_manager);
  4707 + locks_start_grace(net, &nn->nfsd4_manager);
4707 4708 grace_ended = false;
4708 4709 printk(KERN_INFO "NFSD: starting %ld-second grace period\n",
4709 4710 nfsd4_grace);
... ... @@ -451,7 +451,8 @@
451 451  
452 452 struct nfsd4_compound_state;
453 453  
454   -extern __be32 nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
  454 +extern __be32 nfs4_preprocess_stateid_op(struct net *net,
  455 + struct nfsd4_compound_state *cstate,
455 456 stateid_t *stateid, int flags, struct file **filp);
456 457 extern void nfs4_lock_state(void);
457 458 extern void nfs4_unlock_state(void);
... ... @@ -1163,9 +1163,10 @@
1163 1163 struct list_head list;
1164 1164 };
1165 1165  
1166   -void locks_start_grace(struct lock_manager *);
  1166 +struct net;
  1167 +void locks_start_grace(struct net *, struct lock_manager *);
1167 1168 void locks_end_grace(struct lock_manager *);
1168   -int locks_in_grace(void);
  1169 +int locks_in_grace(struct net *);
1169 1170  
1170 1171 /* that will die - we need it for nfs_lock_info */
1171 1172 #include <linux/nfs_fs_i.h>
include/linux/lockd/lockd.h
... ... @@ -262,11 +262,11 @@
262 262 __be32 nlmsvc_lock(struct svc_rqst *, struct nlm_file *,
263 263 struct nlm_host *, struct nlm_lock *, int,
264 264 struct nlm_cookie *, int);
265   -__be32 nlmsvc_unlock(struct nlm_file *, struct nlm_lock *);
  265 +__be32 nlmsvc_unlock(struct net *net, struct nlm_file *, struct nlm_lock *);
266 266 __be32 nlmsvc_testlock(struct svc_rqst *, struct nlm_file *,
267 267 struct nlm_host *, struct nlm_lock *,
268 268 struct nlm_lock *, struct nlm_cookie *);
269   -__be32 nlmsvc_cancel_blocked(struct nlm_file *, struct nlm_lock *);
  269 +__be32 nlmsvc_cancel_blocked(struct net *net, struct nlm_file *, struct nlm_lock *);
270 270 unsigned long nlmsvc_retry_blocked(void);
271 271 void nlmsvc_traverse_blocks(struct nlm_host *, struct nlm_file *,
272 272 nlm_host_match_fn_t match);