summaryrefslogtreecommitdiffstats
path: root/drivers/md/bitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/bitmap.c')
-rw-r--r--drivers/md/bitmap.c136
1 files changed, 76 insertions, 60 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index ac688fb54e1d..c042efd019c3 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -553,6 +553,14 @@ static int bitmap_read_sb(struct bitmap *bitmap)
553 unsigned long long events; 553 unsigned long long events;
554 int err = -EINVAL; 554 int err = -EINVAL;
555 555
556 if (!bitmap->file && !bitmap->mddev->bitmap_info.offset) {
557 chunksize = 128 * 1024 * 1024;
558 daemon_sleep = 5 * HZ;
559 write_behind = 0;
560 bitmap->flags = BITMAP_STALE;
561 err = 0;
562 goto out_no_sb;
563 }
556 /* page 0 is the superblock, read it... */ 564 /* page 0 is the superblock, read it... */
557 if (bitmap->file) { 565 if (bitmap->file) {
558 loff_t isize = i_size_read(bitmap->file->f_mapping->host); 566 loff_t isize = i_size_read(bitmap->file->f_mapping->host);
@@ -623,18 +631,19 @@ static int bitmap_read_sb(struct bitmap *bitmap)
623 } 631 }
624 632
625 /* assign fields using values from superblock */ 633 /* assign fields using values from superblock */
626 bitmap->mddev->bitmap_info.chunksize = chunksize;
627 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep;
628 bitmap->mddev->bitmap_info.max_write_behind = write_behind;
629 bitmap->flags |= le32_to_cpu(sb->state); 634 bitmap->flags |= le32_to_cpu(sb->state);
630 if (le32_to_cpu(sb->version) == BITMAP_MAJOR_HOSTENDIAN) 635 if (le32_to_cpu(sb->version) == BITMAP_MAJOR_HOSTENDIAN)
631 bitmap->flags |= BITMAP_HOSTENDIAN; 636 bitmap->flags |= BITMAP_HOSTENDIAN;
632 bitmap->events_cleared = le64_to_cpu(sb->events_cleared); 637 bitmap->events_cleared = le64_to_cpu(sb->events_cleared);
633 if (bitmap->flags & BITMAP_STALE)
634 bitmap->events_cleared = bitmap->mddev->events;
635 err = 0; 638 err = 0;
636out: 639out:
637 kunmap_atomic(sb); 640 kunmap_atomic(sb);
641out_no_sb:
642 if (bitmap->flags & BITMAP_STALE)
643 bitmap->events_cleared = bitmap->mddev->events;
644 bitmap->mddev->bitmap_info.chunksize = chunksize;
645 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep;
646 bitmap->mddev->bitmap_info.max_write_behind = write_behind;
638 if (err) 647 if (err)
639 bitmap_print_sb(bitmap); 648 bitmap_print_sb(bitmap);
640 return err; 649 return err;
@@ -837,9 +846,6 @@ static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block)
837 void *kaddr; 846 void *kaddr;
838 unsigned long chunk = block >> bitmap->chunkshift; 847 unsigned long chunk = block >> bitmap->chunkshift;
839 848
840 if (!bitmap->filemap)
841 return;
842
843 page = filemap_get_page(bitmap, chunk); 849 page = filemap_get_page(bitmap, chunk);
844 if (!page) 850 if (!page)
845 return; 851 return;
@@ -857,6 +863,29 @@ static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block)
857 set_page_attr(bitmap, page, BITMAP_PAGE_DIRTY); 863 set_page_attr(bitmap, page, BITMAP_PAGE_DIRTY);
858} 864}
859 865
866static void bitmap_file_clear_bit(struct bitmap *bitmap, sector_t block)
867{
868 unsigned long bit;
869 struct page *page;
870 void *paddr;
871 unsigned long chunk = block >> bitmap->chunkshift;
872
873 page = filemap_get_page(bitmap, chunk);
874 if (!page)
875 return;
876 bit = file_page_offset(bitmap, chunk);
877 paddr = kmap_atomic(page);
878 if (bitmap->flags & BITMAP_HOSTENDIAN)
879 clear_bit(bit, paddr);
880 else
881 __clear_bit_le(bit, paddr);
882 kunmap_atomic(paddr);
883 if (!test_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE)) {
884 set_page_attr(bitmap, page, BITMAP_PAGE_PENDING);
885 bitmap->allclean = 0;
886 }
887}
888
860/* this gets called when the md device is ready to unplug its underlying 889/* this gets called when the md device is ready to unplug its underlying
861 * (slave) device queues -- before we let any writes go down, we need to 890 * (slave) device queues -- before we let any writes go down, we need to
862 * sync the dirty pages of the bitmap file to disk */ 891 * sync the dirty pages of the bitmap file to disk */
@@ -867,7 +896,7 @@ void bitmap_unplug(struct bitmap *bitmap)
867 struct page *page; 896 struct page *page;
868 int wait = 0; 897 int wait = 0;
869 898
870 if (!bitmap) 899 if (!bitmap || !bitmap->filemap)
871 return; 900 return;
872 901
873 /* look at each page to see if there are any set bits that need to be 902 /* look at each page to see if there are any set bits that need to be
@@ -930,7 +959,20 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
930 chunks = bitmap->chunks; 959 chunks = bitmap->chunks;
931 file = bitmap->file; 960 file = bitmap->file;
932 961
933 BUG_ON(!file && !bitmap->mddev->bitmap_info.offset); 962 if (!file && !bitmap->mddev->bitmap_info.offset) {
963 /* No permanent bitmap - fill with '1s'. */
964 bitmap->filemap = NULL;
965 bitmap->file_pages = 0;
966 for (i = 0; i < chunks ; i++) {
967 /* if the disk bit is set, set the memory bit */
968 int needed = ((sector_t)(i+1) << (bitmap->chunkshift)
969 >= start);
970 bitmap_set_memory_bits(bitmap,
971 (sector_t)i << bitmap->chunkshift,
972 needed);
973 }
974 return 0;
975 }
934 976
935 outofdate = bitmap->flags & BITMAP_STALE; 977 outofdate = bitmap->flags & BITMAP_STALE;
936 if (outofdate) 978 if (outofdate)
@@ -1045,15 +1087,6 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
1045 } 1087 }
1046 } 1088 }
1047 1089
1048 /* everything went OK */
1049 ret = 0;
1050 bitmap_mask_state(bitmap, BITMAP_STALE, MASK_UNSET);
1051
1052 if (bit_cnt) { /* Kick recovery if any bits were set */
1053 set_bit(MD_RECOVERY_NEEDED, &bitmap->mddev->recovery);
1054 md_wakeup_thread(bitmap->mddev->thread);
1055 }
1056
1057 printk(KERN_INFO "%s: bitmap initialized from disk: " 1090 printk(KERN_INFO "%s: bitmap initialized from disk: "
1058 "read %lu/%lu pages, set %lu of %lu bits\n", 1091 "read %lu/%lu pages, set %lu of %lu bits\n",
1059 bmname(bitmap), bitmap->file_pages, num_pages, bit_cnt, chunks); 1092 bmname(bitmap), bitmap->file_pages, num_pages, bit_cnt, chunks);
@@ -1073,6 +1106,12 @@ void bitmap_write_all(struct bitmap *bitmap)
1073 */ 1106 */
1074 int i; 1107 int i;
1075 1108
1109 if (!bitmap || !bitmap->filemap)
1110 return;
1111 if (bitmap->file)
1112 /* Only one copy, so nothing needed */
1113 return;
1114
1076 spin_lock_irq(&bitmap->lock); 1115 spin_lock_irq(&bitmap->lock);
1077 for (i = 0; i < bitmap->file_pages; i++) 1116 for (i = 0; i < bitmap->file_pages; i++)
1078 set_page_attr(bitmap, bitmap->filemap[i], 1117 set_page_attr(bitmap, bitmap->filemap[i],
@@ -1115,7 +1154,6 @@ void bitmap_daemon_work(struct mddev *mddev)
1115 unsigned long nextpage; 1154 unsigned long nextpage;
1116 unsigned long flags; 1155 unsigned long flags;
1117 sector_t blocks; 1156 sector_t blocks;
1118 void *paddr;
1119 1157
1120 /* Use a mutex to guard daemon_work against 1158 /* Use a mutex to guard daemon_work against
1121 * bitmap_destroy. 1159 * bitmap_destroy.
@@ -1142,10 +1180,6 @@ void bitmap_daemon_work(struct mddev *mddev)
1142 * we will write it. 1180 * we will write it.
1143 */ 1181 */
1144 spin_lock_irqsave(&bitmap->lock, flags); 1182 spin_lock_irqsave(&bitmap->lock, flags);
1145 if (!bitmap->filemap)
1146 /* error or shutdown */
1147 goto out;
1148
1149 for (j = 0; j < bitmap->file_pages; j++) 1183 for (j = 0; j < bitmap->file_pages; j++)
1150 if (test_page_attr(bitmap, bitmap->filemap[j], 1184 if (test_page_attr(bitmap, bitmap->filemap[j],
1151 BITMAP_PAGE_PENDING)) { 1185 BITMAP_PAGE_PENDING)) {
@@ -1161,11 +1195,14 @@ void bitmap_daemon_work(struct mddev *mddev)
1161 * other changes */ 1195 * other changes */
1162 bitmap_super_t *sb; 1196 bitmap_super_t *sb;
1163 bitmap->need_sync = 0; 1197 bitmap->need_sync = 0;
1164 sb = kmap_atomic(bitmap->sb_page); 1198 if (bitmap->filemap) {
1165 sb->events_cleared = 1199 sb = kmap_atomic(bitmap->sb_page);
1166 cpu_to_le64(bitmap->events_cleared); 1200 sb->events_cleared =
1167 kunmap_atomic(sb); 1201 cpu_to_le64(bitmap->events_cleared);
1168 set_page_attr(bitmap, bitmap->sb_page, BITMAP_PAGE_NEEDWRITE); 1202 kunmap_atomic(sb);
1203 set_page_attr(bitmap, bitmap->sb_page,
1204 BITMAP_PAGE_NEEDWRITE);
1205 }
1169 } 1206 }
1170 /* Now look at the bitmap counters and if any are '2' or '1', 1207 /* Now look at the bitmap counters and if any are '2' or '1',
1171 * decrement and handle accordingly. 1208 * decrement and handle accordingly.
@@ -1173,6 +1210,7 @@ void bitmap_daemon_work(struct mddev *mddev)
1173 nextpage = 0; 1210 nextpage = 0;
1174 for (j = 0; j < bitmap->chunks; j++) { 1211 for (j = 0; j < bitmap->chunks; j++) {
1175 bitmap_counter_t *bmc; 1212 bitmap_counter_t *bmc;
1213 sector_t block = (sector_t)j << bitmap->chunkshift;
1176 1214
1177 if (j == nextpage) { 1215 if (j == nextpage) {
1178 nextpage += PAGE_COUNTER_RATIO; 1216 nextpage += PAGE_COUNTER_RATIO;
@@ -1183,7 +1221,7 @@ void bitmap_daemon_work(struct mddev *mddev)
1183 bitmap->bp[j >> PAGE_COUNTER_SHIFT].pending = 0; 1221 bitmap->bp[j >> PAGE_COUNTER_SHIFT].pending = 0;
1184 } 1222 }
1185 bmc = bitmap_get_counter(bitmap, 1223 bmc = bitmap_get_counter(bitmap,
1186 (sector_t)j << bitmap->chunkshift, 1224 block,
1187 &blocks, 0); 1225 &blocks, 0);
1188 1226
1189 if (!bmc) { 1227 if (!bmc) {
@@ -1192,33 +1230,12 @@ void bitmap_daemon_work(struct mddev *mddev)
1192 } 1230 }
1193 if (*bmc == 1 && !bitmap->need_sync) { 1231 if (*bmc == 1 && !bitmap->need_sync) {
1194 /* We can clear the bit */ 1232 /* We can clear the bit */
1195 struct page *page;
1196 *bmc = 0; 1233 *bmc = 0;
1197 bitmap_count_page( 1234 bitmap_count_page(bitmap, block, -1);
1198 bitmap, 1235 bitmap_file_clear_bit(bitmap, block);
1199 (sector_t)j << bitmap->chunkshift,
1200 -1);
1201
1202 page = filemap_get_page(bitmap, j);
1203 paddr = kmap_atomic(page);
1204 if (bitmap->flags & BITMAP_HOSTENDIAN)
1205 clear_bit(file_page_offset(bitmap, j),
1206 paddr);
1207 else
1208 __clear_bit_le(file_page_offset(bitmap, j),
1209 paddr);
1210 kunmap_atomic(paddr);
1211 if (!test_page_attr(bitmap, page,
1212 BITMAP_PAGE_NEEDWRITE)) {
1213 set_page_attr(bitmap, page,
1214 BITMAP_PAGE_PENDING);
1215 bitmap->allclean = 0;
1216 }
1217 } else if (*bmc && *bmc <= 2) { 1236 } else if (*bmc && *bmc <= 2) {
1218 *bmc = 1; 1237 *bmc = 1;
1219 bitmap_set_pending( 1238 bitmap_set_pending(bitmap, block);
1220 bitmap,
1221 (sector_t)j << bitmap->chunkshift);
1222 bitmap->allclean = 0; 1239 bitmap->allclean = 0;
1223 } 1240 }
1224 } 1241 }
@@ -1249,7 +1266,6 @@ void bitmap_daemon_work(struct mddev *mddev)
1249 break; 1266 break;
1250 } 1267 }
1251 } 1268 }
1252out:
1253 spin_unlock_irqrestore(&bitmap->lock, flags); 1269 spin_unlock_irqrestore(&bitmap->lock, flags);
1254 1270
1255 done: 1271 done:
@@ -1551,7 +1567,7 @@ EXPORT_SYMBOL(bitmap_cond_end_sync);
1551static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed) 1567static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed)
1552{ 1568{
1553 /* For each chunk covered by any of these sectors, set the 1569 /* For each chunk covered by any of these sectors, set the
1554 * counter to 1 and set resync_needed. They should all 1570 * counter to 2 and possibly set resync_needed. They should all
1555 * be 0 at this point 1571 * be 0 at this point
1556 */ 1572 */
1557 1573
@@ -1678,10 +1694,6 @@ int bitmap_create(struct mddev *mddev)
1678 1694
1679 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256); 1695 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256);
1680 1696
1681 if (!file
1682 && !mddev->bitmap_info.offset) /* bitmap disabled, nothing to do */
1683 return 0;
1684
1685 BUG_ON(file && mddev->bitmap_info.offset); 1697 BUG_ON(file && mddev->bitmap_info.offset);
1686 1698
1687 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL); 1699 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL);
@@ -1801,6 +1813,10 @@ int bitmap_load(struct mddev *mddev)
1801 1813
1802 if (err) 1814 if (err)
1803 goto out; 1815 goto out;
1816 bitmap_mask_state(bitmap, BITMAP_STALE, MASK_UNSET);
1817
1818 /* Kick recovery in case any bits were set */
1819 set_bit(MD_RECOVERY_NEEDED, &bitmap->mddev->recovery);
1804 1820
1805 mddev->thread->timeout = mddev->bitmap_info.daemon_sleep; 1821 mddev->thread->timeout = mddev->bitmap_info.daemon_sleep;
1806 md_wakeup_thread(mddev->thread); 1822 md_wakeup_thread(mddev->thread);