@@ -2541,6 +2541,20 @@ static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode,
25412541 return p ;
25422542}
25432543
2544+ static __be32 nfsd4_encode_nfstime4 (struct xdr_stream * xdr ,
2545+ struct timespec64 * tv )
2546+ {
2547+ __be32 * p ;
2548+
2549+ p = xdr_reserve_space (xdr , XDR_UNIT * 3 );
2550+ if (!p )
2551+ return nfserr_resource ;
2552+
2553+ p = xdr_encode_hyper (p , (s64 )tv -> tv_sec );
2554+ * p = cpu_to_be32 (tv -> tv_nsec );
2555+ return nfs_ok ;
2556+ }
2557+
25442558/*
25452559 * ctime (in NFSv4, time_metadata) is not writeable, and the client
25462560 * doesn't really care what resolution could theoretically be stored by
@@ -3352,11 +3366,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
33523366 p = xdr_encode_hyper (p , dummy64 );
33533367 }
33543368 if (bmval1 & FATTR4_WORD1_TIME_ACCESS ) {
3355- p = xdr_reserve_space (xdr , 12 );
3356- if (!p )
3357- goto out_resource ;
3358- p = xdr_encode_hyper (p , (s64 )stat .atime .tv_sec );
3359- * p ++ = cpu_to_be32 (stat .atime .tv_nsec );
3369+ status = nfsd4_encode_nfstime4 (xdr , & stat .atime );
3370+ if (status )
3371+ goto out ;
33603372 }
33613373 if (bmval1 & FATTR4_WORD1_TIME_DELTA ) {
33623374 p = xdr_reserve_space (xdr , 12 );
@@ -3365,25 +3377,19 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
33653377 p = encode_time_delta (p , d_inode (dentry ));
33663378 }
33673379 if (bmval1 & FATTR4_WORD1_TIME_METADATA ) {
3368- p = xdr_reserve_space (xdr , 12 );
3369- if (!p )
3370- goto out_resource ;
3371- p = xdr_encode_hyper (p , (s64 )stat .ctime .tv_sec );
3372- * p ++ = cpu_to_be32 (stat .ctime .tv_nsec );
3380+ status = nfsd4_encode_nfstime4 (xdr , & stat .ctime );
3381+ if (status )
3382+ goto out ;
33733383 }
33743384 if (bmval1 & FATTR4_WORD1_TIME_MODIFY ) {
3375- p = xdr_reserve_space (xdr , 12 );
3376- if (!p )
3377- goto out_resource ;
3378- p = xdr_encode_hyper (p , (s64 )stat .mtime .tv_sec );
3379- * p ++ = cpu_to_be32 (stat .mtime .tv_nsec );
3385+ status = nfsd4_encode_nfstime4 (xdr , & stat .mtime );
3386+ if (status )
3387+ goto out ;
33803388 }
33813389 if (bmval1 & FATTR4_WORD1_TIME_CREATE ) {
3382- p = xdr_reserve_space (xdr , 12 );
3383- if (!p )
3384- goto out_resource ;
3385- p = xdr_encode_hyper (p , (s64 )stat .btime .tv_sec );
3386- * p ++ = cpu_to_be32 (stat .btime .tv_nsec );
3390+ status = nfsd4_encode_nfstime4 (xdr , & stat .btime );
3391+ if (status )
3392+ goto out ;
33873393 }
33883394 if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID ) {
33893395 u64 ino = stat .ino ;
0 commit comments