aboutsummaryrefslogtreecommitdiffstats
path: root/block/blk-mq-sysfs.c
diff options
context:
space:
mode:
authorMing Lei <tom.leiming@gmail.com>2017-02-22 05:14:01 -0500
committerJens Axboe <axboe@fb.com>2017-03-08 11:56:12 -0500
commit6c8b232efea1ad3d263ff8b9c16b7e8767a77488 (patch)
treedb30d630a2a170b7f67479654da43812c1d674fa /block/blk-mq-sysfs.c
parent7ea5fe31c12dd8bcf4a9c5a4a7e8e23826a9a3b8 (diff)
blk-mq: make lifetime consistent between hctx and its kobject
This patch removes kobject_put() over hctx in __blk_mq_unregister_dev(), and trys to keep lifetime consistent between hctx and hctx's kobject. Now blk_mq_sysfs_register() and blk_mq_sysfs_unregister() become totally symmetrical, and kobject's refcounter drops to zero just when the hctx is freed. Signed-off-by: Ming Lei <tom.leiming@gmail.com> Tested-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block/blk-mq-sysfs.c')
-rw-r--r--block/blk-mq-sysfs.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c
index 77fb238af2be..cb19ec16a7fc 100644
--- a/block/blk-mq-sysfs.c
+++ b/block/blk-mq-sysfs.c
@@ -17,6 +17,14 @@ static void blk_mq_sysfs_release(struct kobject *kobj)
17{ 17{
18} 18}
19 19
20static void blk_mq_hw_sysfs_release(struct kobject *kobj)
21{
22 struct blk_mq_hw_ctx *hctx = container_of(kobj, struct blk_mq_hw_ctx,
23 kobj);
24 kfree(hctx->ctxs);
25 kfree(hctx);
26}
27
20struct blk_mq_ctx_sysfs_entry { 28struct blk_mq_ctx_sysfs_entry {
21 struct attribute attr; 29 struct attribute attr;
22 ssize_t (*show)(struct blk_mq_ctx *, char *); 30 ssize_t (*show)(struct blk_mq_ctx *, char *);
@@ -200,7 +208,7 @@ static struct kobj_type blk_mq_ctx_ktype = {
200static struct kobj_type blk_mq_hw_ktype = { 208static struct kobj_type blk_mq_hw_ktype = {
201 .sysfs_ops = &blk_mq_hw_sysfs_ops, 209 .sysfs_ops = &blk_mq_hw_sysfs_ops,
202 .default_attrs = default_hw_ctx_attrs, 210 .default_attrs = default_hw_ctx_attrs,
203 .release = blk_mq_sysfs_release, 211 .release = blk_mq_hw_sysfs_release,
204}; 212};
205 213
206static void blk_mq_unregister_hctx(struct blk_mq_hw_ctx *hctx) 214static void blk_mq_unregister_hctx(struct blk_mq_hw_ctx *hctx)
@@ -244,12 +252,9 @@ static void __blk_mq_unregister_dev(struct device *dev, struct request_queue *q)
244 struct blk_mq_hw_ctx *hctx; 252 struct blk_mq_hw_ctx *hctx;
245 int i; 253 int i;
246 254
247 queue_for_each_hw_ctx(q, hctx, i) { 255 queue_for_each_hw_ctx(q, hctx, i)
248 blk_mq_unregister_hctx(hctx); 256 blk_mq_unregister_hctx(hctx);
249 257
250 kobject_put(&hctx->kobj);
251 }
252
253 blk_mq_debugfs_unregister_hctxs(q); 258 blk_mq_debugfs_unregister_hctxs(q);
254 259
255 kobject_uevent(&q->mq_kobj, KOBJ_REMOVE); 260 kobject_uevent(&q->mq_kobj, KOBJ_REMOVE);