]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX_BLKDEV_H |
3 | #define _LINUX_BLKDEV_H | |
4 | ||
85fd0bc9 | 5 | #include <linux/sched.h> |
e6017571 | 6 | #include <linux/sched/clock.h> |
1da177e4 LT |
7 | #include <linux/major.h> |
8 | #include <linux/genhd.h> | |
9 | #include <linux/list.h> | |
320ae51f | 10 | #include <linux/llist.h> |
b296a6d5 | 11 | #include <linux/minmax.h> |
1da177e4 LT |
12 | #include <linux/timer.h> |
13 | #include <linux/workqueue.h> | |
66114cad | 14 | #include <linux/backing-dev-defs.h> |
1da177e4 LT |
15 | #include <linux/wait.h> |
16 | #include <linux/mempool.h> | |
34c0fd54 | 17 | #include <linux/pfn.h> |
1da177e4 | 18 | #include <linux/bio.h> |
1da177e4 | 19 | #include <linux/stringify.h> |
3e6053d7 | 20 | #include <linux/gfp.h> |
d351af01 | 21 | #include <linux/bsg.h> |
c7c22e4d | 22 | #include <linux/smp.h> |
548bc8e1 | 23 | #include <linux/rcupdate.h> |
add703fd | 24 | #include <linux/percpu-refcount.h> |
84be456f | 25 | #include <linux/scatterlist.h> |
6a0cb1bc | 26 | #include <linux/blkzoned.h> |
db04e18d | 27 | #include <linux/pm.h> |
1da177e4 | 28 | |
de477254 | 29 | struct module; |
21b2f0c8 CH |
30 | struct scsi_ioctl_command; |
31 | ||
1da177e4 | 32 | struct request_queue; |
1da177e4 | 33 | struct elevator_queue; |
2056a782 | 34 | struct blk_trace; |
3d6392cf JA |
35 | struct request; |
36 | struct sg_io_hdr; | |
aa387cc8 | 37 | struct bsg_job; |
3c798398 | 38 | struct blkcg_gq; |
7c94e1c1 | 39 | struct blk_flush_queue; |
bbd3e064 | 40 | struct pr_ops; |
a7905043 | 41 | struct rq_qos; |
34dbad5d OS |
42 | struct blk_queue_stats; |
43 | struct blk_stat_callback; | |
1b262839 | 44 | struct blk_keyslot_manager; |
1da177e4 LT |
45 | |
46 | #define BLKDEV_MIN_RQ 4 | |
47 | #define BLKDEV_MAX_RQ 128 /* Default maximum */ | |
48 | ||
096392e0 | 49 | /* Must be consistent with blk_mq_poll_stats_bkt() */ |
0206319f SB |
50 | #define BLK_MQ_POLL_STATS_BKTS 16 |
51 | ||
29ece8b4 YY |
52 | /* Doing classic polling */ |
53 | #define BLK_MQ_POLL_CLASSIC -1 | |
54 | ||
8bd435b3 TH |
55 | /* |
56 | * Maximum number of blkcg policies allowed to be registered concurrently. | |
57 | * Defined here to simplify include dependency. | |
58 | */ | |
01c5f85a | 59 | #define BLKCG_MAX_POLS 5 |
8bd435b3 | 60 | |
2a842aca | 61 | typedef void (rq_end_io_fn)(struct request *, blk_status_t); |
1da177e4 | 62 | |
e8064021 CH |
63 | /* |
64 | * request flags */ | |
65 | typedef __u32 __bitwise req_flags_t; | |
66 | ||
e8064021 CH |
67 | /* drive already may have started this one */ |
68 | #define RQF_STARTED ((__force req_flags_t)(1 << 1)) | |
e8064021 CH |
69 | /* may not be passed by ioscheduler */ |
70 | #define RQF_SOFTBARRIER ((__force req_flags_t)(1 << 3)) | |
71 | /* request for flush sequence */ | |
72 | #define RQF_FLUSH_SEQ ((__force req_flags_t)(1 << 4)) | |
73 | /* merge of different types, fail separately */ | |
74 | #define RQF_MIXED_MERGE ((__force req_flags_t)(1 << 5)) | |
75 | /* track inflight for MQ */ | |
76 | #define RQF_MQ_INFLIGHT ((__force req_flags_t)(1 << 6)) | |
77 | /* don't call prep for this one */ | |
78 | #define RQF_DONTPREP ((__force req_flags_t)(1 << 7)) | |
e8064021 CH |
79 | /* vaguely specified driver internal error. Ignored by the block layer */ |
80 | #define RQF_FAILED ((__force req_flags_t)(1 << 10)) | |
81 | /* don't warn about errors */ | |
82 | #define RQF_QUIET ((__force req_flags_t)(1 << 11)) | |
83 | /* elevator private data attached */ | |
84 | #define RQF_ELVPRIV ((__force req_flags_t)(1 << 12)) | |
4822e902 | 85 | /* account into disk and partition IO statistics */ |
e8064021 | 86 | #define RQF_IO_STAT ((__force req_flags_t)(1 << 13)) |
e8064021 CH |
87 | /* runtime pm request */ |
88 | #define RQF_PM ((__force req_flags_t)(1 << 15)) | |
89 | /* on IO scheduler merge hash */ | |
90 | #define RQF_HASHED ((__force req_flags_t)(1 << 16)) | |
4822e902 | 91 | /* track IO completion time */ |
cf43e6be | 92 | #define RQF_STATS ((__force req_flags_t)(1 << 17)) |
f9d03f96 CH |
93 | /* Look at ->special_vec for the actual data payload instead of the |
94 | bio chain. */ | |
95 | #define RQF_SPECIAL_PAYLOAD ((__force req_flags_t)(1 << 18)) | |
6cc77e9c CH |
96 | /* The per-zone write lock is held for this request */ |
97 | #define RQF_ZONE_WRITE_LOCKED ((__force req_flags_t)(1 << 19)) | |
76a86f9d | 98 | /* already slept for hybrid poll */ |
12f5b931 | 99 | #define RQF_MQ_POLL_SLEPT ((__force req_flags_t)(1 << 20)) |
da661267 CH |
100 | /* ->timeout has been called, don't expire again */ |
101 | #define RQF_TIMED_OUT ((__force req_flags_t)(1 << 21)) | |
e8064021 CH |
102 | |
103 | /* flags that prevent us from merging requests: */ | |
104 | #define RQF_NOMERGE_FLAGS \ | |
f9d03f96 | 105 | (RQF_STARTED | RQF_SOFTBARRIER | RQF_FLUSH_SEQ | RQF_SPECIAL_PAYLOAD) |
e8064021 | 106 | |
12f5b931 KB |
107 | /* |
108 | * Request state for blk-mq. | |
109 | */ | |
110 | enum mq_rq_state { | |
111 | MQ_RQ_IDLE = 0, | |
112 | MQ_RQ_IN_FLIGHT = 1, | |
113 | MQ_RQ_COMPLETE = 2, | |
114 | }; | |
115 | ||
1da177e4 | 116 | /* |
af76e555 CH |
117 | * Try to put the fields that are referenced together in the same cacheline. |
118 | * | |
119 | * If you modify this structure, make sure to update blk_rq_init() and | |
120 | * especially blk_mq_rq_ctx_init() to take care of the added fields. | |
1da177e4 LT |
121 | */ |
122 | struct request { | |
165125e1 | 123 | struct request_queue *q; |
320ae51f | 124 | struct blk_mq_ctx *mq_ctx; |
ea4f995e | 125 | struct blk_mq_hw_ctx *mq_hctx; |
e6a1c874 | 126 | |
ef295ecf | 127 | unsigned int cmd_flags; /* op and common flags */ |
e8064021 | 128 | req_flags_t rq_flags; |
d486f1f2 | 129 | |
2f578aaf | 130 | int tag; |
d486f1f2 JA |
131 | int internal_tag; |
132 | ||
a2dec7b3 | 133 | /* the following two fields are internal, NEVER access directly */ |
a2dec7b3 | 134 | unsigned int __data_len; /* total data len */ |
181fdde3 | 135 | sector_t __sector; /* sector cursor */ |
1da177e4 LT |
136 | |
137 | struct bio *bio; | |
138 | struct bio *biotail; | |
139 | ||
7c3fb70f JA |
140 | struct list_head queuelist; |
141 | ||
360f92c2 JA |
142 | /* |
143 | * The hash is used inside the scheduler, and killed once the | |
144 | * request reaches the dispatch list. The ipi_list is only used | |
145 | * to queue the request for softirq completion, which is long | |
146 | * after the request has been unhashed (and even removed from | |
147 | * the dispatch list). | |
148 | */ | |
149 | union { | |
150 | struct hlist_node hash; /* merge hash */ | |
f9ab4918 | 151 | struct llist_node ipi_list; |
360f92c2 JA |
152 | }; |
153 | ||
e6a1c874 JA |
154 | /* |
155 | * The rb_node is only used inside the io scheduler, requests | |
156 | * are pruned when moved to the dispatch queue. So let the | |
c186794d | 157 | * completion_data share space with the rb_node. |
e6a1c874 JA |
158 | */ |
159 | union { | |
160 | struct rb_node rb_node; /* sort/lookup */ | |
f9d03f96 | 161 | struct bio_vec special_vec; |
c186794d | 162 | void *completion_data; |
e26738e0 | 163 | int error_count; /* for legacy drivers, don't use */ |
e6a1c874 | 164 | }; |
9817064b | 165 | |
ff7d145f | 166 | /* |
7f1dc8a2 | 167 | * Three pointers are available for the IO schedulers, if they need |
c186794d MS |
168 | * more they have to dynamically allocate it. Flush requests are |
169 | * never put on the IO scheduler. So let the flush fields share | |
a612fddf | 170 | * space with the elevator data. |
ff7d145f | 171 | */ |
c186794d | 172 | union { |
a612fddf TH |
173 | struct { |
174 | struct io_cq *icq; | |
175 | void *priv[2]; | |
176 | } elv; | |
177 | ||
c186794d MS |
178 | struct { |
179 | unsigned int seq; | |
180 | struct list_head list; | |
4853abaa | 181 | rq_end_io_fn *saved_end_io; |
c186794d MS |
182 | } flush; |
183 | }; | |
ff7d145f | 184 | |
8f34ee75 | 185 | struct gendisk *rq_disk; |
8446fe92 | 186 | struct block_device *part; |
6f816b4b TH |
187 | #ifdef CONFIG_BLK_RQ_ALLOC_TIME |
188 | /* Time that the first bio started allocating this request. */ | |
189 | u64 alloc_time_ns; | |
190 | #endif | |
191 | /* Time that this request was allocated for this IO. */ | |
522a7775 | 192 | u64 start_time_ns; |
544ccc8d OS |
193 | /* Time that I/O was submitted to the device. */ |
194 | u64 io_start_time_ns; | |
195 | ||
196 | #ifdef CONFIG_BLK_WBT | |
197 | unsigned short wbt_flags; | |
198 | #endif | |
3d244306 HT |
199 | /* |
200 | * rq sectors used for blk stats. It has the same value | |
201 | * with blk_rq_sectors(rq), except that it never be zeroed | |
202 | * by completion. | |
203 | */ | |
204 | unsigned short stats_sectors; | |
544ccc8d OS |
205 | |
206 | /* | |
207 | * Number of scatter-gather DMA addr+len pairs after | |
1da177e4 LT |
208 | * physical address coalescing is performed. |
209 | */ | |
210 | unsigned short nr_phys_segments; | |
7c3fb70f | 211 | |
13f05c8d MP |
212 | #if defined(CONFIG_BLK_DEV_INTEGRITY) |
213 | unsigned short nr_integrity_segments; | |
214 | #endif | |
1da177e4 | 215 | |
a892c8d5 ST |
216 | #ifdef CONFIG_BLK_INLINE_ENCRYPTION |
217 | struct bio_crypt_ctx *crypt_ctx; | |
218 | struct blk_ksm_keyslot *crypt_keyslot; | |
219 | #endif | |
220 | ||
7c3fb70f | 221 | unsigned short write_hint; |
8f34ee75 JA |
222 | unsigned short ioprio; |
223 | ||
12f5b931 KB |
224 | enum mq_rq_state state; |
225 | refcount_t ref; | |
1d9bd516 | 226 | |
0b7576d8 | 227 | unsigned int timeout; |
079076b3 | 228 | unsigned long deadline; |
cb6934f8 | 229 | |
7c3fb70f | 230 | union { |
0a4b6e2f | 231 | struct __call_single_data csd; |
7c3fb70f JA |
232 | u64 fifo_time; |
233 | }; | |
234 | ||
1da177e4 | 235 | /* |
c00895ab | 236 | * completion callback. |
1da177e4 LT |
237 | */ |
238 | rq_end_io_fn *end_io; | |
239 | void *end_io_data; | |
240 | }; | |
241 | ||
14cb0dc6 ML |
242 | static inline bool blk_op_is_scsi(unsigned int op) |
243 | { | |
244 | return op == REQ_OP_SCSI_IN || op == REQ_OP_SCSI_OUT; | |
245 | } | |
246 | ||
247 | static inline bool blk_op_is_private(unsigned int op) | |
248 | { | |
249 | return op == REQ_OP_DRV_IN || op == REQ_OP_DRV_OUT; | |
250 | } | |
251 | ||
aebf526b CH |
252 | static inline bool blk_rq_is_scsi(struct request *rq) |
253 | { | |
14cb0dc6 | 254 | return blk_op_is_scsi(req_op(rq)); |
aebf526b CH |
255 | } |
256 | ||
257 | static inline bool blk_rq_is_private(struct request *rq) | |
258 | { | |
14cb0dc6 | 259 | return blk_op_is_private(req_op(rq)); |
aebf526b CH |
260 | } |
261 | ||
57292b58 CH |
262 | static inline bool blk_rq_is_passthrough(struct request *rq) |
263 | { | |
aebf526b | 264 | return blk_rq_is_scsi(rq) || blk_rq_is_private(rq); |
57292b58 CH |
265 | } |
266 | ||
14cb0dc6 ML |
267 | static inline bool bio_is_passthrough(struct bio *bio) |
268 | { | |
269 | unsigned op = bio_op(bio); | |
270 | ||
271 | return blk_op_is_scsi(op) || blk_op_is_private(op); | |
272 | } | |
273 | ||
8d663f34 LF |
274 | static inline bool blk_op_is_passthrough(unsigned int op) |
275 | { | |
276 | return (blk_op_is_scsi(op & REQ_OP_MASK) || | |
277 | blk_op_is_private(op & REQ_OP_MASK)); | |
278 | } | |
279 | ||
766ca442 FLVC |
280 | static inline unsigned short req_get_ioprio(struct request *req) |
281 | { | |
282 | return req->ioprio; | |
283 | } | |
284 | ||
1da177e4 LT |
285 | #include <linux/elevator.h> |
286 | ||
320ae51f JA |
287 | struct blk_queue_ctx; |
288 | ||
1da177e4 | 289 | struct bio_vec; |
1da177e4 | 290 | |
242f9dcb | 291 | enum blk_eh_timer_return { |
88b0cfad CH |
292 | BLK_EH_DONE, /* drivers has completed the command */ |
293 | BLK_EH_RESET_TIMER, /* reset timer and try again */ | |
242f9dcb JA |
294 | }; |
295 | ||
1da177e4 LT |
296 | enum blk_queue_state { |
297 | Queue_down, | |
298 | Queue_up, | |
299 | }; | |
300 | ||
ee1b6f7a SL |
301 | #define BLK_TAG_ALLOC_FIFO 0 /* allocate starting from 0 */ |
302 | #define BLK_TAG_ALLOC_RR 1 /* allocate starting from last allocated tag */ | |
1da177e4 | 303 | |
abf54393 FT |
304 | #define BLK_SCSI_MAX_CMDS (256) |
305 | #define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8)) | |
306 | ||
797476b8 DLM |
307 | /* |
308 | * Zoned block device models (zoned limit). | |
3093a479 CH |
309 | * |
310 | * Note: This needs to be ordered from the least to the most severe | |
311 | * restrictions for the inheritance in blk_stack_limits() to work. | |
797476b8 DLM |
312 | */ |
313 | enum blk_zoned_model { | |
3093a479 CH |
314 | BLK_ZONED_NONE = 0, /* Regular block device */ |
315 | BLK_ZONED_HA, /* Host-aware zoned block device */ | |
316 | BLK_ZONED_HM, /* Host-managed zoned block device */ | |
797476b8 DLM |
317 | }; |
318 | ||
9bb33f24 CH |
319 | /* |
320 | * BLK_BOUNCE_NONE: never bounce (default) | |
321 | * BLK_BOUNCE_HIGH: bounce all highmem pages | |
322 | */ | |
323 | enum blk_bounce { | |
324 | BLK_BOUNCE_NONE, | |
325 | BLK_BOUNCE_HIGH, | |
326 | }; | |
327 | ||
025146e1 | 328 | struct queue_limits { |
9bb33f24 | 329 | enum blk_bounce bounce; |
025146e1 | 330 | unsigned long seg_boundary_mask; |
03100aad | 331 | unsigned long virt_boundary_mask; |
025146e1 MP |
332 | |
333 | unsigned int max_hw_sectors; | |
ca369d51 | 334 | unsigned int max_dev_sectors; |
762380ad | 335 | unsigned int chunk_sectors; |
025146e1 MP |
336 | unsigned int max_sectors; |
337 | unsigned int max_segment_size; | |
c72758f3 | 338 | unsigned int physical_block_size; |
ad6bf88a | 339 | unsigned int logical_block_size; |
c72758f3 MP |
340 | unsigned int alignment_offset; |
341 | unsigned int io_min; | |
342 | unsigned int io_opt; | |
67efc925 | 343 | unsigned int max_discard_sectors; |
0034af03 | 344 | unsigned int max_hw_discard_sectors; |
4363ac7c | 345 | unsigned int max_write_same_sectors; |
a6f0788e | 346 | unsigned int max_write_zeroes_sectors; |
0512a75b | 347 | unsigned int max_zone_append_sectors; |
86b37281 MP |
348 | unsigned int discard_granularity; |
349 | unsigned int discard_alignment; | |
a805a4fa | 350 | unsigned int zone_write_granularity; |
025146e1 | 351 | |
8a78362c | 352 | unsigned short max_segments; |
13f05c8d | 353 | unsigned short max_integrity_segments; |
1e739730 | 354 | unsigned short max_discard_segments; |
025146e1 | 355 | |
c72758f3 | 356 | unsigned char misaligned; |
86b37281 | 357 | unsigned char discard_misaligned; |
c78afc62 | 358 | unsigned char raid_partial_stripes_expensive; |
797476b8 | 359 | enum blk_zoned_model zoned; |
025146e1 MP |
360 | }; |
361 | ||
d4100351 CH |
362 | typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx, |
363 | void *data); | |
364 | ||
27ba3e8f DLM |
365 | void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model); |
366 | ||
6a0cb1bc HR |
367 | #ifdef CONFIG_BLK_DEV_ZONED |
368 | ||
d4100351 CH |
369 | #define BLK_ALL_ZONES ((unsigned int)-1) |
370 | int blkdev_report_zones(struct block_device *bdev, sector_t sector, | |
371 | unsigned int nr_zones, report_zones_cb cb, void *data); | |
9b38bb4b | 372 | unsigned int blkdev_nr_zones(struct gendisk *disk); |
6c1b1da5 AJ |
373 | extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op, |
374 | sector_t sectors, sector_t nr_sectors, | |
375 | gfp_t gfp_mask); | |
e732671a DLM |
376 | int blk_revalidate_disk_zones(struct gendisk *disk, |
377 | void (*update_driver_data)(struct gendisk *disk)); | |
6a0cb1bc | 378 | |
3ed05a98 ST |
379 | extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, |
380 | unsigned int cmd, unsigned long arg); | |
e876df1f AJ |
381 | extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, |
382 | unsigned int cmd, unsigned long arg); | |
3ed05a98 ST |
383 | |
384 | #else /* CONFIG_BLK_DEV_ZONED */ | |
385 | ||
9b38bb4b | 386 | static inline unsigned int blkdev_nr_zones(struct gendisk *disk) |
a91e1380 DLM |
387 | { |
388 | return 0; | |
389 | } | |
bf505456 | 390 | |
3ed05a98 ST |
391 | static inline int blkdev_report_zones_ioctl(struct block_device *bdev, |
392 | fmode_t mode, unsigned int cmd, | |
393 | unsigned long arg) | |
394 | { | |
395 | return -ENOTTY; | |
396 | } | |
397 | ||
e876df1f AJ |
398 | static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev, |
399 | fmode_t mode, unsigned int cmd, | |
400 | unsigned long arg) | |
3ed05a98 ST |
401 | { |
402 | return -ENOTTY; | |
403 | } | |
404 | ||
6a0cb1bc HR |
405 | #endif /* CONFIG_BLK_DEV_ZONED */ |
406 | ||
d7b76301 | 407 | struct request_queue { |
1da177e4 | 408 | struct request *last_merge; |
b374d18a | 409 | struct elevator_queue *elevator; |
1da177e4 | 410 | |
0549e87c ML |
411 | struct percpu_ref q_usage_counter; |
412 | ||
34dbad5d | 413 | struct blk_queue_stats *stats; |
a7905043 | 414 | struct rq_qos *rq_qos; |
87760e5e | 415 | |
f8a5b122 | 416 | const struct blk_mq_ops *mq_ops; |
320ae51f | 417 | |
320ae51f | 418 | /* sw queues */ |
e6cdb092 | 419 | struct blk_mq_ctx __percpu *queue_ctx; |
320ae51f | 420 | |
d278d4a8 JA |
421 | unsigned int queue_depth; |
422 | ||
320ae51f JA |
423 | /* hw dispatch queues */ |
424 | struct blk_mq_hw_ctx **queue_hw_ctx; | |
425 | unsigned int nr_hw_queues; | |
426 | ||
dc3b17cc | 427 | struct backing_dev_info *backing_dev_info; |
1da177e4 LT |
428 | |
429 | /* | |
430 | * The queue owner gets to use this for whatever they like. | |
431 | * ll_rw_blk doesn't touch it. | |
432 | */ | |
433 | void *queuedata; | |
434 | ||
1da177e4 | 435 | /* |
d7b76301 | 436 | * various queue flags, see QUEUE_* below |
1da177e4 | 437 | */ |
d7b76301 | 438 | unsigned long queue_flags; |
cd84a62e BVA |
439 | /* |
440 | * Number of contexts that have called blk_set_pm_only(). If this | |
a4d34da7 | 441 | * counter is above zero then only RQF_PM requests are processed. |
cd84a62e BVA |
442 | */ |
443 | atomic_t pm_only; | |
1da177e4 | 444 | |
a73f730d TH |
445 | /* |
446 | * ida allocated id for this queue. Used to index queues from | |
447 | * ioctx. | |
448 | */ | |
449 | int id; | |
450 | ||
0d945c1f | 451 | spinlock_t queue_lock; |
1da177e4 LT |
452 | |
453 | /* | |
454 | * queue kobject | |
455 | */ | |
456 | struct kobject kobj; | |
457 | ||
320ae51f JA |
458 | /* |
459 | * mq queue kobject | |
460 | */ | |
1db4909e | 461 | struct kobject *mq_kobj; |
320ae51f | 462 | |
ac6fc48c DW |
463 | #ifdef CONFIG_BLK_DEV_INTEGRITY |
464 | struct blk_integrity integrity; | |
465 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ | |
466 | ||
47fafbc7 | 467 | #ifdef CONFIG_PM |
6c954667 | 468 | struct device *dev; |
db04e18d | 469 | enum rpm_status rpm_status; |
6c954667 LM |
470 | #endif |
471 | ||
1da177e4 LT |
472 | /* |
473 | * queue settings | |
474 | */ | |
475 | unsigned long nr_requests; /* Max # of requests */ | |
1da177e4 | 476 | |
e3790c7d | 477 | unsigned int dma_pad_mask; |
1da177e4 LT |
478 | unsigned int dma_alignment; |
479 | ||
1b262839 ST |
480 | #ifdef CONFIG_BLK_INLINE_ENCRYPTION |
481 | /* Inline crypto capabilities */ | |
482 | struct blk_keyslot_manager *ksm; | |
483 | #endif | |
484 | ||
242f9dcb | 485 | unsigned int rq_timeout; |
64f1c21e | 486 | int poll_nsec; |
34dbad5d OS |
487 | |
488 | struct blk_stat_callback *poll_cb; | |
0206319f | 489 | struct blk_rq_stat poll_stat[BLK_MQ_POLL_STATS_BKTS]; |
34dbad5d | 490 | |
242f9dcb | 491 | struct timer_list timeout; |
287922eb | 492 | struct work_struct timeout_work; |
242f9dcb | 493 | |
bccf5e26 JG |
494 | atomic_t nr_active_requests_shared_sbitmap; |
495 | ||
a612fddf | 496 | struct list_head icq_list; |
4eef3049 | 497 | #ifdef CONFIG_BLK_CGROUP |
a2b1693b | 498 | DECLARE_BITMAP (blkcg_pols, BLKCG_MAX_POLS); |
3c798398 | 499 | struct blkcg_gq *root_blkg; |
03aa264a | 500 | struct list_head blkg_list; |
4eef3049 | 501 | #endif |
a612fddf | 502 | |
025146e1 MP |
503 | struct queue_limits limits; |
504 | ||
68c43f13 DLM |
505 | unsigned int required_elevator_features; |
506 | ||
6a5ac984 | 507 | #ifdef CONFIG_BLK_DEV_ZONED |
6cc77e9c CH |
508 | /* |
509 | * Zoned block device information for request dispatch control. | |
510 | * nr_zones is the total number of zones of the device. This is always | |
f216fdd7 CH |
511 | * 0 for regular block devices. conv_zones_bitmap is a bitmap of nr_zones |
512 | * bits which indicates if a zone is conventional (bit set) or | |
513 | * sequential (bit clear). seq_zones_wlock is a bitmap of nr_zones | |
6cc77e9c CH |
514 | * bits which indicates if a zone is write locked, that is, if a write |
515 | * request targeting the zone was dispatched. All three fields are | |
516 | * initialized by the low level device driver (e.g. scsi/sd.c). | |
517 | * Stacking drivers (device mappers) may or may not initialize | |
518 | * these fields. | |
ccce20fc BVA |
519 | * |
520 | * Reads of this information must be protected with blk_queue_enter() / | |
521 | * blk_queue_exit(). Modifying this information is only allowed while | |
522 | * no requests are being processed. See also blk_mq_freeze_queue() and | |
523 | * blk_mq_unfreeze_queue(). | |
6cc77e9c CH |
524 | */ |
525 | unsigned int nr_zones; | |
f216fdd7 | 526 | unsigned long *conv_zones_bitmap; |
6cc77e9c | 527 | unsigned long *seq_zones_wlock; |
e15864f8 | 528 | unsigned int max_open_zones; |
659bf827 | 529 | unsigned int max_active_zones; |
6a5ac984 | 530 | #endif /* CONFIG_BLK_DEV_ZONED */ |
6cc77e9c | 531 | |
1da177e4 LT |
532 | /* |
533 | * sg stuff | |
534 | */ | |
535 | unsigned int sg_timeout; | |
536 | unsigned int sg_reserved_size; | |
1946089a | 537 | int node; |
85e0cbbb | 538 | struct mutex debugfs_mutex; |
6c5c9341 | 539 | #ifdef CONFIG_BLK_DEV_IO_TRACE |
c780e86d | 540 | struct blk_trace __rcu *blk_trace; |
6c5c9341 | 541 | #endif |
1da177e4 | 542 | /* |
4913efe4 | 543 | * for flush operations |
1da177e4 | 544 | */ |
7c94e1c1 | 545 | struct blk_flush_queue *fq; |
483f4afc | 546 | |
6fca6a61 CH |
547 | struct list_head requeue_list; |
548 | spinlock_t requeue_lock; | |
2849450a | 549 | struct delayed_work requeue_work; |
6fca6a61 | 550 | |
483f4afc | 551 | struct mutex sysfs_lock; |
cecf5d87 | 552 | struct mutex sysfs_dir_lock; |
d351af01 | 553 | |
2f8f1336 ML |
554 | /* |
555 | * for reusing dead hctx instance in case of updating | |
556 | * nr_hw_queues | |
557 | */ | |
558 | struct list_head unused_hctx_list; | |
559 | spinlock_t unused_hctx_lock; | |
560 | ||
7996a8b5 | 561 | int mq_freeze_depth; |
d732580b | 562 | |
d351af01 FT |
563 | #if defined(CONFIG_BLK_DEV_BSG) |
564 | struct bsg_class_device bsg_dev; | |
565 | #endif | |
e43473b7 VG |
566 | |
567 | #ifdef CONFIG_BLK_DEV_THROTTLING | |
568 | /* Throttle data */ | |
569 | struct throtl_data *td; | |
570 | #endif | |
548bc8e1 | 571 | struct rcu_head rcu_head; |
320ae51f | 572 | wait_queue_head_t mq_freeze_wq; |
7996a8b5 BL |
573 | /* |
574 | * Protect concurrent access to q_usage_counter by | |
575 | * percpu_ref_kill() and percpu_ref_reinit(). | |
576 | */ | |
577 | struct mutex mq_freeze_lock; | |
0d2602ca JA |
578 | |
579 | struct blk_mq_tag_set *tag_set; | |
580 | struct list_head tag_set_list; | |
338aa96d | 581 | struct bio_set bio_split; |
4593fdbe | 582 | |
07e4fead | 583 | struct dentry *debugfs_dir; |
85e0cbbb LC |
584 | |
585 | #ifdef CONFIG_BLK_DEBUG_FS | |
d332ce09 | 586 | struct dentry *sched_debugfs_dir; |
cc56694f | 587 | struct dentry *rqos_debugfs_dir; |
07e4fead OS |
588 | #endif |
589 | ||
4593fdbe | 590 | bool mq_sysfs_init_done; |
6d247d7f CH |
591 | |
592 | size_t cmd_size; | |
dc9edc44 | 593 | |
f793dfd3 JA |
594 | #define BLK_MAX_WRITE_HINTS 5 |
595 | u64 write_hints[BLK_MAX_WRITE_HINTS]; | |
1da177e4 LT |
596 | }; |
597 | ||
bfe373f6 | 598 | /* Keep blk_queue_flag_name[] in sync with the definitions below */ |
eca7abf3 JA |
599 | #define QUEUE_FLAG_STOPPED 0 /* queue is stopped */ |
600 | #define QUEUE_FLAG_DYING 1 /* queue being torn down */ | |
eca7abf3 JA |
601 | #define QUEUE_FLAG_NOMERGES 3 /* disable merge attempts */ |
602 | #define QUEUE_FLAG_SAME_COMP 4 /* complete on same CPU-group */ | |
603 | #define QUEUE_FLAG_FAIL_IO 5 /* fake timeout */ | |
604 | #define QUEUE_FLAG_NONROT 6 /* non-rotational device (SSD) */ | |
605 | #define QUEUE_FLAG_VIRT QUEUE_FLAG_NONROT /* paravirt device */ | |
606 | #define QUEUE_FLAG_IO_STAT 7 /* do disk/partitions IO accounting */ | |
607 | #define QUEUE_FLAG_DISCARD 8 /* supports DISCARD */ | |
608 | #define QUEUE_FLAG_NOXMERGES 9 /* No extended merges */ | |
609 | #define QUEUE_FLAG_ADD_RANDOM 10 /* Contributes to random pool */ | |
610 | #define QUEUE_FLAG_SECERASE 11 /* supports secure erase */ | |
611 | #define QUEUE_FLAG_SAME_FORCE 12 /* force complete on same CPU */ | |
612 | #define QUEUE_FLAG_DEAD 13 /* queue tear-down finished */ | |
613 | #define QUEUE_FLAG_INIT_DONE 14 /* queue is initialized */ | |
1cb039f3 | 614 | #define QUEUE_FLAG_STABLE_WRITES 15 /* don't modify blks until WB is done */ |
eca7abf3 JA |
615 | #define QUEUE_FLAG_POLL 16 /* IO polling enabled if set */ |
616 | #define QUEUE_FLAG_WC 17 /* Write back caching */ | |
617 | #define QUEUE_FLAG_FUA 18 /* device supports FUA writes */ | |
618 | #define QUEUE_FLAG_DAX 19 /* device supports DAX */ | |
619 | #define QUEUE_FLAG_STATS 20 /* track IO start and completion times */ | |
620 | #define QUEUE_FLAG_POLL_STATS 21 /* collecting stats for hybrid polling */ | |
621 | #define QUEUE_FLAG_REGISTERED 22 /* queue has been registered to a disk */ | |
622 | #define QUEUE_FLAG_SCSI_PASSTHROUGH 23 /* queue supports SCSI commands */ | |
623 | #define QUEUE_FLAG_QUIESCED 24 /* queue has been quiesced */ | |
624 | #define QUEUE_FLAG_PCI_P2PDMA 25 /* device supports PCI p2p requests */ | |
e84e8f06 | 625 | #define QUEUE_FLAG_ZONE_RESETALL 26 /* supports Zone Reset All */ |
6f816b4b | 626 | #define QUEUE_FLAG_RQ_ALLOC_TIME 27 /* record rq->alloc_time_ns */ |
021a2446 MS |
627 | #define QUEUE_FLAG_HCTX_ACTIVE 28 /* at least one blk-mq hctx is active */ |
628 | #define QUEUE_FLAG_NOWAIT 29 /* device supports NOWAIT */ | |
797e7dbb | 629 | |
94eddfbe | 630 | #define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ |
021a2446 MS |
631 | (1 << QUEUE_FLAG_SAME_COMP) | \ |
632 | (1 << QUEUE_FLAG_NOWAIT)) | |
94eddfbe | 633 | |
8814ce8a BVA |
634 | void blk_queue_flag_set(unsigned int flag, struct request_queue *q); |
635 | void blk_queue_flag_clear(unsigned int flag, struct request_queue *q); | |
636 | bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q); | |
8814ce8a | 637 | |
1da177e4 | 638 | #define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags) |
3f3299d5 | 639 | #define blk_queue_dying(q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags) |
c246e80d | 640 | #define blk_queue_dead(q) test_bit(QUEUE_FLAG_DEAD, &(q)->queue_flags) |
320ae51f | 641 | #define blk_queue_init_done(q) test_bit(QUEUE_FLAG_INIT_DONE, &(q)->queue_flags) |
ac9fafa1 | 642 | #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags) |
488991e2 AB |
643 | #define blk_queue_noxmerges(q) \ |
644 | test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags) | |
a68bbddb | 645 | #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags) |
1cb039f3 CH |
646 | #define blk_queue_stable_writes(q) \ |
647 | test_bit(QUEUE_FLAG_STABLE_WRITES, &(q)->queue_flags) | |
bc58ba94 | 648 | #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags) |
e2e1a148 | 649 | #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags) |
c15227de | 650 | #define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags) |
e84e8f06 CK |
651 | #define blk_queue_zone_resetall(q) \ |
652 | test_bit(QUEUE_FLAG_ZONE_RESETALL, &(q)->queue_flags) | |
288dab8a CH |
653 | #define blk_queue_secure_erase(q) \ |
654 | (test_bit(QUEUE_FLAG_SECERASE, &(q)->queue_flags)) | |
163d4baa | 655 | #define blk_queue_dax(q) test_bit(QUEUE_FLAG_DAX, &(q)->queue_flags) |
9efc160f BVA |
656 | #define blk_queue_scsi_passthrough(q) \ |
657 | test_bit(QUEUE_FLAG_SCSI_PASSTHROUGH, &(q)->queue_flags) | |
49d92c0d LG |
658 | #define blk_queue_pci_p2pdma(q) \ |
659 | test_bit(QUEUE_FLAG_PCI_P2PDMA, &(q)->queue_flags) | |
6f816b4b TH |
660 | #ifdef CONFIG_BLK_RQ_ALLOC_TIME |
661 | #define blk_queue_rq_alloc_time(q) \ | |
662 | test_bit(QUEUE_FLAG_RQ_ALLOC_TIME, &(q)->queue_flags) | |
663 | #else | |
664 | #define blk_queue_rq_alloc_time(q) false | |
665 | #endif | |
1da177e4 | 666 | |
33659ebb CH |
667 | #define blk_noretry_request(rq) \ |
668 | ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \ | |
669 | REQ_FAILFAST_DRIVER)) | |
f4560ffe | 670 | #define blk_queue_quiesced(q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags) |
cd84a62e | 671 | #define blk_queue_pm_only(q) atomic_read(&(q)->pm_only) |
0ce91444 | 672 | #define blk_queue_fua(q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags) |
58c898ba | 673 | #define blk_queue_registered(q) test_bit(QUEUE_FLAG_REGISTERED, &(q)->queue_flags) |
021a2446 | 674 | #define blk_queue_nowait(q) test_bit(QUEUE_FLAG_NOWAIT, &(q)->queue_flags) |
c9254f2d | 675 | |
cd84a62e BVA |
676 | extern void blk_set_pm_only(struct request_queue *q); |
677 | extern void blk_clear_pm_only(struct request_queue *q); | |
33659ebb | 678 | |
1da177e4 LT |
679 | #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist) |
680 | ||
4e1b2d52 | 681 | #define rq_data_dir(rq) (op_is_write(req_op(rq)) ? WRITE : READ) |
1da177e4 | 682 | |
9d9de535 CH |
683 | #define rq_dma_dir(rq) \ |
684 | (op_is_write(req_op(rq)) ? DMA_TO_DEVICE : DMA_FROM_DEVICE) | |
685 | ||
3ab3a031 CH |
686 | #define dma_map_bvec(dev, bv, dir, attrs) \ |
687 | dma_map_page_attrs(dev, (bv)->bv_page, (bv)->bv_offset, (bv)->bv_len, \ | |
688 | (dir), (attrs)) | |
689 | ||
907d5231 JX |
690 | #define queue_to_disk(q) (dev_to_disk(kobj_to_dev((q)->kobj.parent))) |
691 | ||
344e9ffc | 692 | static inline bool queue_is_mq(struct request_queue *q) |
49fd524f | 693 | { |
a1ce35fa | 694 | return q->mq_ops; |
49fd524f JA |
695 | } |
696 | ||
52abca64 AS |
697 | #ifdef CONFIG_PM |
698 | static inline enum rpm_status queue_rpm_status(struct request_queue *q) | |
699 | { | |
700 | return q->rpm_status; | |
701 | } | |
702 | #else | |
703 | static inline enum rpm_status queue_rpm_status(struct request_queue *q) | |
704 | { | |
705 | return RPM_ACTIVE; | |
706 | } | |
707 | #endif | |
708 | ||
797476b8 DLM |
709 | static inline enum blk_zoned_model |
710 | blk_queue_zoned_model(struct request_queue *q) | |
711 | { | |
6fcd6695 CH |
712 | if (IS_ENABLED(CONFIG_BLK_DEV_ZONED)) |
713 | return q->limits.zoned; | |
714 | return BLK_ZONED_NONE; | |
797476b8 DLM |
715 | } |
716 | ||
717 | static inline bool blk_queue_is_zoned(struct request_queue *q) | |
718 | { | |
719 | switch (blk_queue_zoned_model(q)) { | |
720 | case BLK_ZONED_HA: | |
721 | case BLK_ZONED_HM: | |
722 | return true; | |
723 | default: | |
724 | return false; | |
725 | } | |
726 | } | |
727 | ||
113ab72e | 728 | static inline sector_t blk_queue_zone_sectors(struct request_queue *q) |
6a0cb1bc HR |
729 | { |
730 | return blk_queue_is_zoned(q) ? q->limits.chunk_sectors : 0; | |
731 | } | |
732 | ||
6a5ac984 | 733 | #ifdef CONFIG_BLK_DEV_ZONED |
965b652e DLM |
734 | static inline unsigned int blk_queue_nr_zones(struct request_queue *q) |
735 | { | |
736 | return blk_queue_is_zoned(q) ? q->nr_zones : 0; | |
737 | } | |
738 | ||
6cc77e9c CH |
739 | static inline unsigned int blk_queue_zone_no(struct request_queue *q, |
740 | sector_t sector) | |
741 | { | |
742 | if (!blk_queue_is_zoned(q)) | |
743 | return 0; | |
744 | return sector >> ilog2(q->limits.chunk_sectors); | |
745 | } | |
746 | ||
747 | static inline bool blk_queue_zone_is_seq(struct request_queue *q, | |
748 | sector_t sector) | |
749 | { | |
f216fdd7 | 750 | if (!blk_queue_is_zoned(q)) |
6cc77e9c | 751 | return false; |
f216fdd7 CH |
752 | if (!q->conv_zones_bitmap) |
753 | return true; | |
754 | return !test_bit(blk_queue_zone_no(q, sector), q->conv_zones_bitmap); | |
6cc77e9c | 755 | } |
e15864f8 NC |
756 | |
757 | static inline void blk_queue_max_open_zones(struct request_queue *q, | |
758 | unsigned int max_open_zones) | |
759 | { | |
760 | q->max_open_zones = max_open_zones; | |
761 | } | |
762 | ||
763 | static inline unsigned int queue_max_open_zones(const struct request_queue *q) | |
764 | { | |
765 | return q->max_open_zones; | |
766 | } | |
659bf827 NC |
767 | |
768 | static inline void blk_queue_max_active_zones(struct request_queue *q, | |
769 | unsigned int max_active_zones) | |
770 | { | |
771 | q->max_active_zones = max_active_zones; | |
772 | } | |
773 | ||
774 | static inline unsigned int queue_max_active_zones(const struct request_queue *q) | |
775 | { | |
776 | return q->max_active_zones; | |
777 | } | |
965b652e DLM |
778 | #else /* CONFIG_BLK_DEV_ZONED */ |
779 | static inline unsigned int blk_queue_nr_zones(struct request_queue *q) | |
780 | { | |
781 | return 0; | |
782 | } | |
02992df8 JT |
783 | static inline bool blk_queue_zone_is_seq(struct request_queue *q, |
784 | sector_t sector) | |
785 | { | |
786 | return false; | |
787 | } | |
788 | static inline unsigned int blk_queue_zone_no(struct request_queue *q, | |
789 | sector_t sector) | |
790 | { | |
791 | return 0; | |
792 | } | |
e15864f8 NC |
793 | static inline unsigned int queue_max_open_zones(const struct request_queue *q) |
794 | { | |
795 | return 0; | |
796 | } | |
659bf827 NC |
797 | static inline unsigned int queue_max_active_zones(const struct request_queue *q) |
798 | { | |
799 | return 0; | |
800 | } | |
6a5ac984 | 801 | #endif /* CONFIG_BLK_DEV_ZONED */ |
6cc77e9c | 802 | |
1faa16d2 JA |
803 | static inline bool rq_is_sync(struct request *rq) |
804 | { | |
ef295ecf | 805 | return op_is_sync(rq->cmd_flags); |
1faa16d2 JA |
806 | } |
807 | ||
e2a60da7 MP |
808 | static inline bool rq_mergeable(struct request *rq) |
809 | { | |
57292b58 | 810 | if (blk_rq_is_passthrough(rq)) |
e2a60da7 | 811 | return false; |
1da177e4 | 812 | |
3a5e02ce MC |
813 | if (req_op(rq) == REQ_OP_FLUSH) |
814 | return false; | |
815 | ||
a6f0788e CK |
816 | if (req_op(rq) == REQ_OP_WRITE_ZEROES) |
817 | return false; | |
818 | ||
0512a75b KB |
819 | if (req_op(rq) == REQ_OP_ZONE_APPEND) |
820 | return false; | |
821 | ||
e2a60da7 | 822 | if (rq->cmd_flags & REQ_NOMERGE_FLAGS) |
e8064021 CH |
823 | return false; |
824 | if (rq->rq_flags & RQF_NOMERGE_FLAGS) | |
e2a60da7 MP |
825 | return false; |
826 | ||
827 | return true; | |
828 | } | |
1da177e4 | 829 | |
4363ac7c MP |
830 | static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b) |
831 | { | |
efbeccdb CH |
832 | if (bio_page(a) == bio_page(b) && |
833 | bio_offset(a) == bio_offset(b)) | |
4363ac7c MP |
834 | return true; |
835 | ||
836 | return false; | |
837 | } | |
838 | ||
d278d4a8 JA |
839 | static inline unsigned int blk_queue_depth(struct request_queue *q) |
840 | { | |
841 | if (q->queue_depth) | |
842 | return q->queue_depth; | |
843 | ||
844 | return q->nr_requests; | |
845 | } | |
846 | ||
3d6392cf JA |
847 | /* |
848 | * default timeout for SG_IO if none specified | |
849 | */ | |
850 | #define BLK_DEFAULT_SG_TIMEOUT (60 * HZ) | |
f2f1fa78 | 851 | #define BLK_MIN_SG_TIMEOUT (7 * HZ) |
3d6392cf | 852 | |
152e283f FT |
853 | struct rq_map_data { |
854 | struct page **pages; | |
855 | int page_order; | |
856 | int nr_entries; | |
56c451f4 | 857 | unsigned long offset; |
97ae77a1 | 858 | int null_mapped; |
ecb554a8 | 859 | int from_user; |
152e283f FT |
860 | }; |
861 | ||
5705f702 | 862 | struct req_iterator { |
7988613b | 863 | struct bvec_iter iter; |
5705f702 N |
864 | struct bio *bio; |
865 | }; | |
866 | ||
867 | /* This should not be used directly - use rq_for_each_segment */ | |
1e428079 JA |
868 | #define for_each_bio(_bio) \ |
869 | for (; _bio; _bio = _bio->bi_next) | |
5705f702 | 870 | #define __rq_for_each_bio(_bio, rq) \ |
1da177e4 LT |
871 | if ((rq->bio)) \ |
872 | for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next) | |
873 | ||
5705f702 N |
874 | #define rq_for_each_segment(bvl, _rq, _iter) \ |
875 | __rq_for_each_bio(_iter.bio, _rq) \ | |
7988613b | 876 | bio_for_each_segment(bvl, _iter.bio, _iter.iter) |
5705f702 | 877 | |
d18d9174 ML |
878 | #define rq_for_each_bvec(bvl, _rq, _iter) \ |
879 | __rq_for_each_bio(_iter.bio, _rq) \ | |
880 | bio_for_each_bvec(bvl, _iter.bio, _iter.iter) | |
881 | ||
4550dd6c | 882 | #define rq_iter_last(bvec, _iter) \ |
7988613b | 883 | (_iter.bio->bi_next == NULL && \ |
4550dd6c | 884 | bio_iter_last(bvec, _iter.iter)) |
5705f702 | 885 | |
2d4dc890 IL |
886 | #ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE |
887 | # error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform" | |
888 | #endif | |
889 | #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE | |
890 | extern void rq_flush_dcache_pages(struct request *rq); | |
891 | #else | |
892 | static inline void rq_flush_dcache_pages(struct request *rq) | |
893 | { | |
894 | } | |
895 | #endif | |
896 | ||
1da177e4 LT |
897 | extern int blk_register_queue(struct gendisk *disk); |
898 | extern void blk_unregister_queue(struct gendisk *disk); | |
ed00aabd | 899 | blk_qc_t submit_bio_noacct(struct bio *bio); |
2a4aa30c | 900 | extern void blk_rq_init(struct request_queue *q, struct request *rq); |
1da177e4 | 901 | extern void blk_put_request(struct request *); |
cd6ce148 | 902 | extern struct request *blk_get_request(struct request_queue *, unsigned int op, |
ff005a06 | 903 | blk_mq_req_flags_t flags); |
ef9e3fac | 904 | extern int blk_lld_busy(struct request_queue *q); |
78d8e58a MS |
905 | extern int blk_rq_prep_clone(struct request *rq, struct request *rq_src, |
906 | struct bio_set *bs, gfp_t gfp_mask, | |
907 | int (*bio_ctr)(struct bio *, struct bio *, void *), | |
908 | void *data); | |
909 | extern void blk_rq_unprep_clone(struct request *rq); | |
2a842aca | 910 | extern blk_status_t blk_insert_cloned_request(struct request_queue *q, |
82124d60 | 911 | struct request *rq); |
393bb12e | 912 | int blk_rq_append_bio(struct request *rq, struct bio *bio); |
f695ca38 | 913 | extern void blk_queue_split(struct bio **); |
0bfc96cb | 914 | extern int scsi_verify_blk_ioctl(struct block_device *, unsigned int); |
577ebb37 PB |
915 | extern int scsi_cmd_blk_ioctl(struct block_device *, fmode_t, |
916 | unsigned int, void __user *); | |
74f3c8af AV |
917 | extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t, |
918 | unsigned int, void __user *); | |
e915e872 AV |
919 | extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t, |
920 | struct scsi_ioctl_command __user *); | |
98aaaec4 AB |
921 | extern int get_sg_io_hdr(struct sg_io_hdr *hdr, const void __user *argp); |
922 | extern int put_sg_io_hdr(const struct sg_io_hdr *hdr, void __user *argp); | |
3fcfab16 | 923 | |
9a95e4ef | 924 | extern int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags); |
2e6edc95 | 925 | extern void blk_queue_exit(struct request_queue *q); |
1da177e4 | 926 | extern void blk_sync_queue(struct request_queue *q); |
a3bce90e | 927 | extern int blk_rq_map_user(struct request_queue *, struct request *, |
152e283f FT |
928 | struct rq_map_data *, void __user *, unsigned long, |
929 | gfp_t); | |
8e5cfc45 | 930 | extern int blk_rq_unmap_user(struct bio *); |
165125e1 JA |
931 | extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t); |
932 | extern int blk_rq_map_user_iov(struct request_queue *, struct request *, | |
26e49cfc KO |
933 | struct rq_map_data *, const struct iov_iter *, |
934 | gfp_t); | |
684da762 | 935 | extern void blk_execute_rq(struct gendisk *, struct request *, int); |
8eeed0b5 | 936 | extern void blk_execute_rq_nowait(struct gendisk *, |
15fc858a | 937 | struct request *, int, rq_end_io_fn *); |
6e39b69e | 938 | |
e47bc4ed CK |
939 | /* Helper to convert REQ_OP_XXX to its string format XXX */ |
940 | extern const char *blk_op_str(unsigned int op); | |
941 | ||
2a842aca CH |
942 | int blk_status_to_errno(blk_status_t status); |
943 | blk_status_t errno_to_blk_status(int errno); | |
944 | ||
0a1b8b87 | 945 | int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin); |
05229bee | 946 | |
165125e1 | 947 | static inline struct request_queue *bdev_get_queue(struct block_device *bdev) |
1da177e4 | 948 | { |
ff9ea323 | 949 | return bdev->bd_disk->queue; /* this is never NULL */ |
1da177e4 LT |
950 | } |
951 | ||
233bde21 BVA |
952 | /* |
953 | * The basic unit of block I/O is a sector. It is used in a number of contexts | |
954 | * in Linux (blk, bio, genhd). The size of one sector is 512 = 2**9 | |
955 | * bytes. Variables of type sector_t represent an offset or size that is a | |
956 | * multiple of 512 bytes. Hence these two constants. | |
957 | */ | |
958 | #ifndef SECTOR_SHIFT | |
959 | #define SECTOR_SHIFT 9 | |
960 | #endif | |
961 | #ifndef SECTOR_SIZE | |
962 | #define SECTOR_SIZE (1 << SECTOR_SHIFT) | |
963 | #endif | |
964 | ||
5efccd17 | 965 | /* |
80a761fd TH |
966 | * blk_rq_pos() : the current sector |
967 | * blk_rq_bytes() : bytes left in the entire request | |
968 | * blk_rq_cur_bytes() : bytes left in the current segment | |
969 | * blk_rq_err_bytes() : bytes left till the next error boundary | |
970 | * blk_rq_sectors() : sectors left in the entire request | |
971 | * blk_rq_cur_sectors() : sectors left in the current segment | |
3d244306 | 972 | * blk_rq_stats_sectors() : sectors of the entire request used for stats |
5efccd17 | 973 | */ |
5b93629b TH |
974 | static inline sector_t blk_rq_pos(const struct request *rq) |
975 | { | |
a2dec7b3 | 976 | return rq->__sector; |
2e46e8b2 TH |
977 | } |
978 | ||
979 | static inline unsigned int blk_rq_bytes(const struct request *rq) | |
980 | { | |
a2dec7b3 | 981 | return rq->__data_len; |
5b93629b TH |
982 | } |
983 | ||
2e46e8b2 TH |
984 | static inline int blk_rq_cur_bytes(const struct request *rq) |
985 | { | |
986 | return rq->bio ? bio_cur_bytes(rq->bio) : 0; | |
987 | } | |
5efccd17 | 988 | |
80a761fd TH |
989 | extern unsigned int blk_rq_err_bytes(const struct request *rq); |
990 | ||
5b93629b TH |
991 | static inline unsigned int blk_rq_sectors(const struct request *rq) |
992 | { | |
233bde21 | 993 | return blk_rq_bytes(rq) >> SECTOR_SHIFT; |
5b93629b TH |
994 | } |
995 | ||
996 | static inline unsigned int blk_rq_cur_sectors(const struct request *rq) | |
997 | { | |
233bde21 | 998 | return blk_rq_cur_bytes(rq) >> SECTOR_SHIFT; |
5b93629b TH |
999 | } |
1000 | ||
3d244306 HT |
1001 | static inline unsigned int blk_rq_stats_sectors(const struct request *rq) |
1002 | { | |
1003 | return rq->stats_sectors; | |
1004 | } | |
1005 | ||
6a5ac984 | 1006 | #ifdef CONFIG_BLK_DEV_ZONED |
02694e86 CK |
1007 | |
1008 | /* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */ | |
1009 | const char *blk_zone_cond_str(enum blk_zone_cond zone_cond); | |
1010 | ||
6cc77e9c CH |
1011 | static inline unsigned int blk_rq_zone_no(struct request *rq) |
1012 | { | |
1013 | return blk_queue_zone_no(rq->q, blk_rq_pos(rq)); | |
1014 | } | |
1015 | ||
1016 | static inline unsigned int blk_rq_zone_is_seq(struct request *rq) | |
1017 | { | |
1018 | return blk_queue_zone_is_seq(rq->q, blk_rq_pos(rq)); | |
1019 | } | |
6a5ac984 | 1020 | #endif /* CONFIG_BLK_DEV_ZONED */ |
6cc77e9c | 1021 | |
2e3258ec CH |
1022 | /* |
1023 | * Some commands like WRITE SAME have a payload or data transfer size which | |
1024 | * is different from the size of the request. Any driver that supports such | |
1025 | * commands using the RQF_SPECIAL_PAYLOAD flag needs to use this helper to | |
1026 | * calculate the data transfer size. | |
1027 | */ | |
1028 | static inline unsigned int blk_rq_payload_bytes(struct request *rq) | |
1029 | { | |
1030 | if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) | |
1031 | return rq->special_vec.bv_len; | |
1032 | return blk_rq_bytes(rq); | |
1033 | } | |
1034 | ||
3aef3cae CH |
1035 | /* |
1036 | * Return the first full biovec in the request. The caller needs to check that | |
1037 | * there are any bvecs before calling this helper. | |
1038 | */ | |
1039 | static inline struct bio_vec req_bvec(struct request *rq) | |
1040 | { | |
1041 | if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) | |
1042 | return rq->special_vec; | |
1043 | return mp_bvec_iter_bvec(rq->bio->bi_io_vec, rq->bio->bi_iter); | |
1044 | } | |
1045 | ||
f31dc1cd | 1046 | static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, |
8fe0d473 | 1047 | int op) |
f31dc1cd | 1048 | { |
7afafc8a | 1049 | if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) |
233bde21 BVA |
1050 | return min(q->limits.max_discard_sectors, |
1051 | UINT_MAX >> SECTOR_SHIFT); | |
f31dc1cd | 1052 | |
8fe0d473 | 1053 | if (unlikely(op == REQ_OP_WRITE_SAME)) |
4363ac7c MP |
1054 | return q->limits.max_write_same_sectors; |
1055 | ||
a6f0788e CK |
1056 | if (unlikely(op == REQ_OP_WRITE_ZEROES)) |
1057 | return q->limits.max_write_zeroes_sectors; | |
1058 | ||
f31dc1cd MP |
1059 | return q->limits.max_sectors; |
1060 | } | |
1061 | ||
762380ad JA |
1062 | /* |
1063 | * Return maximum size of a request at given offset. Only valid for | |
1064 | * file system requests. | |
1065 | */ | |
1066 | static inline unsigned int blk_max_size_offset(struct request_queue *q, | |
3ee16db3 MS |
1067 | sector_t offset, |
1068 | unsigned int chunk_sectors) | |
762380ad | 1069 | { |
65f33b35 MS |
1070 | if (!chunk_sectors) { |
1071 | if (q->limits.chunk_sectors) | |
1072 | chunk_sectors = q->limits.chunk_sectors; | |
1073 | else | |
1074 | return q->limits.max_sectors; | |
1075 | } | |
762380ad | 1076 | |
07d098e6 MS |
1077 | if (likely(is_power_of_2(chunk_sectors))) |
1078 | chunk_sectors -= offset & (chunk_sectors - 1); | |
1079 | else | |
1080 | chunk_sectors -= sector_div(offset, chunk_sectors); | |
1081 | ||
1082 | return min(q->limits.max_sectors, chunk_sectors); | |
762380ad JA |
1083 | } |
1084 | ||
17007f39 DLM |
1085 | static inline unsigned int blk_rq_get_max_sectors(struct request *rq, |
1086 | sector_t offset) | |
f31dc1cd MP |
1087 | { |
1088 | struct request_queue *q = rq->q; | |
1089 | ||
57292b58 | 1090 | if (blk_rq_is_passthrough(rq)) |
f31dc1cd MP |
1091 | return q->limits.max_hw_sectors; |
1092 | ||
7afafc8a AH |
1093 | if (!q->limits.chunk_sectors || |
1094 | req_op(rq) == REQ_OP_DISCARD || | |
1095 | req_op(rq) == REQ_OP_SECURE_ERASE) | |
8fe0d473 | 1096 | return blk_queue_get_max_sectors(q, req_op(rq)); |
762380ad | 1097 | |
3ee16db3 | 1098 | return min(blk_max_size_offset(q, offset, 0), |
8fe0d473 | 1099 | blk_queue_get_max_sectors(q, req_op(rq))); |
f31dc1cd MP |
1100 | } |
1101 | ||
75afb352 JN |
1102 | static inline unsigned int blk_rq_count_bios(struct request *rq) |
1103 | { | |
1104 | unsigned int nr_bios = 0; | |
1105 | struct bio *bio; | |
1106 | ||
1107 | __rq_for_each_bio(bio, rq) | |
1108 | nr_bios++; | |
1109 | ||
1110 | return nr_bios; | |
1111 | } | |
1112 | ||
ef71de8b CH |
1113 | void blk_steal_bios(struct bio_list *list, struct request *rq); |
1114 | ||
1da177e4 | 1115 | /* |
2e60e022 TH |
1116 | * Request completion related functions. |
1117 | * | |
1118 | * blk_update_request() completes given number of bytes and updates | |
1119 | * the request without completing it. | |
1da177e4 | 1120 | */ |
2a842aca | 1121 | extern bool blk_update_request(struct request *rq, blk_status_t error, |
2e60e022 | 1122 | unsigned int nr_bytes); |
2e60e022 | 1123 | |
242f9dcb | 1124 | extern void blk_abort_request(struct request *); |
ff856bad | 1125 | |
1da177e4 LT |
1126 | /* |
1127 | * Access functions for manipulating queue properties | |
1128 | */ | |
165125e1 | 1129 | extern void blk_cleanup_queue(struct request_queue *); |
9bb33f24 | 1130 | void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce limit); |
086fa5ff | 1131 | extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int); |
762380ad | 1132 | extern void blk_queue_chunk_sectors(struct request_queue *, unsigned int); |
8a78362c | 1133 | extern void blk_queue_max_segments(struct request_queue *, unsigned short); |
1e739730 CH |
1134 | extern void blk_queue_max_discard_segments(struct request_queue *, |
1135 | unsigned short); | |
165125e1 | 1136 | extern void blk_queue_max_segment_size(struct request_queue *, unsigned int); |
67efc925 CH |
1137 | extern void blk_queue_max_discard_sectors(struct request_queue *q, |
1138 | unsigned int max_discard_sectors); | |
4363ac7c MP |
1139 | extern void blk_queue_max_write_same_sectors(struct request_queue *q, |
1140 | unsigned int max_write_same_sectors); | |
a6f0788e CK |
1141 | extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q, |
1142 | unsigned int max_write_same_sectors); | |
ad6bf88a | 1143 | extern void blk_queue_logical_block_size(struct request_queue *, unsigned int); |
0512a75b KB |
1144 | extern void blk_queue_max_zone_append_sectors(struct request_queue *q, |
1145 | unsigned int max_zone_append_sectors); | |
892b6f90 | 1146 | extern void blk_queue_physical_block_size(struct request_queue *, unsigned int); |
a805a4fa DLM |
1147 | void blk_queue_zone_write_granularity(struct request_queue *q, |
1148 | unsigned int size); | |
c72758f3 MP |
1149 | extern void blk_queue_alignment_offset(struct request_queue *q, |
1150 | unsigned int alignment); | |
c2e4cd57 | 1151 | void blk_queue_update_readahead(struct request_queue *q); |
7c958e32 | 1152 | extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min); |
c72758f3 | 1153 | extern void blk_queue_io_min(struct request_queue *q, unsigned int min); |
3c5820c7 | 1154 | extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt); |
c72758f3 | 1155 | extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt); |
d278d4a8 | 1156 | extern void blk_set_queue_depth(struct request_queue *q, unsigned int depth); |
e475bba2 | 1157 | extern void blk_set_default_limits(struct queue_limits *lim); |
b1bd055d | 1158 | extern void blk_set_stacking_limits(struct queue_limits *lim); |
c72758f3 MP |
1159 | extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, |
1160 | sector_t offset); | |
1161 | extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev, | |
1162 | sector_t offset); | |
27f8221a | 1163 | extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int); |
165125e1 | 1164 | extern void blk_queue_segment_boundary(struct request_queue *, unsigned long); |
03100aad | 1165 | extern void blk_queue_virt_boundary(struct request_queue *, unsigned long); |
165125e1 | 1166 | extern void blk_queue_dma_alignment(struct request_queue *, int); |
11c3e689 | 1167 | extern void blk_queue_update_dma_alignment(struct request_queue *, int); |
242f9dcb | 1168 | extern void blk_queue_rq_timeout(struct request_queue *, unsigned int); |
93e9d8e8 | 1169 | extern void blk_queue_write_cache(struct request_queue *q, bool enabled, bool fua); |
68c43f13 DLM |
1170 | extern void blk_queue_required_elevator_features(struct request_queue *q, |
1171 | unsigned int features); | |
45147fb5 YS |
1172 | extern bool blk_queue_can_use_dma_map_merging(struct request_queue *q, |
1173 | struct device *dev); | |
1da177e4 | 1174 | |
1e739730 CH |
1175 | /* |
1176 | * Number of physical segments as sent to the device. | |
1177 | * | |
1178 | * Normally this is the number of discontiguous data segments sent by the | |
1179 | * submitter. But for data-less command like discard we might have no | |
1180 | * actual data segments submitted, but the driver might have to add it's | |
1181 | * own special payload. In that case we still return 1 here so that this | |
1182 | * special payload will be mapped. | |
1183 | */ | |
f9d03f96 CH |
1184 | static inline unsigned short blk_rq_nr_phys_segments(struct request *rq) |
1185 | { | |
1186 | if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) | |
1187 | return 1; | |
1188 | return rq->nr_phys_segments; | |
1189 | } | |
1190 | ||
1e739730 CH |
1191 | /* |
1192 | * Number of discard segments (or ranges) the driver needs to fill in. | |
1193 | * Each discard bio merged into a request is counted as one segment. | |
1194 | */ | |
1195 | static inline unsigned short blk_rq_nr_discard_segments(struct request *rq) | |
1196 | { | |
1197 | return max_t(unsigned short, rq->nr_phys_segments, 1); | |
1198 | } | |
1199 | ||
89de1504 CH |
1200 | int __blk_rq_map_sg(struct request_queue *q, struct request *rq, |
1201 | struct scatterlist *sglist, struct scatterlist **last_sg); | |
1202 | static inline int blk_rq_map_sg(struct request_queue *q, struct request *rq, | |
1203 | struct scatterlist *sglist) | |
1204 | { | |
1205 | struct scatterlist *last_sg = NULL; | |
1206 | ||
1207 | return __blk_rq_map_sg(q, rq, sglist, &last_sg); | |
1208 | } | |
1da177e4 | 1209 | extern void blk_dump_rq_flags(struct request *, char *); |
1da177e4 | 1210 | |
09ac46c4 | 1211 | bool __must_check blk_get_queue(struct request_queue *); |
c62b37d9 | 1212 | struct request_queue *blk_alloc_queue(int node_id); |
165125e1 | 1213 | extern void blk_put_queue(struct request_queue *); |
3f21c265 | 1214 | extern void blk_set_queue_dying(struct request_queue *); |
1da177e4 | 1215 | |
1a4dcfa8 | 1216 | #ifdef CONFIG_BLOCK |
316cc67d | 1217 | /* |
75df7136 SJ |
1218 | * blk_plug permits building a queue of related requests by holding the I/O |
1219 | * fragments for a short period. This allows merging of sequential requests | |
1220 | * into single larger request. As the requests are moved from a per-task list to | |
1221 | * the device's request_queue in a batch, this results in improved scalability | |
1222 | * as the lock contention for request_queue lock is reduced. | |
1223 | * | |
1224 | * It is ok not to disable preemption when adding the request to the plug list | |
1225 | * or when attempting a merge, because blk_schedule_flush_list() will only flush | |
1226 | * the plug list when the task sleeps by itself. For details, please see | |
1227 | * schedule() where blk_schedule_flush_plug() is called. | |
316cc67d | 1228 | */ |
73c10101 | 1229 | struct blk_plug { |
320ae51f | 1230 | struct list_head mq_list; /* blk-mq requests */ |
75df7136 | 1231 | struct list_head cb_list; /* md requires an unplug callback */ |
5f0ed774 | 1232 | unsigned short rq_count; |
ce5b009c | 1233 | bool multiple_queues; |
5a473e83 | 1234 | bool nowait; |
73c10101 | 1235 | }; |
55c022bb | 1236 | #define BLK_MAX_REQUEST_COUNT 16 |
50d24c34 | 1237 | #define BLK_PLUG_FLUSH_SIZE (128 * 1024) |
55c022bb | 1238 | |
9cbb1750 | 1239 | struct blk_plug_cb; |
74018dc3 | 1240 | typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *, bool); |
048c9374 N |
1241 | struct blk_plug_cb { |
1242 | struct list_head list; | |
9cbb1750 N |
1243 | blk_plug_cb_fn callback; |
1244 | void *data; | |
048c9374 | 1245 | }; |
9cbb1750 N |
1246 | extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, |
1247 | void *data, int size); | |
73c10101 JA |
1248 | extern void blk_start_plug(struct blk_plug *); |
1249 | extern void blk_finish_plug(struct blk_plug *); | |
f6603783 | 1250 | extern void blk_flush_plug_list(struct blk_plug *, bool); |
73c10101 JA |
1251 | |
1252 | static inline void blk_flush_plug(struct task_struct *tsk) | |
1253 | { | |
1254 | struct blk_plug *plug = tsk->plug; | |
1255 | ||
a237c1c5 JA |
1256 | if (plug) |
1257 | blk_flush_plug_list(plug, false); | |
1258 | } | |
1259 | ||
1260 | static inline void blk_schedule_flush_plug(struct task_struct *tsk) | |
1261 | { | |
1262 | struct blk_plug *plug = tsk->plug; | |
1263 | ||
88b996cd | 1264 | if (plug) |
f6603783 | 1265 | blk_flush_plug_list(plug, true); |
73c10101 JA |
1266 | } |
1267 | ||
1268 | static inline bool blk_needs_flush_plug(struct task_struct *tsk) | |
1269 | { | |
1270 | struct blk_plug *plug = tsk->plug; | |
1271 | ||
320ae51f | 1272 | return plug && |
a1ce35fa | 1273 | (!list_empty(&plug->mq_list) || |
320ae51f | 1274 | !list_empty(&plug->cb_list)); |
73c10101 JA |
1275 | } |
1276 | ||
c6bf3f0e | 1277 | int blkdev_issue_flush(struct block_device *bdev); |
1a4dcfa8 CH |
1278 | long nr_blockdev_pages(void); |
1279 | #else /* CONFIG_BLOCK */ | |
1280 | struct blk_plug { | |
1281 | }; | |
1282 | ||
1283 | static inline void blk_start_plug(struct blk_plug *plug) | |
1284 | { | |
1285 | } | |
1286 | ||
1287 | static inline void blk_finish_plug(struct blk_plug *plug) | |
1288 | { | |
1289 | } | |
1290 | ||
1291 | static inline void blk_flush_plug(struct task_struct *task) | |
1292 | { | |
1293 | } | |
1294 | ||
1295 | static inline void blk_schedule_flush_plug(struct task_struct *task) | |
1296 | { | |
1297 | } | |
1298 | ||
1299 | ||
1300 | static inline bool blk_needs_flush_plug(struct task_struct *tsk) | |
1301 | { | |
1302 | return false; | |
1303 | } | |
1304 | ||
c6bf3f0e | 1305 | static inline int blkdev_issue_flush(struct block_device *bdev) |
1a4dcfa8 CH |
1306 | { |
1307 | return 0; | |
1308 | } | |
1309 | ||
1310 | static inline long nr_blockdev_pages(void) | |
1311 | { | |
1312 | return 0; | |
1313 | } | |
1314 | #endif /* CONFIG_BLOCK */ | |
1315 | ||
71ac860a ML |
1316 | extern void blk_io_schedule(void); |
1317 | ||
ee472d83 CH |
1318 | extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, |
1319 | sector_t nr_sects, gfp_t gfp_mask, struct page *page); | |
e950fdf7 CH |
1320 | |
1321 | #define BLKDEV_DISCARD_SECURE (1 << 0) /* issue a secure erase */ | |
dd3932ed | 1322 | |
fbd9b09a DM |
1323 | extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector, |
1324 | sector_t nr_sects, gfp_t gfp_mask, unsigned long flags); | |
38f25255 | 1325 | extern int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, |
288dab8a | 1326 | sector_t nr_sects, gfp_t gfp_mask, int flags, |
469e3216 | 1327 | struct bio **biop); |
ee472d83 CH |
1328 | |
1329 | #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */ | |
cb365b96 | 1330 | #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */ |
ee472d83 | 1331 | |
e73c23ff CK |
1332 | extern int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, |
1333 | sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, | |
ee472d83 | 1334 | unsigned flags); |
3f14d792 | 1335 | extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, |
ee472d83 CH |
1336 | sector_t nr_sects, gfp_t gfp_mask, unsigned flags); |
1337 | ||
2cf6d26a CH |
1338 | static inline int sb_issue_discard(struct super_block *sb, sector_t block, |
1339 | sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags) | |
fb2dce86 | 1340 | { |
233bde21 BVA |
1341 | return blkdev_issue_discard(sb->s_bdev, |
1342 | block << (sb->s_blocksize_bits - | |
1343 | SECTOR_SHIFT), | |
1344 | nr_blocks << (sb->s_blocksize_bits - | |
1345 | SECTOR_SHIFT), | |
2cf6d26a | 1346 | gfp_mask, flags); |
fb2dce86 | 1347 | } |
e6fa0be6 | 1348 | static inline int sb_issue_zeroout(struct super_block *sb, sector_t block, |
a107e5a3 | 1349 | sector_t nr_blocks, gfp_t gfp_mask) |
e6fa0be6 LC |
1350 | { |
1351 | return blkdev_issue_zeroout(sb->s_bdev, | |
233bde21 BVA |
1352 | block << (sb->s_blocksize_bits - |
1353 | SECTOR_SHIFT), | |
1354 | nr_blocks << (sb->s_blocksize_bits - | |
1355 | SECTOR_SHIFT), | |
ee472d83 | 1356 | gfp_mask, 0); |
e6fa0be6 | 1357 | } |
1da177e4 | 1358 | |
f00c4d80 | 1359 | extern int blk_verify_command(unsigned char *cmd, fmode_t mode); |
0b07de85 | 1360 | |
fa01b1e9 CH |
1361 | static inline bool bdev_is_partition(struct block_device *bdev) |
1362 | { | |
1363 | return bdev->bd_partno; | |
1364 | } | |
1365 | ||
eb28d31b MP |
1366 | enum blk_default_limits { |
1367 | BLK_MAX_SEGMENTS = 128, | |
1368 | BLK_SAFE_MAX_SECTORS = 255, | |
d2be537c | 1369 | BLK_DEF_MAX_SECTORS = 2560, |
eb28d31b MP |
1370 | BLK_MAX_SEGMENT_SIZE = 65536, |
1371 | BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL, | |
1372 | }; | |
0e435ac2 | 1373 | |
af2c68fe | 1374 | static inline unsigned long queue_segment_boundary(const struct request_queue *q) |
ae03bf63 | 1375 | { |
025146e1 | 1376 | return q->limits.seg_boundary_mask; |
ae03bf63 MP |
1377 | } |
1378 | ||
af2c68fe | 1379 | static inline unsigned long queue_virt_boundary(const struct request_queue *q) |
03100aad KB |
1380 | { |
1381 | return q->limits.virt_boundary_mask; | |
1382 | } | |
1383 | ||
af2c68fe | 1384 | static inline unsigned int queue_max_sectors(const struct request_queue *q) |
ae03bf63 | 1385 | { |
025146e1 | 1386 | return q->limits.max_sectors; |
ae03bf63 MP |
1387 | } |
1388 | ||
af2c68fe | 1389 | static inline unsigned int queue_max_hw_sectors(const struct request_queue *q) |
ae03bf63 | 1390 | { |
025146e1 | 1391 | return q->limits.max_hw_sectors; |
ae03bf63 MP |
1392 | } |
1393 | ||
af2c68fe | 1394 | static inline unsigned short queue_max_segments(const struct request_queue *q) |
ae03bf63 | 1395 | { |
8a78362c | 1396 | return q->limits.max_segments; |
ae03bf63 MP |
1397 | } |
1398 | ||
af2c68fe | 1399 | static inline unsigned short queue_max_discard_segments(const struct request_queue *q) |
1e739730 CH |
1400 | { |
1401 | return q->limits.max_discard_segments; | |
1402 | } | |
1403 | ||
af2c68fe | 1404 | static inline unsigned int queue_max_segment_size(const struct request_queue *q) |
ae03bf63 | 1405 | { |
025146e1 | 1406 | return q->limits.max_segment_size; |
ae03bf63 MP |
1407 | } |
1408 | ||
0512a75b KB |
1409 | static inline unsigned int queue_max_zone_append_sectors(const struct request_queue *q) |
1410 | { | |
fe6f0cdc JT |
1411 | |
1412 | const struct queue_limits *l = &q->limits; | |
1413 | ||
1414 | return min(l->max_zone_append_sectors, l->max_sectors); | |
0512a75b KB |
1415 | } |
1416 | ||
ad6bf88a | 1417 | static inline unsigned queue_logical_block_size(const struct request_queue *q) |
1da177e4 LT |
1418 | { |
1419 | int retval = 512; | |
1420 | ||
025146e1 MP |
1421 | if (q && q->limits.logical_block_size) |
1422 | retval = q->limits.logical_block_size; | |
1da177e4 LT |
1423 | |
1424 | return retval; | |
1425 | } | |
1426 | ||
ad6bf88a | 1427 | static inline unsigned int bdev_logical_block_size(struct block_device *bdev) |
1da177e4 | 1428 | { |
e1defc4f | 1429 | return queue_logical_block_size(bdev_get_queue(bdev)); |
1da177e4 LT |
1430 | } |
1431 | ||
af2c68fe | 1432 | static inline unsigned int queue_physical_block_size(const struct request_queue *q) |
c72758f3 MP |
1433 | { |
1434 | return q->limits.physical_block_size; | |
1435 | } | |
1436 | ||
892b6f90 | 1437 | static inline unsigned int bdev_physical_block_size(struct block_device *bdev) |
ac481c20 MP |
1438 | { |
1439 | return queue_physical_block_size(bdev_get_queue(bdev)); | |
1440 | } | |
1441 | ||
af2c68fe | 1442 | static inline unsigned int queue_io_min(const struct request_queue *q) |
c72758f3 MP |
1443 | { |
1444 | return q->limits.io_min; | |
1445 | } | |
1446 | ||
ac481c20 MP |
1447 | static inline int bdev_io_min(struct block_device *bdev) |
1448 | { | |
1449 | return queue_io_min(bdev_get_queue(bdev)); | |
1450 | } | |
1451 | ||
af2c68fe | 1452 | static inline unsigned int queue_io_opt(const struct request_queue *q) |
c72758f3 MP |
1453 | { |
1454 | return q->limits.io_opt; | |
1455 | } | |
1456 | ||
ac481c20 MP |
1457 | static inline int bdev_io_opt(struct block_device *bdev) |
1458 | { | |
1459 | return queue_io_opt(bdev_get_queue(bdev)); | |
1460 | } | |
1461 | ||
a805a4fa DLM |
1462 | static inline unsigned int |
1463 | queue_zone_write_granularity(const struct request_queue *q) | |
1464 | { | |
1465 | return q->limits.zone_write_granularity; | |
1466 | } | |
1467 | ||
1468 | static inline unsigned int | |
1469 | bdev_zone_write_granularity(struct block_device *bdev) | |
1470 | { | |
1471 | return queue_zone_write_granularity(bdev_get_queue(bdev)); | |
1472 | } | |
1473 | ||
af2c68fe | 1474 | static inline int queue_alignment_offset(const struct request_queue *q) |
c72758f3 | 1475 | { |
ac481c20 | 1476 | if (q->limits.misaligned) |
c72758f3 MP |
1477 | return -1; |
1478 | ||
ac481c20 | 1479 | return q->limits.alignment_offset; |
c72758f3 MP |
1480 | } |
1481 | ||
e03a72e1 | 1482 | static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector) |
81744ee4 MP |
1483 | { |
1484 | unsigned int granularity = max(lim->physical_block_size, lim->io_min); | |
233bde21 BVA |
1485 | unsigned int alignment = sector_div(sector, granularity >> SECTOR_SHIFT) |
1486 | << SECTOR_SHIFT; | |
81744ee4 | 1487 | |
b8839b8c | 1488 | return (granularity + lim->alignment_offset - alignment) % granularity; |
c72758f3 MP |
1489 | } |
1490 | ||
ac481c20 MP |
1491 | static inline int bdev_alignment_offset(struct block_device *bdev) |
1492 | { | |
1493 | struct request_queue *q = bdev_get_queue(bdev); | |
1494 | ||
1495 | if (q->limits.misaligned) | |
1496 | return -1; | |
fa01b1e9 | 1497 | if (bdev_is_partition(bdev)) |
7b8917f5 | 1498 | return queue_limit_alignment_offset(&q->limits, |
29ff57c6 | 1499 | bdev->bd_start_sect); |
ac481c20 MP |
1500 | return q->limits.alignment_offset; |
1501 | } | |
1502 | ||
af2c68fe | 1503 | static inline int queue_discard_alignment(const struct request_queue *q) |
86b37281 MP |
1504 | { |
1505 | if (q->limits.discard_misaligned) | |
1506 | return -1; | |
1507 | ||
1508 | return q->limits.discard_alignment; | |
1509 | } | |
1510 | ||
e03a72e1 | 1511 | static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector) |
86b37281 | 1512 | { |
59771079 | 1513 | unsigned int alignment, granularity, offset; |
dd3d145d | 1514 | |
a934a00a MP |
1515 | if (!lim->max_discard_sectors) |
1516 | return 0; | |
1517 | ||
59771079 | 1518 | /* Why are these in bytes, not sectors? */ |
233bde21 BVA |
1519 | alignment = lim->discard_alignment >> SECTOR_SHIFT; |
1520 | granularity = lim->discard_granularity >> SECTOR_SHIFT; | |
59771079 LT |
1521 | if (!granularity) |
1522 | return 0; | |
1523 | ||
1524 | /* Offset of the partition start in 'granularity' sectors */ | |
1525 | offset = sector_div(sector, granularity); | |
1526 | ||
1527 | /* And why do we do this modulus *again* in blkdev_issue_discard()? */ | |
1528 | offset = (granularity + alignment - offset) % granularity; | |
1529 | ||
1530 | /* Turn it back into bytes, gaah */ | |
233bde21 | 1531 | return offset << SECTOR_SHIFT; |
86b37281 MP |
1532 | } |
1533 | ||
c6e66634 PB |
1534 | static inline int bdev_discard_alignment(struct block_device *bdev) |
1535 | { | |
1536 | struct request_queue *q = bdev_get_queue(bdev); | |
1537 | ||
fa01b1e9 | 1538 | if (bdev_is_partition(bdev)) |
7cf34d97 | 1539 | return queue_limit_discard_alignment(&q->limits, |
29ff57c6 | 1540 | bdev->bd_start_sect); |
c6e66634 PB |
1541 | return q->limits.discard_alignment; |
1542 | } | |
1543 | ||
4363ac7c MP |
1544 | static inline unsigned int bdev_write_same(struct block_device *bdev) |
1545 | { | |
1546 | struct request_queue *q = bdev_get_queue(bdev); | |
1547 | ||
1548 | if (q) | |
1549 | return q->limits.max_write_same_sectors; | |
1550 | ||
1551 | return 0; | |
1552 | } | |
1553 | ||
a6f0788e CK |
1554 | static inline unsigned int bdev_write_zeroes_sectors(struct block_device *bdev) |
1555 | { | |
1556 | struct request_queue *q = bdev_get_queue(bdev); | |
1557 | ||
1558 | if (q) | |
1559 | return q->limits.max_write_zeroes_sectors; | |
1560 | ||
1561 | return 0; | |
1562 | } | |
1563 | ||
797476b8 DLM |
1564 | static inline enum blk_zoned_model bdev_zoned_model(struct block_device *bdev) |
1565 | { | |
1566 | struct request_queue *q = bdev_get_queue(bdev); | |
1567 | ||
1568 | if (q) | |
1569 | return blk_queue_zoned_model(q); | |
1570 | ||
1571 | return BLK_ZONED_NONE; | |
1572 | } | |
1573 | ||
1574 | static inline bool bdev_is_zoned(struct block_device *bdev) | |
1575 | { | |
1576 | struct request_queue *q = bdev_get_queue(bdev); | |
1577 | ||
1578 | if (q) | |
1579 | return blk_queue_is_zoned(q); | |
1580 | ||
1581 | return false; | |
1582 | } | |
1583 | ||
113ab72e | 1584 | static inline sector_t bdev_zone_sectors(struct block_device *bdev) |
6a0cb1bc HR |
1585 | { |
1586 | struct request_queue *q = bdev_get_queue(bdev); | |
1587 | ||
1588 | if (q) | |
f99e8648 | 1589 | return blk_queue_zone_sectors(q); |
6cc77e9c CH |
1590 | return 0; |
1591 | } | |
6a0cb1bc | 1592 | |
e15864f8 NC |
1593 | static inline unsigned int bdev_max_open_zones(struct block_device *bdev) |
1594 | { | |
1595 | struct request_queue *q = bdev_get_queue(bdev); | |
1596 | ||
1597 | if (q) | |
1598 | return queue_max_open_zones(q); | |
1599 | return 0; | |
1600 | } | |
1601 | ||
659bf827 NC |
1602 | static inline unsigned int bdev_max_active_zones(struct block_device *bdev) |
1603 | { | |
1604 | struct request_queue *q = bdev_get_queue(bdev); | |
1605 | ||
1606 | if (q) | |
1607 | return queue_max_active_zones(q); | |
1608 | return 0; | |
1609 | } | |
1610 | ||
af2c68fe | 1611 | static inline int queue_dma_alignment(const struct request_queue *q) |
1da177e4 | 1612 | { |
482eb689 | 1613 | return q ? q->dma_alignment : 511; |
1da177e4 LT |
1614 | } |
1615 | ||
14417799 | 1616 | static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr, |
87904074 FT |
1617 | unsigned int len) |
1618 | { | |
1619 | unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask; | |
14417799 | 1620 | return !(addr & alignment) && !(len & alignment); |
87904074 FT |
1621 | } |
1622 | ||
1da177e4 LT |
1623 | /* assumes size > 256 */ |
1624 | static inline unsigned int blksize_bits(unsigned int size) | |
1625 | { | |
1626 | unsigned int bits = 8; | |
1627 | do { | |
1628 | bits++; | |
1629 | size >>= 1; | |
1630 | } while (size > 256); | |
1631 | return bits; | |
1632 | } | |
1633 | ||
2befb9e3 | 1634 | static inline unsigned int block_size(struct block_device *bdev) |
1da177e4 | 1635 | { |
6b7b181b | 1636 | return 1 << bdev->bd_inode->i_blkbits; |
1da177e4 LT |
1637 | } |
1638 | ||
59c3d45e | 1639 | int kblockd_schedule_work(struct work_struct *work); |
818cd1cb | 1640 | int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay); |
1da177e4 | 1641 | |
1da177e4 LT |
1642 | #define MODULE_ALIAS_BLOCKDEV(major,minor) \ |
1643 | MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor)) | |
1644 | #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \ | |
1645 | MODULE_ALIAS("block-major-" __stringify(major) "-*") | |
1646 | ||
7ba1ba12 MP |
1647 | #if defined(CONFIG_BLK_DEV_INTEGRITY) |
1648 | ||
8288f496 MP |
1649 | enum blk_integrity_flags { |
1650 | BLK_INTEGRITY_VERIFY = 1 << 0, | |
1651 | BLK_INTEGRITY_GENERATE = 1 << 1, | |
3aec2f41 | 1652 | BLK_INTEGRITY_DEVICE_CAPABLE = 1 << 2, |
aae7df50 | 1653 | BLK_INTEGRITY_IP_CHECKSUM = 1 << 3, |
8288f496 | 1654 | }; |
7ba1ba12 | 1655 | |
18593088 | 1656 | struct blk_integrity_iter { |
7ba1ba12 MP |
1657 | void *prot_buf; |
1658 | void *data_buf; | |
3be91c4a | 1659 | sector_t seed; |
7ba1ba12 | 1660 | unsigned int data_size; |
3be91c4a | 1661 | unsigned short interval; |
7ba1ba12 MP |
1662 | const char *disk_name; |
1663 | }; | |
1664 | ||
4e4cbee9 | 1665 | typedef blk_status_t (integrity_processing_fn) (struct blk_integrity_iter *); |
54d4e6ab MG |
1666 | typedef void (integrity_prepare_fn) (struct request *); |
1667 | typedef void (integrity_complete_fn) (struct request *, unsigned int); | |
7ba1ba12 | 1668 | |
0f8087ec MP |
1669 | struct blk_integrity_profile { |
1670 | integrity_processing_fn *generate_fn; | |
1671 | integrity_processing_fn *verify_fn; | |
54d4e6ab MG |
1672 | integrity_prepare_fn *prepare_fn; |
1673 | integrity_complete_fn *complete_fn; | |
0f8087ec MP |
1674 | const char *name; |
1675 | }; | |
7ba1ba12 | 1676 | |
25520d55 | 1677 | extern void blk_integrity_register(struct gendisk *, struct blk_integrity *); |
7ba1ba12 | 1678 | extern void blk_integrity_unregister(struct gendisk *); |
ad7fce93 | 1679 | extern int blk_integrity_compare(struct gendisk *, struct gendisk *); |
13f05c8d MP |
1680 | extern int blk_rq_map_integrity_sg(struct request_queue *, struct bio *, |
1681 | struct scatterlist *); | |
1682 | extern int blk_rq_count_integrity_sg(struct request_queue *, struct bio *); | |
7ba1ba12 | 1683 | |
25520d55 | 1684 | static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) |
b04accc4 | 1685 | { |
ac6fc48c | 1686 | struct blk_integrity *bi = &disk->queue->integrity; |
25520d55 MP |
1687 | |
1688 | if (!bi->profile) | |
1689 | return NULL; | |
1690 | ||
1691 | return bi; | |
b04accc4 JA |
1692 | } |
1693 | ||
25520d55 MP |
1694 | static inline |
1695 | struct blk_integrity *bdev_get_integrity(struct block_device *bdev) | |
b02739b0 | 1696 | { |
25520d55 | 1697 | return blk_get_integrity(bdev->bd_disk); |
b02739b0 MP |
1698 | } |
1699 | ||
d145dc23 ST |
1700 | static inline bool |
1701 | blk_integrity_queue_supports_integrity(struct request_queue *q) | |
1702 | { | |
1703 | return q->integrity.profile; | |
1704 | } | |
1705 | ||
180b2f95 | 1706 | static inline bool blk_integrity_rq(struct request *rq) |
7ba1ba12 | 1707 | { |
180b2f95 | 1708 | return rq->cmd_flags & REQ_INTEGRITY; |
7ba1ba12 MP |
1709 | } |
1710 | ||
13f05c8d MP |
1711 | static inline void blk_queue_max_integrity_segments(struct request_queue *q, |
1712 | unsigned int segs) | |
1713 | { | |
1714 | q->limits.max_integrity_segments = segs; | |
1715 | } | |
1716 | ||
1717 | static inline unsigned short | |
af2c68fe | 1718 | queue_max_integrity_segments(const struct request_queue *q) |
13f05c8d MP |
1719 | { |
1720 | return q->limits.max_integrity_segments; | |
1721 | } | |
1722 | ||
359f6427 GE |
1723 | /** |
1724 | * bio_integrity_intervals - Return number of integrity intervals for a bio | |
1725 | * @bi: blk_integrity profile for device | |
1726 | * @sectors: Size of the bio in 512-byte sectors | |
1727 | * | |
1728 | * Description: The block layer calculates everything in 512 byte | |
1729 | * sectors but integrity metadata is done in terms of the data integrity | |
1730 | * interval size of the storage device. Convert the block layer sectors | |
1731 | * to the appropriate number of integrity intervals. | |
1732 | */ | |
1733 | static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, | |
1734 | unsigned int sectors) | |
1735 | { | |
1736 | return sectors >> (bi->interval_exp - 9); | |
1737 | } | |
1738 | ||
1739 | static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, | |
1740 | unsigned int sectors) | |
1741 | { | |
1742 | return bio_integrity_intervals(bi, sectors) * bi->tuple_size; | |
1743 | } | |
1744 | ||
2a876f5e CH |
1745 | /* |
1746 | * Return the first bvec that contains integrity data. Only drivers that are | |
1747 | * limited to a single integrity segment should use this helper. | |
1748 | */ | |
1749 | static inline struct bio_vec *rq_integrity_vec(struct request *rq) | |
1750 | { | |
1751 | if (WARN_ON_ONCE(queue_max_integrity_segments(rq->q) > 1)) | |
1752 | return NULL; | |
1753 | return rq->bio->bi_integrity->bip_vec; | |
1754 | } | |
1755 | ||
7ba1ba12 MP |
1756 | #else /* CONFIG_BLK_DEV_INTEGRITY */ |
1757 | ||
fd83240a SR |
1758 | struct bio; |
1759 | struct block_device; | |
1760 | struct gendisk; | |
1761 | struct blk_integrity; | |
1762 | ||
1763 | static inline int blk_integrity_rq(struct request *rq) | |
1764 | { | |
1765 | return 0; | |
1766 | } | |
1767 | static inline int blk_rq_count_integrity_sg(struct request_queue *q, | |
1768 | struct bio *b) | |
1769 | { | |
1770 | return 0; | |
1771 | } | |
1772 | static inline int blk_rq_map_integrity_sg(struct request_queue *q, | |
1773 | struct bio *b, | |
1774 | struct scatterlist *s) | |
1775 | { | |
1776 | return 0; | |
1777 | } | |
1778 | static inline struct blk_integrity *bdev_get_integrity(struct block_device *b) | |
1779 | { | |
61a04e5b | 1780 | return NULL; |
fd83240a SR |
1781 | } |
1782 | static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) | |
1783 | { | |
1784 | return NULL; | |
1785 | } | |
d145dc23 ST |
1786 | static inline bool |
1787 | blk_integrity_queue_supports_integrity(struct request_queue *q) | |
1788 | { | |
1789 | return false; | |
1790 | } | |
fd83240a SR |
1791 | static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b) |
1792 | { | |
1793 | return 0; | |
1794 | } | |
25520d55 | 1795 | static inline void blk_integrity_register(struct gendisk *d, |
fd83240a SR |
1796 | struct blk_integrity *b) |
1797 | { | |
fd83240a SR |
1798 | } |
1799 | static inline void blk_integrity_unregister(struct gendisk *d) | |
1800 | { | |
1801 | } | |
1802 | static inline void blk_queue_max_integrity_segments(struct request_queue *q, | |
1803 | unsigned int segs) | |
1804 | { | |
1805 | } | |
af2c68fe | 1806 | static inline unsigned short queue_max_integrity_segments(const struct request_queue *q) |
fd83240a SR |
1807 | { |
1808 | return 0; | |
1809 | } | |
25520d55 | 1810 | |
359f6427 GE |
1811 | static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, |
1812 | unsigned int sectors) | |
1813 | { | |
1814 | return 0; | |
1815 | } | |
1816 | ||
1817 | static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, | |
1818 | unsigned int sectors) | |
1819 | { | |
1820 | return 0; | |
1821 | } | |
1822 | ||
2a876f5e CH |
1823 | static inline struct bio_vec *rq_integrity_vec(struct request *rq) |
1824 | { | |
1825 | return NULL; | |
1826 | } | |
1827 | ||
7ba1ba12 MP |
1828 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ |
1829 | ||
d145dc23 ST |
1830 | #ifdef CONFIG_BLK_INLINE_ENCRYPTION |
1831 | ||
1832 | bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q); | |
1833 | ||
1834 | void blk_ksm_unregister(struct request_queue *q); | |
1835 | ||
1836 | #else /* CONFIG_BLK_INLINE_ENCRYPTION */ | |
1837 | ||
1838 | static inline bool blk_ksm_register(struct blk_keyslot_manager *ksm, | |
1839 | struct request_queue *q) | |
1840 | { | |
1841 | return true; | |
1842 | } | |
1843 | ||
1844 | static inline void blk_ksm_unregister(struct request_queue *q) { } | |
1845 | ||
1846 | #endif /* CONFIG_BLK_INLINE_ENCRYPTION */ | |
1847 | ||
1848 | ||
08f85851 | 1849 | struct block_device_operations { |
c62b37d9 | 1850 | blk_qc_t (*submit_bio) (struct bio *bio); |
d4430d62 | 1851 | int (*open) (struct block_device *, fmode_t); |
db2a144b | 1852 | void (*release) (struct gendisk *, fmode_t); |
3f289dcb | 1853 | int (*rw_page)(struct block_device *, sector_t, struct page *, unsigned int); |
d4430d62 AV |
1854 | int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); |
1855 | int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); | |
77ea887e TH |
1856 | unsigned int (*check_events) (struct gendisk *disk, |
1857 | unsigned int clearing); | |
c3e33e04 | 1858 | void (*unlock_native_capacity) (struct gendisk *); |
08f85851 | 1859 | int (*getgeo)(struct block_device *, struct hd_geometry *); |
e00adcad | 1860 | int (*set_read_only)(struct block_device *bdev, bool ro); |
b3a27d05 NG |
1861 | /* this callback is with swap_lock and sometimes page table lock held */ |
1862 | void (*swap_slot_free_notify) (struct block_device *, unsigned long); | |
e76239a3 | 1863 | int (*report_zones)(struct gendisk *, sector_t sector, |
d4100351 | 1864 | unsigned int nr_zones, report_zones_cb cb, void *data); |
348e114b | 1865 | char *(*devnode)(struct gendisk *disk, umode_t *mode); |
08f85851 | 1866 | struct module *owner; |
bbd3e064 | 1867 | const struct pr_ops *pr_ops; |
08f85851 AV |
1868 | }; |
1869 | ||
ee6a129d AB |
1870 | #ifdef CONFIG_COMPAT |
1871 | extern int blkdev_compat_ptr_ioctl(struct block_device *, fmode_t, | |
1872 | unsigned int, unsigned long); | |
1873 | #else | |
1874 | #define blkdev_compat_ptr_ioctl NULL | |
1875 | #endif | |
1876 | ||
47a191fd MW |
1877 | extern int bdev_read_page(struct block_device *, sector_t, struct page *); |
1878 | extern int bdev_write_page(struct block_device *, sector_t, struct page *, | |
1879 | struct writeback_control *); | |
6cc77e9c CH |
1880 | |
1881 | #ifdef CONFIG_BLK_DEV_ZONED | |
1882 | bool blk_req_needs_zone_write_lock(struct request *rq); | |
1392d370 | 1883 | bool blk_req_zone_write_trylock(struct request *rq); |
6cc77e9c CH |
1884 | void __blk_req_zone_write_lock(struct request *rq); |
1885 | void __blk_req_zone_write_unlock(struct request *rq); | |
1886 | ||
1887 | static inline void blk_req_zone_write_lock(struct request *rq) | |
1888 | { | |
1889 | if (blk_req_needs_zone_write_lock(rq)) | |
1890 | __blk_req_zone_write_lock(rq); | |
1891 | } | |
1892 | ||
1893 | static inline void blk_req_zone_write_unlock(struct request *rq) | |
1894 | { | |
1895 | if (rq->rq_flags & RQF_ZONE_WRITE_LOCKED) | |
1896 | __blk_req_zone_write_unlock(rq); | |
1897 | } | |
1898 | ||
1899 | static inline bool blk_req_zone_is_write_locked(struct request *rq) | |
1900 | { | |
1901 | return rq->q->seq_zones_wlock && | |
1902 | test_bit(blk_rq_zone_no(rq), rq->q->seq_zones_wlock); | |
1903 | } | |
1904 | ||
1905 | static inline bool blk_req_can_dispatch_to_zone(struct request *rq) | |
1906 | { | |
1907 | if (!blk_req_needs_zone_write_lock(rq)) | |
1908 | return true; | |
1909 | return !blk_req_zone_is_write_locked(rq); | |
1910 | } | |
1911 | #else | |
1912 | static inline bool blk_req_needs_zone_write_lock(struct request *rq) | |
1913 | { | |
1914 | return false; | |
1915 | } | |
1916 | ||
1917 | static inline void blk_req_zone_write_lock(struct request *rq) | |
1918 | { | |
1919 | } | |
1920 | ||
1921 | static inline void blk_req_zone_write_unlock(struct request *rq) | |
1922 | { | |
1923 | } | |
1924 | static inline bool blk_req_zone_is_write_locked(struct request *rq) | |
1925 | { | |
1926 | return false; | |
1927 | } | |
1928 | ||
1929 | static inline bool blk_req_can_dispatch_to_zone(struct request *rq) | |
1930 | { | |
1931 | return true; | |
1932 | } | |
1933 | #endif /* CONFIG_BLK_DEV_ZONED */ | |
1934 | ||
0619317f JA |
1935 | static inline void blk_wake_io_task(struct task_struct *waiter) |
1936 | { | |
1937 | /* | |
1938 | * If we're polling, the task itself is doing the completions. For | |
1939 | * that case, we don't need to signal a wakeup, it's enough to just | |
1940 | * mark us as RUNNING. | |
1941 | */ | |
1942 | if (waiter == current) | |
1943 | __set_current_state(TASK_RUNNING); | |
1944 | else | |
1945 | wake_up_process(waiter); | |
1946 | } | |
1947 | ||
956d510e CH |
1948 | unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, |
1949 | unsigned int op); | |
1950 | void disk_end_io_acct(struct gendisk *disk, unsigned int op, | |
1951 | unsigned long start_time); | |
1952 | ||
99dfc43e CH |
1953 | unsigned long bio_start_io_acct(struct bio *bio); |
1954 | void bio_end_io_acct_remapped(struct bio *bio, unsigned long start_time, | |
1955 | struct block_device *orig_bdev); | |
956d510e CH |
1956 | |
1957 | /** | |
1958 | * bio_end_io_acct - end I/O accounting for bio based drivers | |
1959 | * @bio: bio to end account for | |
1960 | * @start: start time returned by bio_start_io_acct() | |
1961 | */ | |
1962 | static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time) | |
1963 | { | |
99dfc43e | 1964 | return bio_end_io_acct_remapped(bio, start_time, bio->bi_bdev); |
956d510e | 1965 | } |
956d510e | 1966 | |
3f1266f1 CH |
1967 | int bdev_read_only(struct block_device *bdev); |
1968 | int set_blocksize(struct block_device *bdev, int size); | |
1969 | ||
1970 | const char *bdevname(struct block_device *bdev, char *buffer); | |
4e7b5671 | 1971 | int lookup_bdev(const char *pathname, dev_t *dev); |
3f1266f1 CH |
1972 | |
1973 | void blkdev_show(struct seq_file *seqf, off_t offset); | |
1974 | ||
1975 | #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ | |
1976 | #define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */ | |
1977 | #ifdef CONFIG_BLOCK | |
1978 | #define BLKDEV_MAJOR_MAX 512 | |
1979 | #else | |
1980 | #define BLKDEV_MAJOR_MAX 0 | |
1981 | #endif | |
1982 | ||
3f1266f1 CH |
1983 | struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, |
1984 | void *holder); | |
1985 | struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder); | |
37c3fc9a CH |
1986 | int bd_prepare_to_claim(struct block_device *bdev, void *holder); |
1987 | void bd_abort_claiming(struct block_device *bdev, void *holder); | |
3f1266f1 CH |
1988 | void blkdev_put(struct block_device *bdev, fmode_t mode); |
1989 | ||
22ae8ce8 CH |
1990 | /* just for blk-cgroup, don't use elsewhere */ |
1991 | struct block_device *blkdev_get_no_open(dev_t dev); | |
1992 | void blkdev_put_no_open(struct block_device *bdev); | |
1993 | ||
1994 | struct block_device *bdev_alloc(struct gendisk *disk, u8 partno); | |
1995 | void bdev_add(struct block_device *bdev, dev_t dev); | |
621c1f42 | 1996 | struct block_device *I_BDEV(struct inode *inode); |
3f1266f1 CH |
1997 | struct block_device *bdgrab(struct block_device *bdev); |
1998 | void bdput(struct block_device *); | |
2c2b9fd6 CH |
1999 | int truncate_bdev_range(struct block_device *bdev, fmode_t mode, loff_t lstart, |
2000 | loff_t lend); | |
3f1266f1 CH |
2001 | |
2002 | #ifdef CONFIG_BLOCK | |
2003 | void invalidate_bdev(struct block_device *bdev); | |
2004 | int sync_blockdev(struct block_device *bdev); | |
2005 | #else | |
2006 | static inline void invalidate_bdev(struct block_device *bdev) | |
2007 | { | |
2008 | } | |
2009 | static inline int sync_blockdev(struct block_device *bdev) | |
2010 | { | |
2011 | return 0; | |
2012 | } | |
1da177e4 | 2013 | #endif |
3f1266f1 CH |
2014 | int fsync_bdev(struct block_device *bdev); |
2015 | ||
040f04bd CH |
2016 | int freeze_bdev(struct block_device *bdev); |
2017 | int thaw_bdev(struct block_device *bdev); | |
3f1266f1 CH |
2018 | |
2019 | #endif /* _LINUX_BLKDEV_H */ |