UBUNTU: Ubuntu-2.6.38-12.51
[linux-flexiantxendom0-natty.git] / block / blk-flush.c
index 452c552..b27d020 100644 (file)
@@ -56,34 +56,47 @@ static struct request *blk_flush_complete_seq(struct request_queue *q,
        return next_rq;
 }
 
+static void blk_flush_complete_seq_end_io(struct request_queue *q,
+                                         unsigned seq, int error)
+{
+       bool was_empty = elv_queue_empty(q);
+       struct request *next_rq;
+
+       next_rq = blk_flush_complete_seq(q, seq, error);
+
+       /*
+        * Moving a request silently to empty queue_head may stall the
+        * 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, true);
+}
+
 static void pre_flush_end_io(struct request *rq, int error)
 {
        elv_completed_request(rq->q, rq);
-       blk_flush_complete_seq(rq->q, QUEUE_FSEQ_PREFLUSH, error);
+       blk_flush_complete_seq_end_io(rq->q, QUEUE_FSEQ_PREFLUSH, error);
 }
 
 static void flush_data_end_io(struct request *rq, int error)
 {
        elv_completed_request(rq->q, rq);
-       blk_flush_complete_seq(rq->q, QUEUE_FSEQ_DATA, error);
+       blk_flush_complete_seq_end_io(rq->q, QUEUE_FSEQ_DATA, error);
 }
 
 static void post_flush_end_io(struct request *rq, int error)
 {
        elv_completed_request(rq->q, rq);
-       blk_flush_complete_seq(rq->q, QUEUE_FSEQ_POSTFLUSH, error);
+       blk_flush_complete_seq_end_io(rq->q, QUEUE_FSEQ_POSTFLUSH, error);
 }
 
-static void queue_flush(struct request_queue *q, struct request *rq,
-                       rq_end_io_fn *end_io)
+static void init_flush_request(struct request *rq, struct gendisk *disk)
 {
-       blk_rq_init(q, rq);
        rq->cmd_type = REQ_TYPE_FS;
-       rq->cmd_flags = REQ_FLUSH;
-       rq->rq_disk = q->orig_flush_rq->rq_disk;
-       rq->end_io = end_io;
-
-       elv_insert(q, rq, ELEVATOR_INSERT_FRONT);
+       rq->cmd_flags = WRITE_FLUSH;
+       rq->rq_disk = disk;
 }
 
 static struct request *queue_next_fseq(struct request_queue *q)
@@ -91,29 +104,35 @@ static struct request *queue_next_fseq(struct request_queue *q)
        struct request *orig_rq = q->orig_flush_rq;
        struct request *rq = &q->flush_rq;
 
+       blk_rq_init(q, rq);
+
        switch (blk_flush_cur_seq(q)) {
        case QUEUE_FSEQ_PREFLUSH:
-               queue_flush(q, rq, pre_flush_end_io);
+               init_flush_request(rq, orig_rq->rq_disk);
+               rq->end_io = pre_flush_end_io;
                break;
-
        case QUEUE_FSEQ_DATA:
-               /* initialize proxy request, inherit FLUSH/FUA and queue it */
-               blk_rq_init(q, rq);
                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;
-
-               elv_insert(q, rq, ELEVATOR_INSERT_FRONT);
                break;
-
        case QUEUE_FSEQ_POSTFLUSH:
-               queue_flush(q, rq, post_flush_end_io);
+               init_flush_request(rq, orig_rq->rq_disk);
+               rq->end_io = post_flush_end_io;
                break;
-
        default:
                BUG();
        }
+
+       elv_insert(q, rq, ELEVATOR_INSERT_REQUEUE);
        return rq;
 }
 
@@ -174,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);
@@ -191,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
@@ -200,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;
@@ -218,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);