blkio: Determine async workload length based on total number of queues
[safe/jmp/linux-2.6] / block / blk-merge.c
index e199967..99cb5cf 100644 (file)
@@ -311,6 +311,36 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
        return 1;
 }
 
+/**
+ * blk_rq_set_mixed_merge - mark a request as mixed merge
+ * @rq: request to mark as mixed merge
+ *
+ * Description:
+ *     @rq is about to be mixed merged.  Make sure the attributes
+ *     which can be mixed are set in each bio and mark @rq as mixed
+ *     merged.
+ */
+void blk_rq_set_mixed_merge(struct request *rq)
+{
+       unsigned int ff = rq->cmd_flags & REQ_FAILFAST_MASK;
+       struct bio *bio;
+
+       if (rq->cmd_flags & REQ_MIXED_MERGE)
+               return;
+
+       /*
+        * @rq will no longer represent mixable attributes for all the
+        * contained bios.  It will just track those of the first one.
+        * Distributes the attributs to each bio.
+        */
+       for (bio = rq->bio; bio; bio = bio->bi_next) {
+               WARN_ON_ONCE((bio->bi_rw & REQ_FAILFAST_MASK) &&
+                            (bio->bi_rw & REQ_FAILFAST_MASK) != ff);
+               bio->bi_rw |= ff;
+       }
+       rq->cmd_flags |= REQ_MIXED_MERGE;
+}
+
 static void blk_account_io_merge(struct request *req)
 {
        if (blk_do_io_stat(req)) {
@@ -321,7 +351,7 @@ static void blk_account_io_merge(struct request *req)
                part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req));
 
                part_round_stats(cpu, part);
-               part_dec_in_flight(part);
+               part_dec_in_flight(part, rq_data_dir(req));
 
                part_stat_unlock();
        }
@@ -350,12 +380,6 @@ static int attempt_merge(struct request_queue *q, struct request *req,
        if (blk_integrity_rq(req) != blk_integrity_rq(next))
                return 0;
 
-       /* don't merge requests of different failfast settings */
-       if (blk_failfast_dev(req)       != blk_failfast_dev(next)       ||
-           blk_failfast_transport(req) != blk_failfast_transport(next) ||
-           blk_failfast_driver(req)    != blk_failfast_driver(next))
-               return 0;
-
        /*
         * If we are allowed to merge, then append bio list
         * from next to rq and release next. merge_requests_fn
@@ -366,6 +390,19 @@ static int attempt_merge(struct request_queue *q, struct request *req,
                return 0;
 
        /*
+        * If failfast settings disagree or any of the two is already
+        * a mixed merge, mark both as mixed before proceeding.  This
+        * makes sure that all involved bios have mixable attributes
+        * set properly.
+        */
+       if ((req->cmd_flags | next->cmd_flags) & REQ_MIXED_MERGE ||
+           (req->cmd_flags & REQ_FAILFAST_MASK) !=
+           (next->cmd_flags & REQ_FAILFAST_MASK)) {
+               blk_rq_set_mixed_merge(req);
+               blk_rq_set_mixed_merge(next);
+       }
+
+       /*
         * At this point we have either done a back merge
         * or front merge. We need the smaller start_time of
         * the merged requests to be the current request