aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2008-02-22 14:50:00 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2008-03-19 18:00:06 -0400
commit643f81115baca3630e544f6874567648b605efae (patch)
treea9eaf544811df5474b8fbf655d1e176b9f7bdfc9 /fs/nfs
parentcaa02bd540618e4b447a1f776363ba27c4c79090 (diff)
NFS: clean up short packet handling for NFSv3 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 nfs3_xdr_readdirres(). Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/nfs3xdr.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
index 3917e2fa4e40..fb03048ac650 100644
--- a/fs/nfs/nfs3xdr.c
+++ b/fs/nfs/nfs3xdr.c
@@ -508,7 +508,7 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res
508 struct page **page; 508 struct page **page;
509 size_t hdrlen; 509 size_t hdrlen;
510 u32 len, recvd, pglen; 510 u32 len, recvd, pglen;
511 int status, nr; 511 int status, nr = 0;
512 __be32 *entry, *end, *kaddr; 512 __be32 *entry, *end, *kaddr;
513 513
514 status = ntohl(*p++); 514 status = ntohl(*p++);
@@ -542,7 +542,12 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res
542 kaddr = p = kmap_atomic(*page, KM_USER0); 542 kaddr = p = kmap_atomic(*page, KM_USER0);
543 end = (__be32 *)((char *)p + pglen); 543 end = (__be32 *)((char *)p + pglen);
544 entry = p; 544 entry = p;
545 for (nr = 0; *p++; nr++) { 545
546 /* Make sure the packet actually has a value_follows and EOF entry */
547 if ((entry + 1) > end)
548 goto short_pkt;
549
550 for (; *p++; nr++) {
546 if (p + 3 > end) 551 if (p + 3 > end)
547 goto short_pkt; 552 goto short_pkt;
548 p += 2; /* inode # */ 553 p += 2; /* inode # */
@@ -581,18 +586,32 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res
581 goto short_pkt; 586 goto short_pkt;
582 entry = p; 587 entry = p;
583 } 588 }
584 if (!nr && (entry[0] != 0 || entry[1] == 0)) 589
585 goto short_pkt; 590 /*
591 * Apparently some server sends responses that are a valid size, but
592 * contain no entries, and have value_follows==0 and EOF==0. For
593 * those, just set the EOF marker.
594 */
595 if (!nr && entry[1] == 0) {
596 dprintk("NFS: readdir reply truncated!\n");
597 entry[1] = 1;
598 }
586 out: 599 out:
587 kunmap_atomic(kaddr, KM_USER0); 600 kunmap_atomic(kaddr, KM_USER0);
588 return nr; 601 return nr;
589 short_pkt: 602 short_pkt:
603 /*
604 * When we get a short packet there are 2 possibilities. We can
605 * return an error, or fix up the response to look like a valid
606 * response and return what we have so far. If there are no
607 * entries and the packet was short, then return -EIO. If there
608 * are valid entries in the response, return them and pretend that
609 * the call was successful, but incomplete. The caller can retry the
610 * readdir starting at the last cookie.
611 */
590 entry[0] = entry[1] = 0; 612 entry[0] = entry[1] = 0;
591 /* truncate listing ? */ 613 if (!nr)
592 if (!nr) { 614 nr = -errno_NFSERR_IO;
593 dprintk("NFS: readdir reply truncated!\n");
594 entry[1] = 1;
595 }
596 goto out; 615 goto out;
597err_unmap: 616err_unmap:
598 nr = -errno_NFSERR_IO; 617 nr = -errno_NFSERR_IO;