Skip to content

Commit f355265

Browse files
Ming Leiaxboe
authored andcommitted
block: introduce blk_init_flush and its pair
These two temporary functions are introduced for holding flush initialization and de-initialization, so that we can introduce 'flush queue' easier in the following patch. And once 'flush queue' and its allocation/free functions are ready, they will be removed for sake of code readability. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Ming Lei <ming.lei@canonical.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 1bcb1ea commit f355265

6 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎block/blk-core.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,7 @@ blk_init_allocated_queue(struct request_queue *q, request_fn_proc *rfn,
705705
if (!q)
706706
return NULL;
707707

708-
q->flush_rq = kzalloc(sizeof(struct request), GFP_KERNEL);
709-
if (!q->flush_rq)
708+
if (blk_init_flush(q))
710709
return NULL;
711710

712711
if (blk_init_rl(&q->root_rl, q, GFP_KERNEL))
@@ -742,7 +741,7 @@ blk_init_allocated_queue(struct request_queue *q, request_fn_proc *rfn,
742741
return q;
743742

744743
fail:
745-
kfree(q->flush_rq);
744+
blk_exit_flush(q);
746745
return NULL;
747746
}
748747
EXPORT_SYMBOL(blk_init_allocated_queue);

‎block/blk-flush.c‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
472472
}
473473
EXPORT_SYMBOL(blkdev_issue_flush);
474474

475-
int blk_mq_init_flush(struct request_queue *q)
475+
static int blk_mq_init_flush(struct request_queue *q)
476476
{
477477
struct blk_mq_tag_set *set = q->tag_set;
478478

@@ -485,3 +485,20 @@ int blk_mq_init_flush(struct request_queue *q)
485485
return -ENOMEM;
486486
return 0;
487487
}
488+
489+
int blk_init_flush(struct request_queue *q)
490+
{
491+
if (q->mq_ops)
492+
return blk_mq_init_flush(q);
493+
494+
q->flush_rq = kzalloc(sizeof(struct request), GFP_KERNEL);
495+
if (!q->flush_rq)
496+
return -ENOMEM;
497+
498+
return 0;
499+
}
500+
501+
void blk_exit_flush(struct request_queue *q)
502+
{
503+
kfree(q->flush_rq);
504+
}

‎block/blk-mq.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
18591859

18601860
blk_mq_add_queue_tag_set(set, q);
18611861

1862-
if (blk_mq_init_flush(q))
1862+
if (blk_init_flush(q))
18631863
goto err_hw_queues;
18641864

18651865
blk_mq_map_swqueue(q);

‎block/blk-mq.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct blk_mq_ctx {
2727

2828
void __blk_mq_complete_request(struct request *rq);
2929
void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
30-
int blk_mq_init_flush(struct request_queue *q);
3130
void blk_mq_freeze_queue(struct request_queue *q);
3231
void blk_mq_free_queue(struct request_queue *q);
3332
void blk_mq_clone_flush_request(struct request *flush_rq,

‎block/blk-sysfs.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,11 @@ static void blk_release_queue(struct kobject *kobj)
517517
if (q->queue_tags)
518518
__blk_queue_free_tags(q);
519519

520+
blk_exit_flush(q);
521+
520522
if (q->mq_ops)
521523
blk_mq_free_queue(q);
522524

523-
kfree(q->flush_rq);
524-
525525
blk_trace_shutdown(q);
526526

527527
bdi_destroy(&q->backing_dev_info);

‎block/blk.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ static inline void __blk_get_queue(struct request_queue *q)
2222
kobject_get(&q->kobj);
2323
}
2424

25+
int blk_init_flush(struct request_queue *q);
26+
void blk_exit_flush(struct request_queue *q);
27+
2528
int blk_init_rl(struct request_list *rl, struct request_queue *q,
2629
gfp_t gfp_mask);
2730
void blk_exit_rl(struct request_list *rl);

0 commit comments

Comments
 (0)