Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 9 | typedef void (elevator_merged_fn) (request_queue_t *, struct request *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 11 | typedef int (elevator_dispatch_fn) (request_queue_t *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 13 | typedef void (elevator_add_req_fn) (request_queue_t *, struct request *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | typedef int (elevator_queue_empty_fn) (request_queue_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 *); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 17 | typedef int (elevator_may_queue_fn) (request_queue_t *, int, struct bio *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Al Viro | 8267e26 | 2005-10-21 03:20:53 -0400 | [diff] [blame] | 19 | typedef int (elevator_set_req_fn) (request_queue_t *, struct request *, struct bio *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | typedef void (elevator_put_req_fn) (request_queue_t *, struct request *); |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 21 | typedef void (elevator_activate_req_fn) (request_queue_t *, struct request *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | typedef void (elevator_deactivate_req_fn) (request_queue_t *, struct request *); |
| 23 | |
Jens Axboe | bc1c116 | 2006-06-08 08:49:06 +0200 | [diff] [blame] | 24 | typedef void *(elevator_init_fn) (request_queue_t *, elevator_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 33 | elevator_dispatch_fn *elevator_dispatch_fn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | elevator_add_req_fn *elevator_add_req_fn; |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 35 | elevator_activate_req_fn *elevator_activate_req_fn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Al Viro | e17a948 | 2006-03-18 13:21:20 -0500 | [diff] [blame] | 51 | void (*trim)(struct io_context *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | #define ELV_NAME_MAX (16) |
| 55 | |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 70 | struct elv_fs_entry *elevator_attrs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | char elevator_name[ELV_NAME_MAX]; |
| 72 | struct module *elevator_owner; |
| 73 | }; |
| 74 | |
| 75 | /* |
Adrian Bunk | 5406958 | 2006-01-10 00:09:36 +0100 | [diff] [blame] | 76 | * each queue has an elevator_queue associated with it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 84 | struct mutex sysfs_lock; |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 85 | struct hlist_head *hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | /* |
| 89 | * block elevator interface |
| 90 | */ |
Jens Axboe | 1b47f53 | 2005-10-20 16:37:00 +0200 | [diff] [blame] | 91 | extern void elv_dispatch_sort(request_queue_t *, struct request *); |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 92 | extern void elv_dispatch_add_tail(request_queue_t *, struct request *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | extern void elv_add_request(request_queue_t *, struct request *, int, int); |
| 94 | extern void __elv_add_request(request_queue_t *, struct request *, int, int); |
Tejun Heo | 30e9656 | 2006-02-08 01:01:31 -0800 | [diff] [blame] | 95 | extern void elv_insert(request_queue_t *, struct request *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | extern int elv_merge(request_queue_t *, struct request **, struct bio *); |
| 97 | extern void elv_merge_requests(request_queue_t *, struct request *, |
| 98 | struct request *); |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 99 | extern void elv_merged_request(request_queue_t *, struct request *, int); |
Tejun Heo | 8922e16 | 2005-10-20 16:23:44 +0200 | [diff] [blame] | 100 | extern void elv_dequeue_request(request_queue_t *, struct request *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | extern void elv_requeue_request(request_queue_t *, struct request *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | extern int elv_queue_empty(request_queue_t *); |
| 103 | extern struct request *elv_next_request(struct request_queue *q); |
| 104 | extern struct request *elv_former_request(request_queue_t *, struct request *); |
| 105 | extern struct request *elv_latter_request(request_queue_t *, struct request *); |
| 106 | extern int elv_register_queue(request_queue_t *q); |
| 107 | extern void elv_unregister_queue(request_queue_t *q); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 108 | extern int elv_may_queue(request_queue_t *, int, struct bio *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | extern void elv_completed_request(request_queue_t *, struct request *); |
Al Viro | 8267e26 | 2005-10-21 03:20:53 -0400 | [diff] [blame] | 110 | extern int elv_set_request(request_queue_t *, struct request *, struct bio *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | extern void elv_put_request(request_queue_t *, struct request *); |
| 112 | |
| 113 | /* |
| 114 | * io scheduler registration |
| 115 | */ |
| 116 | extern int elv_register(struct elevator_type *); |
| 117 | extern void elv_unregister(struct elevator_type *); |
| 118 | |
| 119 | /* |
| 120 | * io scheduler sysfs switching |
| 121 | */ |
| 122 | extern ssize_t elv_iosched_show(request_queue_t *, char *); |
| 123 | extern ssize_t elv_iosched_store(request_queue_t *, const char *, size_t); |
| 124 | |
| 125 | extern int elevator_init(request_queue_t *, char *); |
| 126 | extern void elevator_exit(elevator_t *); |
| 127 | extern int elv_rq_merge_ok(struct request *, struct bio *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | /* |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 130 | * Helper functions. |
| 131 | */ |
| 132 | extern struct request *elv_rb_former_request(request_queue_t *, struct request *); |
| 133 | extern struct request *elv_rb_latter_request(request_queue_t *, struct request *); |
| 134 | |
| 135 | /* |
| 136 | * rb support functions. |
| 137 | */ |
| 138 | extern struct request *elv_rb_add(struct rb_root *, struct request *); |
| 139 | extern void elv_rb_del(struct rb_root *, struct request *); |
| 140 | extern struct request *elv_rb_find(struct rb_root *, sector_t); |
| 141 | |
| 142 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | * Return values from elevator merger |
| 144 | */ |
| 145 | #define ELEVATOR_NO_MERGE 0 |
| 146 | #define ELEVATOR_FRONT_MERGE 1 |
| 147 | #define ELEVATOR_BACK_MERGE 2 |
| 148 | |
| 149 | /* |
| 150 | * Insertion selection |
| 151 | */ |
| 152 | #define ELEVATOR_INSERT_FRONT 1 |
| 153 | #define ELEVATOR_INSERT_BACK 2 |
| 154 | #define ELEVATOR_INSERT_SORT 3 |
Tejun Heo | 797e7db | 2006-01-06 09:51:03 +0100 | [diff] [blame] | 155 | #define ELEVATOR_INSERT_REQUEUE 4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * return values from elevator_may_queue_fn |
| 159 | */ |
| 160 | enum { |
| 161 | ELV_MQUEUE_MAY, |
| 162 | ELV_MQUEUE_NO, |
| 163 | ELV_MQUEUE_MUST, |
| 164 | }; |
| 165 | |
Jens Axboe | 1b47f53 | 2005-10-20 16:37:00 +0200 | [diff] [blame] | 166 | #define rq_end_sector(rq) ((rq)->sector + (rq)->nr_sectors) |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 167 | #define rb_entry_rq(node) rb_entry((node), struct request, rb_node) |
Jens Axboe | 1b47f53 | 2005-10-20 16:37:00 +0200 | [diff] [blame] | 168 | |
Jens Axboe | 1fbfdfc | 2006-07-11 21:49:15 +0200 | [diff] [blame^] | 169 | /* |
| 170 | * Hack to reuse the donelist list_head as the fifo time holder while |
| 171 | * the request is in the io scheduler. Saves an unsigned long in rq. |
| 172 | */ |
| 173 | #define rq_fifo_time(rq) ((unsigned long) (rq)->donelist.next) |
| 174 | #define rq_set_fifo_time(rq,exp) ((rq)->donelist.next = (void *) (exp)) |
| 175 | #define rq_entry_fifo(ptr) list_entry((ptr), struct request, queuelist) |
| 176 | #define rq_fifo_clear(rq) do { \ |
| 177 | list_del_init(&(rq)->queuelist); \ |
| 178 | INIT_LIST_HEAD(&(rq)->donelist); \ |
| 179 | } while (0) |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | #endif |