block: set the bounce_pfn to the actual DMA limit rather than to max memory
[linux-2.6.git] / block / elevator.c
index ca86192..ec585c9 100644 (file)
@@ -79,7 +79,13 @@ 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->bi_rw & REQ_DISCARD) != (rq->bio->bi_rw & REQ_DISCARD))
+               return 0;
+
+       /*
+        * Don't merge discard requests and secure discard requests
+        */
+       if ((bio->bi_rw & REQ_SECURE) != (rq->bio->bi_rw & REQ_SECURE))
                return 0;
 
        /*
@@ -153,10 +159,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);
+               snprintf(elv, sizeof(elv), "%s-iosched", name);
 
                request_module("%s", elv);
                spin_lock(&elv_list_lock);
@@ -192,10 +195,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;
 }
 
@@ -247,9 +247,11 @@ int elevator_init(struct request_queue *q, char *name)
 {
        struct elevator_type *e = NULL;
        struct elevator_queue *eq;
-       int ret = 0;
        void *data;
 
+       if (unlikely(q->elevator))
+               return 0;
+
        INIT_LIST_HEAD(&q->queue_head);
        q->last_merge = NULL;
        q->end_sector = 0;
@@ -289,7 +291,7 @@ int elevator_init(struct request_queue *q, char *name)
        }
 
        elevator_attach(q, eq, data);
-       return ret;
+       return 0;
 }
 EXPORT_SYMBOL(elevator_init);
 
@@ -431,7 +433,8 @@ void elv_dispatch_sort(struct request_queue *q, struct request *rq)
        list_for_each_prev(entry, &q->queue_head) {
                struct request *pos = list_entry_rq(entry);
 
-               if (blk_discard_rq(rq) != blk_discard_rq(pos))
+               if ((rq->cmd_flags & REQ_DISCARD) !=
+                   (pos->cmd_flags & REQ_DISCARD))
                        break;
                if (rq_data_dir(rq) != rq_data_dir(pos))
                        break;
@@ -479,6 +482,15 @@ int elv_merge(struct request_queue *q, struct request **req, struct bio *bio)
        int ret;
 
        /*
+        * Levels of merges:
+        *      nomerges:  No merges at all attempted
+        *      noxmerges: Only simple one-hit cache try
+        *      merges:    All merge tries attempted
+        */
+       if (blk_queue_nomerges(q))
+               return ELEVATOR_NO_MERGE;
+
+       /*
         * First try one-hit cache.
         */
        if (q->last_merge) {
@@ -489,7 +501,7 @@ int elv_merge(struct request_queue *q, struct request **req, struct bio *bio)
                }
        }
 
-       if (blk_queue_nomerges(q))
+       if (blk_queue_noxmerges(q))
                return ELEVATOR_NO_MERGE;
 
        /*
@@ -535,6 +547,15 @@ void elv_merge_requests(struct request_queue *q, struct request *rq,
        q->last_merge = rq;
 }
 
+void elv_bio_merged(struct request_queue *q, struct request *rq,
+                       struct bio *bio)
+{
+       struct elevator_queue *e = q->elevator;
+
+       if (e->ops->elevator_bio_merged_fn)
+               e->ops->elevator_bio_merged_fn(q, rq, bio);
+}
+
 void elv_requeue_request(struct request_queue *q, struct request *rq)
 {
        /*
@@ -543,7 +564,7 @@ void elv_requeue_request(struct request_queue *q, struct request *rq)
         */
        if (blk_account_rq(rq)) {
                q->in_flight[rq_is_sync(rq)]--;
-               if (blk_sorted_rq(rq))
+               if (rq->cmd_flags & REQ_SORTED)
                        elv_deactivate_rq(q, rq);
        }
 
@@ -629,7 +650,8 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
                break;
 
        case ELEVATOR_INSERT_SORT:
-               BUG_ON(!blk_fs_request(rq) && !blk_discard_rq(rq));
+               BUG_ON(rq->cmd_type != REQ_TYPE_FS &&
+                      !(rq->cmd_flags & REQ_DISCARD));
                rq->cmd_flags |= REQ_SORTED;
                q->nr_sorted++;
                if (rq_mergeable(rq)) {
@@ -701,7 +723,7 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where,
                /*
                 * toggle ordered color
                 */
-               if (blk_barrier_rq(rq))
+               if (rq->cmd_flags & REQ_HARDBARRIER)
                        q->ordcolor ^= 1;
 
                /*
@@ -714,7 +736,8 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where,
                 * this request is scheduling boundary, update
                 * end_sector
                 */
-               if (blk_fs_request(rq) || blk_discard_rq(rq)) {
+               if (rq->cmd_type == REQ_TYPE_FS ||
+                   (rq->cmd_flags & REQ_DISCARD)) {
                        q->end_sector = rq_end_sector(rq);
                        q->boundary_rq = rq;
                }
@@ -828,7 +851,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 (blk_sorted_rq(rq) && e->ops->elevator_completed_req_fn)
+               if ((rq->cmd_flags & REQ_SORTED) &&
+                   e->ops->elevator_completed_req_fn)
                        e->ops->elevator_completed_req_fn(q, rq);
        }
 
@@ -888,7 +912,7 @@ elv_attr_store(struct kobject *kobj, struct attribute *attr,
        return error;
 }
 
-static struct sysfs_ops elv_sysfs_ops = {
+static const struct sysfs_ops elv_sysfs_ops = {
        .show   = elv_attr_show,
        .store  = elv_attr_store,
 };
@@ -917,6 +941,7 @@ int elv_register_queue(struct request_queue *q)
        }
        return error;
 }
+EXPORT_SYMBOL(elv_register_queue);
 
 static void __elv_unregister_queue(struct elevator_queue *e)
 {
@@ -929,6 +954,7 @@ void elv_unregister_queue(struct request_queue *q)
        if (q)
                __elv_unregister_queue(q->elevator);
 }
+EXPORT_SYMBOL(elv_unregister_queue);
 
 void elv_register(struct elevator_type *e)
 {
@@ -1058,9 +1084,7 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,
                return count;
 
        strlcpy(elevator_name, name, sizeof(elevator_name));
-       strstrip(elevator_name);
-
-       e = elevator_get(elevator_name);
+       e = elevator_get(strstrip(elevator_name));
        if (!e) {
                printk(KERN_ERR "elevator: type %s not found\n", elevator_name);
                return -EINVAL;
@@ -1084,7 +1108,7 @@ ssize_t elv_iosched_show(struct request_queue *q, char *name)
        struct elevator_type *__e;
        int len = 0;
 
-       if (!q->elevator)
+       if (!q->elevator || !blk_queue_stackable(q))
                return sprintf(name, "none\n");
 
        elv = e->elevator_type;