Lines Matching refs:bbio
5611 static void sort_parity_stripes(struct btrfs_bio *bbio, int num_stripes)
5620 if (bbio->raid_map[i] > bbio->raid_map[i + 1]) {
5621 swap(bbio->stripes[i], bbio->stripes[i + 1]);
5622 swap(bbio->raid_map[i], bbio->raid_map[i + 1]);
5631 struct btrfs_bio *bbio = kzalloc(
5645 atomic_set(&bbio->error, 0);
5646 refcount_set(&bbio->refs, 1);
5648 bbio->tgtdev_map = (int *)(bbio->stripes + total_stripes);
5649 bbio->raid_map = (u64 *)(bbio->tgtdev_map + real_stripes);
5651 return bbio;
5654 void btrfs_get_bbio(struct btrfs_bio *bbio)
5656 WARN_ON(!refcount_read(&bbio->refs));
5657 refcount_inc(&bbio->refs);
5660 void btrfs_put_bbio(struct btrfs_bio *bbio)
5662 if (!bbio)
5664 if (refcount_dec_and_test(&bbio->refs))
5665 kfree(bbio);
5679 struct btrfs_bio *bbio;
5698 /* discard always return a bbio */
5762 bbio = alloc_btrfs_bio(num_stripes, 0);
5763 if (!bbio) {
5769 bbio->stripes[i].physical =
5772 bbio->stripes[i].dev = map->stripes[stripe_index].dev;
5776 bbio->stripes[i].length = stripes_per_dev *
5780 bbio->stripes[i].length +=
5792 bbio->stripes[i].length -=
5798 bbio->stripes[i].length -=
5804 bbio->stripes[i].length = length;
5814 *bbio_ret = bbio;
5815 bbio->map_type = map->type;
5816 bbio->num_stripes = num_stripes;
5840 struct btrfs_bio *bbio = NULL;
5849 logical, &length, &bbio, 0, 0);
5851 ASSERT(bbio == NULL);
5855 num_stripes = bbio->num_stripes;
5862 btrfs_put_bbio(bbio);
5872 if (bbio->stripes[i].dev->devid != srcdev_devid)
5880 physical_of_found <= bbio->stripes[i].physical)
5885 physical_of_found = bbio->stripes[i].physical;
5888 btrfs_put_bbio(bbio);
5904 struct btrfs_bio *bbio = *bbio_ret;
5927 if (bbio->stripes[i].dev->devid == srcdev_devid) {
5930 bbio->stripes + index_where_to_add;
5932 bbio->stripes + i;
5937 bbio->tgtdev_map[i] = index_where_to_add;
5957 if (bbio->stripes[i].dev->devid == srcdev_devid) {
5965 bbio->stripes[i].physical)
5969 physical_of_found = bbio->stripes[i].physical;
5974 bbio->stripes + num_stripes;
5978 bbio->stripes[index_srcdev].length;
5980 bbio->tgtdev_map[index_srcdev] = num_stripes;
5989 bbio->num_tgtdevs = tgtdev_indexes;
5990 *bbio_ret = bbio;
6116 struct btrfs_bio *bbio = NULL;
6268 bbio = alloc_btrfs_bio(num_alloc_stripes, tgtdev_indexes);
6269 if (!bbio) {
6275 bbio->stripes[i].physical = map->stripes[stripe_index].physical +
6277 bbio->stripes[i].dev = map->stripes[stripe_index].dev;
6293 bbio->raid_map[(i+rot) % num_stripes] =
6296 bbio->raid_map[(i+rot) % map->num_stripes] = RAID5_P_STRIPE;
6298 bbio->raid_map[(i+rot+1) % num_stripes] =
6301 sort_parity_stripes(bbio, num_stripes);
6309 handle_ops_on_dev_replace(op, &bbio, dev_replace, &num_stripes,
6313 *bbio_ret = bbio;
6314 bbio->map_type = map->type;
6315 bbio->num_stripes = num_stripes;
6316 bbio->max_errors = max_errors;
6317 bbio->mirror_num = mirror_num;
6326 bbio->stripes[0].dev = dev_replace->tgtdev;
6327 bbio->stripes[0].physical = physical_to_patch_in_first_stripe;
6328 bbio->mirror_num = map->num_stripes + 1;
6360 static inline void btrfs_end_bbio(struct btrfs_bio *bbio, struct bio *bio)
6362 bio->bi_private = bbio->private;
6363 bio->bi_end_io = bbio->end_io;
6366 btrfs_put_bbio(bbio);
6371 struct btrfs_bio *bbio = bio->bi_private;
6375 atomic_inc(&bbio->error);
6393 if (bio == bbio->orig_bio)
6396 btrfs_bio_counter_dec(bbio->fs_info);
6398 if (atomic_dec_and_test(&bbio->stripes_pending)) {
6401 bio = bbio->orig_bio;
6404 btrfs_io_bio(bio)->mirror_num = bbio->mirror_num;
6408 if (atomic_read(&bbio->error) > bbio->max_errors) {
6418 btrfs_end_bbio(bbio, bio);
6424 static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio,
6427 struct btrfs_fs_info *fs_info = bbio->fs_info;
6429 bio->bi_private = bbio;
6445 static void bbio_error(struct btrfs_bio *bbio, struct bio *bio, u64 logical)
6447 atomic_inc(&bbio->error);
6448 if (atomic_dec_and_test(&bbio->stripes_pending)) {
6450 WARN_ON(bio != bbio->orig_bio);
6452 btrfs_io_bio(bio)->mirror_num = bbio->mirror_num;
6454 if (atomic_read(&bbio->error) > bbio->max_errors)
6458 btrfs_end_bbio(bbio, bio);
6473 struct btrfs_bio *bbio = NULL;
6480 &map_length, &bbio, mirror_num, 1);
6486 total_devs = bbio->num_stripes;
6487 bbio->orig_bio = first_bio;
6488 bbio->private = first_bio->bi_private;
6489 bbio->end_io = first_bio->bi_end_io;
6490 bbio->fs_info = fs_info;
6491 atomic_set(&bbio->stripes_pending, bbio->num_stripes);
6493 if ((bbio->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK) &&
6498 ret = raid56_parity_write(fs_info, bio, bbio,
6501 ret = raid56_parity_recover(fs_info, bio, bbio,
6517 dev = bbio->stripes[dev_nr].dev;
6522 bbio_error(bbio, first_bio, logical);
6531 submit_stripe_bio(bbio, bio, bbio->stripes[dev_nr].physical, dev);