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

block: pass a block_device to bio_clone_fast



Pass a block_device to bio_clone_fast and __bio_clone_fast and give
the functions more suitable names.

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-14-hch@lst.de


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent a0e8de79
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -663,11 +663,6 @@ to i/o submission, if the bio fields are likely to be accessed after the
i/o is issued (since the bio may otherwise get freed in case i/o completion
happens in the meantime).

The bio_clone_fast() routine may be used to duplicate a bio, where the clone
shares the bio_vec_list with the original bio (i.e. both point to the
same bio_vec_list). This would typically be used for splitting i/o requests
in lvm or md.

3.2 Generic bio helper Routines
-------------------------------

+18 −13
Original line number Diff line number Diff line
@@ -733,7 +733,8 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp)
	bio_set_flag(bio, BIO_CLONED);
	if (bio_flagged(bio_src, BIO_THROTTLED))
		bio_set_flag(bio, BIO_THROTTLED);
	if (bio_flagged(bio_src, BIO_REMAPPED))
	if (bio->bi_bdev == bio_src->bi_bdev &&
	    bio_flagged(bio_src, BIO_REMAPPED))
		bio_set_flag(bio, BIO_REMAPPED);
	bio->bi_ioprio = bio_src->bi_ioprio;
	bio->bi_write_hint = bio_src->bi_write_hint;
@@ -751,7 +752,8 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp)
}

/**
 * bio_clone_fast - clone a bio that shares the original bio's biovec
 * bio_alloc_clone - clone a bio that shares the original bio's biovec
 * @bdev: block_device to clone onto
 * @bio_src: bio to clone from
 * @gfp: allocation priority
 * @bs: bio_set to allocate from
@@ -761,11 +763,12 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp)
 *
 * The caller must ensure that the return bio is not freed before @bio_src.
 */
struct bio *bio_clone_fast(struct bio *bio_src, gfp_t gfp, struct bio_set *bs)
struct bio *bio_alloc_clone(struct block_device *bdev, struct bio *bio_src,
		gfp_t gfp, struct bio_set *bs)
{
	struct bio *bio;

	bio = bio_alloc_bioset(bio_src->bi_bdev, 0, bio_src->bi_opf, gfp, bs);
	bio = bio_alloc_bioset(bdev, 0, bio_src->bi_opf, gfp, bs);
	if (!bio)
		return NULL;

@@ -777,10 +780,11 @@ struct bio *bio_clone_fast(struct bio *bio_src, gfp_t gfp, struct bio_set *bs)

	return bio;
}
EXPORT_SYMBOL(bio_clone_fast);
EXPORT_SYMBOL(bio_alloc_clone);

/**
 * __bio_clone_fast - clone a bio that shares the original bio's biovec
 * bio_init_clone - clone a bio that shares the original bio's biovec
 * @bdev: block_device to clone onto
 * @bio: bio to clone into
 * @bio_src: bio to clone from
 * @gfp: allocation priority
@@ -790,17 +794,18 @@ EXPORT_SYMBOL(bio_clone_fast);
 *
 * The caller must ensure that @bio_src is not freed before @bio.
 */
int __bio_clone_fast(struct bio *bio, struct bio *bio_src, gfp_t gfp)
int bio_init_clone(struct block_device *bdev, struct bio *bio,
		struct bio *bio_src, gfp_t gfp)
{
	int ret;

	bio_init(bio, bio_src->bi_bdev, bio_src->bi_io_vec, 0, bio_src->bi_opf);
	bio_init(bio, bdev, bio_src->bi_io_vec, 0, bio_src->bi_opf);
	ret = __bio_clone(bio, bio_src, gfp);
	if (ret)
		bio_uninit(bio);
	return ret;
}
EXPORT_SYMBOL(__bio_clone_fast);
EXPORT_SYMBOL(bio_init_clone);

const char *bio_devname(struct bio *bio, char *buf)
{
@@ -1572,7 +1577,7 @@ struct bio *bio_split(struct bio *bio, int sectors,
	if (WARN_ON_ONCE(bio_op(bio) == REQ_OP_ZONE_APPEND))
		return NULL;

	split = bio_clone_fast(bio, gfp, bs);
	split = bio_alloc_clone(bio->bi_bdev, bio, gfp, bs);
	if (!split)
		return NULL;

@@ -1667,9 +1672,9 @@ EXPORT_SYMBOL(bioset_exit);
 *    Note that the bio must be embedded at the END of that structure always,
 *    or things will break badly.
 *    If %BIOSET_NEED_BVECS is set in @flags, a separate pool will be allocated
 *    for allocating iovecs.  This pool is not needed e.g. for bio_clone_fast().
 *    If %BIOSET_NEED_RESCUER is set, a workqueue is created which can be used to
 *    dispatch queued requests when the mempool runs out of space.
 *    for allocating iovecs.  This pool is not needed e.g. for bio_init_clone().
 *    If %BIOSET_NEED_RESCUER is set, a workqueue is created which can be used
 *    to dispatch queued requests when the mempool runs out of space.
 *
 */
int bioset_init(struct bio_set *bs,
+2 −2
Original line number Diff line number Diff line
@@ -2975,10 +2975,10 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
		bs = &fs_bio_set;

	__rq_for_each_bio(bio_src, rq_src) {
		bio = bio_clone_fast(bio_src, gfp_mask, bs);
		bio = bio_alloc_clone(rq->q->disk->part0, bio_src, gfp_mask,
				      bs);
		if (!bio)
			goto free_and_out;
		bio->bi_bdev = rq->q->disk->part0;

		if (bio_ctr && bio_ctr(bio, bio_src, data))
			goto free_and_out;
+1 −2
Original line number Diff line number Diff line
@@ -162,8 +162,7 @@ static struct bio *bounce_clone_bio(struct bio *bio_src)
	 *    that does not own the bio - reason being drivers don't use it for
	 *    iterating over the biovec anymore, so expecting it to be kept up
	 *    to date (i.e. for clones that share the parent biovec) is just
	 *    asking for trouble and would force extra work on
	 *    __bio_clone_fast() anyways.
	 *    asking for trouble and would force extra work.
	 */
	bio = bio_alloc_bioset(bio_src->bi_bdev, bio_segments(bio_src),
			       bio_src->bi_opf, GFP_NOIO, &bounce_bio_set);
+2 −2
Original line number Diff line number Diff line
@@ -30,8 +30,8 @@ static struct drbd_request *drbd_req_new(struct drbd_device *device, struct bio
		return NULL;
	memset(req, 0, sizeof(*req));

	req->private_bio = bio_clone_fast(bio_src, GFP_NOIO, &drbd_io_bio_set);
	bio_set_dev(req->private_bio, device->ldev->backing_bdev);
	req->private_bio = bio_alloc_clone(device->ldev->backing_bdev, bio_src,
					   GFP_NOIO, &drbd_io_bio_set);
	req->private_bio->bi_private = req;
	req->private_bio->bi_end_io = drbd_request_endio;

Loading