new helper: iov_iter_bvec()

similar to iov_iter_kvec(), for ITER_BVEC ones

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2015-01-23 01:08:07 -05:00
parent 26bc420b59
commit 05afcb77eb
4 changed files with 22 additions and 15 deletions

View File

@ -1006,11 +1006,8 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
} }
/* ... iov_iter */ /* ... iov_iter */
from.type = ITER_BVEC | WRITE; iov_iter_bvec(&from, ITER_BVEC | WRITE, array, n,
from.bvec = array; sd.total_len - left);
from.nr_segs = n;
from.count = sd.total_len - left;
from.iov_offset = 0;
/* ... and iocb */ /* ... and iocb */
init_sync_kiocb(&kiocb, out); init_sync_kiocb(&kiocb, out);

View File

@ -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);

View File

@ -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;

View File

@ -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;