]> www.infradead.org Git - users/hch/block.git/commitdiff
block: pass a bdev argument to bio_kmalloc
authorChristoph Hellwig <hch@lst.de>
Fri, 29 Jan 2021 05:50:47 +0000 (06:50 +0100)
committerChristoph Hellwig <hch@lst.de>
Tue, 2 Feb 2021 09:41:12 +0000 (10:41 +0100)
Clean up some code and prepare for always having a valid bi_bdev in
the bio.

Signed-off-by: Christoph Hellwig <hch@lst.de>
12 files changed:
block/bio.c
block/blk-crypto-fallback.c
block/blk-map.c
drivers/block/pktcdvd.c
drivers/md/bcache/debug.c
drivers/md/dm-bufio.c
drivers/md/raid1.c
drivers/md/raid10.c
drivers/target/target_core_pscsi.c
fs/btrfs/volumes.c
fs/squashfs/block.c
include/linux/bio.h

index 9baaa18c2d34f639dd1a4edca3aba6ce451c9493..f56b71153f40bb7da7f476336a18846cb18bcb29 100644 (file)
@@ -507,14 +507,16 @@ EXPORT_SYMBOL(bio_alloc_bioset);
 
 /**
  * bio_kmalloc - kmalloc a bio for I/O
- * @gfp_mask:   the GFP_* mask given to the slab allocator
+ * @bdev:      block device to allocate the bio for.
  * @nr_iovecs: number of iovecs to pre-allocate
+ * @gfp_mask:   the GFP_* mask given to the slab allocator
  *
  * Use kmalloc to allocate and initialize a bio.
  *
  * Returns: Pointer to new bio on success, NULL on failure.
  */
-struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs)
+struct bio *bio_kmalloc(struct block_device *bdev, unsigned int nr_iovecs,
+               gfp_t gfp_mask)
 {
        struct bio *bio;
 
@@ -525,6 +527,8 @@ struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs)
        if (unlikely(!bio))
                return NULL;
        bio_init(bio, nr_iovecs ? bio->bi_inline_vecs : NULL, nr_iovecs);
+       if (bdev)
+               bio_set_dev(bio, bdev);
        bio->bi_pool = NULL;
        return bio;
 }
index e8327c50d7c9f4ddcf6ace26dc97f227d2dcbcba..3c2906cb30b6113e2f445b003bf111bcca94ba6f 100644 (file)
@@ -164,10 +164,10 @@ static struct bio *blk_crypto_clone_bio(struct bio *bio_src)
        struct bio_vec bv;
        struct bio *bio;
 
-       bio = bio_kmalloc(GFP_NOIO, bio_segments(bio_src));
+       bio = bio_kmalloc(bio_src->bi_bdev, bio_segments(bio_src), GFP_NOIO);
        if (!bio)
                return NULL;
-       bio->bi_bdev            = bio_src->bi_bdev;
+
        if (bio_flagged(bio_src, BIO_REMAPPED))
                bio_set_flag(bio, BIO_REMAPPED);
        bio->bi_opf             = bio_src->bi_opf;
index 21630dccac628c3fac3131c5d900fc144ea962e1..38fa596059df07b6966da48cd178b23309c94c56 100644 (file)
@@ -155,7 +155,7 @@ static int bio_copy_user_iov(struct request *rq, struct rq_map_data *map_data,
                nr_pages = BIO_MAX_PAGES;
 
        ret = -ENOMEM;
-       bio = bio_kmalloc(gfp_mask, nr_pages);
+       bio = bio_kmalloc(NULL, nr_pages, gfp_mask);
        if (!bio)
                goto out_bmd;
        bio->bi_opf |= req_op(rq);
@@ -251,7 +251,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
        if (!iov_iter_count(iter))
                return -EINVAL;
 
-       bio = bio_kmalloc(gfp_mask, iov_iter_npages(iter, BIO_MAX_PAGES));
+       bio = bio_kmalloc(NULL, iov_iter_npages(iter, BIO_MAX_PAGES), gfp_mask);
        if (!bio)
                return -ENOMEM;
        bio->bi_opf |= req_op(rq);
@@ -390,7 +390,7 @@ static struct bio *bio_map_kern(struct request_queue *q, void *data,
        int offset, i;
        struct bio *bio;
 
-       bio = bio_kmalloc(gfp_mask, nr_pages);
+       bio = bio_kmalloc(NULL, nr_pages, gfp_mask);
        if (!bio)
                return ERR_PTR(-ENOMEM);
 
@@ -477,7 +477,7 @@ static struct bio *bio_copy_kern(struct request_queue *q, void *data,
                return ERR_PTR(-EINVAL);
 
        nr_pages = end - start;
-       bio = bio_kmalloc(gfp_mask, nr_pages);
+       bio = bio_kmalloc(NULL, nr_pages, gfp_mask);
        if (!bio)
                return ERR_PTR(-ENOMEM);
 
index 461233dc73599ec0c865a86e62bee5d0f8209803..2d33fe898c1be724314c9331a0f1d2d4fb270e6f 100644 (file)
@@ -529,7 +529,7 @@ static struct packet_data *pkt_alloc_packet_data(int frames)
                goto no_pkt;
 
        pkt->frames = frames;
-       pkt->w_bio = bio_kmalloc(GFP_KERNEL, frames);
+       pkt->w_bio = bio_kmalloc(NULL, frames, GFP_KERNEL);
        if (!pkt->w_bio)
                goto no_bio;
 
@@ -543,7 +543,7 @@ static struct packet_data *pkt_alloc_packet_data(int frames)
        bio_list_init(&pkt->orig_bios);
 
        for (i = 0; i < frames; i++) {
-               struct bio *bio = bio_kmalloc(GFP_KERNEL, 1);
+               struct bio *bio = bio_kmalloc(NULL, 1, GFP_KERNEL);
                if (!bio)
                        goto no_rd_bio;
 
index 1b54534973b03a11b9c2a2484a6a9e48e56b26f6..23fad089be2b4467740e2e74674cae69f806d5de 100644 (file)
@@ -110,10 +110,9 @@ void bch_data_verify(struct cached_dev *dc, struct bio *bio)
        struct bio_vec bv, cbv;
        struct bvec_iter iter, citer = { 0 };
 
-       check = bio_kmalloc(GFP_NOIO, bio_segments(bio));
+       check = bio_kmalloc(bio->bi_bdev, bio_segments(bio), GFP_NOIO);
        if (!check)
                return;
-       bio_set_dev(check, bio->bi_bdev);
        check->bi_opf = REQ_OP_READ;
        check->bi_iter.bi_sector = bio->bi_iter.bi_sector;
        check->bi_iter.bi_size = bio->bi_iter.bi_size;
index fce4cbf9529d6c85e5f7df6e99eb71db2c1df053..845697e144bbbd4771eae9a90a508fe66011df12 100644 (file)
@@ -626,7 +626,8 @@ static void use_bio(struct dm_buffer *b, int rw, sector_t sector,
        if (unlikely(b->c->sectors_per_block_bits < PAGE_SHIFT - SECTOR_SHIFT))
                vec_size += 2;
 
-       bio = bio_kmalloc(GFP_NOWAIT | __GFP_NORETRY | __GFP_NOWARN, vec_size);
+       bio = bio_kmalloc(b->c->bdev, vec_size,
+                         GFP_NOWAIT | __GFP_NORETRY | __GFP_NOWARN);
        if (!bio) {
 dmio:
                use_dmio(b, rw, sector, n_sectors, offset);
@@ -634,7 +635,6 @@ dmio:
        }
 
        bio->bi_iter.bi_sector = sector;
-       bio_set_dev(bio, b->c->bdev);
        bio_set_op_attrs(bio, rw, 0);
        bio->bi_end_io = bio_complete;
        bio->bi_private = b;
index 61ebba71152a6df226ad54c3e5fedfdf97476007..27b3f8adecd8e015e0049f82460c913b222eec0e 100644 (file)
@@ -165,7 +165,7 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
         * Allocate bios : 1 for reading, n-1 for writing
         */
        for (j = pi->raid_disks ; j-- ; ) {
-               bio = bio_kmalloc(gfp_flags, RESYNC_PAGES);
+               bio = bio_kmalloc(NULL, RESYNC_PAGES, gfp_flags);
                if (!bio)
                        goto out_free_bio;
                r1_bio->bios[j] = bio;
index e877f3f75430b59be01547c1521d05010ef6b62e..3843706cd15ca34f25d9ffd647e389446aa00843 100644 (file)
@@ -145,13 +145,13 @@ static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data)
         * Allocate bios.
         */
        for (j = nalloc ; j-- ; ) {
-               bio = bio_kmalloc(gfp_flags, RESYNC_PAGES);
+               bio = bio_kmalloc(NULL, RESYNC_PAGES, gfp_flags);
                if (!bio)
                        goto out_free_bio;
                r10_bio->devs[j].bio = bio;
                if (!conf->have_replacement)
                        continue;
-               bio = bio_kmalloc(gfp_flags, RESYNC_PAGES);
+               bio = bio_kmalloc(NULL, RESYNC_PAGES, gfp_flags);
                if (!bio)
                        goto out_free_bio;
                r10_bio->devs[j].repl_bio = bio;
index 33770e5808ce5eb27dbf3fc5ee444bc7aa1b3444..8b264937e025e64af8313e9ac066f06a95ae36cb 100644 (file)
@@ -832,7 +832,7 @@ static inline struct bio *pscsi_get_bio(int nr_vecs)
         * Use bio_malloc() following the comment in for bio -> struct request
         * in block/blk-core.c:blk_make_request()
         */
-       bio = bio_kmalloc(GFP_KERNEL, nr_vecs);
+       bio = bio_kmalloc(NULL, nr_vecs, GFP_KERNEL);
        if (!bio) {
                pr_err("PSCSI: bio_kmalloc() failed\n");
                return NULL;
index 584ba093cf496613f523b53a66d1ebf0579b23d8..e9749b08d9671e6d1c206b76823ea8ca606b63cd 100644 (file)
@@ -420,8 +420,10 @@ static struct btrfs_device *__alloc_device(struct btrfs_fs_info *fs_info)
        /*
         * Preallocate a bio that's always going to be used for flushing device
         * barriers and matches the device lifespan
+        *
+        * bi_bdev will be set later before the bio is used.
         */
-       dev->flush_bio = bio_kmalloc(GFP_KERNEL, 0);
+       dev->flush_bio = bio_kmalloc(NULL, 0, GFP_KERNEL);
        if (!dev->flush_bio) {
                kfree(dev);
                return ERR_PTR(-ENOMEM);
index 0f7a8baca618b83004665f36ebace744f6beaa7d..a9f6861ccf2d70cc3ba63624f16627d407b65596 100644 (file)
@@ -90,7 +90,7 @@ static int squashfs_bio_read(struct super_block *sb, u64 index, int length,
        if (page_count <= BIO_MAX_PAGES)
                bio = bio_alloc(sb->s_bdev, page_count, GFP_NOIO);
        else
-               bio = bio_kmalloc(GFP_NOIO, page_count);
+               bio = bio_kmalloc(sb->s_bdev, page_count, GFP_NOIO);
 
        if (!bio)
                return -ENOMEM;
index 5ca149d60c4162a5272666dcf714d8132de6b52b..d0e87174d263e603b0e2aa9b3df8daab923330f5 100644 (file)
@@ -409,7 +409,8 @@ extern int bioset_init_from_src(struct bio_set *bs, struct bio_set *src);
 
 struct bio *bio_alloc_bioset(struct block_device *bdev, unsigned int nr_iovecs,
                gfp_t gfp_mask, struct bio_set *bs);
-struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs);
+struct bio *bio_kmalloc(struct block_device *bdev, unsigned int nr_iovecs,
+               gfp_t gfp_mask);
 extern void bio_put(struct bio *);
 
 void __bio_clone_fast(struct bio *, struct bio *);