Skip to content

Commit

Permalink
block: allow bio_for_each_segment_all() to iterate over multi-page bvec
Browse files Browse the repository at this point in the history
This patch introduces one extra iterator variable to bio_for_each_segment_all(),
then we can allow bio_for_each_segment_all() to iterate over multi-page bvec.

Given it is just one mechannical & simple change on all bio_for_each_segment_all()
users, this patch does tree-wide change in one single patch, so that we can
avoid to use a temporary helper for this conversion.

Reviewed-by: Omar Sandoval <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Ming Lei <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Ming Lei authored and axboe committed Feb 15, 2019
1 parent 2e1f4f4 commit 6dc4f10
Show file tree
Hide file tree
Showing 27 changed files with 127 additions and 46 deletions.
27 changes: 18 additions & 9 deletions block/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,9 @@ static int bio_copy_from_iter(struct bio *bio, struct iov_iter *iter)
{
int i;
struct bio_vec *bvec;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
ssize_t ret;

ret = copy_page_from_iter(bvec->bv_page,
Expand Down Expand Up @@ -1103,8 +1104,9 @@ static int bio_copy_to_iter(struct bio *bio, struct iov_iter iter)
{
int i;
struct bio_vec *bvec;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
ssize_t ret;

ret = copy_page_to_iter(bvec->bv_page,
Expand All @@ -1126,8 +1128,9 @@ void bio_free_pages(struct bio *bio)
{
struct bio_vec *bvec;
int i;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i)
bio_for_each_segment_all(bvec, bio, i, iter_all)
__free_page(bvec->bv_page);
}
EXPORT_SYMBOL(bio_free_pages);
Expand Down Expand Up @@ -1295,6 +1298,7 @@ struct bio *bio_map_user_iov(struct request_queue *q,
struct bio *bio;
int ret;
struct bio_vec *bvec;
struct bvec_iter_all iter_all;

if (!iov_iter_count(iter))
return ERR_PTR(-EINVAL);
Expand Down Expand Up @@ -1368,7 +1372,7 @@ struct bio *bio_map_user_iov(struct request_queue *q,
return bio;

out_unmap:
bio_for_each_segment_all(bvec, bio, j) {
bio_for_each_segment_all(bvec, bio, j, iter_all) {
put_page(bvec->bv_page);
}
bio_put(bio);
Expand All @@ -1379,11 +1383,12 @@ static void __bio_unmap_user(struct bio *bio)
{
struct bio_vec *bvec;
int i;
struct bvec_iter_all iter_all;

/*
* make sure we dirty pages we wrote to
*/
bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
if (bio_data_dir(bio) == READ)
set_page_dirty_lock(bvec->bv_page);

Expand Down Expand Up @@ -1475,8 +1480,9 @@ static void bio_copy_kern_endio_read(struct bio *bio)
char *p = bio->bi_private;
struct bio_vec *bvec;
int i;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
memcpy(p, page_address(bvec->bv_page), bvec->bv_len);
p += bvec->bv_len;
}
Expand Down Expand Up @@ -1585,8 +1591,9 @@ void bio_set_pages_dirty(struct bio *bio)
{
struct bio_vec *bvec;
int i;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
if (!PageCompound(bvec->bv_page))
set_page_dirty_lock(bvec->bv_page);
}
Expand All @@ -1596,8 +1603,9 @@ static void bio_release_pages(struct bio *bio)
{
struct bio_vec *bvec;
int i;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i)
bio_for_each_segment_all(bvec, bio, i, iter_all)
put_page(bvec->bv_page);
}

Expand Down Expand Up @@ -1644,8 +1652,9 @@ void bio_check_pages_dirty(struct bio *bio)
struct bio_vec *bvec;
unsigned long flags;
int i;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
if (!PageDirty(bvec->bv_page) && !PageCompound(bvec->bv_page))
goto defer;
}
Expand Down
6 changes: 4 additions & 2 deletions block/bounce.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@ static void bounce_end_io(struct bio *bio, mempool_t *pool)
struct bio_vec *bvec, orig_vec;
int i;
struct bvec_iter orig_iter = bio_orig->bi_iter;
struct bvec_iter_all iter_all;

/*
* free up bounce indirect pages used
*/
bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
orig_vec = bio_iter_iovec(bio_orig, orig_iter);
if (bvec->bv_page != orig_vec.bv_page) {
dec_zone_page_state(bvec->bv_page, NR_BOUNCE);
Expand Down Expand Up @@ -294,6 +295,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig,
bool bounce = false;
int sectors = 0;
bool passthrough = bio_is_passthrough(*bio_orig);
struct bvec_iter_all iter_all;

bio_for_each_segment(from, *bio_orig, iter) {
if (i++ < BIO_MAX_PAGES)
Expand All @@ -313,7 +315,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig,
bio = bounce_clone_bio(*bio_orig, GFP_NOIO, passthrough ? NULL :
&bounce_bio_set);

bio_for_each_segment_all(to, bio, i) {
bio_for_each_segment_all(to, bio, i, iter_all) {
struct page *page = to->bv_page;

if (page_to_pfn(page) <= q->limits.bounce_pfn)
Expand Down
3 changes: 2 additions & 1 deletion drivers/md/bcache/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,9 @@ static void do_btree_node_write(struct btree *b)
int j;
struct bio_vec *bv;
void *base = (void *) ((unsigned long) i & ~(PAGE_SIZE - 1));
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bv, b->bio, j)
bio_for_each_segment_all(bv, b->bio, j, iter_all)
memcpy(page_address(bv->bv_page),
base + j * PAGE_SIZE, PAGE_SIZE);

Expand Down
3 changes: 2 additions & 1 deletion drivers/md/dm-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1447,8 +1447,9 @@ static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone)
{
unsigned int i;
struct bio_vec *bv;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bv, clone, i) {
bio_for_each_segment_all(bv, clone, i, iter_all) {
BUG_ON(!bv->bv_page);
mempool_free(bv->bv_page, &cc->page_pool);
}
Expand Down
3 changes: 2 additions & 1 deletion drivers/md/raid1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2112,13 +2112,14 @@ static void process_checks(struct r1bio *r1_bio)
struct page **spages = get_resync_pages(sbio)->pages;
struct bio_vec *bi;
int page_len[RESYNC_PAGES] = { 0 };
struct bvec_iter_all iter_all;

if (sbio->bi_end_io != end_sync_read)
continue;
/* Now we can 'fixup' the error value */
sbio->bi_status = 0;

bio_for_each_segment_all(bi, sbio, j)
bio_for_each_segment_all(bi, sbio, j, iter_all)
page_len[j] = bi->bv_len;

if (!status) {
Expand Down
3 changes: 2 additions & 1 deletion drivers/staging/erofs/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ static inline void read_endio(struct bio *bio)
int i;
struct bio_vec *bvec;
const blk_status_t err = bio->bi_status;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
struct page *page = bvec->bv_page;

/* page is already locked */
Expand Down
3 changes: 2 additions & 1 deletion drivers/staging/erofs/unzip_vle.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,9 @@ static inline void z_erofs_vle_read_endio(struct bio *bio)
#ifdef EROFS_FS_HAS_MANAGED_CACHE
struct address_space *mc = NULL;
#endif
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
struct page *page = bvec->bv_page;
bool cachemngd = false;

Expand Down
6 changes: 4 additions & 2 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
ssize_t ret;
blk_qc_t qc;
int i;
struct bvec_iter_all iter_all;

if ((pos | iov_iter_alignment(iter)) &
(bdev_logical_block_size(bdev) - 1))
Expand Down Expand Up @@ -260,7 +261,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
}
__set_current_state(TASK_RUNNING);

bio_for_each_segment_all(bvec, &bio, i) {
bio_for_each_segment_all(bvec, &bio, i, iter_all) {
if (should_dirty && !PageCompound(bvec->bv_page))
set_page_dirty_lock(bvec->bv_page);
put_page(bvec->bv_page);
Expand Down Expand Up @@ -329,8 +330,9 @@ static void blkdev_bio_end_io(struct bio *bio)
} else {
struct bio_vec *bvec;
int i;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i)
bio_for_each_segment_all(bvec, bio, i, iter_all)
put_page(bvec->bv_page);
bio_put(bio);
}
Expand Down
3 changes: 2 additions & 1 deletion fs/btrfs/compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ static void end_compressed_bio_read(struct bio *bio)
} else {
int i;
struct bio_vec *bvec;
struct bvec_iter_all iter_all;

/*
* we have verified the checksum already, set page
* checked so the end_io handlers know about it
*/
ASSERT(!bio_flagged(bio, BIO_CLONED));
bio_for_each_segment_all(bvec, cb->orig_bio, i)
bio_for_each_segment_all(bvec, cb->orig_bio, i, iter_all)
SetPageChecked(bvec->bv_page);

bio_endio(cb->orig_bio);
Expand Down
3 changes: 2 additions & 1 deletion fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,10 @@ static blk_status_t btree_csum_one_bio(struct bio *bio)
struct bio_vec *bvec;
struct btrfs_root *root;
int i, ret = 0;
struct bvec_iter_all iter_all;

ASSERT(!bio_flagged(bio, BIO_CLONED));
bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
root = BTRFS_I(bvec->bv_page->mapping->host)->root;
ret = csum_dirty_buffer(root->fs_info, bvec->bv_page);
if (ret)
Expand Down
9 changes: 6 additions & 3 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2422,9 +2422,10 @@ static void end_bio_extent_writepage(struct bio *bio)
u64 start;
u64 end;
int i;
struct bvec_iter_all iter_all;

ASSERT(!bio_flagged(bio, BIO_CLONED));
bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
struct page *page = bvec->bv_page;
struct inode *inode = page->mapping->host;
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
Expand Down Expand Up @@ -2493,9 +2494,10 @@ static void end_bio_extent_readpage(struct bio *bio)
int mirror;
int ret;
int i;
struct bvec_iter_all iter_all;

ASSERT(!bio_flagged(bio, BIO_CLONED));
bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
struct page *page = bvec->bv_page;
struct inode *inode = page->mapping->host;
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
Expand Down Expand Up @@ -3635,9 +3637,10 @@ static void end_bio_extent_buffer_writepage(struct bio *bio)
struct bio_vec *bvec;
struct extent_buffer *eb;
int i, done;
struct bvec_iter_all iter_all;

ASSERT(!bio_flagged(bio, BIO_CLONED));
bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
struct page *page = bvec->bv_page;

eb = (struct extent_buffer *)page->private;
Expand Down
6 changes: 4 additions & 2 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -7777,6 +7777,7 @@ static void btrfs_retry_endio_nocsum(struct bio *bio)
struct bio_vec *bvec;
struct extent_io_tree *io_tree, *failure_tree;
int i;
struct bvec_iter_all iter_all;

if (bio->bi_status)
goto end;
Expand All @@ -7788,7 +7789,7 @@ static void btrfs_retry_endio_nocsum(struct bio *bio)

done->uptodate = 1;
ASSERT(!bio_flagged(bio, BIO_CLONED));
bio_for_each_segment_all(bvec, bio, i)
bio_for_each_segment_all(bvec, bio, i, iter_all)
clean_io_failure(BTRFS_I(inode)->root->fs_info, failure_tree,
io_tree, done->start, bvec->bv_page,
btrfs_ino(BTRFS_I(inode)), 0);
Expand Down Expand Up @@ -7867,6 +7868,7 @@ static void btrfs_retry_endio(struct bio *bio)
int uptodate;
int ret;
int i;
struct bvec_iter_all iter_all;

if (bio->bi_status)
goto end;
Expand All @@ -7880,7 +7882,7 @@ static void btrfs_retry_endio(struct bio *bio)
failure_tree = &BTRFS_I(inode)->io_failure_tree;

ASSERT(!bio_flagged(bio, BIO_CLONED));
bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
ret = __readpage_endio_check(inode, io_bio, i, bvec->bv_page,
bvec->bv_offset, done->start,
bvec->bv_len);
Expand Down
3 changes: 2 additions & 1 deletion fs/btrfs/raid56.c
Original file line number Diff line number Diff line change
Expand Up @@ -1443,10 +1443,11 @@ static void set_bio_pages_uptodate(struct bio *bio)
{
struct bio_vec *bvec;
int i;
struct bvec_iter_all iter_all;

ASSERT(!bio_flagged(bio, BIO_CLONED));

bio_for_each_segment_all(bvec, bio, i)
bio_for_each_segment_all(bvec, bio, i, iter_all)
SetPageUptodate(bvec->bv_page);
}

Expand Down
3 changes: 2 additions & 1 deletion fs/crypto/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ static void __fscrypt_decrypt_bio(struct bio *bio, bool done)
{
struct bio_vec *bv;
int i;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bv, bio, i) {
bio_for_each_segment_all(bv, bio, i, iter_all) {
struct page *page = bv->bv_page;
int ret = fscrypt_decrypt_page(page->mapping->host, page,
PAGE_SIZE, 0, page->index);
Expand Down
4 changes: 3 additions & 1 deletion fs/direct-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,9 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio)
if (dio->is_async && dio->op == REQ_OP_READ && dio->should_dirty) {
bio_check_pages_dirty(bio); /* transfers ownership */
} else {
bio_for_each_segment_all(bvec, bio, i) {
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i, iter_all) {
struct page *page = bvec->bv_page;

if (dio->op == REQ_OP_READ && !PageCompound(page) &&
Expand Down
3 changes: 2 additions & 1 deletion fs/exofs/ore.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,9 @@ static void _clear_bio(struct bio *bio)
{
struct bio_vec *bv;
unsigned i;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bv, bio, i) {
bio_for_each_segment_all(bv, bio, i, iter_all) {
unsigned this_count = bv->bv_len;

if (likely(PAGE_SIZE == this_count))
Expand Down
3 changes: 2 additions & 1 deletion fs/exofs/ore_raid.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,12 @@ static void _mark_read4write_pages_uptodate(struct ore_io_state *ios, int ret)
/* loop on all devices all pages */
for (d = 0; d < ios->numdevs; d++) {
struct bio *bio = ios->per_dev[d].bio;
struct bvec_iter_all iter_all;

if (!bio)
continue;

bio_for_each_segment_all(bv, bio, i) {
bio_for_each_segment_all(bv, bio, i, iter_all) {
struct page *page = bv->bv_page;

SetPageUptodate(page);
Expand Down
3 changes: 2 additions & 1 deletion fs/ext4/page-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ static void ext4_finish_bio(struct bio *bio)
{
int i;
struct bio_vec *bvec;
struct bvec_iter_all iter_all;

bio_for_each_segment_all(bvec, bio, i) {
bio_for_each_segment_all(bvec, bio, i, iter_all) {
struct page *page = bvec->bv_page;
#ifdef CONFIG_EXT4_FS_ENCRYPTION
struct page *data_page = NULL;
Expand Down
Loading

0 comments on commit 6dc4f10

Please sign in to comment.