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()
6 From: Chuck Lever <chuck.lever@oracle.com>
8 [ Upstream commit fcb5e3fa012351f3b96024c07bc44834c2478213 ]
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.
16 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
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(-)
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,
34 - * Fill in the pre_op attr for the wcc data
36 -void fill_pre_wcc(struct svc_fh *fhp)
38 - struct inode *inode;
40 - bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
43 - if (fhp->fh_no_wcc || fhp->fh_pre_saved)
45 - inode = d_inode(fhp->fh_dentry);
46 - err = fh_getattr(fhp, &stat);
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;
54 - fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode);
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;
63 - * Fill in the post_op attr for the wcc data
65 -void fill_post_wcc(struct svc_fh *fhp)
67 - bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
68 - struct inode *inode = d_inode(fhp->fh_dentry);
74 - if (fhp->fh_post_saved)
75 - printk("nfsd: inode locked twice during operation.\n");
77 - err = fh_getattr(fhp, &fhp->fh_post_attr);
79 - fhp->fh_post_saved = false;
80 - fhp->fh_post_attr.ctime = inode->i_ctime;
82 - fhp->fh_post_saved = true;
84 - fhp->fh_post_change =
85 - nfsd4_change_attribute(&fhp->fh_post_attr, inode);
89 * XDR decode functions
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)
99 - fh_clear_wcc(current_fh);
100 + fh_clear_pre_post_attrs(current_fh);
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;
112 +#ifdef CONFIG_NFSD_V3
115 + * fh_fill_pre_attrs - Fill in pre-op attributes
116 + * @fhp: file handle to be updated
119 +void fh_fill_pre_attrs(struct svc_fh *fhp)
121 + bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
122 + struct inode *inode;
126 + if (fhp->fh_no_wcc || fhp->fh_pre_saved)
129 + inode = d_inode(fhp->fh_dentry);
130 + err = fh_getattr(fhp, &stat);
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;
138 + fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode);
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;
147 + * fh_fill_post_attrs - Fill in post-op attributes
148 + * @fhp: file handle to be updated
151 +void fh_fill_post_attrs(struct svc_fh *fhp)
153 + bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
154 + struct inode *inode = d_inode(fhp->fh_dentry);
157 + if (fhp->fh_no_wcc)
160 + if (fhp->fh_post_saved)
161 + printk("nfsd: inode locked twice during operation.\n");
163 + err = fh_getattr(fhp, &fhp->fh_post_attr);
165 + fhp->fh_post_saved = false;
166 + fhp->fh_post_attr.ctime = inode->i_ctime;
168 + fhp->fh_post_saved = true;
170 + fhp->fh_post_change =
171 + nfsd4_change_attribute(&fhp->fh_post_attr, inode);
174 +#endif /* CONFIG_NFSD_V3 */
177 * Release a file handle.
179 @@ -623,7 +687,7 @@ fh_put(struct svc_fh *fhp)
181 fhp->fh_dentry = NULL;
184 + fh_clear_pre_post_attrs(fhp);
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)
195 #ifdef CONFIG_NFSD_V3
197 - * The wcc data stored in current_fh should be cleared
198 - * between compound ops.
201 + * fh_clear_pre_post_attrs - Reset pre/post attributes
202 + * @fhp: file handle to be updated
206 -fh_clear_wcc(struct svc_fh *fhp)
207 +static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp)
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);
215 -extern void fill_pre_wcc(struct svc_fh *fhp);
216 -extern void fill_post_wcc(struct svc_fh *fhp);
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);
225 +#else /* !CONFIG_NFSD_V3 */
227 +static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp)
231 +static inline void fh_fill_pre_attrs(struct svc_fh *fhp)
235 +static inline void fh_fill_post_attrs(struct svc_fh *fhp)
239 +#endif /* !CONFIG_NFSD_V3 */
243 @@ -355,7 +367,7 @@ fh_lock_nested(struct svc_fh *fhp, unsigned int subclass)
245 inode = d_inode(dentry);
246 inode_lock_nested(inode, subclass);
248 + fh_fill_pre_attrs(fhp);
249 fhp->fh_locked = true;
252 @@ -372,7 +384,7 @@ static inline void
253 fh_unlock(struct svc_fh *fhp)
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;
261 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
262 index 284dc900d10ba..4d07a506164b0 100644
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);
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.
280 - fill_post_wcc(ffhp);
281 - fill_post_wcc(tfhp);
282 + fh_fill_post_attrs(ffhp);
283 + fh_fill_post_attrs(tfhp);
285 unlock_rename(tdentry, fdentry);
286 ffhp->fh_locked = tfhp->fh_locked = false;