block: move existing elevator ops to union
authorJens Axboe <axboe@fb.com>
Sat, 10 Dec 2016 22:13:59 +0000 (15:13 -0700)
committerJens Axboe <axboe@fb.com>
Tue, 17 Jan 2017 17:03:33 +0000 (10:03 -0700)
Prep patch for adding MQ ops as well, since doing anon unions with
named initializers doesn't work on older compilers.

Signed-off-by: Jens Axboe <axboe@fb.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com>
Reviewed-by: Omar Sandoval <osandov@fb.com>
block/blk-ioc.c
block/blk-merge.c
block/blk.h
block/cfq-iosched.c
block/deadline-iosched.c
block/elevator.c
block/noop-iosched.c
include/linux/elevator.h

index 381cb50a673c33ed86f6f5d597331137f2881ce3..ab372092a57d4e6714b8beb8bfaa8d95f49a0b04 100644 (file)
@@ -43,8 +43,8 @@ static void ioc_exit_icq(struct io_cq *icq)
        if (icq->flags & ICQ_EXITED)
                return;
 
-       if (et->ops.elevator_exit_icq_fn)
-               et->ops.elevator_exit_icq_fn(icq);
+       if (et->ops.sq.elevator_exit_icq_fn)
+               et->ops.sq.elevator_exit_icq_fn(icq);
 
        icq->flags |= ICQ_EXITED;
 }
@@ -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))) {
                hlist_add_head(&icq->ioc_node, &ioc->icq_list);
                list_add(&icq->q_node, &q->icq_list);
-               if (et->ops.elevator_init_icq_fn)
-                       et->ops.elevator_init_icq_fn(icq);
+               if (et->ops.sq.elevator_init_icq_fn)
+                       et->ops.sq.elevator_init_icq_fn(icq);
        } else {
                kmem_cache_free(et->icq_cache, icq);
                icq = ioc_lookup_icq(ioc, q);
index 182398cb152490d96b7e48c4fd74f11657c8e665..480570b691dc6ffe2d2902e66b5fc7c48511a163 100644 (file)
@@ -763,8 +763,8 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq,
 {
        struct elevator_queue *e = q->elevator;
 
-       if (e->type->ops.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)
+               if (!e->type->ops.sq.elevator_allow_rq_merge_fn(q, rq, next))
                        return 0;
 
        return attempt_merge(q, rq, next);
index 041185e5f12994dc146528db2627707e42a700ee..f46c0ac8ae3d8e40b6f5d912dac97dc5676aaa48 100644 (file)
@@ -167,7 +167,7 @@ static inline struct request *__elv_next_request(struct request_queue *q)
                        return NULL;
                }
                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;
        }
 }
@@ -176,16 +176,16 @@ static inline void elv_activate_rq(struct request_queue *q, struct request *rq)
 {
        struct elevator_queue *e = q->elevator;
 
-       if (e->type->ops.elevator_activate_req_fn)
-               e->type->ops.elevator_activate_req_fn(q, rq);
+       if (e->type->ops.sq.elevator_activate_req_fn)
+               e->type->ops.sq.elevator_activate_req_fn(q, rq);
 }
 
 static inline void elv_deactivate_rq(struct request_queue *q, struct request *rq)
 {
        struct elevator_queue *e = q->elevator;
 
-       if (e->type->ops.elevator_deactivate_req_fn)
-               e->type->ops.elevator_deactivate_req_fn(q, rq);
+       if (e->type->ops.sq.elevator_deactivate_req_fn)
+               e->type->ops.sq.elevator_deactivate_req_fn(q, rq);
 }
 
 #ifdef CONFIG_FAIL_IO_TIMEOUT
index c73a6fcaeb9d52c7e2aa1ebbcf725e86cdc707f4..37aeb20fa454a44bbe017cdfdce3383d0e19776e 100644 (file)
@@ -4837,7 +4837,7 @@ static struct elv_fs_entry cfq_attrs[] = {
 };
 
 static struct elevator_type iosched_cfq = {
-       .ops = {
+       .ops.sq = {
                .elevator_merge_fn =            cfq_merge,
                .elevator_merged_fn =           cfq_merged_request,
                .elevator_merge_req_fn =        cfq_merged_requests,
index 55e0bb6d7da796e3b526a16832914ca88fcb879f..05fc0ea25a98d3f93c1f667c2280e7e99d7a799a 100644 (file)
@@ -439,7 +439,7 @@ static struct elv_fs_entry deadline_attrs[] = {
 };
 
 static struct elevator_type iosched_deadline = {
-       .ops = {
+       .ops.sq = {
                .elevator_merge_fn =            deadline_merge,
                .elevator_merged_fn =           deadline_merged_request,
                .elevator_merge_req_fn =        deadline_merged_requests,
index 40f0c04e5ad3d076ee24d34f3424b9e42194d454..022a26830297f3ee94bb14ef1da65f943af2f3da 100644 (file)
@@ -58,8 +58,8 @@ static int elv_iosched_allow_bio_merge(struct request *rq, struct bio *bio)
        struct request_queue *q = rq->q;
        struct elevator_queue *e = q->elevator;
 
-       if (e->type->ops.elevator_allow_bio_merge_fn)
-               return e->type->ops.elevator_allow_bio_merge_fn(q, rq, bio);
+       if (e->type->ops.sq.elevator_allow_bio_merge_fn)
+               return e->type->ops.sq.elevator_allow_bio_merge_fn(q, rq, bio);
 
        return 1;
 }
@@ -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)
                elevator_put(e);
        return err;
@@ -234,8 +234,8 @@ EXPORT_SYMBOL(elevator_init);
 void elevator_exit(struct elevator_queue *e)
 {
        mutex_lock(&e->sysfs_lock);
-       if (e->type->ops.elevator_exit_fn)
-               e->type->ops.elevator_exit_fn(e);
+       if (e->type->ops.sq.elevator_exit_fn)
+               e->type->ops.sq.elevator_exit_fn(e);
        mutex_unlock(&e->sysfs_lock);
 
        kobject_put(&e->kobj);
@@ -443,8 +443,8 @@ int elv_merge(struct request_queue *q, struct request **req, struct bio *bio)
                return ELEVATOR_BACK_MERGE;
        }
 
-       if (e->type->ops.elevator_merge_fn)
-               return e->type->ops.elevator_merge_fn(q, req, bio);
+       if (e->type->ops.sq.elevator_merge_fn)
+               return e->type->ops.sq.elevator_merge_fn(q, req, bio);
 
        return ELEVATOR_NO_MERGE;
 }
@@ -495,8 +495,8 @@ void elv_merged_request(struct request_queue *q, struct request *rq, int type)
 {
        struct elevator_queue *e = q->elevator;
 
-       if (e->type->ops.elevator_merged_fn)
-               e->type->ops.elevator_merged_fn(q, rq, type);
+       if (e->type->ops.sq.elevator_merged_fn)
+               e->type->ops.sq.elevator_merged_fn(q, rq, type);
 
        if (type == ELEVATOR_BACK_MERGE)
                elv_rqhash_reposition(q, rq);
@@ -510,8 +510,8 @@ void elv_merge_requests(struct request_queue *q, struct request *rq,
        struct elevator_queue *e = q->elevator;
        const int next_sorted = next->rq_flags & RQF_SORTED;
 
-       if (next_sorted && e->type->ops.elevator_merge_req_fn)
-               e->type->ops.elevator_merge_req_fn(q, rq, next);
+       if (next_sorted && e->type->ops.sq.elevator_merge_req_fn)
+               e->type->ops.sq.elevator_merge_req_fn(q, rq, next);
 
        elv_rqhash_reposition(q, rq);
 
@@ -528,8 +528,8 @@ void elv_bio_merged(struct request_queue *q, struct request *rq,
 {
        struct elevator_queue *e = q->elevator;
 
-       if (e->type->ops.elevator_bio_merged_fn)
-               e->type->ops.elevator_bio_merged_fn(q, rq, bio);
+       if (e->type->ops.sq.elevator_bio_merged_fn)
+               e->type->ops.sq.elevator_bio_merged_fn(q, rq, bio);
 }
 
 #ifdef CONFIG_PM
@@ -578,7 +578,7 @@ void elv_drain_elevator(struct request_queue *q)
 
        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) {
                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)
                 * rq cannot be accessed after calling
                 * 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;
 
        case ELEVATOR_INSERT_FLUSH:
@@ -682,8 +682,8 @@ struct request *elv_latter_request(struct request_queue *q, struct request *rq)
 {
        struct elevator_queue *e = q->elevator;
 
-       if (e->type->ops.elevator_latter_req_fn)
-               return e->type->ops.elevator_latter_req_fn(q, rq);
+       if (e->type->ops.sq.elevator_latter_req_fn)
+               return e->type->ops.sq.elevator_latter_req_fn(q, rq);
        return NULL;
 }
 
@@ -691,8 +691,8 @@ struct request *elv_former_request(struct request_queue *q, struct request *rq)
 {
        struct elevator_queue *e = q->elevator;
 
-       if (e->type->ops.elevator_former_req_fn)
-               return e->type->ops.elevator_former_req_fn(q, rq);
+       if (e->type->ops.sq.elevator_former_req_fn)
+               return e->type->ops.sq.elevator_former_req_fn(q, rq);
        return NULL;
 }
 
@@ -701,8 +701,8 @@ int elv_set_request(struct request_queue *q, struct request *rq,
 {
        struct elevator_queue *e = q->elevator;
 
-       if (e->type->ops.elevator_set_req_fn)
-               return e->type->ops.elevator_set_req_fn(q, rq, bio, gfp_mask);
+       if (e->type->ops.sq.elevator_set_req_fn)
+               return e->type->ops.sq.elevator_set_req_fn(q, rq, bio, gfp_mask);
        return 0;
 }
 
@@ -710,16 +710,16 @@ void elv_put_request(struct request_queue *q, struct request *rq)
 {
        struct elevator_queue *e = q->elevator;
 
-       if (e->type->ops.elevator_put_req_fn)
-               e->type->ops.elevator_put_req_fn(rq);
+       if (e->type->ops.sq.elevator_put_req_fn)
+               e->type->ops.sq.elevator_put_req_fn(rq);
 }
 
 int elv_may_queue(struct request_queue *q, unsigned int op)
 {
        struct elevator_queue *e = q->elevator;
 
-       if (e->type->ops.elevator_may_queue_fn)
-               return e->type->ops.elevator_may_queue_fn(q, op);
+       if (e->type->ops.sq.elevator_may_queue_fn)
+               return e->type->ops.sq.elevator_may_queue_fn(q, op);
 
        return ELV_MQUEUE_MAY;
 }
@@ -734,8 +734,8 @@ void elv_completed_request(struct request_queue *q, struct request *rq)
        if (blk_account_rq(rq)) {
                q->in_flight[rq_is_sync(rq)]--;
                if ((rq->rq_flags & RQF_SORTED) &&
-                   e->type->ops.elevator_completed_req_fn)
-                       e->type->ops.elevator_completed_req_fn(q, rq);
+                   e->type->ops.sq.elevator_completed_req_fn)
+                       e->type->ops.sq.elevator_completed_req_fn(q, rq);
        }
 }
 
@@ -803,8 +803,8 @@ int elv_register_queue(struct request_queue *q)
                }
                kobject_uevent(&e->kobj, KOBJ_ADD);
                e->registered = 1;
-               if (e->type->ops.elevator_registered_fn)
-                       e->type->ops.elevator_registered_fn(q);
+               if (e->type->ops.sq.elevator_registered_fn)
+                       e->type->ops.sq.elevator_registered_fn(q);
        }
        return error;
 }
@@ -912,7 +912,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
        spin_unlock_irq(q->queue_lock);
 
        /* 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)
                goto fail_init;
 
index a163c487cf38c8250ccbf0ec7beac913672796f0..2d1b15d89b4580e855eba7a7afe0b24650e029db 100644 (file)
@@ -92,7 +92,7 @@ static void noop_exit_queue(struct elevator_queue *e)
 }
 
 static struct elevator_type elevator_noop = {
-       .ops = {
+       .ops.sq = {
                .elevator_merge_req_fn          = noop_merged_requests,
                .elevator_dispatch_fn           = noop_dispatch,
                .elevator_add_req_fn            = noop_add_request,
index b276e9ef0e0b4d482312217a31d9c4a4f2416f84..2a9e966eed03daac81cf2d8a850d15ea4e5eacc1 100644 (file)
@@ -94,7 +94,9 @@ struct elevator_type
        struct kmem_cache *icq_cache;
 
        /* 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_align;       /* ditto */
        struct elv_fs_entry *elevator_attrs;