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

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>

authored by

Stanislav Kinsbursky and committed by
J. Bruce Fields
5ccb0066 db9c4553

+67 -58
+2 -4
fs/lockd/grace.c
··· 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); ··· 56 57 * to answer ordinary lock requests, and when they should accept only 57 58 * lock reclaims. 58 59 */ 59 - int locks_in_grace(void) 60 + int locks_in_grace(struct net *net) 60 61 { 61 - struct net *net = &init_net; 62 62 struct lockd_net *ln = net_generic(net, lockd_net_id); 63 63 64 64 return !list_empty(&ln->grace_list);
+9 -7
fs/lockd/svc.c
··· 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 } ··· 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 ··· 128 127 { 129 128 int err = 0, preverr = 0; 130 129 struct svc_rqst *rqstp = vrqstp; 131 - struct lockd_net *ln = net_generic(&init_net, lockd_net_id); 130 + struct net *net = &init_net; 131 + struct lockd_net *ln = net_generic(net, lockd_net_id); 132 132 133 133 /* try_to_freeze() is called from svc_recv() */ 134 134 set_freezable(); ··· 143 141 nlm_timeout = LOCKD_DFLT_TIMEO; 144 142 nlmsvc_timeout = nlm_timeout * HZ; 145 143 146 - set_grace_period(); 144 + set_grace_period(net); 147 145 148 146 /* 149 147 * The main request loop. We don't terminate until the last
+7 -6
fs/lockd/svc4proc.c
··· 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 ··· 152 151 resp->cookie = argp->cookie; 153 152 154 153 /* Don't accept requests during grace period */ 155 - if (locks_in_grace()) { 154 + if (locks_in_grace(SVC_NET(rqstp))) { 156 155 resp->status = nlm_lck_denied_grace_period; 157 156 return rpc_success; 158 157 } ··· 162 161 return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; 163 162 164 163 /* Try to cancel request. */ 165 - resp->status = nlmsvc_cancel_blocked(file, &argp->lock); 164 + resp->status = nlmsvc_cancel_blocked(SVC_NET(rqstp), file, &argp->lock); 166 165 167 166 dprintk("lockd: CANCEL status %d\n", ntohl(resp->status)); 168 167 nlmsvc_release_host(host); ··· 185 184 resp->cookie = argp->cookie; 186 185 187 186 /* Don't accept new lock requests during grace period */ 188 - if (locks_in_grace()) { 187 + if (locks_in_grace(SVC_NET(rqstp))) { 189 188 resp->status = nlm_lck_denied_grace_period; 190 189 return rpc_success; 191 190 } ··· 195 194 return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; 196 195 197 196 /* Now try to remove the lock */ 198 - resp->status = nlmsvc_unlock(file, &argp->lock); 197 + resp->status = nlmsvc_unlock(SVC_NET(rqstp), file, &argp->lock); 199 198 200 199 dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status)); 201 200 nlmsvc_release_host(host); ··· 322 321 resp->cookie = argp->cookie; 323 322 324 323 /* Don't accept new lock requests during grace period */ 325 - if (locks_in_grace() && !argp->reclaim) { 324 + if (locks_in_grace(SVC_NET(rqstp)) && !argp->reclaim) { 326 325 resp->status = nlm_lck_denied_grace_period; 327 326 return rpc_success; 328 327 } ··· 355 354 resp->cookie = argp->cookie; 356 355 357 356 /* Don't accept requests during grace period */ 358 - if (locks_in_grace()) { 357 + if (locks_in_grace(SVC_NET(rqstp))) { 359 358 resp->status = nlm_lck_denied_grace_period; 360 359 return rpc_success; 361 360 }
+8 -8
fs/lockd/svclock.c
··· 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> ··· 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 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 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 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 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 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);
+9 -6
fs/lockd/svcproc.c
··· 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 ··· 176 175 { 177 176 struct nlm_host *host; 178 177 struct nlm_file *file; 178 + struct net *net = SVC_NET(rqstp); 179 179 180 180 dprintk("lockd: CANCEL called\n"); 181 181 182 182 resp->cookie = argp->cookie; 183 183 184 184 /* Don't accept requests during grace period */ 185 - if (locks_in_grace()) { 185 + if (locks_in_grace(net)) { 186 186 resp->status = nlm_lck_denied_grace_period; 187 187 return rpc_success; 188 188 } ··· 193 191 return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; 194 192 195 193 /* Try to cancel request. */ 196 - resp->status = cast_status(nlmsvc_cancel_blocked(file, &argp->lock)); 194 + resp->status = cast_status(nlmsvc_cancel_blocked(net, file, &argp->lock)); 197 195 198 196 dprintk("lockd: CANCEL status %d\n", ntohl(resp->status)); 199 197 nlmsvc_release_host(host); ··· 210 208 { 211 209 struct nlm_host *host; 212 210 struct nlm_file *file; 211 + struct net *net = SVC_NET(rqstp); 213 212 214 213 dprintk("lockd: UNLOCK called\n"); 215 214 216 215 resp->cookie = argp->cookie; 217 216 218 217 /* Don't accept new lock requests during grace period */ 219 - if (locks_in_grace()) { 218 + if (locks_in_grace(net)) { 220 219 resp->status = nlm_lck_denied_grace_period; 221 220 return rpc_success; 222 221 } ··· 227 224 return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; 228 225 229 226 /* Now try to remove the lock */ 230 - resp->status = cast_status(nlmsvc_unlock(file, &argp->lock)); 227 + resp->status = cast_status(nlmsvc_unlock(net, file, &argp->lock)); 231 228 232 229 dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status)); 233 230 nlmsvc_release_host(host); ··· 364 361 resp->cookie = argp->cookie; 365 362 366 363 /* Don't accept new lock requests during grace period */ 367 - if (locks_in_grace() && !argp->reclaim) { 364 + if (locks_in_grace(SVC_NET(rqstp)) && !argp->reclaim) { 368 365 resp->status = nlm_lck_denied_grace_period; 369 366 return rpc_success; 370 367 } ··· 397 394 resp->cookie = argp->cookie; 398 395 399 396 /* Don't accept requests during grace period */ 400 - if (locks_in_grace()) { 397 + if (locks_in_grace(SVC_NET(rqstp))) { 401 398 resp->status = nlm_lck_denied_grace_period; 402 399 return rpc_success; 403 400 }
+10 -8
fs/nfsd/nfs4proc.c
··· 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 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; ··· 742 741 { 743 742 __be32 status; 744 743 745 - if (locks_in_grace()) 744 + if (locks_in_grace(SVC_NET(rqstp))) 746 745 return nfserr_grace; 747 746 status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 748 747 remove->rm_name, remove->rm_namelen); ··· 761 760 762 761 if (!cstate->save_fh.fh_dentry) 763 762 return status; 764 - if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags 765 - & NFSEXP_NOSUBTREECHECK)) 763 + if (locks_in_grace(SVC_NET(rqstp)) && 764 + !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK)) 766 765 return nfserr_grace; 767 766 status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 768 767 rename->rn_snamelen, &cstate->current_fh, ··· 846 845 847 846 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 848 847 nfs4_lock_state(); 849 - status = nfs4_preprocess_stateid_op(cstate, 848 + status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), cstate, 850 849 &setattr->sa_stateid, WR_STATE, NULL); 851 850 nfs4_unlock_state(); 852 851 if (status) { ··· 891 890 return nfserr_inval; 892 891 893 892 nfs4_lock_state(); 894 - status = nfs4_preprocess_stateid_op(cstate, stateid, WR_STATE, &filp); 893 + status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), 894 + cstate, stateid, WR_STATE, &filp); 895 895 if (filp) 896 896 get_file(filp); 897 897 nfs4_unlock_state();
+15 -14
fs/nfsd/nfs4state.c
··· 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); ··· 2907 2906 case NFS4_OPEN_CLAIM_NULL: 2908 2907 /* Let's not give out any delegations till everyone's 2909 2908 * had the chance to reclaim theirs.... */ 2910 - if (locks_in_grace()) 2909 + if (locks_in_grace(net)) 2911 2910 goto out; 2912 2911 if (!cb_up || !(oo->oo_flags & NFS4_OO_CONFIRMED)) 2913 2912 goto out; ··· 3041 3040 * Attempt to hand out a delegation. No error return, because the 3042 3041 * OPEN succeeds even if we fail. 3043 3042 */ 3044 - nfs4_open_delegation(current_fh, open, stp); 3043 + nfs4_open_delegation(SVC_NET(rqstp), current_fh, open, stp); 3045 3044 nodeleg: 3046 3045 status = nfs_ok; 3047 3046 ··· 3280 3279 } 3281 3280 3282 3281 static inline __be32 3283 - check_special_stateids(svc_fh *current_fh, stateid_t *stateid, int flags) 3282 + check_special_stateids(struct net *net, svc_fh *current_fh, stateid_t *stateid, int flags) 3284 3283 { 3285 3284 if (ONE_STATEID(stateid) && (flags & RD_STATE)) 3286 3285 return nfs_ok; 3287 - else if (locks_in_grace()) { 3286 + else if (locks_in_grace(net)) { 3288 3287 /* Answer in remaining cases depends on existence of 3289 3288 * conflicting state; so we must wait out the grace period. */ 3290 3289 return nfserr_grace; ··· 3301 3300 * that are not able to provide mandatory locking. 3302 3301 */ 3303 3302 static inline int 3304 - grace_disallows_io(struct inode *inode) 3303 + grace_disallows_io(struct net *net, struct inode *inode) 3305 3304 { 3306 - return locks_in_grace() && mandatory_lock(inode); 3305 + return locks_in_grace(net) && mandatory_lock(inode); 3307 3306 } 3308 3307 3309 3308 /* Returns true iff a is later than b: */ ··· 3394 3393 * Checks for stateid operations 3395 3394 */ 3396 3395 __be32 3397 - nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate, 3396 + nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate, 3398 3397 stateid_t *stateid, int flags, struct file **filpp) 3399 3398 { 3400 3399 struct nfs4_stid *s; ··· 3407 3406 if (filpp) 3408 3407 *filpp = NULL; 3409 3408 3410 - if (grace_disallows_io(ino)) 3409 + if (grace_disallows_io(net, ino)) 3411 3410 return nfserr_grace; 3412 3411 3413 3412 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid)) 3414 - return check_special_stateids(current_fh, stateid, flags); 3413 + return check_special_stateids(net, current_fh, stateid, flags); 3415 3414 3416 3415 status = nfsd4_lookup_stateid(stateid, NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID, &s); 3417 3416 if (status) ··· 4108 4107 goto out; 4109 4108 4110 4109 status = nfserr_grace; 4111 - if (locks_in_grace() && !lock->lk_reclaim) 4110 + if (locks_in_grace(SVC_NET(rqstp)) && !lock->lk_reclaim) 4112 4111 goto out; 4113 4112 status = nfserr_no_grace; 4114 - if (!locks_in_grace() && lock->lk_reclaim) 4113 + if (!locks_in_grace(SVC_NET(rqstp)) && lock->lk_reclaim) 4115 4114 goto out; 4116 4115 4117 4116 locks_init_lock(&file_lock); ··· 4211 4210 struct nfs4_lockowner *lo; 4212 4211 __be32 status; 4213 4212 4214 - if (locks_in_grace()) 4213 + if (locks_in_grace(SVC_NET(rqstp))) 4215 4214 return nfserr_grace; 4216 4215 4217 4216 if (check_lock_length(lockt->lt_offset, lockt->lt_length)) ··· 4704 4703 get_net(net); 4705 4704 nfsd4_client_tracking_init(net); 4706 4705 boot_time = get_seconds(); 4707 - locks_start_grace(&nn->nfsd4_manager); 4706 + locks_start_grace(net, &nn->nfsd4_manager); 4708 4707 grace_ended = false; 4709 4708 printk(KERN_INFO "NFSD: starting %ld-second grace period\n", 4710 4709 nfsd4_grace);
+2 -1
fs/nfsd/state.h
··· 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);
+3 -2
include/linux/fs.h
··· 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>
+2 -2
include/linux/lockd/lockd.h
··· 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);