aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2010-06-01 05:37:35 -0400
committerNeilBrown <neilb@suse.de>2010-07-25 23:21:34 -0400
commit69e51b449d383e97b1b9f890f8378c96e9e17346 (patch)
tree650123fa4f08e8fa7f348a4ca875c59c129e5d84
parente384e58549a2e9a83071ad80280c1a9053cfd84c (diff)
md/bitmap: separate out loading a bitmap from initialising the structures.
dm makes this distinction between ->ctr and ->resume, so we need to too. Also get the new bitmap_load to clear out the bitmap first, as this is most consistent with the dm suspend/resume approach Signed-off-by: NeilBrown <neilb@suse.de>
-rw-r--r--drivers/md/bitmap.c69
-rw-r--r--drivers/md/bitmap.h1
-rw-r--r--drivers/md/md.c13
3 files changed, 60 insertions, 23 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 93765261c363..1ba1e122e948 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -1681,7 +1681,6 @@ int bitmap_create(mddev_t *mddev)
1681 unsigned long pages; 1681 unsigned long pages;
1682 struct file *file = mddev->bitmap_info.file; 1682 struct file *file = mddev->bitmap_info.file;
1683 int err; 1683 int err;
1684 sector_t start;
1685 struct sysfs_dirent *bm = NULL; 1684 struct sysfs_dirent *bm = NULL;
1686 1685
1687 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256); 1686 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256);
@@ -1763,13 +1762,40 @@ int bitmap_create(mddev_t *mddev)
1763 if (!bitmap->bp) 1762 if (!bitmap->bp)
1764 goto error; 1763 goto error;
1765 1764
1766 /* now that we have some pages available, initialize the in-memory 1765 printk(KERN_INFO "created bitmap (%lu pages) for device %s\n",
1767 * bitmap from the on-disk bitmap */ 1766 pages, bmname(bitmap));
1768 start = 0; 1767
1769 if (mddev->degraded == 0 1768 mddev->bitmap = bitmap;
1770 || bitmap->events_cleared == mddev->events) 1769
1771 /* no need to keep dirty bits to optimise a re-add of a missing device */ 1770
1772 start = mddev->recovery_cp; 1771 return (bitmap->flags & BITMAP_WRITE_ERROR) ? -EIO : 0;
1772
1773 error:
1774 bitmap_free(bitmap);
1775 return err;
1776}
1777
1778int bitmap_load(mddev_t *mddev)
1779{
1780 int err = 0;
1781 sector_t sector = 0;
1782 struct bitmap *bitmap = mddev->bitmap;
1783
1784 if (!bitmap)
1785 goto out;
1786
1787 /* Clear out old bitmap info first: Either there is none, or we
1788 * are resuming after someone else has possibly changed things,
1789 * so we should forget old cached info.
1790 * All chunks should be clean, but some might need_sync.
1791 */
1792 while (sector < mddev->resync_max_sectors) {
1793 int blocks;
1794 bitmap_start_sync(bitmap, sector, &blocks, 0);
1795 sector += blocks;
1796 }
1797 bitmap_close_sync(bitmap);
1798
1773 if (mddev->bitmap_info.log) { 1799 if (mddev->bitmap_info.log) {
1774 unsigned long i; 1800 unsigned long i;
1775 struct dm_dirty_log *log = mddev->bitmap_info.log; 1801 struct dm_dirty_log *log = mddev->bitmap_info.log;
@@ -1778,29 +1804,30 @@ int bitmap_create(mddev_t *mddev)
1778 bitmap_set_memory_bits(bitmap, 1804 bitmap_set_memory_bits(bitmap,
1779 (sector_t)i << CHUNK_BLOCK_SHIFT(bitmap), 1805 (sector_t)i << CHUNK_BLOCK_SHIFT(bitmap),
1780 1); 1806 1);
1781 err = 0; 1807 } else {
1782 } else 1808 sector_t start = 0;
1783 err = bitmap_init_from_disk(bitmap, start); 1809 if (mddev->degraded == 0
1810 || bitmap->events_cleared == mddev->events)
1811 /* no need to keep dirty bits to optimise a
1812 * re-add of a missing device */
1813 start = mddev->recovery_cp;
1784 1814
1815 err = bitmap_init_from_disk(bitmap, start);
1816 }
1785 if (err) 1817 if (err)
1786 goto error; 1818 goto out;
1787
1788 printk(KERN_INFO "created bitmap (%lu pages) for device %s\n",
1789 pages, bmname(bitmap));
1790
1791 mddev->bitmap = bitmap;
1792 1819
1793 mddev->thread->timeout = mddev->bitmap_info.daemon_sleep; 1820 mddev->thread->timeout = mddev->bitmap_info.daemon_sleep;
1794 md_wakeup_thread(mddev->thread); 1821 md_wakeup_thread(mddev->thread);
1795 1822
1796 bitmap_update_sb(bitmap); 1823 bitmap_update_sb(bitmap);
1797 1824
1798 return (bitmap->flags & BITMAP_WRITE_ERROR) ? -EIO : 0; 1825 if (bitmap->flags & BITMAP_WRITE_ERROR)
1799 1826 err = -EIO;
1800 error: 1827out:
1801 bitmap_free(bitmap);
1802 return err; 1828 return err;
1803} 1829}
1830EXPORT_SYMBOL_GPL(bitmap_load);
1804 1831
1805static ssize_t 1832static ssize_t
1806location_show(mddev_t *mddev, char *page) 1833location_show(mddev_t *mddev, char *page)
diff --git a/drivers/md/bitmap.h b/drivers/md/bitmap.h
index a7a11134268d..e872a7bad6b8 100644
--- a/drivers/md/bitmap.h
+++ b/drivers/md/bitmap.h
@@ -254,6 +254,7 @@ struct bitmap {
254 254
255/* these are used only by md/bitmap */ 255/* these are used only by md/bitmap */
256int bitmap_create(mddev_t *mddev); 256int bitmap_create(mddev_t *mddev);
257int bitmap_load(mddev_t *mddev);
257void bitmap_flush(mddev_t *mddev); 258void bitmap_flush(mddev_t *mddev);
258void bitmap_destroy(mddev_t *mddev); 259void bitmap_destroy(mddev_t *mddev);
259 260
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 9d4e44e460e9..40b7ca0294ac 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -4594,7 +4594,11 @@ static int do_md_run(mddev_t *mddev)
4594 err = md_run(mddev); 4594 err = md_run(mddev);
4595 if (err) 4595 if (err)
4596 goto out; 4596 goto out;
4597 4597 err = bitmap_load(mddev);
4598 if (err) {
4599 bitmap_destroy(mddev);
4600 goto out;
4601 }
4598 set_capacity(mddev->gendisk, mddev->array_sectors); 4602 set_capacity(mddev->gendisk, mddev->array_sectors);
4599 revalidate_disk(mddev->gendisk); 4603 revalidate_disk(mddev->gendisk);
4600 kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); 4604 kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
@@ -5382,8 +5386,11 @@ static int set_bitmap_file(mddev_t *mddev, int fd)
5382 err = 0; 5386 err = 0;
5383 if (mddev->pers) { 5387 if (mddev->pers) {
5384 mddev->pers->quiesce(mddev, 1); 5388 mddev->pers->quiesce(mddev, 1);
5385 if (fd >= 0) 5389 if (fd >= 0) {
5386 err = bitmap_create(mddev); 5390 err = bitmap_create(mddev);
5391 if (!err)
5392 err = bitmap_load(mddev);
5393 }
5387 if (fd < 0 || err) { 5394 if (fd < 0 || err) {
5388 bitmap_destroy(mddev); 5395 bitmap_destroy(mddev);
5389 fd = -1; /* make sure to put the file */ 5396 fd = -1; /* make sure to put the file */
@@ -5632,6 +5639,8 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
5632 mddev->bitmap_info.default_offset; 5639 mddev->bitmap_info.default_offset;
5633 mddev->pers->quiesce(mddev, 1); 5640 mddev->pers->quiesce(mddev, 1);
5634 rv = bitmap_create(mddev); 5641 rv = bitmap_create(mddev);
5642 if (!rv)
5643 rv = bitmap_load(mddev);
5635 if (rv) 5644 if (rv)
5636 bitmap_destroy(mddev); 5645 bitmap_destroy(mddev);
5637 mddev->pers->quiesce(mddev, 0); 5646 mddev->pers->quiesce(mddev, 0);