Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: Convert various code to bio_for_each_segment()

With immutable biovecs we don't want code accessing bi_io_vec directly -
the uses this patch changes weren't incorrect since they all own the
bio, but it makes the code harder to audit for no good reason - also,
this will help with multipage bvecs later.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Chris Mason <chris.mason@fusionio.com>
Cc: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Cc: Joern Engel <joern@logfs.org>
Cc: Prasad Joshi <prasadjoshi.linux@gmail.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>

+66 -101
+4 -6
fs/btrfs/compression.c
··· 201 201 if (cb->errors) { 202 202 bio_io_error(cb->orig_bio); 203 203 } else { 204 - int bio_index = 0; 205 - struct bio_vec *bvec = cb->orig_bio->bi_io_vec; 204 + int i; 205 + struct bio_vec *bvec; 206 206 207 207 /* 208 208 * we have verified the checksum already, set page 209 209 * checked so the end_io handlers know about it 210 210 */ 211 - while (bio_index < cb->orig_bio->bi_vcnt) { 211 + bio_for_each_segment_all(bvec, cb->orig_bio, i) 212 212 SetPageChecked(bvec->bv_page); 213 - bvec++; 214 - bio_index++; 215 - } 213 + 216 214 bio_endio(cb->orig_bio, 0); 217 215 } 218 216
+4 -7
fs/btrfs/disk-io.c
··· 842 842 843 843 static int btree_csum_one_bio(struct bio *bio) 844 844 { 845 - struct bio_vec *bvec = bio->bi_io_vec; 846 - int bio_index = 0; 845 + struct bio_vec *bvec; 847 846 struct btrfs_root *root; 848 - int ret = 0; 847 + int i, ret = 0; 849 848 850 - WARN_ON(bio->bi_vcnt <= 0); 851 - while (bio_index < bio->bi_vcnt) { 849 + bio_for_each_segment_all(bvec, bio, i) { 852 850 root = BTRFS_I(bvec->bv_page->mapping->host)->root; 853 851 ret = csum_dirty_buffer(root, bvec->bv_page); 854 852 if (ret) 855 853 break; 856 - bio_index++; 857 - bvec++; 858 854 } 855 + 859 856 return ret; 860 857 } 861 858
+13 -22
fs/btrfs/extent_io.c
··· 2332 2332 */ 2333 2333 static void end_bio_extent_writepage(struct bio *bio, int err) 2334 2334 { 2335 - struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; 2335 + struct bio_vec *bvec; 2336 2336 struct extent_io_tree *tree; 2337 2337 u64 start; 2338 2338 u64 end; 2339 + int i; 2339 2340 2340 - do { 2341 + bio_for_each_segment_all(bvec, bio, i) { 2341 2342 struct page *page = bvec->bv_page; 2342 2343 tree = &BTRFS_I(page->mapping->host)->io_tree; 2343 2344 ··· 2356 2355 start = page_offset(page); 2357 2356 end = start + bvec->bv_offset + bvec->bv_len - 1; 2358 2357 2359 - if (--bvec >= bio->bi_io_vec) 2360 - prefetchw(&bvec->bv_page->flags); 2361 - 2362 2358 if (end_extent_writepage(page, err, start, end)) 2363 2359 continue; 2364 2360 2365 2361 end_page_writeback(page); 2366 - } while (bvec >= bio->bi_io_vec); 2362 + } 2367 2363 2368 2364 bio_put(bio); 2369 2365 } ··· 2390 2392 */ 2391 2393 static void end_bio_extent_readpage(struct bio *bio, int err) 2392 2394 { 2395 + struct bio_vec *bvec; 2393 2396 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 2394 - struct bio_vec *bvec_end = bio->bi_io_vec + bio->bi_vcnt - 1; 2395 - struct bio_vec *bvec = bio->bi_io_vec; 2396 2397 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); 2397 2398 struct extent_io_tree *tree; 2398 2399 u64 offset = 0; ··· 2402 2405 u64 extent_len = 0; 2403 2406 int mirror; 2404 2407 int ret; 2408 + int i; 2405 2409 2406 2410 if (err) 2407 2411 uptodate = 0; 2408 2412 2409 - do { 2413 + bio_for_each_segment_all(bvec, bio, i) { 2410 2414 struct page *page = bvec->bv_page; 2411 2415 struct inode *inode = page->mapping->host; 2412 2416 ··· 2430 2432 start = page_offset(page); 2431 2433 end = start + bvec->bv_offset + bvec->bv_len - 1; 2432 2434 len = bvec->bv_len; 2433 - 2434 - if (++bvec <= bvec_end) 2435 - prefetchw(&bvec->bv_page->flags); 2436 2435 2437 2436 mirror = io_bio->mirror_num; 2438 2437 if (likely(uptodate && tree->ops && ··· 2511 2516 extent_start = start; 2512 2517 extent_len = end + 1 - start; 2513 2518 } 2514 - } while (bvec <= bvec_end); 2519 + } 2515 2520 2516 2521 if (extent_len) 2517 2522 endio_readpage_release_extent(tree, extent_start, extent_len, ··· 2542 2547 } 2543 2548 2544 2549 if (bio) { 2545 - bio->bi_size = 0; 2546 2550 bio->bi_bdev = bdev; 2547 2551 bio->bi_sector = first_sector; 2548 2552 btrfs_bio = btrfs_io_bio(bio); ··· 3404 3410 3405 3411 static void end_bio_extent_buffer_writepage(struct bio *bio, int err) 3406 3412 { 3407 - int uptodate = err == 0; 3408 - struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; 3413 + struct bio_vec *bvec; 3409 3414 struct extent_buffer *eb; 3410 - int done; 3415 + int i, done; 3411 3416 3412 - do { 3417 + bio_for_each_segment_all(bvec, bio, i) { 3413 3418 struct page *page = bvec->bv_page; 3414 3419 3415 - bvec--; 3416 3420 eb = (struct extent_buffer *)page->private; 3417 3421 BUG_ON(!eb); 3418 3422 done = atomic_dec_and_test(&eb->io_pages); 3419 3423 3420 - if (!uptodate || test_bit(EXTENT_BUFFER_IOERR, &eb->bflags)) { 3424 + if (err || test_bit(EXTENT_BUFFER_IOERR, &eb->bflags)) { 3421 3425 set_bit(EXTENT_BUFFER_IOERR, &eb->bflags); 3422 3426 ClearPageUptodate(page); 3423 3427 SetPageError(page); ··· 3427 3435 continue; 3428 3436 3429 3437 end_extent_buffer_writeback(eb); 3430 - } while (bvec >= bio->bi_io_vec); 3438 + } 3431 3439 3432 3440 bio_put(bio); 3433 - 3434 3441 } 3435 3442 3436 3443 static int write_one_eb(struct extent_buffer *eb,
+6 -9
fs/btrfs/inode.c
··· 6779 6779 static void btrfs_endio_direct_read(struct bio *bio, int err) 6780 6780 { 6781 6781 struct btrfs_dio_private *dip = bio->bi_private; 6782 - struct bio_vec *bvec_end = bio->bi_io_vec + bio->bi_vcnt - 1; 6783 - struct bio_vec *bvec = bio->bi_io_vec; 6782 + struct bio_vec *bvec; 6784 6783 struct inode *inode = dip->inode; 6785 6784 struct btrfs_root *root = BTRFS_I(inode)->root; 6786 6785 struct bio *dio_bio; 6787 6786 u32 *csums = (u32 *)dip->csum; 6788 - int index = 0; 6789 6787 u64 start; 6788 + int i; 6790 6789 6791 6790 start = dip->logical_offset; 6792 - do { 6791 + bio_for_each_segment_all(bvec, bio, i) { 6793 6792 if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) { 6794 6793 struct page *page = bvec->bv_page; 6795 6794 char *kaddr; ··· 6804 6805 local_irq_restore(flags); 6805 6806 6806 6807 flush_dcache_page(bvec->bv_page); 6807 - if (csum != csums[index]) { 6808 + if (csum != csums[i]) { 6808 6809 btrfs_err(root->fs_info, "csum failed ino %llu off %llu csum %u expected csum %u", 6809 6810 btrfs_ino(inode), start, csum, 6810 - csums[index]); 6811 + csums[i]); 6811 6812 err = -EIO; 6812 6813 } 6813 6814 } 6814 6815 6815 6816 start += bvec->bv_len; 6816 - bvec++; 6817 - index++; 6818 - } while (bvec <= bvec_end); 6817 + } 6819 6818 6820 6819 unlock_extent(&BTRFS_I(inode)->io_tree, dip->logical_offset, 6821 6820 dip->logical_offset + dip->bytes - 1);
+2 -2
fs/ext4/page-io.c
··· 65 65 { 66 66 int i; 67 67 int error = !test_bit(BIO_UPTODATE, &bio->bi_flags); 68 + struct bio_vec *bvec; 68 69 69 - for (i = 0; i < bio->bi_vcnt; i++) { 70 - struct bio_vec *bvec = &bio->bi_io_vec[i]; 70 + bio_for_each_segment_all(bvec, bio, i) { 71 71 struct page *page = bvec->bv_page; 72 72 struct buffer_head *bh, *head; 73 73 unsigned bio_start = bvec->bv_offset;
+5 -8
fs/f2fs/data.c
··· 351 351 352 352 static void read_end_io(struct bio *bio, int err) 353 353 { 354 - const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 355 - struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; 354 + struct bio_vec *bvec; 355 + int i; 356 356 357 - do { 357 + bio_for_each_segment_all(bvec, bio, i) { 358 358 struct page *page = bvec->bv_page; 359 359 360 - if (--bvec >= bio->bi_io_vec) 361 - prefetchw(&bvec->bv_page->flags); 362 - 363 - if (uptodate) { 360 + if (!err) { 364 361 SetPageUptodate(page); 365 362 } else { 366 363 ClearPageUptodate(page); 367 364 SetPageError(page); 368 365 } 369 366 unlock_page(page); 370 - } while (bvec >= bio->bi_io_vec); 367 + } 371 368 bio_put(bio); 372 369 } 373 370
+5 -7
fs/f2fs/segment.c
··· 575 575 576 576 static void f2fs_end_io_write(struct bio *bio, int err) 577 577 { 578 - const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 579 - struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; 580 578 struct bio_private *p = bio->bi_private; 579 + struct bio_vec *bvec; 580 + int i; 581 581 582 - do { 582 + bio_for_each_segment_all(bvec, bio, i) { 583 583 struct page *page = bvec->bv_page; 584 584 585 - if (--bvec >= bio->bi_io_vec) 586 - prefetchw(&bvec->bv_page->flags); 587 - if (!uptodate) { 585 + if (err) { 588 586 SetPageError(page); 589 587 if (page->mapping) 590 588 set_bit(AS_EIO, &page->mapping->flags); ··· 591 593 } 592 594 end_page_writeback(page); 593 595 dec_page_count(p->sbi, F2FS_WRITEBACK); 594 - } while (bvec >= bio->bi_io_vec); 596 + } 595 597 596 598 if (p->is_sync) 597 599 complete(p->wait);
+6 -10
fs/logfs/dev_bdev.c
··· 56 56 static void writeseg_end_io(struct bio *bio, int err) 57 57 { 58 58 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 59 - struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; 59 + struct bio_vec *bvec; 60 + int i; 60 61 struct super_block *sb = bio->bi_private; 61 62 struct logfs_super *super = logfs_super(sb); 62 - struct page *page; 63 63 64 64 BUG_ON(!uptodate); /* FIXME: Retry io or write elsewhere */ 65 65 BUG_ON(err); 66 - BUG_ON(bio->bi_vcnt == 0); 67 - do { 68 - page = bvec->bv_page; 69 - if (--bvec >= bio->bi_io_vec) 70 - prefetchw(&bvec->bv_page->flags); 71 66 72 - end_page_writeback(page); 73 - page_cache_release(page); 74 - } while (bvec >= bio->bi_io_vec); 67 + bio_for_each_segment_all(bvec, bio, i) { 68 + end_page_writeback(bvec->bv_page); 69 + page_cache_release(bvec->bv_page); 70 + } 75 71 bio_put(bio); 76 72 if (atomic_dec_and_test(&super->s_pending_writes)) 77 73 wake_up(&wq);
+8 -9
fs/mpage.c
··· 43 43 */ 44 44 static void mpage_end_io(struct bio *bio, int err) 45 45 { 46 - const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 47 - struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; 46 + struct bio_vec *bv; 47 + int i; 48 48 49 - do { 50 - struct page *page = bvec->bv_page; 49 + bio_for_each_segment_all(bv, bio, i) { 50 + struct page *page = bv->bv_page; 51 51 52 - if (--bvec >= bio->bi_io_vec) 53 - prefetchw(&bvec->bv_page->flags); 54 52 if (bio_data_dir(bio) == READ) { 55 - if (uptodate) { 53 + if (!err) { 56 54 SetPageUptodate(page); 57 55 } else { 58 56 ClearPageUptodate(page); ··· 58 60 } 59 61 unlock_page(page); 60 62 } else { /* bio_data_dir(bio) == WRITE */ 61 - if (!uptodate) { 63 + if (err) { 62 64 SetPageError(page); 63 65 if (page->mapping) 64 66 set_bit(AS_EIO, &page->mapping->flags); 65 67 } 66 68 end_page_writeback(page); 67 69 } 68 - } while (bvec >= bio->bi_io_vec); 70 + } 71 + 69 72 bio_put(bio); 70 73 } 71 74
+13 -21
fs/nfs/blocklayout/blocklayout.c
··· 201 201 static void bl_end_io_read(struct bio *bio, int err) 202 202 { 203 203 struct parallel_io *par = bio->bi_private; 204 - const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 205 - struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; 204 + struct bio_vec *bvec; 205 + int i; 206 206 207 - do { 208 - struct page *page = bvec->bv_page; 207 + if (!err) 208 + bio_for_each_segment_all(bvec, bio, i) 209 + SetPageUptodate(bvec->bv_page); 209 210 210 - if (--bvec >= bio->bi_io_vec) 211 - prefetchw(&bvec->bv_page->flags); 212 - if (uptodate) 213 - SetPageUptodate(page); 214 - } while (bvec >= bio->bi_io_vec); 215 - if (!uptodate) { 211 + if (err) { 216 212 struct nfs_read_data *rdata = par->data; 217 213 struct nfs_pgio_header *header = rdata->header; 218 214 ··· 379 383 static void bl_end_io_write_zero(struct bio *bio, int err) 380 384 { 381 385 struct parallel_io *par = bio->bi_private; 382 - const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 383 - struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; 386 + struct bio_vec *bvec; 387 + int i; 384 388 385 - do { 386 - struct page *page = bvec->bv_page; 387 - 388 - if (--bvec >= bio->bi_io_vec) 389 - prefetchw(&bvec->bv_page->flags); 389 + bio_for_each_segment_all(bvec, bio, i) { 390 390 /* This is the zeroing page we added */ 391 - end_page_writeback(page); 392 - page_cache_release(page); 393 - } while (bvec >= bio->bi_io_vec); 391 + end_page_writeback(bvec->bv_page); 392 + page_cache_release(bvec->bv_page); 393 + } 394 394 395 - if (unlikely(!uptodate)) { 395 + if (unlikely(err)) { 396 396 struct nfs_write_data *data = par->data; 397 397 struct nfs_pgio_header *header = data->header; 398 398