Lines Matching refs:bio

7 #include <linux/bio.h>
8 #include "bio.h"
37 return is_data_bbio(bbio) && btrfs_op(&bbio->bio) == BTRFS_MAP_WRITE;
41 * Initialize a btrfs_bio structure. This skips the embedded bio itself as it
47 memset(bbio, 0, offsetof(struct btrfs_bio, bio));
66 struct bio *bio;
68 bio = bio_alloc_bioset(NULL, nr_vecs, opf, GFP_NOFS, &btrfs_bioset);
69 bbio = btrfs_bio(bio);
79 struct bio *bio;
84 bio = bio_split_rw(&orig_bbio->bio, &fs_info->limits, &nr_segs,
87 bio = bio_split(&orig_bbio->bio, map_length >> SECTOR_SHIFT,
90 bbio = btrfs_bio(bio);
103 /* Free a bio that was never submitted to the underlying device. */
108 bio_put(&bbio->bio);
125 bbio->bio.bi_status = status;
129 static void btrfs_orig_write_end_io(struct bio *bio);
140 if (bbio->bio.bi_end_io == &btrfs_orig_write_end_io) {
141 struct btrfs_io_stripe *orig_stripe = orig_bbio->bio.bi_private;
146 orig_bbio->bio.bi_status = bbio->bio.bi_status;
152 if (bbio->bio.bi_pool == &btrfs_clone_bioset) {
155 if (bbio->bio.bi_status)
193 struct bio_vec *bv = bio_first_bvec_all(&repair_bbio->bio);
197 * We can only trigger this for data bio, which doesn't support larger
202 if (repair_bbio->bio.bi_status ||
204 bio_reset(&repair_bbio->bio, NULL, REQ_OP_READ);
205 repair_bbio->bio.bi_iter = repair_bbio->saved_iter;
210 fbio->bbio->bio.bi_status = BLK_STS_IOERR;
228 bio_put(&repair_bbio->bio);
248 struct bio *repair_bio;
258 failed_bbio->bio.bi_status = BLK_STS_IOERR;
293 blk_status_t status = bbio->bio.bi_status;
304 if (bbio->bio.bi_pool == &btrfs_repair_bioset) {
310 bbio->bio.bi_status = BLK_STS_OK;
313 struct bio_vec bv = bio_iter_iovec(&bbio->bio, *iter);
319 bio_advance_iter_single(&bbio->bio, iter, sectorsize);
332 static void btrfs_log_dev_io_error(struct bio *bio, struct btrfs_device *dev)
336 if (bio->bi_status != BLK_STS_IOERR && bio->bi_status != BLK_STS_TARGET)
339 if (btrfs_op(bio) == BTRFS_MAP_WRITE)
341 else if (!(bio->bi_opf & REQ_RAHEAD))
343 if (bio->bi_opf & REQ_PREFLUSH)
348 struct bio *bio)
350 if (bio->bi_opf & REQ_META)
361 btrfs_check_read_bio(bbio, bbio->bio.bi_private);
366 static void btrfs_simple_end_io(struct bio *bio)
368 struct btrfs_bio *bbio = btrfs_bio(bio);
369 struct btrfs_device *dev = bio->bi_private;
374 if (bio->bi_status)
375 btrfs_log_dev_io_error(bio, dev);
377 if (bio_op(bio) == REQ_OP_READ) {
379 queue_work(btrfs_end_io_wq(fs_info, bio), &bbio->end_io_work);
381 if (bio_op(bio) == REQ_OP_ZONE_APPEND && !bio->bi_status)
387 static void btrfs_raid56_end_io(struct bio *bio)
389 struct btrfs_io_context *bioc = bio->bi_private;
390 struct btrfs_bio *bbio = btrfs_bio(bio);
394 if (bio_op(bio) == REQ_OP_READ && is_data_bbio(bbio))
402 static void btrfs_orig_write_end_io(struct bio *bio)
404 struct btrfs_io_stripe *stripe = bio->bi_private;
406 struct btrfs_bio *bbio = btrfs_bio(bio);
410 if (bio->bi_status) {
412 btrfs_log_dev_io_error(bio, stripe->dev);
420 bio->bi_status = BLK_STS_IOERR;
422 bio->bi_status = BLK_STS_OK;
424 if (bio_op(bio) == REQ_OP_ZONE_APPEND && !bio->bi_status)
425 stripe->physical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
431 static void btrfs_clone_write_end_io(struct bio *bio)
433 struct btrfs_io_stripe *stripe = bio->bi_private;
435 if (bio->bi_status) {
437 btrfs_log_dev_io_error(bio, stripe->dev);
438 } else if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
439 stripe->physical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
442 /* Pass on control to the original bio this one was cloned from */
444 bio_put(bio);
447 static void btrfs_submit_dev_bio(struct btrfs_device *dev, struct bio *bio)
451 (btrfs_op(bio) == BTRFS_MAP_WRITE &&
453 bio_io_error(bio);
457 bio_set_dev(bio, dev->bdev);
463 if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
464 u64 physical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
468 bio->bi_iter.bi_sector = zone_start >> SECTOR_SHIFT;
472 __func__, bio_op(bio), bio->bi_opf, bio->bi_iter.bi_sector,
474 dev->devid, bio->bi_iter.bi_size);
476 if (bio->bi_opf & REQ_BTRFS_CGROUP_PUNT)
477 blkcg_punt_bio_submit(bio);
479 submit_bio(bio);
484 struct bio *orig_bio = bioc->orig_bio, *bio;
488 /* Reuse the bio embedded into the btrfs_bio for the last mirror */
490 bio = orig_bio;
491 bio->bi_end_io = btrfs_orig_write_end_io;
493 bio = bio_alloc_clone(NULL, orig_bio, GFP_NOFS, &fs_bio_set);
495 bio->bi_end_io = btrfs_clone_write_end_io;
498 bio->bi_private = &bioc->stripes[dev_nr];
499 bio->bi_iter.bi_sector = bioc->stripes[dev_nr].physical >> SECTOR_SHIFT;
501 bioc->size = bio->bi_iter.bi_size;
502 btrfs_submit_dev_bio(bioc->stripes[dev_nr].dev, bio);
505 static void __btrfs_submit_bio(struct bio *bio, struct btrfs_io_context *bioc,
510 btrfs_bio(bio)->mirror_num = mirror_num;
511 bio->bi_iter.bi_sector = smap->physical >> SECTOR_SHIFT;
512 if (bio_op(bio) != REQ_OP_READ)
513 btrfs_bio(bio)->orig_physical = smap->physical;
514 bio->bi_private = smap->dev;
515 bio->bi_end_io = btrfs_simple_end_io;
516 btrfs_submit_dev_bio(smap->dev, bio);
519 bio->bi_private = bioc;
520 bio->bi_end_io = btrfs_raid56_end_io;
521 if (bio_op(bio) == REQ_OP_READ)
522 raid56_parity_recover(bio, bioc, mirror_num);
524 raid56_parity_write(bio, bioc);
529 bioc->orig_bio = bio;
537 if (bbio->bio.bi_opf & REQ_META)
556 * until bio submission time. All the pages in the bio are checksummed and
570 async->bbio->bio.bi_status = ret;
575 * until bio submission time. All the pages in the bio are checksummed and
587 struct bio *bio = &async->bbio->bio;
594 /* If an error occurred we just want to clean up the bio and move on. */
595 if (bio->bi_status) {
605 bio->bi_opf |= REQ_BTRFS_CGROUP_PUNT;
606 __btrfs_submit_bio(bio, async->bioc, &async->smap, async->mirror_num);
631 if (op_is_sync(bbio->bio.bi_opf))
635 if ((bbio->bio.bi_opf & REQ_META) && btrfs_is_zoned(bbio->fs_info))
642 * Submit bio to an async queue.
672 struct bio *bio = &bbio->bio;
673 u64 logical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
674 u64 length = bio->bi_iter.bi_size;
685 error = btrfs_map_block(fs_info, btrfs_op(bio), logical, &map_length,
698 bio = &bbio->bio;
705 if (bio_op(bio) == REQ_OP_READ && is_data_bbio(bbio)) {
706 bbio->saved_iter = bio->bi_iter;
712 if (btrfs_op(bio) == BTRFS_MAP_WRITE) {
714 bio->bi_opf &= ~REQ_OP_WRITE;
715 bio->bi_opf |= REQ_OP_ZONE_APPEND;
751 __btrfs_submit_bio(bio, bioc, &smap, mirror_num);
779 * mapping ourselves and submit the bio directly.
782 * freeing the bio.
790 struct bio bio;
815 bio_init(&bio, smap.dev->bdev, &bvec, 1, REQ_OP_WRITE | REQ_SYNC);
816 bio.bi_iter.bi_sector = smap.physical >> SECTOR_SHIFT;
817 ret = bio_add_folio(&bio, folio, length, folio_offset);
819 ret = submit_bio_wait(&bio);
833 bio_uninit(&bio);
847 u64 logical = bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT;
848 u64 length = bbio->bio.bi_iter.bi_size;
854 ASSERT(btrfs_op(&bbio->bio) == BTRFS_MAP_WRITE);
866 __btrfs_submit_bio(&bbio->bio, NULL, &smap, mirror_num);
877 offsetof(struct btrfs_bio, bio),
881 offsetof(struct btrfs_bio, bio), 0))
884 offsetof(struct btrfs_bio, bio),