Skip to content

Commit f73f44e

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: add a op_is_flush helper
This centralizes the checks for bios that needs to be go into the flush state machine. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent c13660a commit f73f44e

7 files changed

Lines changed: 26 additions & 28 deletions

File tree

‎block/blk-core.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ static bool blk_rq_should_init_elevator(struct bio *bio)
10351035
* Flush requests do not use the elevator so skip initialization.
10361036
* This allows a request to share the flush and elevator data.
10371037
*/
1038-
if (bio->bi_opf & (REQ_PREFLUSH | REQ_FUA))
1038+
if (op_is_flush(bio->bi_opf))
10391039
return false;
10401040

10411041
return true;
@@ -1641,7 +1641,7 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)
16411641
return BLK_QC_T_NONE;
16421642
}
16431643

1644-
if (bio->bi_opf & (REQ_PREFLUSH | REQ_FUA)) {
1644+
if (op_is_flush(bio->bi_opf)) {
16451645
spin_lock_irq(q->queue_lock);
16461646
where = ELEVATOR_INSERT_FLUSH;
16471647
goto get_rq;
@@ -2145,7 +2145,7 @@ int blk_insert_cloned_request(struct request_queue *q, struct request *rq)
21452145
*/
21462146
BUG_ON(blk_queued_rq(rq));
21472147

2148-
if (rq->cmd_flags & (REQ_PREFLUSH | REQ_FUA))
2148+
if (op_is_flush(rq->cmd_flags))
21492149
where = ELEVATOR_INSERT_FLUSH;
21502150

21512151
add_acct_request(q, rq, where);
@@ -3256,7 +3256,7 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
32563256
/*
32573257
* rq is already accounted, so use raw insert
32583258
*/
3259-
if (rq->cmd_flags & (REQ_PREFLUSH | REQ_FUA))
3259+
if (op_is_flush(rq->cmd_flags))
32603260
__elv_add_request(q, rq, ELEVATOR_INSERT_FLUSH);
32613261
else
32623262
__elv_add_request(q, rq, ELEVATOR_INSERT_SORT_MERGE);

‎block/blk-mq-sched.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ struct request *blk_mq_sched_get_request(struct request_queue *q,
111111
struct blk_mq_hw_ctx *hctx;
112112
struct blk_mq_ctx *ctx;
113113
struct request *rq;
114-
const bool is_flush = op & (REQ_PREFLUSH | REQ_FUA);
115114

116115
blk_queue_enter_live(q);
117116
ctx = blk_mq_get_ctx(q);
@@ -126,7 +125,7 @@ struct request *blk_mq_sched_get_request(struct request_queue *q,
126125
* Flush requests are special and go directly to the
127126
* dispatch list.
128127
*/
129-
if (!is_flush && e->type->ops.mq.get_request) {
128+
if (!op_is_flush(op) && e->type->ops.mq.get_request) {
130129
rq = e->type->ops.mq.get_request(q, op, data);
131130
if (rq)
132131
rq->rq_flags |= RQF_QUEUED;
@@ -139,7 +138,7 @@ struct request *blk_mq_sched_get_request(struct request_queue *q,
139138
}
140139

141140
if (rq) {
142-
if (!is_flush) {
141+
if (!op_is_flush(op)) {
143142
rq->elv.icq = NULL;
144143
if (e && e->type->icq_cache)
145144
blk_mq_sched_assign_ioc(q, rq, bio);

‎block/blk-mq.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ static void blk_mq_try_issue_directly(struct request *rq, blk_qc_t *cookie)
14061406
static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
14071407
{
14081408
const int is_sync = op_is_sync(bio->bi_opf);
1409-
const int is_flush_fua = bio->bi_opf & (REQ_PREFLUSH | REQ_FUA);
1409+
const int is_flush_fua = op_is_flush(bio->bi_opf);
14101410
struct blk_mq_alloc_data data = { .flags = 0 };
14111411
struct request *rq;
14121412
unsigned int request_count = 0, srcu_idx;
@@ -1527,7 +1527,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
15271527
static blk_qc_t blk_sq_make_request(struct request_queue *q, struct bio *bio)
15281528
{
15291529
const int is_sync = op_is_sync(bio->bi_opf);
1530-
const int is_flush_fua = bio->bi_opf & (REQ_PREFLUSH | REQ_FUA);
1530+
const int is_flush_fua = op_is_flush(bio->bi_opf);
15311531
struct blk_plug *plug;
15321532
unsigned int request_count = 0;
15331533
struct blk_mq_alloc_data data = { .flags = 0 };

‎drivers/md/bcache/request.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ static inline struct search *search_alloc(struct bio *bio,
666666
s->iop.write_prio = 0;
667667
s->iop.error = 0;
668668
s->iop.flags = 0;
669-
s->iop.flush_journal = (bio->bi_opf & (REQ_PREFLUSH|REQ_FUA)) != 0;
669+
s->iop.flush_journal = op_is_flush(bio->bi_opf);
670670
s->iop.wq = bcache_wq;
671671

672672
return s;

‎drivers/md/dm-cache-target.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,7 @@ static void check_if_tick_bio_needed(struct cache *cache, struct bio *bio)
787787
struct per_bio_data *pb = get_per_bio_data(bio, pb_data_size);
788788

789789
spin_lock_irqsave(&cache->lock, flags);
790-
if (cache->need_tick_bio &&
791-
!(bio->bi_opf & (REQ_FUA | REQ_PREFLUSH)) &&
790+
if (cache->need_tick_bio && !op_is_flush(bio->bi_opf) &&
792791
bio_op(bio) != REQ_OP_DISCARD) {
793792
pb->tick = true;
794793
cache->need_tick_bio = false;
@@ -828,11 +827,6 @@ static dm_oblock_t get_bio_block(struct cache *cache, struct bio *bio)
828827
return to_oblock(block_nr);
829828
}
830829

831-
static int bio_triggers_commit(struct cache *cache, struct bio *bio)
832-
{
833-
return bio->bi_opf & (REQ_PREFLUSH | REQ_FUA);
834-
}
835-
836830
/*
837831
* You must increment the deferred set whilst the prison cell is held. To
838832
* encourage this, we ask for 'cell' to be passed in.
@@ -884,7 +878,7 @@ static void issue(struct cache *cache, struct bio *bio)
884878
{
885879
unsigned long flags;
886880

887-
if (!bio_triggers_commit(cache, bio)) {
881+
if (!op_is_flush(bio->bi_opf)) {
888882
accounted_request(cache, bio);
889883
return;
890884
}
@@ -1069,8 +1063,7 @@ static void dec_io_migrations(struct cache *cache)
10691063

10701064
static bool discard_or_flush(struct bio *bio)
10711065
{
1072-
return bio_op(bio) == REQ_OP_DISCARD ||
1073-
bio->bi_opf & (REQ_PREFLUSH | REQ_FUA);
1066+
return bio_op(bio) == REQ_OP_DISCARD || op_is_flush(bio->bi_opf);
10741067
}
10751068

10761069
static void __cell_defer(struct cache *cache, struct dm_bio_prison_cell *cell)

‎drivers/md/dm-thin.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ static void remap_to_origin(struct thin_c *tc, struct bio *bio)
699699

700700
static int bio_triggers_commit(struct thin_c *tc, struct bio *bio)
701701
{
702-
return (bio->bi_opf & (REQ_PREFLUSH | REQ_FUA)) &&
702+
return op_is_flush(bio->bi_opf) &&
703703
dm_thin_changed_this_transaction(tc->td);
704704
}
705705

@@ -870,8 +870,7 @@ static void __inc_remap_and_issue_cell(void *context,
870870
struct bio *bio;
871871

872872
while ((bio = bio_list_pop(&cell->bios))) {
873-
if (bio->bi_opf & (REQ_PREFLUSH | REQ_FUA) ||
874-
bio_op(bio) == REQ_OP_DISCARD)
873+
if (op_is_flush(bio->bi_opf) || bio_op(bio) == REQ_OP_DISCARD)
875874
bio_list_add(&info->defer_bios, bio);
876875
else {
877876
inc_all_io_entry(info->tc->pool, bio);
@@ -1716,9 +1715,8 @@ static void __remap_and_issue_shared_cell(void *context,
17161715
struct bio *bio;
17171716

17181717
while ((bio = bio_list_pop(&cell->bios))) {
1719-
if ((bio_data_dir(bio) == WRITE) ||
1720-
(bio->bi_opf & (REQ_PREFLUSH | REQ_FUA) ||
1721-
bio_op(bio) == REQ_OP_DISCARD))
1718+
if (bio_data_dir(bio) == WRITE || op_is_flush(bio->bi_opf) ||
1719+
bio_op(bio) == REQ_OP_DISCARD)
17221720
bio_list_add(&info->defer_bios, bio);
17231721
else {
17241722
struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));;
@@ -2635,8 +2633,7 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio)
26352633
return DM_MAPIO_SUBMITTED;
26362634
}
26372635

2638-
if (bio->bi_opf & (REQ_PREFLUSH | REQ_FUA) ||
2639-
bio_op(bio) == REQ_OP_DISCARD) {
2636+
if (op_is_flush(bio->bi_opf) || bio_op(bio) == REQ_OP_DISCARD) {
26402637
thin_defer_bio_with_throttle(tc, bio);
26412638
return DM_MAPIO_SUBMITTED;
26422639
}

‎include/linux/blk_types.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ static inline bool op_is_write(unsigned int op)
220220
return (op & 1);
221221
}
222222

223+
/*
224+
* Check if the bio or request is one that needs special treatment in the
225+
* flush state machine.
226+
*/
227+
static inline bool op_is_flush(unsigned int op)
228+
{
229+
return op & (REQ_FUA | REQ_PREFLUSH);
230+
}
231+
223232
/*
224233
* Reads are always treated as synchronous, as are requests with the FUA or
225234
* PREFLUSH flag. Other operations may be marked as synchronous using the

0 commit comments

Comments
 (0)