]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
8324aa91 JA |
2 | /* |
3 | * Functions related to sysfs handling | |
4 | */ | |
5 | #include <linux/kernel.h> | |
5a0e3ad6 | 6 | #include <linux/slab.h> |
8324aa91 JA |
7 | #include <linux/module.h> |
8 | #include <linux/bio.h> | |
9 | #include <linux/blkdev.h> | |
66114cad | 10 | #include <linux/backing-dev.h> |
8324aa91 | 11 | #include <linux/blktrace_api.h> |
320ae51f | 12 | #include <linux/blk-mq.h> |
eea8f41c | 13 | #include <linux/blk-cgroup.h> |
8324aa91 JA |
14 | |
15 | #include "blk.h" | |
3edcc0ce | 16 | #include "blk-mq.h" |
d173a251 | 17 | #include "blk-mq-debugfs.h" |
87760e5e | 18 | #include "blk-wbt.h" |
8324aa91 JA |
19 | |
20 | struct queue_sysfs_entry { | |
21 | struct attribute attr; | |
22 | ssize_t (*show)(struct request_queue *, char *); | |
23 | ssize_t (*store)(struct request_queue *, const char *, size_t); | |
24 | }; | |
25 | ||
26 | static ssize_t | |
9cb308ce | 27 | queue_var_show(unsigned long var, char *page) |
8324aa91 | 28 | { |
9cb308ce | 29 | return sprintf(page, "%lu\n", var); |
8324aa91 JA |
30 | } |
31 | ||
32 | static ssize_t | |
33 | queue_var_store(unsigned long *var, const char *page, size_t count) | |
34 | { | |
b1f3b64d DR |
35 | int err; |
36 | unsigned long v; | |
37 | ||
ed751e68 | 38 | err = kstrtoul(page, 10, &v); |
b1f3b64d DR |
39 | if (err || v > UINT_MAX) |
40 | return -EINVAL; | |
41 | ||
42 | *var = v; | |
8324aa91 | 43 | |
8324aa91 JA |
44 | return count; |
45 | } | |
46 | ||
80e091d1 | 47 | static ssize_t queue_var_store64(s64 *var, const char *page) |
87760e5e JA |
48 | { |
49 | int err; | |
80e091d1 | 50 | s64 v; |
87760e5e | 51 | |
80e091d1 | 52 | err = kstrtos64(page, 10, &v); |
87760e5e JA |
53 | if (err < 0) |
54 | return err; | |
55 | ||
56 | *var = v; | |
57 | return 0; | |
58 | } | |
59 | ||
8324aa91 JA |
60 | static ssize_t queue_requests_show(struct request_queue *q, char *page) |
61 | { | |
62 | return queue_var_show(q->nr_requests, (page)); | |
63 | } | |
64 | ||
65 | static ssize_t | |
66 | queue_requests_store(struct request_queue *q, const char *page, size_t count) | |
67 | { | |
8324aa91 | 68 | unsigned long nr; |
e3a2b3f9 | 69 | int ret, err; |
b8a9ae77 | 70 | |
344e9ffc | 71 | if (!queue_is_mq(q)) |
b8a9ae77 JA |
72 | return -EINVAL; |
73 | ||
74 | ret = queue_var_store(&nr, page, count); | |
b1f3b64d DR |
75 | if (ret < 0) |
76 | return ret; | |
77 | ||
8324aa91 JA |
78 | if (nr < BLKDEV_MIN_RQ) |
79 | nr = BLKDEV_MIN_RQ; | |
80 | ||
a1ce35fa | 81 | err = blk_mq_update_nr_requests(q, nr); |
e3a2b3f9 JA |
82 | if (err) |
83 | return err; | |
84 | ||
8324aa91 JA |
85 | return ret; |
86 | } | |
87 | ||
88 | static ssize_t queue_ra_show(struct request_queue *q, char *page) | |
89 | { | |
dc3b17cc | 90 | unsigned long ra_kb = q->backing_dev_info->ra_pages << |
09cbfeaf | 91 | (PAGE_SHIFT - 10); |
8324aa91 JA |
92 | |
93 | return queue_var_show(ra_kb, (page)); | |
94 | } | |
95 | ||
96 | static ssize_t | |
97 | queue_ra_store(struct request_queue *q, const char *page, size_t count) | |
98 | { | |
99 | unsigned long ra_kb; | |
100 | ssize_t ret = queue_var_store(&ra_kb, page, count); | |
101 | ||
b1f3b64d DR |
102 | if (ret < 0) |
103 | return ret; | |
104 | ||
dc3b17cc | 105 | q->backing_dev_info->ra_pages = ra_kb >> (PAGE_SHIFT - 10); |
8324aa91 JA |
106 | |
107 | return ret; | |
108 | } | |
109 | ||
110 | static ssize_t queue_max_sectors_show(struct request_queue *q, char *page) | |
111 | { | |
ae03bf63 | 112 | int max_sectors_kb = queue_max_sectors(q) >> 1; |
8324aa91 JA |
113 | |
114 | return queue_var_show(max_sectors_kb, (page)); | |
115 | } | |
116 | ||
c77a5710 MP |
117 | static ssize_t queue_max_segments_show(struct request_queue *q, char *page) |
118 | { | |
119 | return queue_var_show(queue_max_segments(q), (page)); | |
120 | } | |
121 | ||
1e739730 CH |
122 | static ssize_t queue_max_discard_segments_show(struct request_queue *q, |
123 | char *page) | |
124 | { | |
125 | return queue_var_show(queue_max_discard_segments(q), (page)); | |
126 | } | |
127 | ||
13f05c8d MP |
128 | static ssize_t queue_max_integrity_segments_show(struct request_queue *q, char *page) |
129 | { | |
130 | return queue_var_show(q->limits.max_integrity_segments, (page)); | |
131 | } | |
132 | ||
c77a5710 MP |
133 | static ssize_t queue_max_segment_size_show(struct request_queue *q, char *page) |
134 | { | |
38417468 | 135 | return queue_var_show(queue_max_segment_size(q), (page)); |
c77a5710 MP |
136 | } |
137 | ||
e1defc4f | 138 | static ssize_t queue_logical_block_size_show(struct request_queue *q, char *page) |
e68b903c | 139 | { |
e1defc4f | 140 | return queue_var_show(queue_logical_block_size(q), page); |
e68b903c MP |
141 | } |
142 | ||
c72758f3 MP |
143 | static ssize_t queue_physical_block_size_show(struct request_queue *q, char *page) |
144 | { | |
145 | return queue_var_show(queue_physical_block_size(q), page); | |
146 | } | |
147 | ||
87caf97c HR |
148 | static ssize_t queue_chunk_sectors_show(struct request_queue *q, char *page) |
149 | { | |
150 | return queue_var_show(q->limits.chunk_sectors, page); | |
151 | } | |
152 | ||
c72758f3 MP |
153 | static ssize_t queue_io_min_show(struct request_queue *q, char *page) |
154 | { | |
155 | return queue_var_show(queue_io_min(q), page); | |
156 | } | |
157 | ||
158 | static ssize_t queue_io_opt_show(struct request_queue *q, char *page) | |
159 | { | |
160 | return queue_var_show(queue_io_opt(q), page); | |
e68b903c MP |
161 | } |
162 | ||
86b37281 MP |
163 | static ssize_t queue_discard_granularity_show(struct request_queue *q, char *page) |
164 | { | |
165 | return queue_var_show(q->limits.discard_granularity, page); | |
166 | } | |
167 | ||
0034af03 JA |
168 | static ssize_t queue_discard_max_hw_show(struct request_queue *q, char *page) |
169 | { | |
0034af03 | 170 | |
18f922d0 A |
171 | return sprintf(page, "%llu\n", |
172 | (unsigned long long)q->limits.max_hw_discard_sectors << 9); | |
0034af03 JA |
173 | } |
174 | ||
86b37281 MP |
175 | static ssize_t queue_discard_max_show(struct request_queue *q, char *page) |
176 | { | |
a934a00a MP |
177 | return sprintf(page, "%llu\n", |
178 | (unsigned long long)q->limits.max_discard_sectors << 9); | |
86b37281 MP |
179 | } |
180 | ||
0034af03 JA |
181 | static ssize_t queue_discard_max_store(struct request_queue *q, |
182 | const char *page, size_t count) | |
183 | { | |
184 | unsigned long max_discard; | |
185 | ssize_t ret = queue_var_store(&max_discard, page, count); | |
186 | ||
187 | if (ret < 0) | |
188 | return ret; | |
189 | ||
190 | if (max_discard & (q->limits.discard_granularity - 1)) | |
191 | return -EINVAL; | |
192 | ||
193 | max_discard >>= 9; | |
194 | if (max_discard > UINT_MAX) | |
195 | return -EINVAL; | |
196 | ||
197 | if (max_discard > q->limits.max_hw_discard_sectors) | |
198 | max_discard = q->limits.max_hw_discard_sectors; | |
199 | ||
200 | q->limits.max_discard_sectors = max_discard; | |
201 | return ret; | |
202 | } | |
203 | ||
98262f27 MP |
204 | static ssize_t queue_discard_zeroes_data_show(struct request_queue *q, char *page) |
205 | { | |
48920ff2 | 206 | return queue_var_show(0, page); |
98262f27 MP |
207 | } |
208 | ||
4363ac7c MP |
209 | static ssize_t queue_write_same_max_show(struct request_queue *q, char *page) |
210 | { | |
211 | return sprintf(page, "%llu\n", | |
212 | (unsigned long long)q->limits.max_write_same_sectors << 9); | |
213 | } | |
214 | ||
a6f0788e CK |
215 | static ssize_t queue_write_zeroes_max_show(struct request_queue *q, char *page) |
216 | { | |
217 | return sprintf(page, "%llu\n", | |
218 | (unsigned long long)q->limits.max_write_zeroes_sectors << 9); | |
219 | } | |
4363ac7c | 220 | |
0512a75b KB |
221 | static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page) |
222 | { | |
223 | unsigned long long max_sectors = q->limits.max_zone_append_sectors; | |
224 | ||
225 | return sprintf(page, "%llu\n", max_sectors << SECTOR_SHIFT); | |
226 | } | |
227 | ||
8324aa91 JA |
228 | static ssize_t |
229 | queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) | |
230 | { | |
231 | unsigned long max_sectors_kb, | |
ae03bf63 | 232 | max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1, |
09cbfeaf | 233 | page_kb = 1 << (PAGE_SHIFT - 10); |
8324aa91 JA |
234 | ssize_t ret = queue_var_store(&max_sectors_kb, page, count); |
235 | ||
b1f3b64d DR |
236 | if (ret < 0) |
237 | return ret; | |
238 | ||
ca369d51 MP |
239 | max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long) |
240 | q->limits.max_dev_sectors >> 1); | |
241 | ||
8324aa91 JA |
242 | if (max_sectors_kb > max_hw_sectors_kb || max_sectors_kb < page_kb) |
243 | return -EINVAL; | |
7c239517 | 244 | |
0d945c1f | 245 | spin_lock_irq(&q->queue_lock); |
c295fc05 | 246 | q->limits.max_sectors = max_sectors_kb << 1; |
dc3b17cc | 247 | q->backing_dev_info->io_pages = max_sectors_kb >> (PAGE_SHIFT - 10); |
0d945c1f | 248 | spin_unlock_irq(&q->queue_lock); |
8324aa91 JA |
249 | |
250 | return ret; | |
251 | } | |
252 | ||
253 | static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page) | |
254 | { | |
ae03bf63 | 255 | int max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1; |
8324aa91 JA |
256 | |
257 | return queue_var_show(max_hw_sectors_kb, (page)); | |
258 | } | |
259 | ||
956bcb7c JA |
260 | #define QUEUE_SYSFS_BIT_FNS(name, flag, neg) \ |
261 | static ssize_t \ | |
262 | queue_show_##name(struct request_queue *q, char *page) \ | |
263 | { \ | |
264 | int bit; \ | |
265 | bit = test_bit(QUEUE_FLAG_##flag, &q->queue_flags); \ | |
266 | return queue_var_show(neg ? !bit : bit, page); \ | |
267 | } \ | |
268 | static ssize_t \ | |
269 | queue_store_##name(struct request_queue *q, const char *page, size_t count) \ | |
270 | { \ | |
271 | unsigned long val; \ | |
272 | ssize_t ret; \ | |
273 | ret = queue_var_store(&val, page, count); \ | |
c678ef52 AB |
274 | if (ret < 0) \ |
275 | return ret; \ | |
956bcb7c JA |
276 | if (neg) \ |
277 | val = !val; \ | |
278 | \ | |
956bcb7c | 279 | if (val) \ |
8814ce8a | 280 | blk_queue_flag_set(QUEUE_FLAG_##flag, q); \ |
956bcb7c | 281 | else \ |
8814ce8a | 282 | blk_queue_flag_clear(QUEUE_FLAG_##flag, q); \ |
956bcb7c | 283 | return ret; \ |
1308835f BZ |
284 | } |
285 | ||
956bcb7c JA |
286 | QUEUE_SYSFS_BIT_FNS(nonrot, NONROT, 1); |
287 | QUEUE_SYSFS_BIT_FNS(random, ADD_RANDOM, 0); | |
288 | QUEUE_SYSFS_BIT_FNS(iostats, IO_STAT, 0); | |
289 | #undef QUEUE_SYSFS_BIT_FNS | |
1308835f | 290 | |
797476b8 DLM |
291 | static ssize_t queue_zoned_show(struct request_queue *q, char *page) |
292 | { | |
293 | switch (blk_queue_zoned_model(q)) { | |
294 | case BLK_ZONED_HA: | |
295 | return sprintf(page, "host-aware\n"); | |
296 | case BLK_ZONED_HM: | |
297 | return sprintf(page, "host-managed\n"); | |
298 | default: | |
299 | return sprintf(page, "none\n"); | |
300 | } | |
301 | } | |
302 | ||
965b652e DLM |
303 | static ssize_t queue_nr_zones_show(struct request_queue *q, char *page) |
304 | { | |
305 | return queue_var_show(blk_queue_nr_zones(q), page); | |
306 | } | |
307 | ||
ac9fafa1 AB |
308 | static ssize_t queue_nomerges_show(struct request_queue *q, char *page) |
309 | { | |
488991e2 AB |
310 | return queue_var_show((blk_queue_nomerges(q) << 1) | |
311 | blk_queue_noxmerges(q), page); | |
ac9fafa1 AB |
312 | } |
313 | ||
314 | static ssize_t queue_nomerges_store(struct request_queue *q, const char *page, | |
315 | size_t count) | |
316 | { | |
317 | unsigned long nm; | |
318 | ssize_t ret = queue_var_store(&nm, page, count); | |
319 | ||
b1f3b64d DR |
320 | if (ret < 0) |
321 | return ret; | |
322 | ||
57d74df9 CH |
323 | blk_queue_flag_clear(QUEUE_FLAG_NOMERGES, q); |
324 | blk_queue_flag_clear(QUEUE_FLAG_NOXMERGES, q); | |
488991e2 | 325 | if (nm == 2) |
57d74df9 | 326 | blk_queue_flag_set(QUEUE_FLAG_NOMERGES, q); |
488991e2 | 327 | else if (nm) |
57d74df9 | 328 | blk_queue_flag_set(QUEUE_FLAG_NOXMERGES, q); |
1308835f | 329 | |
ac9fafa1 AB |
330 | return ret; |
331 | } | |
332 | ||
c7c22e4d JA |
333 | static ssize_t queue_rq_affinity_show(struct request_queue *q, char *page) |
334 | { | |
9cb308ce | 335 | bool set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags); |
5757a6d7 | 336 | bool force = test_bit(QUEUE_FLAG_SAME_FORCE, &q->queue_flags); |
c7c22e4d | 337 | |
5757a6d7 | 338 | return queue_var_show(set << force, page); |
c7c22e4d JA |
339 | } |
340 | ||
341 | static ssize_t | |
342 | queue_rq_affinity_store(struct request_queue *q, const char *page, size_t count) | |
343 | { | |
344 | ssize_t ret = -EINVAL; | |
0a06ff06 | 345 | #ifdef CONFIG_SMP |
c7c22e4d JA |
346 | unsigned long val; |
347 | ||
348 | ret = queue_var_store(&val, page, count); | |
b1f3b64d DR |
349 | if (ret < 0) |
350 | return ret; | |
351 | ||
e8037d49 | 352 | if (val == 2) { |
57d74df9 CH |
353 | blk_queue_flag_set(QUEUE_FLAG_SAME_COMP, q); |
354 | blk_queue_flag_set(QUEUE_FLAG_SAME_FORCE, q); | |
e8037d49 | 355 | } else if (val == 1) { |
57d74df9 CH |
356 | blk_queue_flag_set(QUEUE_FLAG_SAME_COMP, q); |
357 | blk_queue_flag_clear(QUEUE_FLAG_SAME_FORCE, q); | |
e8037d49 | 358 | } else if (val == 0) { |
57d74df9 CH |
359 | blk_queue_flag_clear(QUEUE_FLAG_SAME_COMP, q); |
360 | blk_queue_flag_clear(QUEUE_FLAG_SAME_FORCE, q); | |
5757a6d7 | 361 | } |
c7c22e4d JA |
362 | #endif |
363 | return ret; | |
364 | } | |
8324aa91 | 365 | |
06426adf JA |
366 | static ssize_t queue_poll_delay_show(struct request_queue *q, char *page) |
367 | { | |
64f1c21e JA |
368 | int val; |
369 | ||
29ece8b4 YY |
370 | if (q->poll_nsec == BLK_MQ_POLL_CLASSIC) |
371 | val = BLK_MQ_POLL_CLASSIC; | |
64f1c21e JA |
372 | else |
373 | val = q->poll_nsec / 1000; | |
374 | ||
375 | return sprintf(page, "%d\n", val); | |
06426adf JA |
376 | } |
377 | ||
378 | static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page, | |
379 | size_t count) | |
380 | { | |
64f1c21e | 381 | int err, val; |
06426adf JA |
382 | |
383 | if (!q->mq_ops || !q->mq_ops->poll) | |
384 | return -EINVAL; | |
385 | ||
64f1c21e JA |
386 | err = kstrtoint(page, 10, &val); |
387 | if (err < 0) | |
388 | return err; | |
06426adf | 389 | |
29ece8b4 YY |
390 | if (val == BLK_MQ_POLL_CLASSIC) |
391 | q->poll_nsec = BLK_MQ_POLL_CLASSIC; | |
392 | else if (val >= 0) | |
64f1c21e | 393 | q->poll_nsec = val * 1000; |
29ece8b4 YY |
394 | else |
395 | return -EINVAL; | |
64f1c21e JA |
396 | |
397 | return count; | |
06426adf JA |
398 | } |
399 | ||
05229bee JA |
400 | static ssize_t queue_poll_show(struct request_queue *q, char *page) |
401 | { | |
402 | return queue_var_show(test_bit(QUEUE_FLAG_POLL, &q->queue_flags), page); | |
403 | } | |
404 | ||
405 | static ssize_t queue_poll_store(struct request_queue *q, const char *page, | |
406 | size_t count) | |
407 | { | |
408 | unsigned long poll_on; | |
409 | ssize_t ret; | |
410 | ||
cd19181b ML |
411 | if (!q->tag_set || q->tag_set->nr_maps <= HCTX_TYPE_POLL || |
412 | !q->tag_set->map[HCTX_TYPE_POLL].nr_queues) | |
05229bee JA |
413 | return -EINVAL; |
414 | ||
415 | ret = queue_var_store(&poll_on, page, count); | |
416 | if (ret < 0) | |
417 | return ret; | |
418 | ||
05229bee | 419 | if (poll_on) |
8814ce8a | 420 | blk_queue_flag_set(QUEUE_FLAG_POLL, q); |
05229bee | 421 | else |
8814ce8a | 422 | blk_queue_flag_clear(QUEUE_FLAG_POLL, q); |
05229bee JA |
423 | |
424 | return ret; | |
425 | } | |
426 | ||
65cd1d13 WZ |
427 | static ssize_t queue_io_timeout_show(struct request_queue *q, char *page) |
428 | { | |
429 | return sprintf(page, "%u\n", jiffies_to_msecs(q->rq_timeout)); | |
430 | } | |
431 | ||
432 | static ssize_t queue_io_timeout_store(struct request_queue *q, const char *page, | |
433 | size_t count) | |
434 | { | |
435 | unsigned int val; | |
436 | int err; | |
437 | ||
438 | err = kstrtou32(page, 10, &val); | |
439 | if (err || val == 0) | |
440 | return -EINVAL; | |
441 | ||
442 | blk_queue_rq_timeout(q, msecs_to_jiffies(val)); | |
443 | ||
444 | return count; | |
445 | } | |
446 | ||
87760e5e JA |
447 | static ssize_t queue_wb_lat_show(struct request_queue *q, char *page) |
448 | { | |
a7905043 | 449 | if (!wbt_rq_qos(q)) |
87760e5e JA |
450 | return -EINVAL; |
451 | ||
a7905043 | 452 | return sprintf(page, "%llu\n", div_u64(wbt_get_min_lat(q), 1000)); |
87760e5e JA |
453 | } |
454 | ||
455 | static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page, | |
456 | size_t count) | |
457 | { | |
a7905043 | 458 | struct rq_qos *rqos; |
87760e5e | 459 | ssize_t ret; |
80e091d1 | 460 | s64 val; |
87760e5e | 461 | |
87760e5e JA |
462 | ret = queue_var_store64(&val, page); |
463 | if (ret < 0) | |
464 | return ret; | |
d62118b6 JA |
465 | if (val < -1) |
466 | return -EINVAL; | |
467 | ||
a7905043 JB |
468 | rqos = wbt_rq_qos(q); |
469 | if (!rqos) { | |
d62118b6 JA |
470 | ret = wbt_init(q); |
471 | if (ret) | |
472 | return ret; | |
d62118b6 | 473 | } |
87760e5e | 474 | |
80e091d1 | 475 | if (val == -1) |
a7905043 | 476 | val = wbt_default_latency_nsec(q); |
80e091d1 | 477 | else if (val >= 0) |
a7905043 | 478 | val *= 1000ULL; |
d62118b6 | 479 | |
b7143fe6 AZ |
480 | if (wbt_get_min_lat(q) == val) |
481 | return count; | |
482 | ||
c125311d JA |
483 | /* |
484 | * Ensure that the queue is idled, in case the latency update | |
485 | * ends up either enabling or disabling wbt completely. We can't | |
486 | * have IO inflight if that happens. | |
487 | */ | |
a1ce35fa JA |
488 | blk_mq_freeze_queue(q); |
489 | blk_mq_quiesce_queue(q); | |
80e091d1 | 490 | |
c125311d | 491 | wbt_set_min_lat(q, val); |
c125311d | 492 | |
a1ce35fa JA |
493 | blk_mq_unquiesce_queue(q); |
494 | blk_mq_unfreeze_queue(q); | |
c125311d | 495 | |
87760e5e JA |
496 | return count; |
497 | } | |
498 | ||
93e9d8e8 JA |
499 | static ssize_t queue_wc_show(struct request_queue *q, char *page) |
500 | { | |
501 | if (test_bit(QUEUE_FLAG_WC, &q->queue_flags)) | |
502 | return sprintf(page, "write back\n"); | |
503 | ||
504 | return sprintf(page, "write through\n"); | |
505 | } | |
506 | ||
507 | static ssize_t queue_wc_store(struct request_queue *q, const char *page, | |
508 | size_t count) | |
509 | { | |
510 | int set = -1; | |
511 | ||
512 | if (!strncmp(page, "write back", 10)) | |
513 | set = 1; | |
514 | else if (!strncmp(page, "write through", 13) || | |
515 | !strncmp(page, "none", 4)) | |
516 | set = 0; | |
517 | ||
518 | if (set == -1) | |
519 | return -EINVAL; | |
520 | ||
93e9d8e8 | 521 | if (set) |
8814ce8a | 522 | blk_queue_flag_set(QUEUE_FLAG_WC, q); |
93e9d8e8 | 523 | else |
8814ce8a | 524 | blk_queue_flag_clear(QUEUE_FLAG_WC, q); |
93e9d8e8 JA |
525 | |
526 | return count; | |
527 | } | |
528 | ||
6fcefbe5 KO |
529 | static ssize_t queue_fua_show(struct request_queue *q, char *page) |
530 | { | |
531 | return sprintf(page, "%u\n", test_bit(QUEUE_FLAG_FUA, &q->queue_flags)); | |
532 | } | |
533 | ||
ea6ca600 YK |
534 | static ssize_t queue_dax_show(struct request_queue *q, char *page) |
535 | { | |
536 | return queue_var_show(blk_queue_dax(q), page); | |
537 | } | |
538 | ||
8324aa91 | 539 | static struct queue_sysfs_entry queue_requests_entry = { |
5657a819 | 540 | .attr = {.name = "nr_requests", .mode = 0644 }, |
8324aa91 JA |
541 | .show = queue_requests_show, |
542 | .store = queue_requests_store, | |
543 | }; | |
544 | ||
545 | static struct queue_sysfs_entry queue_ra_entry = { | |
5657a819 | 546 | .attr = {.name = "read_ahead_kb", .mode = 0644 }, |
8324aa91 JA |
547 | .show = queue_ra_show, |
548 | .store = queue_ra_store, | |
549 | }; | |
550 | ||
551 | static struct queue_sysfs_entry queue_max_sectors_entry = { | |
5657a819 | 552 | .attr = {.name = "max_sectors_kb", .mode = 0644 }, |
8324aa91 JA |
553 | .show = queue_max_sectors_show, |
554 | .store = queue_max_sectors_store, | |
555 | }; | |
556 | ||
557 | static struct queue_sysfs_entry queue_max_hw_sectors_entry = { | |
5657a819 | 558 | .attr = {.name = "max_hw_sectors_kb", .mode = 0444 }, |
8324aa91 JA |
559 | .show = queue_max_hw_sectors_show, |
560 | }; | |
561 | ||
c77a5710 | 562 | static struct queue_sysfs_entry queue_max_segments_entry = { |
5657a819 | 563 | .attr = {.name = "max_segments", .mode = 0444 }, |
c77a5710 MP |
564 | .show = queue_max_segments_show, |
565 | }; | |
566 | ||
1e739730 | 567 | static struct queue_sysfs_entry queue_max_discard_segments_entry = { |
5657a819 | 568 | .attr = {.name = "max_discard_segments", .mode = 0444 }, |
1e739730 CH |
569 | .show = queue_max_discard_segments_show, |
570 | }; | |
571 | ||
13f05c8d | 572 | static struct queue_sysfs_entry queue_max_integrity_segments_entry = { |
5657a819 | 573 | .attr = {.name = "max_integrity_segments", .mode = 0444 }, |
13f05c8d MP |
574 | .show = queue_max_integrity_segments_show, |
575 | }; | |
576 | ||
c77a5710 | 577 | static struct queue_sysfs_entry queue_max_segment_size_entry = { |
5657a819 | 578 | .attr = {.name = "max_segment_size", .mode = 0444 }, |
c77a5710 MP |
579 | .show = queue_max_segment_size_show, |
580 | }; | |
581 | ||
8324aa91 | 582 | static struct queue_sysfs_entry queue_iosched_entry = { |
5657a819 | 583 | .attr = {.name = "scheduler", .mode = 0644 }, |
8324aa91 JA |
584 | .show = elv_iosched_show, |
585 | .store = elv_iosched_store, | |
586 | }; | |
587 | ||
e68b903c | 588 | static struct queue_sysfs_entry queue_hw_sector_size_entry = { |
5657a819 | 589 | .attr = {.name = "hw_sector_size", .mode = 0444 }, |
e1defc4f MP |
590 | .show = queue_logical_block_size_show, |
591 | }; | |
592 | ||
593 | static struct queue_sysfs_entry queue_logical_block_size_entry = { | |
5657a819 | 594 | .attr = {.name = "logical_block_size", .mode = 0444 }, |
e1defc4f | 595 | .show = queue_logical_block_size_show, |
e68b903c MP |
596 | }; |
597 | ||
c72758f3 | 598 | static struct queue_sysfs_entry queue_physical_block_size_entry = { |
5657a819 | 599 | .attr = {.name = "physical_block_size", .mode = 0444 }, |
c72758f3 MP |
600 | .show = queue_physical_block_size_show, |
601 | }; | |
602 | ||
87caf97c | 603 | static struct queue_sysfs_entry queue_chunk_sectors_entry = { |
5657a819 | 604 | .attr = {.name = "chunk_sectors", .mode = 0444 }, |
87caf97c HR |
605 | .show = queue_chunk_sectors_show, |
606 | }; | |
607 | ||
c72758f3 | 608 | static struct queue_sysfs_entry queue_io_min_entry = { |
5657a819 | 609 | .attr = {.name = "minimum_io_size", .mode = 0444 }, |
c72758f3 MP |
610 | .show = queue_io_min_show, |
611 | }; | |
612 | ||
613 | static struct queue_sysfs_entry queue_io_opt_entry = { | |
5657a819 | 614 | .attr = {.name = "optimal_io_size", .mode = 0444 }, |
c72758f3 | 615 | .show = queue_io_opt_show, |
e68b903c MP |
616 | }; |
617 | ||
86b37281 | 618 | static struct queue_sysfs_entry queue_discard_granularity_entry = { |
5657a819 | 619 | .attr = {.name = "discard_granularity", .mode = 0444 }, |
86b37281 MP |
620 | .show = queue_discard_granularity_show, |
621 | }; | |
622 | ||
0034af03 | 623 | static struct queue_sysfs_entry queue_discard_max_hw_entry = { |
5657a819 | 624 | .attr = {.name = "discard_max_hw_bytes", .mode = 0444 }, |
0034af03 JA |
625 | .show = queue_discard_max_hw_show, |
626 | }; | |
627 | ||
86b37281 | 628 | static struct queue_sysfs_entry queue_discard_max_entry = { |
5657a819 | 629 | .attr = {.name = "discard_max_bytes", .mode = 0644 }, |
86b37281 | 630 | .show = queue_discard_max_show, |
0034af03 | 631 | .store = queue_discard_max_store, |
86b37281 MP |
632 | }; |
633 | ||
98262f27 | 634 | static struct queue_sysfs_entry queue_discard_zeroes_data_entry = { |
5657a819 | 635 | .attr = {.name = "discard_zeroes_data", .mode = 0444 }, |
98262f27 MP |
636 | .show = queue_discard_zeroes_data_show, |
637 | }; | |
638 | ||
4363ac7c | 639 | static struct queue_sysfs_entry queue_write_same_max_entry = { |
5657a819 | 640 | .attr = {.name = "write_same_max_bytes", .mode = 0444 }, |
4363ac7c MP |
641 | .show = queue_write_same_max_show, |
642 | }; | |
643 | ||
a6f0788e | 644 | static struct queue_sysfs_entry queue_write_zeroes_max_entry = { |
5657a819 | 645 | .attr = {.name = "write_zeroes_max_bytes", .mode = 0444 }, |
a6f0788e CK |
646 | .show = queue_write_zeroes_max_show, |
647 | }; | |
648 | ||
0512a75b KB |
649 | static struct queue_sysfs_entry queue_zone_append_max_entry = { |
650 | .attr = {.name = "zone_append_max_bytes", .mode = 0444 }, | |
651 | .show = queue_zone_append_max_show, | |
652 | }; | |
653 | ||
1308835f | 654 | static struct queue_sysfs_entry queue_nonrot_entry = { |
5657a819 | 655 | .attr = {.name = "rotational", .mode = 0644 }, |
956bcb7c JA |
656 | .show = queue_show_nonrot, |
657 | .store = queue_store_nonrot, | |
1308835f BZ |
658 | }; |
659 | ||
797476b8 | 660 | static struct queue_sysfs_entry queue_zoned_entry = { |
5657a819 | 661 | .attr = {.name = "zoned", .mode = 0444 }, |
797476b8 DLM |
662 | .show = queue_zoned_show, |
663 | }; | |
664 | ||
965b652e DLM |
665 | static struct queue_sysfs_entry queue_nr_zones_entry = { |
666 | .attr = {.name = "nr_zones", .mode = 0444 }, | |
667 | .show = queue_nr_zones_show, | |
668 | }; | |
669 | ||
ac9fafa1 | 670 | static struct queue_sysfs_entry queue_nomerges_entry = { |
5657a819 | 671 | .attr = {.name = "nomerges", .mode = 0644 }, |
ac9fafa1 AB |
672 | .show = queue_nomerges_show, |
673 | .store = queue_nomerges_store, | |
674 | }; | |
675 | ||
c7c22e4d | 676 | static struct queue_sysfs_entry queue_rq_affinity_entry = { |
5657a819 | 677 | .attr = {.name = "rq_affinity", .mode = 0644 }, |
c7c22e4d JA |
678 | .show = queue_rq_affinity_show, |
679 | .store = queue_rq_affinity_store, | |
680 | }; | |
681 | ||
bc58ba94 | 682 | static struct queue_sysfs_entry queue_iostats_entry = { |
5657a819 | 683 | .attr = {.name = "iostats", .mode = 0644 }, |
956bcb7c JA |
684 | .show = queue_show_iostats, |
685 | .store = queue_store_iostats, | |
bc58ba94 JA |
686 | }; |
687 | ||
e2e1a148 | 688 | static struct queue_sysfs_entry queue_random_entry = { |
5657a819 | 689 | .attr = {.name = "add_random", .mode = 0644 }, |
956bcb7c JA |
690 | .show = queue_show_random, |
691 | .store = queue_store_random, | |
e2e1a148 JA |
692 | }; |
693 | ||
05229bee | 694 | static struct queue_sysfs_entry queue_poll_entry = { |
5657a819 | 695 | .attr = {.name = "io_poll", .mode = 0644 }, |
05229bee JA |
696 | .show = queue_poll_show, |
697 | .store = queue_poll_store, | |
698 | }; | |
699 | ||
06426adf | 700 | static struct queue_sysfs_entry queue_poll_delay_entry = { |
5657a819 | 701 | .attr = {.name = "io_poll_delay", .mode = 0644 }, |
06426adf JA |
702 | .show = queue_poll_delay_show, |
703 | .store = queue_poll_delay_store, | |
704 | }; | |
705 | ||
93e9d8e8 | 706 | static struct queue_sysfs_entry queue_wc_entry = { |
5657a819 | 707 | .attr = {.name = "write_cache", .mode = 0644 }, |
93e9d8e8 JA |
708 | .show = queue_wc_show, |
709 | .store = queue_wc_store, | |
710 | }; | |
711 | ||
6fcefbe5 | 712 | static struct queue_sysfs_entry queue_fua_entry = { |
5657a819 | 713 | .attr = {.name = "fua", .mode = 0444 }, |
6fcefbe5 KO |
714 | .show = queue_fua_show, |
715 | }; | |
716 | ||
ea6ca600 | 717 | static struct queue_sysfs_entry queue_dax_entry = { |
5657a819 | 718 | .attr = {.name = "dax", .mode = 0444 }, |
ea6ca600 YK |
719 | .show = queue_dax_show, |
720 | }; | |
721 | ||
65cd1d13 WZ |
722 | static struct queue_sysfs_entry queue_io_timeout_entry = { |
723 | .attr = {.name = "io_timeout", .mode = 0644 }, | |
724 | .show = queue_io_timeout_show, | |
725 | .store = queue_io_timeout_store, | |
726 | }; | |
727 | ||
87760e5e | 728 | static struct queue_sysfs_entry queue_wb_lat_entry = { |
5657a819 | 729 | .attr = {.name = "wbt_lat_usec", .mode = 0644 }, |
87760e5e JA |
730 | .show = queue_wb_lat_show, |
731 | .store = queue_wb_lat_store, | |
732 | }; | |
733 | ||
297e3d85 SL |
734 | #ifdef CONFIG_BLK_DEV_THROTTLING_LOW |
735 | static struct queue_sysfs_entry throtl_sample_time_entry = { | |
5657a819 | 736 | .attr = {.name = "throttle_sample_time", .mode = 0644 }, |
297e3d85 SL |
737 | .show = blk_throtl_sample_time_show, |
738 | .store = blk_throtl_sample_time_store, | |
739 | }; | |
740 | #endif | |
741 | ||
4d25339e | 742 | static struct attribute *queue_attrs[] = { |
8324aa91 JA |
743 | &queue_requests_entry.attr, |
744 | &queue_ra_entry.attr, | |
745 | &queue_max_hw_sectors_entry.attr, | |
746 | &queue_max_sectors_entry.attr, | |
c77a5710 | 747 | &queue_max_segments_entry.attr, |
1e739730 | 748 | &queue_max_discard_segments_entry.attr, |
13f05c8d | 749 | &queue_max_integrity_segments_entry.attr, |
c77a5710 | 750 | &queue_max_segment_size_entry.attr, |
8324aa91 | 751 | &queue_iosched_entry.attr, |
e68b903c | 752 | &queue_hw_sector_size_entry.attr, |
e1defc4f | 753 | &queue_logical_block_size_entry.attr, |
c72758f3 | 754 | &queue_physical_block_size_entry.attr, |
87caf97c | 755 | &queue_chunk_sectors_entry.attr, |
c72758f3 MP |
756 | &queue_io_min_entry.attr, |
757 | &queue_io_opt_entry.attr, | |
86b37281 MP |
758 | &queue_discard_granularity_entry.attr, |
759 | &queue_discard_max_entry.attr, | |
0034af03 | 760 | &queue_discard_max_hw_entry.attr, |
98262f27 | 761 | &queue_discard_zeroes_data_entry.attr, |
4363ac7c | 762 | &queue_write_same_max_entry.attr, |
a6f0788e | 763 | &queue_write_zeroes_max_entry.attr, |
0512a75b | 764 | &queue_zone_append_max_entry.attr, |
1308835f | 765 | &queue_nonrot_entry.attr, |
797476b8 | 766 | &queue_zoned_entry.attr, |
965b652e | 767 | &queue_nr_zones_entry.attr, |
ac9fafa1 | 768 | &queue_nomerges_entry.attr, |
c7c22e4d | 769 | &queue_rq_affinity_entry.attr, |
bc58ba94 | 770 | &queue_iostats_entry.attr, |
e2e1a148 | 771 | &queue_random_entry.attr, |
05229bee | 772 | &queue_poll_entry.attr, |
93e9d8e8 | 773 | &queue_wc_entry.attr, |
6fcefbe5 | 774 | &queue_fua_entry.attr, |
ea6ca600 | 775 | &queue_dax_entry.attr, |
87760e5e | 776 | &queue_wb_lat_entry.attr, |
06426adf | 777 | &queue_poll_delay_entry.attr, |
65cd1d13 | 778 | &queue_io_timeout_entry.attr, |
297e3d85 SL |
779 | #ifdef CONFIG_BLK_DEV_THROTTLING_LOW |
780 | &throtl_sample_time_entry.attr, | |
781 | #endif | |
8324aa91 JA |
782 | NULL, |
783 | }; | |
784 | ||
4d25339e WZ |
785 | static umode_t queue_attr_visible(struct kobject *kobj, struct attribute *attr, |
786 | int n) | |
787 | { | |
788 | struct request_queue *q = | |
789 | container_of(kobj, struct request_queue, kobj); | |
790 | ||
791 | if (attr == &queue_io_timeout_entry.attr && | |
792 | (!q->mq_ops || !q->mq_ops->timeout)) | |
793 | return 0; | |
794 | ||
795 | return attr->mode; | |
796 | } | |
797 | ||
798 | static struct attribute_group queue_attr_group = { | |
799 | .attrs = queue_attrs, | |
800 | .is_visible = queue_attr_visible, | |
801 | }; | |
802 | ||
803 | ||
8324aa91 JA |
804 | #define to_queue(atr) container_of((atr), struct queue_sysfs_entry, attr) |
805 | ||
806 | static ssize_t | |
807 | queue_attr_show(struct kobject *kobj, struct attribute *attr, char *page) | |
808 | { | |
809 | struct queue_sysfs_entry *entry = to_queue(attr); | |
810 | struct request_queue *q = | |
811 | container_of(kobj, struct request_queue, kobj); | |
812 | ssize_t res; | |
813 | ||
814 | if (!entry->show) | |
815 | return -EIO; | |
816 | mutex_lock(&q->sysfs_lock); | |
8324aa91 JA |
817 | res = entry->show(q, page); |
818 | mutex_unlock(&q->sysfs_lock); | |
819 | return res; | |
820 | } | |
821 | ||
822 | static ssize_t | |
823 | queue_attr_store(struct kobject *kobj, struct attribute *attr, | |
824 | const char *page, size_t length) | |
825 | { | |
826 | struct queue_sysfs_entry *entry = to_queue(attr); | |
6728cb0e | 827 | struct request_queue *q; |
8324aa91 JA |
828 | ssize_t res; |
829 | ||
830 | if (!entry->store) | |
831 | return -EIO; | |
6728cb0e JA |
832 | |
833 | q = container_of(kobj, struct request_queue, kobj); | |
8324aa91 | 834 | mutex_lock(&q->sysfs_lock); |
8324aa91 JA |
835 | res = entry->store(q, page, length); |
836 | mutex_unlock(&q->sysfs_lock); | |
837 | return res; | |
838 | } | |
839 | ||
548bc8e1 TH |
840 | static void blk_free_queue_rcu(struct rcu_head *rcu_head) |
841 | { | |
842 | struct request_queue *q = container_of(rcu_head, struct request_queue, | |
843 | rcu_head); | |
844 | kmem_cache_free(blk_requestq_cachep, q); | |
845 | } | |
846 | ||
47cdee29 ML |
847 | /* Unconfigure the I/O scheduler and dissociate from the cgroup controller. */ |
848 | static void blk_exit_queue(struct request_queue *q) | |
849 | { | |
850 | /* | |
851 | * Since the I/O scheduler exit code may access cgroup information, | |
852 | * perform I/O scheduler exit before disassociating from the block | |
853 | * cgroup controller. | |
854 | */ | |
855 | if (q->elevator) { | |
856 | ioc_clear_queue(q); | |
c3e22192 | 857 | __elevator_exit(q, q->elevator); |
47cdee29 ML |
858 | q->elevator = NULL; |
859 | } | |
860 | ||
861 | /* | |
862 | * Remove all references to @q from the block cgroup controller before | |
863 | * restoring @q->queue_lock to avoid that restoring this pointer causes | |
864 | * e.g. blkcg_print_blkgs() to crash. | |
865 | */ | |
866 | blkcg_exit_queue(q); | |
867 | ||
868 | /* | |
869 | * Since the cgroup code may dereference the @q->backing_dev_info | |
870 | * pointer, only decrease its reference count after having removed the | |
871 | * association with the block cgroup controller. | |
872 | */ | |
873 | bdi_put(q->backing_dev_info); | |
874 | } | |
875 | ||
876 | ||
8324aa91 | 877 | /** |
1e936428 | 878 | * __blk_release_queue - release a request queue |
dc9edc44 | 879 | * @work: pointer to the release_work member of the request queue to be released |
8324aa91 JA |
880 | * |
881 | * Description: | |
1e936428 MPS |
882 | * This function is called when a block device is being unregistered. The |
883 | * process of releasing a request queue starts with blk_cleanup_queue, which | |
884 | * set the appropriate flags and then calls blk_put_queue, that decrements | |
885 | * the reference counter of the request queue. Once the reference counter | |
886 | * of the request queue reaches zero, blk_release_queue is called to release | |
887 | * all allocated resources of the request queue. | |
dc9edc44 BVA |
888 | */ |
889 | static void __blk_release_queue(struct work_struct *work) | |
8324aa91 | 890 | { |
dc9edc44 | 891 | struct request_queue *q = container_of(work, typeof(*q), release_work); |
8324aa91 | 892 | |
34dbad5d OS |
893 | if (test_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags)) |
894 | blk_stat_remove_callback(q, q->poll_cb); | |
895 | blk_stat_free_callback(q->poll_cb); | |
777eb1bf | 896 | |
34dbad5d OS |
897 | blk_free_queue_stats(q->stats); |
898 | ||
e26cc082 | 899 | if (queue_is_mq(q)) |
900 | cancel_delayed_work_sync(&q->requeue_work); | |
901 | ||
47cdee29 ML |
902 | blk_exit_queue(q); |
903 | ||
bf505456 DLM |
904 | blk_queue_free_zone_bitmaps(q); |
905 | ||
344e9ffc | 906 | if (queue_is_mq(q)) |
e09aae7e | 907 | blk_mq_release(q); |
18741986 | 908 | |
8324aa91 JA |
909 | blk_trace_shutdown(q); |
910 | ||
344e9ffc | 911 | if (queue_is_mq(q)) |
62ebce16 OS |
912 | blk_mq_debugfs_unregister(q); |
913 | ||
338aa96d | 914 | bioset_exit(&q->bio_split); |
54efd50b | 915 | |
a73f730d | 916 | ida_simple_remove(&blk_queue_ida, q->id); |
548bc8e1 | 917 | call_rcu(&q->rcu_head, blk_free_queue_rcu); |
8324aa91 JA |
918 | } |
919 | ||
dc9edc44 BVA |
920 | static void blk_release_queue(struct kobject *kobj) |
921 | { | |
922 | struct request_queue *q = | |
923 | container_of(kobj, struct request_queue, kobj); | |
924 | ||
925 | INIT_WORK(&q->release_work, __blk_release_queue); | |
926 | schedule_work(&q->release_work); | |
927 | } | |
928 | ||
52cf25d0 | 929 | static const struct sysfs_ops queue_sysfs_ops = { |
8324aa91 JA |
930 | .show = queue_attr_show, |
931 | .store = queue_attr_store, | |
932 | }; | |
933 | ||
934 | struct kobj_type blk_queue_ktype = { | |
935 | .sysfs_ops = &queue_sysfs_ops, | |
8324aa91 JA |
936 | .release = blk_release_queue, |
937 | }; | |
938 | ||
2c2086af BVA |
939 | /** |
940 | * blk_register_queue - register a block layer queue with sysfs | |
941 | * @disk: Disk of which the request queue should be registered with sysfs. | |
942 | */ | |
8324aa91 JA |
943 | int blk_register_queue(struct gendisk *disk) |
944 | { | |
945 | int ret; | |
1d54ad6d | 946 | struct device *dev = disk_to_dev(disk); |
8324aa91 | 947 | struct request_queue *q = disk->queue; |
cecf5d87 | 948 | bool has_elevator = false; |
8324aa91 | 949 | |
fb199746 | 950 | if (WARN_ON(!q)) |
8324aa91 JA |
951 | return -ENXIO; |
952 | ||
58c898ba | 953 | WARN_ONCE(blk_queue_registered(q), |
334335d2 OS |
954 | "%s is registering an already registered queue\n", |
955 | kobject_name(&dev->kobj)); | |
334335d2 | 956 | |
749fefe6 | 957 | /* |
17497acb TH |
958 | * SCSI probing may synchronously create and destroy a lot of |
959 | * request_queues for non-existent devices. Shutting down a fully | |
960 | * functional queue takes measureable wallclock time as RCU grace | |
961 | * periods are involved. To avoid excessive latency in these | |
962 | * cases, a request_queue starts out in a degraded mode which is | |
963 | * faster to shut down and is made fully functional here as | |
964 | * request_queues for non-existent devices never get registered. | |
749fefe6 | 965 | */ |
df35c7c9 | 966 | if (!blk_queue_init_done(q)) { |
57d74df9 | 967 | blk_queue_flag_set(QUEUE_FLAG_INIT_DONE, q); |
3ef28e83 | 968 | percpu_ref_switch_to_percpu(&q->q_usage_counter); |
df35c7c9 | 969 | } |
749fefe6 | 970 | |
1d54ad6d LZ |
971 | ret = blk_trace_init_sysfs(dev); |
972 | if (ret) | |
973 | return ret; | |
974 | ||
cecf5d87 | 975 | mutex_lock(&q->sysfs_dir_lock); |
b410aff2 | 976 | |
c9059598 | 977 | ret = kobject_add(&q->kobj, kobject_get(&dev->kobj), "%s", "queue"); |
ed5302d3 LY |
978 | if (ret < 0) { |
979 | blk_trace_remove_sysfs(dev); | |
b410aff2 | 980 | goto unlock; |
ed5302d3 | 981 | } |
8324aa91 | 982 | |
4d25339e WZ |
983 | ret = sysfs_create_group(&q->kobj, &queue_attr_group); |
984 | if (ret) { | |
985 | blk_trace_remove_sysfs(dev); | |
986 | kobject_del(&q->kobj); | |
987 | kobject_put(&dev->kobj); | |
988 | goto unlock; | |
989 | } | |
990 | ||
344e9ffc | 991 | if (queue_is_mq(q)) { |
2d0364c8 | 992 | __blk_mq_register_dev(dev, q); |
a8ecdd71 BVA |
993 | blk_mq_debugfs_register(q); |
994 | } | |
9c1051aa | 995 | |
b89f625e | 996 | mutex_lock(&q->sysfs_lock); |
344e9ffc | 997 | if (q->elevator) { |
cecf5d87 | 998 | ret = elv_register_queue(q, false); |
80c6b157 | 999 | if (ret) { |
b89f625e | 1000 | mutex_unlock(&q->sysfs_lock); |
cecf5d87 | 1001 | mutex_unlock(&q->sysfs_dir_lock); |
80c6b157 OS |
1002 | kobject_del(&q->kobj); |
1003 | blk_trace_remove_sysfs(dev); | |
1004 | kobject_put(&dev->kobj); | |
2c2086af | 1005 | return ret; |
80c6b157 | 1006 | } |
cecf5d87 | 1007 | has_elevator = true; |
8324aa91 | 1008 | } |
cecf5d87 | 1009 | |
cecf5d87 ML |
1010 | blk_queue_flag_set(QUEUE_FLAG_REGISTERED, q); |
1011 | wbt_enable_default(q); | |
1012 | blk_throtl_register_queue(q); | |
1013 | ||
1014 | /* Now everything is ready and send out KOBJ_ADD uevent */ | |
1015 | kobject_uevent(&q->kobj, KOBJ_ADD); | |
1016 | if (has_elevator) | |
1017 | kobject_uevent(&q->elevator->kobj, KOBJ_ADD); | |
1018 | mutex_unlock(&q->sysfs_lock); | |
1019 | ||
b410aff2 TE |
1020 | ret = 0; |
1021 | unlock: | |
cecf5d87 | 1022 | mutex_unlock(&q->sysfs_dir_lock); |
b410aff2 | 1023 | return ret; |
8324aa91 | 1024 | } |
fa70d2e2 | 1025 | EXPORT_SYMBOL_GPL(blk_register_queue); |
8324aa91 | 1026 | |
2c2086af BVA |
1027 | /** |
1028 | * blk_unregister_queue - counterpart of blk_register_queue() | |
1029 | * @disk: Disk of which the request queue should be unregistered from sysfs. | |
1030 | * | |
1031 | * Note: the caller is responsible for guaranteeing that this function is called | |
1032 | * after blk_register_queue() has finished. | |
1033 | */ | |
8324aa91 JA |
1034 | void blk_unregister_queue(struct gendisk *disk) |
1035 | { | |
1036 | struct request_queue *q = disk->queue; | |
1037 | ||
fb199746 AM |
1038 | if (WARN_ON(!q)) |
1039 | return; | |
1040 | ||
fa70d2e2 | 1041 | /* Return early if disk->queue was never registered. */ |
58c898ba | 1042 | if (!blk_queue_registered(q)) |
fa70d2e2 MS |
1043 | return; |
1044 | ||
667257e8 | 1045 | /* |
2c2086af BVA |
1046 | * Since sysfs_remove_dir() prevents adding new directory entries |
1047 | * before removal of existing entries starts, protect against | |
1048 | * concurrent elv_iosched_store() calls. | |
667257e8 | 1049 | */ |
e9a823fb | 1050 | mutex_lock(&q->sysfs_lock); |
8814ce8a | 1051 | blk_queue_flag_clear(QUEUE_FLAG_REGISTERED, q); |
cecf5d87 | 1052 | mutex_unlock(&q->sysfs_lock); |
02ba8893 | 1053 | |
cecf5d87 | 1054 | mutex_lock(&q->sysfs_dir_lock); |
2c2086af BVA |
1055 | /* |
1056 | * Remove the sysfs attributes before unregistering the queue data | |
1057 | * structures that can be modified through sysfs. | |
1058 | */ | |
344e9ffc | 1059 | if (queue_is_mq(q)) |
b21d5b30 | 1060 | blk_mq_unregister_dev(disk_to_dev(disk), q); |
8324aa91 | 1061 | |
48c0d4d4 ZK |
1062 | kobject_uevent(&q->kobj, KOBJ_REMOVE); |
1063 | kobject_del(&q->kobj); | |
1064 | blk_trace_remove_sysfs(disk_to_dev(disk)); | |
667257e8 | 1065 | |
b89f625e | 1066 | mutex_lock(&q->sysfs_lock); |
344e9ffc | 1067 | if (q->elevator) |
2c2086af | 1068 | elv_unregister_queue(q); |
b89f625e | 1069 | mutex_unlock(&q->sysfs_lock); |
cecf5d87 | 1070 | mutex_unlock(&q->sysfs_dir_lock); |
2c2086af BVA |
1071 | |
1072 | kobject_put(&disk_to_dev(disk)->kobj); | |
8324aa91 | 1073 | } |