tunnels: fix netns vs proto registration ordering
[safe/jmp/linux-2.6] / block / elevator.c
index ca6788a..9ad5ccc 100644 (file)
 #include <linux/compiler.h>
 #include <linux/delay.h>
 #include <linux/blktrace_api.h>
-#include <trace/block.h>
 #include <linux/hash.h>
 #include <linux/uaccess.h>
 
+#include <trace/events/block.h>
+
 #include "blk.h"
 
 static DEFINE_SPINLOCK(elv_list_lock);
 static LIST_HEAD(elv_list);
 
-DEFINE_TRACE(block_rq_abort);
-
 /*
  * Merge hash stuff.
  */
@@ -52,11 +51,7 @@ static const int elv_hash_shift = 6;
 #define ELV_HASH_FN(sec)       \
                (hash_long(ELV_HASH_BLOCK((sec)), elv_hash_shift))
 #define ELV_HASH_ENTRIES       (1 << elv_hash_shift)
-#define rq_hash_key(rq)                ((rq)->sector + (rq)->nr_sectors)
-#define ELV_ON_HASH(rq)                (!hlist_unhashed(&(rq)->hash))
-
-DEFINE_TRACE(block_rq_insert);
-DEFINE_TRACE(block_rq_issue);
+#define rq_hash_key(rq)                (blk_rq_pos(rq) + blk_rq_sectors(rq))
 
 /*
  * Query io scheduler to see if the current process issuing bio may be
@@ -84,7 +79,8 @@ int elv_rq_merge_ok(struct request *rq, struct bio *bio)
        /*
         * Don't merge file system requests and discard requests
         */
-       if (bio_discard(bio) != bio_discard(rq->bio))
+       if (bio_rw_flagged(bio, BIO_RW_DISCARD) !=
+           bio_rw_flagged(rq->bio, BIO_RW_DISCARD))
                return 0;
 
        /*
@@ -120,9 +116,9 @@ static inline int elv_try_merge(struct request *__rq, struct bio *bio)
         * we can merge and sequence is ok, check if it's possible
         */
        if (elv_rq_merge_ok(__rq, bio)) {
-               if (__rq->sector + __rq->nr_sectors == bio->bi_sector)
+               if (blk_rq_pos(__rq) + blk_rq_sectors(__rq) == bio->bi_sector)
                        ret = ELEVATOR_BACK_MERGE;
-               else if (__rq->sector - bio_sectors(bio) == bio->bi_sector)
+               else if (blk_rq_pos(__rq) - bio_sectors(bio) == bio->bi_sector)
                        ret = ELEVATOR_FRONT_MERGE;
        }
 
@@ -158,10 +154,7 @@ static struct elevator_type *elevator_get(const char *name)
 
                spin_unlock(&elv_list_lock);
 
-               if (!strcmp(name, "anticipatory"))
-                       sprintf(elv, "as-iosched");
-               else
-                       sprintf(elv, "%s-iosched", name);
+               sprintf(elv, "%s-iosched", name);
 
                request_module("%s", elv);
                spin_lock(&elv_list_lock);
@@ -197,10 +190,7 @@ static int __init elevator_setup(char *str)
         * Be backwards-compatible with previous kernels, so users
         * won't get the wrong elevator.
         */
-       if (!strcmp(str, "as"))
-               strcpy(chosen_elevator, "anticipatory");
-       else
-               strncpy(chosen_elevator, str, sizeof(chosen_elevator) - 1);
+       strncpy(chosen_elevator, str, sizeof(chosen_elevator) - 1);
        return 1;
 }
 
@@ -310,22 +300,6 @@ void elevator_exit(struct elevator_queue *e)
 }
 EXPORT_SYMBOL(elevator_exit);
 
-static void elv_activate_rq(struct request_queue *q, struct request *rq)
-{
-       struct elevator_queue *e = q->elevator;
-
-       if (e->ops->elevator_activate_req_fn)
-               e->ops->elevator_activate_req_fn(q, rq);
-}
-
-static void elv_deactivate_rq(struct request_queue *q, struct request *rq)
-{
-       struct elevator_queue *e = q->elevator;
-
-       if (e->ops->elevator_deactivate_req_fn)
-               e->ops->elevator_deactivate_req_fn(q, rq);
-}
-
 static inline void __elv_rqhash_del(struct request *rq)
 {
        hlist_del_init(&rq->hash);
@@ -387,9 +361,9 @@ struct request *elv_rb_add(struct rb_root *root, struct request *rq)
                parent = *p;
                __rq = rb_entry(parent, struct request, rb_node);
 
-               if (rq->sector < __rq->sector)
+               if (blk_rq_pos(rq) < blk_rq_pos(__rq))
                        p = &(*p)->rb_left;
-               else if (rq->sector > __rq->sector)
+               else if (blk_rq_pos(rq) > blk_rq_pos(__rq))
                        p = &(*p)->rb_right;
                else
                        return __rq;
@@ -417,9 +391,9 @@ struct request *elv_rb_find(struct rb_root *root, sector_t sector)
        while (n) {
                rq = rb_entry(n, struct request, rb_node);
 
-               if (sector < rq->sector)
+               if (sector < blk_rq_pos(rq))
                        n = n->rb_left;
-               else if (sector > rq->sector)
+               else if (sector > blk_rq_pos(rq))
                        n = n->rb_right;
                else
                        return rq;
@@ -458,14 +432,14 @@ void elv_dispatch_sort(struct request_queue *q, struct request *rq)
                        break;
                if (pos->cmd_flags & stop_flags)
                        break;
-               if (rq->sector >= boundary) {
-                       if (pos->sector < boundary)
+               if (blk_rq_pos(rq) >= boundary) {
+                       if (blk_rq_pos(pos) < boundary)
                                continue;
                } else {
-                       if (pos->sector >= boundary)
+                       if (blk_rq_pos(pos) >= boundary)
                                break;
                }
-               if (rq->sector >= pos->sector)
+               if (blk_rq_pos(rq) >= blk_rq_pos(pos))
                        break;
        }
 
@@ -563,7 +537,7 @@ void elv_requeue_request(struct request_queue *q, struct request *rq)
         * in_flight count again
         */
        if (blk_account_rq(rq)) {
-               q->in_flight--;
+               q->in_flight[rq_is_sync(rq)]--;
                if (blk_sorted_rq(rq))
                        elv_deactivate_rq(q, rq);
        }
@@ -573,7 +547,7 @@ void elv_requeue_request(struct request_queue *q, struct request *rq)
        elv_insert(q, rq, ELEVATOR_INSERT_REQUEUE);
 }
 
-static void elv_drain_elevator(struct request_queue *q)
+void elv_drain_elevator(struct request_queue *q)
 {
        static int printed;
        while (q->elevator->ops->elevator_dispatch_fn(q, 1))
@@ -587,6 +561,34 @@ static void elv_drain_elevator(struct request_queue *q)
        }
 }
 
+/*
+ * Call with queue lock held, interrupts disabled
+ */
+void elv_quiesce_start(struct request_queue *q)
+{
+       if (!q->elevator)
+               return;
+
+       queue_flag_set(QUEUE_FLAG_ELVSWITCH, q);
+
+       /*
+        * make sure we don't have any requests in flight
+        */
+       elv_drain_elevator(q);
+       while (q->rq.elvpriv) {
+               __blk_run_queue(q);
+               spin_unlock_irq(q->queue_lock);
+               msleep(10);
+               spin_lock_irq(q->queue_lock);
+               elv_drain_elevator(q);
+       }
+}
+
+void elv_quiesce_end(struct request_queue *q)
+{
+       queue_flag_clear(QUEUE_FLAG_ELVSWITCH, q);
+}
+
 void elv_insert(struct request_queue *q, struct request *rq, int where)
 {
        struct list_head *pos;
@@ -618,8 +620,7 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
                 *   with anything.  There's no point in delaying queue
                 *   processing.
                 */
-               blk_remove_plug(q);
-               blk_start_queueing(q);
+               __blk_run_queue(q);
                break;
 
        case ELEVATOR_INSERT_SORT:
@@ -678,7 +679,7 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
 
        if (unplug_it && blk_queue_plugged(q)) {
                int nrq = q->rq.count[BLK_RW_SYNC] + q->rq.count[BLK_RW_ASYNC]
-                       - q->in_flight;
+                               - queue_in_flight(q);
 
                if (nrq >= q->unplug_thresh)
                        __generic_unplug_device(q);
@@ -734,117 +735,6 @@ void elv_add_request(struct request_queue *q, struct request *rq, int where,
 }
 EXPORT_SYMBOL(elv_add_request);
 
-static inline struct request *__elv_next_request(struct request_queue *q)
-{
-       struct request *rq;
-
-       while (1) {
-               while (!list_empty(&q->queue_head)) {
-                       rq = list_entry_rq(q->queue_head.next);
-                       if (blk_do_ordered(q, &rq))
-                               return rq;
-               }
-
-               if (!q->elevator->ops->elevator_dispatch_fn(q, 0))
-                       return NULL;
-       }
-}
-
-struct request *elv_next_request(struct request_queue *q)
-{
-       struct request *rq;
-       int ret;
-
-       while ((rq = __elv_next_request(q)) != NULL) {
-               if (!(rq->cmd_flags & REQ_STARTED)) {
-                       /*
-                        * This is the first time the device driver
-                        * sees this request (possibly after
-                        * requeueing).  Notify IO scheduler.
-                        */
-                       if (blk_sorted_rq(rq))
-                               elv_activate_rq(q, rq);
-
-                       /*
-                        * just mark as started even if we don't start
-                        * it, a request that has been delayed should
-                        * not be passed by new incoming requests
-                        */
-                       rq->cmd_flags |= REQ_STARTED;
-                       trace_block_rq_issue(q, rq);
-               }
-
-               if (!q->boundary_rq || q->boundary_rq == rq) {
-                       q->end_sector = rq_end_sector(rq);
-                       q->boundary_rq = NULL;
-               }
-
-               if (rq->cmd_flags & REQ_DONTPREP)
-                       break;
-
-               if (q->dma_drain_size && rq->data_len) {
-                       /*
-                        * make sure space for the drain appears we
-                        * know we can do this because max_hw_segments
-                        * has been adjusted to be one fewer than the
-                        * device can handle
-                        */
-                       rq->nr_phys_segments++;
-               }
-
-               if (!q->prep_rq_fn)
-                       break;
-
-               ret = q->prep_rq_fn(q, rq);
-               if (ret == BLKPREP_OK) {
-                       break;
-               } else if (ret == BLKPREP_DEFER) {
-                       /*
-                        * the request may have been (partially) prepped.
-                        * we need to keep this request in the front to
-                        * avoid resource deadlock.  REQ_STARTED will
-                        * prevent other fs requests from passing this one.
-                        */
-                       if (q->dma_drain_size && rq->data_len &&
-                           !(rq->cmd_flags & REQ_DONTPREP)) {
-                               /*
-                                * remove the space for the drain we added
-                                * so that we don't add it again
-                                */
-                               --rq->nr_phys_segments;
-                       }
-
-                       rq = NULL;
-                       break;
-               } else if (ret == BLKPREP_KILL) {
-                       rq->cmd_flags |= REQ_QUIET;
-                       __blk_end_request(rq, -EIO, blk_rq_bytes(rq));
-               } else {
-                       printk(KERN_ERR "%s: bad return=%d\n", __func__, ret);
-                       break;
-               }
-       }
-
-       return rq;
-}
-EXPORT_SYMBOL(elv_next_request);
-
-void elv_dequeue_request(struct request_queue *q, struct request *rq)
-{
-       BUG_ON(list_empty(&rq->queuelist));
-       BUG_ON(ELV_ON_HASH(rq));
-
-       list_del_init(&rq->queuelist);
-
-       /*
-        * the time frame between a request being removed from the lists
-        * and to it is freed is accounted as io that is in progress at
-        * the driver side.
-        */
-       if (blk_account_rq(rq))
-               q->in_flight++;
-}
-
 int elv_queue_empty(struct request_queue *q)
 {
        struct elevator_queue *e = q->elevator;
@@ -914,7 +804,12 @@ void elv_abort_queue(struct request_queue *q)
                rq = list_entry_rq(q->queue_head.next);
                rq->cmd_flags |= REQ_QUIET;
                trace_block_rq_abort(q, rq);
-               __blk_end_request(rq, -EIO, blk_rq_bytes(rq));
+               /*
+                * Mark this request as started so we don't trigger
+                * any debug logic in the end I/O path.
+                */
+               blk_start_request(rq);
+               __blk_end_request_all(rq, -EIO);
        }
 }
 EXPORT_SYMBOL(elv_abort_queue);
@@ -927,7 +822,7 @@ void elv_completed_request(struct request_queue *q, struct request *rq)
         * request is released from the driver, io must be done
         */
        if (blk_account_rq(rq)) {
-               q->in_flight--;
+               q->in_flight[rq_is_sync(rq)]--;
                if (blk_sorted_rq(rq) && e->ops->elevator_completed_req_fn)
                        e->ops->elevator_completed_req_fn(q, rq);
        }
@@ -942,11 +837,11 @@ void elv_completed_request(struct request_queue *q, struct request *rq)
                if (!list_empty(&q->queue_head))
                        next = list_entry_rq(q->queue_head.next);
 
-               if (!q->in_flight &&
+               if (!queue_in_flight(q) &&
                    blk_ordered_cur_seq(q) == QUEUE_ORDSEQ_DRAIN &&
                    (!next || blk_ordered_req_seq(next) > QUEUE_ORDSEQ_DRAIN)) {
                        blk_ordered_complete_seq(q, QUEUE_ORDSEQ_DRAIN, 0);
-                       blk_start_queueing(q);
+                       __blk_run_queue(q);
                }
        }
 }
@@ -1101,18 +996,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
         * Turn on BYPASS and drain all requests w/ elevator private data
         */
        spin_lock_irq(q->queue_lock);
-
-       queue_flag_set(QUEUE_FLAG_ELVSWITCH, q);
-
-       elv_drain_elevator(q);
-
-       while (q->rq.elvpriv) {
-               blk_start_queueing(q);
-               spin_unlock_irq(q->queue_lock);
-               msleep(10);
-               spin_lock_irq(q->queue_lock);
-               elv_drain_elevator(q);
-       }
+       elv_quiesce_start(q);
 
        /*
         * Remember old elevator.
@@ -1136,7 +1020,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
         */
        elevator_exit(old_elevator);
        spin_lock_irq(q->queue_lock);
-       queue_flag_clear(QUEUE_FLAG_ELVSWITCH, q);
+       elv_quiesce_end(q);
        spin_unlock_irq(q->queue_lock);
 
        blk_add_trace_msg(q, "elv switch: %s", e->elevator_type->elevator_name);
@@ -1165,10 +1049,11 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,
        char elevator_name[ELV_NAME_MAX];
        struct elevator_type *e;
 
-       strlcpy(elevator_name, name, sizeof(elevator_name));
-       strstrip(elevator_name);
+       if (!q->elevator)
+               return count;
 
-       e = elevator_get(elevator_name);
+       strlcpy(elevator_name, name, sizeof(elevator_name));
+       e = elevator_get(strstrip(elevator_name));
        if (!e) {
                printk(KERN_ERR "elevator: type %s not found\n", elevator_name);
                return -EINVAL;
@@ -1188,10 +1073,15 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,
 ssize_t elv_iosched_show(struct request_queue *q, char *name)
 {
        struct elevator_queue *e = q->elevator;
-       struct elevator_type *elv = e->elevator_type;
+       struct elevator_type *elv;
        struct elevator_type *__e;
        int len = 0;
 
+       if (!q->elevator)
+               return sprintf(name, "none\n");
+
+       elv = e->elevator_type;
+
        spin_lock(&elv_list_lock);
        list_for_each_entry(__e, &elv_list, list) {
                if (!strcmp(elv->elevator_name, __e->elevator_name))