blob: 306759bbdf1be719ef1f8e0a1f1912475c521a09 [file] [log] [blame]
Jens Axboe8324aa92008-01-29 14:51:59 +01001/*
2 * Functions related to sysfs handling
3 */
4#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09005#include <linux/slab.h>
Jens Axboe8324aa92008-01-29 14:51:59 +01006#include <linux/module.h>
7#include <linux/bio.h>
8#include <linux/blkdev.h>
9#include <linux/blktrace_api.h>
10
11#include "blk.h"
12
13struct queue_sysfs_entry {
14 struct attribute attr;
15 ssize_t (*show)(struct request_queue *, char *);
16 ssize_t (*store)(struct request_queue *, const char *, size_t);
17};
18
19static ssize_t
Xiaotian Feng9cb308c2009-07-17 15:26:26 +080020queue_var_show(unsigned long var, char *page)
Jens Axboe8324aa92008-01-29 14:51:59 +010021{
Xiaotian Feng9cb308c2009-07-17 15:26:26 +080022 return sprintf(page, "%lu\n", var);
Jens Axboe8324aa92008-01-29 14:51:59 +010023}
24
25static ssize_t
26queue_var_store(unsigned long *var, const char *page, size_t count)
27{
28 char *p = (char *) page;
29
30 *var = simple_strtoul(p, &p, 10);
31 return count;
32}
33
34static ssize_t queue_requests_show(struct request_queue *q, char *page)
35{
36 return queue_var_show(q->nr_requests, (page));
37}
38
39static ssize_t
40queue_requests_store(struct request_queue *q, const char *page, size_t count)
41{
42 struct request_list *rl = &q->rq;
43 unsigned long nr;
Jens Axboeb8a9ae72009-09-11 22:44:29 +020044 int ret;
45
46 if (!q->request_fn)
47 return -EINVAL;
48
49 ret = queue_var_store(&nr, page, count);
Jens Axboe8324aa92008-01-29 14:51:59 +010050 if (nr < BLKDEV_MIN_RQ)
51 nr = BLKDEV_MIN_RQ;
52
53 spin_lock_irq(q->queue_lock);
54 q->nr_requests = nr;
55 blk_queue_congestion_threshold(q);
56
Jens Axboe1faa16d2009-04-06 14:48:01 +020057 if (rl->count[BLK_RW_SYNC] >= queue_congestion_on_threshold(q))
58 blk_set_queue_congested(q, BLK_RW_SYNC);
59 else if (rl->count[BLK_RW_SYNC] < queue_congestion_off_threshold(q))
60 blk_clear_queue_congested(q, BLK_RW_SYNC);
Jens Axboe8324aa92008-01-29 14:51:59 +010061
Jens Axboe1faa16d2009-04-06 14:48:01 +020062 if (rl->count[BLK_RW_ASYNC] >= queue_congestion_on_threshold(q))
63 blk_set_queue_congested(q, BLK_RW_ASYNC);
64 else if (rl->count[BLK_RW_ASYNC] < queue_congestion_off_threshold(q))
65 blk_clear_queue_congested(q, BLK_RW_ASYNC);
Jens Axboe8324aa92008-01-29 14:51:59 +010066
Jens Axboe1faa16d2009-04-06 14:48:01 +020067 if (rl->count[BLK_RW_SYNC] >= q->nr_requests) {
68 blk_set_queue_full(q, BLK_RW_SYNC);
69 } else if (rl->count[BLK_RW_SYNC]+1 <= q->nr_requests) {
70 blk_clear_queue_full(q, BLK_RW_SYNC);
71 wake_up(&rl->wait[BLK_RW_SYNC]);
Jens Axboe8324aa92008-01-29 14:51:59 +010072 }
73
Jens Axboe1faa16d2009-04-06 14:48:01 +020074 if (rl->count[BLK_RW_ASYNC] >= q->nr_requests) {
75 blk_set_queue_full(q, BLK_RW_ASYNC);
76 } else if (rl->count[BLK_RW_ASYNC]+1 <= q->nr_requests) {
77 blk_clear_queue_full(q, BLK_RW_ASYNC);
78 wake_up(&rl->wait[BLK_RW_ASYNC]);
Jens Axboe8324aa92008-01-29 14:51:59 +010079 }
80 spin_unlock_irq(q->queue_lock);
81 return ret;
82}
83
84static ssize_t queue_ra_show(struct request_queue *q, char *page)
85{
Xiaotian Feng9cb308c2009-07-17 15:26:26 +080086 unsigned long ra_kb = q->backing_dev_info.ra_pages <<
87 (PAGE_CACHE_SHIFT - 10);
Jens Axboe8324aa92008-01-29 14:51:59 +010088
89 return queue_var_show(ra_kb, (page));
90}
91
92static ssize_t
93queue_ra_store(struct request_queue *q, const char *page, size_t count)
94{
95 unsigned long ra_kb;
96 ssize_t ret = queue_var_store(&ra_kb, page, count);
97
Jens Axboe8324aa92008-01-29 14:51:59 +010098 q->backing_dev_info.ra_pages = ra_kb >> (PAGE_CACHE_SHIFT - 10);
Jens Axboe8324aa92008-01-29 14:51:59 +010099
100 return ret;
101}
102
103static ssize_t queue_max_sectors_show(struct request_queue *q, char *page)
104{
Martin K. Petersenae03bf62009-05-22 17:17:50 -0400105 int max_sectors_kb = queue_max_sectors(q) >> 1;
Jens Axboe8324aa92008-01-29 14:51:59 +0100106
107 return queue_var_show(max_sectors_kb, (page));
108}
109
Martin K. Petersenc77a5712010-03-10 00:48:33 -0500110static ssize_t queue_max_segments_show(struct request_queue *q, char *page)
111{
112 return queue_var_show(queue_max_segments(q), (page));
113}
114
115static ssize_t queue_max_segment_size_show(struct request_queue *q, char *page)
116{
117 if (test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags))
118 return queue_var_show(queue_max_segment_size(q), (page));
119
120 return queue_var_show(PAGE_CACHE_SIZE, (page));
121}
122
Martin K. Petersene1defc42009-05-22 17:17:49 -0400123static ssize_t queue_logical_block_size_show(struct request_queue *q, char *page)
Martin K. Petersene68b9032008-01-29 19:14:08 +0100124{
Martin K. Petersene1defc42009-05-22 17:17:49 -0400125 return queue_var_show(queue_logical_block_size(q), page);
Martin K. Petersene68b9032008-01-29 19:14:08 +0100126}
127
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400128static ssize_t queue_physical_block_size_show(struct request_queue *q, char *page)
129{
130 return queue_var_show(queue_physical_block_size(q), page);
131}
132
133static ssize_t queue_io_min_show(struct request_queue *q, char *page)
134{
135 return queue_var_show(queue_io_min(q), page);
136}
137
138static ssize_t queue_io_opt_show(struct request_queue *q, char *page)
139{
140 return queue_var_show(queue_io_opt(q), page);
Jens Axboe8324aa92008-01-29 14:51:59 +0100141}
142
Martin K. Petersen86b37282009-11-10 11:50:21 +0100143static ssize_t queue_discard_granularity_show(struct request_queue *q, char *page)
144{
145 return queue_var_show(q->limits.discard_granularity, page);
146}
147
148static ssize_t queue_discard_max_show(struct request_queue *q, char *page)
149{
150 return queue_var_show(q->limits.max_discard_sectors << 9, page);
151}
152
Martin K. Petersen98262f22009-12-03 09:24:48 +0100153static ssize_t queue_discard_zeroes_data_show(struct request_queue *q, char *page)
154{
155 return queue_var_show(queue_discard_zeroes_data(q), page);
156}
157
Jens Axboe8324aa92008-01-29 14:51:59 +0100158static ssize_t
159queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
160{
161 unsigned long max_sectors_kb,
Martin K. Petersenae03bf62009-05-22 17:17:50 -0400162 max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1,
Jens Axboe8324aa92008-01-29 14:51:59 +0100163 page_kb = 1 << (PAGE_CACHE_SHIFT - 10);
164 ssize_t ret = queue_var_store(&max_sectors_kb, page, count);
165
166 if (max_sectors_kb > max_hw_sectors_kb || max_sectors_kb < page_kb)
167 return -EINVAL;
Wu Fengguang7c239512008-11-25 09:08:39 +0100168
Jens Axboe8324aa92008-01-29 14:51:59 +0100169 spin_lock_irq(q->queue_lock);
Nikanth Karthikesanc295fc02009-09-01 22:40:15 +0200170 q->limits.max_sectors = max_sectors_kb << 1;
Jens Axboe8324aa92008-01-29 14:51:59 +0100171 spin_unlock_irq(q->queue_lock);
172
173 return ret;
174}
175
176static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page)
177{
Martin K. Petersenae03bf62009-05-22 17:17:50 -0400178 int max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1;
Jens Axboe8324aa92008-01-29 14:51:59 +0100179
180 return queue_var_show(max_hw_sectors_kb, (page));
181}
182
Bartlomiej Zolnierkiewicz1308835f2009-01-07 12:22:39 +0100183static ssize_t queue_nonrot_show(struct request_queue *q, char *page)
184{
185 return queue_var_show(!blk_queue_nonrot(q), page);
186}
187
188static ssize_t queue_nonrot_store(struct request_queue *q, const char *page,
189 size_t count)
190{
191 unsigned long nm;
192 ssize_t ret = queue_var_store(&nm, page, count);
193
194 spin_lock_irq(q->queue_lock);
195 if (nm)
196 queue_flag_clear(QUEUE_FLAG_NONROT, q);
197 else
198 queue_flag_set(QUEUE_FLAG_NONROT, q);
199 spin_unlock_irq(q->queue_lock);
200
201 return ret;
202}
203
Alan D. Brunelleac9fafa2008-04-29 14:44:19 +0200204static ssize_t queue_nomerges_show(struct request_queue *q, char *page)
205{
Alan D. Brunelle488991e2010-01-29 09:04:08 +0100206 return queue_var_show((blk_queue_nomerges(q) << 1) |
207 blk_queue_noxmerges(q), page);
Alan D. Brunelleac9fafa2008-04-29 14:44:19 +0200208}
209
210static ssize_t queue_nomerges_store(struct request_queue *q, const char *page,
211 size_t count)
212{
213 unsigned long nm;
214 ssize_t ret = queue_var_store(&nm, page, count);
215
Jens Axboebf0f9702008-05-07 09:09:39 +0200216 spin_lock_irq(q->queue_lock);
Alan D. Brunelle488991e2010-01-29 09:04:08 +0100217 queue_flag_clear(QUEUE_FLAG_NOMERGES, q);
218 queue_flag_clear(QUEUE_FLAG_NOXMERGES, q);
219 if (nm == 2)
Jens Axboebf0f9702008-05-07 09:09:39 +0200220 queue_flag_set(QUEUE_FLAG_NOMERGES, q);
Alan D. Brunelle488991e2010-01-29 09:04:08 +0100221 else if (nm)
222 queue_flag_set(QUEUE_FLAG_NOXMERGES, q);
Jens Axboebf0f9702008-05-07 09:09:39 +0200223 spin_unlock_irq(q->queue_lock);
Bartlomiej Zolnierkiewicz1308835f2009-01-07 12:22:39 +0100224
Alan D. Brunelleac9fafa2008-04-29 14:44:19 +0200225 return ret;
226}
227
Jens Axboec7c22e42008-09-13 20:26:01 +0200228static ssize_t queue_rq_affinity_show(struct request_queue *q, char *page)
229{
Xiaotian Feng9cb308c2009-07-17 15:26:26 +0800230 bool set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags);
Jens Axboec7c22e42008-09-13 20:26:01 +0200231
Xiaotian Feng9cb308c2009-07-17 15:26:26 +0800232 return queue_var_show(set, page);
Jens Axboec7c22e42008-09-13 20:26:01 +0200233}
234
235static ssize_t
236queue_rq_affinity_store(struct request_queue *q, const char *page, size_t count)
237{
238 ssize_t ret = -EINVAL;
239#if defined(CONFIG_USE_GENERIC_SMP_HELPERS)
240 unsigned long val;
241
242 ret = queue_var_store(&val, page, count);
243 spin_lock_irq(q->queue_lock);
244 if (val)
245 queue_flag_set(QUEUE_FLAG_SAME_COMP, q);
246 else
247 queue_flag_clear(QUEUE_FLAG_SAME_COMP, q);
248 spin_unlock_irq(q->queue_lock);
249#endif
250 return ret;
251}
Jens Axboe8324aa92008-01-29 14:51:59 +0100252
Jens Axboebc58ba92009-01-23 10:54:44 +0100253static ssize_t queue_iostats_show(struct request_queue *q, char *page)
254{
255 return queue_var_show(blk_queue_io_stat(q), page);
256}
257
258static ssize_t queue_iostats_store(struct request_queue *q, const char *page,
259 size_t count)
260{
261 unsigned long stats;
262 ssize_t ret = queue_var_store(&stats, page, count);
263
264 spin_lock_irq(q->queue_lock);
265 if (stats)
266 queue_flag_set(QUEUE_FLAG_IO_STAT, q);
267 else
268 queue_flag_clear(QUEUE_FLAG_IO_STAT, q);
269 spin_unlock_irq(q->queue_lock);
270
271 return ret;
272}
273
Jens Axboe8324aa92008-01-29 14:51:59 +0100274static struct queue_sysfs_entry queue_requests_entry = {
275 .attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR },
276 .show = queue_requests_show,
277 .store = queue_requests_store,
278};
279
280static struct queue_sysfs_entry queue_ra_entry = {
281 .attr = {.name = "read_ahead_kb", .mode = S_IRUGO | S_IWUSR },
282 .show = queue_ra_show,
283 .store = queue_ra_store,
284};
285
286static struct queue_sysfs_entry queue_max_sectors_entry = {
287 .attr = {.name = "max_sectors_kb", .mode = S_IRUGO | S_IWUSR },
288 .show = queue_max_sectors_show,
289 .store = queue_max_sectors_store,
290};
291
292static struct queue_sysfs_entry queue_max_hw_sectors_entry = {
293 .attr = {.name = "max_hw_sectors_kb", .mode = S_IRUGO },
294 .show = queue_max_hw_sectors_show,
295};
296
Martin K. Petersenc77a5712010-03-10 00:48:33 -0500297static struct queue_sysfs_entry queue_max_segments_entry = {
298 .attr = {.name = "max_segments", .mode = S_IRUGO },
299 .show = queue_max_segments_show,
300};
301
302static struct queue_sysfs_entry queue_max_segment_size_entry = {
303 .attr = {.name = "max_segment_size", .mode = S_IRUGO },
304 .show = queue_max_segment_size_show,
305};
306
Jens Axboe8324aa92008-01-29 14:51:59 +0100307static struct queue_sysfs_entry queue_iosched_entry = {
308 .attr = {.name = "scheduler", .mode = S_IRUGO | S_IWUSR },
309 .show = elv_iosched_show,
310 .store = elv_iosched_store,
311};
312
Martin K. Petersene68b9032008-01-29 19:14:08 +0100313static struct queue_sysfs_entry queue_hw_sector_size_entry = {
314 .attr = {.name = "hw_sector_size", .mode = S_IRUGO },
Martin K. Petersene1defc42009-05-22 17:17:49 -0400315 .show = queue_logical_block_size_show,
316};
317
318static struct queue_sysfs_entry queue_logical_block_size_entry = {
319 .attr = {.name = "logical_block_size", .mode = S_IRUGO },
320 .show = queue_logical_block_size_show,
Martin K. Petersene68b9032008-01-29 19:14:08 +0100321};
322
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400323static struct queue_sysfs_entry queue_physical_block_size_entry = {
324 .attr = {.name = "physical_block_size", .mode = S_IRUGO },
325 .show = queue_physical_block_size_show,
326};
327
328static struct queue_sysfs_entry queue_io_min_entry = {
329 .attr = {.name = "minimum_io_size", .mode = S_IRUGO },
330 .show = queue_io_min_show,
331};
332
333static struct queue_sysfs_entry queue_io_opt_entry = {
334 .attr = {.name = "optimal_io_size", .mode = S_IRUGO },
335 .show = queue_io_opt_show,
Jens Axboe8324aa92008-01-29 14:51:59 +0100336};
337
Martin K. Petersen86b37282009-11-10 11:50:21 +0100338static struct queue_sysfs_entry queue_discard_granularity_entry = {
339 .attr = {.name = "discard_granularity", .mode = S_IRUGO },
340 .show = queue_discard_granularity_show,
341};
342
343static struct queue_sysfs_entry queue_discard_max_entry = {
344 .attr = {.name = "discard_max_bytes", .mode = S_IRUGO },
345 .show = queue_discard_max_show,
346};
347
Martin K. Petersen98262f22009-12-03 09:24:48 +0100348static struct queue_sysfs_entry queue_discard_zeroes_data_entry = {
349 .attr = {.name = "discard_zeroes_data", .mode = S_IRUGO },
350 .show = queue_discard_zeroes_data_show,
351};
352
Bartlomiej Zolnierkiewicz1308835f2009-01-07 12:22:39 +0100353static struct queue_sysfs_entry queue_nonrot_entry = {
354 .attr = {.name = "rotational", .mode = S_IRUGO | S_IWUSR },
355 .show = queue_nonrot_show,
356 .store = queue_nonrot_store,
357};
358
Alan D. Brunelleac9fafa2008-04-29 14:44:19 +0200359static struct queue_sysfs_entry queue_nomerges_entry = {
360 .attr = {.name = "nomerges", .mode = S_IRUGO | S_IWUSR },
361 .show = queue_nomerges_show,
362 .store = queue_nomerges_store,
363};
364
Jens Axboec7c22e42008-09-13 20:26:01 +0200365static struct queue_sysfs_entry queue_rq_affinity_entry = {
366 .attr = {.name = "rq_affinity", .mode = S_IRUGO | S_IWUSR },
367 .show = queue_rq_affinity_show,
368 .store = queue_rq_affinity_store,
369};
370
Jens Axboebc58ba92009-01-23 10:54:44 +0100371static struct queue_sysfs_entry queue_iostats_entry = {
372 .attr = {.name = "iostats", .mode = S_IRUGO | S_IWUSR },
373 .show = queue_iostats_show,
374 .store = queue_iostats_store,
375};
376
Jens Axboe8324aa92008-01-29 14:51:59 +0100377static struct attribute *default_attrs[] = {
378 &queue_requests_entry.attr,
379 &queue_ra_entry.attr,
380 &queue_max_hw_sectors_entry.attr,
381 &queue_max_sectors_entry.attr,
Martin K. Petersenc77a5712010-03-10 00:48:33 -0500382 &queue_max_segments_entry.attr,
383 &queue_max_segment_size_entry.attr,
Jens Axboe8324aa92008-01-29 14:51:59 +0100384 &queue_iosched_entry.attr,
Martin K. Petersene68b9032008-01-29 19:14:08 +0100385 &queue_hw_sector_size_entry.attr,
Martin K. Petersene1defc42009-05-22 17:17:49 -0400386 &queue_logical_block_size_entry.attr,
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400387 &queue_physical_block_size_entry.attr,
388 &queue_io_min_entry.attr,
389 &queue_io_opt_entry.attr,
Martin K. Petersen86b37282009-11-10 11:50:21 +0100390 &queue_discard_granularity_entry.attr,
391 &queue_discard_max_entry.attr,
Martin K. Petersen98262f22009-12-03 09:24:48 +0100392 &queue_discard_zeroes_data_entry.attr,
Bartlomiej Zolnierkiewicz1308835f2009-01-07 12:22:39 +0100393 &queue_nonrot_entry.attr,
Alan D. Brunelleac9fafa2008-04-29 14:44:19 +0200394 &queue_nomerges_entry.attr,
Jens Axboec7c22e42008-09-13 20:26:01 +0200395 &queue_rq_affinity_entry.attr,
Jens Axboebc58ba92009-01-23 10:54:44 +0100396 &queue_iostats_entry.attr,
Jens Axboe8324aa92008-01-29 14:51:59 +0100397 NULL,
398};
399
400#define to_queue(atr) container_of((atr), struct queue_sysfs_entry, attr)
401
402static ssize_t
403queue_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
404{
405 struct queue_sysfs_entry *entry = to_queue(attr);
406 struct request_queue *q =
407 container_of(kobj, struct request_queue, kobj);
408 ssize_t res;
409
410 if (!entry->show)
411 return -EIO;
412 mutex_lock(&q->sysfs_lock);
413 if (test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)) {
414 mutex_unlock(&q->sysfs_lock);
415 return -ENOENT;
416 }
417 res = entry->show(q, page);
418 mutex_unlock(&q->sysfs_lock);
419 return res;
420}
421
422static ssize_t
423queue_attr_store(struct kobject *kobj, struct attribute *attr,
424 const char *page, size_t length)
425{
426 struct queue_sysfs_entry *entry = to_queue(attr);
Jens Axboe6728cb02008-01-31 13:03:55 +0100427 struct request_queue *q;
Jens Axboe8324aa92008-01-29 14:51:59 +0100428 ssize_t res;
429
430 if (!entry->store)
431 return -EIO;
Jens Axboe6728cb02008-01-31 13:03:55 +0100432
433 q = container_of(kobj, struct request_queue, kobj);
Jens Axboe8324aa92008-01-29 14:51:59 +0100434 mutex_lock(&q->sysfs_lock);
435 if (test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)) {
436 mutex_unlock(&q->sysfs_lock);
437 return -ENOENT;
438 }
439 res = entry->store(q, page, length);
440 mutex_unlock(&q->sysfs_lock);
441 return res;
442}
443
444/**
445 * blk_cleanup_queue: - release a &struct request_queue when it is no longer needed
446 * @kobj: the kobj belonging of the request queue to be released
447 *
448 * Description:
449 * blk_cleanup_queue is the pair to blk_init_queue() or
450 * blk_queue_make_request(). It should be called when a request queue is
451 * being released; typically when a block device is being de-registered.
452 * Currently, its primary task it to free all the &struct request
453 * structures that were allocated to the queue and the queue itself.
454 *
455 * Caveat:
456 * Hopefully the low level driver will have finished any
457 * outstanding requests first...
458 **/
459static void blk_release_queue(struct kobject *kobj)
460{
461 struct request_queue *q =
462 container_of(kobj, struct request_queue, kobj);
463 struct request_list *rl = &q->rq;
464
465 blk_sync_queue(q);
466
467 if (rl->rq_pool)
468 mempool_destroy(rl->rq_pool);
469
470 if (q->queue_tags)
471 __blk_queue_free_tags(q);
472
473 blk_trace_shutdown(q);
474
475 bdi_destroy(&q->backing_dev_info);
476 kmem_cache_free(blk_requestq_cachep, q);
477}
478
Emese Revfy52cf25d2010-01-19 02:58:23 +0100479static const struct sysfs_ops queue_sysfs_ops = {
Jens Axboe8324aa92008-01-29 14:51:59 +0100480 .show = queue_attr_show,
481 .store = queue_attr_store,
482};
483
484struct kobj_type blk_queue_ktype = {
485 .sysfs_ops = &queue_sysfs_ops,
486 .default_attrs = default_attrs,
487 .release = blk_release_queue,
488};
489
490int blk_register_queue(struct gendisk *disk)
491{
492 int ret;
Li Zefan1d54ad62009-04-14 14:00:05 +0800493 struct device *dev = disk_to_dev(disk);
Jens Axboe8324aa92008-01-29 14:51:59 +0100494
495 struct request_queue *q = disk->queue;
496
Akinobu Mitafb199742008-04-21 09:51:06 +0200497 if (WARN_ON(!q))
Jens Axboe8324aa92008-01-29 14:51:59 +0100498 return -ENXIO;
499
Li Zefan1d54ad62009-04-14 14:00:05 +0800500 ret = blk_trace_init_sysfs(dev);
501 if (ret)
502 return ret;
503
Linus Torvaldsc9059592009-06-11 10:52:27 -0700504 ret = kobject_add(&q->kobj, kobject_get(&dev->kobj), "%s", "queue");
Jens Axboe8324aa92008-01-29 14:51:59 +0100505 if (ret < 0)
506 return ret;
507
508 kobject_uevent(&q->kobj, KOBJ_ADD);
509
Martin K. Petersencd43e262009-05-22 17:17:52 -0400510 if (!q->request_fn)
511 return 0;
512
Jens Axboe8324aa92008-01-29 14:51:59 +0100513 ret = elv_register_queue(q);
514 if (ret) {
515 kobject_uevent(&q->kobj, KOBJ_REMOVE);
516 kobject_del(&q->kobj);
Zdenek Kabelac48c0d4d2009-09-25 06:19:26 +0200517 blk_trace_remove_sysfs(disk_to_dev(disk));
Jens Axboe8324aa92008-01-29 14:51:59 +0100518 return ret;
519 }
520
521 return 0;
522}
523
524void blk_unregister_queue(struct gendisk *disk)
525{
526 struct request_queue *q = disk->queue;
527
Akinobu Mitafb199742008-04-21 09:51:06 +0200528 if (WARN_ON(!q))
529 return;
530
Zdenek Kabelac48c0d4d2009-09-25 06:19:26 +0200531 if (q->request_fn)
Jens Axboe8324aa92008-01-29 14:51:59 +0100532 elv_unregister_queue(q);
533
Zdenek Kabelac48c0d4d2009-09-25 06:19:26 +0200534 kobject_uevent(&q->kobj, KOBJ_REMOVE);
535 kobject_del(&q->kobj);
536 blk_trace_remove_sysfs(disk_to_dev(disk));
537 kobject_put(&disk_to_dev(disk)->kobj);
Jens Axboe8324aa92008-01-29 14:51:59 +0100538}