Commit c51ca6cf authored by Jens Axboe's avatar Jens Axboe

block: move existing elevator ops to union

Prep patch for adding MQ ops as well, since doing anon unions with
named initializers doesn't work on older compilers.
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: default avatarBart Van Assche <bart.vanassche@sandisk.com>
Reviewed-by: default avatarOmar Sandoval <osandov@fb.com>
parent c5082b70
...@@ -43,8 +43,8 @@ static void ioc_exit_icq(struct io_cq *icq) ...@@ -43,8 +43,8 @@ static void ioc_exit_icq(struct io_cq *icq)
if (icq->flags & ICQ_EXITED) if (icq->flags & ICQ_EXITED)
return; return;
if (et->ops.elevator_exit_icq_fn) if (et->ops.sq.elevator_exit_icq_fn)
et->ops.elevator_exit_icq_fn(icq); et->ops.sq.elevator_exit_icq_fn(icq);
icq->flags |= ICQ_EXITED; icq->flags |= ICQ_EXITED;
} }
...@@ -383,8 +383,8 @@ struct io_cq *ioc_create_icq(struct io_context *ioc, struct request_queue *q, ...@@ -383,8 +383,8 @@ struct io_cq *ioc_create_icq(struct io_context *ioc, struct request_queue *q,
if (likely(!radix_tree_insert(&ioc->icq_tree, q->id, icq))) { if (likely(!radix_tree_insert(&ioc->icq_tree, q->id, icq))) {
hlist_add_head(&icq->ioc_node, &ioc->icq_list); hlist_add_head(&icq->ioc_node, &ioc->icq_list);
list_add(&icq->q_node, &q->icq_list); list_add(&icq->q_node, &q->icq_list);
if (et->ops.elevator_init_icq_fn) if (et->ops.sq.elevator_init_icq_fn)
et->ops.elevator_init_icq_fn(icq); et->ops.sq.elevator_init_icq_fn(icq);
} else { } else {
kmem_cache_free(et->icq_cache, icq); kmem_cache_free(et->icq_cache, icq);
icq = ioc_lookup_icq(ioc, q); icq = ioc_lookup_icq(ioc, q);
......
...@@ -763,8 +763,8 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq, ...@@ -763,8 +763,8 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq,
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_allow_rq_merge_fn) if (e->type->ops.sq.elevator_allow_rq_merge_fn)
if (!e->type->ops.elevator_allow_rq_merge_fn(q, rq, next)) if (!e->type->ops.sq.elevator_allow_rq_merge_fn(q, rq, next))
return 0; return 0;
return attempt_merge(q, rq, next); return attempt_merge(q, rq, next);
......
...@@ -167,7 +167,7 @@ static inline struct request *__elv_next_request(struct request_queue *q) ...@@ -167,7 +167,7 @@ static inline struct request *__elv_next_request(struct request_queue *q)
return NULL; return NULL;
} }
if (unlikely(blk_queue_bypass(q)) || if (unlikely(blk_queue_bypass(q)) ||
!q->elevator->type->ops.elevator_dispatch_fn(q, 0)) !q->elevator->type->ops.sq.elevator_dispatch_fn(q, 0))
return NULL; return NULL;
} }
} }
...@@ -176,16 +176,16 @@ static inline void elv_activate_rq(struct request_queue *q, struct request *rq) ...@@ -176,16 +176,16 @@ static inline void elv_activate_rq(struct request_queue *q, struct request *rq)
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_activate_req_fn) if (e->type->ops.sq.elevator_activate_req_fn)
e->type->ops.elevator_activate_req_fn(q, rq); e->type->ops.sq.elevator_activate_req_fn(q, rq);
} }
static inline void elv_deactivate_rq(struct request_queue *q, struct request *rq) static inline void elv_deactivate_rq(struct request_queue *q, struct request *rq)
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_deactivate_req_fn) if (e->type->ops.sq.elevator_deactivate_req_fn)
e->type->ops.elevator_deactivate_req_fn(q, rq); e->type->ops.sq.elevator_deactivate_req_fn(q, rq);
} }
#ifdef CONFIG_FAIL_IO_TIMEOUT #ifdef CONFIG_FAIL_IO_TIMEOUT
......
...@@ -4837,7 +4837,7 @@ static struct elv_fs_entry cfq_attrs[] = { ...@@ -4837,7 +4837,7 @@ static struct elv_fs_entry cfq_attrs[] = {
}; };
static struct elevator_type iosched_cfq = { static struct elevator_type iosched_cfq = {
.ops = { .ops.sq = {
.elevator_merge_fn = cfq_merge, .elevator_merge_fn = cfq_merge,
.elevator_merged_fn = cfq_merged_request, .elevator_merged_fn = cfq_merged_request,
.elevator_merge_req_fn = cfq_merged_requests, .elevator_merge_req_fn = cfq_merged_requests,
......
...@@ -439,7 +439,7 @@ static struct elv_fs_entry deadline_attrs[] = { ...@@ -439,7 +439,7 @@ static struct elv_fs_entry deadline_attrs[] = {
}; };
static struct elevator_type iosched_deadline = { static struct elevator_type iosched_deadline = {
.ops = { .ops.sq = {
.elevator_merge_fn = deadline_merge, .elevator_merge_fn = deadline_merge,
.elevator_merged_fn = deadline_merged_request, .elevator_merged_fn = deadline_merged_request,
.elevator_merge_req_fn = deadline_merged_requests, .elevator_merge_req_fn = deadline_merged_requests,
......
...@@ -58,8 +58,8 @@ static int elv_iosched_allow_bio_merge(struct request *rq, struct bio *bio) ...@@ -58,8 +58,8 @@ static int elv_iosched_allow_bio_merge(struct request *rq, struct bio *bio)
struct request_queue *q = rq->q; struct request_queue *q = rq->q;
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_allow_bio_merge_fn) if (e->type->ops.sq.elevator_allow_bio_merge_fn)
return e->type->ops.elevator_allow_bio_merge_fn(q, rq, bio); return e->type->ops.sq.elevator_allow_bio_merge_fn(q, rq, bio);
return 1; return 1;
} }
...@@ -224,7 +224,7 @@ int elevator_init(struct request_queue *q, char *name) ...@@ -224,7 +224,7 @@ int elevator_init(struct request_queue *q, char *name)
} }
} }
err = e->ops.elevator_init_fn(q, e); err = e->ops.sq.elevator_init_fn(q, e);
if (err) if (err)
elevator_put(e); elevator_put(e);
return err; return err;
...@@ -234,8 +234,8 @@ EXPORT_SYMBOL(elevator_init); ...@@ -234,8 +234,8 @@ EXPORT_SYMBOL(elevator_init);
void elevator_exit(struct elevator_queue *e) void elevator_exit(struct elevator_queue *e)
{ {
mutex_lock(&e->sysfs_lock); mutex_lock(&e->sysfs_lock);
if (e->type->ops.elevator_exit_fn) if (e->type->ops.sq.elevator_exit_fn)
e->type->ops.elevator_exit_fn(e); e->type->ops.sq.elevator_exit_fn(e);
mutex_unlock(&e->sysfs_lock); mutex_unlock(&e->sysfs_lock);
kobject_put(&e->kobj); kobject_put(&e->kobj);
...@@ -443,8 +443,8 @@ int elv_merge(struct request_queue *q, struct request **req, struct bio *bio) ...@@ -443,8 +443,8 @@ int elv_merge(struct request_queue *q, struct request **req, struct bio *bio)
return ELEVATOR_BACK_MERGE; return ELEVATOR_BACK_MERGE;
} }
if (e->type->ops.elevator_merge_fn) if (e->type->ops.sq.elevator_merge_fn)
return e->type->ops.elevator_merge_fn(q, req, bio); return e->type->ops.sq.elevator_merge_fn(q, req, bio);
return ELEVATOR_NO_MERGE; return ELEVATOR_NO_MERGE;
} }
...@@ -495,8 +495,8 @@ void elv_merged_request(struct request_queue *q, struct request *rq, int type) ...@@ -495,8 +495,8 @@ void elv_merged_request(struct request_queue *q, struct request *rq, int type)
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_merged_fn) if (e->type->ops.sq.elevator_merged_fn)
e->type->ops.elevator_merged_fn(q, rq, type); e->type->ops.sq.elevator_merged_fn(q, rq, type);
if (type == ELEVATOR_BACK_MERGE) if (type == ELEVATOR_BACK_MERGE)
elv_rqhash_reposition(q, rq); elv_rqhash_reposition(q, rq);
...@@ -510,8 +510,8 @@ void elv_merge_requests(struct request_queue *q, struct request *rq, ...@@ -510,8 +510,8 @@ void elv_merge_requests(struct request_queue *q, struct request *rq,
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
const int next_sorted = next->rq_flags & RQF_SORTED; const int next_sorted = next->rq_flags & RQF_SORTED;
if (next_sorted && e->type->ops.elevator_merge_req_fn) if (next_sorted && e->type->ops.sq.elevator_merge_req_fn)
e->type->ops.elevator_merge_req_fn(q, rq, next); e->type->ops.sq.elevator_merge_req_fn(q, rq, next);
elv_rqhash_reposition(q, rq); elv_rqhash_reposition(q, rq);
...@@ -528,8 +528,8 @@ void elv_bio_merged(struct request_queue *q, struct request *rq, ...@@ -528,8 +528,8 @@ void elv_bio_merged(struct request_queue *q, struct request *rq,
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_bio_merged_fn) if (e->type->ops.sq.elevator_bio_merged_fn)
e->type->ops.elevator_bio_merged_fn(q, rq, bio); e->type->ops.sq.elevator_bio_merged_fn(q, rq, bio);
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
...@@ -578,7 +578,7 @@ void elv_drain_elevator(struct request_queue *q) ...@@ -578,7 +578,7 @@ void elv_drain_elevator(struct request_queue *q)
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
while (q->elevator->type->ops.elevator_dispatch_fn(q, 1)) while (q->elevator->type->ops.sq.elevator_dispatch_fn(q, 1))
; ;
if (q->nr_sorted && printed++ < 10) { if (q->nr_sorted && printed++ < 10) {
printk(KERN_ERR "%s: forced dispatching is broken " printk(KERN_ERR "%s: forced dispatching is broken "
...@@ -653,7 +653,7 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where) ...@@ -653,7 +653,7 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where)
* rq cannot be accessed after calling * rq cannot be accessed after calling
* elevator_add_req_fn. * elevator_add_req_fn.
*/ */
q->elevator->type->ops.elevator_add_req_fn(q, rq); q->elevator->type->ops.sq.elevator_add_req_fn(q, rq);
break; break;
case ELEVATOR_INSERT_FLUSH: case ELEVATOR_INSERT_FLUSH:
...@@ -682,8 +682,8 @@ struct request *elv_latter_request(struct request_queue *q, struct request *rq) ...@@ -682,8 +682,8 @@ struct request *elv_latter_request(struct request_queue *q, struct request *rq)
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_latter_req_fn) if (e->type->ops.sq.elevator_latter_req_fn)
return e->type->ops.elevator_latter_req_fn(q, rq); return e->type->ops.sq.elevator_latter_req_fn(q, rq);
return NULL; return NULL;
} }
...@@ -691,8 +691,8 @@ struct request *elv_former_request(struct request_queue *q, struct request *rq) ...@@ -691,8 +691,8 @@ struct request *elv_former_request(struct request_queue *q, struct request *rq)
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_former_req_fn) if (e->type->ops.sq.elevator_former_req_fn)
return e->type->ops.elevator_former_req_fn(q, rq); return e->type->ops.sq.elevator_former_req_fn(q, rq);
return NULL; return NULL;
} }
...@@ -701,8 +701,8 @@ int elv_set_request(struct request_queue *q, struct request *rq, ...@@ -701,8 +701,8 @@ int elv_set_request(struct request_queue *q, struct request *rq,
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_set_req_fn) if (e->type->ops.sq.elevator_set_req_fn)
return e->type->ops.elevator_set_req_fn(q, rq, bio, gfp_mask); return e->type->ops.sq.elevator_set_req_fn(q, rq, bio, gfp_mask);
return 0; return 0;
} }
...@@ -710,16 +710,16 @@ void elv_put_request(struct request_queue *q, struct request *rq) ...@@ -710,16 +710,16 @@ void elv_put_request(struct request_queue *q, struct request *rq)
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_put_req_fn) if (e->type->ops.sq.elevator_put_req_fn)
e->type->ops.elevator_put_req_fn(rq); e->type->ops.sq.elevator_put_req_fn(rq);
} }
int elv_may_queue(struct request_queue *q, unsigned int op) int elv_may_queue(struct request_queue *q, unsigned int op)
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_may_queue_fn) if (e->type->ops.sq.elevator_may_queue_fn)
return e->type->ops.elevator_may_queue_fn(q, op); return e->type->ops.sq.elevator_may_queue_fn(q, op);
return ELV_MQUEUE_MAY; return ELV_MQUEUE_MAY;
} }
...@@ -734,8 +734,8 @@ void elv_completed_request(struct request_queue *q, struct request *rq) ...@@ -734,8 +734,8 @@ void elv_completed_request(struct request_queue *q, struct request *rq)
if (blk_account_rq(rq)) { if (blk_account_rq(rq)) {
q->in_flight[rq_is_sync(rq)]--; q->in_flight[rq_is_sync(rq)]--;
if ((rq->rq_flags & RQF_SORTED) && if ((rq->rq_flags & RQF_SORTED) &&
e->type->ops.elevator_completed_req_fn) e->type->ops.sq.elevator_completed_req_fn)
e->type->ops.elevator_completed_req_fn(q, rq); e->type->ops.sq.elevator_completed_req_fn(q, rq);
} }
} }
...@@ -803,8 +803,8 @@ int elv_register_queue(struct request_queue *q) ...@@ -803,8 +803,8 @@ int elv_register_queue(struct request_queue *q)
} }
kobject_uevent(&e->kobj, KOBJ_ADD); kobject_uevent(&e->kobj, KOBJ_ADD);
e->registered = 1; e->registered = 1;
if (e->type->ops.elevator_registered_fn) if (e->type->ops.sq.elevator_registered_fn)
e->type->ops.elevator_registered_fn(q); e->type->ops.sq.elevator_registered_fn(q);
} }
return error; return error;
} }
...@@ -912,7 +912,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e) ...@@ -912,7 +912,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
spin_unlock_irq(q->queue_lock); spin_unlock_irq(q->queue_lock);
/* allocate, init and register new elevator */ /* allocate, init and register new elevator */
err = new_e->ops.elevator_init_fn(q, new_e); err = new_e->ops.sq.elevator_init_fn(q, new_e);
if (err) if (err)
goto fail_init; goto fail_init;
......
...@@ -92,7 +92,7 @@ static void noop_exit_queue(struct elevator_queue *e) ...@@ -92,7 +92,7 @@ static void noop_exit_queue(struct elevator_queue *e)
} }
static struct elevator_type elevator_noop = { static struct elevator_type elevator_noop = {
.ops = { .ops.sq = {
.elevator_merge_req_fn = noop_merged_requests, .elevator_merge_req_fn = noop_merged_requests,
.elevator_dispatch_fn = noop_dispatch, .elevator_dispatch_fn = noop_dispatch,
.elevator_add_req_fn = noop_add_request, .elevator_add_req_fn = noop_add_request,
......
...@@ -94,7 +94,9 @@ struct elevator_type ...@@ -94,7 +94,9 @@ struct elevator_type
struct kmem_cache *icq_cache; struct kmem_cache *icq_cache;
/* fields provided by elevator implementation */ /* fields provided by elevator implementation */
struct elevator_ops ops; union {
struct elevator_ops sq;
} ops;
size_t icq_size; /* see iocontext.h */ size_t icq_size; /* see iocontext.h */
size_t icq_align; /* ditto */ size_t icq_align; /* ditto */
struct elv_fs_entry *elevator_attrs; struct elv_fs_entry *elevator_attrs;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment