]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/nfs/read.c
Pull now into release branch
[linux-2.6-omap-h63xx.git] / fs / nfs / read.c
index 0effa74992df503ce0d7bf9b6e3789a4f1a5d0fa..19e05633f4e3463152b2867fcc2ac3f13e933b96 100644 (file)
@@ -27,8 +27,8 @@
 
 #define NFSDBG_FACILITY                NFSDBG_PAGECACHE
 
-static int nfs_pagein_multi(struct inode *, struct list_head *, size_t, int);
-static int nfs_pagein_one(struct inode *, struct list_head *, size_t, int);
+static int nfs_pagein_multi(struct inode *, struct list_head *, unsigned int, size_t, int);
+static int nfs_pagein_one(struct inode *, struct list_head *, unsigned int, size_t, int);
 static const struct rpc_call_ops nfs_read_partial_ops;
 static const struct rpc_call_ops nfs_read_full_ops;
 
@@ -37,9 +37,8 @@ static mempool_t *nfs_rdata_mempool;
 
 #define MIN_POOL_READ  (32)
 
-struct nfs_read_data *nfs_readdata_alloc(size_t len)
+struct nfs_read_data *nfs_readdata_alloc(unsigned int pagecount)
 {
-       unsigned int pagecount = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
        struct nfs_read_data *p = mempool_alloc(nfs_rdata_mempool, GFP_NOFS);
 
        if (p) {
@@ -80,7 +79,7 @@ void nfs_readdata_release(void *data)
 static
 int nfs_return_empty_page(struct page *page)
 {
-       memclear_highpage_flush(page, 0, PAGE_CACHE_SIZE);
+       zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
        SetPageUptodate(page);
        unlock_page(page);
        return 0;
@@ -104,10 +103,10 @@ static void nfs_readpage_truncate_uninitialised_page(struct nfs_read_data *data)
        pglen = PAGE_CACHE_SIZE - base;
        for (;;) {
                if (remainder <= pglen) {
-                       memclear_highpage_flush(*pages, base, remainder);
+                       zero_user_page(*pages, base, remainder, KM_USER0);
                        break;
                }
-               memclear_highpage_flush(*pages, base, pglen);
+               zero_user_page(*pages, base, pglen, KM_USER0);
                pages++;
                remainder -= pglen;
                pglen = PAGE_CACHE_SIZE;
@@ -131,13 +130,13 @@ static int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,
                return PTR_ERR(new);
        }
        if (len < PAGE_CACHE_SIZE)
-               memclear_highpage_flush(page, len, PAGE_CACHE_SIZE - len);
+               zero_user_page(page, len, PAGE_CACHE_SIZE - len, KM_USER0);
 
        nfs_list_add_request(new, &one_request);
        if (NFS_SERVER(inode)->rsize < PAGE_CACHE_SIZE)
-               nfs_pagein_multi(inode, &one_request, len, 0);
+               nfs_pagein_multi(inode, &one_request, 1, len, 0);
        else
-               nfs_pagein_one(inode, &one_request, len, 0);
+               nfs_pagein_one(inode, &one_request, 1, len, 0);
        return 0;
 }
 
@@ -146,8 +145,8 @@ static void nfs_readpage_release(struct nfs_page *req)
        unlock_page(req->wb_page);
 
        dprintk("NFS: read done (%s/%Ld %d@%Ld)\n",
-                       req->wb_context->dentry->d_inode->i_sb->s_id,
-                       (long long)NFS_FILEID(req->wb_context->dentry->d_inode),
+                       req->wb_context->path.dentry->d_inode->i_sb->s_id,
+                       (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
                        req->wb_bytes,
                        (long long)req_offset(req));
        nfs_clear_request(req);
@@ -165,7 +164,7 @@ static void nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
        int flags;
 
        data->req         = req;
-       data->inode       = inode = req->wb_context->dentry->d_inode;
+       data->inode       = inode = req->wb_context->path.dentry->d_inode;
        data->cred        = req->wb_context->cred;
 
        data->args.fh     = NFS_FH(inode);
@@ -234,7 +233,7 @@ static void nfs_execute_read(struct nfs_read_data *data)
  * won't see the new data until our attribute cache is updated.  This is more
  * or less conventional NFS client behavior.
  */
-static int nfs_pagein_multi(struct inode *inode, struct list_head *head, size_t count, int flags)
+static int nfs_pagein_multi(struct inode *inode, struct list_head *head, unsigned int npages, size_t count, int flags)
 {
        struct nfs_page *req = nfs_list_entry(head->next);
        struct page *page = req->wb_page;
@@ -250,7 +249,7 @@ static int nfs_pagein_multi(struct inode *inode, struct list_head *head, size_t
        do {
                size_t len = min(nbytes,rsize);
 
-               data = nfs_readdata_alloc(len);
+               data = nfs_readdata_alloc(1);
                if (!data)
                        goto out_bad;
                INIT_LIST_HEAD(&data->pages);
@@ -291,13 +290,13 @@ out_bad:
        return -ENOMEM;
 }
 
-static int nfs_pagein_one(struct inode *inode, struct list_head *head, size_t count, int flags)
+static int nfs_pagein_one(struct inode *inode, struct list_head *head, unsigned int npages, size_t count, int flags)
 {
        struct nfs_page         *req;
        struct page             **pages;
        struct nfs_read_data    *data;
 
-       data = nfs_readdata_alloc(count);
+       data = nfs_readdata_alloc(npages);
        if (!data)
                goto out_bad;
 
@@ -321,28 +320,6 @@ out_bad:
        return -ENOMEM;
 }
 
-static int
-nfs_pagein_list(struct inode *inode, struct list_head *head, unsigned int rsize)
-{
-       struct nfs_pageio_descriptor desc;
-       unsigned int pages = 0;
-       int error = 0;
-
-       if (rsize < PAGE_CACHE_SIZE)
-               nfs_pageio_init(&desc, inode, nfs_pagein_multi, rsize, 0);
-       else
-               nfs_pageio_init(&desc, inode, nfs_pagein_one, rsize, 0);
-
-       nfs_pageio_add_list(&desc, head);
-       nfs_pageio_complete(&desc);
-       pages += (desc.pg_bytes_written + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
-
-       nfs_async_read_error(head);
-       if (error >= 0)
-               return pages;
-       return error;
-}
-
 /*
  * This is the callback from RPC telling us whether a reply was
  * received or some error occurred (timeout or socket shutdown).
@@ -506,17 +483,19 @@ int nfs_readpage(struct file *file, struct page *page)
         */
        error = nfs_wb_page(inode, page);
        if (error)
-               goto out_error;
+               goto out_unlock;
+       if (PageUptodate(page))
+               goto out_unlock;
 
        error = -ESTALE;
        if (NFS_STALE(inode))
-               goto out_error;
+               goto out_unlock;
 
        if (file == NULL) {
                error = -EBADF;
                ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
                if (ctx == NULL)
-                       goto out_error;
+                       goto out_unlock;
        } else
                ctx = get_nfs_open_context((struct nfs_open_context *)
                                file->private_data);
@@ -525,14 +504,13 @@ int nfs_readpage(struct file *file, struct page *page)
 
        put_nfs_open_context(ctx);
        return error;
-
-out_error:
+out_unlock:
        unlock_page(page);
        return error;
 }
 
 struct nfs_readdesc {
-       struct list_head *head;
+       struct nfs_pageio_descriptor *pgio;
        struct nfs_open_context *ctx;
 };
 
@@ -543,32 +521,45 @@ readpage_async_filler(void *data, struct page *page)
        struct inode *inode = page->mapping->host;
        struct nfs_page *new;
        unsigned int len;
+       int error;
+
+       error = nfs_wb_page(inode, page);
+       if (error)
+               goto out_unlock;
+       if (PageUptodate(page))
+               goto out_unlock;
 
-       nfs_wb_page(inode, page);
        len = nfs_page_length(page);
        if (len == 0)
                return nfs_return_empty_page(page);
+
        new = nfs_create_request(desc->ctx, inode, page, 0, len);
-       if (IS_ERR(new)) {
-                       SetPageError(page);
-                       unlock_page(page);
-                       return PTR_ERR(new);
-       }
+       if (IS_ERR(new))
+               goto out_error;
+
        if (len < PAGE_CACHE_SIZE)
-               memclear_highpage_flush(page, len, PAGE_CACHE_SIZE - len);
-       nfs_list_add_request(new, desc->head);
+               zero_user_page(page, len, PAGE_CACHE_SIZE - len, KM_USER0);
+       nfs_pageio_add_request(desc->pgio, new);
        return 0;
+out_error:
+       error = PTR_ERR(new);
+       SetPageError(page);
+out_unlock:
+       unlock_page(page);
+       return error;
 }
 
 int nfs_readpages(struct file *filp, struct address_space *mapping,
                struct list_head *pages, unsigned nr_pages)
 {
-       LIST_HEAD(head);
+       struct nfs_pageio_descriptor pgio;
        struct nfs_readdesc desc = {
-               .head           = &head,
+               .pgio = &pgio,
        };
        struct inode *inode = mapping->host;
        struct nfs_server *server = NFS_SERVER(inode);
+       size_t rsize = server->rsize;
+       unsigned long npages;
        int ret = -ESTALE;
 
        dprintk("NFS: nfs_readpages (%s/%Ld %d)\n",
@@ -587,13 +578,16 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,
        } else
                desc.ctx = get_nfs_open_context((struct nfs_open_context *)
                                filp->private_data);
+       if (rsize < PAGE_CACHE_SIZE)
+               nfs_pageio_init(&pgio, inode, nfs_pagein_multi, rsize, 0);
+       else
+               nfs_pageio_init(&pgio, inode, nfs_pagein_one, rsize, 0);
+
        ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc);
-       if (!list_empty(&head)) {
-               int err = nfs_pagein_list(inode, &head, server->rsize);
-               if (!ret)
-                       nfs_add_stats(inode, NFSIOS_READPAGES, err);
-                       ret = err;
-       }
+
+       nfs_pageio_complete(&pgio);
+       npages = (pgio.pg_bytes_written + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+       nfs_add_stats(inode, NFSIOS_READPAGES, npages);
        put_nfs_open_context(desc.ctx);
 out:
        return ret;
@@ -604,7 +598,7 @@ int __init nfs_init_readpagecache(void)
        nfs_rdata_cachep = kmem_cache_create("nfs_read_data",
                                             sizeof(struct nfs_read_data),
                                             0, SLAB_HWCACHE_ALIGN,
-                                            NULL, NULL);
+                                            NULL);
        if (nfs_rdata_cachep == NULL)
                return -ENOMEM;