]> www.infradead.org Git - users/hch/block.git/commitdiff
block: allow passing a NULL bdev to bio_alloc_clone/bio_init_clone blk-clone-no-bdev
authorChristoph Hellwig <hch@lst.de>
Sat, 23 Apr 2022 16:13:55 +0000 (18:13 +0200)
committerChristoph Hellwig <hch@lst.de>
Sat, 23 Apr 2022 16:54:31 +0000 (18:54 +0200)
Device mapper wants to allocate a bio before knowing the device it
gets send to, so add explicit support for that.

Signed-off-by: Christoph Hellwig <hch@lst.de>
block/bio.c

index 3cffc01e6377fc575fd0d82e134ba577b8b9107e..23a6838cb97e096f75524b740f26aeec807f589f 100644 (file)
@@ -732,13 +732,15 @@ 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->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_iter = bio_src->bi_iter;
 
-       bio_clone_blkg_association(bio, bio_src);
+       if (bio->bi_bdev) {
+               if (bio->bi_bdev == bio_src->bi_bdev &&
+                   bio_flagged(bio_src, BIO_REMAPPED))
+                       bio_set_flag(bio, BIO_REMAPPED);
+               bio_clone_blkg_association(bio, bio_src);
+       }
 
        if (bio_crypt_clone(bio, bio_src, gfp) < 0)
                return -ENOMEM;