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