Skip to content

Commit 1059699

Browse files
Ming Leiaxboe
authored andcommitted
block: move blkcg initialization/destroy into disk allocation/release handler
blkcg works on FS bio level, so it is reasonable to make both blkcg and gendisk sharing same lifetime. Meantime there won't be any FS IO when releasing disk, so safe to move blkcg initialization/destroy into disk allocation/release handler Long term, we can move blkcg into gendisk completely. Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Link: https://lore.kernel.org/r/20220308055200.735835-10-hch@lst.de [axboe: fixup missing blk-cgroup.h include] Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 01d0c69 commit 1059699

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

block/blk-core.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,17 +496,12 @@ struct request_queue *blk_alloc_queue(int node_id, bool alloc_srcu)
496496
PERCPU_REF_INIT_ATOMIC, GFP_KERNEL))
497497
goto fail_stats;
498498

499-
if (blkcg_init_queue(q))
500-
goto fail_ref;
501-
502499
blk_queue_dma_alignment(q, 511);
503500
blk_set_default_limits(&q->limits);
504501
q->nr_requests = BLKDEV_DEFAULT_RQ;
505502

506503
return q;
507504

508-
fail_ref:
509-
percpu_ref_exit(&q->q_usage_counter);
510505
fail_stats:
511506
blk_free_queue_stats(q->stats);
512507
fail_split:

block/blk-sysfs.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -751,13 +751,6 @@ static void blk_exit_queue(struct request_queue *q)
751751
ioc_clear_queue(q);
752752
elevator_exit(q);
753753
}
754-
755-
/*
756-
* Remove all references to @q from the block cgroup controller before
757-
* restoring @q->queue_lock to avoid that restoring this pointer causes
758-
* e.g. blkcg_print_blkgs() to crash.
759-
*/
760-
blkcg_exit_queue(q);
761754
}
762755

763756
/**

block/genhd.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "blk.h"
3030
#include "blk-mq-sched.h"
3131
#include "blk-rq-qos.h"
32+
#include "blk-cgroup.h"
3233

3334
static struct kobject *block_depr;
3435

@@ -1120,9 +1121,12 @@ static void disk_release(struct device *dev)
11201121

11211122
blk_mq_cancel_work_sync(disk->queue);
11221123

1124+
blkcg_exit_queue(disk->queue);
1125+
11231126
disk_release_events(disk);
11241127
kfree(disk->random);
11251128
xa_destroy(&disk->part_tbl);
1129+
11261130
disk->queue->disk = NULL;
11271131
blk_put_queue(disk->queue);
11281132

@@ -1328,6 +1332,9 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
13281332
if (xa_insert(&disk->part_tbl, 0, disk->part0, GFP_KERNEL))
13291333
goto out_destroy_part_tbl;
13301334

1335+
if (blkcg_init_queue(q))
1336+
goto out_erase_part0;
1337+
13311338
rand_initialize_disk(disk);
13321339
disk_to_dev(disk)->class = &block_class;
13331340
disk_to_dev(disk)->type = &disk_type;
@@ -1340,6 +1347,8 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
13401347
#endif
13411348
return disk;
13421349

1350+
out_erase_part0:
1351+
xa_erase(&disk->part_tbl, 0);
13431352
out_destroy_part_tbl:
13441353
xa_destroy(&disk->part_tbl);
13451354
disk->part0->bd_disk = NULL;

0 commit comments

Comments
 (0)