UBUNTU: Ubuntu-2.6.38-12.51
[linux-flexiantxendom0-natty.git] / block / blk-flush.c
index cb4c844..b27d020 100644 (file)
@@ -66,10 +66,12 @@ static void blk_flush_complete_seq_end_io(struct request_queue *q,
 
        /*
         * Moving a request silently to empty queue_head may stall the
-        * queue.  Kick the queue in those cases.
+        * queue.  Kick the queue in those cases.  This function is called
+        * from request completion path and calling directly into
+        * request_fn may confuse the driver.  Always use kblockd.
         */
        if (was_empty && next_rq)
-               __blk_run_queue(q);
+               __blk_run_queue(q, true);
 }
 
 static void pre_flush_end_io(struct request *rq, int error)
@@ -111,6 +113,13 @@ static struct request *queue_next_fseq(struct request_queue *q)
                break;
        case QUEUE_FSEQ_DATA:
                init_request_from_bio(rq, orig_rq->bio);
+               /*
+                * orig_rq->rq_disk may be different from
+                * bio->bi_bdev->bd_disk if orig_rq got here through
+                * remapping drivers.  Make sure rq->rq_disk points
+                * to the same one as orig_rq.
+                */
+               rq->rq_disk = orig_rq->rq_disk;
                rq->cmd_flags &= ~(REQ_FLUSH | REQ_FUA);
                rq->cmd_flags |= orig_rq->cmd_flags & (REQ_FLUSH | REQ_FUA);
                rq->end_io = flush_data_end_io;
@@ -123,7 +132,7 @@ static struct request *queue_next_fseq(struct request_queue *q)
                BUG();
        }
 
-       elv_insert(q, rq, ELEVATOR_INSERT_FRONT);
+       elv_insert(q, rq, ELEVATOR_INSERT_REQUEUE);
        return rq;
 }
 
@@ -184,13 +193,10 @@ struct request *blk_do_flush(struct request_queue *q, struct request *rq)
        return blk_flush_complete_seq(q, skip, 0);
 }
 
-static void bio_end_empty_barrier(struct bio *bio, int err)
+static void bio_end_flush(struct bio *bio, int err)
 {
-       if (err) {
-               if (err == -EOPNOTSUPP)
-                       set_bit(BIO_EOPNOTSUPP, &bio->bi_flags);
+       if (err)
                clear_bit(BIO_UPTODATE, &bio->bi_flags);
-       }
        if (bio->bi_private)
                complete(bio->bi_private);
        bio_put(bio);
@@ -201,7 +207,6 @@ static void bio_end_empty_barrier(struct bio *bio, int err)
  * @bdev:      blockdev to issue flush for
  * @gfp_mask:  memory allocation flags (for bio_alloc)
  * @error_sector:      error sector
- * @flags:     BLKDEV_IFL_* flags to control behaviour
  *
  * Description:
  *    Issue a flush for the block device in question. Caller can supply
@@ -210,7 +215,7 @@ static void bio_end_empty_barrier(struct bio *bio, int err)
  *    request was pushed in some internal queue for later handling.
  */
 int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
-               sector_t *error_sector, unsigned long flags)
+               sector_t *error_sector)
 {
        DECLARE_COMPLETION_ONSTACK(wait);
        struct request_queue *q;
@@ -228,33 +233,29 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
         * some block devices may not have their queue correctly set up here
         * (e.g. loop device without a backing file) and so issuing a flush
         * here will panic. Ensure there is a request function before issuing
-        * the barrier.
+        * the flush.
         */
        if (!q->make_request_fn)
                return -ENXIO;
 
        bio = bio_alloc(gfp_mask, 0);
-       bio->bi_end_io = bio_end_empty_barrier;
+       bio->bi_end_io = bio_end_flush;
        bio->bi_bdev = bdev;
-       if (test_bit(BLKDEV_WAIT, &flags))
-               bio->bi_private = &wait;
+       bio->bi_private = &wait;
 
        bio_get(bio);
-       submit_bio(WRITE_BARRIER, bio);
-       if (test_bit(BLKDEV_WAIT, &flags)) {
-               wait_for_completion(&wait);
-               /*
-                * The driver must store the error location in ->bi_sector, if
-                * it supports it. For non-stacked drivers, this should be
-                * copied from blk_rq_pos(rq).
-                */
-               if (error_sector)
-                       *error_sector = bio->bi_sector;
-       }
+       submit_bio(WRITE_FLUSH, bio);
+       wait_for_completion(&wait);
+
+       /*
+        * The driver must store the error location in ->bi_sector, if
+        * it supports it. For non-stacked drivers, this should be
+        * copied from blk_rq_pos(rq).
+        */
+       if (error_sector)
+               *error_sector = bio->bi_sector;
 
-       if (bio_flagged(bio, BIO_EOPNOTSUPP))
-               ret = -EOPNOTSUPP;
-       else if (!bio_flagged(bio, BIO_UPTODATE))
+       if (!bio_flagged(bio, BIO_UPTODATE))
                ret = -EIO;
 
        bio_put(bio);