block: add meaningful macro for flush op flags
Subsystems (8)
Chaitanya Kulkarni
maintainerRFC PATCH 1/1 block: add meaningful macro for flush op flags
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/[email protected]/
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.
--- 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(-)
block/blk-flush.c +1 -1
@@ -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);
drivers/md/bcache/request.c +1 -2
@@ -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 ;
drivers/md/dm-bufio.c +1 -1
@@ -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,
drivers/md/dm-integrity.c +1 -1
@@ -1533,7 +1533,7 @@ static void dm_integrity_flush_buffers(struct dm_integrity_c *ic, bool flush_datif (!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,
drivers/md/dm-log.c +1 -1
@@ -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 ); }
drivers/md/dm-raid1.c +1 -1
@@ -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,
drivers/md/dm-snap-persistent.c +2 -3
@@ -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;
drivers/md/dm-writecache.c +1 -1
@@ -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;
drivers/md/dm.c +1 -1
@@ -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 ;
drivers/md/md.c +1 -2
@@ -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;
drivers/md/raid5-cache.c +1 -2
@@ -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); }
drivers/md/raid5-ppl.c +1 -2
@@ -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;
drivers/nvme/target/io-cmd-bdev.c +1 -1
@@ -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;
drivers/target/target_core_iblock.c +1 -2
@@ -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;
include/linux/blk_types.h +7 -0
@@ -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 ,
Signature · 1 line
2.40.0
Christoph Hellwig
maintainerHell no. This is just obsfucation. We can look into actually exposing REQ_OP_FLUSH at the bio level, but not something like this.
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Quoted 3 lines · Christoph Hellwig
Hell no. This is just obsfucation. We can look into actually exposing
REQ_OP_FLUSHat the bio level, but not something like this.
and that's why I made it RFC, thanks for the can you please elaborate on "exposing REQ_OP_FLUSH at the bio level" ?
I'd really like work that ...
-ck
Quoted 26 lines
2023年5月12日 10:07,Chaitanya Kulkarni <[email protected]> 写道:
Flush requests are implemented as
REQ_OP_WRITE+REQ_OP_PREFLUSHcombination and notREQ_OP_FLUSH+REQ_PREFLUSHcombination.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/[email protected]/
2. https://marc.info/?l=linux-block&m=168386364026498&w=2Add a macro (name can me more meaningful) with a meaningful comment clearing the confusion and replace the
REQ_OP_WRITE|REQ_PREFLUSHwith the new macro name that also saves code repetation.Signed-off-by Chaitanya Kulkarni <[email protected]>include/linux/blk_types.h +0
-0@@ -455,6 +455,13 @@ enum req_flag_bits {#define REQ_NOMERGE_FLAGS \ (REQ_NOMERGE | REQ_PREFLUSH | REQ_FUA)
include/linux/blk_types.h enum req_flag_bits { · line 467
Quoted 10 lines
include/linux/blk_types.h +7
-0+/* +* 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 ,
Personally I like current explicit way, it is simpler than an extra macro. This is just my own points, FYI.
Thanks.
Coly Li
Hi,
Quoted 7 lines · Chaitanya Kulkarni
Quoted 3 lines · Christoph Hellwig
Hell no. This is just obsfucation. We can look into actually exposing
REQ_OP_FLUSHat the bio level, but not something like this.and that's why I made it RFC, thanks for the can you please elaborate on "exposing
REQ_OP_FLUSHat the bio level" ?
I think Christoph means that use this flag directly for bio, it's only used for reqeust for now.
Thanks,
Kuai
Quoted 6 lines
I'd really like work that ...
-ck