Commit 6e4efd56 authored by Trond Myklebust's avatar Trond Myklebust

NFS: Clean up nfs_read_rpcsetup and nfs_write_rpcsetup

Split them up into two parts: one which sets up the struct nfs_read/write_data,
the other which sets up the actual RPC call or pNFS call.
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 87ed5eb4
...@@ -213,17 +213,14 @@ EXPORT_SYMBOL_GPL(nfs_initiate_read); ...@@ -213,17 +213,14 @@ EXPORT_SYMBOL_GPL(nfs_initiate_read);
/* /*
* Set up the NFS read request struct * Set up the NFS read request struct
*/ */
static int nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data, static void nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
const struct rpc_call_ops *call_ops, unsigned int count, unsigned int offset)
unsigned int count, unsigned int offset,
struct pnfs_layout_segment *lseg)
{ {
struct inode *inode = req->wb_context->path.dentry->d_inode; struct inode *inode = req->wb_context->path.dentry->d_inode;
data->req = req; data->req = req;
data->inode = inode; data->inode = inode;
data->cred = req->wb_context->cred; data->cred = req->wb_context->cred;
data->lseg = get_lseg(lseg);
data->args.fh = NFS_FH(inode); data->args.fh = NFS_FH(inode);
data->args.offset = req_offset(req) + offset; data->args.offset = req_offset(req) + offset;
...@@ -237,10 +234,21 @@ static int nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data, ...@@ -237,10 +234,21 @@ static int nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
data->res.count = count; data->res.count = count;
data->res.eof = 0; data->res.eof = 0;
nfs_fattr_init(&data->fattr); nfs_fattr_init(&data->fattr);
}
if (data->lseg && static int nfs_do_read(struct nfs_read_data *data,
(pnfs_try_to_read_data(data, call_ops) == PNFS_ATTEMPTED)) const struct rpc_call_ops *call_ops,
return 0; struct pnfs_layout_segment *lseg)
{
struct inode *inode = data->args.context->path.dentry->d_inode;
if (lseg) {
data->lseg = get_lseg(lseg);
if (pnfs_try_to_read_data(data, call_ops) == PNFS_ATTEMPTED)
return 0;
put_lseg(data->lseg);
data->lseg = NULL;
}
return nfs_initiate_read(data, NFS_CLIENT(inode), call_ops); return nfs_initiate_read(data, NFS_CLIENT(inode), call_ops);
} }
...@@ -292,7 +300,7 @@ static int nfs_pagein_multi(struct nfs_pageio_descriptor *desc) ...@@ -292,7 +300,7 @@ static int nfs_pagein_multi(struct nfs_pageio_descriptor *desc)
data = nfs_readdata_alloc(1); data = nfs_readdata_alloc(1);
if (!data) if (!data)
goto out_bad; goto out_bad;
list_add(&data->pages, &list); list_add(&data->list, &list);
requests++; requests++;
nbytes -= len; nbytes -= len;
} while(nbytes != 0); } while(nbytes != 0);
...@@ -304,15 +312,15 @@ static int nfs_pagein_multi(struct nfs_pageio_descriptor *desc) ...@@ -304,15 +312,15 @@ static int nfs_pagein_multi(struct nfs_pageio_descriptor *desc)
do { do {
int ret2; int ret2;
data = list_entry(list.next, struct nfs_read_data, pages); data = list_entry(list.next, struct nfs_read_data, list);
list_del_init(&data->pages); list_del_init(&data->list);
data->pagevec[0] = page; data->pagevec[0] = page;
if (nbytes < rsize) if (nbytes < rsize)
rsize = nbytes; rsize = nbytes;
ret2 = nfs_read_rpcsetup(req, data, &nfs_read_partial_ops, nfs_read_rpcsetup(req, data, rsize, offset);
rsize, offset, lseg); ret2 = nfs_do_read(data, &nfs_read_partial_ops, lseg);
if (ret == 0) if (ret == 0)
ret = ret2; ret = ret2;
offset += rsize; offset += rsize;
...@@ -325,8 +333,8 @@ static int nfs_pagein_multi(struct nfs_pageio_descriptor *desc) ...@@ -325,8 +333,8 @@ static int nfs_pagein_multi(struct nfs_pageio_descriptor *desc)
out_bad: out_bad:
while (!list_empty(&list)) { while (!list_empty(&list)) {
data = list_entry(list.next, struct nfs_read_data, pages); data = list_entry(list.next, struct nfs_read_data, list);
list_del(&data->pages); list_del(&data->list);
nfs_readdata_free(data); nfs_readdata_free(data);
} }
SetPageError(page); SetPageError(page);
...@@ -362,8 +370,8 @@ static int nfs_pagein_one(struct nfs_pageio_descriptor *desc) ...@@ -362,8 +370,8 @@ static int nfs_pagein_one(struct nfs_pageio_descriptor *desc)
} }
req = nfs_list_entry(data->pages.next); req = nfs_list_entry(data->pages.next);
ret = nfs_read_rpcsetup(req, data, &nfs_read_full_ops, desc->pg_count, nfs_read_rpcsetup(req, data, desc->pg_count, 0);
0, lseg); ret = nfs_do_read(data, &nfs_read_full_ops, lseg);
out: out:
put_lseg(lseg); put_lseg(lseg);
desc->pg_lseg = NULL; desc->pg_lseg = NULL;
......
...@@ -845,11 +845,9 @@ EXPORT_SYMBOL_GPL(nfs_initiate_write); ...@@ -845,11 +845,9 @@ EXPORT_SYMBOL_GPL(nfs_initiate_write);
/* /*
* Set up the argument/result storage required for the RPC call. * Set up the argument/result storage required for the RPC call.
*/ */
static int nfs_write_rpcsetup(struct nfs_page *req, static void nfs_write_rpcsetup(struct nfs_page *req,
struct nfs_write_data *data, struct nfs_write_data *data,
const struct rpc_call_ops *call_ops,
unsigned int count, unsigned int offset, unsigned int count, unsigned int offset,
struct pnfs_layout_segment *lseg,
int how) int how)
{ {
struct inode *inode = req->wb_context->path.dentry->d_inode; struct inode *inode = req->wb_context->path.dentry->d_inode;
...@@ -860,7 +858,6 @@ static int nfs_write_rpcsetup(struct nfs_page *req, ...@@ -860,7 +858,6 @@ static int nfs_write_rpcsetup(struct nfs_page *req,
data->req = req; data->req = req;
data->inode = inode = req->wb_context->path.dentry->d_inode; data->inode = inode = req->wb_context->path.dentry->d_inode;
data->cred = req->wb_context->cred; data->cred = req->wb_context->cred;
data->lseg = get_lseg(lseg);
data->args.fh = NFS_FH(inode); data->args.fh = NFS_FH(inode);
data->args.offset = req_offset(req) + offset; data->args.offset = req_offset(req) + offset;
...@@ -886,10 +883,22 @@ static int nfs_write_rpcsetup(struct nfs_page *req, ...@@ -886,10 +883,22 @@ static int nfs_write_rpcsetup(struct nfs_page *req,
data->res.count = count; data->res.count = count;
data->res.verf = &data->verf; data->res.verf = &data->verf;
nfs_fattr_init(&data->fattr); nfs_fattr_init(&data->fattr);
}
if (data->lseg && static int nfs_do_write(struct nfs_write_data *data,
(pnfs_try_to_write_data(data, call_ops, how) == PNFS_ATTEMPTED)) const struct rpc_call_ops *call_ops,
return 0; struct pnfs_layout_segment *lseg,
int how)
{
struct inode *inode = data->args.context->path.dentry->d_inode;
if (lseg != NULL) {
data->lseg = get_lseg(lseg);
if (pnfs_try_to_write_data(data, call_ops, how) == PNFS_ATTEMPTED)
return 0;
put_lseg(data->lseg);
data->lseg = NULL;
}
return nfs_initiate_write(data, NFS_CLIENT(inode), call_ops, how); return nfs_initiate_write(data, NFS_CLIENT(inode), call_ops, how);
} }
...@@ -938,7 +947,7 @@ static int nfs_flush_multi(struct nfs_pageio_descriptor *desc) ...@@ -938,7 +947,7 @@ static int nfs_flush_multi(struct nfs_pageio_descriptor *desc)
data = nfs_writedata_alloc(1); data = nfs_writedata_alloc(1);
if (!data) if (!data)
goto out_bad; goto out_bad;
list_add(&data->pages, &list); list_add(&data->list, &list);
requests++; requests++;
nbytes -= len; nbytes -= len;
} while (nbytes != 0); } while (nbytes != 0);
...@@ -950,15 +959,16 @@ static int nfs_flush_multi(struct nfs_pageio_descriptor *desc) ...@@ -950,15 +959,16 @@ static int nfs_flush_multi(struct nfs_pageio_descriptor *desc)
do { do {
int ret2; int ret2;
data = list_entry(list.next, struct nfs_write_data, pages); data = list_entry(list.next, struct nfs_write_data, list);
list_del_init(&data->pages); list_del_init(&data->list);
data->pagevec[0] = page; data->pagevec[0] = page;
if (nbytes < wsize) if (nbytes < wsize)
wsize = nbytes; wsize = nbytes;
ret2 = nfs_write_rpcsetup(req, data, &nfs_write_partial_ops, nfs_write_rpcsetup(req, data, wsize, offset, desc->pg_ioflags);
wsize, offset, lseg, desc->pg_ioflags); ret2 = nfs_do_write(data, &nfs_write_partial_ops, lseg,
desc->pg_ioflags);
if (ret == 0) if (ret == 0)
ret = ret2; ret = ret2;
offset += wsize; offset += wsize;
...@@ -971,8 +981,8 @@ static int nfs_flush_multi(struct nfs_pageio_descriptor *desc) ...@@ -971,8 +981,8 @@ static int nfs_flush_multi(struct nfs_pageio_descriptor *desc)
out_bad: out_bad:
while (!list_empty(&list)) { while (!list_empty(&list)) {
data = list_entry(list.next, struct nfs_write_data, pages); data = list_entry(list.next, struct nfs_write_data, list);
list_del(&data->pages); list_del(&data->list);
nfs_writedata_free(data); nfs_writedata_free(data);
} }
nfs_redirty_request(req); nfs_redirty_request(req);
...@@ -1024,7 +1034,8 @@ static int nfs_flush_one(struct nfs_pageio_descriptor *desc) ...@@ -1024,7 +1034,8 @@ static int nfs_flush_one(struct nfs_pageio_descriptor *desc)
desc->pg_ioflags &= ~FLUSH_COND_STABLE; desc->pg_ioflags &= ~FLUSH_COND_STABLE;
/* Set up the argument struct */ /* Set up the argument struct */
ret = nfs_write_rpcsetup(req, data, &nfs_write_full_ops, desc->pg_count, 0, lseg, desc->pg_ioflags); nfs_write_rpcsetup(req, data, desc->pg_count, 0, desc->pg_ioflags);
ret = nfs_do_write(data, &nfs_write_full_ops, lseg, desc->pg_ioflags);
out: out:
put_lseg(lseg); /* Cleans any gotten in ->pg_test */ put_lseg(lseg); /* Cleans any gotten in ->pg_test */
desc->pg_lseg = NULL; desc->pg_lseg = NULL;
......
...@@ -1126,6 +1126,7 @@ struct nfs_read_data { ...@@ -1126,6 +1126,7 @@ struct nfs_read_data {
struct rpc_cred *cred; struct rpc_cred *cred;
struct nfs_fattr fattr; /* fattr storage */ struct nfs_fattr fattr; /* fattr storage */
struct list_head pages; /* Coalesced read requests */ struct list_head pages; /* Coalesced read requests */
struct list_head list; /* lists of struct nfs_read_data */
struct nfs_page *req; /* multi ops per nfs_page */ struct nfs_page *req; /* multi ops per nfs_page */
struct page **pagevec; struct page **pagevec;
unsigned int npages; /* Max length of pagevec */ unsigned int npages; /* Max length of pagevec */
...@@ -1149,6 +1150,7 @@ struct nfs_write_data { ...@@ -1149,6 +1150,7 @@ struct nfs_write_data {
struct nfs_fattr fattr; struct nfs_fattr fattr;
struct nfs_writeverf verf; struct nfs_writeverf verf;
struct list_head pages; /* Coalesced requests we wish to flush */ struct list_head pages; /* Coalesced requests we wish to flush */
struct list_head list; /* lists of struct nfs_write_data */
struct nfs_page *req; /* multi ops per nfs_page */ struct nfs_page *req; /* multi ops per nfs_page */
struct page **pagevec; struct page **pagevec;
unsigned int npages; /* Max length of pagevec */ unsigned int npages; /* Max length of pagevec */
......
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