nfs: move nfs_pgio_data and remove nfs_rw_header
[cascardo/linux.git] / fs / nfs / read.c
index 53d5b83..d9df4ab 100644 (file)
@@ -33,12 +33,12 @@ static const struct nfs_rw_ops nfs_rw_read_ops;
 
 static struct kmem_cache *nfs_rdata_cachep;
 
-static struct nfs_rw_header *nfs_readhdr_alloc(void)
+static struct nfs_pgio_header *nfs_readhdr_alloc(void)
 {
        return kmem_cache_zalloc(nfs_rdata_cachep, GFP_KERNEL);
 }
 
-static void nfs_readhdr_free(struct nfs_rw_header *rhdr)
+static void nfs_readhdr_free(struct nfs_pgio_header *rhdr)
 {
        kmem_cache_free(nfs_rdata_cachep, rhdr);
 }
@@ -130,7 +130,6 @@ static void nfs_page_group_set_uptodate(struct nfs_page *req)
                SetPageUptodate(req->wb_page);
 }
 
-/* Note io was page aligned */
 static void nfs_read_completion(struct nfs_pgio_header *hdr)
 {
        unsigned long bytes = 0;
@@ -140,14 +139,25 @@ static void nfs_read_completion(struct nfs_pgio_header *hdr)
        while (!list_empty(&hdr->pages)) {
                struct nfs_page *req = nfs_list_entry(hdr->pages.next);
                struct page *page = req->wb_page;
+               unsigned long start = req->wb_pgbase;
+               unsigned long end = req->wb_pgbase + req->wb_bytes;
 
                if (test_bit(NFS_IOHDR_EOF, &hdr->flags)) {
-                       if (bytes > hdr->good_bytes)
-                               zero_user(page, 0, PAGE_SIZE);
-                       else if (hdr->good_bytes - bytes < PAGE_SIZE)
-                               zero_user_segment(page,
-                                       hdr->good_bytes & ~PAGE_MASK,
-                                       PAGE_SIZE);
+                       /* note: regions of the page not covered by a
+                        * request are zeroed in nfs_readpage_async /
+                        * readpage_async_filler */
+                       if (bytes > hdr->good_bytes) {
+                               /* nothing in this request was good, so zero
+                                * the full extent of the request */
+                               zero_user_segment(page, start, end);
+
+                       } else if (hdr->good_bytes - bytes < req->wb_bytes) {
+                               /* part of this request has good bytes, but
+                                * not all. zero the bad bytes */
+                               start += hdr->good_bytes - bytes;
+                               WARN_ON(start < req->wb_pgbase);
+                               zero_user_segment(page, start, end);
+                       }
                }
                bytes += req->wb_bytes;
                if (test_bit(NFS_IOHDR_ERROR, &hdr->flags)) {
@@ -394,7 +404,7 @@ out:
 int __init nfs_init_readpagecache(void)
 {
        nfs_rdata_cachep = kmem_cache_create("nfs_read_data",
-                                            sizeof(struct nfs_rw_header),
+                                            sizeof(struct nfs_pgio_header),
                                             0, SLAB_HWCACHE_ALIGN,
                                             NULL);
        if (nfs_rdata_cachep == NULL)