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