aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsd/nfs4state.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfsd/nfs4state.c')
-rw-r--r--fs/nfsd/nfs4state.c201
1 files changed, 118 insertions, 83 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 94effd5bc4a1..cc894eda385a 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -38,18 +38,21 @@
38#include <linux/namei.h> 38#include <linux/namei.h>
39#include <linux/swap.h> 39#include <linux/swap.h>
40#include <linux/pagemap.h> 40#include <linux/pagemap.h>
41#include <linux/ratelimit.h>
41#include <linux/sunrpc/svcauth_gss.h> 42#include <linux/sunrpc/svcauth_gss.h>
42#include <linux/sunrpc/clnt.h> 43#include <linux/sunrpc/clnt.h>
43#include "xdr4.h" 44#include "xdr4.h"
44#include "vfs.h" 45#include "vfs.h"
45#include "current_stateid.h" 46#include "current_stateid.h"
47#include "fault_inject.h"
48
49#include "netns.h"
46 50
47#define NFSDDBG_FACILITY NFSDDBG_PROC 51#define NFSDDBG_FACILITY NFSDDBG_PROC
48 52
49/* Globals */ 53/* Globals */
50time_t nfsd4_lease = 90; /* default lease time */ 54time_t nfsd4_lease = 90; /* default lease time */
51time_t nfsd4_grace = 90; 55time_t nfsd4_grace = 90;
52static time_t boot_time;
53 56
54#define all_ones {{~0,~0},~0} 57#define all_ones {{~0,~0},~0}
55static const stateid_t one_stateid = { 58static const stateid_t one_stateid = {
@@ -862,6 +865,11 @@ static __be32 nfsd4_new_conn(struct svc_rqst *rqstp, struct nfsd4_session *ses,
862 if (ret) 865 if (ret)
863 /* oops; xprt is already down: */ 866 /* oops; xprt is already down: */
864 nfsd4_conn_lost(&conn->cn_xpt_user); 867 nfsd4_conn_lost(&conn->cn_xpt_user);
868 if (ses->se_client->cl_cb_state == NFSD4_CB_DOWN &&
869 dir & NFS4_CDFC4_BACK) {
870 /* callback channel may be back up */
871 nfsd4_probe_callback(ses->se_client);
872 }
865 return nfs_ok; 873 return nfs_ok;
866} 874}
867 875
@@ -1047,12 +1055,12 @@ renew_client(struct nfs4_client *clp)
1047 1055
1048/* SETCLIENTID and SETCLIENTID_CONFIRM Helper functions */ 1056/* SETCLIENTID and SETCLIENTID_CONFIRM Helper functions */
1049static int 1057static int
1050STALE_CLIENTID(clientid_t *clid) 1058STALE_CLIENTID(clientid_t *clid, struct nfsd_net *nn)
1051{ 1059{
1052 if (clid->cl_boot == boot_time) 1060 if (clid->cl_boot == nn->boot_time)
1053 return 0; 1061 return 0;
1054 dprintk("NFSD stale clientid (%08x/%08x) boot_time %08lx\n", 1062 dprintk("NFSD stale clientid (%08x/%08x) boot_time %08lx\n",
1055 clid->cl_boot, clid->cl_id, boot_time); 1063 clid->cl_boot, clid->cl_id, nn->boot_time);
1056 return 1; 1064 return 1;
1057} 1065}
1058 1066
@@ -1215,7 +1223,7 @@ static bool groups_equal(struct group_info *g1, struct group_info *g2)
1215 return true; 1223 return true;
1216} 1224}
1217 1225
1218static int 1226static bool
1219same_creds(struct svc_cred *cr1, struct svc_cred *cr2) 1227same_creds(struct svc_cred *cr1, struct svc_cred *cr2)
1220{ 1228{
1221 if ((cr1->cr_flavor != cr2->cr_flavor) 1229 if ((cr1->cr_flavor != cr2->cr_flavor)
@@ -1227,14 +1235,15 @@ same_creds(struct svc_cred *cr1, struct svc_cred *cr2)
1227 return true; 1235 return true;
1228 if (!cr1->cr_principal || !cr2->cr_principal) 1236 if (!cr1->cr_principal || !cr2->cr_principal)
1229 return false; 1237 return false;
1230 return 0 == strcmp(cr1->cr_principal, cr1->cr_principal); 1238 return 0 == strcmp(cr1->cr_principal, cr2->cr_principal);
1231} 1239}
1232 1240
1233static void gen_clid(struct nfs4_client *clp) 1241static void gen_clid(struct nfs4_client *clp)
1234{ 1242{
1235 static u32 current_clientid = 1; 1243 static u32 current_clientid = 1;
1244 struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
1236 1245
1237 clp->cl_clientid.cl_boot = boot_time; 1246 clp->cl_clientid.cl_boot = nn->boot_time;
1238 clp->cl_clientid.cl_id = current_clientid++; 1247 clp->cl_clientid.cl_id = current_clientid++;
1239} 1248}
1240 1249
@@ -2217,8 +2226,9 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
2217 nfs4_verifier confirm = setclientid_confirm->sc_confirm; 2226 nfs4_verifier confirm = setclientid_confirm->sc_confirm;
2218 clientid_t * clid = &setclientid_confirm->sc_clientid; 2227 clientid_t * clid = &setclientid_confirm->sc_clientid;
2219 __be32 status; 2228 __be32 status;
2229 struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
2220 2230
2221 if (STALE_CLIENTID(clid)) 2231 if (STALE_CLIENTID(clid, nn))
2222 return nfserr_stale_clientid; 2232 return nfserr_stale_clientid;
2223 nfs4_lock_state(); 2233 nfs4_lock_state();
2224 2234
@@ -2577,8 +2587,9 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate,
2577 unsigned int strhashval; 2587 unsigned int strhashval;
2578 struct nfs4_openowner *oo = NULL; 2588 struct nfs4_openowner *oo = NULL;
2579 __be32 status; 2589 __be32 status;
2590 struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
2580 2591
2581 if (STALE_CLIENTID(&open->op_clientid)) 2592 if (STALE_CLIENTID(&open->op_clientid, nn))
2582 return nfserr_stale_clientid; 2593 return nfserr_stale_clientid;
2583 /* 2594 /*
2584 * In case we need it later, after we've already created the 2595 * In case we need it later, after we've already created the
@@ -2876,7 +2887,8 @@ static void nfsd4_open_deleg_none_ext(struct nfsd4_open *open, int status)
2876 * Attempt to hand out a delegation. 2887 * Attempt to hand out a delegation.
2877 */ 2888 */
2878static void 2889static void
2879nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_ol_stateid *stp) 2890nfs4_open_delegation(struct net *net, struct svc_fh *fh,
2891 struct nfsd4_open *open, struct nfs4_ol_stateid *stp)
2880{ 2892{
2881 struct nfs4_delegation *dp; 2893 struct nfs4_delegation *dp;
2882 struct nfs4_openowner *oo = container_of(stp->st_stateowner, struct nfs4_openowner, oo_owner); 2894 struct nfs4_openowner *oo = container_of(stp->st_stateowner, struct nfs4_openowner, oo_owner);
@@ -2897,7 +2909,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_ol_
2897 case NFS4_OPEN_CLAIM_NULL: 2909 case NFS4_OPEN_CLAIM_NULL:
2898 /* Let's not give out any delegations till everyone's 2910 /* Let's not give out any delegations till everyone's
2899 * had the chance to reclaim theirs.... */ 2911 * had the chance to reclaim theirs.... */
2900 if (locks_in_grace()) 2912 if (locks_in_grace(net))
2901 goto out; 2913 goto out;
2902 if (!cb_up || !(oo->oo_flags & NFS4_OO_CONFIRMED)) 2914 if (!cb_up || !(oo->oo_flags & NFS4_OO_CONFIRMED))
2903 goto out; 2915 goto out;
@@ -3007,14 +3019,12 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
3007 status = nfs4_get_vfs_file(rqstp, fp, current_fh, open); 3019 status = nfs4_get_vfs_file(rqstp, fp, current_fh, open);
3008 if (status) 3020 if (status)
3009 goto out; 3021 goto out;
3022 status = nfsd4_truncate(rqstp, current_fh, open);
3023 if (status)
3024 goto out;
3010 stp = open->op_stp; 3025 stp = open->op_stp;
3011 open->op_stp = NULL; 3026 open->op_stp = NULL;
3012 init_open_stateid(stp, fp, open); 3027 init_open_stateid(stp, fp, open);
3013 status = nfsd4_truncate(rqstp, current_fh, open);
3014 if (status) {
3015 release_open_stateid(stp);
3016 goto out;
3017 }
3018 } 3028 }
3019 update_stateid(&stp->st_stid.sc_stateid); 3029 update_stateid(&stp->st_stid.sc_stateid);
3020 memcpy(&open->op_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t)); 3030 memcpy(&open->op_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t));
@@ -3033,7 +3043,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
3033 * Attempt to hand out a delegation. No error return, because the 3043 * Attempt to hand out a delegation. No error return, because the
3034 * OPEN succeeds even if we fail. 3044 * OPEN succeeds even if we fail.
3035 */ 3045 */
3036 nfs4_open_delegation(current_fh, open, stp); 3046 nfs4_open_delegation(SVC_NET(rqstp), current_fh, open, stp);
3037nodeleg: 3047nodeleg:
3038 status = nfs_ok; 3048 status = nfs_ok;
3039 3049
@@ -3087,12 +3097,13 @@ nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
3087{ 3097{
3088 struct nfs4_client *clp; 3098 struct nfs4_client *clp;
3089 __be32 status; 3099 __be32 status;
3100 struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
3090 3101
3091 nfs4_lock_state(); 3102 nfs4_lock_state();
3092 dprintk("process_renew(%08x/%08x): starting\n", 3103 dprintk("process_renew(%08x/%08x): starting\n",
3093 clid->cl_boot, clid->cl_id); 3104 clid->cl_boot, clid->cl_id);
3094 status = nfserr_stale_clientid; 3105 status = nfserr_stale_clientid;
3095 if (STALE_CLIENTID(clid)) 3106 if (STALE_CLIENTID(clid, nn))
3096 goto out; 3107 goto out;
3097 clp = find_confirmed_client(clid); 3108 clp = find_confirmed_client(clid);
3098 status = nfserr_expired; 3109 status = nfserr_expired;
@@ -3111,22 +3122,19 @@ out:
3111 return status; 3122 return status;
3112} 3123}
3113 3124
3114static struct lock_manager nfsd4_manager = {
3115};
3116
3117static bool grace_ended;
3118
3119static void 3125static void
3120nfsd4_end_grace(void) 3126nfsd4_end_grace(struct net *net)
3121{ 3127{
3128 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
3129
3122 /* do nothing if grace period already ended */ 3130 /* do nothing if grace period already ended */
3123 if (grace_ended) 3131 if (nn->grace_ended)
3124 return; 3132 return;
3125 3133
3126 dprintk("NFSD: end of grace period\n"); 3134 dprintk("NFSD: end of grace period\n");
3127 grace_ended = true; 3135 nn->grace_ended = true;
3128 nfsd4_record_grace_done(&init_net, boot_time); 3136 nfsd4_record_grace_done(net, nn->boot_time);
3129 locks_end_grace(&nfsd4_manager); 3137 locks_end_grace(&nn->nfsd4_manager);
3130 /* 3138 /*
3131 * Now that every NFSv4 client has had the chance to recover and 3139 * Now that every NFSv4 client has had the chance to recover and
3132 * to see the (possibly new, possibly shorter) lease time, we 3140 * to see the (possibly new, possibly shorter) lease time, we
@@ -3149,7 +3157,7 @@ nfs4_laundromat(void)
3149 nfs4_lock_state(); 3157 nfs4_lock_state();
3150 3158
3151 dprintk("NFSD: laundromat service - starting\n"); 3159 dprintk("NFSD: laundromat service - starting\n");
3152 nfsd4_end_grace(); 3160 nfsd4_end_grace(&init_net);
3153 INIT_LIST_HEAD(&reaplist); 3161 INIT_LIST_HEAD(&reaplist);
3154 spin_lock(&client_lock); 3162 spin_lock(&client_lock);
3155 list_for_each_safe(pos, next, &client_lru) { 3163 list_for_each_safe(pos, next, &client_lru) {
@@ -3231,9 +3239,9 @@ static inline __be32 nfs4_check_fh(struct svc_fh *fhp, struct nfs4_ol_stateid *s
3231} 3239}
3232 3240
3233static int 3241static int
3234STALE_STATEID(stateid_t *stateid) 3242STALE_STATEID(stateid_t *stateid, struct nfsd_net *nn)
3235{ 3243{
3236 if (stateid->si_opaque.so_clid.cl_boot == boot_time) 3244 if (stateid->si_opaque.so_clid.cl_boot == nn->boot_time)
3237 return 0; 3245 return 0;
3238 dprintk("NFSD: stale stateid " STATEID_FMT "!\n", 3246 dprintk("NFSD: stale stateid " STATEID_FMT "!\n",
3239 STATEID_VAL(stateid)); 3247 STATEID_VAL(stateid));
@@ -3273,11 +3281,11 @@ out:
3273} 3281}
3274 3282
3275static inline __be32 3283static inline __be32
3276check_special_stateids(svc_fh *current_fh, stateid_t *stateid, int flags) 3284check_special_stateids(struct net *net, svc_fh *current_fh, stateid_t *stateid, int flags)
3277{ 3285{
3278 if (ONE_STATEID(stateid) && (flags & RD_STATE)) 3286 if (ONE_STATEID(stateid) && (flags & RD_STATE))
3279 return nfs_ok; 3287 return nfs_ok;
3280 else if (locks_in_grace()) { 3288 else if (locks_in_grace(net)) {
3281 /* Answer in remaining cases depends on existence of 3289 /* Answer in remaining cases depends on existence of
3282 * conflicting state; so we must wait out the grace period. */ 3290 * conflicting state; so we must wait out the grace period. */
3283 return nfserr_grace; 3291 return nfserr_grace;
@@ -3294,9 +3302,9 @@ check_special_stateids(svc_fh *current_fh, stateid_t *stateid, int flags)
3294 * that are not able to provide mandatory locking. 3302 * that are not able to provide mandatory locking.
3295 */ 3303 */
3296static inline int 3304static inline int
3297grace_disallows_io(struct inode *inode) 3305grace_disallows_io(struct net *net, struct inode *inode)
3298{ 3306{
3299 return locks_in_grace() && mandatory_lock(inode); 3307 return locks_in_grace(net) && mandatory_lock(inode);
3300} 3308}
3301 3309
3302/* Returns true iff a is later than b: */ 3310/* Returns true iff a is later than b: */
@@ -3333,18 +3341,26 @@ static __be32 check_stateid_generation(stateid_t *in, stateid_t *ref, bool has_s
3333 return nfserr_old_stateid; 3341 return nfserr_old_stateid;
3334} 3342}
3335 3343
3336__be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) 3344static __be32 nfsd4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid)
3337{ 3345{
3338 struct nfs4_stid *s; 3346 struct nfs4_stid *s;
3339 struct nfs4_ol_stateid *ols; 3347 struct nfs4_ol_stateid *ols;
3340 __be32 status; 3348 __be32 status;
3341 3349
3342 if (STALE_STATEID(stateid)) 3350 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
3343 return nfserr_stale_stateid; 3351 return nfserr_bad_stateid;
3344 3352 /* Client debugging aid. */
3353 if (!same_clid(&stateid->si_opaque.so_clid, &cl->cl_clientid)) {
3354 char addr_str[INET6_ADDRSTRLEN];
3355 rpc_ntop((struct sockaddr *)&cl->cl_addr, addr_str,
3356 sizeof(addr_str));
3357 pr_warn_ratelimited("NFSD: client %s testing state ID "
3358 "with incorrect client ID\n", addr_str);
3359 return nfserr_bad_stateid;
3360 }
3345 s = find_stateid(cl, stateid); 3361 s = find_stateid(cl, stateid);
3346 if (!s) 3362 if (!s)
3347 return nfserr_stale_stateid; 3363 return nfserr_bad_stateid;
3348 status = check_stateid_generation(stateid, &s->sc_stateid, 1); 3364 status = check_stateid_generation(stateid, &s->sc_stateid, 1);
3349 if (status) 3365 if (status)
3350 return status; 3366 return status;
@@ -3360,10 +3376,11 @@ __be32 nfs4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid)
3360static __be32 nfsd4_lookup_stateid(stateid_t *stateid, unsigned char typemask, struct nfs4_stid **s) 3376static __be32 nfsd4_lookup_stateid(stateid_t *stateid, unsigned char typemask, struct nfs4_stid **s)
3361{ 3377{
3362 struct nfs4_client *cl; 3378 struct nfs4_client *cl;
3379 struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
3363 3380
3364 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid)) 3381 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
3365 return nfserr_bad_stateid; 3382 return nfserr_bad_stateid;
3366 if (STALE_STATEID(stateid)) 3383 if (STALE_STATEID(stateid, nn))
3367 return nfserr_stale_stateid; 3384 return nfserr_stale_stateid;
3368 cl = find_confirmed_client(&stateid->si_opaque.so_clid); 3385 cl = find_confirmed_client(&stateid->si_opaque.so_clid);
3369 if (!cl) 3386 if (!cl)
@@ -3379,7 +3396,7 @@ static __be32 nfsd4_lookup_stateid(stateid_t *stateid, unsigned char typemask, s
3379* Checks for stateid operations 3396* Checks for stateid operations
3380*/ 3397*/
3381__be32 3398__be32
3382nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate, 3399nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
3383 stateid_t *stateid, int flags, struct file **filpp) 3400 stateid_t *stateid, int flags, struct file **filpp)
3384{ 3401{
3385 struct nfs4_stid *s; 3402 struct nfs4_stid *s;
@@ -3392,11 +3409,11 @@ nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
3392 if (filpp) 3409 if (filpp)
3393 *filpp = NULL; 3410 *filpp = NULL;
3394 3411
3395 if (grace_disallows_io(ino)) 3412 if (grace_disallows_io(net, ino))
3396 return nfserr_grace; 3413 return nfserr_grace;
3397 3414
3398 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid)) 3415 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
3399 return check_special_stateids(current_fh, stateid, flags); 3416 return check_special_stateids(net, current_fh, stateid, flags);
3400 3417
3401 status = nfsd4_lookup_stateid(stateid, NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID, &s); 3418 status = nfsd4_lookup_stateid(stateid, NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID, &s);
3402 if (status) 3419 if (status)
@@ -3463,7 +3480,8 @@ nfsd4_test_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
3463 3480
3464 nfs4_lock_state(); 3481 nfs4_lock_state();
3465 list_for_each_entry(stateid, &test_stateid->ts_stateid_list, ts_id_list) 3482 list_for_each_entry(stateid, &test_stateid->ts_stateid_list, ts_id_list)
3466 stateid->ts_id_status = nfs4_validate_stateid(cl, &stateid->ts_id_stateid); 3483 stateid->ts_id_status =
3484 nfsd4_validate_stateid(cl, &stateid->ts_id_stateid);
3467 nfs4_unlock_state(); 3485 nfs4_unlock_state();
3468 3486
3469 return nfs_ok; 3487 return nfs_ok;
@@ -3750,12 +3768,19 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
3750 nfsd4_close_open_stateid(stp); 3768 nfsd4_close_open_stateid(stp);
3751 oo->oo_last_closed_stid = stp; 3769 oo->oo_last_closed_stid = stp;
3752 3770
3753 /* place unused nfs4_stateowners on so_close_lru list to be 3771 if (list_empty(&oo->oo_owner.so_stateids)) {
3754 * released by the laundromat service after the lease period 3772 if (cstate->minorversion) {
3755 * to enable us to handle CLOSE replay 3773 release_openowner(oo);
3756 */ 3774 cstate->replay_owner = NULL;
3757 if (list_empty(&oo->oo_owner.so_stateids)) 3775 } else {
3758 move_to_close_lru(oo); 3776 /*
3777 * In the 4.0 case we need to keep the owners around a
3778 * little while to handle CLOSE replay.
3779 */
3780 if (list_empty(&oo->oo_owner.so_stateids))
3781 move_to_close_lru(oo);
3782 }
3783 }
3759out: 3784out:
3760 if (!cstate->replay_owner) 3785 if (!cstate->replay_owner)
3761 nfs4_unlock_state(); 3786 nfs4_unlock_state();
@@ -4027,6 +4052,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4027 bool new_state = false; 4052 bool new_state = false;
4028 int lkflg; 4053 int lkflg;
4029 int err; 4054 int err;
4055 struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
4030 4056
4031 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n", 4057 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
4032 (long long) lock->lk_offset, 4058 (long long) lock->lk_offset,
@@ -4044,11 +4070,6 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4044 nfs4_lock_state(); 4070 nfs4_lock_state();
4045 4071
4046 if (lock->lk_is_new) { 4072 if (lock->lk_is_new) {
4047 /*
4048 * Client indicates that this is a new lockowner.
4049 * Use open owner and open stateid to create lock owner and
4050 * lock stateid.
4051 */
4052 struct nfs4_ol_stateid *open_stp = NULL; 4073 struct nfs4_ol_stateid *open_stp = NULL;
4053 4074
4054 if (nfsd4_has_session(cstate)) 4075 if (nfsd4_has_session(cstate))
@@ -4058,7 +4079,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4058 sizeof(clientid_t)); 4079 sizeof(clientid_t));
4059 4080
4060 status = nfserr_stale_clientid; 4081 status = nfserr_stale_clientid;
4061 if (STALE_CLIENTID(&lock->lk_new_clientid)) 4082 if (STALE_CLIENTID(&lock->lk_new_clientid, nn))
4062 goto out; 4083 goto out;
4063 4084
4064 /* validate and update open stateid and open seqid */ 4085 /* validate and update open stateid and open seqid */
@@ -4075,17 +4096,13 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4075 goto out; 4096 goto out;
4076 status = lookup_or_create_lock_state(cstate, open_stp, lock, 4097 status = lookup_or_create_lock_state(cstate, open_stp, lock,
4077 &lock_stp, &new_state); 4098 &lock_stp, &new_state);
4078 if (status) 4099 } else
4079 goto out;
4080 } else {
4081 /* lock (lock owner + lock stateid) already exists */
4082 status = nfs4_preprocess_seqid_op(cstate, 4100 status = nfs4_preprocess_seqid_op(cstate,
4083 lock->lk_old_lock_seqid, 4101 lock->lk_old_lock_seqid,
4084 &lock->lk_old_lock_stateid, 4102 &lock->lk_old_lock_stateid,
4085 NFS4_LOCK_STID, &lock_stp); 4103 NFS4_LOCK_STID, &lock_stp);
4086 if (status) 4104 if (status)
4087 goto out; 4105 goto out;
4088 }
4089 lock_sop = lockowner(lock_stp->st_stateowner); 4106 lock_sop = lockowner(lock_stp->st_stateowner);
4090 4107
4091 lkflg = setlkflg(lock->lk_type); 4108 lkflg = setlkflg(lock->lk_type);
@@ -4094,10 +4111,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4094 goto out; 4111 goto out;
4095 4112
4096 status = nfserr_grace; 4113 status = nfserr_grace;
4097 if (locks_in_grace() && !lock->lk_reclaim) 4114 if (locks_in_grace(SVC_NET(rqstp)) && !lock->lk_reclaim)
4098 goto out; 4115 goto out;
4099 status = nfserr_no_grace; 4116 status = nfserr_no_grace;
4100 if (!locks_in_grace() && lock->lk_reclaim) 4117 if (!locks_in_grace(SVC_NET(rqstp)) && lock->lk_reclaim)
4101 goto out; 4118 goto out;
4102 4119
4103 locks_init_lock(&file_lock); 4120 locks_init_lock(&file_lock);
@@ -4196,8 +4213,9 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4196 struct file_lock file_lock; 4213 struct file_lock file_lock;
4197 struct nfs4_lockowner *lo; 4214 struct nfs4_lockowner *lo;
4198 __be32 status; 4215 __be32 status;
4216 struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
4199 4217
4200 if (locks_in_grace()) 4218 if (locks_in_grace(SVC_NET(rqstp)))
4201 return nfserr_grace; 4219 return nfserr_grace;
4202 4220
4203 if (check_lock_length(lockt->lt_offset, lockt->lt_length)) 4221 if (check_lock_length(lockt->lt_offset, lockt->lt_length))
@@ -4206,7 +4224,7 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4206 nfs4_lock_state(); 4224 nfs4_lock_state();
4207 4225
4208 status = nfserr_stale_clientid; 4226 status = nfserr_stale_clientid;
4209 if (!nfsd4_has_session(cstate) && STALE_CLIENTID(&lockt->lt_clientid)) 4227 if (!nfsd4_has_session(cstate) && STALE_CLIENTID(&lockt->lt_clientid, nn))
4210 goto out; 4228 goto out;
4211 4229
4212 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) 4230 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0)))
@@ -4355,6 +4373,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
4355 struct list_head matches; 4373 struct list_head matches;
4356 unsigned int hashval = ownerstr_hashval(clid->cl_id, owner); 4374 unsigned int hashval = ownerstr_hashval(clid->cl_id, owner);
4357 __be32 status; 4375 __be32 status;
4376 struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
4358 4377
4359 dprintk("nfsd4_release_lockowner clientid: (%08x/%08x):\n", 4378 dprintk("nfsd4_release_lockowner clientid: (%08x/%08x):\n",
4360 clid->cl_boot, clid->cl_id); 4379 clid->cl_boot, clid->cl_id);
@@ -4362,7 +4381,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
4362 /* XXX check for lease expiration */ 4381 /* XXX check for lease expiration */
4363 4382
4364 status = nfserr_stale_clientid; 4383 status = nfserr_stale_clientid;
4365 if (STALE_CLIENTID(clid)) 4384 if (STALE_CLIENTID(clid, nn))
4366 return status; 4385 return status;
4367 4386
4368 nfs4_lock_state(); 4387 nfs4_lock_state();
@@ -4564,7 +4583,7 @@ void nfsd_forget_openowners(u64 num)
4564 printk(KERN_INFO "NFSD: Forgot %d open owners", count); 4583 printk(KERN_INFO "NFSD: Forgot %d open owners", count);
4565} 4584}
4566 4585
4567int nfsd_process_n_delegations(u64 num, void (*deleg_func)(struct nfs4_delegation *)) 4586int nfsd_process_n_delegations(u64 num, struct list_head *list)
4568{ 4587{
4569 int i, count = 0; 4588 int i, count = 0;
4570 struct nfs4_file *fp, *fnext; 4589 struct nfs4_file *fp, *fnext;
@@ -4573,7 +4592,7 @@ int nfsd_process_n_delegations(u64 num, void (*deleg_func)(struct nfs4_delegatio
4573 for (i = 0; i < FILE_HASH_SIZE; i++) { 4592 for (i = 0; i < FILE_HASH_SIZE; i++) {
4574 list_for_each_entry_safe(fp, fnext, &file_hashtbl[i], fi_hash) { 4593 list_for_each_entry_safe(fp, fnext, &file_hashtbl[i], fi_hash) {
4575 list_for_each_entry_safe(dp, dnext, &fp->fi_delegations, dl_perfile) { 4594 list_for_each_entry_safe(dp, dnext, &fp->fi_delegations, dl_perfile) {
4576 deleg_func(dp); 4595 list_move(&dp->dl_recall_lru, list);
4577 if (++count == num) 4596 if (++count == num)
4578 return count; 4597 return count;
4579 } 4598 }
@@ -4586,9 +4605,16 @@ int nfsd_process_n_delegations(u64 num, void (*deleg_func)(struct nfs4_delegatio
4586void nfsd_forget_delegations(u64 num) 4605void nfsd_forget_delegations(u64 num)
4587{ 4606{
4588 unsigned int count; 4607 unsigned int count;
4608 LIST_HEAD(victims);
4609 struct nfs4_delegation *dp, *dnext;
4610
4611 spin_lock(&recall_lock);
4612 count = nfsd_process_n_delegations(num, &victims);
4613 spin_unlock(&recall_lock);
4589 4614
4590 nfs4_lock_state(); 4615 nfs4_lock_state();
4591 count = nfsd_process_n_delegations(num, unhash_delegation); 4616 list_for_each_entry_safe(dp, dnext, &victims, dl_recall_lru)
4617 unhash_delegation(dp);
4592 nfs4_unlock_state(); 4618 nfs4_unlock_state();
4593 4619
4594 printk(KERN_INFO "NFSD: Forgot %d delegations", count); 4620 printk(KERN_INFO "NFSD: Forgot %d delegations", count);
@@ -4597,12 +4623,16 @@ void nfsd_forget_delegations(u64 num)
4597void nfsd_recall_delegations(u64 num) 4623void nfsd_recall_delegations(u64 num)
4598{ 4624{
4599 unsigned int count; 4625 unsigned int count;
4626 LIST_HEAD(victims);
4627 struct nfs4_delegation *dp, *dnext;
4600 4628
4601 nfs4_lock_state();
4602 spin_lock(&recall_lock); 4629 spin_lock(&recall_lock);
4603 count = nfsd_process_n_delegations(num, nfsd_break_one_deleg); 4630 count = nfsd_process_n_delegations(num, &victims);
4631 list_for_each_entry_safe(dp, dnext, &victims, dl_recall_lru) {
4632 list_del(&dp->dl_recall_lru);
4633 nfsd_break_one_deleg(dp);
4634 }
4604 spin_unlock(&recall_lock); 4635 spin_unlock(&recall_lock);
4605 nfs4_unlock_state();
4606 4636
4607 printk(KERN_INFO "NFSD: Recalled %d delegations", count); 4637 printk(KERN_INFO "NFSD: Recalled %d delegations", count);
4608} 4638}
@@ -4665,6 +4695,8 @@ set_max_delegations(void)
4665int 4695int
4666nfs4_state_start(void) 4696nfs4_state_start(void)
4667{ 4697{
4698 struct net *net = &init_net;
4699 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
4668 int ret; 4700 int ret;
4669 4701
4670 /* 4702 /*
@@ -4674,11 +4706,11 @@ nfs4_state_start(void)
4674 * to that instead and then do most of the rest of this on a per-net 4706 * to that instead and then do most of the rest of this on a per-net
4675 * basis. 4707 * basis.
4676 */ 4708 */
4677 get_net(&init_net); 4709 get_net(net);
4678 nfsd4_client_tracking_init(&init_net); 4710 nfsd4_client_tracking_init(net);
4679 boot_time = get_seconds(); 4711 nn->boot_time = get_seconds();
4680 locks_start_grace(&nfsd4_manager); 4712 locks_start_grace(net, &nn->nfsd4_manager);
4681 grace_ended = false; 4713 nn->grace_ended = false;
4682 printk(KERN_INFO "NFSD: starting %ld-second grace period\n", 4714 printk(KERN_INFO "NFSD: starting %ld-second grace period\n",
4683 nfsd4_grace); 4715 nfsd4_grace);
4684 ret = set_callback_cred(); 4716 ret = set_callback_cred();
@@ -4700,8 +4732,8 @@ nfs4_state_start(void)
4700out_free_laundry: 4732out_free_laundry:
4701 destroy_workqueue(laundry_wq); 4733 destroy_workqueue(laundry_wq);
4702out_recovery: 4734out_recovery:
4703 nfsd4_client_tracking_exit(&init_net); 4735 nfsd4_client_tracking_exit(net);
4704 put_net(&init_net); 4736 put_net(net);
4705 return ret; 4737 return ret;
4706} 4738}
4707 4739
@@ -4742,9 +4774,12 @@ __nfs4_state_shutdown(void)
4742void 4774void
4743nfs4_state_shutdown(void) 4775nfs4_state_shutdown(void)
4744{ 4776{
4777 struct net *net = &init_net;
4778 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
4779
4745 cancel_delayed_work_sync(&laundromat_work); 4780 cancel_delayed_work_sync(&laundromat_work);
4746 destroy_workqueue(laundry_wq); 4781 destroy_workqueue(laundry_wq);
4747 locks_end_grace(&nfsd4_manager); 4782 locks_end_grace(&nn->nfsd4_manager);
4748 nfs4_lock_state(); 4783 nfs4_lock_state();
4749 __nfs4_state_shutdown(); 4784 __nfs4_state_shutdown();
4750 nfs4_unlock_state(); 4785 nfs4_unlock_state();