summaryrefslogtreecommitdiffstats
path: root/fs/nfs/write.c
diff options
context:
space:
mode:
authorAnna Schumaker <Anna.Schumaker@netapp.com>2014-05-06 09:12:30 -0400
committerTrond Myklebust <trond.myklebust@primarydata.com>2014-05-28 18:40:04 -0400
commit4a0de55c565a36cac8422b76a948c4634a90781e (patch)
tree749ab695ab23756f1f7c791a17a2125eac993d9c /fs/nfs/write.c
parent00bfa30abe86982ce1929e9cabd703e5546106bd (diff)
NFS: Create a common rw_header_alloc and rw_header_free function
I create a new struct nfs_rw_ops to decide the differences between reads and writes. This struct will be set when initializing a new nfs_pgio_descriptor, and then passed on to the nfs_rw_header when a new header is allocated. Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Diffstat (limited to 'fs/nfs/write.c')
-rw-r--r--fs/nfs/write.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 0dc4d6a28bd0..9c5cde38da45 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -46,6 +46,7 @@ static const struct rpc_call_ops nfs_write_common_ops;
46static const struct rpc_call_ops nfs_commit_ops; 46static const struct rpc_call_ops nfs_commit_ops;
47static const struct nfs_pgio_completion_ops nfs_async_write_completion_ops; 47static const struct nfs_pgio_completion_ops nfs_async_write_completion_ops;
48static const struct nfs_commit_completion_ops nfs_commit_completion_ops; 48static const struct nfs_commit_completion_ops nfs_commit_completion_ops;
49static const struct nfs_rw_ops nfs_rw_write_ops;
49 50
50static struct kmem_cache *nfs_wdata_cachep; 51static struct kmem_cache *nfs_wdata_cachep;
51static mempool_t *nfs_wdata_mempool; 52static mempool_t *nfs_wdata_mempool;
@@ -70,29 +71,19 @@ void nfs_commit_free(struct nfs_commit_data *p)
70} 71}
71EXPORT_SYMBOL_GPL(nfs_commit_free); 72EXPORT_SYMBOL_GPL(nfs_commit_free);
72 73
73struct nfs_rw_header *nfs_writehdr_alloc(void) 74static struct nfs_rw_header *nfs_writehdr_alloc(void)
74{ 75{
75 struct nfs_rw_header *p = mempool_alloc(nfs_wdata_mempool, GFP_NOIO); 76 struct nfs_rw_header *p = mempool_alloc(nfs_wdata_mempool, GFP_NOIO);
76 77
77 if (p) { 78 if (p)
78 struct nfs_pgio_header *hdr = &p->header;
79
80 memset(p, 0, sizeof(*p)); 79 memset(p, 0, sizeof(*p));
81 INIT_LIST_HEAD(&hdr->pages);
82 INIT_LIST_HEAD(&hdr->rpc_list);
83 spin_lock_init(&hdr->lock);
84 atomic_set(&hdr->refcnt, 0);
85 }
86 return p; 80 return p;
87} 81}
88EXPORT_SYMBOL_GPL(nfs_writehdr_alloc);
89 82
90void nfs_writehdr_free(struct nfs_pgio_header *hdr) 83static void nfs_writehdr_free(struct nfs_rw_header *whdr)
91{ 84{
92 struct nfs_rw_header *whdr = container_of(hdr, struct nfs_rw_header, header);
93 mempool_free(whdr, nfs_wdata_mempool); 85 mempool_free(whdr, nfs_wdata_mempool);
94} 86}
95EXPORT_SYMBOL_GPL(nfs_writehdr_free);
96 87
97static void nfs_context_set_write_error(struct nfs_open_context *ctx, int error) 88static void nfs_context_set_write_error(struct nfs_open_context *ctx, int error)
98{ 89{
@@ -1210,13 +1201,13 @@ static int nfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc)
1210 struct nfs_pgio_header *hdr; 1201 struct nfs_pgio_header *hdr;
1211 int ret; 1202 int ret;
1212 1203
1213 whdr = nfs_writehdr_alloc(); 1204 whdr = nfs_rw_header_alloc(desc->pg_rw_ops);
1214 if (!whdr) { 1205 if (!whdr) {
1215 desc->pg_completion_ops->error_cleanup(&desc->pg_list); 1206 desc->pg_completion_ops->error_cleanup(&desc->pg_list);
1216 return -ENOMEM; 1207 return -ENOMEM;
1217 } 1208 }
1218 hdr = &whdr->header; 1209 hdr = &whdr->header;
1219 nfs_pgheader_init(desc, hdr, nfs_writehdr_free); 1210 nfs_pgheader_init(desc, hdr, nfs_rw_header_free);
1220 atomic_inc(&hdr->refcnt); 1211 atomic_inc(&hdr->refcnt);
1221 ret = nfs_generic_flush(desc, hdr); 1212 ret = nfs_generic_flush(desc, hdr);
1222 if (ret == 0) 1213 if (ret == 0)
@@ -1244,7 +1235,8 @@ void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
1244 if (server->pnfs_curr_ld && !force_mds) 1235 if (server->pnfs_curr_ld && !force_mds)
1245 pg_ops = server->pnfs_curr_ld->pg_write_ops; 1236 pg_ops = server->pnfs_curr_ld->pg_write_ops;
1246#endif 1237#endif
1247 nfs_pageio_init(pgio, inode, pg_ops, compl_ops, server->wsize, ioflags); 1238 nfs_pageio_init(pgio, inode, pg_ops, compl_ops, &nfs_rw_write_ops,
1239 server->wsize, ioflags);
1248} 1240}
1249EXPORT_SYMBOL_GPL(nfs_pageio_init_write); 1241EXPORT_SYMBOL_GPL(nfs_pageio_init_write);
1250 1242
@@ -1925,3 +1917,7 @@ void nfs_destroy_writepagecache(void)
1925 kmem_cache_destroy(nfs_wdata_cachep); 1917 kmem_cache_destroy(nfs_wdata_cachep);
1926} 1918}
1927 1919
1920static const struct nfs_rw_ops nfs_rw_write_ops = {
1921 .rw_alloc_header = nfs_writehdr_alloc,
1922 .rw_free_header = nfs_writehdr_free,
1923};