1923 lines · 54.0 KB · C
RawDownload
/* SPDX-License-Identifier: GPL-2.0 */#ifndef _LINUX_BLKDEV_H#define _LINUX_BLKDEV_H #include <linux/sched.h>#include <linux/sched/clock.h> #ifdef CONFIG_BLOCK #include <linux/major.h>#include <linux/genhd.h>#include <linux/list.h>#include <linux/llist.h>#include <linux/timer.h>#include <linux/workqueue.h>#include <linux/pagemap.h>#include <linux/backing-dev-defs.h>#include <linux/wait.h>#include <linux/mempool.h>#include <linux/pfn.h>#include <linux/bio.h>#include <linux/stringify.h>#include <linux/gfp.h>#include <linux/bsg.h>#include <linux/smp.h>#include <linux/rcupdate.h>#include <linux/percpu-refcount.h>#include <linux/scatterlist.h>#include <linux/blkzoned.h> struct module;struct scsi_ioctl_command; struct request_queue;struct elevator_queue;struct blk_trace;struct request;struct sg_io_hdr;struct bsg_job;struct blkcg_gq;struct blk_flush_queue;struct pr_ops;struct rq_qos;struct blk_queue_stats;struct blk_stat_callback;struct blk_keyslot_manager; #define BLKDEV_MIN_RQ	4#define BLKDEV_MAX_RQ	128	/* Default maximum */ /* Must be consistent with blk_mq_poll_stats_bkt() */#define BLK_MQ_POLL_STATS_BKTS 16 /* Doing classic polling */#define BLK_MQ_POLL_CLASSIC -1 /* * Maximum number of blkcg policies allowed to be registered concurrently. * Defined here to simplify include dependency. */#define BLKCG_MAX_POLS		5 typedef void (rq_end_io_fn)(struct request *, blk_status_t); /* * request flags */typedef __u32 __bitwise req_flags_t; /* elevator knows about this request */#define RQF_SORTED		((__force req_flags_t)(1 << 0))/* drive already may have started this one */#define RQF_STARTED		((__force req_flags_t)(1 << 1))/* may not be passed by ioscheduler */#define RQF_SOFTBARRIER		((__force req_flags_t)(1 << 3))/* request for flush sequence */#define RQF_FLUSH_SEQ		((__force req_flags_t)(1 << 4))/* merge of different types, fail separately */#define RQF_MIXED_MERGE		((__force req_flags_t)(1 << 5))/* track inflight for MQ */#define RQF_MQ_INFLIGHT		((__force req_flags_t)(1 << 6))/* don't call prep for this one */#define RQF_DONTPREP		((__force req_flags_t)(1 << 7))/* set for "ide_preempt" requests and also for requests for which the SCSI   "quiesce" state must be ignored. */#define RQF_PREEMPT		((__force req_flags_t)(1 << 8))/* vaguely specified driver internal error.  Ignored by the block layer */#define RQF_FAILED		((__force req_flags_t)(1 << 10))/* don't warn about errors */#define RQF_QUIET		((__force req_flags_t)(1 << 11))/* elevator private data attached */#define RQF_ELVPRIV		((__force req_flags_t)(1 << 12))/* account into disk and partition IO statistics */#define RQF_IO_STAT		((__force req_flags_t)(1 << 13))/* request came from our alloc pool */#define RQF_ALLOCED		((__force req_flags_t)(1 << 14))/* runtime pm request */#define RQF_PM			((__force req_flags_t)(1 << 15))/* on IO scheduler merge hash */#define RQF_HASHED		((__force req_flags_t)(1 << 16))/* track IO completion time */#define RQF_STATS		((__force req_flags_t)(1 << 17))/* Look at ->special_vec for the actual data payload instead of the   bio chain. */#define RQF_SPECIAL_PAYLOAD	((__force req_flags_t)(1 << 18))/* The per-zone write lock is held for this request */#define RQF_ZONE_WRITE_LOCKED	((__force req_flags_t)(1 << 19))/* already slept for hybrid poll */#define RQF_MQ_POLL_SLEPT	((__force req_flags_t)(1 << 20))/* ->timeout has been called, don't expire again */#define RQF_TIMED_OUT		((__force req_flags_t)(1 << 21)) /* flags that prevent us from merging requests: */#define RQF_NOMERGE_FLAGS \	(RQF_STARTED | RQF_SOFTBARRIER | RQF_FLUSH_SEQ | RQF_SPECIAL_PAYLOAD) /* * Request state for blk-mq. */enum mq_rq_state {	MQ_RQ_IDLE		= 0,	MQ_RQ_IN_FLIGHT		= 1,	MQ_RQ_COMPLETE		= 2,}; /* * Try to put the fields that are referenced together in the same cacheline. * * If you modify this structure, make sure to update blk_rq_init() and * especially blk_mq_rq_ctx_init() to take care of the added fields. */struct request {	struct request_queue *q;	struct blk_mq_ctx *mq_ctx;	struct blk_mq_hw_ctx *mq_hctx; 	unsigned int cmd_flags;		/* op and common flags */	req_flags_t rq_flags; 	int tag;	int internal_tag; 	/* the following two fields are internal, NEVER access directly */	unsigned int __data_len;	/* total data len */	sector_t __sector;		/* sector cursor */ 	struct bio *bio;	struct bio *biotail; 	struct list_head queuelist; 	/*	 * The hash is used inside the scheduler, and killed once the	 * request reaches the dispatch list. The ipi_list is only used	 * to queue the request for softirq completion, which is long	 * after the request has been unhashed (and even removed from	 * the dispatch list).	 */	union {		struct hlist_node hash;	/* merge hash */		struct list_head ipi_list;	}; 	/*	 * The rb_node is only used inside the io scheduler, requests	 * are pruned when moved to the dispatch queue. So let the	 * completion_data share space with the rb_node.	 */	union {		struct rb_node rb_node;	/* sort/lookup */		struct bio_vec special_vec;		void *completion_data;		int error_count; /* for legacy drivers, don't use */	}; 	/*	 * Three pointers are available for the IO schedulers, if they need	 * more they have to dynamically allocate it.  Flush requests are	 * never put on the IO scheduler. So let the flush fields share	 * space with the elevator data.	 */	union {		struct {			struct io_cq		*icq;			void			*priv[2];		} elv; 		struct {			unsigned int		seq;			struct list_head	list;			rq_end_io_fn		*saved_end_io;		} flush;	}; 	struct gendisk *rq_disk;	struct hd_struct *part;#ifdef CONFIG_BLK_RQ_ALLOC_TIME	/* Time that the first bio started allocating this request. */	u64 alloc_time_ns;#endif	/* Time that this request was allocated for this IO. */	u64 start_time_ns;	/* Time that I/O was submitted to the device. */	u64 io_start_time_ns; #ifdef CONFIG_BLK_WBT	unsigned short wbt_flags;#endif	/*	 * rq sectors used for blk stats. It has the same value	 * with blk_rq_sectors(rq), except that it never be zeroed	 * by completion.	 */	unsigned short stats_sectors; 	/*	 * Number of scatter-gather DMA addr+len pairs after	 * physical address coalescing is performed.	 */	unsigned short nr_phys_segments; #if defined(CONFIG_BLK_DEV_INTEGRITY)	unsigned short nr_integrity_segments;#endif #ifdef CONFIG_BLK_INLINE_ENCRYPTION	struct bio_crypt_ctx *crypt_ctx;	struct blk_ksm_keyslot *crypt_keyslot;#endif 	unsigned short write_hint;	unsigned short ioprio; 	enum mq_rq_state state;	refcount_t ref; 	unsigned int timeout;	unsigned long deadline; 	union {		struct __call_single_data csd;		u64 fifo_time;	}; 	/*	 * completion callback.	 */	rq_end_io_fn *end_io;	void *end_io_data;}; static inline bool blk_op_is_scsi(unsigned int op){	return op == REQ_OP_SCSI_IN || op == REQ_OP_SCSI_OUT;} static inline bool blk_op_is_private(unsigned int op){	return op == REQ_OP_DRV_IN || op == REQ_OP_DRV_OUT;} static inline bool blk_rq_is_scsi(struct request *rq){	return blk_op_is_scsi(req_op(rq));} static inline bool blk_rq_is_private(struct request *rq){	return blk_op_is_private(req_op(rq));} static inline bool blk_rq_is_passthrough(struct request *rq){	return blk_rq_is_scsi(rq) || blk_rq_is_private(rq);} static inline bool bio_is_passthrough(struct bio *bio){	unsigned op = bio_op(bio); 	return blk_op_is_scsi(op) || blk_op_is_private(op);} static inline unsigned short req_get_ioprio(struct request *req){	return req->ioprio;} #include <linux/elevator.h> struct blk_queue_ctx; typedef blk_qc_t (make_request_fn) (struct request_queue *q, struct bio *bio); struct bio_vec; enum blk_eh_timer_return {	BLK_EH_DONE,		/* drivers has completed the command */	BLK_EH_RESET_TIMER,	/* reset timer and try again */}; enum blk_queue_state {	Queue_down,	Queue_up,}; #define BLK_TAG_ALLOC_FIFO 0 /* allocate starting from 0 */#define BLK_TAG_ALLOC_RR 1 /* allocate starting from last allocated tag */ #define BLK_SCSI_MAX_CMDS	(256)#define BLK_SCSI_CMD_PER_LONG	(BLK_SCSI_MAX_CMDS / (sizeof(long) * 8)) /* * Zoned block device models (zoned limit). */enum blk_zoned_model {	BLK_ZONED_NONE,	/* Regular block device */	BLK_ZONED_HA,	/* Host-aware zoned block device */	BLK_ZONED_HM,	/* Host-managed zoned block device */}; struct queue_limits {	unsigned long		bounce_pfn;	unsigned long		seg_boundary_mask;	unsigned long		virt_boundary_mask; 	unsigned int		max_hw_sectors;	unsigned int		max_dev_sectors;	unsigned int		chunk_sectors;	unsigned int		max_sectors;	unsigned int		max_segment_size;	unsigned int		physical_block_size;	unsigned int		logical_block_size;	unsigned int		alignment_offset;	unsigned int		io_min;	unsigned int		io_opt;	unsigned int		max_discard_sectors;	unsigned int		max_hw_discard_sectors;	unsigned int		max_write_same_sectors;	unsigned int		max_write_zeroes_sectors;	unsigned int		max_zone_append_sectors;	unsigned int		discard_granularity;	unsigned int		discard_alignment; 	unsigned short		max_segments;	unsigned short		max_integrity_segments;	unsigned short		max_discard_segments; 	unsigned char		misaligned;	unsigned char		discard_misaligned;	unsigned char		raid_partial_stripes_expensive;	enum blk_zoned_model	zoned;}; typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx,			       void *data); #ifdef CONFIG_BLK_DEV_ZONED #define BLK_ALL_ZONES  ((unsigned int)-1)int blkdev_report_zones(struct block_device *bdev, sector_t sector,			unsigned int nr_zones, report_zones_cb cb, void *data);unsigned int blkdev_nr_zones(struct gendisk *disk);extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,			    sector_t sectors, sector_t nr_sectors,			    gfp_t gfp_mask);int blk_revalidate_disk_zones(struct gendisk *disk,			      void (*update_driver_data)(struct gendisk *disk)); extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,				     unsigned int cmd, unsigned long arg);extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,				  unsigned int cmd, unsigned long arg); #else /* CONFIG_BLK_DEV_ZONED */ static inline unsigned int blkdev_nr_zones(struct gendisk *disk){	return 0;} static inline int blkdev_report_zones_ioctl(struct block_device *bdev,					    fmode_t mode, unsigned int cmd,					    unsigned long arg){	return -ENOTTY;} static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev,					 fmode_t mode, unsigned int cmd,					 unsigned long arg){	return -ENOTTY;} #endif /* CONFIG_BLK_DEV_ZONED */ struct request_queue {	struct request		*last_merge;	struct elevator_queue	*elevator; 	struct blk_queue_stats	*stats;	struct rq_qos		*rq_qos; 	make_request_fn		*make_request_fn; 	const struct blk_mq_ops	*mq_ops; 	/* sw queues */	struct blk_mq_ctx __percpu	*queue_ctx; 	unsigned int		queue_depth; 	/* hw dispatch queues */	struct blk_mq_hw_ctx	**queue_hw_ctx;	unsigned int		nr_hw_queues; 	struct backing_dev_info	*backing_dev_info; 	/*	 * The queue owner gets to use this for whatever they like.	 * ll_rw_blk doesn't touch it.	 */	void			*queuedata; 	/*	 * various queue flags, see QUEUE_* below	 */	unsigned long		queue_flags;	/*	 * Number of contexts that have called blk_set_pm_only(). If this	 * counter is above zero then only RQF_PM and RQF_PREEMPT requests are	 * processed.	 */	atomic_t		pm_only; 	/*	 * ida allocated id for this queue.  Used to index queues from	 * ioctx.	 */	int			id; 	/*	 * queue needs bounce pages for pages above this limit	 */	gfp_t			bounce_gfp; 	spinlock_t		queue_lock; 	/*	 * queue kobject	 */	struct kobject kobj; 	/*	 * mq queue kobject	 */	struct kobject *mq_kobj; #ifdef  CONFIG_BLK_DEV_INTEGRITY	struct blk_integrity integrity;#endif	/* CONFIG_BLK_DEV_INTEGRITY */ #ifdef CONFIG_PM	struct device		*dev;	int			rpm_status;	unsigned int		nr_pending;#endif 	/*	 * queue settings	 */	unsigned long		nr_requests;	/* Max # of requests */ 	unsigned int		dma_pad_mask;	unsigned int		dma_alignment; #ifdef CONFIG_BLK_INLINE_ENCRYPTION	/* Inline crypto capabilities */	struct blk_keyslot_manager *ksm;#endif 	unsigned int		rq_timeout;	int			poll_nsec; 	struct blk_stat_callback	*poll_cb;	struct blk_rq_stat	poll_stat[BLK_MQ_POLL_STATS_BKTS]; 	struct timer_list	timeout;	struct work_struct	timeout_work; 	struct list_head	icq_list;#ifdef CONFIG_BLK_CGROUP	DECLARE_BITMAP		(blkcg_pols, BLKCG_MAX_POLS);	struct blkcg_gq		*root_blkg;	struct list_head	blkg_list;#endif 	struct queue_limits	limits; 	unsigned int		required_elevator_features;

Lines 1–500 of 1923.