Skip to content

Commit 892ad71

Browse files
dennisszhouaxboe
authored andcommitted
dm: set the static flush bio device on demand
The next patch changes the macro bio_set_dev() to associate a bio with a blkg based on the device set. However, dm creates a static bio to be used as the basis for cloning empty flush bios on creation. The bio_set_dev() call in alloc_dev() will cause problems with the next patch adding association to bio_set_dev() because the call is before the bdev is associated with a gendisk (bd_disk is %NULL). To get around this, set the device on the static bio every time and use that to clone to the other bios. Signed-off-by: Dennis Zhou <dennis@kernel.org> Acked-by: Mike Snitzer <snitzer@redhat.com> Cc: Alasdair Kergon <agk@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 2268c0f commit 892ad71

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

block/bio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,7 @@ void bio_disassociate_blkg(struct bio *bio)
20212021
bio->bi_blkg = NULL;
20222022
}
20232023
}
2024+
EXPORT_SYMBOL_GPL(bio_disassociate_blkg);
20242025

20252026
/**
20262027
* __bio_associate_blkg - associate a bio with the a blkg

drivers/md/dm.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,10 +1417,21 @@ static int __send_empty_flush(struct clone_info *ci)
14171417
unsigned target_nr = 0;
14181418
struct dm_target *ti;
14191419

1420+
/*
1421+
* Empty flush uses a statically initialized bio, &md->flush_bio, as
1422+
* the base for cloning. However, blkg association requires that a
1423+
* bdev is associated with a gendisk, which doesn't happen until the
1424+
* bdev is opened. So, blkg association is done at issue time of the
1425+
* flush rather than when the device is created in alloc_dev().
1426+
*/
1427+
bio_set_dev(ci->bio, ci->io->md->bdev);
1428+
14201429
BUG_ON(bio_has_data(ci->bio));
14211430
while ((ti = dm_table_get_target(ci->map, target_nr++)))
14221431
__send_duplicate_bios(ci, ti, ti->num_flush_bios, NULL);
14231432

1433+
bio_disassociate_blkg(ci->bio);
1434+
14241435
return 0;
14251436
}
14261437

@@ -1939,7 +1950,6 @@ static struct mapped_device *alloc_dev(int minor)
19391950
goto bad;
19401951

19411952
bio_init(&md->flush_bio, NULL, 0);
1942-
bio_set_dev(&md->flush_bio, md->bdev);
19431953
md->flush_bio.bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC;
19441954

19451955
dm_stats_init(&md->stats);

0 commit comments

Comments
 (0)