aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorAnna Schumaker <Anna.Schumaker@netapp.com>2014-05-06 09:12:37 -0400
committerTrond Myklebust <trond.myklebust@primarydata.com>2014-05-29 11:11:40 -0400
commit1ed26f33008e954a8e91d26f97d4380dea8145db (patch)
treea187a1fb9658ee39d5c00e71fd6105b7cb6d3f56 /fs/nfs
parentef2c488c073f4f0b3a200745dd8d608c01d69c39 (diff)
NFS: Create a common initiate_pgio() function
Most of this code is the same for both the read and write paths, so combine everything and use the rw_ops when necessary. Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/internal.h9
-rw-r--r--fs/nfs/nfs4filelayout.c6
-rw-r--r--fs/nfs/pagelist.c46
-rw-r--r--fs/nfs/read.c42
-rw-r--r--fs/nfs/write.c55
5 files changed, 64 insertions, 94 deletions
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 365cdb11d0de..be4f2a7e9178 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -241,6 +241,8 @@ struct nfs_rw_header *nfs_rw_header_alloc(const struct nfs_rw_ops *);
241void nfs_rw_header_free(struct nfs_pgio_header *); 241void nfs_rw_header_free(struct nfs_pgio_header *);
242void nfs_pgio_data_release(struct nfs_pgio_data *); 242void nfs_pgio_data_release(struct nfs_pgio_data *);
243int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *); 243int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
244int nfs_initiate_pgio(struct rpc_clnt *, struct nfs_pgio_data *,
245 const struct rpc_call_ops *, int, int);
244 246
245static inline void nfs_iocounter_init(struct nfs_io_counter *c) 247static inline void nfs_iocounter_init(struct nfs_io_counter *c)
246{ 248{
@@ -402,9 +404,6 @@ struct nfs_pgio_completion_ops;
402extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, 404extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
403 struct inode *inode, bool force_mds, 405 struct inode *inode, bool force_mds,
404 const struct nfs_pgio_completion_ops *compl_ops); 406 const struct nfs_pgio_completion_ops *compl_ops);
405extern int nfs_initiate_read(struct rpc_clnt *clnt,
406 struct nfs_pgio_data *data,
407 const struct rpc_call_ops *call_ops, int flags);
408extern void nfs_read_prepare(struct rpc_task *task, void *calldata); 407extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
409extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio); 408extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
410 409
@@ -425,10 +424,6 @@ extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
425 const struct nfs_pgio_completion_ops *compl_ops); 424 const struct nfs_pgio_completion_ops *compl_ops);
426extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio); 425extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
427extern void nfs_commit_free(struct nfs_commit_data *p); 426extern void nfs_commit_free(struct nfs_commit_data *p);
428extern int nfs_initiate_write(struct rpc_clnt *clnt,
429 struct nfs_pgio_data *data,
430 const struct rpc_call_ops *call_ops,
431 int how, int flags);
432extern void nfs_write_prepare(struct rpc_task *task, void *calldata); 427extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
433extern void nfs_commit_prepare(struct rpc_task *task, void *calldata); 428extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
434extern int nfs_initiate_commit(struct rpc_clnt *clnt, 429extern int nfs_initiate_commit(struct rpc_clnt *clnt,
diff --git a/fs/nfs/nfs4filelayout.c b/fs/nfs/nfs4filelayout.c
index e6936147ad95..7954e16a6d83 100644
--- a/fs/nfs/nfs4filelayout.c
+++ b/fs/nfs/nfs4filelayout.c
@@ -568,8 +568,8 @@ filelayout_read_pagelist(struct nfs_pgio_data *data)
568 data->mds_offset = offset; 568 data->mds_offset = offset;
569 569
570 /* Perform an asynchronous read to ds */ 570 /* Perform an asynchronous read to ds */
571 nfs_initiate_read(ds_clnt, data, 571 nfs_initiate_pgio(ds_clnt, data,
572 &filelayout_read_call_ops, RPC_TASK_SOFTCONN); 572 &filelayout_read_call_ops, 0, RPC_TASK_SOFTCONN);
573 return PNFS_ATTEMPTED; 573 return PNFS_ATTEMPTED;
574} 574}
575 575
@@ -613,7 +613,7 @@ filelayout_write_pagelist(struct nfs_pgio_data *data, int sync)
613 data->args.offset = filelayout_get_dserver_offset(lseg, offset); 613 data->args.offset = filelayout_get_dserver_offset(lseg, offset);
614 614
615 /* Perform an asynchronous write */ 615 /* Perform an asynchronous write */
616 nfs_initiate_write(ds_clnt, data, 616 nfs_initiate_pgio(ds_clnt, data,
617 &filelayout_write_call_ops, sync, 617 &filelayout_write_call_ops, sync,
618 RPC_TASK_SOFTCONN); 618 RPC_TASK_SOFTCONN);
619 return PNFS_ATTEMPTED; 619 return PNFS_ATTEMPTED;
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index d8d25a4deb88..ab5b1850ca4f 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -447,6 +447,52 @@ static void nfs_pgio_prepare(struct rpc_task *task, void *calldata)
447 rpc_exit(task, err); 447 rpc_exit(task, err);
448} 448}
449 449
450int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_data *data,
451 const struct rpc_call_ops *call_ops, int how, int flags)
452{
453 struct rpc_task *task;
454 struct rpc_message msg = {
455 .rpc_argp = &data->args,
456 .rpc_resp = &data->res,
457 .rpc_cred = data->header->cred,
458 };
459 struct rpc_task_setup task_setup_data = {
460 .rpc_client = clnt,
461 .task = &data->task,
462 .rpc_message = &msg,
463 .callback_ops = call_ops,
464 .callback_data = data,
465 .workqueue = nfsiod_workqueue,
466 .flags = RPC_TASK_ASYNC | flags,
467 };
468 int ret = 0;
469
470 data->header->rw_ops->rw_initiate(data, &msg, &task_setup_data, how);
471
472 dprintk("NFS: %5u initiated pgio call "
473 "(req %s/%llu, %u bytes @ offset %llu)\n",
474 data->task.tk_pid,
475 data->header->inode->i_sb->s_id,
476 (unsigned long long)NFS_FILEID(data->header->inode),
477 data->args.count,
478 (unsigned long long)data->args.offset);
479
480 task = rpc_run_task(&task_setup_data);
481 if (IS_ERR(task)) {
482 ret = PTR_ERR(task);
483 goto out;
484 }
485 if (how & FLUSH_SYNC) {
486 ret = rpc_wait_for_completion_task(task);
487 if (ret == 0)
488 ret = task->tk_status;
489 }
490 rpc_put_task(task);
491out:
492 return ret;
493}
494EXPORT_SYMBOL_GPL(nfs_initiate_pgio);
495
450/** 496/**
451 * nfs_pgio_error - Clean up from a pageio error 497 * nfs_pgio_error - Clean up from a pageio error
452 * @desc: IO descriptor 498 * @desc: IO descriptor
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index 4fcef82d78b4..0359b0d76ef6 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -151,53 +151,22 @@ out:
151 hdr->release(hdr); 151 hdr->release(hdr);
152} 152}
153 153
154int nfs_initiate_read(struct rpc_clnt *clnt, 154static void nfs_initiate_read(struct nfs_pgio_data *data, struct rpc_message *msg,
155 struct nfs_pgio_data *data, 155 struct rpc_task_setup *task_setup_data, int how)
156 const struct rpc_call_ops *call_ops, int flags)
157{ 156{
158 struct inode *inode = data->header->inode; 157 struct inode *inode = data->header->inode;
159 int swap_flags = IS_SWAPFILE(inode) ? NFS_RPC_SWAPFLAGS : 0; 158 int swap_flags = IS_SWAPFILE(inode) ? NFS_RPC_SWAPFLAGS : 0;
160 struct rpc_task *task;
161 struct rpc_message msg = {
162 .rpc_argp = &data->args,
163 .rpc_resp = &data->res,
164 .rpc_cred = data->header->cred,
165 };
166 struct rpc_task_setup task_setup_data = {
167 .task = &data->task,
168 .rpc_client = clnt,
169 .rpc_message = &msg,
170 .callback_ops = call_ops,
171 .callback_data = data,
172 .workqueue = nfsiod_workqueue,
173 .flags = RPC_TASK_ASYNC | swap_flags | flags,
174 };
175 159
176 /* Set up the initial task struct. */ 160 task_setup_data->flags |= swap_flags;
177 NFS_PROTO(inode)->read_setup(data, &msg); 161 NFS_PROTO(inode)->read_setup(data, msg);
178
179 dprintk("NFS: %5u initiated read call (req %s/%llu, %u bytes @ "
180 "offset %llu)\n",
181 data->task.tk_pid,
182 inode->i_sb->s_id,
183 (unsigned long long)NFS_FILEID(inode),
184 data->args.count,
185 (unsigned long long)data->args.offset);
186
187 task = rpc_run_task(&task_setup_data);
188 if (IS_ERR(task))
189 return PTR_ERR(task);
190 rpc_put_task(task);
191 return 0;
192} 162}
193EXPORT_SYMBOL_GPL(nfs_initiate_read);
194 163
195static int nfs_do_read(struct nfs_pgio_data *data, 164static int nfs_do_read(struct nfs_pgio_data *data,
196 const struct rpc_call_ops *call_ops) 165 const struct rpc_call_ops *call_ops)
197{ 166{
198 struct inode *inode = data->header->inode; 167 struct inode *inode = data->header->inode;
199 168
200 return nfs_initiate_read(NFS_CLIENT(inode), data, call_ops, 0); 169 return nfs_initiate_pgio(NFS_CLIENT(inode), data, call_ops, 0, 0);
201} 170}
202 171
203static int 172static int
@@ -491,4 +460,5 @@ static const struct nfs_rw_ops nfs_rw_read_ops = {
491 .rw_free_header = nfs_readhdr_free, 460 .rw_free_header = nfs_readhdr_free,
492 .rw_done = nfs_readpage_done, 461 .rw_done = nfs_readpage_done,
493 .rw_result = nfs_readpage_result, 462 .rw_result = nfs_readpage_result,
463 .rw_initiate = nfs_initiate_read,
494}; 464};
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 0e34c7024195..e46a1fc6c1fe 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -932,60 +932,18 @@ static int flush_task_priority(int how)
932 return RPC_PRIORITY_NORMAL; 932 return RPC_PRIORITY_NORMAL;
933} 933}
934 934
935int nfs_initiate_write(struct rpc_clnt *clnt, 935static void nfs_initiate_write(struct nfs_pgio_data *data, struct rpc_message *msg,
936 struct nfs_pgio_data *data, 936 struct rpc_task_setup *task_setup_data, int how)
937 const struct rpc_call_ops *call_ops,
938 int how, int flags)
939{ 937{
940 struct inode *inode = data->header->inode; 938 struct inode *inode = data->header->inode;
941 int priority = flush_task_priority(how); 939 int priority = flush_task_priority(how);
942 struct rpc_task *task;
943 struct rpc_message msg = {
944 .rpc_argp = &data->args,
945 .rpc_resp = &data->res,
946 .rpc_cred = data->header->cred,
947 };
948 struct rpc_task_setup task_setup_data = {
949 .rpc_client = clnt,
950 .task = &data->task,
951 .rpc_message = &msg,
952 .callback_ops = call_ops,
953 .callback_data = data,
954 .workqueue = nfsiod_workqueue,
955 .flags = RPC_TASK_ASYNC | flags,
956 .priority = priority,
957 };
958 int ret = 0;
959 940
960 /* Set up the initial task struct. */ 941 task_setup_data->priority = priority;
961 NFS_PROTO(inode)->write_setup(data, &msg); 942 NFS_PROTO(inode)->write_setup(data, msg);
962
963 dprintk("NFS: %5u initiated write call "
964 "(req %s/%llu, %u bytes @ offset %llu)\n",
965 data->task.tk_pid,
966 inode->i_sb->s_id,
967 (unsigned long long)NFS_FILEID(inode),
968 data->args.count,
969 (unsigned long long)data->args.offset);
970 943
971 nfs4_state_protect_write(NFS_SERVER(inode)->nfs_client, 944 nfs4_state_protect_write(NFS_SERVER(inode)->nfs_client,
972 &task_setup_data.rpc_client, &msg, data); 945 &task_setup_data->rpc_client, msg, data);
973
974 task = rpc_run_task(&task_setup_data);
975 if (IS_ERR(task)) {
976 ret = PTR_ERR(task);
977 goto out;
978 }
979 if (how & FLUSH_SYNC) {
980 ret = rpc_wait_for_completion_task(task);
981 if (ret == 0)
982 ret = task->tk_status;
983 }
984 rpc_put_task(task);
985out:
986 return ret;
987} 946}
988EXPORT_SYMBOL_GPL(nfs_initiate_write);
989 947
990static int nfs_do_write(struct nfs_pgio_data *data, 948static int nfs_do_write(struct nfs_pgio_data *data,
991 const struct rpc_call_ops *call_ops, 949 const struct rpc_call_ops *call_ops,
@@ -993,7 +951,7 @@ static int nfs_do_write(struct nfs_pgio_data *data,
993{ 951{
994 struct inode *inode = data->header->inode; 952 struct inode *inode = data->header->inode;
995 953
996 return nfs_initiate_write(NFS_CLIENT(inode), data, call_ops, how, 0); 954 return nfs_initiate_pgio(NFS_CLIENT(inode), data, call_ops, how, 0);
997} 955}
998 956
999static int nfs_do_multiple_writes(struct list_head *head, 957static int nfs_do_multiple_writes(struct list_head *head,
@@ -1743,4 +1701,5 @@ static const struct nfs_rw_ops nfs_rw_write_ops = {
1743 .rw_release = nfs_writeback_release_common, 1701 .rw_release = nfs_writeback_release_common,
1744 .rw_done = nfs_writeback_done, 1702 .rw_done = nfs_writeback_done,
1745 .rw_result = nfs_writeback_result, 1703 .rw_result = nfs_writeback_result,
1704 .rw_initiate = nfs_initiate_write,
1746}; 1705};