Commit 6c75dc0d authored by Fred Isaman's avatar Fred Isaman Committed by Trond Myklebust

NFS: merge _full and _partial write rpc_ops

Decouple nfs_pgio_header and nfs_write_data, and have (possibly
multiple) nfs_write_datas each take a refcount on nfs_pgio_header.

For the moment keeps nfs_write_header as a way to preallocate a single
nfs_write_data with the nfs_pgio_header.  The code doesn't need this,
and would be prettier without, but given the amount of churn I am
already introducing I didn't want to play with tuning new mempools.

This also fixes bug in pnfs_ld_handle_write_error.  In the case of
desc->pg_bsize < PAGE_CACHE_SIZE, the pages list was empty, causing
replay attempt to do nothing.
Signed-off-by: default avatarFred Isaman <iisaman@netapp.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 4db6e0b7
...@@ -768,11 +768,17 @@ static ssize_t nfs_direct_write_schedule_segment(struct nfs_direct_req *dreq, ...@@ -768,11 +768,17 @@ static ssize_t nfs_direct_write_schedule_segment(struct nfs_direct_req *dreq,
bytes = min(wsize,count); bytes = min(wsize,count);
result = -ENOMEM; result = -ENOMEM;
whdr = nfs_writehdr_alloc(nfs_page_array_len(pgbase, bytes)); whdr = nfs_writehdr_alloc();
if (unlikely(!whdr)) if (unlikely(!whdr))
break; break;
data = &whdr->rpc_data; data = nfs_writedata_alloc(&whdr->header, nfs_page_array_len(pgbase, bytes));
if (!data) {
nfs_writehdr_free(&whdr->header);
break;
}
data->header = &whdr->header;
atomic_inc(&data->header->refcnt);
pages = &data->pages; pages = &data->pages;
down_read(&current->mm->mmap_sem); down_read(&current->mm->mmap_sem);
......
...@@ -319,10 +319,14 @@ extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio); ...@@ -319,10 +319,14 @@ extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
extern void nfs_readdata_release(struct nfs_read_data *rdata); extern void nfs_readdata_release(struct nfs_read_data *rdata);
/* write.c */ /* write.c */
extern struct nfs_write_header *nfs_writehdr_alloc(unsigned int npages); extern void nfs_async_write_error(struct list_head *head);
extern struct nfs_write_header *nfs_writehdr_alloc(void);
extern void nfs_writehdr_free(struct nfs_pgio_header *hdr); extern void nfs_writehdr_free(struct nfs_pgio_header *hdr);
extern struct nfs_write_data *nfs_writedata_alloc(struct nfs_pgio_header *hdr,
unsigned int pagecount);
extern void nfs_write_completion(struct nfs_pgio_header *hdr);
extern int nfs_generic_flush(struct nfs_pageio_descriptor *desc, extern int nfs_generic_flush(struct nfs_pageio_descriptor *desc,
struct list_head *head); struct nfs_pgio_header *hdr);
extern void nfs_pageio_init_write_mds(struct nfs_pageio_descriptor *pgio, extern void nfs_pageio_init_write_mds(struct nfs_pageio_descriptor *pgio,
struct inode *inode, int ioflags); struct inode *inode, int ioflags);
extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio); extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
......
...@@ -314,7 +314,6 @@ static void filelayout_write_release(void *data) ...@@ -314,7 +314,6 @@ static void filelayout_write_release(void *data)
{ {
struct nfs_write_data *wdata = data; struct nfs_write_data *wdata = data;
put_lseg(wdata->header->lseg);
wdata->header->mds_ops->rpc_release(data); wdata->header->mds_ops->rpc_release(data);
} }
......
...@@ -3431,8 +3431,6 @@ void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) ...@@ -3431,8 +3431,6 @@ void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data)
struct inode *inode = hdr->inode; struct inode *inode = hdr->inode;
dprintk("%s Reset task for i/o through\n", __func__); dprintk("%s Reset task for i/o through\n", __func__);
put_lseg(hdr->lseg);
hdr->lseg = NULL;
data->ds_clp = NULL; data->ds_clp = NULL;
data->write_done_cb = nfs4_write_done_cb; data->write_done_cb = nfs4_write_done_cb;
data->args.fh = NFS_FH(inode); data->args.fh = NFS_FH(inode);
...@@ -3448,7 +3446,7 @@ static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_messag ...@@ -3448,7 +3446,7 @@ static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_messag
{ {
struct nfs_server *server = NFS_SERVER(data->header->inode); struct nfs_server *server = NFS_SERVER(data->header->inode);
if (data->header->lseg) { if (data->ds_clp) {
data->args.bitmask = NULL; data->args.bitmask = NULL;
data->res.fattr = NULL; data->res.fattr = NULL;
} else } else
......
...@@ -1199,7 +1199,9 @@ static void pnfs_ld_handle_write_error(struct nfs_write_data *data) ...@@ -1199,7 +1199,9 @@ static void pnfs_ld_handle_write_error(struct nfs_write_data *data)
clear_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(hdr->inode)->flags); clear_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(hdr->inode)->flags);
pnfs_return_layout(hdr->inode); pnfs_return_layout(hdr->inode);
} }
data->task.tk_status = pnfs_write_done_resend_to_mds(hdr->inode, &hdr->pages); if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags))
data->task.tk_status = pnfs_write_done_resend_to_mds(hdr->inode,
&hdr->pages);
} }
/* /*
...@@ -1214,7 +1216,6 @@ void pnfs_ld_write_done(struct nfs_write_data *data) ...@@ -1214,7 +1216,6 @@ void pnfs_ld_write_done(struct nfs_write_data *data)
hdr->mds_ops->rpc_call_done(&data->task, data); hdr->mds_ops->rpc_call_done(&data->task, data);
} else } else
pnfs_ld_handle_write_error(data); pnfs_ld_handle_write_error(data);
put_lseg(hdr->lseg);
hdr->mds_ops->rpc_release(data); hdr->mds_ops->rpc_release(data);
} }
EXPORT_SYMBOL_GPL(pnfs_ld_write_done); EXPORT_SYMBOL_GPL(pnfs_ld_write_done);
...@@ -1225,12 +1226,11 @@ pnfs_write_through_mds(struct nfs_pageio_descriptor *desc, ...@@ -1225,12 +1226,11 @@ pnfs_write_through_mds(struct nfs_pageio_descriptor *desc,
{ {
struct nfs_pgio_header *hdr = data->header; struct nfs_pgio_header *hdr = data->header;
list_splice_tail_init(&hdr->pages, &desc->pg_list); if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
if (hdr->req && list_empty(&hdr->req->wb_list)) list_splice_tail_init(&hdr->pages, &desc->pg_list);
nfs_list_add_request(hdr->req, &desc->pg_list); nfs_pageio_reset_write_mds(desc);
nfs_pageio_reset_write_mds(desc); desc->pg_recoalesce = 1;
desc->pg_recoalesce = 1; }
put_lseg(hdr->lseg);
nfs_writedata_release(data); nfs_writedata_release(data);
} }
...@@ -1246,18 +1246,12 @@ pnfs_try_to_write_data(struct nfs_write_data *wdata, ...@@ -1246,18 +1246,12 @@ pnfs_try_to_write_data(struct nfs_write_data *wdata,
struct nfs_server *nfss = NFS_SERVER(inode); struct nfs_server *nfss = NFS_SERVER(inode);
hdr->mds_ops = call_ops; hdr->mds_ops = call_ops;
hdr->lseg = get_lseg(lseg);
dprintk("%s: Writing ino:%lu %u@%llu (how %d)\n", __func__, dprintk("%s: Writing ino:%lu %u@%llu (how %d)\n", __func__,
inode->i_ino, wdata->args.count, wdata->args.offset, how); inode->i_ino, wdata->args.count, wdata->args.offset, how);
trypnfs = nfss->pnfs_curr_ld->write_pagelist(wdata, how); trypnfs = nfss->pnfs_curr_ld->write_pagelist(wdata, how);
if (trypnfs == PNFS_NOT_ATTEMPTED) { if (trypnfs != PNFS_NOT_ATTEMPTED)
put_lseg(hdr->lseg);
hdr->lseg = NULL;
} else
nfs_inc_stats(inode, NFSIOS_PNFS_WRITE); nfs_inc_stats(inode, NFSIOS_PNFS_WRITE);
dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs); dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs);
return trypnfs; return trypnfs;
} }
...@@ -1273,7 +1267,7 @@ pnfs_do_multiple_writes(struct nfs_pageio_descriptor *desc, struct list_head *he ...@@ -1273,7 +1267,7 @@ pnfs_do_multiple_writes(struct nfs_pageio_descriptor *desc, struct list_head *he
while (!list_empty(head)) { while (!list_empty(head)) {
enum pnfs_try_status trypnfs; enum pnfs_try_status trypnfs;
data = list_entry(head->next, struct nfs_write_data, list); data = list_first_entry(head, struct nfs_write_data, list);
list_del_init(&data->list); list_del_init(&data->list);
trypnfs = pnfs_try_to_write_data(data, call_ops, lseg, how); trypnfs = pnfs_try_to_write_data(data, call_ops, lseg, how);
...@@ -1283,20 +1277,40 @@ pnfs_do_multiple_writes(struct nfs_pageio_descriptor *desc, struct list_head *he ...@@ -1283,20 +1277,40 @@ pnfs_do_multiple_writes(struct nfs_pageio_descriptor *desc, struct list_head *he
put_lseg(lseg); put_lseg(lseg);
} }
static void pnfs_writehdr_free(struct nfs_pgio_header *hdr)
{
put_lseg(hdr->lseg);
nfs_writehdr_free(hdr);
}
int int
pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc) pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc)
{ {
LIST_HEAD(head); struct nfs_write_header *whdr;
struct nfs_pgio_header *hdr;
int ret; int ret;
ret = nfs_generic_flush(desc, &head); whdr = nfs_writehdr_alloc();
if (ret != 0) { if (!whdr) {
nfs_async_write_error(&desc->pg_list);
put_lseg(desc->pg_lseg); put_lseg(desc->pg_lseg);
desc->pg_lseg = NULL; desc->pg_lseg = NULL;
return ret; return -ENOMEM;
} }
pnfs_do_multiple_writes(desc, &head, desc->pg_ioflags); hdr = &whdr->header;
return 0; nfs_pgheader_init(desc, hdr, pnfs_writehdr_free);
hdr->lseg = get_lseg(desc->pg_lseg);
atomic_inc(&hdr->refcnt);
ret = nfs_generic_flush(desc, hdr);
if (ret != 0) {
put_lseg(desc->pg_lseg);
desc->pg_lseg = NULL;
set_bit(NFS_IOHDR_REDO, &hdr->flags);
} else
pnfs_do_multiple_writes(desc, &hdr->rpc_list, desc->pg_ioflags);
if (atomic_dec_and_test(&hdr->refcnt))
nfs_write_completion(hdr);
return ret;
} }
EXPORT_SYMBOL_GPL(pnfs_generic_pg_writepages); EXPORT_SYMBOL_GPL(pnfs_generic_pg_writepages);
......
This diff is collapsed.
...@@ -1192,6 +1192,8 @@ enum { ...@@ -1192,6 +1192,8 @@ enum {
NFS_IOHDR_ERROR = 0, NFS_IOHDR_ERROR = 0,
NFS_IOHDR_EOF, NFS_IOHDR_EOF,
NFS_IOHDR_REDO, NFS_IOHDR_REDO,
NFS_IOHDR_NEED_COMMIT,
NFS_IOHDR_NEED_RESCHED,
}; };
struct nfs_pgio_header { struct nfs_pgio_header {
......
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