Commit 49dee700 authored by Dave Wysochanski's avatar Dave Wysochanski Committed by Anna Schumaker

NFS: Clean up nfs_readpage() and nfs_readpages()

In prep for the new fscache netfs API, refactor nfs_readpage()
and nfs_readpages() for future patches.  No functional change.
Signed-off-by: default avatarDave Wysochanski <dwysocha@redhat.com>
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
parent ffb81717
...@@ -314,7 +314,7 @@ int nfs_readpage(struct file *file, struct page *page) ...@@ -314,7 +314,7 @@ int nfs_readpage(struct file *file, struct page *page)
{ {
struct nfs_open_context *ctx; struct nfs_open_context *ctx;
struct inode *inode = page_file_mapping(page)->host; struct inode *inode = page_file_mapping(page)->host;
int error; int ret;
dprintk("NFS: nfs_readpage (%p %ld@%lu)\n", dprintk("NFS: nfs_readpage (%p %ld@%lu)\n",
page, PAGE_SIZE, page_index(page)); page, PAGE_SIZE, page_index(page));
...@@ -328,18 +328,18 @@ int nfs_readpage(struct file *file, struct page *page) ...@@ -328,18 +328,18 @@ int nfs_readpage(struct file *file, struct page *page)
* be any new pending writes generated at this point * be any new pending writes generated at this point
* for this page (other pages can be written to). * for this page (other pages can be written to).
*/ */
error = nfs_wb_page(inode, page); ret = nfs_wb_page(inode, page);
if (error) if (ret)
goto out_unlock; goto out_unlock;
if (PageUptodate(page)) if (PageUptodate(page))
goto out_unlock; goto out_unlock;
error = -ESTALE; ret = -ESTALE;
if (NFS_STALE(inode)) if (NFS_STALE(inode))
goto out_unlock; goto out_unlock;
if (file == NULL) { if (file == NULL) {
error = -EBADF; ret = -EBADF;
ctx = nfs_find_open_context(inode, NULL, FMODE_READ); ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
if (ctx == NULL) if (ctx == NULL)
goto out_unlock; goto out_unlock;
...@@ -347,24 +347,24 @@ int nfs_readpage(struct file *file, struct page *page) ...@@ -347,24 +347,24 @@ int nfs_readpage(struct file *file, struct page *page)
ctx = get_nfs_open_context(nfs_file_open_context(file)); ctx = get_nfs_open_context(nfs_file_open_context(file));
if (!IS_SYNC(inode)) { if (!IS_SYNC(inode)) {
error = nfs_readpage_from_fscache(ctx, inode, page); ret = nfs_readpage_from_fscache(ctx, inode, page);
if (error == 0) if (ret == 0)
goto out; goto out;
} }
xchg(&ctx->error, 0); xchg(&ctx->error, 0);
error = nfs_readpage_async(ctx, inode, page); ret = nfs_readpage_async(ctx, inode, page);
if (!error) { if (!ret) {
error = wait_on_page_locked_killable(page); ret = wait_on_page_locked_killable(page);
if (!PageUptodate(page) && !error) if (!PageUptodate(page) && !ret)
error = xchg(&ctx->error, 0); ret = xchg(&ctx->error, 0);
} }
out: out:
put_nfs_open_context(ctx); put_nfs_open_context(ctx);
return error; return ret;
out_unlock: out_unlock:
unlock_page(page); unlock_page(page);
return error; return ret;
} }
struct nfs_readdesc { struct nfs_readdesc {
...@@ -404,17 +404,15 @@ readpage_async_filler(void *data, struct page *page) ...@@ -404,17 +404,15 @@ readpage_async_filler(void *data, struct page *page)
return error; return error;
} }
int nfs_readpages(struct file *filp, struct address_space *mapping, int nfs_readpages(struct file *file, struct address_space *mapping,
struct list_head *pages, unsigned nr_pages) struct list_head *pages, unsigned nr_pages)
{ {
struct nfs_pageio_descriptor pgio; struct nfs_pageio_descriptor pgio;
struct nfs_pgio_mirror *pgm; struct nfs_pgio_mirror *pgm;
struct nfs_readdesc desc = { struct nfs_readdesc desc;
.pgio = &pgio,
};
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
unsigned long npages; unsigned long npages;
int ret = -ESTALE; int ret;
dprintk("NFS: nfs_readpages (%s/%Lu %d)\n", dprintk("NFS: nfs_readpages (%s/%Lu %d)\n",
inode->i_sb->s_id, inode->i_sb->s_id,
...@@ -422,15 +420,17 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, ...@@ -422,15 +420,17 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,
nr_pages); nr_pages);
nfs_inc_stats(inode, NFSIOS_VFSREADPAGES); nfs_inc_stats(inode, NFSIOS_VFSREADPAGES);
ret = -ESTALE;
if (NFS_STALE(inode)) if (NFS_STALE(inode))
goto out; goto out;
if (filp == NULL) { if (file == NULL) {
ret = -EBADF;
desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ); desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
if (desc.ctx == NULL) if (desc.ctx == NULL)
return -EBADF; goto out;
} else } else
desc.ctx = get_nfs_open_context(nfs_file_open_context(filp)); desc.ctx = get_nfs_open_context(nfs_file_open_context(file));
/* attempt to read as many of the pages as possible from the cache /* attempt to read as many of the pages as possible from the cache
* - this returns -ENOBUFS immediately if the cookie is negative * - this returns -ENOBUFS immediately if the cookie is negative
...@@ -440,6 +440,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, ...@@ -440,6 +440,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,
if (ret == 0) if (ret == 0)
goto read_complete; /* all pages were read */ goto read_complete; /* all pages were read */
desc.pgio = &pgio;
nfs_pageio_init_read(&pgio, inode, false, nfs_pageio_init_read(&pgio, inode, false,
&nfs_async_read_completion_ops); &nfs_async_read_completion_ops);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment