diff options
author | Jeff Layton <jlayton@redhat.com> | 2008-02-22 14:50:01 -0500 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2008-03-19 18:00:10 -0400 |
commit | 7bda2cdf484a00e52b0ed925e99d4bf4696b2c7a (patch) | |
tree | 021f419b3007a8f300959c974ae40e609672deee | |
parent | 643f81115baca3630e544f6874567648b605efae (diff) |
NFS: clean up short packet handling for NFSv4 readdir
Currently, the NFS readdir decoders have a workaround for buggy servers
that send an empty readdir response with the EOF bit unset. If the
server sends a malformed response in some cases, this workaround kicks
in and just returns an empty response rather than returning a proper
error to the caller.
This patch does 3 things:
1) have malformed responses with no entries return error (-EIO)
2) preserve existing workaround for servers that send empty
responses with the EOF marker unset.
3) Add some comments to clarify the logic in decode_readdir().
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
-rw-r--r-- | fs/nfs/nfs4xdr.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 37421dd4805d..2b519f6325f9 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c | |||
@@ -3481,7 +3481,7 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n | |||
3481 | size_t hdrlen; | 3481 | size_t hdrlen; |
3482 | u32 recvd, pglen = rcvbuf->page_len; | 3482 | u32 recvd, pglen = rcvbuf->page_len; |
3483 | __be32 *end, *entry, *p, *kaddr; | 3483 | __be32 *end, *entry, *p, *kaddr; |
3484 | unsigned int nr; | 3484 | unsigned int nr = 0; |
3485 | int status; | 3485 | int status; |
3486 | 3486 | ||
3487 | status = decode_op_hdr(xdr, OP_READDIR); | 3487 | status = decode_op_hdr(xdr, OP_READDIR); |
@@ -3505,7 +3505,12 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n | |||
3505 | kaddr = p = kmap_atomic(page, KM_USER0); | 3505 | kaddr = p = kmap_atomic(page, KM_USER0); |
3506 | end = p + ((pglen + readdir->pgbase) >> 2); | 3506 | end = p + ((pglen + readdir->pgbase) >> 2); |
3507 | entry = p; | 3507 | entry = p; |
3508 | for (nr = 0; *p++; nr++) { | 3508 | |
3509 | /* Make sure the packet actually has a value_follows and EOF entry */ | ||
3510 | if ((entry + 1) > end) | ||
3511 | goto short_pkt; | ||
3512 | |||
3513 | for (; *p++; nr++) { | ||
3509 | u32 len, attrlen, xlen; | 3514 | u32 len, attrlen, xlen; |
3510 | if (end - p < 3) | 3515 | if (end - p < 3) |
3511 | goto short_pkt; | 3516 | goto short_pkt; |
@@ -3532,20 +3537,32 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n | |||
3532 | p += attrlen; /* attributes */ | 3537 | p += attrlen; /* attributes */ |
3533 | entry = p; | 3538 | entry = p; |
3534 | } | 3539 | } |
3535 | if (!nr && (entry[0] != 0 || entry[1] == 0)) | 3540 | /* |
3536 | goto short_pkt; | 3541 | * Apparently some server sends responses that are a valid size, but |
3542 | * contain no entries, and have value_follows==0 and EOF==0. For | ||
3543 | * those, just set the EOF marker. | ||
3544 | */ | ||
3545 | if (!nr && entry[1] == 0) { | ||
3546 | dprintk("NFS: readdir reply truncated!\n"); | ||
3547 | entry[1] = 1; | ||
3548 | } | ||
3537 | out: | 3549 | out: |
3538 | kunmap_atomic(kaddr, KM_USER0); | 3550 | kunmap_atomic(kaddr, KM_USER0); |
3539 | return 0; | 3551 | return 0; |
3540 | short_pkt: | 3552 | short_pkt: |
3553 | /* | ||
3554 | * When we get a short packet there are 2 possibilities. We can | ||
3555 | * return an error, or fix up the response to look like a valid | ||
3556 | * response and return what we have so far. If there are no | ||
3557 | * entries and the packet was short, then return -EIO. If there | ||
3558 | * are valid entries in the response, return them and pretend that | ||
3559 | * the call was successful, but incomplete. The caller can retry the | ||
3560 | * readdir starting at the last cookie. | ||
3561 | */ | ||
3541 | dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr); | 3562 | dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr); |
3542 | entry[0] = entry[1] = 0; | 3563 | entry[0] = entry[1] = 0; |
3543 | /* truncate listing ? */ | 3564 | if (nr) |
3544 | if (!nr) { | 3565 | goto out; |
3545 | dprintk("NFS: readdir reply truncated!\n"); | ||
3546 | entry[1] = 1; | ||
3547 | } | ||
3548 | goto out; | ||
3549 | err_unmap: | 3566 | err_unmap: |
3550 | kunmap_atomic(kaddr, KM_USER0); | 3567 | kunmap_atomic(kaddr, KM_USER0); |
3551 | return -errno_NFSERR_IO; | 3568 | return -errno_NFSERR_IO; |