Skip to content

Commit 927bfc5

Browse files
neilbrownchucklever
authored andcommitted
NFSD: change nfsd_create()/nfsd_symlink() to unlock directory before returning.
nfsd_create() usually returns with the directory still locked. nfsd_symlink() usually returns with it unlocked. This is clumsy. Until recently nfsd_create() needed to keep the directory locked until ACLs and security label had been set. These are now set inside nfsd_create() (in nfsd_setattr()) so this need is gone. So change nfsd_create() and nfsd_symlink() to always unlock, and remove any fh_unlock() calls that follow calls to these functions. Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent c0cbe70 commit 927bfc5

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

fs/nfsd/nfs3proc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ nfsd3_proc_mkdir(struct svc_rqst *rqstp)
388388
fh_init(&resp->fh, NFS3_FHSIZE);
389389
resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
390390
&attrs, S_IFDIR, 0, &resp->fh);
391-
fh_unlock(&resp->dirfh);
392391
return rpc_success;
393392
}
394393

@@ -469,7 +468,6 @@ nfsd3_proc_mknod(struct svc_rqst *rqstp)
469468
type = nfs3_ftypes[argp->ftype];
470469
resp->status = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
471470
&attrs, type, rdev, &resp->fh);
472-
fh_unlock(&resp->dirfh);
473471
out:
474472
return rpc_success;
475473
}

fs/nfsd/nfs4proc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,6 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
823823
create->cr_bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
824824
if (attrs.na_aclerr)
825825
create->cr_bmval[0] &= ~FATTR4_WORD0_ACL;
826-
827-
fh_unlock(&cstate->current_fh);
828826
set_change_info(&create->cr_cinfo, &cstate->current_fh);
829827
fh_dup2(&cstate->current_fh, &resfh);
830828
out:

fs/nfsd/vfs.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,18 +1379,23 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
13791379
fh_lock_nested(fhp, I_MUTEX_PARENT);
13801380
dchild = lookup_one_len(fname, dentry, flen);
13811381
host_err = PTR_ERR(dchild);
1382-
if (IS_ERR(dchild))
1383-
return nfserrno(host_err);
1382+
if (IS_ERR(dchild)) {
1383+
err = nfserrno(host_err);
1384+
goto out_unlock;
1385+
}
13841386
err = fh_compose(resfhp, fhp->fh_export, dchild, fhp);
13851387
/*
13861388
* We unconditionally drop our ref to dchild as fh_compose will have
13871389
* already grabbed its own ref for it.
13881390
*/
13891391
dput(dchild);
13901392
if (err)
1391-
return err;
1392-
return nfsd_create_locked(rqstp, fhp, fname, flen, attrs, type,
1393-
rdev, resfhp);
1393+
goto out_unlock;
1394+
err = nfsd_create_locked(rqstp, fhp, fname, flen, attrs, type,
1395+
rdev, resfhp);
1396+
out_unlock:
1397+
fh_unlock(fhp);
1398+
return err;
13941399
}
13951400

13961401
/*
@@ -1467,16 +1472,19 @@ nfsd_symlink(struct svc_rqst *rqstp, struct svc_fh *fhp,
14671472
goto out;
14681473

14691474
host_err = fh_want_write(fhp);
1470-
if (host_err)
1471-
goto out_nfserr;
1475+
if (host_err) {
1476+
err = nfserrno(host_err);
1477+
goto out;
1478+
}
14721479

14731480
fh_lock(fhp);
14741481
dentry = fhp->fh_dentry;
14751482
dnew = lookup_one_len(fname, dentry, flen);
1476-
host_err = PTR_ERR(dnew);
1477-
if (IS_ERR(dnew))
1478-
goto out_nfserr;
1479-
1483+
if (IS_ERR(dnew)) {
1484+
err = nfserrno(PTR_ERR(dnew));
1485+
fh_unlock(fhp);
1486+
goto out_drop_write;
1487+
}
14801488
host_err = vfs_symlink(&init_user_ns, d_inode(dentry), dnew, path);
14811489
err = nfserrno(host_err);
14821490
cerr = fh_compose(resfhp, fhp->fh_export, dnew, fhp);
@@ -1485,16 +1493,12 @@ nfsd_symlink(struct svc_rqst *rqstp, struct svc_fh *fhp,
14851493
fh_unlock(fhp);
14861494
if (!err)
14871495
err = nfserrno(commit_metadata(fhp));
1488-
fh_drop_write(fhp);
1489-
14901496
dput(dnew);
14911497
if (err==0) err = cerr;
1498+
out_drop_write:
1499+
fh_drop_write(fhp);
14921500
out:
14931501
return err;
1494-
1495-
out_nfserr:
1496-
err = nfserrno(host_err);
1497-
goto out;
14981502
}
14991503

15001504
/*

0 commit comments

Comments
 (0)