1 #ifndef _LINUX_ELEVATOR_H 2 #define _LINUX_ELEVATOR_H 3 4 typedef int (elevator_merge_fn) (request_queue_t *, struct request **, 5 struct bio *); 6 7 typedef void (elevator_merge_req_fn) (request_queue_t *, struct request *, struct request *); 8 9 typedef void (elevator_merged_fn) (request_queue_t *, struct request *); 10 11 typedef int (elevator_dispatch_fn) (request_queue_t *, int); 12 13 typedef void (elevator_add_req_fn) (request_queue_t *, struct request *); 14 typedef int (elevator_queue_empty_fn) (request_queue_t *); 15 typedef struct request *(elevator_request_list_fn) (request_queue_t *, struct request *); 16 typedef void (elevator_completed_req_fn) (request_queue_t *, struct request *); 17 typedef int (elevator_may_queue_fn) (request_queue_t *, int, struct bio *); 18 19 typedef int (elevator_set_req_fn) (request_queue_t *, struct request *, struct bio *, gfp_t); 20 typedef void (elevator_put_req_fn) (request_queue_t *, struct request *); 21 typedef void (elevator_activate_req_fn) (request_queue_t *, struct request *); 22 typedef void (elevator_deactivate_req_fn) (request_queue_t *, struct request *); 23 24 typedef void *(elevator_init_fn) (request_queue_t *, elevator_t *); 25 typedef void (elevator_exit_fn) (elevator_t *); 26 27 struct elevator_ops 28 { 29 elevator_merge_fn *elevator_merge_fn; 30 elevator_merged_fn *elevator_merged_fn; 31 elevator_merge_req_fn *elevator_merge_req_fn; 32 33 elevator_dispatch_fn *elevator_dispatch_fn; 34 elevator_add_req_fn *elevator_add_req_fn; 35 elevator_activate_req_fn *elevator_activate_req_fn; 36 elevator_deactivate_req_fn *elevator_deactivate_req_fn; 37 38 elevator_queue_empty_fn *elevator_queue_empty_fn; 39 elevator_completed_req_fn *elevator_completed_req_fn; 40 41 elevator_request_list_fn *elevator_former_req_fn; 42 elevator_request_list_fn *elevator_latter_req_fn; 43 44 elevator_set_req_fn *elevator_set_req_fn; 45 elevator_put_req_fn *elevator_put_req_fn; 46 47 elevator_may_queue_fn *elevator_may_queue_fn; 48 49 elevator_init_fn *elevator_init_fn; 50 elevator_exit_fn *elevator_exit_fn; 51 void (*trim)(struct io_context *); 52 }; 53 54 #define ELV_NAME_MAX (16) 55 56 struct elv_fs_entry { 57 struct attribute attr; 58 ssize_t (*show)(elevator_t *, char *); 59 ssize_t (*store)(elevator_t *, const char *, size_t); 60 }; 61 62 /* 63 * identifies an elevator type, such as AS or deadline 64 */ 65 struct elevator_type 66 { 67 struct list_head list; 68 struct elevator_ops ops; 69 struct elevator_type *elevator_type; 70 struct elv_fs_entry *elevator_attrs; 71 char elevator_name[ELV_NAME_MAX]; 72 struct module *elevator_owner; 73 }; 74 75 /* 76 * each queue has an elevator_queue associated with it 77 */ 78 struct elevator_queue 79 { 80 struct elevator_ops *ops; 81 void *elevator_data; 82 struct kobject kobj; 83 struct elevator_type *elevator_type; 84 struct mutex sysfs_lock; 85 }; 86 87 /* 88 * block elevator interface 89 */ 90 extern void elv_dispatch_sort(request_queue_t *, struct request *); 91 extern void elv_add_request(request_queue_t *, struct request *, int, int); 92 extern void __elv_add_request(request_queue_t *, struct request *, int, int); 93 extern void elv_insert(request_queue_t *, struct request *, int); 94 extern int elv_merge(request_queue_t *, struct request **, struct bio *); 95 extern void elv_merge_requests(request_queue_t *, struct request *, 96 struct request *); 97 extern void elv_merged_request(request_queue_t *, struct request *); 98 extern void elv_dequeue_request(request_queue_t *, struct request *); 99 extern void elv_requeue_request(request_queue_t *, struct request *); 100 extern int elv_queue_empty(request_queue_t *); 101 extern struct request *elv_next_request(struct request_queue *q); 102 extern struct request *elv_former_request(request_queue_t *, struct request *); 103 extern struct request *elv_latter_request(request_queue_t *, struct request *); 104 extern int elv_register_queue(request_queue_t *q); 105 extern void elv_unregister_queue(request_queue_t *q); 106 extern int elv_may_queue(request_queue_t *, int, struct bio *); 107 extern void elv_completed_request(request_queue_t *, struct request *); 108 extern int elv_set_request(request_queue_t *, struct request *, struct bio *, gfp_t); 109 extern void elv_put_request(request_queue_t *, struct request *); 110 111 /* 112 * io scheduler registration 113 */ 114 extern int elv_register(struct elevator_type *); 115 extern void elv_unregister(struct elevator_type *); 116 117 /* 118 * io scheduler sysfs switching 119 */ 120 extern ssize_t elv_iosched_show(request_queue_t *, char *); 121 extern ssize_t elv_iosched_store(request_queue_t *, const char *, size_t); 122 123 extern int elevator_init(request_queue_t *, char *); 124 extern void elevator_exit(elevator_t *); 125 extern int elv_rq_merge_ok(struct request *, struct bio *); 126 127 /* 128 * Return values from elevator merger 129 */ 130 #define ELEVATOR_NO_MERGE 0 131 #define ELEVATOR_FRONT_MERGE 1 132 #define ELEVATOR_BACK_MERGE 2 133 134 /* 135 * Insertion selection 136 */ 137 #define ELEVATOR_INSERT_FRONT 1 138 #define ELEVATOR_INSERT_BACK 2 139 #define ELEVATOR_INSERT_SORT 3 140 #define ELEVATOR_INSERT_REQUEUE 4 141 142 /* 143 * return values from elevator_may_queue_fn 144 */ 145 enum { 146 ELV_MQUEUE_MAY, 147 ELV_MQUEUE_NO, 148 ELV_MQUEUE_MUST, 149 }; 150 151 #define rq_end_sector(rq) ((rq)->sector + (rq)->nr_sectors) 152 153 #endif 154