Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Functions related to sysfs handling |
| 3 | */ |
| 4 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 5 | #include <linux/slab.h> |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 6 | #include <linux/module.h> |
| 7 | #include <linux/bio.h> |
| 8 | #include <linux/blkdev.h> |
Tejun Heo | 66114ca | 2015-05-22 17:13:32 -0400 | [diff] [blame] | 9 | #include <linux/backing-dev.h> |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 10 | #include <linux/blktrace_api.h> |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 11 | #include <linux/blk-mq.h> |
Tejun Heo | eea8f41 | 2015-05-22 17:13:17 -0400 | [diff] [blame] | 12 | #include <linux/blk-cgroup.h> |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 13 | |
| 14 | #include "blk.h" |
Ming Lei | 3edcc0c | 2013-12-26 21:31:38 +0800 | [diff] [blame] | 15 | #include "blk-mq.h" |
Omar Sandoval | d173a25 | 2017-05-04 00:31:30 -0700 | [diff] [blame] | 16 | #include "blk-mq-debugfs.h" |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 17 | #include "blk-wbt.h" |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 18 | |
| 19 | struct queue_sysfs_entry { |
| 20 | struct attribute attr; |
| 21 | ssize_t (*show)(struct request_queue *, char *); |
| 22 | ssize_t (*store)(struct request_queue *, const char *, size_t); |
| 23 | }; |
| 24 | |
| 25 | static ssize_t |
Xiaotian Feng | 9cb308c | 2009-07-17 15:26:26 +0800 | [diff] [blame] | 26 | queue_var_show(unsigned long var, char *page) |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 27 | { |
Xiaotian Feng | 9cb308c | 2009-07-17 15:26:26 +0800 | [diff] [blame] | 28 | return sprintf(page, "%lu\n", var); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static ssize_t |
| 32 | queue_var_store(unsigned long *var, const char *page, size_t count) |
| 33 | { |
Dave Reisner | b1f3b64 | 2012-09-08 11:55:45 -0400 | [diff] [blame] | 34 | int err; |
| 35 | unsigned long v; |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 36 | |
Jingoo Han | ed751e6 | 2013-09-11 14:20:08 -0700 | [diff] [blame] | 37 | err = kstrtoul(page, 10, &v); |
Dave Reisner | b1f3b64 | 2012-09-08 11:55:45 -0400 | [diff] [blame] | 38 | if (err || v > UINT_MAX) |
| 39 | return -EINVAL; |
| 40 | |
| 41 | *var = v; |
| 42 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 43 | return count; |
| 44 | } |
| 45 | |
Jens Axboe | 80e091d | 2016-11-28 09:22:47 -0700 | [diff] [blame] | 46 | static ssize_t queue_var_store64(s64 *var, const char *page) |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 47 | { |
| 48 | int err; |
Jens Axboe | 80e091d | 2016-11-28 09:22:47 -0700 | [diff] [blame] | 49 | s64 v; |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 50 | |
Jens Axboe | 80e091d | 2016-11-28 09:22:47 -0700 | [diff] [blame] | 51 | err = kstrtos64(page, 10, &v); |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 52 | if (err < 0) |
| 53 | return err; |
| 54 | |
| 55 | *var = v; |
| 56 | return 0; |
| 57 | } |
| 58 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 59 | static ssize_t queue_requests_show(struct request_queue *q, char *page) |
| 60 | { |
| 61 | return queue_var_show(q->nr_requests, (page)); |
| 62 | } |
| 63 | |
| 64 | static ssize_t |
| 65 | queue_requests_store(struct request_queue *q, const char *page, size_t count) |
| 66 | { |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 67 | unsigned long nr; |
Jens Axboe | e3a2b3f | 2014-05-20 11:49:02 -0600 | [diff] [blame] | 68 | int ret, err; |
Jens Axboe | b8a9ae7 | 2009-09-11 22:44:29 +0200 | [diff] [blame] | 69 | |
Jens Axboe | e3a2b3f | 2014-05-20 11:49:02 -0600 | [diff] [blame] | 70 | if (!q->request_fn && !q->mq_ops) |
Jens Axboe | b8a9ae7 | 2009-09-11 22:44:29 +0200 | [diff] [blame] | 71 | return -EINVAL; |
| 72 | |
| 73 | ret = queue_var_store(&nr, page, count); |
Dave Reisner | b1f3b64 | 2012-09-08 11:55:45 -0400 | [diff] [blame] | 74 | if (ret < 0) |
| 75 | return ret; |
| 76 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 77 | if (nr < BLKDEV_MIN_RQ) |
| 78 | nr = BLKDEV_MIN_RQ; |
| 79 | |
Jens Axboe | e3a2b3f | 2014-05-20 11:49:02 -0600 | [diff] [blame] | 80 | if (q->request_fn) |
| 81 | err = blk_update_nr_requests(q, nr); |
| 82 | else |
| 83 | err = blk_mq_update_nr_requests(q, nr); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 84 | |
Jens Axboe | e3a2b3f | 2014-05-20 11:49:02 -0600 | [diff] [blame] | 85 | if (err) |
| 86 | return err; |
Tejun Heo | a051661 | 2012-06-26 15:05:44 -0700 | [diff] [blame] | 87 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 88 | return ret; |
| 89 | } |
| 90 | |
| 91 | static ssize_t queue_ra_show(struct request_queue *q, char *page) |
| 92 | { |
Jan Kara | dc3b17c | 2017-02-02 15:56:50 +0100 | [diff] [blame] | 93 | unsigned long ra_kb = q->backing_dev_info->ra_pages << |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 94 | (PAGE_SHIFT - 10); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 95 | |
| 96 | return queue_var_show(ra_kb, (page)); |
| 97 | } |
| 98 | |
| 99 | static ssize_t |
| 100 | queue_ra_store(struct request_queue *q, const char *page, size_t count) |
| 101 | { |
| 102 | unsigned long ra_kb; |
| 103 | ssize_t ret = queue_var_store(&ra_kb, page, count); |
| 104 | |
Dave Reisner | b1f3b64 | 2012-09-08 11:55:45 -0400 | [diff] [blame] | 105 | if (ret < 0) |
| 106 | return ret; |
| 107 | |
Jan Kara | dc3b17c | 2017-02-02 15:56:50 +0100 | [diff] [blame] | 108 | q->backing_dev_info->ra_pages = ra_kb >> (PAGE_SHIFT - 10); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 109 | |
| 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | static ssize_t queue_max_sectors_show(struct request_queue *q, char *page) |
| 114 | { |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 115 | int max_sectors_kb = queue_max_sectors(q) >> 1; |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 116 | |
| 117 | return queue_var_show(max_sectors_kb, (page)); |
| 118 | } |
| 119 | |
Martin K. Petersen | c77a571 | 2010-03-10 00:48:33 -0500 | [diff] [blame] | 120 | static ssize_t queue_max_segments_show(struct request_queue *q, char *page) |
| 121 | { |
| 122 | return queue_var_show(queue_max_segments(q), (page)); |
| 123 | } |
| 124 | |
Christoph Hellwig | 1e73973 | 2017-02-08 14:46:49 +0100 | [diff] [blame] | 125 | static ssize_t queue_max_discard_segments_show(struct request_queue *q, |
| 126 | char *page) |
| 127 | { |
| 128 | return queue_var_show(queue_max_discard_segments(q), (page)); |
| 129 | } |
| 130 | |
Martin K. Petersen | 13f05c8 | 2010-09-10 20:50:10 +0200 | [diff] [blame] | 131 | static ssize_t queue_max_integrity_segments_show(struct request_queue *q, char *page) |
| 132 | { |
| 133 | return queue_var_show(q->limits.max_integrity_segments, (page)); |
| 134 | } |
| 135 | |
Martin K. Petersen | c77a571 | 2010-03-10 00:48:33 -0500 | [diff] [blame] | 136 | static ssize_t queue_max_segment_size_show(struct request_queue *q, char *page) |
| 137 | { |
Martin K. Petersen | e692cb6 | 2010-12-01 19:41:49 +0100 | [diff] [blame] | 138 | if (blk_queue_cluster(q)) |
Martin K. Petersen | c77a571 | 2010-03-10 00:48:33 -0500 | [diff] [blame] | 139 | return queue_var_show(queue_max_segment_size(q), (page)); |
| 140 | |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 141 | return queue_var_show(PAGE_SIZE, (page)); |
Martin K. Petersen | c77a571 | 2010-03-10 00:48:33 -0500 | [diff] [blame] | 142 | } |
| 143 | |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 144 | static ssize_t queue_logical_block_size_show(struct request_queue *q, char *page) |
Martin K. Petersen | e68b903 | 2008-01-29 19:14:08 +0100 | [diff] [blame] | 145 | { |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 146 | return queue_var_show(queue_logical_block_size(q), page); |
Martin K. Petersen | e68b903 | 2008-01-29 19:14:08 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Martin K. Petersen | c72758f | 2009-05-22 17:17:53 -0400 | [diff] [blame] | 149 | static ssize_t queue_physical_block_size_show(struct request_queue *q, char *page) |
| 150 | { |
| 151 | return queue_var_show(queue_physical_block_size(q), page); |
| 152 | } |
| 153 | |
Hannes Reinecke | 87caf97 | 2016-10-18 15:40:30 +0900 | [diff] [blame] | 154 | static ssize_t queue_chunk_sectors_show(struct request_queue *q, char *page) |
| 155 | { |
| 156 | return queue_var_show(q->limits.chunk_sectors, page); |
| 157 | } |
| 158 | |
Martin K. Petersen | c72758f | 2009-05-22 17:17:53 -0400 | [diff] [blame] | 159 | static ssize_t queue_io_min_show(struct request_queue *q, char *page) |
| 160 | { |
| 161 | return queue_var_show(queue_io_min(q), page); |
| 162 | } |
| 163 | |
| 164 | static ssize_t queue_io_opt_show(struct request_queue *q, char *page) |
| 165 | { |
| 166 | return queue_var_show(queue_io_opt(q), page); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Martin K. Petersen | 86b3728 | 2009-11-10 11:50:21 +0100 | [diff] [blame] | 169 | static ssize_t queue_discard_granularity_show(struct request_queue *q, char *page) |
| 170 | { |
| 171 | return queue_var_show(q->limits.discard_granularity, page); |
| 172 | } |
| 173 | |
Jens Axboe | 0034af0 | 2015-07-16 09:14:26 -0600 | [diff] [blame] | 174 | static ssize_t queue_discard_max_hw_show(struct request_queue *q, char *page) |
| 175 | { |
Jens Axboe | 0034af0 | 2015-07-16 09:14:26 -0600 | [diff] [blame] | 176 | |
Alan | 18f922d0 | 2016-02-17 14:15:30 +0000 | [diff] [blame] | 177 | return sprintf(page, "%llu\n", |
| 178 | (unsigned long long)q->limits.max_hw_discard_sectors << 9); |
Jens Axboe | 0034af0 | 2015-07-16 09:14:26 -0600 | [diff] [blame] | 179 | } |
| 180 | |
Martin K. Petersen | 86b3728 | 2009-11-10 11:50:21 +0100 | [diff] [blame] | 181 | static ssize_t queue_discard_max_show(struct request_queue *q, char *page) |
| 182 | { |
Martin K. Petersen | a934a00 | 2011-05-18 10:37:35 +0200 | [diff] [blame] | 183 | return sprintf(page, "%llu\n", |
| 184 | (unsigned long long)q->limits.max_discard_sectors << 9); |
Martin K. Petersen | 86b3728 | 2009-11-10 11:50:21 +0100 | [diff] [blame] | 185 | } |
| 186 | |
Jens Axboe | 0034af0 | 2015-07-16 09:14:26 -0600 | [diff] [blame] | 187 | static ssize_t queue_discard_max_store(struct request_queue *q, |
| 188 | const char *page, size_t count) |
| 189 | { |
| 190 | unsigned long max_discard; |
| 191 | ssize_t ret = queue_var_store(&max_discard, page, count); |
| 192 | |
| 193 | if (ret < 0) |
| 194 | return ret; |
| 195 | |
| 196 | if (max_discard & (q->limits.discard_granularity - 1)) |
| 197 | return -EINVAL; |
| 198 | |
| 199 | max_discard >>= 9; |
| 200 | if (max_discard > UINT_MAX) |
| 201 | return -EINVAL; |
| 202 | |
| 203 | if (max_discard > q->limits.max_hw_discard_sectors) |
| 204 | max_discard = q->limits.max_hw_discard_sectors; |
| 205 | |
| 206 | q->limits.max_discard_sectors = max_discard; |
| 207 | return ret; |
| 208 | } |
| 209 | |
Martin K. Petersen | 98262f2 | 2009-12-03 09:24:48 +0100 | [diff] [blame] | 210 | static ssize_t queue_discard_zeroes_data_show(struct request_queue *q, char *page) |
| 211 | { |
Christoph Hellwig | 48920ff | 2017-04-05 19:21:23 +0200 | [diff] [blame] | 212 | return queue_var_show(0, page); |
Martin K. Petersen | 98262f2 | 2009-12-03 09:24:48 +0100 | [diff] [blame] | 213 | } |
| 214 | |
Martin K. Petersen | 4363ac7 | 2012-09-18 12:19:27 -0400 | [diff] [blame] | 215 | static ssize_t queue_write_same_max_show(struct request_queue *q, char *page) |
| 216 | { |
| 217 | return sprintf(page, "%llu\n", |
| 218 | (unsigned long long)q->limits.max_write_same_sectors << 9); |
| 219 | } |
| 220 | |
Chaitanya Kulkarni | a6f0788 | 2016-11-30 12:28:59 -0800 | [diff] [blame] | 221 | static ssize_t queue_write_zeroes_max_show(struct request_queue *q, char *page) |
| 222 | { |
| 223 | return sprintf(page, "%llu\n", |
| 224 | (unsigned long long)q->limits.max_write_zeroes_sectors << 9); |
| 225 | } |
Martin K. Petersen | 4363ac7 | 2012-09-18 12:19:27 -0400 | [diff] [blame] | 226 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 227 | static ssize_t |
| 228 | queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) |
| 229 | { |
| 230 | unsigned long max_sectors_kb, |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 231 | max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1, |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 232 | page_kb = 1 << (PAGE_SHIFT - 10); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 233 | ssize_t ret = queue_var_store(&max_sectors_kb, page, count); |
| 234 | |
Dave Reisner | b1f3b64 | 2012-09-08 11:55:45 -0400 | [diff] [blame] | 235 | if (ret < 0) |
| 236 | return ret; |
| 237 | |
Martin K. Petersen | ca369d5 | 2015-11-13 16:46:48 -0500 | [diff] [blame] | 238 | max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long) |
| 239 | q->limits.max_dev_sectors >> 1); |
| 240 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 241 | if (max_sectors_kb > max_hw_sectors_kb || max_sectors_kb < page_kb) |
| 242 | return -EINVAL; |
Wu Fengguang | 7c23951 | 2008-11-25 09:08:39 +0100 | [diff] [blame] | 243 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 244 | spin_lock_irq(q->queue_lock); |
Nikanth Karthikesan | c295fc0 | 2009-09-01 22:40:15 +0200 | [diff] [blame] | 245 | q->limits.max_sectors = max_sectors_kb << 1; |
Jan Kara | dc3b17c | 2017-02-02 15:56:50 +0100 | [diff] [blame] | 246 | q->backing_dev_info->io_pages = max_sectors_kb >> (PAGE_SHIFT - 10); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 247 | spin_unlock_irq(q->queue_lock); |
| 248 | |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page) |
| 253 | { |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 254 | int max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1; |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 255 | |
| 256 | return queue_var_show(max_hw_sectors_kb, (page)); |
| 257 | } |
| 258 | |
Jens Axboe | 956bcb7 | 2010-08-07 18:13:50 +0200 | [diff] [blame] | 259 | #define QUEUE_SYSFS_BIT_FNS(name, flag, neg) \ |
| 260 | static ssize_t \ |
| 261 | queue_show_##name(struct request_queue *q, char *page) \ |
| 262 | { \ |
| 263 | int bit; \ |
| 264 | bit = test_bit(QUEUE_FLAG_##flag, &q->queue_flags); \ |
| 265 | return queue_var_show(neg ? !bit : bit, page); \ |
| 266 | } \ |
| 267 | static ssize_t \ |
| 268 | queue_store_##name(struct request_queue *q, const char *page, size_t count) \ |
| 269 | { \ |
| 270 | unsigned long val; \ |
| 271 | ssize_t ret; \ |
| 272 | ret = queue_var_store(&val, page, count); \ |
Arnd Bergmann | c678ef5 | 2013-04-03 21:53:57 +0200 | [diff] [blame] | 273 | if (ret < 0) \ |
| 274 | return ret; \ |
Jens Axboe | 956bcb7 | 2010-08-07 18:13:50 +0200 | [diff] [blame] | 275 | if (neg) \ |
| 276 | val = !val; \ |
| 277 | \ |
| 278 | spin_lock_irq(q->queue_lock); \ |
| 279 | if (val) \ |
| 280 | queue_flag_set(QUEUE_FLAG_##flag, q); \ |
| 281 | else \ |
| 282 | queue_flag_clear(QUEUE_FLAG_##flag, q); \ |
| 283 | spin_unlock_irq(q->queue_lock); \ |
| 284 | return ret; \ |
Bartlomiej Zolnierkiewicz | 1308835f | 2009-01-07 12:22:39 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Jens Axboe | 956bcb7 | 2010-08-07 18:13:50 +0200 | [diff] [blame] | 287 | QUEUE_SYSFS_BIT_FNS(nonrot, NONROT, 1); |
| 288 | QUEUE_SYSFS_BIT_FNS(random, ADD_RANDOM, 0); |
| 289 | QUEUE_SYSFS_BIT_FNS(iostats, IO_STAT, 0); |
| 290 | #undef QUEUE_SYSFS_BIT_FNS |
Bartlomiej Zolnierkiewicz | 1308835f | 2009-01-07 12:22:39 +0100 | [diff] [blame] | 291 | |
Damien Le Moal | 797476b | 2016-10-18 15:40:29 +0900 | [diff] [blame] | 292 | static ssize_t queue_zoned_show(struct request_queue *q, char *page) |
| 293 | { |
| 294 | switch (blk_queue_zoned_model(q)) { |
| 295 | case BLK_ZONED_HA: |
| 296 | return sprintf(page, "host-aware\n"); |
| 297 | case BLK_ZONED_HM: |
| 298 | return sprintf(page, "host-managed\n"); |
| 299 | default: |
| 300 | return sprintf(page, "none\n"); |
| 301 | } |
| 302 | } |
| 303 | |
Alan D. Brunelle | ac9fafa | 2008-04-29 14:44:19 +0200 | [diff] [blame] | 304 | static ssize_t queue_nomerges_show(struct request_queue *q, char *page) |
| 305 | { |
Alan D. Brunelle | 488991e | 2010-01-29 09:04:08 +0100 | [diff] [blame] | 306 | return queue_var_show((blk_queue_nomerges(q) << 1) | |
| 307 | blk_queue_noxmerges(q), page); |
Alan D. Brunelle | ac9fafa | 2008-04-29 14:44:19 +0200 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static ssize_t queue_nomerges_store(struct request_queue *q, const char *page, |
| 311 | size_t count) |
| 312 | { |
| 313 | unsigned long nm; |
| 314 | ssize_t ret = queue_var_store(&nm, page, count); |
| 315 | |
Dave Reisner | b1f3b64 | 2012-09-08 11:55:45 -0400 | [diff] [blame] | 316 | if (ret < 0) |
| 317 | return ret; |
| 318 | |
Jens Axboe | bf0f970 | 2008-05-07 09:09:39 +0200 | [diff] [blame] | 319 | spin_lock_irq(q->queue_lock); |
Alan D. Brunelle | 488991e | 2010-01-29 09:04:08 +0100 | [diff] [blame] | 320 | queue_flag_clear(QUEUE_FLAG_NOMERGES, q); |
| 321 | queue_flag_clear(QUEUE_FLAG_NOXMERGES, q); |
| 322 | if (nm == 2) |
Jens Axboe | bf0f970 | 2008-05-07 09:09:39 +0200 | [diff] [blame] | 323 | queue_flag_set(QUEUE_FLAG_NOMERGES, q); |
Alan D. Brunelle | 488991e | 2010-01-29 09:04:08 +0100 | [diff] [blame] | 324 | else if (nm) |
| 325 | queue_flag_set(QUEUE_FLAG_NOXMERGES, q); |
Jens Axboe | bf0f970 | 2008-05-07 09:09:39 +0200 | [diff] [blame] | 326 | spin_unlock_irq(q->queue_lock); |
Bartlomiej Zolnierkiewicz | 1308835f | 2009-01-07 12:22:39 +0100 | [diff] [blame] | 327 | |
Alan D. Brunelle | ac9fafa | 2008-04-29 14:44:19 +0200 | [diff] [blame] | 328 | return ret; |
| 329 | } |
| 330 | |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 331 | static ssize_t queue_rq_affinity_show(struct request_queue *q, char *page) |
| 332 | { |
Xiaotian Feng | 9cb308c | 2009-07-17 15:26:26 +0800 | [diff] [blame] | 333 | bool set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags); |
Dan Williams | 5757a6d | 2011-07-23 20:44:25 +0200 | [diff] [blame] | 334 | bool force = test_bit(QUEUE_FLAG_SAME_FORCE, &q->queue_flags); |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 335 | |
Dan Williams | 5757a6d | 2011-07-23 20:44:25 +0200 | [diff] [blame] | 336 | return queue_var_show(set << force, page); |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static ssize_t |
| 340 | queue_rq_affinity_store(struct request_queue *q, const char *page, size_t count) |
| 341 | { |
| 342 | ssize_t ret = -EINVAL; |
Christoph Hellwig | 0a06ff0 | 2013-11-14 14:32:07 -0800 | [diff] [blame] | 343 | #ifdef CONFIG_SMP |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 344 | unsigned long val; |
| 345 | |
| 346 | ret = queue_var_store(&val, page, count); |
Dave Reisner | b1f3b64 | 2012-09-08 11:55:45 -0400 | [diff] [blame] | 347 | if (ret < 0) |
| 348 | return ret; |
| 349 | |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 350 | spin_lock_irq(q->queue_lock); |
Eric Seppanen | e8037d4 | 2011-08-23 21:25:12 +0200 | [diff] [blame] | 351 | if (val == 2) { |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 352 | queue_flag_set(QUEUE_FLAG_SAME_COMP, q); |
Eric Seppanen | e8037d4 | 2011-08-23 21:25:12 +0200 | [diff] [blame] | 353 | queue_flag_set(QUEUE_FLAG_SAME_FORCE, q); |
| 354 | } else if (val == 1) { |
| 355 | queue_flag_set(QUEUE_FLAG_SAME_COMP, q); |
| 356 | queue_flag_clear(QUEUE_FLAG_SAME_FORCE, q); |
| 357 | } else if (val == 0) { |
Dan Williams | 5757a6d | 2011-07-23 20:44:25 +0200 | [diff] [blame] | 358 | queue_flag_clear(QUEUE_FLAG_SAME_COMP, q); |
| 359 | queue_flag_clear(QUEUE_FLAG_SAME_FORCE, q); |
| 360 | } |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 361 | spin_unlock_irq(q->queue_lock); |
| 362 | #endif |
| 363 | return ret; |
| 364 | } |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 365 | |
Jens Axboe | 06426ad | 2016-11-14 13:01:59 -0700 | [diff] [blame] | 366 | static ssize_t queue_poll_delay_show(struct request_queue *q, char *page) |
| 367 | { |
Jens Axboe | 64f1c21 | 2016-11-14 13:03:03 -0700 | [diff] [blame] | 368 | int val; |
| 369 | |
| 370 | if (q->poll_nsec == -1) |
| 371 | val = -1; |
| 372 | else |
| 373 | val = q->poll_nsec / 1000; |
| 374 | |
| 375 | return sprintf(page, "%d\n", val); |
Jens Axboe | 06426ad | 2016-11-14 13:01:59 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page, |
| 379 | size_t count) |
| 380 | { |
Jens Axboe | 64f1c21 | 2016-11-14 13:03:03 -0700 | [diff] [blame] | 381 | int err, val; |
Jens Axboe | 06426ad | 2016-11-14 13:01:59 -0700 | [diff] [blame] | 382 | |
| 383 | if (!q->mq_ops || !q->mq_ops->poll) |
| 384 | return -EINVAL; |
| 385 | |
Jens Axboe | 64f1c21 | 2016-11-14 13:03:03 -0700 | [diff] [blame] | 386 | err = kstrtoint(page, 10, &val); |
| 387 | if (err < 0) |
| 388 | return err; |
Jens Axboe | 06426ad | 2016-11-14 13:01:59 -0700 | [diff] [blame] | 389 | |
Jens Axboe | 64f1c21 | 2016-11-14 13:03:03 -0700 | [diff] [blame] | 390 | if (val == -1) |
| 391 | q->poll_nsec = -1; |
| 392 | else |
| 393 | q->poll_nsec = val * 1000; |
| 394 | |
| 395 | return count; |
Jens Axboe | 06426ad | 2016-11-14 13:01:59 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Jens Axboe | 05229be | 2015-11-05 10:44:55 -0700 | [diff] [blame] | 398 | static ssize_t queue_poll_show(struct request_queue *q, char *page) |
| 399 | { |
| 400 | return queue_var_show(test_bit(QUEUE_FLAG_POLL, &q->queue_flags), page); |
| 401 | } |
| 402 | |
| 403 | static ssize_t queue_poll_store(struct request_queue *q, const char *page, |
| 404 | size_t count) |
| 405 | { |
| 406 | unsigned long poll_on; |
| 407 | ssize_t ret; |
| 408 | |
| 409 | if (!q->mq_ops || !q->mq_ops->poll) |
| 410 | return -EINVAL; |
| 411 | |
| 412 | ret = queue_var_store(&poll_on, page, count); |
| 413 | if (ret < 0) |
| 414 | return ret; |
| 415 | |
| 416 | spin_lock_irq(q->queue_lock); |
| 417 | if (poll_on) |
| 418 | queue_flag_set(QUEUE_FLAG_POLL, q); |
| 419 | else |
| 420 | queue_flag_clear(QUEUE_FLAG_POLL, q); |
| 421 | spin_unlock_irq(q->queue_lock); |
| 422 | |
| 423 | return ret; |
| 424 | } |
| 425 | |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 426 | static ssize_t queue_wb_lat_show(struct request_queue *q, char *page) |
| 427 | { |
| 428 | if (!q->rq_wb) |
| 429 | return -EINVAL; |
| 430 | |
| 431 | return sprintf(page, "%llu\n", div_u64(q->rq_wb->min_lat_nsec, 1000)); |
| 432 | } |
| 433 | |
| 434 | static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page, |
| 435 | size_t count) |
| 436 | { |
Jens Axboe | 80e091d | 2016-11-28 09:22:47 -0700 | [diff] [blame] | 437 | struct rq_wb *rwb; |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 438 | ssize_t ret; |
Jens Axboe | 80e091d | 2016-11-28 09:22:47 -0700 | [diff] [blame] | 439 | s64 val; |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 440 | |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 441 | ret = queue_var_store64(&val, page); |
| 442 | if (ret < 0) |
| 443 | return ret; |
Jens Axboe | d62118b | 2016-11-28 09:40:34 -0700 | [diff] [blame] | 444 | if (val < -1) |
| 445 | return -EINVAL; |
| 446 | |
| 447 | rwb = q->rq_wb; |
| 448 | if (!rwb) { |
| 449 | ret = wbt_init(q); |
| 450 | if (ret) |
| 451 | return ret; |
| 452 | |
| 453 | rwb = q->rq_wb; |
| 454 | if (!rwb) |
| 455 | return -EINVAL; |
| 456 | } |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 457 | |
Jens Axboe | 80e091d | 2016-11-28 09:22:47 -0700 | [diff] [blame] | 458 | if (val == -1) |
| 459 | rwb->min_lat_nsec = wbt_default_latency_nsec(q); |
| 460 | else if (val >= 0) |
| 461 | rwb->min_lat_nsec = val * 1000ULL; |
Jens Axboe | d62118b | 2016-11-28 09:40:34 -0700 | [diff] [blame] | 462 | |
| 463 | if (rwb->enable_state == WBT_STATE_ON_DEFAULT) |
| 464 | rwb->enable_state = WBT_STATE_ON_MANUAL; |
Jens Axboe | 80e091d | 2016-11-28 09:22:47 -0700 | [diff] [blame] | 465 | |
| 466 | wbt_update_limits(rwb); |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 467 | return count; |
| 468 | } |
| 469 | |
Jens Axboe | 93e9d8e | 2016-04-12 12:32:46 -0600 | [diff] [blame] | 470 | static ssize_t queue_wc_show(struct request_queue *q, char *page) |
| 471 | { |
| 472 | if (test_bit(QUEUE_FLAG_WC, &q->queue_flags)) |
| 473 | return sprintf(page, "write back\n"); |
| 474 | |
| 475 | return sprintf(page, "write through\n"); |
| 476 | } |
| 477 | |
| 478 | static ssize_t queue_wc_store(struct request_queue *q, const char *page, |
| 479 | size_t count) |
| 480 | { |
| 481 | int set = -1; |
| 482 | |
| 483 | if (!strncmp(page, "write back", 10)) |
| 484 | set = 1; |
| 485 | else if (!strncmp(page, "write through", 13) || |
| 486 | !strncmp(page, "none", 4)) |
| 487 | set = 0; |
| 488 | |
| 489 | if (set == -1) |
| 490 | return -EINVAL; |
| 491 | |
| 492 | spin_lock_irq(q->queue_lock); |
| 493 | if (set) |
| 494 | queue_flag_set(QUEUE_FLAG_WC, q); |
| 495 | else |
| 496 | queue_flag_clear(QUEUE_FLAG_WC, q); |
| 497 | spin_unlock_irq(q->queue_lock); |
| 498 | |
| 499 | return count; |
| 500 | } |
| 501 | |
Yigal Korman | ea6ca60 | 2016-06-23 17:05:51 -0400 | [diff] [blame] | 502 | static ssize_t queue_dax_show(struct request_queue *q, char *page) |
| 503 | { |
| 504 | return queue_var_show(blk_queue_dax(q), page); |
| 505 | } |
| 506 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 507 | static struct queue_sysfs_entry queue_requests_entry = { |
| 508 | .attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR }, |
| 509 | .show = queue_requests_show, |
| 510 | .store = queue_requests_store, |
| 511 | }; |
| 512 | |
| 513 | static struct queue_sysfs_entry queue_ra_entry = { |
| 514 | .attr = {.name = "read_ahead_kb", .mode = S_IRUGO | S_IWUSR }, |
| 515 | .show = queue_ra_show, |
| 516 | .store = queue_ra_store, |
| 517 | }; |
| 518 | |
| 519 | static struct queue_sysfs_entry queue_max_sectors_entry = { |
| 520 | .attr = {.name = "max_sectors_kb", .mode = S_IRUGO | S_IWUSR }, |
| 521 | .show = queue_max_sectors_show, |
| 522 | .store = queue_max_sectors_store, |
| 523 | }; |
| 524 | |
| 525 | static struct queue_sysfs_entry queue_max_hw_sectors_entry = { |
| 526 | .attr = {.name = "max_hw_sectors_kb", .mode = S_IRUGO }, |
| 527 | .show = queue_max_hw_sectors_show, |
| 528 | }; |
| 529 | |
Martin K. Petersen | c77a571 | 2010-03-10 00:48:33 -0500 | [diff] [blame] | 530 | static struct queue_sysfs_entry queue_max_segments_entry = { |
| 531 | .attr = {.name = "max_segments", .mode = S_IRUGO }, |
| 532 | .show = queue_max_segments_show, |
| 533 | }; |
| 534 | |
Christoph Hellwig | 1e73973 | 2017-02-08 14:46:49 +0100 | [diff] [blame] | 535 | static struct queue_sysfs_entry queue_max_discard_segments_entry = { |
| 536 | .attr = {.name = "max_discard_segments", .mode = S_IRUGO }, |
| 537 | .show = queue_max_discard_segments_show, |
| 538 | }; |
| 539 | |
Martin K. Petersen | 13f05c8 | 2010-09-10 20:50:10 +0200 | [diff] [blame] | 540 | static struct queue_sysfs_entry queue_max_integrity_segments_entry = { |
| 541 | .attr = {.name = "max_integrity_segments", .mode = S_IRUGO }, |
| 542 | .show = queue_max_integrity_segments_show, |
| 543 | }; |
| 544 | |
Martin K. Petersen | c77a571 | 2010-03-10 00:48:33 -0500 | [diff] [blame] | 545 | static struct queue_sysfs_entry queue_max_segment_size_entry = { |
| 546 | .attr = {.name = "max_segment_size", .mode = S_IRUGO }, |
| 547 | .show = queue_max_segment_size_show, |
| 548 | }; |
| 549 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 550 | static struct queue_sysfs_entry queue_iosched_entry = { |
| 551 | .attr = {.name = "scheduler", .mode = S_IRUGO | S_IWUSR }, |
| 552 | .show = elv_iosched_show, |
| 553 | .store = elv_iosched_store, |
| 554 | }; |
| 555 | |
Martin K. Petersen | e68b903 | 2008-01-29 19:14:08 +0100 | [diff] [blame] | 556 | static struct queue_sysfs_entry queue_hw_sector_size_entry = { |
| 557 | .attr = {.name = "hw_sector_size", .mode = S_IRUGO }, |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 558 | .show = queue_logical_block_size_show, |
| 559 | }; |
| 560 | |
| 561 | static struct queue_sysfs_entry queue_logical_block_size_entry = { |
| 562 | .attr = {.name = "logical_block_size", .mode = S_IRUGO }, |
| 563 | .show = queue_logical_block_size_show, |
Martin K. Petersen | e68b903 | 2008-01-29 19:14:08 +0100 | [diff] [blame] | 564 | }; |
| 565 | |
Martin K. Petersen | c72758f | 2009-05-22 17:17:53 -0400 | [diff] [blame] | 566 | static struct queue_sysfs_entry queue_physical_block_size_entry = { |
| 567 | .attr = {.name = "physical_block_size", .mode = S_IRUGO }, |
| 568 | .show = queue_physical_block_size_show, |
| 569 | }; |
| 570 | |
Hannes Reinecke | 87caf97 | 2016-10-18 15:40:30 +0900 | [diff] [blame] | 571 | static struct queue_sysfs_entry queue_chunk_sectors_entry = { |
| 572 | .attr = {.name = "chunk_sectors", .mode = S_IRUGO }, |
| 573 | .show = queue_chunk_sectors_show, |
| 574 | }; |
| 575 | |
Martin K. Petersen | c72758f | 2009-05-22 17:17:53 -0400 | [diff] [blame] | 576 | static struct queue_sysfs_entry queue_io_min_entry = { |
| 577 | .attr = {.name = "minimum_io_size", .mode = S_IRUGO }, |
| 578 | .show = queue_io_min_show, |
| 579 | }; |
| 580 | |
| 581 | static struct queue_sysfs_entry queue_io_opt_entry = { |
| 582 | .attr = {.name = "optimal_io_size", .mode = S_IRUGO }, |
| 583 | .show = queue_io_opt_show, |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 584 | }; |
| 585 | |
Martin K. Petersen | 86b3728 | 2009-11-10 11:50:21 +0100 | [diff] [blame] | 586 | static struct queue_sysfs_entry queue_discard_granularity_entry = { |
| 587 | .attr = {.name = "discard_granularity", .mode = S_IRUGO }, |
| 588 | .show = queue_discard_granularity_show, |
| 589 | }; |
| 590 | |
Jens Axboe | 0034af0 | 2015-07-16 09:14:26 -0600 | [diff] [blame] | 591 | static struct queue_sysfs_entry queue_discard_max_hw_entry = { |
| 592 | .attr = {.name = "discard_max_hw_bytes", .mode = S_IRUGO }, |
| 593 | .show = queue_discard_max_hw_show, |
| 594 | }; |
| 595 | |
Martin K. Petersen | 86b3728 | 2009-11-10 11:50:21 +0100 | [diff] [blame] | 596 | static struct queue_sysfs_entry queue_discard_max_entry = { |
Jens Axboe | 0034af0 | 2015-07-16 09:14:26 -0600 | [diff] [blame] | 597 | .attr = {.name = "discard_max_bytes", .mode = S_IRUGO | S_IWUSR }, |
Martin K. Petersen | 86b3728 | 2009-11-10 11:50:21 +0100 | [diff] [blame] | 598 | .show = queue_discard_max_show, |
Jens Axboe | 0034af0 | 2015-07-16 09:14:26 -0600 | [diff] [blame] | 599 | .store = queue_discard_max_store, |
Martin K. Petersen | 86b3728 | 2009-11-10 11:50:21 +0100 | [diff] [blame] | 600 | }; |
| 601 | |
Martin K. Petersen | 98262f2 | 2009-12-03 09:24:48 +0100 | [diff] [blame] | 602 | static struct queue_sysfs_entry queue_discard_zeroes_data_entry = { |
| 603 | .attr = {.name = "discard_zeroes_data", .mode = S_IRUGO }, |
| 604 | .show = queue_discard_zeroes_data_show, |
| 605 | }; |
| 606 | |
Martin K. Petersen | 4363ac7 | 2012-09-18 12:19:27 -0400 | [diff] [blame] | 607 | static struct queue_sysfs_entry queue_write_same_max_entry = { |
| 608 | .attr = {.name = "write_same_max_bytes", .mode = S_IRUGO }, |
| 609 | .show = queue_write_same_max_show, |
| 610 | }; |
| 611 | |
Chaitanya Kulkarni | a6f0788 | 2016-11-30 12:28:59 -0800 | [diff] [blame] | 612 | static struct queue_sysfs_entry queue_write_zeroes_max_entry = { |
| 613 | .attr = {.name = "write_zeroes_max_bytes", .mode = S_IRUGO }, |
| 614 | .show = queue_write_zeroes_max_show, |
| 615 | }; |
| 616 | |
Bartlomiej Zolnierkiewicz | 1308835f | 2009-01-07 12:22:39 +0100 | [diff] [blame] | 617 | static struct queue_sysfs_entry queue_nonrot_entry = { |
| 618 | .attr = {.name = "rotational", .mode = S_IRUGO | S_IWUSR }, |
Jens Axboe | 956bcb7 | 2010-08-07 18:13:50 +0200 | [diff] [blame] | 619 | .show = queue_show_nonrot, |
| 620 | .store = queue_store_nonrot, |
Bartlomiej Zolnierkiewicz | 1308835f | 2009-01-07 12:22:39 +0100 | [diff] [blame] | 621 | }; |
| 622 | |
Damien Le Moal | 797476b | 2016-10-18 15:40:29 +0900 | [diff] [blame] | 623 | static struct queue_sysfs_entry queue_zoned_entry = { |
| 624 | .attr = {.name = "zoned", .mode = S_IRUGO }, |
| 625 | .show = queue_zoned_show, |
| 626 | }; |
| 627 | |
Alan D. Brunelle | ac9fafa | 2008-04-29 14:44:19 +0200 | [diff] [blame] | 628 | static struct queue_sysfs_entry queue_nomerges_entry = { |
| 629 | .attr = {.name = "nomerges", .mode = S_IRUGO | S_IWUSR }, |
| 630 | .show = queue_nomerges_show, |
| 631 | .store = queue_nomerges_store, |
| 632 | }; |
| 633 | |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 634 | static struct queue_sysfs_entry queue_rq_affinity_entry = { |
| 635 | .attr = {.name = "rq_affinity", .mode = S_IRUGO | S_IWUSR }, |
| 636 | .show = queue_rq_affinity_show, |
| 637 | .store = queue_rq_affinity_store, |
| 638 | }; |
| 639 | |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 640 | static struct queue_sysfs_entry queue_iostats_entry = { |
| 641 | .attr = {.name = "iostats", .mode = S_IRUGO | S_IWUSR }, |
Jens Axboe | 956bcb7 | 2010-08-07 18:13:50 +0200 | [diff] [blame] | 642 | .show = queue_show_iostats, |
| 643 | .store = queue_store_iostats, |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 644 | }; |
| 645 | |
Jens Axboe | e2e1a14 | 2010-06-09 10:42:09 +0200 | [diff] [blame] | 646 | static struct queue_sysfs_entry queue_random_entry = { |
| 647 | .attr = {.name = "add_random", .mode = S_IRUGO | S_IWUSR }, |
Jens Axboe | 956bcb7 | 2010-08-07 18:13:50 +0200 | [diff] [blame] | 648 | .show = queue_show_random, |
| 649 | .store = queue_store_random, |
Jens Axboe | e2e1a14 | 2010-06-09 10:42:09 +0200 | [diff] [blame] | 650 | }; |
| 651 | |
Jens Axboe | 05229be | 2015-11-05 10:44:55 -0700 | [diff] [blame] | 652 | static struct queue_sysfs_entry queue_poll_entry = { |
| 653 | .attr = {.name = "io_poll", .mode = S_IRUGO | S_IWUSR }, |
| 654 | .show = queue_poll_show, |
| 655 | .store = queue_poll_store, |
| 656 | }; |
| 657 | |
Jens Axboe | 06426ad | 2016-11-14 13:01:59 -0700 | [diff] [blame] | 658 | static struct queue_sysfs_entry queue_poll_delay_entry = { |
| 659 | .attr = {.name = "io_poll_delay", .mode = S_IRUGO | S_IWUSR }, |
| 660 | .show = queue_poll_delay_show, |
| 661 | .store = queue_poll_delay_store, |
| 662 | }; |
| 663 | |
Jens Axboe | 93e9d8e | 2016-04-12 12:32:46 -0600 | [diff] [blame] | 664 | static struct queue_sysfs_entry queue_wc_entry = { |
| 665 | .attr = {.name = "write_cache", .mode = S_IRUGO | S_IWUSR }, |
| 666 | .show = queue_wc_show, |
| 667 | .store = queue_wc_store, |
| 668 | }; |
| 669 | |
Yigal Korman | ea6ca60 | 2016-06-23 17:05:51 -0400 | [diff] [blame] | 670 | static struct queue_sysfs_entry queue_dax_entry = { |
| 671 | .attr = {.name = "dax", .mode = S_IRUGO }, |
| 672 | .show = queue_dax_show, |
| 673 | }; |
| 674 | |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 675 | static struct queue_sysfs_entry queue_wb_lat_entry = { |
| 676 | .attr = {.name = "wbt_lat_usec", .mode = S_IRUGO | S_IWUSR }, |
| 677 | .show = queue_wb_lat_show, |
| 678 | .store = queue_wb_lat_store, |
| 679 | }; |
| 680 | |
Shaohua Li | 297e3d8 | 2017-03-27 10:51:37 -0700 | [diff] [blame] | 681 | #ifdef CONFIG_BLK_DEV_THROTTLING_LOW |
| 682 | static struct queue_sysfs_entry throtl_sample_time_entry = { |
| 683 | .attr = {.name = "throttle_sample_time", .mode = S_IRUGO | S_IWUSR }, |
| 684 | .show = blk_throtl_sample_time_show, |
| 685 | .store = blk_throtl_sample_time_store, |
| 686 | }; |
| 687 | #endif |
| 688 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 689 | static struct attribute *default_attrs[] = { |
| 690 | &queue_requests_entry.attr, |
| 691 | &queue_ra_entry.attr, |
| 692 | &queue_max_hw_sectors_entry.attr, |
| 693 | &queue_max_sectors_entry.attr, |
Martin K. Petersen | c77a571 | 2010-03-10 00:48:33 -0500 | [diff] [blame] | 694 | &queue_max_segments_entry.attr, |
Christoph Hellwig | 1e73973 | 2017-02-08 14:46:49 +0100 | [diff] [blame] | 695 | &queue_max_discard_segments_entry.attr, |
Martin K. Petersen | 13f05c8 | 2010-09-10 20:50:10 +0200 | [diff] [blame] | 696 | &queue_max_integrity_segments_entry.attr, |
Martin K. Petersen | c77a571 | 2010-03-10 00:48:33 -0500 | [diff] [blame] | 697 | &queue_max_segment_size_entry.attr, |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 698 | &queue_iosched_entry.attr, |
Martin K. Petersen | e68b903 | 2008-01-29 19:14:08 +0100 | [diff] [blame] | 699 | &queue_hw_sector_size_entry.attr, |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 700 | &queue_logical_block_size_entry.attr, |
Martin K. Petersen | c72758f | 2009-05-22 17:17:53 -0400 | [diff] [blame] | 701 | &queue_physical_block_size_entry.attr, |
Hannes Reinecke | 87caf97 | 2016-10-18 15:40:30 +0900 | [diff] [blame] | 702 | &queue_chunk_sectors_entry.attr, |
Martin K. Petersen | c72758f | 2009-05-22 17:17:53 -0400 | [diff] [blame] | 703 | &queue_io_min_entry.attr, |
| 704 | &queue_io_opt_entry.attr, |
Martin K. Petersen | 86b3728 | 2009-11-10 11:50:21 +0100 | [diff] [blame] | 705 | &queue_discard_granularity_entry.attr, |
| 706 | &queue_discard_max_entry.attr, |
Jens Axboe | 0034af0 | 2015-07-16 09:14:26 -0600 | [diff] [blame] | 707 | &queue_discard_max_hw_entry.attr, |
Martin K. Petersen | 98262f2 | 2009-12-03 09:24:48 +0100 | [diff] [blame] | 708 | &queue_discard_zeroes_data_entry.attr, |
Martin K. Petersen | 4363ac7 | 2012-09-18 12:19:27 -0400 | [diff] [blame] | 709 | &queue_write_same_max_entry.attr, |
Chaitanya Kulkarni | a6f0788 | 2016-11-30 12:28:59 -0800 | [diff] [blame] | 710 | &queue_write_zeroes_max_entry.attr, |
Bartlomiej Zolnierkiewicz | 1308835f | 2009-01-07 12:22:39 +0100 | [diff] [blame] | 711 | &queue_nonrot_entry.attr, |
Damien Le Moal | 797476b | 2016-10-18 15:40:29 +0900 | [diff] [blame] | 712 | &queue_zoned_entry.attr, |
Alan D. Brunelle | ac9fafa | 2008-04-29 14:44:19 +0200 | [diff] [blame] | 713 | &queue_nomerges_entry.attr, |
Jens Axboe | c7c22e4 | 2008-09-13 20:26:01 +0200 | [diff] [blame] | 714 | &queue_rq_affinity_entry.attr, |
Jens Axboe | bc58ba9 | 2009-01-23 10:54:44 +0100 | [diff] [blame] | 715 | &queue_iostats_entry.attr, |
Jens Axboe | e2e1a14 | 2010-06-09 10:42:09 +0200 | [diff] [blame] | 716 | &queue_random_entry.attr, |
Jens Axboe | 05229be | 2015-11-05 10:44:55 -0700 | [diff] [blame] | 717 | &queue_poll_entry.attr, |
Jens Axboe | 93e9d8e | 2016-04-12 12:32:46 -0600 | [diff] [blame] | 718 | &queue_wc_entry.attr, |
Yigal Korman | ea6ca60 | 2016-06-23 17:05:51 -0400 | [diff] [blame] | 719 | &queue_dax_entry.attr, |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 720 | &queue_wb_lat_entry.attr, |
Jens Axboe | 06426ad | 2016-11-14 13:01:59 -0700 | [diff] [blame] | 721 | &queue_poll_delay_entry.attr, |
Shaohua Li | 297e3d8 | 2017-03-27 10:51:37 -0700 | [diff] [blame] | 722 | #ifdef CONFIG_BLK_DEV_THROTTLING_LOW |
| 723 | &throtl_sample_time_entry.attr, |
| 724 | #endif |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 725 | NULL, |
| 726 | }; |
| 727 | |
| 728 | #define to_queue(atr) container_of((atr), struct queue_sysfs_entry, attr) |
| 729 | |
| 730 | static ssize_t |
| 731 | queue_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
| 732 | { |
| 733 | struct queue_sysfs_entry *entry = to_queue(attr); |
| 734 | struct request_queue *q = |
| 735 | container_of(kobj, struct request_queue, kobj); |
| 736 | ssize_t res; |
| 737 | |
| 738 | if (!entry->show) |
| 739 | return -EIO; |
| 740 | mutex_lock(&q->sysfs_lock); |
Bart Van Assche | 3f3299d | 2012-11-28 13:42:38 +0100 | [diff] [blame] | 741 | if (blk_queue_dying(q)) { |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 742 | mutex_unlock(&q->sysfs_lock); |
| 743 | return -ENOENT; |
| 744 | } |
| 745 | res = entry->show(q, page); |
| 746 | mutex_unlock(&q->sysfs_lock); |
| 747 | return res; |
| 748 | } |
| 749 | |
| 750 | static ssize_t |
| 751 | queue_attr_store(struct kobject *kobj, struct attribute *attr, |
| 752 | const char *page, size_t length) |
| 753 | { |
| 754 | struct queue_sysfs_entry *entry = to_queue(attr); |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 755 | struct request_queue *q; |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 756 | ssize_t res; |
| 757 | |
| 758 | if (!entry->store) |
| 759 | return -EIO; |
Jens Axboe | 6728cb0 | 2008-01-31 13:03:55 +0100 | [diff] [blame] | 760 | |
| 761 | q = container_of(kobj, struct request_queue, kobj); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 762 | mutex_lock(&q->sysfs_lock); |
Bart Van Assche | 3f3299d | 2012-11-28 13:42:38 +0100 | [diff] [blame] | 763 | if (blk_queue_dying(q)) { |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 764 | mutex_unlock(&q->sysfs_lock); |
| 765 | return -ENOENT; |
| 766 | } |
| 767 | res = entry->store(q, page, length); |
| 768 | mutex_unlock(&q->sysfs_lock); |
| 769 | return res; |
| 770 | } |
| 771 | |
Tejun Heo | 548bc8e | 2013-01-09 08:05:13 -0800 | [diff] [blame] | 772 | static void blk_free_queue_rcu(struct rcu_head *rcu_head) |
| 773 | { |
| 774 | struct request_queue *q = container_of(rcu_head, struct request_queue, |
| 775 | rcu_head); |
| 776 | kmem_cache_free(blk_requestq_cachep, q); |
| 777 | } |
| 778 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 779 | /** |
Andrew Morton | 499337b | 2011-09-21 10:01:22 +0200 | [diff] [blame] | 780 | * blk_release_queue: - release a &struct request_queue when it is no longer needed |
| 781 | * @kobj: the kobj belonging to the request queue to be released |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 782 | * |
| 783 | * Description: |
Andrew Morton | 499337b | 2011-09-21 10:01:22 +0200 | [diff] [blame] | 784 | * blk_release_queue is the pair to blk_init_queue() or |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 785 | * blk_queue_make_request(). It should be called when a request queue is |
| 786 | * being released; typically when a block device is being de-registered. |
| 787 | * Currently, its primary task it to free all the &struct request |
| 788 | * structures that were allocated to the queue and the queue itself. |
| 789 | * |
Bart Van Assche | 45a9c9d | 2014-12-09 16:57:48 +0100 | [diff] [blame] | 790 | * Note: |
| 791 | * The low level driver must have finished any outstanding requests first |
| 792 | * via blk_cleanup_queue(). |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 793 | **/ |
| 794 | static void blk_release_queue(struct kobject *kobj) |
| 795 | { |
| 796 | struct request_queue *q = |
| 797 | container_of(kobj, struct request_queue, kobj); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 798 | |
Omar Sandoval | 34dbad5 | 2017-03-21 08:56:08 -0700 | [diff] [blame] | 799 | if (test_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags)) |
| 800 | blk_stat_remove_callback(q, q->poll_cb); |
| 801 | blk_stat_free_callback(q->poll_cb); |
Jan Kara | d03f6cd | 2017-02-02 15:56:51 +0100 | [diff] [blame] | 802 | bdi_put(q->backing_dev_info); |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 803 | blkcg_exit_queue(q); |
| 804 | |
Tejun Heo | 7e5a879 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 805 | if (q->elevator) { |
Tejun Heo | 7e5a879 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 806 | ioc_clear_queue(q); |
Omar Sandoval | 54d5329 | 2017-04-07 08:52:27 -0600 | [diff] [blame] | 807 | elevator_exit(q, q->elevator); |
Tejun Heo | 7e5a879 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 808 | } |
Hannes Reinecke | 777eb1b | 2011-09-28 08:07:01 -0600 | [diff] [blame] | 809 | |
Omar Sandoval | 34dbad5 | 2017-03-21 08:56:08 -0700 | [diff] [blame] | 810 | blk_free_queue_stats(q->stats); |
| 811 | |
Bart Van Assche | b425e50 | 2017-05-31 14:43:45 -0700 | [diff] [blame] | 812 | blk_exit_rl(q, &q->root_rl); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 813 | |
| 814 | if (q->queue_tags) |
| 815 | __blk_queue_free_tags(q); |
| 816 | |
Christoph Hellwig | 6d247d7 | 2017-01-27 09:51:45 -0700 | [diff] [blame] | 817 | if (!q->mq_ops) { |
| 818 | if (q->exit_rq_fn) |
| 819 | q->exit_rq_fn(q, q->fq->flush_rq); |
Ming Lei | f70ced0 | 2014-09-25 23:23:47 +0800 | [diff] [blame] | 820 | blk_free_flush_queue(q->fq); |
Christoph Hellwig | 6d247d7 | 2017-01-27 09:51:45 -0700 | [diff] [blame] | 821 | } else { |
Ming Lei | e09aae7 | 2015-01-29 20:17:27 +0800 | [diff] [blame] | 822 | blk_mq_release(q); |
Christoph Hellwig | 6d247d7 | 2017-01-27 09:51:45 -0700 | [diff] [blame] | 823 | } |
Christoph Hellwig | 1874198 | 2014-02-10 09:29:00 -0700 | [diff] [blame] | 824 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 825 | blk_trace_shutdown(q); |
| 826 | |
Omar Sandoval | 62ebce1 | 2017-01-31 14:53:21 -0800 | [diff] [blame] | 827 | if (q->mq_ops) |
| 828 | blk_mq_debugfs_unregister(q); |
| 829 | |
Kent Overstreet | 54efd50 | 2015-04-23 22:37:18 -0700 | [diff] [blame] | 830 | if (q->bio_split) |
| 831 | bioset_free(q->bio_split); |
| 832 | |
Tejun Heo | a73f730 | 2011-12-14 00:33:37 +0100 | [diff] [blame] | 833 | ida_simple_remove(&blk_queue_ida, q->id); |
Tejun Heo | 548bc8e | 2013-01-09 08:05:13 -0800 | [diff] [blame] | 834 | call_rcu(&q->rcu_head, blk_free_queue_rcu); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 835 | } |
| 836 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 837 | static const struct sysfs_ops queue_sysfs_ops = { |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 838 | .show = queue_attr_show, |
| 839 | .store = queue_attr_store, |
| 840 | }; |
| 841 | |
| 842 | struct kobj_type blk_queue_ktype = { |
| 843 | .sysfs_ops = &queue_sysfs_ops, |
| 844 | .default_attrs = default_attrs, |
| 845 | .release = blk_release_queue, |
| 846 | }; |
| 847 | |
| 848 | int blk_register_queue(struct gendisk *disk) |
| 849 | { |
| 850 | int ret; |
Li Zefan | 1d54ad6 | 2009-04-14 14:00:05 +0800 | [diff] [blame] | 851 | struct device *dev = disk_to_dev(disk); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 852 | struct request_queue *q = disk->queue; |
| 853 | |
Akinobu Mita | fb19974 | 2008-04-21 09:51:06 +0200 | [diff] [blame] | 854 | if (WARN_ON(!q)) |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 855 | return -ENXIO; |
| 856 | |
Omar Sandoval | 334335d | 2017-03-28 16:12:15 -0700 | [diff] [blame] | 857 | WARN_ONCE(test_bit(QUEUE_FLAG_REGISTERED, &q->queue_flags), |
| 858 | "%s is registering an already registered queue\n", |
| 859 | kobject_name(&dev->kobj)); |
| 860 | queue_flag_set_unlocked(QUEUE_FLAG_REGISTERED, q); |
| 861 | |
Tejun Heo | 749fefe | 2012-09-20 14:08:52 -0700 | [diff] [blame] | 862 | /* |
Tejun Heo | 17497ac | 2014-09-24 13:31:50 -0400 | [diff] [blame] | 863 | * SCSI probing may synchronously create and destroy a lot of |
| 864 | * request_queues for non-existent devices. Shutting down a fully |
| 865 | * functional queue takes measureable wallclock time as RCU grace |
| 866 | * periods are involved. To avoid excessive latency in these |
| 867 | * cases, a request_queue starts out in a degraded mode which is |
| 868 | * faster to shut down and is made fully functional here as |
| 869 | * request_queues for non-existent devices never get registered. |
Tejun Heo | 749fefe | 2012-09-20 14:08:52 -0700 | [diff] [blame] | 870 | */ |
Alan Stern | df35c7c | 2014-09-09 11:50:58 -0400 | [diff] [blame] | 871 | if (!blk_queue_init_done(q)) { |
| 872 | queue_flag_set_unlocked(QUEUE_FLAG_INIT_DONE, q); |
Dan Williams | 3ef28e8 | 2015-10-21 13:20:12 -0400 | [diff] [blame] | 873 | percpu_ref_switch_to_percpu(&q->q_usage_counter); |
Alan Stern | df35c7c | 2014-09-09 11:50:58 -0400 | [diff] [blame] | 874 | blk_queue_bypass_end(q); |
| 875 | } |
Tejun Heo | 749fefe | 2012-09-20 14:08:52 -0700 | [diff] [blame] | 876 | |
Li Zefan | 1d54ad6 | 2009-04-14 14:00:05 +0800 | [diff] [blame] | 877 | ret = blk_trace_init_sysfs(dev); |
| 878 | if (ret) |
| 879 | return ret; |
| 880 | |
Tahsin Erdogan | b410aff | 2017-02-14 19:27:38 -0800 | [diff] [blame] | 881 | /* Prevent changes through sysfs until registration is completed. */ |
| 882 | mutex_lock(&q->sysfs_lock); |
| 883 | |
Linus Torvalds | c905959 | 2009-06-11 10:52:27 -0700 | [diff] [blame] | 884 | ret = kobject_add(&q->kobj, kobject_get(&dev->kobj), "%s", "queue"); |
Liu Yuan | ed5302d | 2011-04-19 13:47:58 +0200 | [diff] [blame] | 885 | if (ret < 0) { |
| 886 | blk_trace_remove_sysfs(dev); |
Tahsin Erdogan | b410aff | 2017-02-14 19:27:38 -0800 | [diff] [blame] | 887 | goto unlock; |
Liu Yuan | ed5302d | 2011-04-19 13:47:58 +0200 | [diff] [blame] | 888 | } |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 889 | |
Bart Van Assche | a8ecdd7 | 2017-05-25 16:38:06 -0700 | [diff] [blame] | 890 | if (q->mq_ops) { |
Bart Van Assche | 2d0364c | 2017-04-26 13:47:48 -0700 | [diff] [blame] | 891 | __blk_mq_register_dev(dev, q); |
Bart Van Assche | a8ecdd7 | 2017-05-25 16:38:06 -0700 | [diff] [blame] | 892 | blk_mq_debugfs_register(q); |
| 893 | } |
Omar Sandoval | 9c1051a | 2017-05-04 08:17:21 -0600 | [diff] [blame] | 894 | |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 895 | kobject_uevent(&q->kobj, KOBJ_ADD); |
| 896 | |
Jan Kara | 8330cdb | 2017-04-19 11:33:27 +0200 | [diff] [blame] | 897 | wbt_enable_default(q); |
Jens Axboe | 87760e5 | 2016-11-09 12:38:14 -0700 | [diff] [blame] | 898 | |
Shaohua Li | d61fcfa | 2017-03-27 10:51:38 -0700 | [diff] [blame] | 899 | blk_throtl_register_queue(q); |
| 900 | |
Omar Sandoval | 80c6b15 | 2017-02-06 12:52:24 -0800 | [diff] [blame] | 901 | if (q->request_fn || (q->mq_ops && q->elevator)) { |
| 902 | ret = elv_register_queue(q); |
| 903 | if (ret) { |
| 904 | kobject_uevent(&q->kobj, KOBJ_REMOVE); |
| 905 | kobject_del(&q->kobj); |
| 906 | blk_trace_remove_sysfs(dev); |
| 907 | kobject_put(&dev->kobj); |
Tahsin Erdogan | b410aff | 2017-02-14 19:27:38 -0800 | [diff] [blame] | 908 | goto unlock; |
Omar Sandoval | 80c6b15 | 2017-02-06 12:52:24 -0800 | [diff] [blame] | 909 | } |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 910 | } |
Tahsin Erdogan | b410aff | 2017-02-14 19:27:38 -0800 | [diff] [blame] | 911 | ret = 0; |
| 912 | unlock: |
| 913 | mutex_unlock(&q->sysfs_lock); |
| 914 | return ret; |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | void blk_unregister_queue(struct gendisk *disk) |
| 918 | { |
| 919 | struct request_queue *q = disk->queue; |
| 920 | |
Akinobu Mita | fb19974 | 2008-04-21 09:51:06 +0200 | [diff] [blame] | 921 | if (WARN_ON(!q)) |
| 922 | return; |
| 923 | |
Omar Sandoval | 334335d | 2017-03-28 16:12:15 -0700 | [diff] [blame] | 924 | queue_flag_clear_unlocked(QUEUE_FLAG_REGISTERED, q); |
| 925 | |
Omar Sandoval | 02ba889 | 2017-03-28 16:12:17 -0700 | [diff] [blame] | 926 | wbt_exit(q); |
| 927 | |
| 928 | |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 929 | if (q->mq_ops) |
Matias Bjørling | b21d5b3 | 2016-09-16 14:25:06 +0200 | [diff] [blame] | 930 | blk_mq_unregister_dev(disk_to_dev(disk), q); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 931 | |
Omar Sandoval | 80c6b15 | 2017-02-06 12:52:24 -0800 | [diff] [blame] | 932 | if (q->request_fn || (q->mq_ops && q->elevator)) |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 933 | elv_unregister_queue(q); |
| 934 | |
Zdenek Kabelac | 48c0d4d | 2009-09-25 06:19:26 +0200 | [diff] [blame] | 935 | kobject_uevent(&q->kobj, KOBJ_REMOVE); |
| 936 | kobject_del(&q->kobj); |
| 937 | blk_trace_remove_sysfs(disk_to_dev(disk)); |
| 938 | kobject_put(&disk_to_dev(disk)->kobj); |
Jens Axboe | 8324aa9 | 2008-01-29 14:51:59 +0100 | [diff] [blame] | 939 | } |