Skip to content

Commit a83b576

Browse files
committed
block: fix stacked driver stats init and free
If a driver allocates a queue for stacked usage, then it does not currently get stats allocated. This causes the later init of, eg, writeback throttling to blow up. Move the init to the queue allocation instead. Additionally, allow a NULL callback unregistration. This avoids having the caller check for that, fixing another oops on removal of a block device that doesn't have poll stats allocated. Fixes: 34dbad5 ("blk-stat: convert to callback-based statistics reporting") Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 34dbad5 commit a83b576

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎block/blk-core.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,10 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
720720
if (!q->backing_dev_info)
721721
goto fail_split;
722722

723+
q->stats = blk_alloc_queue_stats();
724+
if (!q->stats)
725+
goto fail_stats;
726+
723727
q->backing_dev_info->ra_pages =
724728
(VM_MAX_READAHEAD * 1024) / PAGE_SIZE;
725729
q->backing_dev_info->capabilities = BDI_CAP_CGROUP_WRITEBACK;
@@ -776,6 +780,8 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
776780
fail_ref:
777781
percpu_ref_exit(&q->q_usage_counter);
778782
fail_bdi:
783+
blk_free_queue_stats(q->stats);
784+
fail_stats:
779785
bdi_put(q->backing_dev_info);
780786
fail_split:
781787
bioset_free(q->bio_split);
@@ -852,10 +858,6 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio);
852858

853859
int blk_init_allocated_queue(struct request_queue *q)
854860
{
855-
q->stats = blk_alloc_queue_stats();
856-
if (!q->stats)
857-
return -ENOMEM;
858-
859861
q->fq = blk_alloc_flush_queue(q, NUMA_NO_NODE, q->cmd_size);
860862
if (!q->fq)
861863
return -ENOMEM;

‎block/blk-stat.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ static void blk_stat_free_callback_rcu(struct rcu_head *head)
210210

211211
void blk_stat_free_callback(struct blk_stat_callback *cb)
212212
{
213-
call_rcu(&cb->rcu, blk_stat_free_callback_rcu);
213+
if (cb)
214+
call_rcu(&cb->rcu, blk_stat_free_callback_rcu);
214215
}
215216
EXPORT_SYMBOL_GPL(blk_stat_free_callback);
216217

0 commit comments

Comments
 (0)