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