Skip to content

Commit a1aee9a

Browse files
committed
NFSD: Clean up nfsd4_encode_entry4()
Reshape nfsd4_encode_entry4() to be more like the legacy dirent encoders, which were recently rewritten to use xdr_stream. Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 3fc5048 commit a1aee9a

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

fs/nfsd/nfs4xdr.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,7 +3772,6 @@ nfsd4_encode_entry4(void *ccdv, const char *name, int namlen,
37723772
u32 name_and_cookie;
37733773
int entry_bytes;
37743774
__be32 nfserr = nfserr_toosmall;
3775-
__be32 *p;
37763775

37773776
/* In nfsv4, "." and ".." never make it onto the wire.. */
37783777
if (name && isdotent(name, namlen)) {
@@ -3783,17 +3782,15 @@ nfsd4_encode_entry4(void *ccdv, const char *name, int namlen,
37833782
/* Encode the previous entry's cookie value */
37843783
nfsd4_encode_entry4_nfs_cookie4(cd, offset);
37853784

3786-
p = xdr_reserve_space(xdr, 4);
3787-
if (!p)
3785+
if (xdr_stream_encode_item_present(xdr) != XDR_UNIT)
37883786
goto fail;
3789-
*p++ = xdr_one; /* mark entry present */
3787+
3788+
/* Reserve send buffer space for this entry's cookie value. */
37903789
cookie_offset = xdr->buf->len;
3791-
p = xdr_reserve_space(xdr, 3*4 + namlen);
3792-
if (!p)
3790+
if (nfsd4_encode_nfs_cookie4(xdr, OFFSET_MAX) != nfs_ok)
3791+
goto fail;
3792+
if (nfsd4_encode_component4(xdr, name, namlen) != nfs_ok)
37933793
goto fail;
3794-
p = xdr_encode_hyper(p, OFFSET_MAX); /* offset of next entry */
3795-
p = xdr_encode_array(p, name, namlen); /* name length & name */
3796-
37973794
nfserr = nfsd4_encode_entry4_fattr(cd, name, namlen);
37983795
switch (nfserr) {
37993796
case nfs_ok:

fs/nfsd/xdr4.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ nfsd4_encode_uint64_t(struct xdr_stream *xdr, u64 val)
120120
}
121121

122122
#define nfsd4_encode_changeid4(x, v) nfsd4_encode_uint64_t(x, v)
123+
#define nfsd4_encode_nfs_cookie4(x, v) nfsd4_encode_uint64_t(x, v)
123124
#define nfsd4_encode_length4(x, v) nfsd4_encode_uint64_t(x, v)
124125
#define nfsd4_encode_offset4(x, v) nfsd4_encode_uint64_t(x, v)
125126

@@ -174,6 +175,8 @@ nfsd4_encode_opaque(struct xdr_stream *xdr, const void *data, size_t size)
174175
return nfs_ok;
175176
}
176177

178+
#define nfsd4_encode_component4(x, d, s) nfsd4_encode_opaque(x, d, s)
179+
177180
struct nfsd4_compound_state {
178181
struct svc_fh current_fh;
179182
struct svc_fh save_fh;

0 commit comments

Comments
 (0)