Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Kent Overstreet and committed by
Jens Axboe
bf800ef1 3f86a82a

+29 -46
+1 -7
block/blk-core.c
··· 2781 2781 blk_rq_init(NULL, rq); 2782 2782 2783 2783 __rq_for_each_bio(bio_src, rq_src) { 2784 - bio = bio_alloc_bioset(gfp_mask, bio_src->bi_max_vecs, bs); 2784 + bio = bio_clone_bioset(bio_src, gfp_mask, bs); 2785 2785 if (!bio) 2786 - goto free_and_out; 2787 - 2788 - __bio_clone(bio, bio_src); 2789 - 2790 - if (bio_integrity(bio_src) && 2791 - bio_integrity_clone(bio, bio_src, gfp_mask)) 2792 2786 goto free_and_out; 2793 2787 2794 2788 if (bio_ctr && bio_ctr(bio, bio_src, data))
+1 -2
drivers/block/osdblk.c
··· 266 266 struct bio *tmp, *new_chain = NULL, *tail = NULL; 267 267 268 268 while (old_chain) { 269 - tmp = bio_kmalloc(gfpmask, old_chain->bi_max_vecs); 269 + tmp = bio_clone_kmalloc(old_chain, gfpmask); 270 270 if (!tmp) 271 271 goto err_out; 272 272 273 - __bio_clone(tmp, old_chain); 274 273 tmp->bi_bdev = NULL; 275 274 gfpmask &= ~__GFP_WAIT; 276 275 tmp->bi_next = NULL;
+1 -6
drivers/md/dm-crypt.c
··· 979 979 * copy the required bvecs because we need the original 980 980 * one in order to decrypt the whole bio data *afterwards*. 981 981 */ 982 - clone = bio_alloc_bioset(gfp, bio_segments(base_bio), cc->bs); 982 + clone = bio_clone_bioset(base_bio, gfp, cc->bs); 983 983 if (!clone) 984 984 return 1; 985 985 986 986 crypt_inc_pending(io); 987 987 988 988 clone_init(io, clone); 989 - clone->bi_idx = 0; 990 - clone->bi_vcnt = bio_segments(base_bio); 991 - clone->bi_size = base_bio->bi_size; 992 989 clone->bi_sector = cc->start + io->sector; 993 - memcpy(clone->bi_io_vec, bio_iovec(base_bio), 994 - sizeof(struct bio_vec) * clone->bi_vcnt); 995 990 996 991 generic_make_request(clone); 997 992 return 0;
+2 -2
drivers/md/dm.c
··· 1129 1129 * ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush 1130 1130 * and discard, so no need for concern about wasted bvec allocations. 1131 1131 */ 1132 - clone = bio_alloc_bioset(GFP_NOIO, ci->bio->bi_max_vecs, ci->md->bs); 1133 - __bio_clone(clone, ci->bio); 1132 + clone = bio_clone_bioset(ci->bio, GFP_NOIO, ci->md->bs); 1133 + 1134 1134 if (len) { 1135 1135 clone->bi_sector = ci->sector; 1136 1136 clone->bi_size = to_bytes(len);
+1 -19
drivers/md/md.c
··· 173 173 struct bio *bio_clone_mddev(struct bio *bio, gfp_t gfp_mask, 174 174 struct mddev *mddev) 175 175 { 176 - struct bio *b; 177 - 178 176 if (!mddev || !mddev->bio_set) 179 177 return bio_clone(bio, gfp_mask); 180 178 181 - b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, mddev->bio_set); 182 - if (!b) 183 - return NULL; 184 - 185 - __bio_clone(b, bio); 186 - if (bio_integrity(bio)) { 187 - int ret; 188 - 189 - ret = bio_integrity_clone(b, bio, gfp_mask); 190 - 191 - if (ret < 0) { 192 - bio_put(b); 193 - return NULL; 194 - } 195 - } 196 - 197 - return b; 179 + return bio_clone_bioset(bio, gfp_mask, mddev->bio_set); 198 180 } 199 181 EXPORT_SYMBOL_GPL(bio_clone_mddev); 200 182
+7 -4
fs/bio.c
··· 438 438 EXPORT_SYMBOL(__bio_clone); 439 439 440 440 /** 441 - * bio_clone - clone a bio 441 + * bio_clone_bioset - clone a bio 442 442 * @bio: bio to clone 443 443 * @gfp_mask: allocation priority 444 + * @bs: bio_set to allocate from 444 445 * 445 446 * Like __bio_clone, only also allocates the returned bio 446 447 */ 447 - struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask) 448 + struct bio *bio_clone_bioset(struct bio *bio, gfp_t gfp_mask, 449 + struct bio_set *bs) 448 450 { 449 - struct bio *b = bio_alloc(gfp_mask, bio->bi_max_vecs); 451 + struct bio *b; 450 452 453 + b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, bs); 451 454 if (!b) 452 455 return NULL; 453 456 ··· 469 466 470 467 return b; 471 468 } 472 - EXPORT_SYMBOL(bio_clone); 469 + EXPORT_SYMBOL(bio_clone_bioset); 473 470 474 471 /** 475 472 * bio_get_nr_vecs - return approx number of vecs
+2 -3
fs/exofs/ore.c
··· 814 814 struct bio *bio; 815 815 816 816 if (per_dev != master_dev) { 817 - bio = bio_kmalloc(GFP_KERNEL, 818 - master_dev->bio->bi_max_vecs); 817 + bio = bio_clone_kmalloc(master_dev->bio, 818 + GFP_KERNEL); 819 819 if (unlikely(!bio)) { 820 820 ORE_DBGMSG( 821 821 "Failed to allocate BIO size=%u\n", ··· 824 824 goto out; 825 825 } 826 826 827 - __bio_clone(bio, master_dev->bio); 828 827 bio->bi_bdev = NULL; 829 828 bio->bi_next = NULL; 830 829 per_dev->offset = master_dev->offset;
+14 -3
include/linux/bio.h
··· 215 215 extern struct bio *bio_alloc_bioset(gfp_t, int, struct bio_set *); 216 216 extern void bio_put(struct bio *); 217 217 218 + extern void __bio_clone(struct bio *, struct bio *); 219 + extern struct bio *bio_clone_bioset(struct bio *, gfp_t, struct bio_set *bs); 220 + 218 221 extern struct bio_set *fs_bio_set; 219 222 220 223 static inline struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs) ··· 225 222 return bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set); 226 223 } 227 224 225 + static inline struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask) 226 + { 227 + return bio_clone_bioset(bio, gfp_mask, fs_bio_set); 228 + } 229 + 228 230 static inline struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs) 229 231 { 230 232 return bio_alloc_bioset(gfp_mask, nr_iovecs, NULL); 231 233 } 232 234 235 + static inline struct bio *bio_clone_kmalloc(struct bio *bio, gfp_t gfp_mask) 236 + { 237 + return bio_clone_bioset(bio, gfp_mask, NULL); 238 + 239 + } 240 + 233 241 extern void bio_endio(struct bio *, int); 234 242 struct request_queue; 235 243 extern int bio_phys_segments(struct request_queue *, struct bio *); 236 - 237 - extern void __bio_clone(struct bio *, struct bio *); 238 - extern struct bio *bio_clone(struct bio *, gfp_t); 239 244 240 245 extern void bio_init(struct bio *); 241 246 extern void bio_reset(struct bio *);