]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.15/nfsd-move-fill_pre_wcc-and-fill_post_wcc.patch
6.6-stable patches
[thirdparty/kernel/stable-queue.git] / queue-5.15 / nfsd-move-fill_pre_wcc-and-fill_post_wcc.patch
1 From bbbee79d363a4cdd606e56b7f707784ab59cd959 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Fri, 24 Dec 2021 14:36:49 -0500
4 Subject: NFSD: Move fill_pre_wcc() and fill_post_wcc()
5
6 From: Chuck Lever <chuck.lever@oracle.com>
7
8 [ Upstream commit fcb5e3fa012351f3b96024c07bc44834c2478213 ]
9
10 These functions are related to file handle processing and have
11 nothing to do with XDR encoding or decoding. Also they are no longer
12 NFSv3-specific. As a clean-up, move their definitions to a more
13 appropriate location. WCC is also an NFSv3-specific term, so rename
14 them as general-purpose helpers.
15
16 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
17 ---
18 fs/nfsd/nfs3xdr.c | 55 --------------------------------------
19 fs/nfsd/nfs4proc.c | 2 +-
20 fs/nfsd/nfsfh.c | 66 +++++++++++++++++++++++++++++++++++++++++++++-
21 fs/nfsd/nfsfh.h | 40 ++++++++++++++++++----------
22 fs/nfsd/vfs.c | 8 +++---
23 5 files changed, 96 insertions(+), 75 deletions(-)
24
25 diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
26 index 48e8a02ebc83b..2e47a07029f1d 100644
27 --- a/fs/nfsd/nfs3xdr.c
28 +++ b/fs/nfsd/nfs3xdr.c
29 @@ -487,61 +487,6 @@ svcxdr_encode_wcc_data(struct svc_rqst *rqstp, struct xdr_stream *xdr,
30 return true;
31 }
32
33 -/*
34 - * Fill in the pre_op attr for the wcc data
35 - */
36 -void fill_pre_wcc(struct svc_fh *fhp)
37 -{
38 - struct inode *inode;
39 - struct kstat stat;
40 - bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
41 - __be32 err;
42 -
43 - if (fhp->fh_no_wcc || fhp->fh_pre_saved)
44 - return;
45 - inode = d_inode(fhp->fh_dentry);
46 - err = fh_getattr(fhp, &stat);
47 - if (err) {
48 - /* Grab the times from inode anyway */
49 - stat.mtime = inode->i_mtime;
50 - stat.ctime = inode->i_ctime;
51 - stat.size = inode->i_size;
52 - }
53 - if (v4)
54 - fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode);
55 -
56 - fhp->fh_pre_mtime = stat.mtime;
57 - fhp->fh_pre_ctime = stat.ctime;
58 - fhp->fh_pre_size = stat.size;
59 - fhp->fh_pre_saved = true;
60 -}
61 -
62 -/*
63 - * Fill in the post_op attr for the wcc data
64 - */
65 -void fill_post_wcc(struct svc_fh *fhp)
66 -{
67 - bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
68 - struct inode *inode = d_inode(fhp->fh_dentry);
69 - __be32 err;
70 -
71 - if (fhp->fh_no_wcc)
72 - return;
73 -
74 - if (fhp->fh_post_saved)
75 - printk("nfsd: inode locked twice during operation.\n");
76 -
77 - err = fh_getattr(fhp, &fhp->fh_post_attr);
78 - if (err) {
79 - fhp->fh_post_saved = false;
80 - fhp->fh_post_attr.ctime = inode->i_ctime;
81 - } else
82 - fhp->fh_post_saved = true;
83 - if (v4)
84 - fhp->fh_post_change =
85 - nfsd4_change_attribute(&fhp->fh_post_attr, inode);
86 -}
87 -
88 /*
89 * XDR decode functions
90 */
91 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
92 index a8ad7e6ace927..73c62561580a1 100644
93 --- a/fs/nfsd/nfs4proc.c
94 +++ b/fs/nfsd/nfs4proc.c
95 @@ -2536,7 +2536,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)
96 goto encode_op;
97 }
98
99 - fh_clear_wcc(current_fh);
100 + fh_clear_pre_post_attrs(current_fh);
101
102 /* If op is non-idempotent */
103 if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) {
104 diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
105 index f3779fa72c896..145208bcb9bd4 100644
106 --- a/fs/nfsd/nfsfh.c
107 +++ b/fs/nfsd/nfsfh.c
108 @@ -611,6 +611,70 @@ fh_update(struct svc_fh *fhp)
109 return nfserr_serverfault;
110 }
111
112 +#ifdef CONFIG_NFSD_V3
113 +
114 +/**
115 + * fh_fill_pre_attrs - Fill in pre-op attributes
116 + * @fhp: file handle to be updated
117 + *
118 + */
119 +void fh_fill_pre_attrs(struct svc_fh *fhp)
120 +{
121 + bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
122 + struct inode *inode;
123 + struct kstat stat;
124 + __be32 err;
125 +
126 + if (fhp->fh_no_wcc || fhp->fh_pre_saved)
127 + return;
128 +
129 + inode = d_inode(fhp->fh_dentry);
130 + err = fh_getattr(fhp, &stat);
131 + if (err) {
132 + /* Grab the times from inode anyway */
133 + stat.mtime = inode->i_mtime;
134 + stat.ctime = inode->i_ctime;
135 + stat.size = inode->i_size;
136 + }
137 + if (v4)
138 + fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode);
139 +
140 + fhp->fh_pre_mtime = stat.mtime;
141 + fhp->fh_pre_ctime = stat.ctime;
142 + fhp->fh_pre_size = stat.size;
143 + fhp->fh_pre_saved = true;
144 +}
145 +
146 +/**
147 + * fh_fill_post_attrs - Fill in post-op attributes
148 + * @fhp: file handle to be updated
149 + *
150 + */
151 +void fh_fill_post_attrs(struct svc_fh *fhp)
152 +{
153 + bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
154 + struct inode *inode = d_inode(fhp->fh_dentry);
155 + __be32 err;
156 +
157 + if (fhp->fh_no_wcc)
158 + return;
159 +
160 + if (fhp->fh_post_saved)
161 + printk("nfsd: inode locked twice during operation.\n");
162 +
163 + err = fh_getattr(fhp, &fhp->fh_post_attr);
164 + if (err) {
165 + fhp->fh_post_saved = false;
166 + fhp->fh_post_attr.ctime = inode->i_ctime;
167 + } else
168 + fhp->fh_post_saved = true;
169 + if (v4)
170 + fhp->fh_post_change =
171 + nfsd4_change_attribute(&fhp->fh_post_attr, inode);
172 +}
173 +
174 +#endif /* CONFIG_NFSD_V3 */
175 +
176 /*
177 * Release a file handle.
178 */
179 @@ -623,7 +687,7 @@ fh_put(struct svc_fh *fhp)
180 fh_unlock(fhp);
181 fhp->fh_dentry = NULL;
182 dput(dentry);
183 - fh_clear_wcc(fhp);
184 + fh_clear_pre_post_attrs(fhp);
185 }
186 fh_drop_write(fhp);
187 if (exp) {
188 diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h
189 index d11e4b6870d68..434930d8a946e 100644
190 --- a/fs/nfsd/nfsfh.h
191 +++ b/fs/nfsd/nfsfh.h
192 @@ -284,12 +284,13 @@ static inline u32 knfsd_fh_hash(const struct knfsd_fh *fh)
193 #endif
194
195 #ifdef CONFIG_NFSD_V3
196 -/*
197 - * The wcc data stored in current_fh should be cleared
198 - * between compound ops.
199 +
200 +/**
201 + * fh_clear_pre_post_attrs - Reset pre/post attributes
202 + * @fhp: file handle to be updated
203 + *
204 */
205 -static inline void
206 -fh_clear_wcc(struct svc_fh *fhp)
207 +static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp)
208 {
209 fhp->fh_post_saved = false;
210 fhp->fh_pre_saved = false;
211 @@ -323,13 +324,24 @@ static inline u64 nfsd4_change_attribute(struct kstat *stat,
212 return time_to_chattr(&stat->ctime);
213 }
214
215 -extern void fill_pre_wcc(struct svc_fh *fhp);
216 -extern void fill_post_wcc(struct svc_fh *fhp);
217 -#else
218 -#define fh_clear_wcc(ignored)
219 -#define fill_pre_wcc(ignored)
220 -#define fill_post_wcc(notused)
221 -#endif /* CONFIG_NFSD_V3 */
222 +extern void fh_fill_pre_attrs(struct svc_fh *fhp);
223 +extern void fh_fill_post_attrs(struct svc_fh *fhp);
224 +
225 +#else /* !CONFIG_NFSD_V3 */
226 +
227 +static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp)
228 +{
229 +}
230 +
231 +static inline void fh_fill_pre_attrs(struct svc_fh *fhp)
232 +{
233 +}
234 +
235 +static inline void fh_fill_post_attrs(struct svc_fh *fhp)
236 +{
237 +}
238 +
239 +#endif /* !CONFIG_NFSD_V3 */
240
241
242 /*
243 @@ -355,7 +367,7 @@ fh_lock_nested(struct svc_fh *fhp, unsigned int subclass)
244
245 inode = d_inode(dentry);
246 inode_lock_nested(inode, subclass);
247 - fill_pre_wcc(fhp);
248 + fh_fill_pre_attrs(fhp);
249 fhp->fh_locked = true;
250 }
251
252 @@ -372,7 +384,7 @@ static inline void
253 fh_unlock(struct svc_fh *fhp)
254 {
255 if (fhp->fh_locked) {
256 - fill_post_wcc(fhp);
257 + fh_fill_post_attrs(fhp);
258 inode_unlock(d_inode(fhp->fh_dentry));
259 fhp->fh_locked = false;
260 }
261 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
262 index 284dc900d10ba..4d07a506164b0 100644
263 --- a/fs/nfsd/vfs.c
264 +++ b/fs/nfsd/vfs.c
265 @@ -1793,8 +1793,8 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
266 * so do it by hand */
267 trap = lock_rename(tdentry, fdentry);
268 ffhp->fh_locked = tfhp->fh_locked = true;
269 - fill_pre_wcc(ffhp);
270 - fill_pre_wcc(tfhp);
271 + fh_fill_pre_attrs(ffhp);
272 + fh_fill_pre_attrs(tfhp);
273
274 odentry = lookup_one_len(fname, fdentry, flen);
275 host_err = PTR_ERR(odentry);
276 @@ -1848,8 +1848,8 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
277 * were the same, so again we do it by hand.
278 */
279 if (!close_cached) {
280 - fill_post_wcc(ffhp);
281 - fill_post_wcc(tfhp);
282 + fh_fill_post_attrs(ffhp);
283 + fh_fill_post_attrs(tfhp);
284 }
285 unlock_rename(tdentry, fdentry);
286 ffhp->fh_locked = tfhp->fh_locked = false;
287 --
288 2.43.0
289