Suggested-by: Christoph Hellwig <hch@xxxxxx> Signed-off-by: Mike Snitzer <snitzer@xxxxxxxxxx> --- drivers/md/dm.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 2461df65e2fe..20c7b1b4d1f7 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -546,13 +546,16 @@ static struct bio *alloc_tio(struct clone_info *ci, struct dm_target *ti, unsigned target_bio_nr, unsigned *len, gfp_t gfp_mask) { struct dm_target_io *tio; + struct bio *clone; if (!ci->io->tio.io) { /* the dm_target_io embedded in ci->io is available */ tio = &ci->io->tio; + /* alloc_io() already initialized embedded clone */ + clone = &tio->clone; } else { - struct bio *clone = bio_alloc_clone(ci->bio->bi_bdev, ci->bio, - gfp_mask, &ci->io->md->bs); + clone = bio_alloc_clone(ci->bio->bi_bdev, ci->bio, + gfp_mask, &ci->io->md->bs); if (!clone) return NULL; @@ -567,7 +570,13 @@ static struct bio *alloc_tio(struct clone_info *ci, struct dm_target *ti, tio->len_ptr = len; tio->old_sector = 0; - return &tio->clone; + if (len) { + clone->bi_iter.bi_size = to_bytes(*len); + if (bio_integrity(clone)) + bio_integrity_trim(clone); + } + + return clone; } static void free_tio(struct bio *clone) @@ -1258,17 +1267,12 @@ static void __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti, break; case 1: clone = alloc_tio(ci, ti, 0, len, GFP_NOIO); - if (len) - clone->bi_iter.bi_size = to_bytes(*len); __map_bio(clone); break; default: alloc_multiple_bios(&blist, ci, ti, num_bios, len); - while ((clone = bio_list_pop(&blist))) { - if (len) - clone->bi_iter.bi_size = to_bytes(*len); + while ((clone = bio_list_pop(&blist))) __map_bio(clone); - } break; } } @@ -1382,12 +1386,7 @@ static int __split_and_process_bio(struct clone_info *ci) return r; len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count); - clone = alloc_tio(ci, ti, 0, &len, GFP_NOIO); - clone->bi_iter.bi_size = to_bytes(len); - if (bio_integrity(clone)) - bio_integrity_trim(clone); - __map_bio(clone); ci->sector += len; -- 2.15.0