Christoph Hellwig | 3dcf60b | 2019-04-30 14:42:43 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 2 | #include <linux/kernel.h> |
| 3 | #include <linux/module.h> |
| 4 | #include <linux/backing-dev.h> |
| 5 | #include <linux/bio.h> |
| 6 | #include <linux/blkdev.h> |
| 7 | #include <linux/mm.h> |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/slab.h> |
| 10 | #include <linux/workqueue.h> |
| 11 | #include <linux/smp.h> |
| 12 | |
| 13 | #include <linux/blk-mq.h> |
Ming Lei | c7e2d94 | 2019-04-30 09:52:25 +0800 | [diff] [blame] | 14 | #include "blk.h" |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 15 | #include "blk-mq.h" |
| 16 | #include "blk-mq-tag.h" |
| 17 | |
| 18 | static void blk_mq_sysfs_release(struct kobject *kobj) |
| 19 | { |
Ming Lei | 1db4909 | 2018-11-20 09:44:35 +0800 | [diff] [blame] | 20 | struct blk_mq_ctxs *ctxs = container_of(kobj, struct blk_mq_ctxs, kobj); |
| 21 | |
| 22 | free_percpu(ctxs->queue_ctx); |
| 23 | kfree(ctxs); |
| 24 | } |
| 25 | |
| 26 | static void blk_mq_ctx_sysfs_release(struct kobject *kobj) |
| 27 | { |
| 28 | struct blk_mq_ctx *ctx = container_of(kobj, struct blk_mq_ctx, kobj); |
| 29 | |
| 30 | /* ctx->ctxs won't be released until all ctx are freed */ |
| 31 | kobject_put(&ctx->ctxs->kobj); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 32 | } |
| 33 | |
Ming Lei | 6c8b232 | 2017-02-22 18:14:01 +0800 | [diff] [blame] | 34 | static void blk_mq_hw_sysfs_release(struct kobject *kobj) |
| 35 | { |
| 36 | struct blk_mq_hw_ctx *hctx = container_of(kobj, struct blk_mq_hw_ctx, |
| 37 | kobj); |
Ming Lei | c7e2d94 | 2019-04-30 09:52:25 +0800 | [diff] [blame] | 38 | |
| 39 | if (hctx->flags & BLK_MQ_F_BLOCKING) |
| 40 | cleanup_srcu_struct(hctx->srcu); |
| 41 | blk_free_flush_queue(hctx->fq); |
| 42 | sbitmap_free(&hctx->ctx_map); |
Ming Lei | 01388df | 2017-02-22 18:14:02 +0800 | [diff] [blame] | 43 | free_cpumask_var(hctx->cpumask); |
Ming Lei | 6c8b232 | 2017-02-22 18:14:01 +0800 | [diff] [blame] | 44 | kfree(hctx->ctxs); |
| 45 | kfree(hctx); |
| 46 | } |
| 47 | |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 48 | struct blk_mq_hw_ctx_sysfs_entry { |
| 49 | struct attribute attr; |
| 50 | ssize_t (*show)(struct blk_mq_hw_ctx *, char *); |
| 51 | ssize_t (*store)(struct blk_mq_hw_ctx *, const char *, size_t); |
| 52 | }; |
| 53 | |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 54 | static ssize_t blk_mq_hw_sysfs_show(struct kobject *kobj, |
| 55 | struct attribute *attr, char *page) |
| 56 | { |
| 57 | struct blk_mq_hw_ctx_sysfs_entry *entry; |
| 58 | struct blk_mq_hw_ctx *hctx; |
| 59 | struct request_queue *q; |
| 60 | ssize_t res; |
| 61 | |
| 62 | entry = container_of(attr, struct blk_mq_hw_ctx_sysfs_entry, attr); |
| 63 | hctx = container_of(kobj, struct blk_mq_hw_ctx, kobj); |
| 64 | q = hctx->queue; |
| 65 | |
| 66 | if (!entry->show) |
| 67 | return -EIO; |
| 68 | |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 69 | mutex_lock(&q->sysfs_lock); |
Bart Van Assche | bae85c1 | 2019-09-30 16:00:43 -0700 | [diff] [blame] | 70 | res = entry->show(hctx, page); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 71 | mutex_unlock(&q->sysfs_lock); |
| 72 | return res; |
| 73 | } |
| 74 | |
| 75 | static ssize_t blk_mq_hw_sysfs_store(struct kobject *kobj, |
| 76 | struct attribute *attr, const char *page, |
| 77 | size_t length) |
| 78 | { |
| 79 | struct blk_mq_hw_ctx_sysfs_entry *entry; |
| 80 | struct blk_mq_hw_ctx *hctx; |
| 81 | struct request_queue *q; |
| 82 | ssize_t res; |
| 83 | |
| 84 | entry = container_of(attr, struct blk_mq_hw_ctx_sysfs_entry, attr); |
| 85 | hctx = container_of(kobj, struct blk_mq_hw_ctx, kobj); |
| 86 | q = hctx->queue; |
| 87 | |
| 88 | if (!entry->store) |
| 89 | return -EIO; |
| 90 | |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 91 | mutex_lock(&q->sysfs_lock); |
Bart Van Assche | bae85c1 | 2019-09-30 16:00:43 -0700 | [diff] [blame] | 92 | res = entry->store(hctx, page, length); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 93 | mutex_unlock(&q->sysfs_lock); |
| 94 | return res; |
| 95 | } |
| 96 | |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 97 | static ssize_t blk_mq_hw_sysfs_nr_tags_show(struct blk_mq_hw_ctx *hctx, |
| 98 | char *page) |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 99 | { |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 100 | return sprintf(page, "%u\n", hctx->tags->nr_tags); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 103 | static ssize_t blk_mq_hw_sysfs_nr_reserved_tags_show(struct blk_mq_hw_ctx *hctx, |
| 104 | char *page) |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 105 | { |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 106 | return sprintf(page, "%u\n", hctx->tags->nr_reserved_tags); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Jens Axboe | 676141e | 2014-03-20 13:29:18 -0600 | [diff] [blame] | 109 | static ssize_t blk_mq_hw_sysfs_cpus_show(struct blk_mq_hw_ctx *hctx, char *page) |
| 110 | { |
Ming Lei | 8962842 | 2019-11-02 16:02:15 +0800 | [diff] [blame] | 111 | const size_t size = PAGE_SIZE - 1; |
Jens Axboe | cb2da43 | 2014-04-09 10:53:21 -0600 | [diff] [blame] | 112 | unsigned int i, first = 1; |
Ming Lei | 8962842 | 2019-11-02 16:02:15 +0800 | [diff] [blame] | 113 | int ret = 0, pos = 0; |
Jens Axboe | 676141e | 2014-03-20 13:29:18 -0600 | [diff] [blame] | 114 | |
Jens Axboe | cb2da43 | 2014-04-09 10:53:21 -0600 | [diff] [blame] | 115 | for_each_cpu(i, hctx->cpumask) { |
Jens Axboe | 676141e | 2014-03-20 13:29:18 -0600 | [diff] [blame] | 116 | if (first) |
Ming Lei | 8962842 | 2019-11-02 16:02:15 +0800 | [diff] [blame] | 117 | ret = snprintf(pos + page, size - pos, "%u", i); |
Jens Axboe | 676141e | 2014-03-20 13:29:18 -0600 | [diff] [blame] | 118 | else |
Ming Lei | 8962842 | 2019-11-02 16:02:15 +0800 | [diff] [blame] | 119 | ret = snprintf(pos + page, size - pos, ", %u", i); |
| 120 | |
| 121 | if (ret >= size - pos) |
| 122 | break; |
Jens Axboe | 676141e | 2014-03-20 13:29:18 -0600 | [diff] [blame] | 123 | |
| 124 | first = 0; |
Ming Lei | 8962842 | 2019-11-02 16:02:15 +0800 | [diff] [blame] | 125 | pos += ret; |
Jens Axboe | 676141e | 2014-03-20 13:29:18 -0600 | [diff] [blame] | 126 | } |
| 127 | |
Ming Lei | d2c9be8 | 2019-11-04 16:26:53 +0800 | [diff] [blame] | 128 | ret = snprintf(pos + page, size + 1 - pos, "\n"); |
Ming Lei | 8962842 | 2019-11-02 16:02:15 +0800 | [diff] [blame] | 129 | return pos + ret; |
Jens Axboe | 676141e | 2014-03-20 13:29:18 -0600 | [diff] [blame] | 130 | } |
| 131 | |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 132 | static struct blk_mq_hw_ctx_sysfs_entry blk_mq_hw_sysfs_nr_tags = { |
Joe Perches | 5657a81 | 2018-05-24 13:38:59 -0600 | [diff] [blame] | 133 | .attr = {.name = "nr_tags", .mode = 0444 }, |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 134 | .show = blk_mq_hw_sysfs_nr_tags_show, |
| 135 | }; |
| 136 | static struct blk_mq_hw_ctx_sysfs_entry blk_mq_hw_sysfs_nr_reserved_tags = { |
Joe Perches | 5657a81 | 2018-05-24 13:38:59 -0600 | [diff] [blame] | 137 | .attr = {.name = "nr_reserved_tags", .mode = 0444 }, |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 138 | .show = blk_mq_hw_sysfs_nr_reserved_tags_show, |
| 139 | }; |
Jens Axboe | 676141e | 2014-03-20 13:29:18 -0600 | [diff] [blame] | 140 | static struct blk_mq_hw_ctx_sysfs_entry blk_mq_hw_sysfs_cpus = { |
Joe Perches | 5657a81 | 2018-05-24 13:38:59 -0600 | [diff] [blame] | 141 | .attr = {.name = "cpu_list", .mode = 0444 }, |
Jens Axboe | 676141e | 2014-03-20 13:29:18 -0600 | [diff] [blame] | 142 | .show = blk_mq_hw_sysfs_cpus_show, |
| 143 | }; |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 144 | |
| 145 | static struct attribute *default_hw_ctx_attrs[] = { |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 146 | &blk_mq_hw_sysfs_nr_tags.attr, |
| 147 | &blk_mq_hw_sysfs_nr_reserved_tags.attr, |
Jens Axboe | 676141e | 2014-03-20 13:29:18 -0600 | [diff] [blame] | 148 | &blk_mq_hw_sysfs_cpus.attr, |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 149 | NULL, |
| 150 | }; |
Kimberly Brown | 800f5aa | 2019-04-01 22:51:30 -0400 | [diff] [blame] | 151 | ATTRIBUTE_GROUPS(default_hw_ctx); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 152 | |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 153 | static const struct sysfs_ops blk_mq_hw_sysfs_ops = { |
| 154 | .show = blk_mq_hw_sysfs_show, |
| 155 | .store = blk_mq_hw_sysfs_store, |
| 156 | }; |
| 157 | |
| 158 | static struct kobj_type blk_mq_ktype = { |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 159 | .release = blk_mq_sysfs_release, |
| 160 | }; |
| 161 | |
| 162 | static struct kobj_type blk_mq_ctx_ktype = { |
Ming Lei | 1db4909 | 2018-11-20 09:44:35 +0800 | [diff] [blame] | 163 | .release = blk_mq_ctx_sysfs_release, |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | static struct kobj_type blk_mq_hw_ktype = { |
| 167 | .sysfs_ops = &blk_mq_hw_sysfs_ops, |
Kimberly Brown | 800f5aa | 2019-04-01 22:51:30 -0400 | [diff] [blame] | 168 | .default_groups = default_hw_ctx_groups, |
Ming Lei | 6c8b232 | 2017-02-22 18:14:01 +0800 | [diff] [blame] | 169 | .release = blk_mq_hw_sysfs_release, |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 170 | }; |
| 171 | |
Fengguang Wu | ee3c5db | 2014-05-30 10:31:13 -0600 | [diff] [blame] | 172 | static void blk_mq_unregister_hctx(struct blk_mq_hw_ctx *hctx) |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 173 | { |
| 174 | struct blk_mq_ctx *ctx; |
| 175 | int i; |
| 176 | |
Akinobu Mita | 4593fdb | 2015-09-27 02:09:20 +0900 | [diff] [blame] | 177 | if (!hctx->nr_ctx) |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 178 | return; |
| 179 | |
| 180 | hctx_for_each_ctx(hctx, ctx, i) |
| 181 | kobject_del(&ctx->kobj); |
| 182 | |
| 183 | kobject_del(&hctx->kobj); |
| 184 | } |
| 185 | |
Fengguang Wu | ee3c5db | 2014-05-30 10:31:13 -0600 | [diff] [blame] | 186 | static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx) |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 187 | { |
| 188 | struct request_queue *q = hctx->queue; |
| 189 | struct blk_mq_ctx *ctx; |
| 190 | int i, ret; |
| 191 | |
Akinobu Mita | 4593fdb | 2015-09-27 02:09:20 +0900 | [diff] [blame] | 192 | if (!hctx->nr_ctx) |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 193 | return 0; |
| 194 | |
Ming Lei | 1db4909 | 2018-11-20 09:44:35 +0800 | [diff] [blame] | 195 | ret = kobject_add(&hctx->kobj, q->mq_kobj, "%u", hctx->queue_num); |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 196 | if (ret) |
| 197 | return ret; |
| 198 | |
| 199 | hctx_for_each_ctx(hctx, ctx, i) { |
| 200 | ret = kobject_add(&ctx->kobj, &hctx->kobj, "cpu%u", ctx->cpu); |
| 201 | if (ret) |
| 202 | break; |
| 203 | } |
| 204 | |
| 205 | return ret; |
| 206 | } |
| 207 | |
Mike Snitzer | 667257e | 2018-01-11 14:11:01 -0500 | [diff] [blame] | 208 | void blk_mq_unregister_dev(struct device *dev, struct request_queue *q) |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 209 | { |
Andrey Vagin | 8515736 | 2013-12-06 09:06:41 +0400 | [diff] [blame] | 210 | struct blk_mq_hw_ctx *hctx; |
Ming Lei | 7ea5fe3 | 2017-02-22 18:14:00 +0800 | [diff] [blame] | 211 | int i; |
Andrey Vagin | 8515736 | 2013-12-06 09:06:41 +0400 | [diff] [blame] | 212 | |
Ming Lei | cecf5d8 | 2019-08-27 19:01:48 +0800 | [diff] [blame] | 213 | lockdep_assert_held(&q->sysfs_dir_lock); |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 214 | |
Ming Lei | 6c8b232 | 2017-02-22 18:14:01 +0800 | [diff] [blame] | 215 | queue_for_each_hw_ctx(q, hctx, i) |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 216 | blk_mq_unregister_hctx(hctx); |
| 217 | |
Ming Lei | 1db4909 | 2018-11-20 09:44:35 +0800 | [diff] [blame] | 218 | kobject_uevent(q->mq_kobj, KOBJ_REMOVE); |
| 219 | kobject_del(q->mq_kobj); |
Matias Bjørling | b21d5b3 | 2016-09-16 14:25:06 +0200 | [diff] [blame] | 220 | kobject_put(&dev->kobj); |
Akinobu Mita | 4593fdb | 2015-09-27 02:09:20 +0900 | [diff] [blame] | 221 | |
| 222 | q->mq_sysfs_init_done = false; |
Jens Axboe | c0f3fd2 | 2016-08-02 08:45:44 -0600 | [diff] [blame] | 223 | } |
| 224 | |
Keith Busch | 868f2f0 | 2015-12-17 17:08:14 -0700 | [diff] [blame] | 225 | void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx) |
| 226 | { |
| 227 | kobject_init(&hctx->kobj, &blk_mq_hw_ktype); |
| 228 | } |
| 229 | |
Ming Lei | 7ea5fe3 | 2017-02-22 18:14:00 +0800 | [diff] [blame] | 230 | void blk_mq_sysfs_deinit(struct request_queue *q) |
| 231 | { |
| 232 | struct blk_mq_ctx *ctx; |
| 233 | int cpu; |
| 234 | |
| 235 | for_each_possible_cpu(cpu) { |
| 236 | ctx = per_cpu_ptr(q->queue_ctx, cpu); |
| 237 | kobject_put(&ctx->kobj); |
| 238 | } |
Ming Lei | 1db4909 | 2018-11-20 09:44:35 +0800 | [diff] [blame] | 239 | kobject_put(q->mq_kobj); |
Ming Lei | 7ea5fe3 | 2017-02-22 18:14:00 +0800 | [diff] [blame] | 240 | } |
| 241 | |
Ming Lei | 737f98c | 2017-02-22 18:13:59 +0800 | [diff] [blame] | 242 | void blk_mq_sysfs_init(struct request_queue *q) |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 243 | { |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 244 | struct blk_mq_ctx *ctx; |
Thomas Gleixner | 897bb0c | 2016-03-19 11:30:33 +0100 | [diff] [blame] | 245 | int cpu; |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 246 | |
Ming Lei | 1db4909 | 2018-11-20 09:44:35 +0800 | [diff] [blame] | 247 | kobject_init(q->mq_kobj, &blk_mq_ktype); |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 248 | |
Thomas Gleixner | 897bb0c | 2016-03-19 11:30:33 +0100 | [diff] [blame] | 249 | for_each_possible_cpu(cpu) { |
| 250 | ctx = per_cpu_ptr(q->queue_ctx, cpu); |
Ming Lei | 1db4909 | 2018-11-20 09:44:35 +0800 | [diff] [blame] | 251 | |
| 252 | kobject_get(q->mq_kobj); |
Takashi Iwai | 06a41a9 | 2014-12-10 16:38:30 +0100 | [diff] [blame] | 253 | kobject_init(&ctx->kobj, &blk_mq_ctx_ktype); |
Thomas Gleixner | 897bb0c | 2016-03-19 11:30:33 +0100 | [diff] [blame] | 254 | } |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 255 | } |
| 256 | |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 257 | int __blk_mq_register_dev(struct device *dev, struct request_queue *q) |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 258 | { |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 259 | struct blk_mq_hw_ctx *hctx; |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 260 | int ret, i; |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 261 | |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 262 | WARN_ON_ONCE(!q->kobj.parent); |
Ming Lei | cecf5d8 | 2019-08-27 19:01:48 +0800 | [diff] [blame] | 263 | lockdep_assert_held(&q->sysfs_dir_lock); |
Akinobu Mita | 4593fdb | 2015-09-27 02:09:20 +0900 | [diff] [blame] | 264 | |
Ming Lei | 1db4909 | 2018-11-20 09:44:35 +0800 | [diff] [blame] | 265 | ret = kobject_add(q->mq_kobj, kobject_get(&dev->kobj), "%s", "mq"); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 266 | if (ret < 0) |
Akinobu Mita | 4593fdb | 2015-09-27 02:09:20 +0900 | [diff] [blame] | 267 | goto out; |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 268 | |
Ming Lei | 1db4909 | 2018-11-20 09:44:35 +0800 | [diff] [blame] | 269 | kobject_uevent(q->mq_kobj, KOBJ_ADD); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 270 | |
| 271 | queue_for_each_hw_ctx(q, hctx, i) { |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 272 | ret = blk_mq_register_hctx(hctx); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 273 | if (ret) |
Bart Van Assche | f05d1ba | 2017-04-26 13:47:51 -0700 | [diff] [blame] | 274 | goto unreg; |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 275 | } |
| 276 | |
Bart Van Assche | f05d1ba | 2017-04-26 13:47:51 -0700 | [diff] [blame] | 277 | q->mq_sysfs_init_done = true; |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 278 | |
Akinobu Mita | 4593fdb | 2015-09-27 02:09:20 +0900 | [diff] [blame] | 279 | out: |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 280 | return ret; |
Bart Van Assche | f05d1ba | 2017-04-26 13:47:51 -0700 | [diff] [blame] | 281 | |
| 282 | unreg: |
| 283 | while (--i >= 0) |
| 284 | blk_mq_unregister_hctx(q->queue_hw_ctx[i]); |
| 285 | |
Ming Lei | 1db4909 | 2018-11-20 09:44:35 +0800 | [diff] [blame] | 286 | kobject_uevent(q->mq_kobj, KOBJ_REMOVE); |
| 287 | kobject_del(q->mq_kobj); |
Bart Van Assche | f05d1ba | 2017-04-26 13:47:51 -0700 | [diff] [blame] | 288 | kobject_put(&dev->kobj); |
| 289 | return ret; |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 292 | void blk_mq_sysfs_unregister(struct request_queue *q) |
| 293 | { |
| 294 | struct blk_mq_hw_ctx *hctx; |
| 295 | int i; |
| 296 | |
Ming Lei | cecf5d8 | 2019-08-27 19:01:48 +0800 | [diff] [blame] | 297 | mutex_lock(&q->sysfs_dir_lock); |
Akinobu Mita | 4593fdb | 2015-09-27 02:09:20 +0900 | [diff] [blame] | 298 | if (!q->mq_sysfs_init_done) |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 299 | goto unlock; |
Akinobu Mita | 4593fdb | 2015-09-27 02:09:20 +0900 | [diff] [blame] | 300 | |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 301 | queue_for_each_hw_ctx(q, hctx, i) |
| 302 | blk_mq_unregister_hctx(hctx); |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 303 | |
| 304 | unlock: |
Ming Lei | cecf5d8 | 2019-08-27 19:01:48 +0800 | [diff] [blame] | 305 | mutex_unlock(&q->sysfs_dir_lock); |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | int blk_mq_sysfs_register(struct request_queue *q) |
| 309 | { |
| 310 | struct blk_mq_hw_ctx *hctx; |
| 311 | int i, ret = 0; |
| 312 | |
Ming Lei | cecf5d8 | 2019-08-27 19:01:48 +0800 | [diff] [blame] | 313 | mutex_lock(&q->sysfs_dir_lock); |
Akinobu Mita | 4593fdb | 2015-09-27 02:09:20 +0900 | [diff] [blame] | 314 | if (!q->mq_sysfs_init_done) |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 315 | goto unlock; |
Akinobu Mita | 4593fdb | 2015-09-27 02:09:20 +0900 | [diff] [blame] | 316 | |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 317 | queue_for_each_hw_ctx(q, hctx, i) { |
| 318 | ret = blk_mq_register_hctx(hctx); |
| 319 | if (ret) |
| 320 | break; |
| 321 | } |
| 322 | |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 323 | unlock: |
Ming Lei | cecf5d8 | 2019-08-27 19:01:48 +0800 | [diff] [blame] | 324 | mutex_unlock(&q->sysfs_dir_lock); |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 325 | |
Jens Axboe | 67aec14 | 2014-05-30 08:25:36 -0600 | [diff] [blame] | 326 | return ret; |
| 327 | } |