diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2014-03-04 21:53:33 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2014-05-06 17:32:44 -0400 |
commit | 619d30b4b8c488042b4a720ca79dccc346d1a516 (patch) | |
tree | 70877e3e8e2e47032512bc49d9e23cabd33c0f3b /fs | |
parent | d8d3d94b80aa1a1c0ca75c58b8abdc7356f38418 (diff) |
convert the guts of nfs_direct_IO() to iov_iter
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/nfs/direct.c | 46 | ||||
-rw-r--r-- | fs/nfs/file.c | 18 |
2 files changed, 33 insertions, 31 deletions
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index e9cde3935001..21723149668b 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c | |||
@@ -132,9 +132,9 @@ ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, loff_t | |||
132 | VM_BUG_ON(iocb->ki_nbytes != PAGE_SIZE); | 132 | VM_BUG_ON(iocb->ki_nbytes != PAGE_SIZE); |
133 | 133 | ||
134 | if (rw == READ || rw == KERNEL_READ) | 134 | if (rw == READ || rw == KERNEL_READ) |
135 | return nfs_file_direct_read(iocb, iter->iov, iter->nr_segs, pos, | 135 | return nfs_file_direct_read(iocb, iter, pos, |
136 | rw == READ ? true : false); | 136 | rw == READ ? true : false); |
137 | return nfs_file_direct_write(iocb, iter->iov, iter->nr_segs, pos, | 137 | return nfs_file_direct_write(iocb, iter, pos, |
138 | rw == WRITE ? true : false); | 138 | rw == WRITE ? true : false); |
139 | #endif /* CONFIG_NFS_SWAP */ | 139 | #endif /* CONFIG_NFS_SWAP */ |
140 | } | 140 | } |
@@ -414,8 +414,7 @@ static ssize_t nfs_direct_read_schedule_segment(struct nfs_pageio_descriptor *de | |||
414 | } | 414 | } |
415 | 415 | ||
416 | static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, | 416 | static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, |
417 | const struct iovec *iov, | 417 | struct iov_iter *iter, |
418 | unsigned long nr_segs, | ||
419 | loff_t pos, bool uio) | 418 | loff_t pos, bool uio) |
420 | { | 419 | { |
421 | struct nfs_pageio_descriptor desc; | 420 | struct nfs_pageio_descriptor desc; |
@@ -430,8 +429,8 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, | |||
430 | desc.pg_dreq = dreq; | 429 | desc.pg_dreq = dreq; |
431 | atomic_inc(&inode->i_dio_count); | 430 | atomic_inc(&inode->i_dio_count); |
432 | 431 | ||
433 | for (seg = 0; seg < nr_segs; seg++) { | 432 | for (seg = 0; seg < iter->nr_segs; seg++) { |
434 | const struct iovec *vec = &iov[seg]; | 433 | const struct iovec *vec = &iter->iov[seg]; |
435 | result = nfs_direct_read_schedule_segment(&desc, vec, pos, uio); | 434 | result = nfs_direct_read_schedule_segment(&desc, vec, pos, uio); |
436 | if (result < 0) | 435 | if (result < 0) |
437 | break; | 436 | break; |
@@ -461,8 +460,7 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, | |||
461 | /** | 460 | /** |
462 | * nfs_file_direct_read - file direct read operation for NFS files | 461 | * nfs_file_direct_read - file direct read operation for NFS files |
463 | * @iocb: target I/O control block | 462 | * @iocb: target I/O control block |
464 | * @iov: vector of user buffers into which to read data | 463 | * @iter: vector of user buffers into which to read data |
465 | * @nr_segs: size of iov vector | ||
466 | * @pos: byte offset in file where reading starts | 464 | * @pos: byte offset in file where reading starts |
467 | * | 465 | * |
468 | * We use this function for direct reads instead of calling | 466 | * We use this function for direct reads instead of calling |
@@ -479,8 +477,8 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, | |||
479 | * client must read the updated atime from the server back into its | 477 | * client must read the updated atime from the server back into its |
480 | * cache. | 478 | * cache. |
481 | */ | 479 | */ |
482 | ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov, | 480 | ssize_t nfs_file_direct_read(struct kiocb *iocb, struct iov_iter *iter, |
483 | unsigned long nr_segs, loff_t pos, bool uio) | 481 | loff_t pos, bool uio) |
484 | { | 482 | { |
485 | struct file *file = iocb->ki_filp; | 483 | struct file *file = iocb->ki_filp; |
486 | struct address_space *mapping = file->f_mapping; | 484 | struct address_space *mapping = file->f_mapping; |
@@ -490,7 +488,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov, | |||
490 | ssize_t result = -EINVAL; | 488 | ssize_t result = -EINVAL; |
491 | size_t count; | 489 | size_t count; |
492 | 490 | ||
493 | count = iov_length(iov, nr_segs); | 491 | count = iov_length(iter->iov, iter->nr_segs); |
494 | nfs_add_stats(mapping->host, NFSIOS_DIRECTREADBYTES, count); | 492 | nfs_add_stats(mapping->host, NFSIOS_DIRECTREADBYTES, count); |
495 | 493 | ||
496 | dfprintk(FILE, "NFS: direct read(%pD2, %zd@%Ld)\n", | 494 | dfprintk(FILE, "NFS: direct read(%pD2, %zd@%Ld)\n", |
@@ -513,7 +511,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov, | |||
513 | goto out_unlock; | 511 | goto out_unlock; |
514 | 512 | ||
515 | dreq->inode = inode; | 513 | dreq->inode = inode; |
516 | dreq->bytes_left = iov_length(iov, nr_segs); | 514 | dreq->bytes_left = count; |
517 | dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); | 515 | dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); |
518 | l_ctx = nfs_get_lock_context(dreq->ctx); | 516 | l_ctx = nfs_get_lock_context(dreq->ctx); |
519 | if (IS_ERR(l_ctx)) { | 517 | if (IS_ERR(l_ctx)) { |
@@ -524,8 +522,8 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov, | |||
524 | if (!is_sync_kiocb(iocb)) | 522 | if (!is_sync_kiocb(iocb)) |
525 | dreq->iocb = iocb; | 523 | dreq->iocb = iocb; |
526 | 524 | ||
527 | NFS_I(inode)->read_io += iov_length(iov, nr_segs); | 525 | NFS_I(inode)->read_io += count; |
528 | result = nfs_direct_read_schedule_iovec(dreq, iov, nr_segs, pos, uio); | 526 | result = nfs_direct_read_schedule_iovec(dreq, iter, pos, uio); |
529 | 527 | ||
530 | mutex_unlock(&inode->i_mutex); | 528 | mutex_unlock(&inode->i_mutex); |
531 | 529 | ||
@@ -864,8 +862,7 @@ static const struct nfs_pgio_completion_ops nfs_direct_write_completion_ops = { | |||
864 | }; | 862 | }; |
865 | 863 | ||
866 | static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, | 864 | static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, |
867 | const struct iovec *iov, | 865 | struct iov_iter *iter, |
868 | unsigned long nr_segs, | ||
869 | loff_t pos, bool uio) | 866 | loff_t pos, bool uio) |
870 | { | 867 | { |
871 | struct nfs_pageio_descriptor desc; | 868 | struct nfs_pageio_descriptor desc; |
@@ -880,9 +877,9 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, | |||
880 | get_dreq(dreq); | 877 | get_dreq(dreq); |
881 | atomic_inc(&inode->i_dio_count); | 878 | atomic_inc(&inode->i_dio_count); |
882 | 879 | ||
883 | NFS_I(dreq->inode)->write_io += iov_length(iov, nr_segs); | 880 | NFS_I(dreq->inode)->write_io += iov_length(iter->iov, iter->nr_segs); |
884 | for (seg = 0; seg < nr_segs; seg++) { | 881 | for (seg = 0; seg < iter->nr_segs; seg++) { |
885 | const struct iovec *vec = &iov[seg]; | 882 | const struct iovec *vec = &iter->iov[seg]; |
886 | result = nfs_direct_write_schedule_segment(&desc, vec, pos, uio); | 883 | result = nfs_direct_write_schedule_segment(&desc, vec, pos, uio); |
887 | if (result < 0) | 884 | if (result < 0) |
888 | break; | 885 | break; |
@@ -911,8 +908,7 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, | |||
911 | /** | 908 | /** |
912 | * nfs_file_direct_write - file direct write operation for NFS files | 909 | * nfs_file_direct_write - file direct write operation for NFS files |
913 | * @iocb: target I/O control block | 910 | * @iocb: target I/O control block |
914 | * @iov: vector of user buffers from which to write data | 911 | * @iter: vector of user buffers from which to write data |
915 | * @nr_segs: size of iov vector | ||
916 | * @pos: byte offset in file where writing starts | 912 | * @pos: byte offset in file where writing starts |
917 | * | 913 | * |
918 | * We use this function for direct writes instead of calling | 914 | * We use this function for direct writes instead of calling |
@@ -930,8 +926,8 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, | |||
930 | * Note that O_APPEND is not supported for NFS direct writes, as there | 926 | * Note that O_APPEND is not supported for NFS direct writes, as there |
931 | * is no atomic O_APPEND write facility in the NFS protocol. | 927 | * is no atomic O_APPEND write facility in the NFS protocol. |
932 | */ | 928 | */ |
933 | ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov, | 929 | ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter, |
934 | unsigned long nr_segs, loff_t pos, bool uio) | 930 | loff_t pos, bool uio) |
935 | { | 931 | { |
936 | ssize_t result = -EINVAL; | 932 | ssize_t result = -EINVAL; |
937 | struct file *file = iocb->ki_filp; | 933 | struct file *file = iocb->ki_filp; |
@@ -942,7 +938,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov, | |||
942 | loff_t end; | 938 | loff_t end; |
943 | size_t count; | 939 | size_t count; |
944 | 940 | ||
945 | count = iov_length(iov, nr_segs); | 941 | count = iov_length(iter->iov, iter->nr_segs); |
946 | end = (pos + count - 1) >> PAGE_CACHE_SHIFT; | 942 | end = (pos + count - 1) >> PAGE_CACHE_SHIFT; |
947 | 943 | ||
948 | nfs_add_stats(mapping->host, NFSIOS_DIRECTWRITTENBYTES, count); | 944 | nfs_add_stats(mapping->host, NFSIOS_DIRECTWRITTENBYTES, count); |
@@ -993,7 +989,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov, | |||
993 | if (!is_sync_kiocb(iocb)) | 989 | if (!is_sync_kiocb(iocb)) |
994 | dreq->iocb = iocb; | 990 | dreq->iocb = iocb; |
995 | 991 | ||
996 | result = nfs_direct_write_schedule_iovec(dreq, iov, nr_segs, pos, uio); | 992 | result = nfs_direct_write_schedule_iovec(dreq, iter, pos, uio); |
997 | 993 | ||
998 | if (mapping->nrpages) { | 994 | if (mapping->nrpages) { |
999 | invalidate_inode_pages2_range(mapping, | 995 | invalidate_inode_pages2_range(mapping, |
diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 284ca901fe16..3d01b152894e 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c | |||
@@ -169,14 +169,18 @@ nfs_file_read(struct kiocb *iocb, const struct iovec *iov, | |||
169 | unsigned long nr_segs, loff_t pos) | 169 | unsigned long nr_segs, loff_t pos) |
170 | { | 170 | { |
171 | struct inode *inode = file_inode(iocb->ki_filp); | 171 | struct inode *inode = file_inode(iocb->ki_filp); |
172 | size_t count = iov_length(iov, nr_segs); | ||
172 | ssize_t result; | 173 | ssize_t result; |
174 | struct iov_iter to; | ||
175 | |||
176 | iov_iter_init(&to, iov, nr_segs, count, 0); | ||
173 | 177 | ||
174 | if (iocb->ki_filp->f_flags & O_DIRECT) | 178 | if (iocb->ki_filp->f_flags & O_DIRECT) |
175 | return nfs_file_direct_read(iocb, iov, nr_segs, pos, true); | 179 | return nfs_file_direct_read(iocb, &to, pos, true); |
176 | 180 | ||
177 | dprintk("NFS: read(%pD2, %lu@%lu)\n", | 181 | dprintk("NFS: read(%pD2, %zu@%lu)\n", |
178 | iocb->ki_filp, | 182 | iocb->ki_filp, |
179 | (unsigned long) iov_length(iov, nr_segs), (unsigned long) pos); | 183 | count, (unsigned long) pos); |
180 | 184 | ||
181 | result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping); | 185 | result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping); |
182 | if (!result) { | 186 | if (!result) { |
@@ -643,16 +647,18 @@ ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov, | |||
643 | unsigned long written = 0; | 647 | unsigned long written = 0; |
644 | ssize_t result; | 648 | ssize_t result; |
645 | size_t count = iov_length(iov, nr_segs); | 649 | size_t count = iov_length(iov, nr_segs); |
650 | struct iov_iter from; | ||
651 | iov_iter_init(&from, iov, nr_segs, count, 0); | ||
646 | 652 | ||
647 | result = nfs_key_timeout_notify(file, inode); | 653 | result = nfs_key_timeout_notify(file, inode); |
648 | if (result) | 654 | if (result) |
649 | return result; | 655 | return result; |
650 | 656 | ||
651 | if (file->f_flags & O_DIRECT) | 657 | if (file->f_flags & O_DIRECT) |
652 | return nfs_file_direct_write(iocb, iov, nr_segs, pos, true); | 658 | return nfs_file_direct_write(iocb, &from, pos, true); |
653 | 659 | ||
654 | dprintk("NFS: write(%pD2, %lu@%Ld)\n", | 660 | dprintk("NFS: write(%pD2, %zu@%Ld)\n", |
655 | file, (unsigned long) count, (long long) pos); | 661 | file, count, (long long) pos); |
656 | 662 | ||
657 | result = -EBUSY; | 663 | result = -EBUSY; |
658 | if (IS_SWAPFILE(inode)) | 664 | if (IS_SWAPFILE(inode)) |