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