How about something like this? diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c index 857c49399c28..c263173a142f 100644 --- a/drivers/md/raid0.c +++ b/drivers/md/raid0.c @@ -393,6 +393,9 @@ static int raid0_run(struct mddev *mddev) mddev->private = conf; } conf = mddev->private; + + init_waitqueue_head(&conf->wait_for_quiescent); + if (mddev->queue) { struct md_rdev *rdev; @@ -512,6 +515,18 @@ static void raid0_handle_discard(struct mddev *mddev, struct bio *bio) bio_endio(bio); } +static void raid0_end_request(struct bio *bio) +{ + struct bio *orig_bio = bio->bi_private; + struct gendisk *disk = orig_bio->bi_bdev->bd_disk; + struct mddev *mddev = disk->private; + struct r0conf *conf = mddev->private; + + atomic_dec(&conf->bios); + bio_put(bio); + bio_endio(orig_bio); +} + static bool raid0_make_request(struct mddev *mddev, struct bio *bio) { struct r0conf *conf = mddev->private; @@ -522,6 +537,7 @@ static bool raid0_make_request(struct mddev *mddev, struct bio *bio) sector_t orig_sector; unsigned chunk_sects; unsigned sectors; + struct bio *r0_bio; if (unlikely(bio->bi_opf & REQ_PREFLUSH) && md_flush_request(mddev, bio)) @@ -575,15 +591,20 @@ static bool raid0_make_request(struct mddev *mddev, struct bio *bio) return true; } - bio_set_dev(bio, tmp_dev->bdev); - bio->bi_iter.bi_sector = sector + zone->dev_start + + r0_bio = bio_alloc_clone(tmp_dev->bdev, bio, GFP_NOIO, + &mddev->bio_set); + + r0_bio->bi_private = bio; + r0_bio->bi_end_io = raid0_end_request; + r0_bio->bi_iter.bi_sector = sector + zone->dev_start + tmp_dev->data_offset; if (mddev->gendisk) - trace_block_bio_remap(bio, disk_devt(mddev->gendisk), + trace_block_bio_remap(r0_bio, disk_devt(mddev->gendisk), bio_sector); - mddev_check_write_zeroes(mddev, bio); - submit_bio_noacct(bio); + mddev_check_write_zeroes(mddev, r0_bio); + atomic_inc(&conf->bios); + submit_bio_noacct(r0_bio); return true; } @@ -754,6 +775,10 @@ static void *raid0_takeover(struct mddev *mddev) static void raid0_quiesce(struct mddev *mddev, int quiesce) { + struct r0conf *conf = mddev->private; + + if (quiesce) + wait_event(&conf->wait_for_quiescent, atomic_read(&conf->bios)==0); } static struct md_personality raid0_personality= diff --git a/drivers/md/raid0.h b/drivers/md/raid0.h index 3816e5477db1..a0ec5c235962 100644 --- a/drivers/md/raid0.h +++ b/drivers/md/raid0.h @@ -27,6 +27,9 @@ struct r0conf { * by strip_zone->dev */ int nr_strip_zones; enum r0layout layout; + atomic_t bios; /* The bios that submit to + * member disks */ + struct wait_queue_head_t wait_for_quiescent; }; Regards Xiao