]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.15/nfsd-only-call-fh_unlock-once-in-nfsd_link.patch
Fixes for 5.15
[thirdparty/kernel/stable-queue.git] / queue-5.15 / nfsd-only-call-fh_unlock-once-in-nfsd_link.patch
1 From 325495c4b028a5326191f2ee000299fdec104e2f Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Tue, 26 Jul 2022 16:45:30 +1000
4 Subject: NFSD: only call fh_unlock() once in nfsd_link()
5
6 From: NeilBrown <neilb@suse.de>
7
8 [ Upstream commit e18bcb33bc5b69bccc2b532075aa00bb49cc01c5 ]
9
10 On non-error paths, nfsd_link() calls fh_unlock() twice. This is safe
11 because fh_unlock() records that the unlock has been done and doesn't
12 repeat it.
13 However it makes the code a little confusing and interferes with changes
14 that are planned for directory locking.
15
16 So rearrange the code to ensure fh_unlock() is called exactly once if
17 fh_lock() was called.
18
19 Reviewed-by: Jeff Layton <jlayton@kernel.org>
20 Signed-off-by: NeilBrown <neilb@suse.de>
21 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
22 ---
23 fs/nfsd/vfs.c | 19 ++++++++++---------
24 1 file changed, 10 insertions(+), 9 deletions(-)
25
26 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
27 index 4b1304fe718fd..ac716ced1fd5f 100644
28 --- a/fs/nfsd/vfs.c
29 +++ b/fs/nfsd/vfs.c
30 @@ -1542,9 +1542,10 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
31 dirp = d_inode(ddir);
32
33 dnew = lookup_one_len(name, ddir, len);
34 - host_err = PTR_ERR(dnew);
35 - if (IS_ERR(dnew))
36 - goto out_nfserr;
37 + if (IS_ERR(dnew)) {
38 + err = nfserrno(PTR_ERR(dnew));
39 + goto out_unlock;
40 + }
41
42 dold = tfhp->fh_dentry;
43
44 @@ -1563,17 +1564,17 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
45 else
46 err = nfserrno(host_err);
47 }
48 -out_dput:
49 dput(dnew);
50 -out_unlock:
51 - fh_unlock(ffhp);
52 +out_drop_write:
53 fh_drop_write(tfhp);
54 out:
55 return err;
56
57 -out_nfserr:
58 - err = nfserrno(host_err);
59 - goto out_unlock;
60 +out_dput:
61 + dput(dnew);
62 +out_unlock:
63 + fh_unlock(ffhp);
64 + goto out_drop_write;
65 }
66
67 static void
68 --
69 2.43.0
70