Commit 22f746e2 authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

block: remove elevator_queue->ops

elevator_queue->ops points to the same ops struct ->elevator_type.ops
is pointing to.  The only effect of caching it in elevator_queue is
shorter notation - it doesn't save any indirect derefence.

Relocate elevator_type->list which used only during module init/exit
to the end of the structure, rename elevator_queue->elevator_type to
->type, and replace elevator_queue->ops with elevator_queue->type.ops.

This doesn't introduce any functional difference.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent f8fc877d
...@@ -94,7 +94,7 @@ static inline struct request *__elv_next_request(struct request_queue *q) ...@@ -94,7 +94,7 @@ static inline struct request *__elv_next_request(struct request_queue *q)
return NULL; return NULL;
} }
if (unlikely(blk_queue_dead(q)) || if (unlikely(blk_queue_dead(q)) ||
!q->elevator->ops->elevator_dispatch_fn(q, 0)) !q->elevator->type->ops.elevator_dispatch_fn(q, 0))
return NULL; return NULL;
} }
} }
...@@ -103,16 +103,16 @@ static inline void elv_activate_rq(struct request_queue *q, struct request *rq) ...@@ -103,16 +103,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->ops->elevator_activate_req_fn) if (e->type->ops.elevator_activate_req_fn)
e->ops->elevator_activate_req_fn(q, rq); e->type->ops.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->ops->elevator_deactivate_req_fn) if (e->type->ops.elevator_deactivate_req_fn)
e->ops->elevator_deactivate_req_fn(q, rq); e->type->ops.elevator_deactivate_req_fn(q, rq);
} }
#ifdef CONFIG_FAIL_IO_TIMEOUT #ifdef CONFIG_FAIL_IO_TIMEOUT
......
...@@ -61,8 +61,8 @@ static int elv_iosched_allow_merge(struct request *rq, struct bio *bio) ...@@ -61,8 +61,8 @@ static int elv_iosched_allow_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->ops->elevator_allow_merge_fn) if (e->type->ops.elevator_allow_merge_fn)
return e->ops->elevator_allow_merge_fn(q, rq, bio); return e->type->ops.elevator_allow_merge_fn(q, rq, bio);
return 1; return 1;
} }
...@@ -171,7 +171,7 @@ static struct elevator_type *elevator_get(const char *name) ...@@ -171,7 +171,7 @@ static struct elevator_type *elevator_get(const char *name)
static int elevator_init_queue(struct request_queue *q, static int elevator_init_queue(struct request_queue *q,
struct elevator_queue *eq) struct elevator_queue *eq)
{ {
eq->elevator_data = eq->ops->elevator_init_fn(q); eq->elevator_data = eq->type->ops.elevator_init_fn(q);
if (eq->elevator_data) if (eq->elevator_data)
return 0; return 0;
return -ENOMEM; return -ENOMEM;
...@@ -203,8 +203,7 @@ static struct elevator_queue *elevator_alloc(struct request_queue *q, ...@@ -203,8 +203,7 @@ static struct elevator_queue *elevator_alloc(struct request_queue *q,
if (unlikely(!eq)) if (unlikely(!eq))
goto err; goto err;
eq->ops = &e->ops; eq->type = e;
eq->elevator_type = e;
kobject_init(&eq->kobj, &elv_ktype); kobject_init(&eq->kobj, &elv_ktype);
mutex_init(&eq->sysfs_lock); mutex_init(&eq->sysfs_lock);
...@@ -228,7 +227,7 @@ static void elevator_release(struct kobject *kobj) ...@@ -228,7 +227,7 @@ static void elevator_release(struct kobject *kobj)
struct elevator_queue *e; struct elevator_queue *e;
e = container_of(kobj, struct elevator_queue, kobj); e = container_of(kobj, struct elevator_queue, kobj);
elevator_put(e->elevator_type); elevator_put(e->type);
kfree(e->hash); kfree(e->hash);
kfree(e); kfree(e);
} }
...@@ -288,9 +287,8 @@ EXPORT_SYMBOL(elevator_init); ...@@ -288,9 +287,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->ops->elevator_exit_fn) if (e->type->ops.elevator_exit_fn)
e->ops->elevator_exit_fn(e); e->type->ops.elevator_exit_fn(e);
e->ops = NULL;
mutex_unlock(&e->sysfs_lock); mutex_unlock(&e->sysfs_lock);
kobject_put(&e->kobj); kobject_put(&e->kobj);
...@@ -500,8 +498,8 @@ int elv_merge(struct request_queue *q, struct request **req, struct bio *bio) ...@@ -500,8 +498,8 @@ int elv_merge(struct request_queue *q, struct request **req, struct bio *bio)
return ELEVATOR_BACK_MERGE; return ELEVATOR_BACK_MERGE;
} }
if (e->ops->elevator_merge_fn) if (e->type->ops.elevator_merge_fn)
return e->ops->elevator_merge_fn(q, req, bio); return e->type->ops.elevator_merge_fn(q, req, bio);
return ELEVATOR_NO_MERGE; return ELEVATOR_NO_MERGE;
} }
...@@ -544,8 +542,8 @@ void elv_merged_request(struct request_queue *q, struct request *rq, int type) ...@@ -544,8 +542,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->ops->elevator_merged_fn) if (e->type->ops.elevator_merged_fn)
e->ops->elevator_merged_fn(q, rq, type); e->type->ops.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);
...@@ -559,8 +557,8 @@ void elv_merge_requests(struct request_queue *q, struct request *rq, ...@@ -559,8 +557,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->cmd_flags & REQ_SORTED; const int next_sorted = next->cmd_flags & REQ_SORTED;
if (next_sorted && e->ops->elevator_merge_req_fn) if (next_sorted && e->type->ops.elevator_merge_req_fn)
e->ops->elevator_merge_req_fn(q, rq, next); e->type->ops.elevator_merge_req_fn(q, rq, next);
elv_rqhash_reposition(q, rq); elv_rqhash_reposition(q, rq);
...@@ -577,8 +575,8 @@ void elv_bio_merged(struct request_queue *q, struct request *rq, ...@@ -577,8 +575,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->ops->elevator_bio_merged_fn) if (e->type->ops.elevator_bio_merged_fn)
e->ops->elevator_bio_merged_fn(q, rq, bio); e->type->ops.elevator_bio_merged_fn(q, rq, bio);
} }
void elv_requeue_request(struct request_queue *q, struct request *rq) void elv_requeue_request(struct request_queue *q, struct request *rq)
...@@ -604,12 +602,12 @@ void elv_drain_elevator(struct request_queue *q) ...@@ -604,12 +602,12 @@ void elv_drain_elevator(struct request_queue *q)
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
while (q->elevator->ops->elevator_dispatch_fn(q, 1)) while (q->elevator->type->ops.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 "
"(nr_sorted=%u), please report this\n", "(nr_sorted=%u), please report this\n",
q->elevator->elevator_type->elevator_name, q->nr_sorted); q->elevator->type->elevator_name, q->nr_sorted);
} }
} }
...@@ -698,7 +696,7 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where) ...@@ -698,7 +696,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->ops->elevator_add_req_fn(q, rq); q->elevator->type->ops.elevator_add_req_fn(q, rq);
break; break;
case ELEVATOR_INSERT_FLUSH: case ELEVATOR_INSERT_FLUSH:
...@@ -727,8 +725,8 @@ struct request *elv_latter_request(struct request_queue *q, struct request *rq) ...@@ -727,8 +725,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->ops->elevator_latter_req_fn) if (e->type->ops.elevator_latter_req_fn)
return e->ops->elevator_latter_req_fn(q, rq); return e->type->ops.elevator_latter_req_fn(q, rq);
return NULL; return NULL;
} }
...@@ -736,8 +734,8 @@ struct request *elv_former_request(struct request_queue *q, struct request *rq) ...@@ -736,8 +734,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->ops->elevator_former_req_fn) if (e->type->ops.elevator_former_req_fn)
return e->ops->elevator_former_req_fn(q, rq); return e->type->ops.elevator_former_req_fn(q, rq);
return NULL; return NULL;
} }
...@@ -745,8 +743,8 @@ int elv_set_request(struct request_queue *q, struct request *rq, gfp_t gfp_mask) ...@@ -745,8 +743,8 @@ int elv_set_request(struct request_queue *q, struct request *rq, gfp_t gfp_mask)
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->ops->elevator_set_req_fn) if (e->type->ops.elevator_set_req_fn)
return e->ops->elevator_set_req_fn(q, rq, gfp_mask); return e->type->ops.elevator_set_req_fn(q, rq, gfp_mask);
rq->elevator_private[0] = NULL; rq->elevator_private[0] = NULL;
return 0; return 0;
...@@ -756,16 +754,16 @@ void elv_put_request(struct request_queue *q, struct request *rq) ...@@ -756,16 +754,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->ops->elevator_put_req_fn) if (e->type->ops.elevator_put_req_fn)
e->ops->elevator_put_req_fn(rq); e->type->ops.elevator_put_req_fn(rq);
} }
int elv_may_queue(struct request_queue *q, int rw) int elv_may_queue(struct request_queue *q, int rw)
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->ops->elevator_may_queue_fn) if (e->type->ops.elevator_may_queue_fn)
return e->ops->elevator_may_queue_fn(q, rw); return e->type->ops.elevator_may_queue_fn(q, rw);
return ELV_MQUEUE_MAY; return ELV_MQUEUE_MAY;
} }
...@@ -800,8 +798,8 @@ void elv_completed_request(struct request_queue *q, struct request *rq) ...@@ -800,8 +798,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->cmd_flags & REQ_SORTED) && if ((rq->cmd_flags & REQ_SORTED) &&
e->ops->elevator_completed_req_fn) e->type->ops.elevator_completed_req_fn)
e->ops->elevator_completed_req_fn(q, rq); e->type->ops.elevator_completed_req_fn(q, rq);
} }
} }
...@@ -819,7 +817,7 @@ elv_attr_show(struct kobject *kobj, struct attribute *attr, char *page) ...@@ -819,7 +817,7 @@ elv_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
e = container_of(kobj, struct elevator_queue, kobj); e = container_of(kobj, struct elevator_queue, kobj);
mutex_lock(&e->sysfs_lock); mutex_lock(&e->sysfs_lock);
error = e->ops ? entry->show(e, page) : -ENOENT; error = e->type ? entry->show(e, page) : -ENOENT;
mutex_unlock(&e->sysfs_lock); mutex_unlock(&e->sysfs_lock);
return error; return error;
} }
...@@ -837,7 +835,7 @@ elv_attr_store(struct kobject *kobj, struct attribute *attr, ...@@ -837,7 +835,7 @@ elv_attr_store(struct kobject *kobj, struct attribute *attr,
e = container_of(kobj, struct elevator_queue, kobj); e = container_of(kobj, struct elevator_queue, kobj);
mutex_lock(&e->sysfs_lock); mutex_lock(&e->sysfs_lock);
error = e->ops ? entry->store(e, page, length) : -ENOENT; error = e->type ? entry->store(e, page, length) : -ENOENT;
mutex_unlock(&e->sysfs_lock); mutex_unlock(&e->sysfs_lock);
return error; return error;
} }
...@@ -858,7 +856,7 @@ int __elv_register_queue(struct request_queue *q, struct elevator_queue *e) ...@@ -858,7 +856,7 @@ int __elv_register_queue(struct request_queue *q, struct elevator_queue *e)
error = kobject_add(&e->kobj, &q->kobj, "%s", "iosched"); error = kobject_add(&e->kobj, &q->kobj, "%s", "iosched");
if (!error) { if (!error) {
struct elv_fs_entry *attr = e->elevator_type->elevator_attrs; struct elv_fs_entry *attr = e->type->elevator_attrs;
if (attr) { if (attr) {
while (attr->attr.name) { while (attr->attr.name) {
if (sysfs_create_file(&e->kobj, &attr->attr)) if (sysfs_create_file(&e->kobj, &attr->attr))
...@@ -959,7 +957,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e) ...@@ -959,7 +957,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
elevator_exit(old_elevator); elevator_exit(old_elevator);
elv_quiesce_end(q); elv_quiesce_end(q);
blk_add_trace_msg(q, "elv switch: %s", e->elevator_type->elevator_name); blk_add_trace_msg(q, "elv switch: %s", e->type->elevator_name);
return 0; return 0;
...@@ -993,7 +991,7 @@ int elevator_change(struct request_queue *q, const char *name) ...@@ -993,7 +991,7 @@ int elevator_change(struct request_queue *q, const char *name)
return -EINVAL; return -EINVAL;
} }
if (!strcmp(elevator_name, q->elevator->elevator_type->elevator_name)) { if (!strcmp(elevator_name, q->elevator->type->elevator_name)) {
elevator_put(e); elevator_put(e);
return 0; return 0;
} }
...@@ -1028,7 +1026,7 @@ ssize_t elv_iosched_show(struct request_queue *q, char *name) ...@@ -1028,7 +1026,7 @@ ssize_t elv_iosched_show(struct request_queue *q, char *name)
if (!q->elevator || !blk_queue_stackable(q)) if (!q->elevator || !blk_queue_stackable(q))
return sprintf(name, "none\n"); return sprintf(name, "none\n");
elv = e->elevator_type; elv = e->type;
spin_lock(&elv_list_lock); spin_lock(&elv_list_lock);
list_for_each_entry(__e, &elv_list, list) { list_for_each_entry(__e, &elv_list, list) {
......
...@@ -78,11 +78,11 @@ struct elv_fs_entry { ...@@ -78,11 +78,11 @@ struct elv_fs_entry {
*/ */
struct elevator_type struct elevator_type
{ {
struct list_head list;
struct elevator_ops ops; struct elevator_ops ops;
struct elv_fs_entry *elevator_attrs; struct elv_fs_entry *elevator_attrs;
char elevator_name[ELV_NAME_MAX]; char elevator_name[ELV_NAME_MAX];
struct module *elevator_owner; struct module *elevator_owner;
struct list_head list;
}; };
/* /*
...@@ -90,10 +90,9 @@ struct elevator_type ...@@ -90,10 +90,9 @@ struct elevator_type
*/ */
struct elevator_queue struct elevator_queue
{ {
struct elevator_ops *ops; struct elevator_type *type;
void *elevator_data; void *elevator_data;
struct kobject kobj; struct kobject kobj;
struct elevator_type *elevator_type;
struct mutex sysfs_lock; struct mutex sysfs_lock;
struct hlist_head *hash; struct hlist_head *hash;
unsigned int registered:1; unsigned int registered:1;
......
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