@@ -3664,6 +3664,22 @@ __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words,
36643664 return ret ;
36653665}
36663666
3667+ /*
3668+ * The buffer space for this field was reserved during a previous
3669+ * call to nfsd4_encode_entry4().
3670+ */
3671+ static void nfsd4_encode_entry4_nfs_cookie4 (const struct nfsd4_readdir * readdir ,
3672+ u64 offset )
3673+ {
3674+ __be64 cookie = cpu_to_be64 (offset );
3675+ struct xdr_stream * xdr = readdir -> xdr ;
3676+
3677+ if (!readdir -> cookie_offset )
3678+ return ;
3679+ write_bytes_to_xdr_buf (xdr -> buf , readdir -> cookie_offset , & cookie ,
3680+ sizeof (cookie ));
3681+ }
3682+
36673683static inline int attributes_need_mount (u32 * bmval )
36683684{
36693685 if (bmval [0 ] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME ))
@@ -3756,7 +3772,6 @@ nfsd4_encode_entry4(void *ccdv, const char *name, int namlen,
37563772 u32 name_and_cookie ;
37573773 int entry_bytes ;
37583774 __be32 nfserr = nfserr_toosmall ;
3759- __be64 wire_offset ;
37603775 __be32 * p ;
37613776
37623777 /* In nfsv4, "." and ".." never make it onto the wire.. */
@@ -3765,11 +3780,8 @@ nfsd4_encode_entry4(void *ccdv, const char *name, int namlen,
37653780 return 0 ;
37663781 }
37673782
3768- if (cd -> cookie_offset ) {
3769- wire_offset = cpu_to_be64 (offset );
3770- write_bytes_to_xdr_buf (xdr -> buf , cd -> cookie_offset ,
3771- & wire_offset , 8 );
3772- }
3783+ /* Encode the previous entry's cookie value */
3784+ nfsd4_encode_entry4_nfs_cookie4 (cd , offset );
37733785
37743786 p = xdr_reserve_space (xdr , 4 );
37753787 if (!p )
@@ -4451,7 +4463,6 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr,
44514463 int maxcount ;
44524464 int bytes_left ;
44534465 loff_t offset ;
4454- __be64 wire_offset ;
44554466 struct xdr_stream * xdr = resp -> xdr ;
44564467 int starting_len = xdr -> buf -> len ;
44574468 __be32 * p ;
@@ -4509,11 +4520,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr,
45094520 if (nfserr )
45104521 goto err_no_verf ;
45114522
4512- if (readdir -> cookie_offset ) {
4513- wire_offset = cpu_to_be64 (offset );
4514- write_bytes_to_xdr_buf (xdr -> buf , readdir -> cookie_offset ,
4515- & wire_offset , 8 );
4516- }
4523+ /* Encode the final entry's cookie value */
4524+ nfsd4_encode_entry4_nfs_cookie4 (readdir , offset );
45174525
45184526 p = xdr_reserve_space (xdr , 8 );
45194527 if (!p ) {
0 commit comments