Skip to content

Commit fcb5e3f

Browse files
committed
NFSD: Move fill_pre_wcc() and fill_post_wcc()
These functions are related to file handle processing and have nothing to do with XDR encoding or decoding. Also they are no longer NFSv3-specific. As a clean-up, move their definitions to a more appropriate location. WCC is also an NFSv3-specific term, so rename them as general-purpose helpers. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 58f258f commit fcb5e3f

5 files changed

Lines changed: 96 additions & 75 deletions

File tree

fs/nfsd/nfs3xdr.c

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -487,61 +487,6 @@ svcxdr_encode_wcc_data(struct svc_rqst *rqstp, struct xdr_stream *xdr,
487487
return true;
488488
}
489489

490-
/*
491-
* Fill in the pre_op attr for the wcc data
492-
*/
493-
void fill_pre_wcc(struct svc_fh *fhp)
494-
{
495-
struct inode *inode;
496-
struct kstat stat;
497-
bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
498-
__be32 err;
499-
500-
if (fhp->fh_no_wcc || fhp->fh_pre_saved)
501-
return;
502-
inode = d_inode(fhp->fh_dentry);
503-
err = fh_getattr(fhp, &stat);
504-
if (err) {
505-
/* Grab the times from inode anyway */
506-
stat.mtime = inode->i_mtime;
507-
stat.ctime = inode->i_ctime;
508-
stat.size = inode->i_size;
509-
}
510-
if (v4)
511-
fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode);
512-
513-
fhp->fh_pre_mtime = stat.mtime;
514-
fhp->fh_pre_ctime = stat.ctime;
515-
fhp->fh_pre_size = stat.size;
516-
fhp->fh_pre_saved = true;
517-
}
518-
519-
/*
520-
* Fill in the post_op attr for the wcc data
521-
*/
522-
void fill_post_wcc(struct svc_fh *fhp)
523-
{
524-
bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
525-
struct inode *inode = d_inode(fhp->fh_dentry);
526-
__be32 err;
527-
528-
if (fhp->fh_no_wcc)
529-
return;
530-
531-
if (fhp->fh_post_saved)
532-
printk("nfsd: inode locked twice during operation.\n");
533-
534-
err = fh_getattr(fhp, &fhp->fh_post_attr);
535-
if (err) {
536-
fhp->fh_post_saved = false;
537-
fhp->fh_post_attr.ctime = inode->i_ctime;
538-
} else
539-
fhp->fh_post_saved = true;
540-
if (v4)
541-
fhp->fh_post_change =
542-
nfsd4_change_attribute(&fhp->fh_post_attr, inode);
543-
}
544-
545490
/*
546491
* XDR decode functions
547492
*/

fs/nfsd/nfs4proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)
25302530
goto encode_op;
25312531
}
25322532

2533-
fh_clear_wcc(current_fh);
2533+
fh_clear_pre_post_attrs(current_fh);
25342534

25352535
/* If op is non-idempotent */
25362536
if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) {

fs/nfsd/nfsfh.c

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,70 @@ fh_update(struct svc_fh *fhp)
611611
return nfserr_serverfault;
612612
}
613613

614+
#ifdef CONFIG_NFSD_V3
615+
616+
/**
617+
* fh_fill_pre_attrs - Fill in pre-op attributes
618+
* @fhp: file handle to be updated
619+
*
620+
*/
621+
void fh_fill_pre_attrs(struct svc_fh *fhp)
622+
{
623+
bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
624+
struct inode *inode;
625+
struct kstat stat;
626+
__be32 err;
627+
628+
if (fhp->fh_no_wcc || fhp->fh_pre_saved)
629+
return;
630+
631+
inode = d_inode(fhp->fh_dentry);
632+
err = fh_getattr(fhp, &stat);
633+
if (err) {
634+
/* Grab the times from inode anyway */
635+
stat.mtime = inode->i_mtime;
636+
stat.ctime = inode->i_ctime;
637+
stat.size = inode->i_size;
638+
}
639+
if (v4)
640+
fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode);
641+
642+
fhp->fh_pre_mtime = stat.mtime;
643+
fhp->fh_pre_ctime = stat.ctime;
644+
fhp->fh_pre_size = stat.size;
645+
fhp->fh_pre_saved = true;
646+
}
647+
648+
/**
649+
* fh_fill_post_attrs - Fill in post-op attributes
650+
* @fhp: file handle to be updated
651+
*
652+
*/
653+
void fh_fill_post_attrs(struct svc_fh *fhp)
654+
{
655+
bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
656+
struct inode *inode = d_inode(fhp->fh_dentry);
657+
__be32 err;
658+
659+
if (fhp->fh_no_wcc)
660+
return;
661+
662+
if (fhp->fh_post_saved)
663+
printk("nfsd: inode locked twice during operation.\n");
664+
665+
err = fh_getattr(fhp, &fhp->fh_post_attr);
666+
if (err) {
667+
fhp->fh_post_saved = false;
668+
fhp->fh_post_attr.ctime = inode->i_ctime;
669+
} else
670+
fhp->fh_post_saved = true;
671+
if (v4)
672+
fhp->fh_post_change =
673+
nfsd4_change_attribute(&fhp->fh_post_attr, inode);
674+
}
675+
676+
#endif /* CONFIG_NFSD_V3 */
677+
614678
/*
615679
* Release a file handle.
616680
*/
@@ -623,7 +687,7 @@ fh_put(struct svc_fh *fhp)
623687
fh_unlock(fhp);
624688
fhp->fh_dentry = NULL;
625689
dput(dentry);
626-
fh_clear_wcc(fhp);
690+
fh_clear_pre_post_attrs(fhp);
627691
}
628692
fh_drop_write(fhp);
629693
if (exp) {

fs/nfsd/nfsfh.h

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,13 @@ static inline u32 knfsd_fh_hash(const struct knfsd_fh *fh)
284284
#endif
285285

286286
#ifdef CONFIG_NFSD_V3
287-
/*
288-
* The wcc data stored in current_fh should be cleared
289-
* between compound ops.
287+
288+
/**
289+
* fh_clear_pre_post_attrs - Reset pre/post attributes
290+
* @fhp: file handle to be updated
291+
*
290292
*/
291-
static inline void
292-
fh_clear_wcc(struct svc_fh *fhp)
293+
static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp)
293294
{
294295
fhp->fh_post_saved = false;
295296
fhp->fh_pre_saved = false;
@@ -323,13 +324,24 @@ static inline u64 nfsd4_change_attribute(struct kstat *stat,
323324
return time_to_chattr(&stat->ctime);
324325
}
325326

326-
extern void fill_pre_wcc(struct svc_fh *fhp);
327-
extern void fill_post_wcc(struct svc_fh *fhp);
328-
#else
329-
#define fh_clear_wcc(ignored)
330-
#define fill_pre_wcc(ignored)
331-
#define fill_post_wcc(notused)
332-
#endif /* CONFIG_NFSD_V3 */
327+
extern void fh_fill_pre_attrs(struct svc_fh *fhp);
328+
extern void fh_fill_post_attrs(struct svc_fh *fhp);
329+
330+
#else /* !CONFIG_NFSD_V3 */
331+
332+
static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp)
333+
{
334+
}
335+
336+
static inline void fh_fill_pre_attrs(struct svc_fh *fhp)
337+
{
338+
}
339+
340+
static inline void fh_fill_post_attrs(struct svc_fh *fhp)
341+
{
342+
}
343+
344+
#endif /* !CONFIG_NFSD_V3 */
333345

334346

335347
/*
@@ -355,7 +367,7 @@ fh_lock_nested(struct svc_fh *fhp, unsigned int subclass)
355367

356368
inode = d_inode(dentry);
357369
inode_lock_nested(inode, subclass);
358-
fill_pre_wcc(fhp);
370+
fh_fill_pre_attrs(fhp);
359371
fhp->fh_locked = true;
360372
}
361373

@@ -372,7 +384,7 @@ static inline void
372384
fh_unlock(struct svc_fh *fhp)
373385
{
374386
if (fhp->fh_locked) {
375-
fill_post_wcc(fhp);
387+
fh_fill_post_attrs(fhp);
376388
inode_unlock(d_inode(fhp->fh_dentry));
377389
fhp->fh_locked = false;
378390
}

fs/nfsd/vfs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,8 +1755,8 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
17551755
* so do it by hand */
17561756
trap = lock_rename(tdentry, fdentry);
17571757
ffhp->fh_locked = tfhp->fh_locked = true;
1758-
fill_pre_wcc(ffhp);
1759-
fill_pre_wcc(tfhp);
1758+
fh_fill_pre_attrs(ffhp);
1759+
fh_fill_pre_attrs(tfhp);
17601760

17611761
odentry = lookup_one_len(fname, fdentry, flen);
17621762
host_err = PTR_ERR(odentry);
@@ -1816,8 +1816,8 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
18161816
* were the same, so again we do it by hand.
18171817
*/
18181818
if (!close_cached) {
1819-
fill_post_wcc(ffhp);
1820-
fill_post_wcc(tfhp);
1819+
fh_fill_post_attrs(ffhp);
1820+
fh_fill_post_attrs(tfhp);
18211821
}
18221822
unlock_rename(tdentry, fdentry);
18231823
ffhp->fh_locked = tfhp->fh_locked = false;

0 commit comments

Comments
 (0)