diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c index 09d32db06d20002b2b8f8e7502d7b72be8c16189..41df4cda66e2f27b668a98988aaf80121fb16236 100644 --- a/drivers/md/bitmap.c +++ b/drivers/md/bitmap.c @@ -1450,6 +1450,29 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset) } +/* + * flush out any pending updates + */ +void bitmap_flush(mddev_t *mddev) +{ + struct bitmap *bitmap = mddev->bitmap; + int sleep; + + if (!bitmap) /* there was no bitmap */ + return; + + /* run the daemon_work three time to ensure everything is flushed + * that can be + */ + sleep = bitmap->daemon_sleep; + bitmap->daemon_sleep = 0; + bitmap_daemon_work(bitmap); + bitmap_daemon_work(bitmap); + bitmap_daemon_work(bitmap); + bitmap->daemon_sleep = sleep; + bitmap_update_sb(bitmap); +} + /* * free memory that was allocated */ diff --git a/drivers/md/md.c b/drivers/md/md.c index 9fd4dbea0d0d739a8b5902051c5e69cba1ecab8d..480f658db6f21f11809216e905c90eb676f76268 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -1798,6 +1798,8 @@ static int do_md_stop(mddev_t * mddev, int ro) goto out; mddev->ro = 1; } else { + bitmap_flush(mddev); + wait_event(mddev->sb_wait, atomic_read(&mddev->pending_writes)==0); if (mddev->ro) set_disk_ro(disk, 0); blk_queue_make_request(mddev->queue, md_fail_request); diff --git a/include/linux/raid/bitmap.h b/include/linux/raid/bitmap.h index 6213e976eadedbd3385ba6e6ecad9f862259aea6..4bf1659f8aa87df1e9aad302f17c008f10850bd5 100644 --- a/include/linux/raid/bitmap.h +++ b/include/linux/raid/bitmap.h @@ -248,6 +248,7 @@ struct bitmap { /* these are used only by md/bitmap */ int bitmap_create(mddev_t *mddev); +void bitmap_flush(mddev_t *mddev); void bitmap_destroy(mddev_t *mddev); int bitmap_active(struct bitmap *bitmap);