Commit 1e83b173 authored by Dave Wysochanski's avatar Dave Wysochanski Committed by Anna Schumaker

NFS: Add nfs_pageio_complete_read() and remove nfs_readpage_async()

Add nfs_pageio_complete_read() and call this from both nfs_readpage()
and nfs_readpages(), since the submission and accounting is the same
for both functions.
Signed-off-by: default avatarDave Wysochanski <dwysocha@redhat.com>
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
parent 0c119e3a
...@@ -390,10 +390,6 @@ static void nfs_readpage_from_fscache_complete(struct page *page, ...@@ -390,10 +390,6 @@ static void nfs_readpage_from_fscache_complete(struct page *page,
if (!error) { if (!error) {
SetPageUptodate(page); SetPageUptodate(page);
unlock_page(page); unlock_page(page);
} else {
error = nfs_readpage_async(context, page->mapping->host, page);
if (error)
unlock_page(page);
} }
} }
......
...@@ -74,6 +74,24 @@ void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, ...@@ -74,6 +74,24 @@ void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
} }
EXPORT_SYMBOL_GPL(nfs_pageio_init_read); EXPORT_SYMBOL_GPL(nfs_pageio_init_read);
static void nfs_pageio_complete_read(struct nfs_pageio_descriptor *pgio,
struct inode *inode)
{
struct nfs_pgio_mirror *pgm;
unsigned long npages;
nfs_pageio_complete(pgio);
/* It doesn't make sense to do mirrored reads! */
WARN_ON_ONCE(pgio->pg_mirror_count != 1);
pgm = &pgio->pg_mirrors[0];
NFS_I(inode)->read_io += pgm->pg_bytes_written;
npages = (pgm->pg_bytes_written + PAGE_SIZE - 1) >> PAGE_SHIFT;
nfs_add_stats(inode, NFSIOS_READPAGES, npages);
}
void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio) void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio)
{ {
struct nfs_pgio_mirror *mirror; struct nfs_pgio_mirror *mirror;
...@@ -119,36 +137,6 @@ struct nfs_readdesc { ...@@ -119,36 +137,6 @@ struct nfs_readdesc {
struct nfs_open_context *ctx; struct nfs_open_context *ctx;
}; };
static int readpage_async_filler(void *data, struct page *page);
int nfs_readpage_async(void *data, struct inode *inode,
struct page *page)
{
struct nfs_readdesc *desc = data;
struct nfs_pgio_mirror *pgm;
int error;
nfs_pageio_init_read(&desc->pgio, inode, false,
&nfs_async_read_completion_ops);
error = readpage_async_filler(desc, page);
if (error)
goto out;
nfs_pageio_complete(&desc->pgio);
/* It doesn't make sense to do mirrored reads! */
WARN_ON_ONCE(desc->pgio.pg_mirror_count != 1);
pgm = &desc->pgio.pg_mirrors[0];
NFS_I(inode)->read_io += pgm->pg_bytes_written;
return desc->pgio.pg_error < 0 ? desc->pgio.pg_error : 0;
out:
return error;
}
static void nfs_page_group_set_uptodate(struct nfs_page *req) static void nfs_page_group_set_uptodate(struct nfs_page *req)
{ {
if (nfs_page_group_sync_on_bit(req, PG_UPTODATE)) if (nfs_page_group_sync_on_bit(req, PG_UPTODATE))
...@@ -170,8 +158,7 @@ static void nfs_read_completion(struct nfs_pgio_header *hdr) ...@@ -170,8 +158,7 @@ static void nfs_read_completion(struct nfs_pgio_header *hdr)
if (test_bit(NFS_IOHDR_EOF, &hdr->flags)) { if (test_bit(NFS_IOHDR_EOF, &hdr->flags)) {
/* note: regions of the page not covered by a /* note: regions of the page not covered by a
* request are zeroed in nfs_readpage_async / * request are zeroed in readpage_async_filler */
* readpage_async_filler */
if (bytes > hdr->good_bytes) { if (bytes > hdr->good_bytes) {
/* nothing in this request was good, so zero /* nothing in this request was good, so zero
* the full extent of the request */ * the full extent of the request */
...@@ -303,6 +290,38 @@ static void nfs_readpage_result(struct rpc_task *task, ...@@ -303,6 +290,38 @@ static void nfs_readpage_result(struct rpc_task *task,
nfs_readpage_retry(task, hdr); nfs_readpage_retry(task, hdr);
} }
static int
readpage_async_filler(void *data, struct page *page)
{
struct nfs_readdesc *desc = data;
struct nfs_page *new;
unsigned int len;
int error;
len = nfs_page_length(page);
if (len == 0)
return nfs_return_empty_page(page);
new = nfs_create_request(desc->ctx, page, 0, len);
if (IS_ERR(new))
goto out_error;
if (len < PAGE_SIZE)
zero_user_segment(page, len, PAGE_SIZE);
if (!nfs_pageio_add_request(&desc->pgio, new)) {
nfs_list_remove_request(new);
error = desc->pgio.pg_error;
nfs_readpage_release(new, error);
goto out;
}
return 0;
out_error:
error = PTR_ERR(new);
unlock_page(page);
out:
return error;
}
/* /*
* Read a page over NFS. * Read a page over NFS.
* We read the page synchronously in the following case: * We read the page synchronously in the following case:
...@@ -351,13 +370,20 @@ int nfs_readpage(struct file *file, struct page *page) ...@@ -351,13 +370,20 @@ int nfs_readpage(struct file *file, struct page *page)
} }
xchg(&desc.ctx->error, 0); xchg(&desc.ctx->error, 0);
ret = nfs_readpage_async(&desc, inode, page); nfs_pageio_init_read(&desc.pgio, inode, false,
&nfs_async_read_completion_ops);
ret = readpage_async_filler(&desc, page);
if (!ret)
nfs_pageio_complete_read(&desc.pgio, inode);
ret = desc.pgio.pg_error < 0 ? desc.pgio.pg_error : 0;
if (!ret) { if (!ret) {
ret = wait_on_page_locked_killable(page); ret = wait_on_page_locked_killable(page);
if (!PageUptodate(page) && !ret) if (!PageUptodate(page) && !ret)
ret = xchg(&desc.ctx->error, 0); ret = xchg(&desc.ctx->error, 0);
} }
nfs_add_stats(inode, NFSIOS_READPAGES, 1);
out: out:
put_nfs_open_context(desc.ctx); put_nfs_open_context(desc.ctx);
return ret; return ret;
...@@ -366,45 +392,11 @@ int nfs_readpage(struct file *file, struct page *page) ...@@ -366,45 +392,11 @@ int nfs_readpage(struct file *file, struct page *page)
return ret; return ret;
} }
static int
readpage_async_filler(void *data, struct page *page)
{
struct nfs_readdesc *desc = (struct nfs_readdesc *)data;
struct nfs_page *new;
unsigned int len;
int error;
len = nfs_page_length(page);
if (len == 0)
return nfs_return_empty_page(page);
new = nfs_create_request(desc->ctx, page, 0, len);
if (IS_ERR(new))
goto out_error;
if (len < PAGE_SIZE)
zero_user_segment(page, len, PAGE_SIZE);
if (!nfs_pageio_add_request(&desc->pgio, new)) {
nfs_list_remove_request(new);
error = desc->pgio.pg_error;
nfs_readpage_release(new, error);
goto out;
}
return 0;
out_error:
error = PTR_ERR(new);
unlock_page(page);
out:
return error;
}
int nfs_readpages(struct file *file, 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_pgio_mirror *pgm;
struct nfs_readdesc desc; struct nfs_readdesc desc;
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
unsigned long npages;
int ret; int ret;
dprintk("NFS: nfs_readpages (%s/%Lu %d)\n", dprintk("NFS: nfs_readpages (%s/%Lu %d)\n",
...@@ -437,16 +429,9 @@ int nfs_readpages(struct file *file, struct address_space *mapping, ...@@ -437,16 +429,9 @@ int nfs_readpages(struct file *file, struct address_space *mapping,
&nfs_async_read_completion_ops); &nfs_async_read_completion_ops);
ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc); ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc);
nfs_pageio_complete(&desc.pgio);
/* It doesn't make sense to do mirrored reads! */ nfs_pageio_complete_read(&desc.pgio, inode);
WARN_ON_ONCE(desc.pgio.pg_mirror_count != 1);
pgm = &desc.pgio.pg_mirrors[0];
NFS_I(inode)->read_io += pgm->pg_bytes_written;
npages = (pgm->pg_bytes_written + PAGE_SIZE - 1) >>
PAGE_SHIFT;
nfs_add_stats(inode, NFSIOS_READPAGES, npages);
read_complete: read_complete:
put_nfs_open_context(desc.ctx); put_nfs_open_context(desc.ctx);
out: out:
......
...@@ -570,7 +570,6 @@ nfs_have_writebacks(struct inode *inode) ...@@ -570,7 +570,6 @@ nfs_have_writebacks(struct inode *inode)
extern int nfs_readpage(struct file *, struct page *); extern int nfs_readpage(struct file *, struct page *);
extern int nfs_readpages(struct file *, struct address_space *, extern int nfs_readpages(struct file *, struct address_space *,
struct list_head *, unsigned); struct list_head *, unsigned);
extern int nfs_readpage_async(void *, struct inode *, struct page *);
/* /*
* inline functions * inline functions
......
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