Commit dc8e2021 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe
Browse files

dm: move cloning the bio into alloc_tio



Move the call to __bio_clone_fast and the assignment of ->len_ptr from
the callers into alloc_tio to prepare for changes to the bio clone API.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarMike Snitzer <snitzer@redhat.com>
Link: https://lore.kernel.org/r/20220202160109.108149-6-hch@lst.de


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 8eabf5d0
Loading
Loading
Loading
Loading
+10 −12
Original line number Diff line number Diff line
@@ -545,7 +545,7 @@ static void free_io(struct mapped_device *md, struct dm_io *io)
}

static struct dm_target_io *alloc_tio(struct clone_info *ci, struct dm_target *ti,
				      unsigned target_bio_nr, gfp_t gfp_mask)
		unsigned target_bio_nr, unsigned *len, gfp_t gfp_mask)
{
	struct dm_target_io *tio;

@@ -561,11 +561,13 @@ static struct dm_target_io *alloc_tio(struct clone_info *ci, struct dm_target *t
		tio = clone_to_tio(clone);
		tio->inside_dm_io = false;
	}
	__bio_clone_fast(&tio->clone, ci->bio);

	tio->magic = DM_TIO_MAGIC;
	tio->io = ci->io;
	tio->ti = ti;
	tio->target_bio_nr = target_bio_nr;
	tio->len_ptr = len;

	return tio;
}
@@ -1197,11 +1199,8 @@ static int __clone_and_map_data_bio(struct clone_info *ci, struct dm_target *ti,
	struct dm_target_io *tio;
	int r;

	tio = alloc_tio(ci, ti, 0, GFP_NOIO);
	tio->len_ptr = len;

	tio = alloc_tio(ci, ti, 0, len, GFP_NOIO);
	clone = &tio->clone;
	__bio_clone_fast(clone, bio);

	r = bio_crypt_clone(clone, bio, GFP_NOIO);
	if (r < 0)
@@ -1236,7 +1235,8 @@ static int __clone_and_map_data_bio(struct clone_info *ci, struct dm_target *ti,
}

static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci,
				struct dm_target *ti, unsigned num_bios)
				struct dm_target *ti, unsigned num_bios,
				unsigned *len)
{
	struct dm_target_io *tio;
	int try;
@@ -1245,7 +1245,7 @@ static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci,
		return;

	if (num_bios == 1) {
		tio = alloc_tio(ci, ti, 0, GFP_NOIO);
		tio = alloc_tio(ci, ti, 0, len, GFP_NOIO);
		bio_list_add(blist, &tio->clone);
		return;
	}
@@ -1257,7 +1257,8 @@ static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci,
		if (try)
			mutex_lock(&ci->io->md->table_devices_lock);
		for (bio_nr = 0; bio_nr < num_bios; bio_nr++) {
			tio = alloc_tio(ci, ti, bio_nr, try ? GFP_NOIO : GFP_NOWAIT);
			tio = alloc_tio(ci, ti, bio_nr, len,
					try ? GFP_NOIO : GFP_NOWAIT);
			if (!tio)
				break;

@@ -1279,14 +1280,11 @@ static void __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti,
	struct bio_list blist = BIO_EMPTY_LIST;
	struct bio *clone;

	alloc_multiple_bios(&blist, ci, ti, num_bios);
	alloc_multiple_bios(&blist, ci, ti, num_bios, len);

	while ((clone = bio_list_pop(&blist))) {
		struct dm_target_io *tio = clone_to_tio(clone);

		tio->len_ptr = len;

		__bio_clone_fast(clone, ci->bio);
		if (len)
			bio_setup_sector(clone, ci->sector, *len);
		__map_bio(tio);