Barrier support. Barriers are submitted to a worker thread that issues them in-order. __process_bio functions is modified that when it sees a barrier request, it waits for all pending IO before the request, then submits the barrier and waits for it. DM_ENDIO_REQUEUE doesn't work and I doubt that it can be made work with barriers. Signed-off-by: Mikulas Patocka --- drivers/md/dm.c | 77 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 15 deletions(-) Index: linux-2.6.28-clean/drivers/md/dm.c =================================================================== --- linux-2.6.28-clean.orig/drivers/md/dm.c 2009-01-12 15:17:18.000000000 +0100 +++ linux-2.6.28-clean/drivers/md/dm.c 2009-01-12 15:19:40.000000000 +0100 @@ -100,6 +100,11 @@ struct mapped_device { struct bio_list pushback; /* + * An error from the barrier request currently being processed. + */ + int barrier_error; + + /* * Processing queue (flush/barriers) */ struct workqueue_struct *wq; @@ -381,6 +386,10 @@ static void end_io_acct(struct dm_io *io part_stat_add(cpu, &dm_disk(md)->part0, ticks[rw], duration); part_stat_unlock(); + /* + * after this is decremented, the bio must not be touched if it is + * barrier bio + */ dm_disk(md)->part0.in_flight = pending = atomic_dec_return(&md->pending); @@ -480,7 +489,8 @@ static void dec_pending(struct dm_io *io * suspend queue merges the pushback list. */ spin_lock_irqsave(&io->md->pushback_lock, flags); - if (__noflush_suspending(io->md)) + /* TODO: no barriers for noflush are supported now */ + if (__noflush_suspending(io->md) && !bio_barrier(io->bio)) bio_list_add(&io->md->pushback, io->bio); else /* noflush suspend was interrupted. */ @@ -488,13 +498,23 @@ static void dec_pending(struct dm_io *io spin_unlock_irqrestore(&io->md->pushback_lock, flags); } - end_io_acct(io); - - if (io->error != DM_ENDIO_REQUEUE) { - blk_add_trace_bio(io->md->queue, io->bio, - BLK_TA_COMPLETE); + if (bio_barrier(io->bio)) { + /* + * There could be just one barrier request, so we use + * per-device variable for error reporting is OK. + * Note that you can't touch the bio after end_io_acct + */ + io->md->barrier_error = io->error; + end_io_acct(io); + } else { + end_io_acct(io); + + if (io->error != DM_ENDIO_REQUEUE) { + blk_add_trace_bio(io->md->queue, io->bio, + BLK_TA_COMPLETE); - bio_endio(io->bio, io->error); + bio_endio(io->bio, io->error); + } } free_io(io->md, io); @@ -660,6 +680,7 @@ static struct bio *clone_bio(struct bio clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs); __bio_clone(clone, bio); + clone->bi_rw &= ~(1 << BIO_RW_BARRIER); clone->bi_destructor = dm_bio_destructor; clone->bi_sector = sector; clone->bi_idx = idx; @@ -780,7 +801,10 @@ static void __process_bio(struct mapped_ ci.map = dm_get_table(md); if (unlikely(!ci.map)) { - bio_io_error(bio); + if (!bio_barrier(bio)) + bio_io_error(bio); + else + md->barrier_error = -EIO; return; } @@ -868,11 +892,6 @@ static int dm_request(struct request_que * There is no use in forwarding any barrier request since we can't * guarantee it is (or can be) handled by the targets correctly. */ - if (unlikely(bio_barrier(bio))) { - bio_endio(bio, -EOPNOTSUPP); - return 0; - } - down_read(&md->io_lock); cpu = part_stat_lock(); @@ -884,7 +903,8 @@ static int dm_request(struct request_que * If we're suspended we have to queue * this io for later. */ - if (unlikely(test_bit(DMF_BLOCK_IO, &md->flags))) { + if (unlikely(test_bit(DMF_BLOCK_IO, &md->flags)) || + unlikely(bio_barrier(bio))) { up_read(&md->io_lock); queue_io(md, bio); @@ -1341,6 +1361,12 @@ static int dm_wait_for_completion(struct return r; } +static int dm_flush(struct mapped_device *md) +{ + dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); + return 0; +} + static void __merge_pushback_list(struct mapped_device *md) { unsigned long flags; @@ -1368,8 +1394,29 @@ static void dm_wq_work(struct work_struc } up_write(&md->io_lock); - __process_bio(md, c); + if (!bio_barrier(c)) + __process_bio(md, c); + else { + int error = dm_flush(md); + if (unlikely(error)) { + bio_endio(c, error); + goto next_bio; + } + if (bio_empty_barrier(c)) { + bio_endio(c, 0); + goto next_bio; + } + + __process_bio(md, c); + + error = dm_flush(md); + if (!error && md->barrier_error) + error = md->barrier_error; + + bio_endio(c, error); + } +next_bio: down_write(&md->io_lock); }