Skip to content

Commit b34f27a

Browse files
author
J. Bruce Fields
committed
nfsd4: get lock checks out of preprocess_seqid_op
We've got some lock-specific code here in nfs4_preprocess_seqid_op which is only used by nfsd4_lock(). Move it to the caller. Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent 9afb978 commit b34f27a

1 file changed

Lines changed: 20 additions & 29 deletions

File tree

‎fs/nfsd/nfs4state.c‎

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,7 +3396,7 @@ static __be32
33963396
nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
33973397
stateid_t *stateid, int flags,
33983398
struct nfs4_stateowner **sopp,
3399-
struct nfs4_stateid **stpp, struct nfsd4_lock *lock)
3399+
struct nfs4_stateid **stpp)
34003400
{
34013401
struct nfs4_stateid *stp;
34023402
struct nfs4_stateowner *sop;
@@ -3439,27 +3439,6 @@ nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
34393439
*stpp = stp;
34403440
*sopp = sop = stp->st_stateowner;
34413441

3442-
if (lock) {
3443-
clientid_t *lockclid = &lock->v.new.clientid;
3444-
struct nfs4_client *clp = sop->so_client;
3445-
int lkflg = 0;
3446-
__be32 status;
3447-
3448-
lkflg = setlkflg(lock->lk_type);
3449-
3450-
if (lock->lk_is_new) {
3451-
if (!sop->so_is_open_owner)
3452-
return nfserr_bad_stateid;
3453-
if (!nfsd4_has_session(cstate) &&
3454-
!same_clid(&clp->cl_clientid, lockclid))
3455-
return nfserr_bad_stateid;
3456-
}
3457-
/* stp is the open stateid */
3458-
status = nfs4_check_openmode(stp, lkflg);
3459-
if (status)
3460-
return status;
3461-
}
3462-
34633442
if (nfs4_check_fh(current_fh, stp)) {
34643443
dprintk("NFSD: preprocess_seqid_op: fh-stateid mismatch!\n");
34653444
return nfserr_bad_stateid;
@@ -3522,7 +3501,7 @@ nfsd4_open_confirm(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
35223501
if ((status = nfs4_preprocess_seqid_op(cstate,
35233502
oc->oc_seqid, &oc->oc_req_stateid,
35243503
CONFIRM | OPEN_STATE,
3525-
&oc->oc_stateowner, &stp, NULL)))
3504+
&oc->oc_stateowner, &stp)))
35263505
goto out;
35273506

35283507
sop = oc->oc_stateowner;
@@ -3585,7 +3564,7 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
35853564
od->od_seqid,
35863565
&od->od_stateid,
35873566
OPEN_STATE,
3588-
&od->od_stateowner, &stp, NULL)))
3567+
&od->od_stateowner, &stp)))
35893568
goto out;
35903569

35913570
status = nfserr_inval;
@@ -3635,7 +3614,7 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
36353614
close->cl_seqid,
36363615
&close->cl_stateid,
36373616
OPEN_STATE | CLOSE_STATE,
3638-
&close->cl_stateowner, &stp, NULL)))
3617+
&close->cl_stateowner, &stp)))
36393618
goto out;
36403619
status = nfs_ok;
36413620
update_stateid(&stp->st_stateid);
@@ -3997,6 +3976,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
39973976
struct file_lock conflock;
39983977
__be32 status = 0;
39993978
unsigned int strhashval;
3979+
int lkflg;
40003980
int err;
40013981

40023982
dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
@@ -4032,11 +4012,17 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
40324012
lock->lk_new_open_seqid,
40334013
&lock->lk_new_open_stateid,
40344014
OPEN_STATE,
4035-
&lock->lk_replay_owner, &open_stp,
4036-
lock);
4015+
&lock->lk_replay_owner, &open_stp);
40374016
if (status)
40384017
goto out;
4018+
status = nfserr_bad_stateid;
40394019
open_sop = lock->lk_replay_owner;
4020+
if (!open_sop->so_is_open_owner)
4021+
goto out;
4022+
if (!nfsd4_has_session(cstate) &&
4023+
!same_clid(&open_sop->so_client->cl_clientid,
4024+
&lock->v.new.clientid))
4025+
goto out;
40404026
/* create lockowner and lock stateid */
40414027
fp = open_stp->st_file;
40424028
strhashval = lock_ownerstr_hashval(fp->fi_inode,
@@ -4059,14 +4045,19 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
40594045
lock->lk_old_lock_seqid,
40604046
&lock->lk_old_lock_stateid,
40614047
LOCK_STATE,
4062-
&lock->lk_replay_owner, &lock_stp, lock);
4048+
&lock->lk_replay_owner, &lock_stp);
40634049
if (status)
40644050
goto out;
40654051
lock_sop = lock->lk_replay_owner;
40664052
fp = lock_stp->st_file;
40674053
}
40684054
/* lock->lk_replay_owner and lock_stp have been created or found */
40694055

4056+
lkflg = setlkflg(lock->lk_type);
4057+
status = nfs4_check_openmode(lock_stp, lkflg);
4058+
if (status)
4059+
goto out;
4060+
40704061
status = nfserr_grace;
40714062
if (locks_in_grace() && !lock->lk_reclaim)
40724063
goto out;
@@ -4259,7 +4250,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
42594250
locku->lu_seqid,
42604251
&locku->lu_stateid,
42614252
LOCK_STATE,
4262-
&locku->lu_stateowner, &stp, NULL)))
4253+
&locku->lu_stateowner, &stp)))
42634254
goto out;
42644255

42654256
filp = find_any_file(stp->st_file);

0 commit comments

Comments
 (0)