diff options
author | Anna Schumaker <Anna.Schumaker@netapp.com> | 2014-05-06 09:12:34 -0400 |
---|---|---|
committer | Trond Myklebust <trond.myklebust@primarydata.com> | 2014-05-28 18:40:56 -0400 |
commit | ce59515c1484d3a01bc2f3e7043dc488d25efe34 (patch) | |
tree | 00c371ca81a26280eab34ad96fae8ca9c95d940d | |
parent | 6f92fa4581f1c26562f80dc686b3c9ea76556911 (diff) |
NFS: Create a common rpcsetup function for reads and writes
Write adds a little bit of code dealing with flush flags, but since
"how" will always be 0 when reading we can share the code.
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
-rw-r--r-- | fs/nfs/internal.h | 3 | ||||
-rw-r--r-- | fs/nfs/pagelist.c | 44 | ||||
-rw-r--r-- | fs/nfs/read.c | 26 | ||||
-rw-r--r-- | fs/nfs/write.c | 46 |
4 files changed, 53 insertions, 66 deletions
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index e34220f10165..519864b3296a 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h | |||
@@ -242,6 +242,8 @@ struct nfs_rw_header *nfs_rw_header_alloc(const struct nfs_rw_ops *); | |||
242 | void nfs_rw_header_free(struct nfs_pgio_header *); | 242 | void nfs_rw_header_free(struct nfs_pgio_header *); |
243 | struct nfs_pgio_data *nfs_pgio_data_alloc(struct nfs_pgio_header *, unsigned int); | 243 | struct nfs_pgio_data *nfs_pgio_data_alloc(struct nfs_pgio_header *, unsigned int); |
244 | void nfs_pgio_data_release(struct nfs_pgio_data *); | 244 | void nfs_pgio_data_release(struct nfs_pgio_data *); |
245 | void nfs_pgio_rpcsetup(struct nfs_pgio_data *, unsigned int, unsigned int, int, | ||
246 | struct nfs_commit_info *); | ||
245 | 247 | ||
246 | static inline void nfs_iocounter_init(struct nfs_io_counter *c) | 248 | static inline void nfs_iocounter_init(struct nfs_io_counter *c) |
247 | { | 249 | { |
@@ -446,6 +448,7 @@ extern void nfs_init_commit(struct nfs_commit_data *data, | |||
446 | struct nfs_commit_info *cinfo); | 448 | struct nfs_commit_info *cinfo); |
447 | int nfs_scan_commit_list(struct list_head *src, struct list_head *dst, | 449 | int nfs_scan_commit_list(struct list_head *src, struct list_head *dst, |
448 | struct nfs_commit_info *cinfo, int max); | 450 | struct nfs_commit_info *cinfo, int max); |
451 | unsigned long nfs_reqs_to_commit(struct nfs_commit_info *); | ||
449 | int nfs_scan_commit(struct inode *inode, struct list_head *dst, | 452 | int nfs_scan_commit(struct inode *inode, struct list_head *dst, |
450 | struct nfs_commit_info *cinfo); | 453 | struct nfs_commit_info *cinfo); |
451 | void nfs_mark_request_commit(struct nfs_page *req, | 454 | void nfs_mark_request_commit(struct nfs_page *req, |
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index aabff78dc6e5..0ccd95116968 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c | |||
@@ -389,6 +389,50 @@ void nfs_pgio_data_release(struct nfs_pgio_data *data) | |||
389 | EXPORT_SYMBOL_GPL(nfs_pgio_data_release); | 389 | EXPORT_SYMBOL_GPL(nfs_pgio_data_release); |
390 | 390 | ||
391 | /** | 391 | /** |
392 | * nfs_pgio_rpcsetup - Set up arguments for a pageio call | ||
393 | * @data: The pageio data | ||
394 | * @count: Number of bytes to read | ||
395 | * @offset: Initial offset | ||
396 | * @how: How to commit data (writes only) | ||
397 | * @cinfo: Commit information for the call (writes only) | ||
398 | */ | ||
399 | void nfs_pgio_rpcsetup(struct nfs_pgio_data *data, | ||
400 | unsigned int count, unsigned int offset, | ||
401 | int how, struct nfs_commit_info *cinfo) | ||
402 | { | ||
403 | struct nfs_page *req = data->header->req; | ||
404 | |||
405 | /* Set up the RPC argument and reply structs | ||
406 | * NB: take care not to mess about with data->commit et al. */ | ||
407 | |||
408 | data->args.fh = NFS_FH(data->header->inode); | ||
409 | data->args.offset = req_offset(req) + offset; | ||
410 | /* pnfs_set_layoutcommit needs this */ | ||
411 | data->mds_offset = data->args.offset; | ||
412 | data->args.pgbase = req->wb_pgbase + offset; | ||
413 | data->args.pages = data->pages.pagevec; | ||
414 | data->args.count = count; | ||
415 | data->args.context = get_nfs_open_context(req->wb_context); | ||
416 | data->args.lock_context = req->wb_lock_context; | ||
417 | data->args.stable = NFS_UNSTABLE; | ||
418 | switch (how & (FLUSH_STABLE | FLUSH_COND_STABLE)) { | ||
419 | case 0: | ||
420 | break; | ||
421 | case FLUSH_COND_STABLE: | ||
422 | if (nfs_reqs_to_commit(cinfo)) | ||
423 | break; | ||
424 | default: | ||
425 | data->args.stable = NFS_FILE_SYNC; | ||
426 | } | ||
427 | |||
428 | data->res.fattr = &data->fattr; | ||
429 | data->res.count = count; | ||
430 | data->res.eof = 0; | ||
431 | data->res.verf = &data->verf; | ||
432 | nfs_fattr_init(&data->fattr); | ||
433 | } | ||
434 | |||
435 | /** | ||
392 | * nfs_pgio_prepare - Prepare pageio data to go over the wire | 436 | * nfs_pgio_prepare - Prepare pageio data to go over the wire |
393 | * @task: The current task | 437 | * @task: The current task |
394 | * @calldata: pageio data to prepare | 438 | * @calldata: pageio data to prepare |
diff --git a/fs/nfs/read.c b/fs/nfs/read.c index a33490c0899f..0c88c60fbee9 100644 --- a/fs/nfs/read.c +++ b/fs/nfs/read.c | |||
@@ -192,28 +192,6 @@ int nfs_initiate_read(struct rpc_clnt *clnt, | |||
192 | } | 192 | } |
193 | EXPORT_SYMBOL_GPL(nfs_initiate_read); | 193 | EXPORT_SYMBOL_GPL(nfs_initiate_read); |
194 | 194 | ||
195 | /* | ||
196 | * Set up the NFS read request struct | ||
197 | */ | ||
198 | static void nfs_read_rpcsetup(struct nfs_pgio_data *data, | ||
199 | unsigned int count, unsigned int offset) | ||
200 | { | ||
201 | struct nfs_page *req = data->header->req; | ||
202 | |||
203 | data->args.fh = NFS_FH(data->header->inode); | ||
204 | data->args.offset = req_offset(req) + offset; | ||
205 | data->args.pgbase = req->wb_pgbase + offset; | ||
206 | data->args.pages = data->pages.pagevec; | ||
207 | data->args.count = count; | ||
208 | data->args.context = get_nfs_open_context(req->wb_context); | ||
209 | data->args.lock_context = req->wb_lock_context; | ||
210 | |||
211 | data->res.fattr = &data->fattr; | ||
212 | data->res.count = count; | ||
213 | data->res.eof = 0; | ||
214 | nfs_fattr_init(&data->fattr); | ||
215 | } | ||
216 | |||
217 | static int nfs_do_read(struct nfs_pgio_data *data, | 195 | static int nfs_do_read(struct nfs_pgio_data *data, |
218 | const struct rpc_call_ops *call_ops) | 196 | const struct rpc_call_ops *call_ops) |
219 | { | 197 | { |
@@ -305,7 +283,7 @@ static int nfs_pagein_multi(struct nfs_pageio_descriptor *desc, | |||
305 | return -ENOMEM; | 283 | return -ENOMEM; |
306 | } | 284 | } |
307 | data->pages.pagevec[0] = page; | 285 | data->pages.pagevec[0] = page; |
308 | nfs_read_rpcsetup(data, len, offset); | 286 | nfs_pgio_rpcsetup(data, len, offset, 0, NULL); |
309 | list_add(&data->list, &hdr->rpc_list); | 287 | list_add(&data->list, &hdr->rpc_list); |
310 | nbytes -= len; | 288 | nbytes -= len; |
311 | offset += len; | 289 | offset += len; |
@@ -340,7 +318,7 @@ static int nfs_pagein_one(struct nfs_pageio_descriptor *desc, | |||
340 | *pages++ = req->wb_page; | 318 | *pages++ = req->wb_page; |
341 | } | 319 | } |
342 | 320 | ||
343 | nfs_read_rpcsetup(data, desc->pg_count, 0); | 321 | nfs_pgio_rpcsetup(data, desc->pg_count, 0, 0, NULL); |
344 | list_add(&data->list, &hdr->rpc_list); | 322 | list_add(&data->list, &hdr->rpc_list); |
345 | desc->pg_rpc_callops = &nfs_pgio_common_ops; | 323 | desc->pg_rpc_callops = &nfs_pgio_common_ops; |
346 | return 0; | 324 | return 0; |
diff --git a/fs/nfs/write.c b/fs/nfs/write.c index d877f15fb31a..0d367aa87814 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c | |||
@@ -603,7 +603,7 @@ out: | |||
603 | } | 603 | } |
604 | 604 | ||
605 | #if IS_ENABLED(CONFIG_NFS_V3) || IS_ENABLED(CONFIG_NFS_V4) | 605 | #if IS_ENABLED(CONFIG_NFS_V3) || IS_ENABLED(CONFIG_NFS_V4) |
606 | static unsigned long | 606 | unsigned long |
607 | nfs_reqs_to_commit(struct nfs_commit_info *cinfo) | 607 | nfs_reqs_to_commit(struct nfs_commit_info *cinfo) |
608 | { | 608 | { |
609 | return cinfo->mds->ncommit; | 609 | return cinfo->mds->ncommit; |
@@ -660,7 +660,7 @@ nfs_scan_commit(struct inode *inode, struct list_head *dst, | |||
660 | } | 660 | } |
661 | 661 | ||
662 | #else | 662 | #else |
663 | static unsigned long nfs_reqs_to_commit(struct nfs_commit_info *cinfo) | 663 | unsigned long nfs_reqs_to_commit(struct nfs_commit_info *cinfo) |
664 | { | 664 | { |
665 | return 0; | 665 | return 0; |
666 | } | 666 | } |
@@ -987,44 +987,6 @@ out: | |||
987 | } | 987 | } |
988 | EXPORT_SYMBOL_GPL(nfs_initiate_write); | 988 | EXPORT_SYMBOL_GPL(nfs_initiate_write); |
989 | 989 | ||
990 | /* | ||
991 | * Set up the argument/result storage required for the RPC call. | ||
992 | */ | ||
993 | static void nfs_write_rpcsetup(struct nfs_pgio_data *data, | ||
994 | unsigned int count, unsigned int offset, | ||
995 | int how, struct nfs_commit_info *cinfo) | ||
996 | { | ||
997 | struct nfs_page *req = data->header->req; | ||
998 | |||
999 | /* Set up the RPC argument and reply structs | ||
1000 | * NB: take care not to mess about with data->commit et al. */ | ||
1001 | |||
1002 | data->args.fh = NFS_FH(data->header->inode); | ||
1003 | data->args.offset = req_offset(req) + offset; | ||
1004 | /* pnfs_set_layoutcommit needs this */ | ||
1005 | data->mds_offset = data->args.offset; | ||
1006 | data->args.pgbase = req->wb_pgbase + offset; | ||
1007 | data->args.pages = data->pages.pagevec; | ||
1008 | data->args.count = count; | ||
1009 | data->args.context = get_nfs_open_context(req->wb_context); | ||
1010 | data->args.lock_context = req->wb_lock_context; | ||
1011 | data->args.stable = NFS_UNSTABLE; | ||
1012 | switch (how & (FLUSH_STABLE | FLUSH_COND_STABLE)) { | ||
1013 | case 0: | ||
1014 | break; | ||
1015 | case FLUSH_COND_STABLE: | ||
1016 | if (nfs_reqs_to_commit(cinfo)) | ||
1017 | break; | ||
1018 | default: | ||
1019 | data->args.stable = NFS_FILE_SYNC; | ||
1020 | } | ||
1021 | |||
1022 | data->res.fattr = &data->fattr; | ||
1023 | data->res.count = count; | ||
1024 | data->res.verf = &data->verf; | ||
1025 | nfs_fattr_init(&data->fattr); | ||
1026 | } | ||
1027 | |||
1028 | static int nfs_do_write(struct nfs_pgio_data *data, | 990 | static int nfs_do_write(struct nfs_pgio_data *data, |
1029 | const struct rpc_call_ops *call_ops, | 991 | const struct rpc_call_ops *call_ops, |
1030 | int how) | 992 | int how) |
@@ -1129,7 +1091,7 @@ static int nfs_flush_multi(struct nfs_pageio_descriptor *desc, | |||
1129 | return -ENOMEM; | 1091 | return -ENOMEM; |
1130 | } | 1092 | } |
1131 | data->pages.pagevec[0] = page; | 1093 | data->pages.pagevec[0] = page; |
1132 | nfs_write_rpcsetup(data, len, offset, desc->pg_ioflags, &cinfo); | 1094 | nfs_pgio_rpcsetup(data, len, offset, desc->pg_ioflags, &cinfo); |
1133 | list_add(&data->list, &hdr->rpc_list); | 1095 | list_add(&data->list, &hdr->rpc_list); |
1134 | requests++; | 1096 | requests++; |
1135 | nbytes -= len; | 1097 | nbytes -= len; |
@@ -1179,7 +1141,7 @@ static int nfs_flush_one(struct nfs_pageio_descriptor *desc, | |||
1179 | desc->pg_ioflags &= ~FLUSH_COND_STABLE; | 1141 | desc->pg_ioflags &= ~FLUSH_COND_STABLE; |
1180 | 1142 | ||
1181 | /* Set up the argument struct */ | 1143 | /* Set up the argument struct */ |
1182 | nfs_write_rpcsetup(data, desc->pg_count, 0, desc->pg_ioflags, &cinfo); | 1144 | nfs_pgio_rpcsetup(data, desc->pg_count, 0, desc->pg_ioflags, &cinfo); |
1183 | list_add(&data->list, &hdr->rpc_list); | 1145 | list_add(&data->list, &hdr->rpc_list); |
1184 | desc->pg_rpc_callops = &nfs_pgio_common_ops; | 1146 | desc->pg_rpc_callops = &nfs_pgio_common_ops; |
1185 | return 0; | 1147 | return 0; |