]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - include/linux/elevator.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_ELEVATOR_H
3 #define _LINUX_ELEVATOR_H
5 #include <linux/percpu.h>
6 #include <linux/hashtable.h>
12 #ifdef CONFIG_BLK_DEBUG_FS
13 struct blk_mq_debugfs_attr
;
17 * Return values from elevator merger
20 ELEVATOR_NO_MERGE
= 0,
21 ELEVATOR_FRONT_MERGE
= 1,
22 ELEVATOR_BACK_MERGE
= 2,
23 ELEVATOR_DISCARD_MERGE
= 3,
26 struct blk_mq_alloc_data
;
29 struct elevator_mq_ops
{
30 int (*init_sched
)(struct request_queue
*, struct elevator_type
*);
31 void (*exit_sched
)(struct elevator_queue
*);
32 int (*init_hctx
)(struct blk_mq_hw_ctx
*, unsigned int);
33 void (*exit_hctx
)(struct blk_mq_hw_ctx
*, unsigned int);
34 void (*depth_updated
)(struct blk_mq_hw_ctx
*);
36 bool (*allow_merge
)(struct request_queue
*, struct request
*, struct bio
*);
37 bool (*bio_merge
)(struct blk_mq_hw_ctx
*, struct bio
*);
38 int (*request_merge
)(struct request_queue
*q
, struct request
**, struct bio
*);
39 void (*request_merged
)(struct request_queue
*, struct request
*, enum elv_merge
);
40 void (*requests_merged
)(struct request_queue
*, struct request
*, struct request
*);
41 void (*limit_depth
)(unsigned int, struct blk_mq_alloc_data
*);
42 void (*prepare_request
)(struct request
*, struct bio
*bio
);
43 void (*finish_request
)(struct request
*);
44 void (*insert_requests
)(struct blk_mq_hw_ctx
*, struct list_head
*, bool);
45 struct request
*(*dispatch_request
)(struct blk_mq_hw_ctx
*);
46 bool (*has_work
)(struct blk_mq_hw_ctx
*);
47 void (*completed_request
)(struct request
*, u64
);
48 void (*started_request
)(struct request
*);
49 void (*requeue_request
)(struct request
*);
50 struct request
*(*former_request
)(struct request_queue
*, struct request
*);
51 struct request
*(*next_request
)(struct request_queue
*, struct request
*);
52 void (*init_icq
)(struct io_cq
*);
53 void (*exit_icq
)(struct io_cq
*);
56 #define ELV_NAME_MAX (16)
59 struct attribute attr
;
60 ssize_t (*show
)(struct elevator_queue
*, char *);
61 ssize_t (*store
)(struct elevator_queue
*, const char *, size_t);
65 * identifies an elevator type, such as AS or deadline
69 /* managed by elevator core */
70 struct kmem_cache
*icq_cache
;
72 /* fields provided by elevator implementation */
73 struct elevator_mq_ops ops
;
75 size_t icq_size
; /* see iocontext.h */
76 size_t icq_align
; /* ditto */
77 struct elv_fs_entry
*elevator_attrs
;
78 char elevator_name
[ELV_NAME_MAX
];
79 const char *elevator_alias
;
80 struct module
*elevator_owner
;
81 #ifdef CONFIG_BLK_DEBUG_FS
82 const struct blk_mq_debugfs_attr
*queue_debugfs_attrs
;
83 const struct blk_mq_debugfs_attr
*hctx_debugfs_attrs
;
86 /* managed by elevator core */
87 char icq_cache_name
[ELV_NAME_MAX
+ 6]; /* elvname + "_io_cq" */
88 struct list_head list
;
91 #define ELV_HASH_BITS 6
93 void elv_rqhash_del(struct request_queue
*q
, struct request
*rq
);
94 void elv_rqhash_add(struct request_queue
*q
, struct request
*rq
);
95 void elv_rqhash_reposition(struct request_queue
*q
, struct request
*rq
);
96 struct request
*elv_rqhash_find(struct request_queue
*q
, sector_t offset
);
99 * each queue has an elevator_queue associated with it
101 struct elevator_queue
103 struct elevator_type
*type
;
106 struct mutex sysfs_lock
;
107 unsigned int registered
:1;
108 DECLARE_HASHTABLE(hash
, ELV_HASH_BITS
);
112 * block elevator interface
114 extern enum elv_merge
elv_merge(struct request_queue
*, struct request
**,
116 extern void elv_merge_requests(struct request_queue
*, struct request
*,
118 extern void elv_merged_request(struct request_queue
*, struct request
*,
120 extern bool elv_attempt_insert_merge(struct request_queue
*, struct request
*);
121 extern struct request
*elv_former_request(struct request_queue
*, struct request
*);
122 extern struct request
*elv_latter_request(struct request_queue
*, struct request
*);
125 * io scheduler registration
127 extern int elv_register(struct elevator_type
*);
128 extern void elv_unregister(struct elevator_type
*);
131 * io scheduler sysfs switching
133 extern ssize_t
elv_iosched_show(struct request_queue
*, char *);
134 extern ssize_t
elv_iosched_store(struct request_queue
*, const char *, size_t);
136 extern bool elv_bio_merge_ok(struct request
*, struct bio
*);
137 extern struct elevator_queue
*elevator_alloc(struct request_queue
*,
138 struct elevator_type
*);
143 extern struct request
*elv_rb_former_request(struct request_queue
*, struct request
*);
144 extern struct request
*elv_rb_latter_request(struct request_queue
*, struct request
*);
147 * rb support functions.
149 extern void elv_rb_add(struct rb_root
*, struct request
*);
150 extern void elv_rb_del(struct rb_root
*, struct request
*);
151 extern struct request
*elv_rb_find(struct rb_root
*, sector_t
);
154 * Insertion selection
156 #define ELEVATOR_INSERT_FRONT 1
157 #define ELEVATOR_INSERT_BACK 2
158 #define ELEVATOR_INSERT_SORT 3
159 #define ELEVATOR_INSERT_REQUEUE 4
160 #define ELEVATOR_INSERT_FLUSH 5
161 #define ELEVATOR_INSERT_SORT_MERGE 6
164 * return values from elevator_may_queue_fn
172 #define rq_end_sector(rq) (blk_rq_pos(rq) + blk_rq_sectors(rq))
173 #define rb_entry_rq(node) rb_entry((node), struct request, rb_node)
175 #define rq_entry_fifo(ptr) list_entry((ptr), struct request, queuelist)
176 #define rq_fifo_clear(rq) list_del_init(&(rq)->queuelist)
178 #endif /* CONFIG_BLOCK */