Commit 0eecb214 authored by Anna Schumaker's avatar Anna Schumaker Committed by Trond Myklebust

NFS: Create a common nfs_pgio_result_common function

Combining these functions will let me make a single nfs_rw_common_ops
struct (see the next patch).
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
parent a4cdda59
...@@ -243,6 +243,7 @@ struct nfs_pgio_data *nfs_pgio_data_alloc(struct nfs_pgio_header *, unsigned int ...@@ -243,6 +243,7 @@ struct nfs_pgio_data *nfs_pgio_data_alloc(struct nfs_pgio_header *, unsigned int
void nfs_pgio_data_release(struct nfs_pgio_data *); void nfs_pgio_data_release(struct nfs_pgio_data *);
void nfs_pgio_prepare(struct rpc_task *, void *); void nfs_pgio_prepare(struct rpc_task *, void *);
void nfs_pgio_release(void *); void nfs_pgio_release(void *);
void nfs_pgio_result(struct rpc_task *, void *);
static inline void nfs_iocounter_init(struct nfs_io_counter *c) static inline void nfs_iocounter_init(struct nfs_io_counter *c)
{ {
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "internal.h" #include "internal.h"
#include "pnfs.h" #include "pnfs.h"
#define NFSDBG_FACILITY NFSDBG_PAGECACHE
static struct kmem_cache *nfs_page_cachep; static struct kmem_cache *nfs_page_cachep;
static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount) static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount)
...@@ -447,6 +449,27 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc, ...@@ -447,6 +449,27 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc,
} }
EXPORT_SYMBOL_GPL(nfs_pageio_init); EXPORT_SYMBOL_GPL(nfs_pageio_init);
/**
* nfs_pgio_result - Basic pageio error handling
* @task: The task that ran
* @calldata: Pageio data to check
*/
void nfs_pgio_result(struct rpc_task *task, void *calldata)
{
struct nfs_pgio_data *data = calldata;
struct inode *inode = data->header->inode;
dprintk("NFS: %s: %5u, (status %d)\n", __func__,
task->tk_pid, task->tk_status);
if (data->header->rw_ops->rw_done(task, data, inode) != 0)
return;
if (task->tk_status < 0)
nfs_set_pgio_error(data->header, task->tk_status, data->args.offset);
else
data->header->rw_ops->rw_result(task, data);
}
static bool nfs_match_open_context(const struct nfs_open_context *ctx1, static bool nfs_match_open_context(const struct nfs_open_context *ctx1,
const struct nfs_open_context *ctx2) const struct nfs_open_context *ctx2)
{ {
......
...@@ -388,15 +388,10 @@ static const struct nfs_pageio_ops nfs_pageio_read_ops = { ...@@ -388,15 +388,10 @@ static const struct nfs_pageio_ops nfs_pageio_read_ops = {
* This is the callback from RPC telling us whether a reply was * This is the callback from RPC telling us whether a reply was
* received or some error occurred (timeout or socket shutdown). * received or some error occurred (timeout or socket shutdown).
*/ */
int nfs_readpage_result(struct rpc_task *task, struct nfs_pgio_data *data) static int nfs_readpage_done(struct rpc_task *task, struct nfs_pgio_data *data,
struct inode *inode)
{ {
struct inode *inode = data->header->inode; int status = NFS_PROTO(inode)->read_done(task, data);
int status;
dprintk("NFS: %s: %5u, (status %d)\n", __func__, task->tk_pid,
task->tk_status);
status = NFS_PROTO(inode)->read_done(task, data);
if (status != 0) if (status != 0)
return status; return status;
...@@ -429,17 +424,11 @@ static void nfs_readpage_retry(struct rpc_task *task, struct nfs_pgio_data *data ...@@ -429,17 +424,11 @@ static void nfs_readpage_retry(struct rpc_task *task, struct nfs_pgio_data *data
rpc_restart_call_prepare(task); rpc_restart_call_prepare(task);
} }
static void nfs_readpage_result_common(struct rpc_task *task, void *calldata) static void nfs_readpage_result(struct rpc_task *task, struct nfs_pgio_data *data)
{ {
struct nfs_pgio_data *data = calldata;
struct nfs_pgio_header *hdr = data->header; struct nfs_pgio_header *hdr = data->header;
/* Note the only returns of nfs_readpage_result are 0 and -EAGAIN */ if (data->res.eof) {
if (nfs_readpage_result(task, data) != 0)
return;
if (task->tk_status < 0)
nfs_set_pgio_error(hdr, task->tk_status, data->args.offset);
else if (data->res.eof) {
loff_t bound; loff_t bound;
bound = data->args.offset + data->res.count; bound = data->args.offset + data->res.count;
...@@ -456,7 +445,7 @@ static void nfs_readpage_result_common(struct rpc_task *task, void *calldata) ...@@ -456,7 +445,7 @@ static void nfs_readpage_result_common(struct rpc_task *task, void *calldata)
static const struct rpc_call_ops nfs_read_common_ops = { static const struct rpc_call_ops nfs_read_common_ops = {
.rpc_call_prepare = nfs_pgio_prepare, .rpc_call_prepare = nfs_pgio_prepare,
.rpc_call_done = nfs_readpage_result_common, .rpc_call_done = nfs_pgio_result,
.rpc_release = nfs_pgio_release, .rpc_release = nfs_pgio_release,
}; };
...@@ -625,4 +614,6 @@ static const struct nfs_rw_ops nfs_rw_read_ops = { ...@@ -625,4 +614,6 @@ static const struct nfs_rw_ops nfs_rw_read_ops = {
.rw_mode = FMODE_READ, .rw_mode = FMODE_READ,
.rw_alloc_header = nfs_readhdr_alloc, .rw_alloc_header = nfs_readhdr_alloc,
.rw_free_header = nfs_readhdr_free, .rw_free_header = nfs_readhdr_free,
.rw_done = nfs_readpage_done,
.rw_result = nfs_readpage_result,
}; };
...@@ -1255,20 +1255,6 @@ void nfs_commit_prepare(struct rpc_task *task, void *calldata) ...@@ -1255,20 +1255,6 @@ void nfs_commit_prepare(struct rpc_task *task, void *calldata)
NFS_PROTO(data->inode)->commit_rpc_prepare(task, data); NFS_PROTO(data->inode)->commit_rpc_prepare(task, data);
} }
/*
* Handle a write reply that flushes a whole page.
*
* FIXME: There is an inherent race with invalidate_inode_pages and
* writebacks since the page->count is kept > 1 for as long
* as the page has a write request pending.
*/
static void nfs_writeback_done_common(struct rpc_task *task, void *calldata)
{
struct nfs_pgio_data *data = calldata;
nfs_writeback_done(task, data);
}
static void nfs_writeback_release_common(struct nfs_pgio_data *data) static void nfs_writeback_release_common(struct nfs_pgio_data *data)
{ {
struct nfs_pgio_header *hdr = data->header; struct nfs_pgio_header *hdr = data->header;
...@@ -1288,7 +1274,7 @@ static void nfs_writeback_release_common(struct nfs_pgio_data *data) ...@@ -1288,7 +1274,7 @@ static void nfs_writeback_release_common(struct nfs_pgio_data *data)
static const struct rpc_call_ops nfs_write_common_ops = { static const struct rpc_call_ops nfs_write_common_ops = {
.rpc_call_prepare = nfs_pgio_prepare, .rpc_call_prepare = nfs_pgio_prepare,
.rpc_call_done = nfs_writeback_done_common, .rpc_call_done = nfs_pgio_result,
.rpc_release = nfs_pgio_release, .rpc_release = nfs_pgio_release,
}; };
...@@ -1320,16 +1306,11 @@ static int nfs_should_remove_suid(const struct inode *inode) ...@@ -1320,16 +1306,11 @@ static int nfs_should_remove_suid(const struct inode *inode)
/* /*
* This function is called when the WRITE call is complete. * This function is called when the WRITE call is complete.
*/ */
void nfs_writeback_done(struct rpc_task *task, struct nfs_pgio_data *data) static int nfs_writeback_done(struct rpc_task *task, struct nfs_pgio_data *data,
struct inode *inode)
{ {
struct nfs_pgio_args *argp = &data->args;
struct nfs_pgio_res *resp = &data->res;
struct inode *inode = data->header->inode;
int status; int status;
dprintk("NFS: %5u nfs_writeback_done (status %d)\n",
task->tk_pid, task->tk_status);
/* /*
* ->write_done will attempt to use post-op attributes to detect * ->write_done will attempt to use post-op attributes to detect
* conflicting writes by other clients. A strict interpretation * conflicting writes by other clients. A strict interpretation
...@@ -1339,11 +1320,11 @@ void nfs_writeback_done(struct rpc_task *task, struct nfs_pgio_data *data) ...@@ -1339,11 +1320,11 @@ void nfs_writeback_done(struct rpc_task *task, struct nfs_pgio_data *data)
*/ */
status = NFS_PROTO(inode)->write_done(task, data); status = NFS_PROTO(inode)->write_done(task, data);
if (status != 0) if (status != 0)
return; return status;
nfs_add_stats(inode, NFSIOS_SERVERWRITTENBYTES, resp->count); nfs_add_stats(inode, NFSIOS_SERVERWRITTENBYTES, data->res.count);
#if IS_ENABLED(CONFIG_NFS_V3) || IS_ENABLED(CONFIG_NFS_V4) #if IS_ENABLED(CONFIG_NFS_V3) || IS_ENABLED(CONFIG_NFS_V4)
if (resp->verf->committed < argp->stable && task->tk_status >= 0) { if (data->res.verf->committed < data->args.stable && task->tk_status >= 0) {
/* We tried a write call, but the server did not /* We tried a write call, but the server did not
* commit data to stable storage even though we * commit data to stable storage even though we
* requested it. * requested it.
...@@ -1359,25 +1340,31 @@ void nfs_writeback_done(struct rpc_task *task, struct nfs_pgio_data *data) ...@@ -1359,25 +1340,31 @@ void nfs_writeback_done(struct rpc_task *task, struct nfs_pgio_data *data)
dprintk("NFS: faulty NFS server %s:" dprintk("NFS: faulty NFS server %s:"
" (committed = %d) != (stable = %d)\n", " (committed = %d) != (stable = %d)\n",
NFS_SERVER(inode)->nfs_client->cl_hostname, NFS_SERVER(inode)->nfs_client->cl_hostname,
resp->verf->committed, argp->stable); data->res.verf->committed, data->args.stable);
complain = jiffies + 300 * HZ; complain = jiffies + 300 * HZ;
} }
} }
#endif #endif
if (task->tk_status < 0) {
nfs_set_pgio_error(data->header, task->tk_status, argp->offset);
return;
}
/* Deal with the suid/sgid bit corner case */ /* Deal with the suid/sgid bit corner case */
if (nfs_should_remove_suid(inode)) if (nfs_should_remove_suid(inode))
nfs_mark_for_revalidate(inode); nfs_mark_for_revalidate(inode);
return 0;
}
/*
* This function is called when the WRITE call is complete.
*/
static void nfs_writeback_result(struct rpc_task *task, struct nfs_pgio_data *data)
{
struct nfs_pgio_args *argp = &data->args;
struct nfs_pgio_res *resp = &data->res;
if (resp->count < argp->count) { if (resp->count < argp->count) {
static unsigned long complain; static unsigned long complain;
/* This a short write! */ /* This a short write! */
nfs_inc_stats(inode, NFSIOS_SHORTWRITE); nfs_inc_stats(data->header->inode, NFSIOS_SHORTWRITE);
/* Has the server at least made some progress? */ /* Has the server at least made some progress? */
if (resp->count == 0) { if (resp->count == 0) {
...@@ -1911,4 +1898,6 @@ static const struct nfs_rw_ops nfs_rw_write_ops = { ...@@ -1911,4 +1898,6 @@ static const struct nfs_rw_ops nfs_rw_write_ops = {
.rw_alloc_header = nfs_writehdr_alloc, .rw_alloc_header = nfs_writehdr_alloc,
.rw_free_header = nfs_writehdr_free, .rw_free_header = nfs_writehdr_free,
.rw_release = nfs_writeback_release_common, .rw_release = nfs_writeback_release_common,
.rw_done = nfs_writeback_done,
.rw_result = nfs_writeback_result,
}; };
...@@ -520,7 +520,6 @@ extern int nfs_writepage(struct page *page, struct writeback_control *wbc); ...@@ -520,7 +520,6 @@ extern int nfs_writepage(struct page *page, struct writeback_control *wbc);
extern int nfs_writepages(struct address_space *, struct writeback_control *); extern int nfs_writepages(struct address_space *, struct writeback_control *);
extern int nfs_flush_incompatible(struct file *file, struct page *page); extern int nfs_flush_incompatible(struct file *file, struct page *page);
extern int nfs_updatepage(struct file *, struct page *, unsigned int, unsigned int); extern int nfs_updatepage(struct file *, struct page *, unsigned int, unsigned int);
extern void nfs_writeback_done(struct rpc_task *, struct nfs_pgio_data *);
/* /*
* Try to write back everything synchronously (but check the * Try to write back everything synchronously (but check the
...@@ -553,7 +552,6 @@ nfs_have_writebacks(struct inode *inode) ...@@ -553,7 +552,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_result(struct rpc_task *, struct nfs_pgio_data *);
extern int nfs_readpage_async(struct nfs_open_context *, struct inode *, extern int nfs_readpage_async(struct nfs_open_context *, struct inode *,
struct page *); struct page *);
......
...@@ -57,6 +57,8 @@ struct nfs_rw_ops { ...@@ -57,6 +57,8 @@ struct nfs_rw_ops {
struct nfs_rw_header *(*rw_alloc_header)(void); struct nfs_rw_header *(*rw_alloc_header)(void);
void (*rw_free_header)(struct nfs_rw_header *); void (*rw_free_header)(struct nfs_rw_header *);
void (*rw_release)(struct nfs_pgio_data *); void (*rw_release)(struct nfs_pgio_data *);
int (*rw_done)(struct rpc_task *, struct nfs_pgio_data *, struct inode *);
void (*rw_result)(struct rpc_task *, struct nfs_pgio_data *);
}; };
struct nfs_pageio_descriptor { struct nfs_pageio_descriptor {
......
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