@@ -460,7 +460,7 @@ int blkdev_issue_flush(struct block_device *bdev)
{
struct bio bio;
- bio_init(&bio, bdev, NULL, 0, REQ_OP_WRITE | REQ_PREFLUSH);
+ bio_init(&bio, bdev, NULL, 0, REQ_FLUSH_OPF);
return submit_bio_wait(&bio);
}
EXPORT_SYMBOL(blkdev_issue_flush);
@@ -1023,8 +1023,7 @@ static void cached_dev_write(struct cached_dev *dc, struct search *s)
*/
struct bio *flush;
- flush = bio_alloc_bioset(bio->bi_bdev, 0,
- REQ_OP_WRITE | REQ_PREFLUSH,
+ flush = bio_alloc_bioset(bio->bi_bdev, 0, REQ_FLUSH_OPF,
GFP_NOIO, &dc->disk.bio_split);
if (!flush) {
s->iop.status = BLK_STS_RESOURCE;
@@ -2133,7 +2133,7 @@ EXPORT_SYMBOL_GPL(dm_bufio_write_dirty_buffers);
int dm_bufio_issue_flush(struct dm_bufio_client *c)
{
struct dm_io_request io_req = {
- .bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC,
+ .bi_opf = REQ_FLUSH_OPF | REQ_SYNC,
.mem.type = DM_IO_KMEM,
.mem.ptr.addr = NULL,
.client = c->dm_io,
@@ -1533,7 +1533,7 @@ static void dm_integrity_flush_buffers(struct dm_integrity_c *ic, bool flush_dat
if (!ic->meta_dev)
flush_data = false;
if (flush_data) {
- fr.io_req.bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC,
+ fr.io_req.bi_opf = REQ_FLUSH_OPF | REQ_SYNC,
fr.io_req.mem.type = DM_IO_KMEM,
fr.io_req.mem.ptr.addr = NULL,
fr.io_req.notify.fn = flush_notify,
@@ -311,7 +311,7 @@ static int flush_header(struct log_c *lc)
.count = 0,
};
- lc->io_req.bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
+ lc->io_req.bi_opf = REQ_FLUSH_OPF;
return dm_io(&lc->io_req, 1, &null_location, NULL);
}
@@ -265,7 +265,7 @@ static int mirror_flush(struct dm_target *ti)
struct dm_io_region io[MAX_NR_MIRRORS];
struct mirror *m;
struct dm_io_request io_req = {
- .bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC,
+ .bi_opf = REQ_FLUSH_OPF | REQ_SYNC,
.mem.type = DM_IO_KMEM,
.mem.ptr.addr = NULL,
.client = ms->io_client,
@@ -739,8 +739,7 @@ static void persistent_commit_exception(struct dm_exception_store *store,
/*
* Commit exceptions to disk.
*/
- if (ps->valid && area_io(ps, REQ_OP_WRITE | REQ_PREFLUSH | REQ_FUA |
- REQ_SYNC))
+ if (ps->valid && area_io(ps, REQ_FLUSH_OPF | REQ_FUA | REQ_SYNC))
ps->valid = 0;
/*
@@ -817,7 +816,7 @@ static int persistent_commit_merge(struct dm_exception_store *store,
for (i = 0; i < nr_merged; i++)
clear_exception(ps, ps->current_committed - 1 - i);
- r = area_io(ps, REQ_OP_WRITE | REQ_PREFLUSH | REQ_FUA);
+ r = area_io(ps, REQ_FLUSH_OPF | REQ_FUA);
if (r < 0)
return r;
@@ -590,7 +590,7 @@ static void writecache_disk_flush(struct dm_writecache *wc, struct dm_dev *dev)
region.bdev = dev->bdev;
region.sector = 0;
region.count = 0;
- req.bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
+ req.bi_opf = REQ_FLUSH_OPF;
req.mem.type = DM_IO_KMEM;
req.mem.ptr.addr = NULL;
req.client = wc->dm_io;
@@ -1555,7 +1555,7 @@ static void __send_empty_flush(struct clone_info *ci)
* the basis for the clone(s).
*/
bio_init(&flush_bio, ci->io->md->disk->part0, NULL, 0,
- REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC);
+ REQ_FLUSH_OPF | REQ_SYNC);
ci->bio = &flush_bio;
ci->sector_count = 0;
@@ -533,8 +533,7 @@ static void submit_flushes(struct work_struct *ws)
atomic_inc(&rdev->nr_pending);
atomic_inc(&rdev->nr_pending);
rcu_read_unlock();
- bi = bio_alloc_bioset(rdev->bdev, 0,
- REQ_OP_WRITE | REQ_PREFLUSH,
+ bi = bio_alloc_bioset(rdev->bdev, 0, REQ_FLUSH_OPF,
GFP_NOIO, &mddev->bio_set);
bi->bi_end_io = md_end_flush;
bi->bi_private = rdev;
@@ -1303,8 +1303,7 @@ void r5l_flush_stripe_to_raid(struct r5l_log *log)
if (!do_flush)
return;
- bio_init(&log->flush_bio, log->rdev->bdev, NULL, 0,
- REQ_OP_WRITE | REQ_PREFLUSH);
+ bio_init(&log->flush_bio, log->rdev->bdev, NULL, 0, REQ_FLUSH_OPF);
log->flush_bio.bi_end_io = r5l_log_flush_endio;
submit_bio(&log->flush_bio);
}
@@ -629,8 +629,7 @@ static void ppl_do_flush(struct ppl_io_unit *io)
if (bdev) {
struct bio *bio;
- bio = bio_alloc_bioset(bdev, 0,
- REQ_OP_WRITE | REQ_PREFLUSH,
+ bio = bio_alloc_bioset(bdev, 0, REQ_FLUSH_OPF,
GFP_NOIO, &ppl_conf->flush_bs);
bio->bi_private = io;
bio->bi_end_io = ppl_flush_endio;
@@ -342,7 +342,7 @@ static void nvmet_bdev_execute_flush(struct nvmet_req *req)
return;
bio_init(bio, req->ns->bdev, req->inline_bvec,
- ARRAY_SIZE(req->inline_bvec), REQ_OP_WRITE | REQ_PREFLUSH);
+ ARRAY_SIZE(req->inline_bvec), REQ_FLUSH_OPF);
bio->bi_private = req;
bio->bi_end_io = nvmet_bio_done;
@@ -419,8 +419,7 @@ iblock_execute_sync_cache(struct se_cmd *cmd)
if (immed)
target_complete_cmd(cmd, SAM_STAT_GOOD);
- bio = bio_alloc(ib_dev->ibd_bd, 0, REQ_OP_WRITE | REQ_PREFLUSH,
- GFP_KERNEL);
+ bio = bio_alloc(ib_dev->ibd_bd, 0, REQ_FLUSH_OPF, GFP_KERNEL);
bio->bi_end_io = iblock_end_io_flush;
if (!immed)
bio->bi_private = cmd;
@@ -455,6 +455,13 @@ enum req_flag_bits {
#define REQ_NOMERGE_FLAGS \
(REQ_NOMERGE | REQ_PREFLUSH | REQ_FUA)
+/*
+ * Flush requests are implemented as REQ_OP_WRITE + REQ_OP_PREFLUSH combination
+ * and not REQ_OP_FLUSH + REQ_PREFLUSH combination.
+ */
+
+#define REQ_FLUSH_OPF (REQ_OP_WRITE | REQ_PREFLUSH)
+
enum stat_group {
STAT_READ,
STAT_WRITE,
Flush requests are implemented as REQ_OP_WRITE + REQ_OP_PREFLUSH combination and not REQ_OP_FLUSH + REQ_PREFLUSH combination. This unclear nature has lead to the confusion and bugs in the code for block drivers causing more work for testing, reviews and fixes :- 1. https://lore.kernel.org/all/ZFHgefWofVt24tRl@infradead.org/ 2. https://marc.info/?l=linux-block&m=168386364026498&w=2 Add a macro (name can me more meaningful) with a meaningful comment clearing the confusion and replace the REQ_OP_WRITE | REQ_PREFLUSH with the new macro name that also saves code repetation. Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com> --- block/blk-flush.c | 2 +- drivers/md/bcache/request.c | 3 +-- drivers/md/dm-bufio.c | 2 +- drivers/md/dm-integrity.c | 2 +- drivers/md/dm-log.c | 2 +- drivers/md/dm-raid1.c | 2 +- drivers/md/dm-snap-persistent.c | 5 ++--- drivers/md/dm-writecache.c | 2 +- drivers/md/dm.c | 2 +- drivers/md/md.c | 3 +-- drivers/md/raid5-cache.c | 3 +-- drivers/md/raid5-ppl.c | 3 +-- drivers/nvme/target/io-cmd-bdev.c | 2 +- drivers/target/target_core_iblock.c | 3 +-- include/linux/blk_types.h | 7 +++++++ 15 files changed, 22 insertions(+), 21 deletions(-)