aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-01-25 15:11:59 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2015-01-29 00:13:13 -0500
commitdbe4e192a234cd6133d86fffb965d0f032c12ccc (patch)
treee5b5bbc9b22a289ec33fbc808f7e81d926caec06 /fs
parent05afcb77eb4713f46e7ebaa3cb54bc465c5d516e (diff)
fs: add vfs_iter_{read,write} helpers
Simple helpers that pass an arbitrary iov_iter to filesystems. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r--fs/read_write.c46
-rw-r--r--fs/splice.c16
2 files changed, 48 insertions, 14 deletions
diff --git a/fs/read_write.c b/fs/read_write.c
index c0805c93b6fa..ab4f26a7d5cb 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -333,6 +333,52 @@ out_putf:
333} 333}
334#endif 334#endif
335 335
336ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos)
337{
338 struct kiocb kiocb;
339 ssize_t ret;
340
341 if (!file->f_op->read_iter)
342 return -EINVAL;
343
344 init_sync_kiocb(&kiocb, file);
345 kiocb.ki_pos = *ppos;
346 kiocb.ki_nbytes = iov_iter_count(iter);
347
348 iter->type |= READ;
349 ret = file->f_op->read_iter(&kiocb, iter);
350 if (ret == -EIOCBQUEUED)
351 ret = wait_on_sync_kiocb(&kiocb);
352
353 if (ret > 0)
354 *ppos = kiocb.ki_pos;
355 return ret;
356}
357EXPORT_SYMBOL(vfs_iter_read);
358
359ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos)
360{
361 struct kiocb kiocb;
362 ssize_t ret;
363
364 if (!file->f_op->write_iter)
365 return -EINVAL;
366
367 init_sync_kiocb(&kiocb, file);
368 kiocb.ki_pos = *ppos;
369 kiocb.ki_nbytes = iov_iter_count(iter);
370
371 iter->type |= WRITE;
372 ret = file->f_op->write_iter(&kiocb, iter);
373 if (ret == -EIOCBQUEUED)
374 ret = wait_on_sync_kiocb(&kiocb);
375
376 if (ret > 0)
377 *ppos = kiocb.ki_pos;
378 return ret;
379}
380EXPORT_SYMBOL(vfs_iter_write);
381
336/* 382/*
337 * rw_verify_area doesn't like huge counts. We limit 383 * rw_verify_area doesn't like huge counts. We limit
338 * them to something that fits in "int" so that others 384 * them to something that fits in "int" so that others
diff --git a/fs/splice.c b/fs/splice.c
index 7c7176f2d1e7..7968da96bebb 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -961,7 +961,6 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
961 splice_from_pipe_begin(&sd); 961 splice_from_pipe_begin(&sd);
962 while (sd.total_len) { 962 while (sd.total_len) {
963 struct iov_iter from; 963 struct iov_iter from;
964 struct kiocb kiocb;
965 size_t left; 964 size_t left;
966 int n, idx; 965 int n, idx;
967 966
@@ -1005,26 +1004,15 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
1005 left -= this_len; 1004 left -= this_len;
1006 } 1005 }
1007 1006
1008 /* ... iov_iter */
1009 iov_iter_bvec(&from, ITER_BVEC | WRITE, array, n, 1007 iov_iter_bvec(&from, ITER_BVEC | WRITE, array, n,
1010 sd.total_len - left); 1008 sd.total_len - left);
1011 1009 ret = vfs_iter_write(out, &from, &sd.pos);
1012 /* ... and iocb */
1013 init_sync_kiocb(&kiocb, out);
1014 kiocb.ki_pos = sd.pos;
1015 kiocb.ki_nbytes = sd.total_len - left;
1016
1017 /* now, send it */
1018 ret = out->f_op->write_iter(&kiocb, &from);
1019 if (-EIOCBQUEUED == ret)
1020 ret = wait_on_sync_kiocb(&kiocb);
1021
1022 if (ret <= 0) 1010 if (ret <= 0)
1023 break; 1011 break;
1024 1012
1025 sd.num_spliced += ret; 1013 sd.num_spliced += ret;
1026 sd.total_len -= ret; 1014 sd.total_len -= ret;
1027 *ppos = sd.pos = kiocb.ki_pos; 1015 *ppos = sd.pos;
1028 1016
1029 /* dismiss the fully eaten buffers, adjust the partial one */ 1017 /* dismiss the fully eaten buffers, adjust the partial one */
1030 while (ret) { 1018 while (ret) {