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