block: Add bio_clone_bioset(), bio_clone_kmalloc()
Previously, there was bio_clone() but it only allocated from the fs bio set; as a result various users were open coding it and using __bio_clone(). This changes bio_clone() to become bio_clone_bioset(), and then we add bio_clone() and bio_clone_kmalloc() as wrappers around it, making use of the functionality the last patch adedd. This will also help in a later patch changing how bio cloning works. Signed-off-by: Kent Overstreet <koverstreet@google.com> CC: Jens Axboe <axboe@kernel.dk> CC: NeilBrown <neilb@suse.de> CC: Alasdair Kergon <agk@redhat.com> CC: Boaz Harrosh <bharrosh@panasas.com> CC: Jeff Garzik <jeff@garzik.org> Acked-by: Jeff Garzik <jgarzik@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Родитель
3f86a82aeb
Коммит
bf800ef181
|
@ -2781,16 +2781,10 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
|
||||||
blk_rq_init(NULL, rq);
|
blk_rq_init(NULL, rq);
|
||||||
|
|
||||||
__rq_for_each_bio(bio_src, rq_src) {
|
__rq_for_each_bio(bio_src, rq_src) {
|
||||||
bio = bio_alloc_bioset(gfp_mask, bio_src->bi_max_vecs, bs);
|
bio = bio_clone_bioset(bio_src, gfp_mask, bs);
|
||||||
if (!bio)
|
if (!bio)
|
||||||
goto free_and_out;
|
goto free_and_out;
|
||||||
|
|
||||||
__bio_clone(bio, bio_src);
|
|
||||||
|
|
||||||
if (bio_integrity(bio_src) &&
|
|
||||||
bio_integrity_clone(bio, bio_src, gfp_mask))
|
|
||||||
goto free_and_out;
|
|
||||||
|
|
||||||
if (bio_ctr && bio_ctr(bio, bio_src, data))
|
if (bio_ctr && bio_ctr(bio, bio_src, data))
|
||||||
goto free_and_out;
|
goto free_and_out;
|
||||||
|
|
||||||
|
|
|
@ -266,11 +266,10 @@ static struct bio *bio_chain_clone(struct bio *old_chain, gfp_t gfpmask)
|
||||||
struct bio *tmp, *new_chain = NULL, *tail = NULL;
|
struct bio *tmp, *new_chain = NULL, *tail = NULL;
|
||||||
|
|
||||||
while (old_chain) {
|
while (old_chain) {
|
||||||
tmp = bio_kmalloc(gfpmask, old_chain->bi_max_vecs);
|
tmp = bio_clone_kmalloc(old_chain, gfpmask);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
goto err_out;
|
goto err_out;
|
||||||
|
|
||||||
__bio_clone(tmp, old_chain);
|
|
||||||
tmp->bi_bdev = NULL;
|
tmp->bi_bdev = NULL;
|
||||||
gfpmask &= ~__GFP_WAIT;
|
gfpmask &= ~__GFP_WAIT;
|
||||||
tmp->bi_next = NULL;
|
tmp->bi_next = NULL;
|
||||||
|
|
|
@ -979,19 +979,14 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
|
||||||
* copy the required bvecs because we need the original
|
* copy the required bvecs because we need the original
|
||||||
* one in order to decrypt the whole bio data *afterwards*.
|
* one in order to decrypt the whole bio data *afterwards*.
|
||||||
*/
|
*/
|
||||||
clone = bio_alloc_bioset(gfp, bio_segments(base_bio), cc->bs);
|
clone = bio_clone_bioset(base_bio, gfp, cc->bs);
|
||||||
if (!clone)
|
if (!clone)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
crypt_inc_pending(io);
|
crypt_inc_pending(io);
|
||||||
|
|
||||||
clone_init(io, clone);
|
clone_init(io, clone);
|
||||||
clone->bi_idx = 0;
|
|
||||||
clone->bi_vcnt = bio_segments(base_bio);
|
|
||||||
clone->bi_size = base_bio->bi_size;
|
|
||||||
clone->bi_sector = cc->start + io->sector;
|
clone->bi_sector = cc->start + io->sector;
|
||||||
memcpy(clone->bi_io_vec, bio_iovec(base_bio),
|
|
||||||
sizeof(struct bio_vec) * clone->bi_vcnt);
|
|
||||||
|
|
||||||
generic_make_request(clone);
|
generic_make_request(clone);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1129,8 +1129,8 @@ static void __issue_target_request(struct clone_info *ci, struct dm_target *ti,
|
||||||
* ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush
|
* ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush
|
||||||
* and discard, so no need for concern about wasted bvec allocations.
|
* and discard, so no need for concern about wasted bvec allocations.
|
||||||
*/
|
*/
|
||||||
clone = bio_alloc_bioset(GFP_NOIO, ci->bio->bi_max_vecs, ci->md->bs);
|
clone = bio_clone_bioset(ci->bio, GFP_NOIO, ci->md->bs);
|
||||||
__bio_clone(clone, ci->bio);
|
|
||||||
if (len) {
|
if (len) {
|
||||||
clone->bi_sector = ci->sector;
|
clone->bi_sector = ci->sector;
|
||||||
clone->bi_size = to_bytes(len);
|
clone->bi_size = to_bytes(len);
|
||||||
|
|
|
@ -173,28 +173,10 @@ EXPORT_SYMBOL_GPL(bio_alloc_mddev);
|
||||||
struct bio *bio_clone_mddev(struct bio *bio, gfp_t gfp_mask,
|
struct bio *bio_clone_mddev(struct bio *bio, gfp_t gfp_mask,
|
||||||
struct mddev *mddev)
|
struct mddev *mddev)
|
||||||
{
|
{
|
||||||
struct bio *b;
|
|
||||||
|
|
||||||
if (!mddev || !mddev->bio_set)
|
if (!mddev || !mddev->bio_set)
|
||||||
return bio_clone(bio, gfp_mask);
|
return bio_clone(bio, gfp_mask);
|
||||||
|
|
||||||
b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, mddev->bio_set);
|
return bio_clone_bioset(bio, gfp_mask, mddev->bio_set);
|
||||||
if (!b)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
__bio_clone(b, bio);
|
|
||||||
if (bio_integrity(bio)) {
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = bio_integrity_clone(b, bio, gfp_mask);
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
bio_put(b);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(bio_clone_mddev);
|
EXPORT_SYMBOL_GPL(bio_clone_mddev);
|
||||||
|
|
||||||
|
|
11
fs/bio.c
11
fs/bio.c
|
@ -438,16 +438,19 @@ void __bio_clone(struct bio *bio, struct bio *bio_src)
|
||||||
EXPORT_SYMBOL(__bio_clone);
|
EXPORT_SYMBOL(__bio_clone);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bio_clone - clone a bio
|
* bio_clone_bioset - clone a bio
|
||||||
* @bio: bio to clone
|
* @bio: bio to clone
|
||||||
* @gfp_mask: allocation priority
|
* @gfp_mask: allocation priority
|
||||||
|
* @bs: bio_set to allocate from
|
||||||
*
|
*
|
||||||
* Like __bio_clone, only also allocates the returned bio
|
* Like __bio_clone, only also allocates the returned bio
|
||||||
*/
|
*/
|
||||||
struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask)
|
struct bio *bio_clone_bioset(struct bio *bio, gfp_t gfp_mask,
|
||||||
|
struct bio_set *bs)
|
||||||
{
|
{
|
||||||
struct bio *b = bio_alloc(gfp_mask, bio->bi_max_vecs);
|
struct bio *b;
|
||||||
|
|
||||||
|
b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, bs);
|
||||||
if (!b)
|
if (!b)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -466,7 +469,7 @@ struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask)
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(bio_clone);
|
EXPORT_SYMBOL(bio_clone_bioset);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bio_get_nr_vecs - return approx number of vecs
|
* bio_get_nr_vecs - return approx number of vecs
|
||||||
|
|
|
@ -814,8 +814,8 @@ static int _write_mirror(struct ore_io_state *ios, int cur_comp)
|
||||||
struct bio *bio;
|
struct bio *bio;
|
||||||
|
|
||||||
if (per_dev != master_dev) {
|
if (per_dev != master_dev) {
|
||||||
bio = bio_kmalloc(GFP_KERNEL,
|
bio = bio_clone_kmalloc(master_dev->bio,
|
||||||
master_dev->bio->bi_max_vecs);
|
GFP_KERNEL);
|
||||||
if (unlikely(!bio)) {
|
if (unlikely(!bio)) {
|
||||||
ORE_DBGMSG(
|
ORE_DBGMSG(
|
||||||
"Failed to allocate BIO size=%u\n",
|
"Failed to allocate BIO size=%u\n",
|
||||||
|
@ -824,7 +824,6 @@ static int _write_mirror(struct ore_io_state *ios, int cur_comp)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
__bio_clone(bio, master_dev->bio);
|
|
||||||
bio->bi_bdev = NULL;
|
bio->bi_bdev = NULL;
|
||||||
bio->bi_next = NULL;
|
bio->bi_next = NULL;
|
||||||
per_dev->offset = master_dev->offset;
|
per_dev->offset = master_dev->offset;
|
||||||
|
|
|
@ -215,6 +215,9 @@ extern void bioset_free(struct bio_set *);
|
||||||
extern struct bio *bio_alloc_bioset(gfp_t, int, struct bio_set *);
|
extern struct bio *bio_alloc_bioset(gfp_t, int, struct bio_set *);
|
||||||
extern void bio_put(struct bio *);
|
extern void bio_put(struct bio *);
|
||||||
|
|
||||||
|
extern void __bio_clone(struct bio *, struct bio *);
|
||||||
|
extern struct bio *bio_clone_bioset(struct bio *, gfp_t, struct bio_set *bs);
|
||||||
|
|
||||||
extern struct bio_set *fs_bio_set;
|
extern struct bio_set *fs_bio_set;
|
||||||
|
|
||||||
static inline struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs)
|
static inline struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs)
|
||||||
|
@ -222,18 +225,26 @@ static inline struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs)
|
||||||
return bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set);
|
return bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask)
|
||||||
|
{
|
||||||
|
return bio_clone_bioset(bio, gfp_mask, fs_bio_set);
|
||||||
|
}
|
||||||
|
|
||||||
static inline struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs)
|
static inline struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs)
|
||||||
{
|
{
|
||||||
return bio_alloc_bioset(gfp_mask, nr_iovecs, NULL);
|
return bio_alloc_bioset(gfp_mask, nr_iovecs, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct bio *bio_clone_kmalloc(struct bio *bio, gfp_t gfp_mask)
|
||||||
|
{
|
||||||
|
return bio_clone_bioset(bio, gfp_mask, NULL);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
extern void bio_endio(struct bio *, int);
|
extern void bio_endio(struct bio *, int);
|
||||||
struct request_queue;
|
struct request_queue;
|
||||||
extern int bio_phys_segments(struct request_queue *, struct bio *);
|
extern int bio_phys_segments(struct request_queue *, struct bio *);
|
||||||
|
|
||||||
extern void __bio_clone(struct bio *, struct bio *);
|
|
||||||
extern struct bio *bio_clone(struct bio *, gfp_t);
|
|
||||||
|
|
||||||
extern void bio_init(struct bio *);
|
extern void bio_init(struct bio *);
|
||||||
extern void bio_reset(struct bio *);
|
extern void bio_reset(struct bio *);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче