block: make barrier completion more robust
[firefly-linux-kernel-4.4.55.git] / block / elevator.c
index a6951f76ba0c3fa3e9a0c9f8ff58a108e63dc85c..261ffaaf47bdbd125e3c91e44a4e9f7b3ed59fc0 100644 (file)
@@ -33,6 +33,7 @@
 #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>
 
@@ -41,6 +42,8 @@
 static DEFINE_SPINLOCK(elv_list_lock);
 static LIST_HEAD(elv_list);
 
+DEFINE_TRACE(block_rq_abort);
+
 /*
  * Merge hash stuff.
  */
@@ -52,6 +55,9 @@ static const int elv_hash_shift = 6;
 #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);
+
 /*
  * Query io scheduler to see if the current process issuing bio may be
  * merged with rq.
@@ -586,7 +592,7 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
        unsigned ordseq;
        int unplug_it = 1;
 
-       blk_add_trace_rq(q, rq, BLK_TA_INSERT);
+       trace_block_rq_insert(q, rq);
 
        rq->q = q;
 
@@ -772,7 +778,7 @@ struct request *elv_next_request(struct request_queue *q)
                         * not be passed by new incoming requests
                         */
                        rq->cmd_flags |= REQ_STARTED;
-                       blk_add_trace_rq(q, rq, BLK_TA_ISSUE);
+                       trace_block_rq_issue(q, rq);
                }
 
                if (!q->boundary_rq || q->boundary_rq == rq) {
@@ -914,7 +920,7 @@ void elv_abort_queue(struct request_queue *q)
        while (!list_empty(&q->queue_head)) {
                rq = list_entry_rq(q->queue_head.next);
                rq->cmd_flags |= REQ_QUIET;
-               blk_add_trace_rq(q, rq, BLK_TA_ABORT);
+               trace_block_rq_abort(q, rq);
                __blk_end_request(rq, -EIO, blk_rq_bytes(rq));
        }
 }
@@ -938,10 +944,14 @@ void elv_completed_request(struct request_queue *q, struct request *rq)
         * drained for flush sequence.
         */
        if (unlikely(q->ordseq)) {
-               struct request *first_rq = list_entry_rq(q->queue_head.next);
-               if (q->in_flight == 0 &&
+               struct request *next = NULL;
+
+               if (!list_empty(&q->queue_head))
+                       next = list_entry_rq(q->queue_head.next);
+
+               if (!q->in_flight &&
                    blk_ordered_cur_seq(q) == QUEUE_ORDSEQ_DRAIN &&
-                   blk_ordered_req_seq(first_rq) > 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);
                }