]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.15/nfsd-use-un-lock_inode-instead-of-fh_-un-lock-for-fi.patch
Fixes for 5.15
[thirdparty/kernel/stable-queue.git] / queue-5.15 / nfsd-use-un-lock_inode-instead-of-fh_-un-lock-for-fi.patch
1 From d6f30a383c330905761aaadde5894efe6572ae29 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: use (un)lock_inode instead of fh_(un)lock for file operations
5
6 From: NeilBrown <neilb@suse.de>
7
8 [ Upstream commit bb4d53d66e4b8c8b8e5634802262e53851a2d2db ]
9
10 When locking a file to access ACLs and xattrs etc, use explicit locking
11 with inode_lock() instead of fh_lock(). This means that the calls to
12 fh_fill_pre/post_attr() are also explicit which improves readability and
13 allows us to place them only where they are needed. Only the xattr
14 calls need pre/post information.
15
16 When locking a file we don't need I_MUTEX_PARENT as the file is not a
17 parent of anything, so we can use inode_lock() directly rather than the
18 inode_lock_nested() call that fh_lock() uses.
19
20 Reviewed-by: Jeff Layton <jlayton@kernel.org>
21 Signed-off-by: NeilBrown <neilb@suse.de>
22 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
23 ---
24 fs/nfsd/nfs2acl.c | 6 +++---
25 fs/nfsd/nfs3acl.c | 4 ++--
26 fs/nfsd/nfs4state.c | 9 +++++----
27 fs/nfsd/vfs.c | 34 ++++++++++++++++++++--------------
28 4 files changed, 30 insertions(+), 23 deletions(-)
29
30 diff --git a/fs/nfsd/nfs2acl.c b/fs/nfsd/nfs2acl.c
31 index efcd429b0f28e..87f224cd30a85 100644
32 --- a/fs/nfsd/nfs2acl.c
33 +++ b/fs/nfsd/nfs2acl.c
34 @@ -111,7 +111,7 @@ static __be32 nfsacld_proc_setacl(struct svc_rqst *rqstp)
35 if (error)
36 goto out_errno;
37
38 - fh_lock(fh);
39 + inode_lock(inode);
40
41 error = set_posix_acl(&init_user_ns, inode, ACL_TYPE_ACCESS,
42 argp->acl_access);
43 @@ -122,7 +122,7 @@ static __be32 nfsacld_proc_setacl(struct svc_rqst *rqstp)
44 if (error)
45 goto out_drop_lock;
46
47 - fh_unlock(fh);
48 + inode_unlock(inode);
49
50 fh_drop_write(fh);
51
52 @@ -136,7 +136,7 @@ static __be32 nfsacld_proc_setacl(struct svc_rqst *rqstp)
53 return rpc_success;
54
55 out_drop_lock:
56 - fh_unlock(fh);
57 + inode_unlock(inode);
58 fh_drop_write(fh);
59 out_errno:
60 resp->status = nfserrno(error);
61 diff --git a/fs/nfsd/nfs3acl.c b/fs/nfsd/nfs3acl.c
62 index 35b2ebda14dac..9446c67436649 100644
63 --- a/fs/nfsd/nfs3acl.c
64 +++ b/fs/nfsd/nfs3acl.c
65 @@ -101,7 +101,7 @@ static __be32 nfsd3_proc_setacl(struct svc_rqst *rqstp)
66 if (error)
67 goto out_errno;
68
69 - fh_lock(fh);
70 + inode_lock(inode);
71
72 error = set_posix_acl(&init_user_ns, inode, ACL_TYPE_ACCESS,
73 argp->acl_access);
74 @@ -111,7 +111,7 @@ static __be32 nfsd3_proc_setacl(struct svc_rqst *rqstp)
75 argp->acl_default);
76
77 out_drop_lock:
78 - fh_unlock(fh);
79 + inode_unlock(inode);
80 fh_drop_write(fh);
81 out_errno:
82 resp->status = nfserrno(error);
83 diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
84 index f66fb39714893..66cf8217ebe57 100644
85 --- a/fs/nfsd/nfs4state.c
86 +++ b/fs/nfsd/nfs4state.c
87 @@ -7415,21 +7415,22 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
88 static __be32 nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file_lock *lock)
89 {
90 struct nfsd_file *nf;
91 + struct inode *inode;
92 __be32 err;
93
94 err = nfsd_file_acquire(rqstp, fhp, NFSD_MAY_READ, &nf);
95 if (err)
96 return err;
97 - fh_lock(fhp); /* to block new leases till after test_lock: */
98 - err = nfserrno(nfsd_open_break_lease(fhp->fh_dentry->d_inode,
99 - NFSD_MAY_READ));
100 + inode = fhp->fh_dentry->d_inode;
101 + inode_lock(inode); /* to block new leases till after test_lock: */
102 + err = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ));
103 if (err)
104 goto out;
105 lock->fl_file = nf->nf_file;
106 err = nfserrno(vfs_test_lock(nf->nf_file, lock));
107 lock->fl_file = NULL;
108 out:
109 - fh_unlock(fhp);
110 + inode_unlock(inode);
111 nfsd_file_put(nf);
112 return err;
113 }
114 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
115 index 7de76b37a9bc2..73a153be6a5ad 100644
116 --- a/fs/nfsd/vfs.c
117 +++ b/fs/nfsd/vfs.c
118 @@ -417,7 +417,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
119 return err;
120 }
121
122 - fh_lock(fhp);
123 + inode_lock(inode);
124 if (size_change) {
125 /*
126 * RFC5661, Section 18.30.4:
127 @@ -465,7 +465,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
128 attr->na_aclerr = set_posix_acl(&init_user_ns,
129 inode, ACL_TYPE_DEFAULT,
130 attr->na_dpacl);
131 - fh_unlock(fhp);
132 + inode_unlock(inode);
133 if (size_change)
134 put_write_access(inode);
135 out:
136 @@ -2156,13 +2156,16 @@ nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char **bufp,
137 return err;
138 }
139
140 -/*
141 - * Removexattr and setxattr need to call fh_lock to both lock the inode
142 - * and set the change attribute. Since the top-level vfs_removexattr
143 - * and vfs_setxattr calls already do their own inode_lock calls, call
144 - * the _locked variant. Pass in a NULL pointer for delegated_inode,
145 - * and let the client deal with NFS4ERR_DELAY (same as with e.g.
146 - * setattr and remove).
147 +/**
148 + * nfsd_removexattr - Remove an extended attribute
149 + * @rqstp: RPC transaction being executed
150 + * @fhp: NFS filehandle of object with xattr to remove
151 + * @name: name of xattr to remove (NUL-terminate)
152 + *
153 + * Pass in a NULL pointer for delegated_inode, and let the client deal
154 + * with NFS4ERR_DELAY (same as with e.g. setattr and remove).
155 + *
156 + * Returns nfs_ok on success, or an nfsstat in network byte order.
157 */
158 __be32
159 nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name)
160 @@ -2178,12 +2181,14 @@ nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name)
161 if (ret)
162 return nfserrno(ret);
163
164 - fh_lock(fhp);
165 + inode_lock(fhp->fh_dentry->d_inode);
166 + fh_fill_pre_attrs(fhp);
167
168 ret = __vfs_removexattr_locked(&init_user_ns, fhp->fh_dentry,
169 name, NULL);
170
171 - fh_unlock(fhp);
172 + fh_fill_post_attrs(fhp);
173 + inode_unlock(fhp->fh_dentry->d_inode);
174 fh_drop_write(fhp);
175
176 return nfsd_xattr_errno(ret);
177 @@ -2203,12 +2208,13 @@ nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,
178 ret = fh_want_write(fhp);
179 if (ret)
180 return nfserrno(ret);
181 - fh_lock(fhp);
182 + inode_lock(fhp->fh_dentry->d_inode);
183 + fh_fill_pre_attrs(fhp);
184
185 ret = __vfs_setxattr_locked(&init_user_ns, fhp->fh_dentry, name, buf,
186 len, flags, NULL);
187 -
188 - fh_unlock(fhp);
189 + fh_fill_post_attrs(fhp);
190 + inode_unlock(fhp->fh_dentry->d_inode);
191 fh_drop_write(fhp);
192
193 return nfsd_xattr_errno(ret);
194 --
195 2.43.0
196