Commit 66dc830d authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'iov_iter' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull iov_iter updates from Al Viro:
 "More iov_iter work - missing counterpart of iov_iter_init() for
  bvec-backed ones and vfs_read_iter()/vfs_write_iter() - wrappers for
  sync calls of ->read_iter()/->write_iter()"

* 'iov_iter' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  fs: add vfs_iter_{read,write} helpers
  new helper: iov_iter_bvec()
parents 05016b0f dbe4e192
...@@ -333,6 +333,52 @@ SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high, ...@@ -333,6 +333,52 @@ SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
} }
#endif #endif
ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos)
{
struct kiocb kiocb;
ssize_t ret;
if (!file->f_op->read_iter)
return -EINVAL;
init_sync_kiocb(&kiocb, file);
kiocb.ki_pos = *ppos;
kiocb.ki_nbytes = iov_iter_count(iter);
iter->type |= READ;
ret = file->f_op->read_iter(&kiocb, iter);
if (ret == -EIOCBQUEUED)
ret = wait_on_sync_kiocb(&kiocb);
if (ret > 0)
*ppos = kiocb.ki_pos;
return ret;
}
EXPORT_SYMBOL(vfs_iter_read);
ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos)
{
struct kiocb kiocb;
ssize_t ret;
if (!file->f_op->write_iter)
return -EINVAL;
init_sync_kiocb(&kiocb, file);
kiocb.ki_pos = *ppos;
kiocb.ki_nbytes = iov_iter_count(iter);
iter->type |= WRITE;
ret = file->f_op->write_iter(&kiocb, iter);
if (ret == -EIOCBQUEUED)
ret = wait_on_sync_kiocb(&kiocb);
if (ret > 0)
*ppos = kiocb.ki_pos;
return ret;
}
EXPORT_SYMBOL(vfs_iter_write);
/* /*
* rw_verify_area doesn't like huge counts. We limit * rw_verify_area doesn't like huge counts. We limit
* them to something that fits in "int" so that others * them to something that fits in "int" so that others
......
...@@ -961,7 +961,6 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, ...@@ -961,7 +961,6 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
splice_from_pipe_begin(&sd); splice_from_pipe_begin(&sd);
while (sd.total_len) { while (sd.total_len) {
struct iov_iter from; struct iov_iter from;
struct kiocb kiocb;
size_t left; size_t left;
int n, idx; int n, idx;
...@@ -1005,29 +1004,15 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, ...@@ -1005,29 +1004,15 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
left -= this_len; left -= this_len;
} }
/* ... iov_iter */ iov_iter_bvec(&from, ITER_BVEC | WRITE, array, n,
from.type = ITER_BVEC | WRITE; sd.total_len - left);
from.bvec = array; ret = vfs_iter_write(out, &from, &sd.pos);
from.nr_segs = n;
from.count = sd.total_len - left;
from.iov_offset = 0;
/* ... and iocb */
init_sync_kiocb(&kiocb, out);
kiocb.ki_pos = sd.pos;
kiocb.ki_nbytes = sd.total_len - left;
/* now, send it */
ret = out->f_op->write_iter(&kiocb, &from);
if (-EIOCBQUEUED == ret)
ret = wait_on_sync_kiocb(&kiocb);
if (ret <= 0) if (ret <= 0)
break; break;
sd.num_spliced += ret; sd.num_spliced += ret;
sd.total_len -= ret; sd.total_len -= ret;
*ppos = sd.pos = kiocb.ki_pos; *ppos = sd.pos;
/* dismiss the fully eaten buffers, adjust the partial one */ /* dismiss the fully eaten buffers, adjust the partial one */
while (ret) { while (ret) {
......
...@@ -2548,6 +2548,9 @@ extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t l ...@@ -2548,6 +2548,9 @@ extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t l
extern ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); extern ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos);
extern ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); extern ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos);
ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos);
/* fs/block_dev.c */ /* fs/block_dev.c */
extern ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to); extern ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to);
extern ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from); extern ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from);
......
...@@ -88,7 +88,9 @@ size_t iov_iter_zero(size_t bytes, struct iov_iter *); ...@@ -88,7 +88,9 @@ size_t iov_iter_zero(size_t bytes, struct iov_iter *);
unsigned long iov_iter_alignment(const struct iov_iter *i); unsigned long iov_iter_alignment(const struct iov_iter *i);
void iov_iter_init(struct iov_iter *i, int direction, const struct iovec *iov, void iov_iter_init(struct iov_iter *i, int direction, const struct iovec *iov,
unsigned long nr_segs, size_t count); unsigned long nr_segs, size_t count);
void iov_iter_kvec(struct iov_iter *i, int direction, const struct kvec *iov, void iov_iter_kvec(struct iov_iter *i, int direction, const struct kvec *kvec,
unsigned long nr_segs, size_t count);
void iov_iter_bvec(struct iov_iter *i, int direction, const struct bio_vec *bvec,
unsigned long nr_segs, size_t count); unsigned long nr_segs, size_t count);
ssize_t iov_iter_get_pages(struct iov_iter *i, struct page **pages, ssize_t iov_iter_get_pages(struct iov_iter *i, struct page **pages,
size_t maxsize, unsigned maxpages, size_t *start); size_t maxsize, unsigned maxpages, size_t *start);
......
...@@ -501,18 +501,31 @@ size_t iov_iter_single_seg_count(const struct iov_iter *i) ...@@ -501,18 +501,31 @@ size_t iov_iter_single_seg_count(const struct iov_iter *i)
EXPORT_SYMBOL(iov_iter_single_seg_count); EXPORT_SYMBOL(iov_iter_single_seg_count);
void iov_iter_kvec(struct iov_iter *i, int direction, void iov_iter_kvec(struct iov_iter *i, int direction,
const struct kvec *iov, unsigned long nr_segs, const struct kvec *kvec, unsigned long nr_segs,
size_t count) size_t count)
{ {
BUG_ON(!(direction & ITER_KVEC)); BUG_ON(!(direction & ITER_KVEC));
i->type = direction; i->type = direction;
i->kvec = (struct kvec *)iov; i->kvec = kvec;
i->nr_segs = nr_segs; i->nr_segs = nr_segs;
i->iov_offset = 0; i->iov_offset = 0;
i->count = count; i->count = count;
} }
EXPORT_SYMBOL(iov_iter_kvec); EXPORT_SYMBOL(iov_iter_kvec);
void iov_iter_bvec(struct iov_iter *i, int direction,
const struct bio_vec *bvec, unsigned long nr_segs,
size_t count)
{
BUG_ON(!(direction & ITER_BVEC));
i->type = direction;
i->bvec = bvec;
i->nr_segs = nr_segs;
i->iov_offset = 0;
i->count = count;
}
EXPORT_SYMBOL(iov_iter_bvec);
unsigned long iov_iter_alignment(const struct iov_iter *i) unsigned long iov_iter_alignment(const struct iov_iter *i)
{ {
unsigned long res = 0; unsigned long res = 0;
......
...@@ -269,14 +269,9 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, ...@@ -269,14 +269,9 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
.bv_len = PAGE_SIZE, .bv_len = PAGE_SIZE,
.bv_offset = 0 .bv_offset = 0
}; };
struct iov_iter from = { struct iov_iter from;
.type = ITER_BVEC | WRITE,
.count = PAGE_SIZE,
.iov_offset = 0,
.nr_segs = 1,
};
from.bvec = &bv; /* older gcc versions are broken */
iov_iter_bvec(&from, ITER_BVEC | WRITE, &bv, 1, PAGE_SIZE);
init_sync_kiocb(&kiocb, swap_file); init_sync_kiocb(&kiocb, swap_file);
kiocb.ki_pos = page_file_offset(page); kiocb.ki_pos = page_file_offset(page);
kiocb.ki_nbytes = PAGE_SIZE; kiocb.ki_nbytes = PAGE_SIZE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment