]>
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> |
1da177e4 LT |
6 | #include <linux/genhd.h> |
7 | #include <linux/list.h> | |
320ae51f | 8 | #include <linux/llist.h> |
b296a6d5 | 9 | #include <linux/minmax.h> |
1da177e4 LT |
10 | #include <linux/timer.h> |
11 | #include <linux/workqueue.h> | |
1da177e4 | 12 | #include <linux/wait.h> |
1da177e4 | 13 | #include <linux/bio.h> |
3e6053d7 | 14 | #include <linux/gfp.h> |
548bc8e1 | 15 | #include <linux/rcupdate.h> |
add703fd | 16 | #include <linux/percpu-refcount.h> |
6a0cb1bc | 17 | #include <linux/blkzoned.h> |
d97e594c | 18 | #include <linux/sbitmap.h> |
1da177e4 | 19 | |
de477254 | 20 | struct module; |
1da177e4 | 21 | struct request_queue; |
1da177e4 | 22 | struct elevator_queue; |
2056a782 | 23 | struct blk_trace; |
3d6392cf JA |
24 | struct request; |
25 | struct sg_io_hdr; | |
3c798398 | 26 | struct blkcg_gq; |
7c94e1c1 | 27 | struct blk_flush_queue; |
3e08773c | 28 | struct kiocb; |
bbd3e064 | 29 | struct pr_ops; |
a7905043 | 30 | struct rq_qos; |
34dbad5d OS |
31 | struct blk_queue_stats; |
32 | struct blk_stat_callback; | |
cb77cb5a | 33 | struct blk_crypto_profile; |
1da177e4 | 34 | |
096392e0 | 35 | /* Must be consistent with blk_mq_poll_stats_bkt() */ |
0206319f SB |
36 | #define BLK_MQ_POLL_STATS_BKTS 16 |
37 | ||
29ece8b4 YY |
38 | /* Doing classic polling */ |
39 | #define BLK_MQ_POLL_CLASSIC -1 | |
40 | ||
8bd435b3 TH |
41 | /* |
42 | * Maximum number of blkcg policies allowed to be registered concurrently. | |
43 | * Defined here to simplify include dependency. | |
44 | */ | |
ec645dc9 | 45 | #define BLKCG_MAX_POLS 6 |
8bd435b3 | 46 | |
570b1cac XY |
47 | static inline int blk_validate_block_size(unsigned int bsize) |
48 | { | |
49 | if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize)) | |
50 | return -EINVAL; | |
51 | ||
52 | return 0; | |
53 | } | |
54 | ||
da6269da | 55 | static inline bool blk_op_is_passthrough(unsigned int op) |
14cb0dc6 | 56 | { |
da6269da | 57 | op &= REQ_OP_MASK; |
14cb0dc6 ML |
58 | return op == REQ_OP_DRV_IN || op == REQ_OP_DRV_OUT; |
59 | } | |
60 | ||
797476b8 DLM |
61 | /* |
62 | * Zoned block device models (zoned limit). | |
3093a479 CH |
63 | * |
64 | * Note: This needs to be ordered from the least to the most severe | |
65 | * restrictions for the inheritance in blk_stack_limits() to work. | |
797476b8 DLM |
66 | */ |
67 | enum blk_zoned_model { | |
3093a479 CH |
68 | BLK_ZONED_NONE = 0, /* Regular block device */ |
69 | BLK_ZONED_HA, /* Host-aware zoned block device */ | |
70 | BLK_ZONED_HM, /* Host-managed zoned block device */ | |
797476b8 DLM |
71 | }; |
72 | ||
9bb33f24 CH |
73 | /* |
74 | * BLK_BOUNCE_NONE: never bounce (default) | |
75 | * BLK_BOUNCE_HIGH: bounce all highmem pages | |
76 | */ | |
77 | enum blk_bounce { | |
78 | BLK_BOUNCE_NONE, | |
79 | BLK_BOUNCE_HIGH, | |
80 | }; | |
81 | ||
025146e1 | 82 | struct queue_limits { |
9bb33f24 | 83 | enum blk_bounce bounce; |
025146e1 | 84 | unsigned long seg_boundary_mask; |
03100aad | 85 | unsigned long virt_boundary_mask; |
025146e1 MP |
86 | |
87 | unsigned int max_hw_sectors; | |
ca369d51 | 88 | unsigned int max_dev_sectors; |
762380ad | 89 | unsigned int chunk_sectors; |
025146e1 MP |
90 | unsigned int max_sectors; |
91 | unsigned int max_segment_size; | |
c72758f3 | 92 | unsigned int physical_block_size; |
ad6bf88a | 93 | unsigned int logical_block_size; |
c72758f3 MP |
94 | unsigned int alignment_offset; |
95 | unsigned int io_min; | |
96 | unsigned int io_opt; | |
67efc925 | 97 | unsigned int max_discard_sectors; |
0034af03 | 98 | unsigned int max_hw_discard_sectors; |
4363ac7c | 99 | unsigned int max_write_same_sectors; |
a6f0788e | 100 | unsigned int max_write_zeroes_sectors; |
0512a75b | 101 | unsigned int max_zone_append_sectors; |
86b37281 MP |
102 | unsigned int discard_granularity; |
103 | unsigned int discard_alignment; | |
a805a4fa | 104 | unsigned int zone_write_granularity; |
025146e1 | 105 | |
8a78362c | 106 | unsigned short max_segments; |
13f05c8d | 107 | unsigned short max_integrity_segments; |
1e739730 | 108 | unsigned short max_discard_segments; |
025146e1 | 109 | |
c72758f3 | 110 | unsigned char misaligned; |
86b37281 | 111 | unsigned char discard_misaligned; |
c78afc62 | 112 | unsigned char raid_partial_stripes_expensive; |
797476b8 | 113 | enum blk_zoned_model zoned; |
025146e1 MP |
114 | }; |
115 | ||
d4100351 CH |
116 | typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx, |
117 | void *data); | |
118 | ||
27ba3e8f DLM |
119 | void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model); |
120 | ||
6a0cb1bc HR |
121 | #ifdef CONFIG_BLK_DEV_ZONED |
122 | ||
d4100351 CH |
123 | #define BLK_ALL_ZONES ((unsigned int)-1) |
124 | int blkdev_report_zones(struct block_device *bdev, sector_t sector, | |
125 | unsigned int nr_zones, report_zones_cb cb, void *data); | |
9b38bb4b | 126 | unsigned int blkdev_nr_zones(struct gendisk *disk); |
6c1b1da5 AJ |
127 | extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op, |
128 | sector_t sectors, sector_t nr_sectors, | |
129 | gfp_t gfp_mask); | |
e732671a DLM |
130 | int blk_revalidate_disk_zones(struct gendisk *disk, |
131 | void (*update_driver_data)(struct gendisk *disk)); | |
6a0cb1bc | 132 | |
3ed05a98 ST |
133 | extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, |
134 | unsigned int cmd, unsigned long arg); | |
e876df1f AJ |
135 | extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, |
136 | unsigned int cmd, unsigned long arg); | |
3ed05a98 ST |
137 | |
138 | #else /* CONFIG_BLK_DEV_ZONED */ | |
139 | ||
9b38bb4b | 140 | static inline unsigned int blkdev_nr_zones(struct gendisk *disk) |
a91e1380 DLM |
141 | { |
142 | return 0; | |
143 | } | |
bf505456 | 144 | |
3ed05a98 ST |
145 | static inline int blkdev_report_zones_ioctl(struct block_device *bdev, |
146 | fmode_t mode, unsigned int cmd, | |
147 | unsigned long arg) | |
148 | { | |
149 | return -ENOTTY; | |
150 | } | |
151 | ||
e876df1f AJ |
152 | static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev, |
153 | fmode_t mode, unsigned int cmd, | |
154 | unsigned long arg) | |
3ed05a98 ST |
155 | { |
156 | return -ENOTTY; | |
157 | } | |
158 | ||
6a0cb1bc HR |
159 | #endif /* CONFIG_BLK_DEV_ZONED */ |
160 | ||
a2247f19 DLM |
161 | /* |
162 | * Independent access ranges: struct blk_independent_access_range describes | |
163 | * a range of contiguous sectors that can be accessed using device command | |
164 | * execution resources that are independent from the resources used for | |
165 | * other access ranges. This is typically found with single-LUN multi-actuator | |
166 | * HDDs where each access range is served by a different set of heads. | |
167 | * The set of independent ranges supported by the device is defined using | |
168 | * struct blk_independent_access_ranges. The independent ranges must not overlap | |
169 | * and must include all sectors within the disk capacity (no sector holes | |
170 | * allowed). | |
171 | * For a device with multiple ranges, requests targeting sectors in different | |
172 | * ranges can be executed in parallel. A request can straddle an access range | |
173 | * boundary. | |
174 | */ | |
175 | struct blk_independent_access_range { | |
176 | struct kobject kobj; | |
177 | struct request_queue *queue; | |
178 | sector_t sector; | |
179 | sector_t nr_sectors; | |
180 | }; | |
181 | ||
182 | struct blk_independent_access_ranges { | |
183 | struct kobject kobj; | |
184 | bool sysfs_registered; | |
185 | unsigned int nr_ia_ranges; | |
186 | struct blk_independent_access_range ia_range[]; | |
187 | }; | |
188 | ||
d7b76301 | 189 | struct request_queue { |
1da177e4 | 190 | struct request *last_merge; |
b374d18a | 191 | struct elevator_queue *elevator; |
1da177e4 | 192 | |
0549e87c ML |
193 | struct percpu_ref q_usage_counter; |
194 | ||
34dbad5d | 195 | struct blk_queue_stats *stats; |
a7905043 | 196 | struct rq_qos *rq_qos; |
87760e5e | 197 | |
f8a5b122 | 198 | const struct blk_mq_ops *mq_ops; |
320ae51f | 199 | |
320ae51f | 200 | /* sw queues */ |
e6cdb092 | 201 | struct blk_mq_ctx __percpu *queue_ctx; |
320ae51f | 202 | |
d278d4a8 JA |
203 | unsigned int queue_depth; |
204 | ||
320ae51f JA |
205 | /* hw dispatch queues */ |
206 | struct blk_mq_hw_ctx **queue_hw_ctx; | |
207 | unsigned int nr_hw_queues; | |
208 | ||
1da177e4 LT |
209 | /* |
210 | * The queue owner gets to use this for whatever they like. | |
211 | * ll_rw_blk doesn't touch it. | |
212 | */ | |
213 | void *queuedata; | |
214 | ||
1da177e4 | 215 | /* |
d7b76301 | 216 | * various queue flags, see QUEUE_* below |
1da177e4 | 217 | */ |
d7b76301 | 218 | unsigned long queue_flags; |
cd84a62e BVA |
219 | /* |
220 | * Number of contexts that have called blk_set_pm_only(). If this | |
a4d34da7 | 221 | * counter is above zero then only RQF_PM requests are processed. |
cd84a62e BVA |
222 | */ |
223 | atomic_t pm_only; | |
1da177e4 | 224 | |
a73f730d TH |
225 | /* |
226 | * ida allocated id for this queue. Used to index queues from | |
227 | * ioctx. | |
228 | */ | |
229 | int id; | |
230 | ||
0d945c1f | 231 | spinlock_t queue_lock; |
1da177e4 | 232 | |
d152c682 CH |
233 | struct gendisk *disk; |
234 | ||
1da177e4 LT |
235 | /* |
236 | * queue kobject | |
237 | */ | |
238 | struct kobject kobj; | |
239 | ||
320ae51f JA |
240 | /* |
241 | * mq queue kobject | |
242 | */ | |
1db4909e | 243 | struct kobject *mq_kobj; |
320ae51f | 244 | |
ac6fc48c DW |
245 | #ifdef CONFIG_BLK_DEV_INTEGRITY |
246 | struct blk_integrity integrity; | |
247 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ | |
248 | ||
47fafbc7 | 249 | #ifdef CONFIG_PM |
6c954667 | 250 | struct device *dev; |
db04e18d | 251 | enum rpm_status rpm_status; |
6c954667 LM |
252 | #endif |
253 | ||
1da177e4 LT |
254 | /* |
255 | * queue settings | |
256 | */ | |
257 | unsigned long nr_requests; /* Max # of requests */ | |
1da177e4 | 258 | |
e3790c7d | 259 | unsigned int dma_pad_mask; |
1da177e4 LT |
260 | unsigned int dma_alignment; |
261 | ||
1b262839 | 262 | #ifdef CONFIG_BLK_INLINE_ENCRYPTION |
cb77cb5a | 263 | struct blk_crypto_profile *crypto_profile; |
1b262839 ST |
264 | #endif |
265 | ||
242f9dcb | 266 | unsigned int rq_timeout; |
64f1c21e | 267 | int poll_nsec; |
34dbad5d OS |
268 | |
269 | struct blk_stat_callback *poll_cb; | |
48b5c1fb | 270 | struct blk_rq_stat *poll_stat; |
34dbad5d | 271 | |
242f9dcb | 272 | struct timer_list timeout; |
287922eb | 273 | struct work_struct timeout_work; |
242f9dcb | 274 | |
079a2e3e | 275 | atomic_t nr_active_requests_shared_tags; |
bccf5e26 | 276 | |
079a2e3e | 277 | struct blk_mq_tags *sched_shared_tags; |
d97e594c | 278 | |
a612fddf | 279 | struct list_head icq_list; |
4eef3049 | 280 | #ifdef CONFIG_BLK_CGROUP |
a2b1693b | 281 | DECLARE_BITMAP (blkcg_pols, BLKCG_MAX_POLS); |
3c798398 | 282 | struct blkcg_gq *root_blkg; |
03aa264a | 283 | struct list_head blkg_list; |
4eef3049 | 284 | #endif |
a612fddf | 285 | |
025146e1 MP |
286 | struct queue_limits limits; |
287 | ||
68c43f13 DLM |
288 | unsigned int required_elevator_features; |
289 | ||
6a5ac984 | 290 | #ifdef CONFIG_BLK_DEV_ZONED |
6cc77e9c CH |
291 | /* |
292 | * Zoned block device information for request dispatch control. | |
293 | * nr_zones is the total number of zones of the device. This is always | |
f216fdd7 CH |
294 | * 0 for regular block devices. conv_zones_bitmap is a bitmap of nr_zones |
295 | * bits which indicates if a zone is conventional (bit set) or | |
296 | * sequential (bit clear). seq_zones_wlock is a bitmap of nr_zones | |
6cc77e9c CH |
297 | * bits which indicates if a zone is write locked, that is, if a write |
298 | * request targeting the zone was dispatched. All three fields are | |
299 | * initialized by the low level device driver (e.g. scsi/sd.c). | |
300 | * Stacking drivers (device mappers) may or may not initialize | |
301 | * these fields. | |
ccce20fc BVA |
302 | * |
303 | * Reads of this information must be protected with blk_queue_enter() / | |
304 | * blk_queue_exit(). Modifying this information is only allowed while | |
305 | * no requests are being processed. See also blk_mq_freeze_queue() and | |
306 | * blk_mq_unfreeze_queue(). | |
6cc77e9c CH |
307 | */ |
308 | unsigned int nr_zones; | |
f216fdd7 | 309 | unsigned long *conv_zones_bitmap; |
6cc77e9c | 310 | unsigned long *seq_zones_wlock; |
e15864f8 | 311 | unsigned int max_open_zones; |
659bf827 | 312 | unsigned int max_active_zones; |
6a5ac984 | 313 | #endif /* CONFIG_BLK_DEV_ZONED */ |
6cc77e9c | 314 | |
1946089a | 315 | int node; |
85e0cbbb | 316 | struct mutex debugfs_mutex; |
6c5c9341 | 317 | #ifdef CONFIG_BLK_DEV_IO_TRACE |
c780e86d | 318 | struct blk_trace __rcu *blk_trace; |
6c5c9341 | 319 | #endif |
1da177e4 | 320 | /* |
4913efe4 | 321 | * for flush operations |
1da177e4 | 322 | */ |
7c94e1c1 | 323 | struct blk_flush_queue *fq; |
483f4afc | 324 | |
6fca6a61 CH |
325 | struct list_head requeue_list; |
326 | spinlock_t requeue_lock; | |
2849450a | 327 | struct delayed_work requeue_work; |
6fca6a61 | 328 | |
483f4afc | 329 | struct mutex sysfs_lock; |
cecf5d87 | 330 | struct mutex sysfs_dir_lock; |
d351af01 | 331 | |
2f8f1336 ML |
332 | /* |
333 | * for reusing dead hctx instance in case of updating | |
334 | * nr_hw_queues | |
335 | */ | |
336 | struct list_head unused_hctx_list; | |
337 | spinlock_t unused_hctx_lock; | |
338 | ||
7996a8b5 | 339 | int mq_freeze_depth; |
d732580b | 340 | |
e43473b7 VG |
341 | #ifdef CONFIG_BLK_DEV_THROTTLING |
342 | /* Throttle data */ | |
343 | struct throtl_data *td; | |
344 | #endif | |
548bc8e1 | 345 | struct rcu_head rcu_head; |
320ae51f | 346 | wait_queue_head_t mq_freeze_wq; |
7996a8b5 BL |
347 | /* |
348 | * Protect concurrent access to q_usage_counter by | |
349 | * percpu_ref_kill() and percpu_ref_reinit(). | |
350 | */ | |
351 | struct mutex mq_freeze_lock; | |
0d2602ca | 352 | |
e70feb8b ML |
353 | int quiesce_depth; |
354 | ||
0d2602ca JA |
355 | struct blk_mq_tag_set *tag_set; |
356 | struct list_head tag_set_list; | |
338aa96d | 357 | struct bio_set bio_split; |
4593fdbe | 358 | |
07e4fead | 359 | struct dentry *debugfs_dir; |
85e0cbbb LC |
360 | |
361 | #ifdef CONFIG_BLK_DEBUG_FS | |
d332ce09 | 362 | struct dentry *sched_debugfs_dir; |
cc56694f | 363 | struct dentry *rqos_debugfs_dir; |
07e4fead OS |
364 | #endif |
365 | ||
4593fdbe | 366 | bool mq_sysfs_init_done; |
6d247d7f | 367 | |
f793dfd3 JA |
368 | #define BLK_MAX_WRITE_HINTS 5 |
369 | u64 write_hints[BLK_MAX_WRITE_HINTS]; | |
a2247f19 DLM |
370 | |
371 | /* | |
372 | * Independent sector access ranges. This is always NULL for | |
373 | * devices that do not have multiple independent access ranges. | |
374 | */ | |
375 | struct blk_independent_access_ranges *ia_ranges; | |
1da177e4 LT |
376 | }; |
377 | ||
bfe373f6 | 378 | /* Keep blk_queue_flag_name[] in sync with the definitions below */ |
eca7abf3 JA |
379 | #define QUEUE_FLAG_STOPPED 0 /* queue is stopped */ |
380 | #define QUEUE_FLAG_DYING 1 /* queue being torn down */ | |
eca7abf3 JA |
381 | #define QUEUE_FLAG_NOMERGES 3 /* disable merge attempts */ |
382 | #define QUEUE_FLAG_SAME_COMP 4 /* complete on same CPU-group */ | |
383 | #define QUEUE_FLAG_FAIL_IO 5 /* fake timeout */ | |
384 | #define QUEUE_FLAG_NONROT 6 /* non-rotational device (SSD) */ | |
385 | #define QUEUE_FLAG_VIRT QUEUE_FLAG_NONROT /* paravirt device */ | |
386 | #define QUEUE_FLAG_IO_STAT 7 /* do disk/partitions IO accounting */ | |
387 | #define QUEUE_FLAG_DISCARD 8 /* supports DISCARD */ | |
388 | #define QUEUE_FLAG_NOXMERGES 9 /* No extended merges */ | |
389 | #define QUEUE_FLAG_ADD_RANDOM 10 /* Contributes to random pool */ | |
390 | #define QUEUE_FLAG_SECERASE 11 /* supports secure erase */ | |
391 | #define QUEUE_FLAG_SAME_FORCE 12 /* force complete on same CPU */ | |
392 | #define QUEUE_FLAG_DEAD 13 /* queue tear-down finished */ | |
393 | #define QUEUE_FLAG_INIT_DONE 14 /* queue is initialized */ | |
1cb039f3 | 394 | #define QUEUE_FLAG_STABLE_WRITES 15 /* don't modify blks until WB is done */ |
eca7abf3 JA |
395 | #define QUEUE_FLAG_POLL 16 /* IO polling enabled if set */ |
396 | #define QUEUE_FLAG_WC 17 /* Write back caching */ | |
397 | #define QUEUE_FLAG_FUA 18 /* device supports FUA writes */ | |
398 | #define QUEUE_FLAG_DAX 19 /* device supports DAX */ | |
399 | #define QUEUE_FLAG_STATS 20 /* track IO start and completion times */ | |
eca7abf3 | 400 | #define QUEUE_FLAG_REGISTERED 22 /* queue has been registered to a disk */ |
eca7abf3 JA |
401 | #define QUEUE_FLAG_QUIESCED 24 /* queue has been quiesced */ |
402 | #define QUEUE_FLAG_PCI_P2PDMA 25 /* device supports PCI p2p requests */ | |
e84e8f06 | 403 | #define QUEUE_FLAG_ZONE_RESETALL 26 /* supports Zone Reset All */ |
6f816b4b | 404 | #define QUEUE_FLAG_RQ_ALLOC_TIME 27 /* record rq->alloc_time_ns */ |
021a2446 MS |
405 | #define QUEUE_FLAG_HCTX_ACTIVE 28 /* at least one blk-mq hctx is active */ |
406 | #define QUEUE_FLAG_NOWAIT 29 /* device supports NOWAIT */ | |
797e7dbb | 407 | |
94eddfbe | 408 | #define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ |
021a2446 MS |
409 | (1 << QUEUE_FLAG_SAME_COMP) | \ |
410 | (1 << QUEUE_FLAG_NOWAIT)) | |
94eddfbe | 411 | |
8814ce8a BVA |
412 | void blk_queue_flag_set(unsigned int flag, struct request_queue *q); |
413 | void blk_queue_flag_clear(unsigned int flag, struct request_queue *q); | |
414 | bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q); | |
8814ce8a | 415 | |
1da177e4 | 416 | #define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags) |
3f3299d5 | 417 | #define blk_queue_dying(q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags) |
c246e80d | 418 | #define blk_queue_dead(q) test_bit(QUEUE_FLAG_DEAD, &(q)->queue_flags) |
320ae51f | 419 | #define blk_queue_init_done(q) test_bit(QUEUE_FLAG_INIT_DONE, &(q)->queue_flags) |
ac9fafa1 | 420 | #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags) |
488991e2 AB |
421 | #define blk_queue_noxmerges(q) \ |
422 | test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags) | |
a68bbddb | 423 | #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags) |
1cb039f3 CH |
424 | #define blk_queue_stable_writes(q) \ |
425 | test_bit(QUEUE_FLAG_STABLE_WRITES, &(q)->queue_flags) | |
bc58ba94 | 426 | #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags) |
e2e1a148 | 427 | #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags) |
c15227de | 428 | #define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags) |
e84e8f06 CK |
429 | #define blk_queue_zone_resetall(q) \ |
430 | test_bit(QUEUE_FLAG_ZONE_RESETALL, &(q)->queue_flags) | |
288dab8a CH |
431 | #define blk_queue_secure_erase(q) \ |
432 | (test_bit(QUEUE_FLAG_SECERASE, &(q)->queue_flags)) | |
163d4baa | 433 | #define blk_queue_dax(q) test_bit(QUEUE_FLAG_DAX, &(q)->queue_flags) |
49d92c0d LG |
434 | #define blk_queue_pci_p2pdma(q) \ |
435 | test_bit(QUEUE_FLAG_PCI_P2PDMA, &(q)->queue_flags) | |
6f816b4b TH |
436 | #ifdef CONFIG_BLK_RQ_ALLOC_TIME |
437 | #define blk_queue_rq_alloc_time(q) \ | |
438 | test_bit(QUEUE_FLAG_RQ_ALLOC_TIME, &(q)->queue_flags) | |
439 | #else | |
440 | #define blk_queue_rq_alloc_time(q) false | |
441 | #endif | |
1da177e4 | 442 | |
33659ebb CH |
443 | #define blk_noretry_request(rq) \ |
444 | ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \ | |
445 | REQ_FAILFAST_DRIVER)) | |
f4560ffe | 446 | #define blk_queue_quiesced(q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags) |
cd84a62e | 447 | #define blk_queue_pm_only(q) atomic_read(&(q)->pm_only) |
0ce91444 | 448 | #define blk_queue_fua(q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags) |
58c898ba | 449 | #define blk_queue_registered(q) test_bit(QUEUE_FLAG_REGISTERED, &(q)->queue_flags) |
021a2446 | 450 | #define blk_queue_nowait(q) test_bit(QUEUE_FLAG_NOWAIT, &(q)->queue_flags) |
c9254f2d | 451 | |
cd84a62e BVA |
452 | extern void blk_set_pm_only(struct request_queue *q); |
453 | extern void blk_clear_pm_only(struct request_queue *q); | |
33659ebb | 454 | |
1da177e4 LT |
455 | #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist) |
456 | ||
3ab3a031 CH |
457 | #define dma_map_bvec(dev, bv, dir, attrs) \ |
458 | dma_map_page_attrs(dev, (bv)->bv_page, (bv)->bv_offset, (bv)->bv_len, \ | |
459 | (dir), (attrs)) | |
460 | ||
344e9ffc | 461 | static inline bool queue_is_mq(struct request_queue *q) |
49fd524f | 462 | { |
a1ce35fa | 463 | return q->mq_ops; |
49fd524f JA |
464 | } |
465 | ||
52abca64 AS |
466 | #ifdef CONFIG_PM |
467 | static inline enum rpm_status queue_rpm_status(struct request_queue *q) | |
468 | { | |
469 | return q->rpm_status; | |
470 | } | |
471 | #else | |
472 | static inline enum rpm_status queue_rpm_status(struct request_queue *q) | |
473 | { | |
474 | return RPM_ACTIVE; | |
475 | } | |
476 | #endif | |
477 | ||
797476b8 DLM |
478 | static inline enum blk_zoned_model |
479 | blk_queue_zoned_model(struct request_queue *q) | |
480 | { | |
6fcd6695 CH |
481 | if (IS_ENABLED(CONFIG_BLK_DEV_ZONED)) |
482 | return q->limits.zoned; | |
483 | return BLK_ZONED_NONE; | |
797476b8 DLM |
484 | } |
485 | ||
486 | static inline bool blk_queue_is_zoned(struct request_queue *q) | |
487 | { | |
488 | switch (blk_queue_zoned_model(q)) { | |
489 | case BLK_ZONED_HA: | |
490 | case BLK_ZONED_HM: | |
491 | return true; | |
492 | default: | |
493 | return false; | |
494 | } | |
495 | } | |
496 | ||
113ab72e | 497 | static inline sector_t blk_queue_zone_sectors(struct request_queue *q) |
6a0cb1bc HR |
498 | { |
499 | return blk_queue_is_zoned(q) ? q->limits.chunk_sectors : 0; | |
500 | } | |
501 | ||
6a5ac984 | 502 | #ifdef CONFIG_BLK_DEV_ZONED |
965b652e DLM |
503 | static inline unsigned int blk_queue_nr_zones(struct request_queue *q) |
504 | { | |
505 | return blk_queue_is_zoned(q) ? q->nr_zones : 0; | |
506 | } | |
507 | ||
6cc77e9c CH |
508 | static inline unsigned int blk_queue_zone_no(struct request_queue *q, |
509 | sector_t sector) | |
510 | { | |
511 | if (!blk_queue_is_zoned(q)) | |
512 | return 0; | |
513 | return sector >> ilog2(q->limits.chunk_sectors); | |
514 | } | |
515 | ||
516 | static inline bool blk_queue_zone_is_seq(struct request_queue *q, | |
517 | sector_t sector) | |
518 | { | |
f216fdd7 | 519 | if (!blk_queue_is_zoned(q)) |
6cc77e9c | 520 | return false; |
f216fdd7 CH |
521 | if (!q->conv_zones_bitmap) |
522 | return true; | |
523 | return !test_bit(blk_queue_zone_no(q, sector), q->conv_zones_bitmap); | |
6cc77e9c | 524 | } |
e15864f8 NC |
525 | |
526 | static inline void blk_queue_max_open_zones(struct request_queue *q, | |
527 | unsigned int max_open_zones) | |
528 | { | |
529 | q->max_open_zones = max_open_zones; | |
530 | } | |
531 | ||
532 | static inline unsigned int queue_max_open_zones(const struct request_queue *q) | |
533 | { | |
534 | return q->max_open_zones; | |
535 | } | |
659bf827 NC |
536 | |
537 | static inline void blk_queue_max_active_zones(struct request_queue *q, | |
538 | unsigned int max_active_zones) | |
539 | { | |
540 | q->max_active_zones = max_active_zones; | |
541 | } | |
542 | ||
543 | static inline unsigned int queue_max_active_zones(const struct request_queue *q) | |
544 | { | |
545 | return q->max_active_zones; | |
546 | } | |
965b652e DLM |
547 | #else /* CONFIG_BLK_DEV_ZONED */ |
548 | static inline unsigned int blk_queue_nr_zones(struct request_queue *q) | |
549 | { | |
550 | return 0; | |
551 | } | |
02992df8 JT |
552 | static inline bool blk_queue_zone_is_seq(struct request_queue *q, |
553 | sector_t sector) | |
554 | { | |
555 | return false; | |
556 | } | |
557 | static inline unsigned int blk_queue_zone_no(struct request_queue *q, | |
558 | sector_t sector) | |
559 | { | |
560 | return 0; | |
561 | } | |
e15864f8 NC |
562 | static inline unsigned int queue_max_open_zones(const struct request_queue *q) |
563 | { | |
564 | return 0; | |
565 | } | |
659bf827 NC |
566 | static inline unsigned int queue_max_active_zones(const struct request_queue *q) |
567 | { | |
568 | return 0; | |
569 | } | |
6a5ac984 | 570 | #endif /* CONFIG_BLK_DEV_ZONED */ |
6cc77e9c | 571 | |
d278d4a8 JA |
572 | static inline unsigned int blk_queue_depth(struct request_queue *q) |
573 | { | |
574 | if (q->queue_depth) | |
575 | return q->queue_depth; | |
576 | ||
577 | return q->nr_requests; | |
578 | } | |
579 | ||
3d6392cf JA |
580 | /* |
581 | * default timeout for SG_IO if none specified | |
582 | */ | |
583 | #define BLK_DEFAULT_SG_TIMEOUT (60 * HZ) | |
f2f1fa78 | 584 | #define BLK_MIN_SG_TIMEOUT (7 * HZ) |
3d6392cf | 585 | |
5705f702 | 586 | /* This should not be used directly - use rq_for_each_segment */ |
1e428079 JA |
587 | #define for_each_bio(_bio) \ |
588 | for (; _bio; _bio = _bio->bi_next) | |
5705f702 | 589 | |
2d4dc890 | 590 | |
1da177e4 LT |
591 | extern int blk_register_queue(struct gendisk *disk); |
592 | extern void blk_unregister_queue(struct gendisk *disk); | |
3e08773c | 593 | void submit_bio_noacct(struct bio *bio); |
24b83deb | 594 | |
ef9e3fac | 595 | extern int blk_lld_busy(struct request_queue *q); |
f695ca38 | 596 | extern void blk_queue_split(struct bio **); |
9a95e4ef | 597 | extern int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags); |
2e6edc95 | 598 | extern void blk_queue_exit(struct request_queue *q); |
1da177e4 | 599 | extern void blk_sync_queue(struct request_queue *q); |
fb9b16e1 | 600 | |
e47bc4ed CK |
601 | /* Helper to convert REQ_OP_XXX to its string format XXX */ |
602 | extern const char *blk_op_str(unsigned int op); | |
603 | ||
2a842aca CH |
604 | int blk_status_to_errno(blk_status_t status); |
605 | blk_status_t errno_to_blk_status(int errno); | |
606 | ||
ef99b2d3 CH |
607 | /* only poll the hardware once, don't continue until a completion was found */ |
608 | #define BLK_POLL_ONESHOT (1 << 0) | |
d729cf9a CH |
609 | /* do not sleep to wait for the expected completion time */ |
610 | #define BLK_POLL_NOSLEEP (1 << 1) | |
5a72e899 JA |
611 | int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags); |
612 | int iocb_bio_iopoll(struct kiocb *kiocb, struct io_comp_batch *iob, | |
613 | unsigned int flags); | |
05229bee | 614 | |
165125e1 | 615 | static inline struct request_queue *bdev_get_queue(struct block_device *bdev) |
1da177e4 | 616 | { |
17220ca5 | 617 | return bdev->bd_queue; /* this is never NULL */ |
1da177e4 LT |
618 | } |
619 | ||
6a5ac984 | 620 | #ifdef CONFIG_BLK_DEV_ZONED |
02694e86 CK |
621 | |
622 | /* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */ | |
623 | const char *blk_zone_cond_str(enum blk_zone_cond zone_cond); | |
624 | ||
d0ea6bde DLM |
625 | static inline unsigned int bio_zone_no(struct bio *bio) |
626 | { | |
627 | return blk_queue_zone_no(bdev_get_queue(bio->bi_bdev), | |
628 | bio->bi_iter.bi_sector); | |
629 | } | |
630 | ||
631 | static inline unsigned int bio_zone_is_seq(struct bio *bio) | |
632 | { | |
633 | return blk_queue_zone_is_seq(bdev_get_queue(bio->bi_bdev), | |
634 | bio->bi_iter.bi_sector); | |
635 | } | |
6a5ac984 | 636 | #endif /* CONFIG_BLK_DEV_ZONED */ |
6cc77e9c | 637 | |
f31dc1cd | 638 | static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, |
8fe0d473 | 639 | int op) |
f31dc1cd | 640 | { |
7afafc8a | 641 | if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) |
233bde21 BVA |
642 | return min(q->limits.max_discard_sectors, |
643 | UINT_MAX >> SECTOR_SHIFT); | |
f31dc1cd | 644 | |
8fe0d473 | 645 | if (unlikely(op == REQ_OP_WRITE_SAME)) |
4363ac7c MP |
646 | return q->limits.max_write_same_sectors; |
647 | ||
a6f0788e CK |
648 | if (unlikely(op == REQ_OP_WRITE_ZEROES)) |
649 | return q->limits.max_write_zeroes_sectors; | |
650 | ||
f31dc1cd MP |
651 | return q->limits.max_sectors; |
652 | } | |
653 | ||
762380ad JA |
654 | /* |
655 | * Return maximum size of a request at given offset. Only valid for | |
656 | * file system requests. | |
657 | */ | |
658 | static inline unsigned int blk_max_size_offset(struct request_queue *q, | |
3ee16db3 MS |
659 | sector_t offset, |
660 | unsigned int chunk_sectors) | |
762380ad | 661 | { |
65f33b35 MS |
662 | if (!chunk_sectors) { |
663 | if (q->limits.chunk_sectors) | |
664 | chunk_sectors = q->limits.chunk_sectors; | |
665 | else | |
666 | return q->limits.max_sectors; | |
667 | } | |
762380ad | 668 | |
07d098e6 MS |
669 | if (likely(is_power_of_2(chunk_sectors))) |
670 | chunk_sectors -= offset & (chunk_sectors - 1); | |
671 | else | |
672 | chunk_sectors -= sector_div(offset, chunk_sectors); | |
673 | ||
674 | return min(q->limits.max_sectors, chunk_sectors); | |
762380ad JA |
675 | } |
676 | ||
1da177e4 LT |
677 | /* |
678 | * Access functions for manipulating queue properties | |
679 | */ | |
165125e1 | 680 | extern void blk_cleanup_queue(struct request_queue *); |
9bb33f24 | 681 | void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce limit); |
086fa5ff | 682 | extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int); |
762380ad | 683 | extern void blk_queue_chunk_sectors(struct request_queue *, unsigned int); |
8a78362c | 684 | extern void blk_queue_max_segments(struct request_queue *, unsigned short); |
1e739730 CH |
685 | extern void blk_queue_max_discard_segments(struct request_queue *, |
686 | unsigned short); | |
165125e1 | 687 | extern void blk_queue_max_segment_size(struct request_queue *, unsigned int); |
67efc925 CH |
688 | extern void blk_queue_max_discard_sectors(struct request_queue *q, |
689 | unsigned int max_discard_sectors); | |
4363ac7c MP |
690 | extern void blk_queue_max_write_same_sectors(struct request_queue *q, |
691 | unsigned int max_write_same_sectors); | |
a6f0788e CK |
692 | extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q, |
693 | unsigned int max_write_same_sectors); | |
ad6bf88a | 694 | extern void blk_queue_logical_block_size(struct request_queue *, unsigned int); |
0512a75b KB |
695 | extern void blk_queue_max_zone_append_sectors(struct request_queue *q, |
696 | unsigned int max_zone_append_sectors); | |
892b6f90 | 697 | extern void blk_queue_physical_block_size(struct request_queue *, unsigned int); |
a805a4fa DLM |
698 | void blk_queue_zone_write_granularity(struct request_queue *q, |
699 | unsigned int size); | |
c72758f3 MP |
700 | extern void blk_queue_alignment_offset(struct request_queue *q, |
701 | unsigned int alignment); | |
471aa704 | 702 | void disk_update_readahead(struct gendisk *disk); |
7c958e32 | 703 | extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min); |
c72758f3 | 704 | extern void blk_queue_io_min(struct request_queue *q, unsigned int min); |
3c5820c7 | 705 | extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt); |
c72758f3 | 706 | extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt); |
d278d4a8 | 707 | extern void blk_set_queue_depth(struct request_queue *q, unsigned int depth); |
e475bba2 | 708 | extern void blk_set_default_limits(struct queue_limits *lim); |
b1bd055d | 709 | extern void blk_set_stacking_limits(struct queue_limits *lim); |
c72758f3 MP |
710 | extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, |
711 | sector_t offset); | |
712 | extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev, | |
713 | sector_t offset); | |
27f8221a | 714 | extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int); |
165125e1 | 715 | extern void blk_queue_segment_boundary(struct request_queue *, unsigned long); |
03100aad | 716 | extern void blk_queue_virt_boundary(struct request_queue *, unsigned long); |
165125e1 | 717 | extern void blk_queue_dma_alignment(struct request_queue *, int); |
11c3e689 | 718 | extern void blk_queue_update_dma_alignment(struct request_queue *, int); |
242f9dcb | 719 | extern void blk_queue_rq_timeout(struct request_queue *, unsigned int); |
93e9d8e8 | 720 | extern void blk_queue_write_cache(struct request_queue *q, bool enabled, bool fua); |
2e9bc346 | 721 | |
a2247f19 DLM |
722 | struct blk_independent_access_ranges * |
723 | disk_alloc_independent_access_ranges(struct gendisk *disk, int nr_ia_ranges); | |
724 | void disk_set_independent_access_ranges(struct gendisk *disk, | |
725 | struct blk_independent_access_ranges *iars); | |
726 | ||
2e9bc346 CH |
727 | /* |
728 | * Elevator features for blk_queue_required_elevator_features: | |
729 | */ | |
730 | /* Supports zoned block devices sequential write constraint */ | |
731 | #define ELEVATOR_F_ZBD_SEQ_WRITE (1U << 0) | |
732 | /* Supports scheduling on multiple hardware queues */ | |
733 | #define ELEVATOR_F_MQ_AWARE (1U << 1) | |
734 | ||
68c43f13 DLM |
735 | extern void blk_queue_required_elevator_features(struct request_queue *q, |
736 | unsigned int features); | |
45147fb5 YS |
737 | extern bool blk_queue_can_use_dma_map_merging(struct request_queue *q, |
738 | struct device *dev); | |
1da177e4 | 739 | |
09ac46c4 | 740 | bool __must_check blk_get_queue(struct request_queue *); |
165125e1 | 741 | extern void blk_put_queue(struct request_queue *); |
3f21c265 | 742 | extern void blk_set_queue_dying(struct request_queue *); |
1da177e4 | 743 | |
1a4dcfa8 | 744 | #ifdef CONFIG_BLOCK |
316cc67d | 745 | /* |
75df7136 SJ |
746 | * blk_plug permits building a queue of related requests by holding the I/O |
747 | * fragments for a short period. This allows merging of sequential requests | |
748 | * into single larger request. As the requests are moved from a per-task list to | |
749 | * the device's request_queue in a batch, this results in improved scalability | |
750 | * as the lock contention for request_queue lock is reduced. | |
751 | * | |
752 | * It is ok not to disable preemption when adding the request to the plug list | |
008f75a2 CH |
753 | * or when attempting a merge. For details, please see schedule() where |
754 | * blk_flush_plug() is called. | |
316cc67d | 755 | */ |
73c10101 | 756 | struct blk_plug { |
bc490f81 | 757 | struct request *mq_list; /* blk-mq requests */ |
47c122e3 JA |
758 | |
759 | /* if ios_left is > 1, we can batch tag/rq allocations */ | |
760 | struct request *cached_rq; | |
761 | unsigned short nr_ios; | |
762 | ||
5f0ed774 | 763 | unsigned short rq_count; |
47c122e3 | 764 | |
ce5b009c | 765 | bool multiple_queues; |
dc5fc361 | 766 | bool has_elevator; |
5a473e83 | 767 | bool nowait; |
47c122e3 JA |
768 | |
769 | struct list_head cb_list; /* md requires an unplug callback */ | |
73c10101 | 770 | }; |
55c022bb | 771 | |
9cbb1750 | 772 | struct blk_plug_cb; |
74018dc3 | 773 | typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *, bool); |
048c9374 N |
774 | struct blk_plug_cb { |
775 | struct list_head list; | |
9cbb1750 N |
776 | blk_plug_cb_fn callback; |
777 | void *data; | |
048c9374 | 778 | }; |
9cbb1750 N |
779 | extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, |
780 | void *data, int size); | |
73c10101 | 781 | extern void blk_start_plug(struct blk_plug *); |
47c122e3 | 782 | extern void blk_start_plug_nr_ios(struct blk_plug *, unsigned short); |
73c10101 | 783 | extern void blk_finish_plug(struct blk_plug *); |
73c10101 | 784 | |
008f75a2 | 785 | void blk_flush_plug(struct blk_plug *plug, bool from_schedule); |
73c10101 JA |
786 | |
787 | static inline bool blk_needs_flush_plug(struct task_struct *tsk) | |
788 | { | |
789 | struct blk_plug *plug = tsk->plug; | |
790 | ||
320ae51f | 791 | return plug && |
bc490f81 | 792 | (plug->mq_list || !list_empty(&plug->cb_list)); |
73c10101 JA |
793 | } |
794 | ||
c6bf3f0e | 795 | int blkdev_issue_flush(struct block_device *bdev); |
1a4dcfa8 CH |
796 | long nr_blockdev_pages(void); |
797 | #else /* CONFIG_BLOCK */ | |
798 | struct blk_plug { | |
799 | }; | |
800 | ||
47c122e3 JA |
801 | static inline void blk_start_plug_nr_ios(struct blk_plug *plug, |
802 | unsigned short nr_ios) | |
803 | { | |
804 | } | |
805 | ||
1a4dcfa8 CH |
806 | static inline void blk_start_plug(struct blk_plug *plug) |
807 | { | |
808 | } | |
809 | ||
810 | static inline void blk_finish_plug(struct blk_plug *plug) | |
811 | { | |
812 | } | |
813 | ||
008f75a2 | 814 | static inline void blk_flush_plug(struct blk_plug *plug, bool async) |
1a4dcfa8 CH |
815 | { |
816 | } | |
817 | ||
1a4dcfa8 CH |
818 | static inline bool blk_needs_flush_plug(struct task_struct *tsk) |
819 | { | |
820 | return false; | |
821 | } | |
822 | ||
c6bf3f0e | 823 | static inline int blkdev_issue_flush(struct block_device *bdev) |
1a4dcfa8 CH |
824 | { |
825 | return 0; | |
826 | } | |
827 | ||
828 | static inline long nr_blockdev_pages(void) | |
829 | { | |
830 | return 0; | |
831 | } | |
832 | #endif /* CONFIG_BLOCK */ | |
833 | ||
71ac860a ML |
834 | extern void blk_io_schedule(void); |
835 | ||
ee472d83 CH |
836 | extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, |
837 | sector_t nr_sects, gfp_t gfp_mask, struct page *page); | |
e950fdf7 CH |
838 | |
839 | #define BLKDEV_DISCARD_SECURE (1 << 0) /* issue a secure erase */ | |
dd3932ed | 840 | |
fbd9b09a DM |
841 | extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector, |
842 | sector_t nr_sects, gfp_t gfp_mask, unsigned long flags); | |
38f25255 | 843 | extern int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, |
288dab8a | 844 | sector_t nr_sects, gfp_t gfp_mask, int flags, |
469e3216 | 845 | struct bio **biop); |
ee472d83 CH |
846 | |
847 | #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */ | |
cb365b96 | 848 | #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */ |
ee472d83 | 849 | |
e73c23ff CK |
850 | extern int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, |
851 | sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, | |
ee472d83 | 852 | unsigned flags); |
3f14d792 | 853 | extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, |
ee472d83 CH |
854 | sector_t nr_sects, gfp_t gfp_mask, unsigned flags); |
855 | ||
2cf6d26a CH |
856 | static inline int sb_issue_discard(struct super_block *sb, sector_t block, |
857 | sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags) | |
fb2dce86 | 858 | { |
233bde21 BVA |
859 | return blkdev_issue_discard(sb->s_bdev, |
860 | block << (sb->s_blocksize_bits - | |
861 | SECTOR_SHIFT), | |
862 | nr_blocks << (sb->s_blocksize_bits - | |
863 | SECTOR_SHIFT), | |
2cf6d26a | 864 | gfp_mask, flags); |
fb2dce86 | 865 | } |
e6fa0be6 | 866 | static inline int sb_issue_zeroout(struct super_block *sb, sector_t block, |
a107e5a3 | 867 | sector_t nr_blocks, gfp_t gfp_mask) |
e6fa0be6 LC |
868 | { |
869 | return blkdev_issue_zeroout(sb->s_bdev, | |
233bde21 BVA |
870 | block << (sb->s_blocksize_bits - |
871 | SECTOR_SHIFT), | |
872 | nr_blocks << (sb->s_blocksize_bits - | |
873 | SECTOR_SHIFT), | |
ee472d83 | 874 | gfp_mask, 0); |
e6fa0be6 | 875 | } |
1da177e4 | 876 | |
fa01b1e9 CH |
877 | static inline bool bdev_is_partition(struct block_device *bdev) |
878 | { | |
879 | return bdev->bd_partno; | |
880 | } | |
881 | ||
eb28d31b MP |
882 | enum blk_default_limits { |
883 | BLK_MAX_SEGMENTS = 128, | |
884 | BLK_SAFE_MAX_SECTORS = 255, | |
d2be537c | 885 | BLK_DEF_MAX_SECTORS = 2560, |
eb28d31b MP |
886 | BLK_MAX_SEGMENT_SIZE = 65536, |
887 | BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL, | |
888 | }; | |
0e435ac2 | 889 | |
af2c68fe | 890 | static inline unsigned long queue_segment_boundary(const struct request_queue *q) |
ae03bf63 | 891 | { |
025146e1 | 892 | return q->limits.seg_boundary_mask; |
ae03bf63 MP |
893 | } |
894 | ||
af2c68fe | 895 | static inline unsigned long queue_virt_boundary(const struct request_queue *q) |
03100aad KB |
896 | { |
897 | return q->limits.virt_boundary_mask; | |
898 | } | |
899 | ||
af2c68fe | 900 | static inline unsigned int queue_max_sectors(const struct request_queue *q) |
ae03bf63 | 901 | { |
025146e1 | 902 | return q->limits.max_sectors; |
ae03bf63 MP |
903 | } |
904 | ||
547e2f70 CH |
905 | static inline unsigned int queue_max_bytes(struct request_queue *q) |
906 | { | |
907 | return min_t(unsigned int, queue_max_sectors(q), INT_MAX >> 9) << 9; | |
908 | } | |
909 | ||
af2c68fe | 910 | static inline unsigned int queue_max_hw_sectors(const struct request_queue *q) |
ae03bf63 | 911 | { |
025146e1 | 912 | return q->limits.max_hw_sectors; |
ae03bf63 MP |
913 | } |
914 | ||
af2c68fe | 915 | static inline unsigned short queue_max_segments(const struct request_queue *q) |
ae03bf63 | 916 | { |
8a78362c | 917 | return q->limits.max_segments; |
ae03bf63 MP |
918 | } |
919 | ||
af2c68fe | 920 | static inline unsigned short queue_max_discard_segments(const struct request_queue *q) |
1e739730 CH |
921 | { |
922 | return q->limits.max_discard_segments; | |
923 | } | |
924 | ||
af2c68fe | 925 | static inline unsigned int queue_max_segment_size(const struct request_queue *q) |
ae03bf63 | 926 | { |
025146e1 | 927 | return q->limits.max_segment_size; |
ae03bf63 MP |
928 | } |
929 | ||
0512a75b KB |
930 | static inline unsigned int queue_max_zone_append_sectors(const struct request_queue *q) |
931 | { | |
fe6f0cdc JT |
932 | |
933 | const struct queue_limits *l = &q->limits; | |
934 | ||
935 | return min(l->max_zone_append_sectors, l->max_sectors); | |
0512a75b KB |
936 | } |
937 | ||
ad6bf88a | 938 | static inline unsigned queue_logical_block_size(const struct request_queue *q) |
1da177e4 LT |
939 | { |
940 | int retval = 512; | |
941 | ||
025146e1 MP |
942 | if (q && q->limits.logical_block_size) |
943 | retval = q->limits.logical_block_size; | |
1da177e4 LT |
944 | |
945 | return retval; | |
946 | } | |
947 | ||
ad6bf88a | 948 | static inline unsigned int bdev_logical_block_size(struct block_device *bdev) |
1da177e4 | 949 | { |
e1defc4f | 950 | return queue_logical_block_size(bdev_get_queue(bdev)); |
1da177e4 LT |
951 | } |
952 | ||
af2c68fe | 953 | static inline unsigned int queue_physical_block_size(const struct request_queue *q) |
c72758f3 MP |
954 | { |
955 | return q->limits.physical_block_size; | |
956 | } | |
957 | ||
892b6f90 | 958 | static inline unsigned int bdev_physical_block_size(struct block_device *bdev) |
ac481c20 MP |
959 | { |
960 | return queue_physical_block_size(bdev_get_queue(bdev)); | |
961 | } | |
962 | ||
af2c68fe | 963 | static inline unsigned int queue_io_min(const struct request_queue *q) |
c72758f3 MP |
964 | { |
965 | return q->limits.io_min; | |
966 | } | |
967 | ||
ac481c20 MP |
968 | static inline int bdev_io_min(struct block_device *bdev) |
969 | { | |
970 | return queue_io_min(bdev_get_queue(bdev)); | |
971 | } | |
972 | ||
af2c68fe | 973 | static inline unsigned int queue_io_opt(const struct request_queue *q) |
c72758f3 MP |
974 | { |
975 | return q->limits.io_opt; | |
976 | } | |
977 | ||
ac481c20 MP |
978 | static inline int bdev_io_opt(struct block_device *bdev) |
979 | { | |
980 | return queue_io_opt(bdev_get_queue(bdev)); | |
981 | } | |
982 | ||
a805a4fa DLM |
983 | static inline unsigned int |
984 | queue_zone_write_granularity(const struct request_queue *q) | |
985 | { | |
986 | return q->limits.zone_write_granularity; | |
987 | } | |
988 | ||
989 | static inline unsigned int | |
990 | bdev_zone_write_granularity(struct block_device *bdev) | |
991 | { | |
992 | return queue_zone_write_granularity(bdev_get_queue(bdev)); | |
993 | } | |
994 | ||
af2c68fe | 995 | static inline int queue_alignment_offset(const struct request_queue *q) |
c72758f3 | 996 | { |
ac481c20 | 997 | if (q->limits.misaligned) |
c72758f3 MP |
998 | return -1; |
999 | ||
ac481c20 | 1000 | return q->limits.alignment_offset; |
c72758f3 MP |
1001 | } |
1002 | ||
e03a72e1 | 1003 | static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector) |
81744ee4 MP |
1004 | { |
1005 | unsigned int granularity = max(lim->physical_block_size, lim->io_min); | |
233bde21 BVA |
1006 | unsigned int alignment = sector_div(sector, granularity >> SECTOR_SHIFT) |
1007 | << SECTOR_SHIFT; | |
81744ee4 | 1008 | |
b8839b8c | 1009 | return (granularity + lim->alignment_offset - alignment) % granularity; |
c72758f3 MP |
1010 | } |
1011 | ||
ac481c20 MP |
1012 | static inline int bdev_alignment_offset(struct block_device *bdev) |
1013 | { | |
1014 | struct request_queue *q = bdev_get_queue(bdev); | |
1015 | ||
1016 | if (q->limits.misaligned) | |
1017 | return -1; | |
fa01b1e9 | 1018 | if (bdev_is_partition(bdev)) |
7b8917f5 | 1019 | return queue_limit_alignment_offset(&q->limits, |
29ff57c6 | 1020 | bdev->bd_start_sect); |
ac481c20 MP |
1021 | return q->limits.alignment_offset; |
1022 | } | |
1023 | ||
af2c68fe | 1024 | static inline int queue_discard_alignment(const struct request_queue *q) |
86b37281 MP |
1025 | { |
1026 | if (q->limits.discard_misaligned) | |
1027 | return -1; | |
1028 | ||
1029 | return q->limits.discard_alignment; | |
1030 | } | |
1031 | ||
e03a72e1 | 1032 | static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector) |
86b37281 | 1033 | { |
59771079 | 1034 | unsigned int alignment, granularity, offset; |
dd3d145d | 1035 | |
a934a00a MP |
1036 | if (!lim->max_discard_sectors) |
1037 | return 0; | |
1038 | ||
59771079 | 1039 | /* Why are these in bytes, not sectors? */ |
233bde21 BVA |
1040 | alignment = lim->discard_alignment >> SECTOR_SHIFT; |
1041 | granularity = lim->discard_granularity >> SECTOR_SHIFT; | |
59771079 LT |
1042 | if (!granularity) |
1043 | return 0; | |
1044 | ||
1045 | /* Offset of the partition start in 'granularity' sectors */ | |
1046 | offset = sector_div(sector, granularity); | |
1047 | ||
1048 | /* And why do we do this modulus *again* in blkdev_issue_discard()? */ | |
1049 | offset = (granularity + alignment - offset) % granularity; | |
1050 | ||
1051 | /* Turn it back into bytes, gaah */ | |
233bde21 | 1052 | return offset << SECTOR_SHIFT; |
86b37281 MP |
1053 | } |
1054 | ||
c6e66634 PB |
1055 | static inline int bdev_discard_alignment(struct block_device *bdev) |
1056 | { | |
1057 | struct request_queue *q = bdev_get_queue(bdev); | |
1058 | ||
fa01b1e9 | 1059 | if (bdev_is_partition(bdev)) |
7cf34d97 | 1060 | return queue_limit_discard_alignment(&q->limits, |
29ff57c6 | 1061 | bdev->bd_start_sect); |
c6e66634 PB |
1062 | return q->limits.discard_alignment; |
1063 | } | |
1064 | ||
4363ac7c MP |
1065 | static inline unsigned int bdev_write_same(struct block_device *bdev) |
1066 | { | |
1067 | struct request_queue *q = bdev_get_queue(bdev); | |
1068 | ||
1069 | if (q) | |
1070 | return q->limits.max_write_same_sectors; | |
1071 | ||
1072 | return 0; | |
1073 | } | |
1074 | ||
a6f0788e CK |
1075 | static inline unsigned int bdev_write_zeroes_sectors(struct block_device *bdev) |
1076 | { | |
1077 | struct request_queue *q = bdev_get_queue(bdev); | |
1078 | ||
1079 | if (q) | |
1080 | return q->limits.max_write_zeroes_sectors; | |
1081 | ||
1082 | return 0; | |
1083 | } | |
1084 | ||
797476b8 DLM |
1085 | static inline enum blk_zoned_model bdev_zoned_model(struct block_device *bdev) |
1086 | { | |
1087 | struct request_queue *q = bdev_get_queue(bdev); | |
1088 | ||
1089 | if (q) | |
1090 | return blk_queue_zoned_model(q); | |
1091 | ||
1092 | return BLK_ZONED_NONE; | |
1093 | } | |
1094 | ||
1095 | static inline bool bdev_is_zoned(struct block_device *bdev) | |
1096 | { | |
1097 | struct request_queue *q = bdev_get_queue(bdev); | |
1098 | ||
1099 | if (q) | |
1100 | return blk_queue_is_zoned(q); | |
1101 | ||
1102 | return false; | |
1103 | } | |
1104 | ||
113ab72e | 1105 | static inline sector_t bdev_zone_sectors(struct block_device *bdev) |
6a0cb1bc HR |
1106 | { |
1107 | struct request_queue *q = bdev_get_queue(bdev); | |
1108 | ||
1109 | if (q) | |
f99e8648 | 1110 | return blk_queue_zone_sectors(q); |
6cc77e9c CH |
1111 | return 0; |
1112 | } | |
6a0cb1bc | 1113 | |
e15864f8 NC |
1114 | static inline unsigned int bdev_max_open_zones(struct block_device *bdev) |
1115 | { | |
1116 | struct request_queue *q = bdev_get_queue(bdev); | |
1117 | ||
1118 | if (q) | |
1119 | return queue_max_open_zones(q); | |
1120 | return 0; | |
1121 | } | |
1122 | ||
659bf827 NC |
1123 | static inline unsigned int bdev_max_active_zones(struct block_device *bdev) |
1124 | { | |
1125 | struct request_queue *q = bdev_get_queue(bdev); | |
1126 | ||
1127 | if (q) | |
1128 | return queue_max_active_zones(q); | |
1129 | return 0; | |
1130 | } | |
1131 | ||
af2c68fe | 1132 | static inline int queue_dma_alignment(const struct request_queue *q) |
1da177e4 | 1133 | { |
482eb689 | 1134 | return q ? q->dma_alignment : 511; |
1da177e4 LT |
1135 | } |
1136 | ||
14417799 | 1137 | static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr, |
87904074 FT |
1138 | unsigned int len) |
1139 | { | |
1140 | unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask; | |
14417799 | 1141 | return !(addr & alignment) && !(len & alignment); |
87904074 FT |
1142 | } |
1143 | ||
1da177e4 LT |
1144 | /* assumes size > 256 */ |
1145 | static inline unsigned int blksize_bits(unsigned int size) | |
1146 | { | |
1147 | unsigned int bits = 8; | |
1148 | do { | |
1149 | bits++; | |
1150 | size >>= 1; | |
1151 | } while (size > 256); | |
1152 | return bits; | |
1153 | } | |
1154 | ||
2befb9e3 | 1155 | static inline unsigned int block_size(struct block_device *bdev) |
1da177e4 | 1156 | { |
6b7b181b | 1157 | return 1 << bdev->bd_inode->i_blkbits; |
1da177e4 LT |
1158 | } |
1159 | ||
59c3d45e | 1160 | int kblockd_schedule_work(struct work_struct *work); |
818cd1cb | 1161 | int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay); |
1da177e4 | 1162 | |
1da177e4 LT |
1163 | #define MODULE_ALIAS_BLOCKDEV(major,minor) \ |
1164 | MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor)) | |
1165 | #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \ | |
1166 | MODULE_ALIAS("block-major-" __stringify(major) "-*") | |
1167 | ||
d145dc23 ST |
1168 | #ifdef CONFIG_BLK_INLINE_ENCRYPTION |
1169 | ||
cb77cb5a EB |
1170 | bool blk_crypto_register(struct blk_crypto_profile *profile, |
1171 | struct request_queue *q); | |
d145dc23 | 1172 | |
d145dc23 ST |
1173 | #else /* CONFIG_BLK_INLINE_ENCRYPTION */ |
1174 | ||
cb77cb5a EB |
1175 | static inline bool blk_crypto_register(struct blk_crypto_profile *profile, |
1176 | struct request_queue *q) | |
d145dc23 ST |
1177 | { |
1178 | return true; | |
1179 | } | |
1180 | ||
d145dc23 ST |
1181 | #endif /* CONFIG_BLK_INLINE_ENCRYPTION */ |
1182 | ||
9208d414 CH |
1183 | enum blk_unique_id { |
1184 | /* these match the Designator Types specified in SPC */ | |
1185 | BLK_UID_T10 = 1, | |
1186 | BLK_UID_EUI64 = 2, | |
1187 | BLK_UID_NAA = 3, | |
1188 | }; | |
1189 | ||
1190 | #define NFL4_UFLG_MASK 0x0000003F | |
d145dc23 | 1191 | |
08f85851 | 1192 | struct block_device_operations { |
3e08773c | 1193 | void (*submit_bio)(struct bio *bio); |
d4430d62 | 1194 | int (*open) (struct block_device *, fmode_t); |
db2a144b | 1195 | void (*release) (struct gendisk *, fmode_t); |
3f289dcb | 1196 | int (*rw_page)(struct block_device *, sector_t, struct page *, unsigned int); |
d4430d62 AV |
1197 | int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); |
1198 | int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); | |
77ea887e TH |
1199 | unsigned int (*check_events) (struct gendisk *disk, |
1200 | unsigned int clearing); | |
c3e33e04 | 1201 | void (*unlock_native_capacity) (struct gendisk *); |
08f85851 | 1202 | int (*getgeo)(struct block_device *, struct hd_geometry *); |
e00adcad | 1203 | int (*set_read_only)(struct block_device *bdev, bool ro); |
b3a27d05 NG |
1204 | /* this callback is with swap_lock and sometimes page table lock held */ |
1205 | void (*swap_slot_free_notify) (struct block_device *, unsigned long); | |
e76239a3 | 1206 | int (*report_zones)(struct gendisk *, sector_t sector, |
d4100351 | 1207 | unsigned int nr_zones, report_zones_cb cb, void *data); |
348e114b | 1208 | char *(*devnode)(struct gendisk *disk, umode_t *mode); |
9208d414 CH |
1209 | /* returns the length of the identifier or a negative errno: */ |
1210 | int (*get_unique_id)(struct gendisk *disk, u8 id[16], | |
1211 | enum blk_unique_id id_type); | |
08f85851 | 1212 | struct module *owner; |
bbd3e064 | 1213 | const struct pr_ops *pr_ops; |
0bdfbca8 DO |
1214 | |
1215 | /* | |
1216 | * Special callback for probing GPT entry at a given sector. | |
1217 | * Needed by Android devices, used by GPT scanner and MMC blk | |
1218 | * driver. | |
1219 | */ | |
1220 | int (*alternative_gpt_sector)(struct gendisk *disk, sector_t *sector); | |
08f85851 AV |
1221 | }; |
1222 | ||
ee6a129d AB |
1223 | #ifdef CONFIG_COMPAT |
1224 | extern int blkdev_compat_ptr_ioctl(struct block_device *, fmode_t, | |
1225 | unsigned int, unsigned long); | |
1226 | #else | |
1227 | #define blkdev_compat_ptr_ioctl NULL | |
1228 | #endif | |
1229 | ||
47a191fd MW |
1230 | extern int bdev_read_page(struct block_device *, sector_t, struct page *); |
1231 | extern int bdev_write_page(struct block_device *, sector_t, struct page *, | |
1232 | struct writeback_control *); | |
6cc77e9c | 1233 | |
0619317f JA |
1234 | static inline void blk_wake_io_task(struct task_struct *waiter) |
1235 | { | |
1236 | /* | |
1237 | * If we're polling, the task itself is doing the completions. For | |
1238 | * that case, we don't need to signal a wakeup, it's enough to just | |
1239 | * mark us as RUNNING. | |
1240 | */ | |
1241 | if (waiter == current) | |
1242 | __set_current_state(TASK_RUNNING); | |
1243 | else | |
1244 | wake_up_process(waiter); | |
1245 | } | |
1246 | ||
956d510e CH |
1247 | unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, |
1248 | unsigned int op); | |
1249 | void disk_end_io_acct(struct gendisk *disk, unsigned int op, | |
1250 | unsigned long start_time); | |
1251 | ||
99dfc43e CH |
1252 | unsigned long bio_start_io_acct(struct bio *bio); |
1253 | void bio_end_io_acct_remapped(struct bio *bio, unsigned long start_time, | |
1254 | struct block_device *orig_bdev); | |
956d510e CH |
1255 | |
1256 | /** | |
1257 | * bio_end_io_acct - end I/O accounting for bio based drivers | |
1258 | * @bio: bio to end account for | |
1259 | * @start: start time returned by bio_start_io_acct() | |
1260 | */ | |
1261 | static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time) | |
1262 | { | |
99dfc43e | 1263 | return bio_end_io_acct_remapped(bio, start_time, bio->bi_bdev); |
956d510e | 1264 | } |
956d510e | 1265 | |
3f1266f1 CH |
1266 | int bdev_read_only(struct block_device *bdev); |
1267 | int set_blocksize(struct block_device *bdev, int size); | |
1268 | ||
1269 | const char *bdevname(struct block_device *bdev, char *buffer); | |
4e7b5671 | 1270 | int lookup_bdev(const char *pathname, dev_t *dev); |
3f1266f1 CH |
1271 | |
1272 | void blkdev_show(struct seq_file *seqf, off_t offset); | |
1273 | ||
1274 | #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ | |
1275 | #define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */ | |
1276 | #ifdef CONFIG_BLOCK | |
1277 | #define BLKDEV_MAJOR_MAX 512 | |
1278 | #else | |
1279 | #define BLKDEV_MAJOR_MAX 0 | |
1280 | #endif | |
1281 | ||
3f1266f1 CH |
1282 | struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, |
1283 | void *holder); | |
1284 | struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder); | |
37c3fc9a CH |
1285 | int bd_prepare_to_claim(struct block_device *bdev, void *holder); |
1286 | void bd_abort_claiming(struct block_device *bdev, void *holder); | |
3f1266f1 CH |
1287 | void blkdev_put(struct block_device *bdev, fmode_t mode); |
1288 | ||
22ae8ce8 CH |
1289 | /* just for blk-cgroup, don't use elsewhere */ |
1290 | struct block_device *blkdev_get_no_open(dev_t dev); | |
1291 | void blkdev_put_no_open(struct block_device *bdev); | |
1292 | ||
1293 | struct block_device *bdev_alloc(struct gendisk *disk, u8 partno); | |
1294 | void bdev_add(struct block_device *bdev, dev_t dev); | |
621c1f42 | 1295 | struct block_device *I_BDEV(struct inode *inode); |
2c2b9fd6 CH |
1296 | int truncate_bdev_range(struct block_device *bdev, fmode_t mode, loff_t lstart, |
1297 | loff_t lend); | |
3f1266f1 CH |
1298 | |
1299 | #ifdef CONFIG_BLOCK | |
1300 | void invalidate_bdev(struct block_device *bdev); | |
1301 | int sync_blockdev(struct block_device *bdev); | |
70164eb6 | 1302 | int sync_blockdev_nowait(struct block_device *bdev); |
1e03a36b | 1303 | void sync_bdevs(bool wait); |
3f1266f1 CH |
1304 | #else |
1305 | static inline void invalidate_bdev(struct block_device *bdev) | |
1306 | { | |
1307 | } | |
1308 | static inline int sync_blockdev(struct block_device *bdev) | |
1309 | { | |
1310 | return 0; | |
1311 | } | |
70164eb6 CH |
1312 | static inline int sync_blockdev_nowait(struct block_device *bdev) |
1313 | { | |
1314 | return 0; | |
1315 | } | |
1e03a36b CH |
1316 | static inline void sync_bdevs(bool wait) |
1317 | { | |
1318 | } | |
1da177e4 | 1319 | #endif |
3f1266f1 CH |
1320 | int fsync_bdev(struct block_device *bdev); |
1321 | ||
040f04bd CH |
1322 | int freeze_bdev(struct block_device *bdev); |
1323 | int thaw_bdev(struct block_device *bdev); | |
3f1266f1 | 1324 | |
5a72e899 JA |
1325 | struct io_comp_batch { |
1326 | struct request *req_list; | |
1327 | bool need_ts; | |
1328 | void (*complete)(struct io_comp_batch *); | |
1329 | }; | |
1330 | ||
1331 | #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { } | |
1332 | ||
013a7f95 JA |
1333 | #define rq_list_add(listptr, rq) do { \ |
1334 | (rq)->rq_next = *(listptr); \ | |
1335 | *(listptr) = rq; \ | |
1336 | } while (0) | |
1337 | ||
1338 | #define rq_list_pop(listptr) \ | |
1339 | ({ \ | |
1340 | struct request *__req = NULL; \ | |
1341 | if ((listptr) && *(listptr)) { \ | |
1342 | __req = *(listptr); \ | |
1343 | *(listptr) = __req->rq_next; \ | |
1344 | } \ | |
1345 | __req; \ | |
1346 | }) | |
1347 | ||
1348 | #define rq_list_peek(listptr) \ | |
1349 | ({ \ | |
1350 | struct request *__req = NULL; \ | |
1351 | if ((listptr) && *(listptr)) \ | |
1352 | __req = *(listptr); \ | |
1353 | __req; \ | |
1354 | }) | |
1355 | ||
1356 | #define rq_list_for_each(listptr, pos) \ | |
1357 | for (pos = rq_list_peek((listptr)); pos; pos = rq_list_next(pos)) \ | |
1358 | ||
1359 | #define rq_list_next(rq) (rq)->rq_next | |
1360 | #define rq_list_empty(list) ((list) == (struct request *) NULL) | |
1361 | ||
3f1266f1 | 1362 | #endif /* _LINUX_BLKDEV_H */ |