aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/bitmap.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-10-26 15:39:42 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-26 15:39:42 -0400
commitc3ae1f33569e06984f0426a7834ff63251d44d84 (patch)
tree0d7f6f6b49c331e440850cf2e8a7bc0cf220f8bc /drivers/md/bitmap.c
parentc28cfd60e4ec3f494b73ef7d6c661f5f491cd84f (diff)
parentd890fa2b0586b6177b119643ff66932127d58afa (diff)
Merge branch 'for-linus' of git://neil.brown.name/md
* 'for-linus' of git://neil.brown.name/md: (34 commits) md: Fix some bugs in recovery_disabled handling. md/raid5: fix bug that could result in reads from a failed device. lib/raid6: Fix filename emitted in generated code md.c: trivial comment fix MD: Allow restarting an interrupted incremental recovery. md: clear In_sync bit on devices added to an active array. md: add proper write-congestion reporting to RAID1 and RAID10. md: rename "mdk_personality" to "md_personality" md/bitmap remove fault injection options. md/raid5: typedef removal: raid5_conf_t -> struct r5conf md/raid1: typedef removal: conf_t -> struct r1conf md/raid10: typedef removal: conf_t -> struct r10conf md/raid0: typedef removal: raid0_conf_t -> struct r0conf md/multipath: typedef removal: multipath_conf_t -> struct mpconf md/linear: typedef removal: linear_conf_t -> struct linear_conf md/faulty: remove typedef: conf_t -> struct faulty_conf md/linear: remove typedefs: dev_info_t -> struct dev_info md: remove typedefs: mirror_info_t -> struct mirror_info md: remove typedefs: r10bio_t -> struct r10bio and r1bio_t -> struct r1bio md: remove typedefs: mdk_thread_t -> struct md_thread ...
Diffstat (limited to 'drivers/md/bitmap.c')
-rw-r--r--drivers/md/bitmap.c188
1 files changed, 77 insertions, 111 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 0dc6546b77a8..7878712721bf 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -29,35 +29,6 @@
29#include "md.h" 29#include "md.h"
30#include "bitmap.h" 30#include "bitmap.h"
31 31
32/* debug macros */
33
34#define DEBUG 0
35
36#if DEBUG
37/* these are for debugging purposes only! */
38
39/* define one and only one of these */
40#define INJECT_FAULTS_1 0 /* cause bitmap_alloc_page to fail always */
41#define INJECT_FAULTS_2 0 /* cause bitmap file to be kicked when first bit set*/
42#define INJECT_FAULTS_3 0 /* treat bitmap file as kicked at init time */
43#define INJECT_FAULTS_4 0 /* undef */
44#define INJECT_FAULTS_5 0 /* undef */
45#define INJECT_FAULTS_6 0
46
47/* if these are defined, the driver will fail! debug only */
48#define INJECT_FATAL_FAULT_1 0 /* fail kmalloc, causing bitmap_create to fail */
49#define INJECT_FATAL_FAULT_2 0 /* undef */
50#define INJECT_FATAL_FAULT_3 0 /* undef */
51#endif
52
53#ifndef PRINTK
54# if DEBUG > 0
55# define PRINTK(x...) printk(KERN_DEBUG x)
56# else
57# define PRINTK(x...)
58# endif
59#endif
60
61static inline char *bmname(struct bitmap *bitmap) 32static inline char *bmname(struct bitmap *bitmap)
62{ 33{
63 return bitmap->mddev ? mdname(bitmap->mddev) : "mdX"; 34 return bitmap->mddev ? mdname(bitmap->mddev) : "mdX";
@@ -70,16 +41,12 @@ static unsigned char *bitmap_alloc_page(struct bitmap *bitmap)
70{ 41{
71 unsigned char *page; 42 unsigned char *page;
72 43
73#ifdef INJECT_FAULTS_1
74 page = NULL;
75#else
76 page = kzalloc(PAGE_SIZE, GFP_NOIO); 44 page = kzalloc(PAGE_SIZE, GFP_NOIO);
77#endif
78 if (!page) 45 if (!page)
79 printk("%s: bitmap_alloc_page FAILED\n", bmname(bitmap)); 46 printk("%s: bitmap_alloc_page FAILED\n", bmname(bitmap));
80 else 47 else
81 PRINTK("%s: bitmap_alloc_page: allocated page at %p\n", 48 pr_debug("%s: bitmap_alloc_page: allocated page at %p\n",
82 bmname(bitmap), page); 49 bmname(bitmap), page);
83 return page; 50 return page;
84} 51}
85 52
@@ -88,7 +55,7 @@ static unsigned char *bitmap_alloc_page(struct bitmap *bitmap)
88 */ 55 */
89static void bitmap_free_page(struct bitmap *bitmap, unsigned char *page) 56static void bitmap_free_page(struct bitmap *bitmap, unsigned char *page)
90{ 57{
91 PRINTK("%s: bitmap_free_page: free page %p\n", bmname(bitmap), page); 58 pr_debug("%s: bitmap_free_page: free page %p\n", bmname(bitmap), page);
92 kfree(page); 59 kfree(page);
93} 60}
94 61
@@ -133,8 +100,8 @@ __acquires(bitmap->lock)
133 spin_lock_irq(&bitmap->lock); 100 spin_lock_irq(&bitmap->lock);
134 101
135 if (mappage == NULL) { 102 if (mappage == NULL) {
136 PRINTK("%s: bitmap map page allocation failed, hijacking\n", 103 pr_debug("%s: bitmap map page allocation failed, hijacking\n",
137 bmname(bitmap)); 104 bmname(bitmap));
138 /* failed - set the hijacked flag so that we can use the 105 /* failed - set the hijacked flag so that we can use the
139 * pointer as a counter */ 106 * pointer as a counter */
140 if (!bitmap->bp[page].map) 107 if (!bitmap->bp[page].map)
@@ -187,13 +154,13 @@ static void bitmap_checkfree(struct bitmap *bitmap, unsigned long page)
187 */ 154 */
188 155
189/* IO operations when bitmap is stored near all superblocks */ 156/* IO operations when bitmap is stored near all superblocks */
190static struct page *read_sb_page(mddev_t *mddev, loff_t offset, 157static struct page *read_sb_page(struct mddev *mddev, loff_t offset,
191 struct page *page, 158 struct page *page,
192 unsigned long index, int size) 159 unsigned long index, int size)
193{ 160{
194 /* choose a good rdev and read the page from there */ 161 /* choose a good rdev and read the page from there */
195 162
196 mdk_rdev_t *rdev; 163 struct md_rdev *rdev;
197 sector_t target; 164 sector_t target;
198 int did_alloc = 0; 165 int did_alloc = 0;
199 166
@@ -226,7 +193,7 @@ static struct page *read_sb_page(mddev_t *mddev, loff_t offset,
226 193
227} 194}
228 195
229static mdk_rdev_t *next_active_rdev(mdk_rdev_t *rdev, mddev_t *mddev) 196static struct md_rdev *next_active_rdev(struct md_rdev *rdev, struct mddev *mddev)
230{ 197{
231 /* Iterate the disks of an mddev, using rcu to protect access to the 198 /* Iterate the disks of an mddev, using rcu to protect access to the
232 * linked list, and raising the refcount of devices we return to ensure 199 * linked list, and raising the refcount of devices we return to ensure
@@ -247,7 +214,7 @@ static mdk_rdev_t *next_active_rdev(mdk_rdev_t *rdev, mddev_t *mddev)
247 pos = &rdev->same_set; 214 pos = &rdev->same_set;
248 } 215 }
249 list_for_each_continue_rcu(pos, &mddev->disks) { 216 list_for_each_continue_rcu(pos, &mddev->disks) {
250 rdev = list_entry(pos, mdk_rdev_t, same_set); 217 rdev = list_entry(pos, struct md_rdev, same_set);
251 if (rdev->raid_disk >= 0 && 218 if (rdev->raid_disk >= 0 &&
252 !test_bit(Faulty, &rdev->flags)) { 219 !test_bit(Faulty, &rdev->flags)) {
253 /* this is a usable devices */ 220 /* this is a usable devices */
@@ -262,9 +229,9 @@ static mdk_rdev_t *next_active_rdev(mdk_rdev_t *rdev, mddev_t *mddev)
262 229
263static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait) 230static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
264{ 231{
265 mdk_rdev_t *rdev = NULL; 232 struct md_rdev *rdev = NULL;
266 struct block_device *bdev; 233 struct block_device *bdev;
267 mddev_t *mddev = bitmap->mddev; 234 struct mddev *mddev = bitmap->mddev;
268 235
269 while ((rdev = next_active_rdev(rdev, mddev)) != NULL) { 236 while ((rdev = next_active_rdev(rdev, mddev)) != NULL) {
270 int size = PAGE_SIZE; 237 int size = PAGE_SIZE;
@@ -409,8 +376,8 @@ static struct page *read_page(struct file *file, unsigned long index,
409 struct buffer_head *bh; 376 struct buffer_head *bh;
410 sector_t block; 377 sector_t block;
411 378
412 PRINTK("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE, 379 pr_debug("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE,
413 (unsigned long long)index << PAGE_SHIFT); 380 (unsigned long long)index << PAGE_SHIFT);
414 381
415 page = alloc_page(GFP_KERNEL); 382 page = alloc_page(GFP_KERNEL);
416 if (!page) 383 if (!page)
@@ -868,7 +835,8 @@ static void bitmap_file_kick(struct bitmap *bitmap)
868 835
869enum bitmap_page_attr { 836enum bitmap_page_attr {
870 BITMAP_PAGE_DIRTY = 0, /* there are set bits that need to be synced */ 837 BITMAP_PAGE_DIRTY = 0, /* there are set bits that need to be synced */
871 BITMAP_PAGE_CLEAN = 1, /* there are bits that might need to be cleared */ 838 BITMAP_PAGE_PENDING = 1, /* there are bits that are being cleaned.
839 * i.e. counter is 1 or 2. */
872 BITMAP_PAGE_NEEDWRITE = 2, /* there are cleared bits that need to be synced */ 840 BITMAP_PAGE_NEEDWRITE = 2, /* there are cleared bits that need to be synced */
873}; 841};
874 842
@@ -919,7 +887,7 @@ static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block)
919 else 887 else
920 __set_bit_le(bit, kaddr); 888 __set_bit_le(bit, kaddr);
921 kunmap_atomic(kaddr, KM_USER0); 889 kunmap_atomic(kaddr, KM_USER0);
922 PRINTK("set file bit %lu page %lu\n", bit, page->index); 890 pr_debug("set file bit %lu page %lu\n", bit, page->index);
923 /* record page number so it gets flushed to disk when unplug occurs */ 891 /* record page number so it gets flushed to disk when unplug occurs */
924 set_page_attr(bitmap, page, BITMAP_PAGE_DIRTY); 892 set_page_attr(bitmap, page, BITMAP_PAGE_DIRTY);
925} 893}
@@ -997,11 +965,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
997 965
998 BUG_ON(!file && !bitmap->mddev->bitmap_info.offset); 966 BUG_ON(!file && !bitmap->mddev->bitmap_info.offset);
999 967
1000#ifdef INJECT_FAULTS_3
1001 outofdate = 1;
1002#else
1003 outofdate = bitmap->flags & BITMAP_STALE; 968 outofdate = bitmap->flags & BITMAP_STALE;
1004#endif
1005 if (outofdate) 969 if (outofdate)
1006 printk(KERN_INFO "%s: bitmap file is out of date, doing full " 970 printk(KERN_INFO "%s: bitmap file is out of date, doing full "
1007 "recovery\n", bmname(bitmap)); 971 "recovery\n", bmname(bitmap));
@@ -1111,7 +1075,6 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
1111 (sector_t)i << CHUNK_BLOCK_SHIFT(bitmap), 1075 (sector_t)i << CHUNK_BLOCK_SHIFT(bitmap),
1112 needed); 1076 needed);
1113 bit_cnt++; 1077 bit_cnt++;
1114 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
1115 } 1078 }
1116 } 1079 }
1117 1080
@@ -1146,6 +1109,7 @@ void bitmap_write_all(struct bitmap *bitmap)
1146 for (i = 0; i < bitmap->file_pages; i++) 1109 for (i = 0; i < bitmap->file_pages; i++)
1147 set_page_attr(bitmap, bitmap->filemap[i], 1110 set_page_attr(bitmap, bitmap->filemap[i],
1148 BITMAP_PAGE_NEEDWRITE); 1111 BITMAP_PAGE_NEEDWRITE);
1112 bitmap->allclean = 0;
1149} 1113}
1150 1114
1151static void bitmap_count_page(struct bitmap *bitmap, sector_t offset, int inc) 1115static void bitmap_count_page(struct bitmap *bitmap, sector_t offset, int inc)
@@ -1164,7 +1128,7 @@ static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
1164 * out to disk 1128 * out to disk
1165 */ 1129 */
1166 1130
1167void bitmap_daemon_work(mddev_t *mddev) 1131void bitmap_daemon_work(struct mddev *mddev)
1168{ 1132{
1169 struct bitmap *bitmap; 1133 struct bitmap *bitmap;
1170 unsigned long j; 1134 unsigned long j;
@@ -1204,17 +1168,15 @@ void bitmap_daemon_work(mddev_t *mddev)
1204 1168
1205 if (page != lastpage) { 1169 if (page != lastpage) {
1206 /* skip this page unless it's marked as needing cleaning */ 1170 /* skip this page unless it's marked as needing cleaning */
1207 if (!test_page_attr(bitmap, page, BITMAP_PAGE_CLEAN)) { 1171 if (!test_page_attr(bitmap, page, BITMAP_PAGE_PENDING)) {
1208 int need_write = test_page_attr(bitmap, page, 1172 int need_write = test_page_attr(bitmap, page,
1209 BITMAP_PAGE_NEEDWRITE); 1173 BITMAP_PAGE_NEEDWRITE);
1210 if (need_write) 1174 if (need_write)
1211 clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE); 1175 clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
1212 1176
1213 spin_unlock_irqrestore(&bitmap->lock, flags); 1177 spin_unlock_irqrestore(&bitmap->lock, flags);
1214 if (need_write) { 1178 if (need_write)
1215 write_page(bitmap, page, 0); 1179 write_page(bitmap, page, 0);
1216 bitmap->allclean = 0;
1217 }
1218 spin_lock_irqsave(&bitmap->lock, flags); 1180 spin_lock_irqsave(&bitmap->lock, flags);
1219 j |= (PAGE_BITS - 1); 1181 j |= (PAGE_BITS - 1);
1220 continue; 1182 continue;
@@ -1222,12 +1184,16 @@ void bitmap_daemon_work(mddev_t *mddev)
1222 1184
1223 /* grab the new page, sync and release the old */ 1185 /* grab the new page, sync and release the old */
1224 if (lastpage != NULL) { 1186 if (lastpage != NULL) {
1225 if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) { 1187 if (test_page_attr(bitmap, lastpage,
1226 clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1188 BITMAP_PAGE_NEEDWRITE)) {
1189 clear_page_attr(bitmap, lastpage,
1190 BITMAP_PAGE_NEEDWRITE);
1227 spin_unlock_irqrestore(&bitmap->lock, flags); 1191 spin_unlock_irqrestore(&bitmap->lock, flags);
1228 write_page(bitmap, lastpage, 0); 1192 write_page(bitmap, lastpage, 0);
1229 } else { 1193 } else {
1230 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1194 set_page_attr(bitmap, lastpage,
1195 BITMAP_PAGE_NEEDWRITE);
1196 bitmap->allclean = 0;
1231 spin_unlock_irqrestore(&bitmap->lock, flags); 1197 spin_unlock_irqrestore(&bitmap->lock, flags);
1232 } 1198 }
1233 } else 1199 } else
@@ -1249,19 +1215,17 @@ void bitmap_daemon_work(mddev_t *mddev)
1249 } 1215 }
1250 spin_lock_irqsave(&bitmap->lock, flags); 1216 spin_lock_irqsave(&bitmap->lock, flags);
1251 if (!bitmap->need_sync) 1217 if (!bitmap->need_sync)
1252 clear_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); 1218 clear_page_attr(bitmap, page, BITMAP_PAGE_PENDING);
1219 else
1220 bitmap->allclean = 0;
1253 } 1221 }
1254 bmc = bitmap_get_counter(bitmap, 1222 bmc = bitmap_get_counter(bitmap,
1255 (sector_t)j << CHUNK_BLOCK_SHIFT(bitmap), 1223 (sector_t)j << CHUNK_BLOCK_SHIFT(bitmap),
1256 &blocks, 0); 1224 &blocks, 0);
1257 if (bmc) { 1225 if (!bmc)
1258 if (*bmc) 1226 j |= PAGE_COUNTER_MASK;
1259 bitmap->allclean = 0; 1227 else if (*bmc) {
1260 1228 if (*bmc == 1 && !bitmap->need_sync) {
1261 if (*bmc == 2) {
1262 *bmc = 1; /* maybe clear the bit next time */
1263 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
1264 } else if (*bmc == 1 && !bitmap->need_sync) {
1265 /* we can clear the bit */ 1229 /* we can clear the bit */
1266 *bmc = 0; 1230 *bmc = 0;
1267 bitmap_count_page(bitmap, 1231 bitmap_count_page(bitmap,
@@ -1275,13 +1239,16 @@ void bitmap_daemon_work(mddev_t *mddev)
1275 paddr); 1239 paddr);
1276 else 1240 else
1277 __clear_bit_le( 1241 __clear_bit_le(
1278 file_page_offset(bitmap, 1242 file_page_offset(bitmap,
1279 j), 1243 j),
1280 paddr); 1244 paddr);
1281 kunmap_atomic(paddr, KM_USER0); 1245 kunmap_atomic(paddr, KM_USER0);
1246 } else if (*bmc <= 2) {
1247 *bmc = 1; /* maybe clear the bit next time */
1248 set_page_attr(bitmap, page, BITMAP_PAGE_PENDING);
1249 bitmap->allclean = 0;
1282 } 1250 }
1283 } else 1251 }
1284 j |= PAGE_COUNTER_MASK;
1285 } 1252 }
1286 spin_unlock_irqrestore(&bitmap->lock, flags); 1253 spin_unlock_irqrestore(&bitmap->lock, flags);
1287 1254
@@ -1294,6 +1261,7 @@ void bitmap_daemon_work(mddev_t *mddev)
1294 write_page(bitmap, lastpage, 0); 1261 write_page(bitmap, lastpage, 0);
1295 } else { 1262 } else {
1296 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1263 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
1264 bitmap->allclean = 0;
1297 spin_unlock_irqrestore(&bitmap->lock, flags); 1265 spin_unlock_irqrestore(&bitmap->lock, flags);
1298 } 1266 }
1299 } 1267 }
@@ -1359,8 +1327,8 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect
1359 if (bw > bitmap->behind_writes_used) 1327 if (bw > bitmap->behind_writes_used)
1360 bitmap->behind_writes_used = bw; 1328 bitmap->behind_writes_used = bw;
1361 1329
1362 PRINTK(KERN_DEBUG "inc write-behind count %d/%d\n", 1330 pr_debug("inc write-behind count %d/%lu\n",
1363 bw, bitmap->max_write_behind); 1331 bw, bitmap->mddev->bitmap_info.max_write_behind);
1364 } 1332 }
1365 1333
1366 while (sectors) { 1334 while (sectors) {
@@ -1407,7 +1375,6 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect
1407 else 1375 else
1408 sectors = 0; 1376 sectors = 0;
1409 } 1377 }
1410 bitmap->allclean = 0;
1411 return 0; 1378 return 0;
1412} 1379}
1413EXPORT_SYMBOL(bitmap_startwrite); 1380EXPORT_SYMBOL(bitmap_startwrite);
@@ -1420,8 +1387,9 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto
1420 if (behind) { 1387 if (behind) {
1421 if (atomic_dec_and_test(&bitmap->behind_writes)) 1388 if (atomic_dec_and_test(&bitmap->behind_writes))
1422 wake_up(&bitmap->behind_wait); 1389 wake_up(&bitmap->behind_wait);
1423 PRINTK(KERN_DEBUG "dec write-behind count %d/%d\n", 1390 pr_debug("dec write-behind count %d/%lu\n",
1424 atomic_read(&bitmap->behind_writes), bitmap->max_write_behind); 1391 atomic_read(&bitmap->behind_writes),
1392 bitmap->mddev->bitmap_info.max_write_behind);
1425 } 1393 }
1426 if (bitmap->mddev->degraded) 1394 if (bitmap->mddev->degraded)
1427 /* Never clear bits or update events_cleared when degraded */ 1395 /* Never clear bits or update events_cleared when degraded */
@@ -1453,13 +1421,14 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto
1453 wake_up(&bitmap->overflow_wait); 1421 wake_up(&bitmap->overflow_wait);
1454 1422
1455 (*bmc)--; 1423 (*bmc)--;
1456 if (*bmc <= 2) 1424 if (*bmc <= 2) {
1457 set_page_attr(bitmap, 1425 set_page_attr(bitmap,
1458 filemap_get_page( 1426 filemap_get_page(
1459 bitmap, 1427 bitmap,
1460 offset >> CHUNK_BLOCK_SHIFT(bitmap)), 1428 offset >> CHUNK_BLOCK_SHIFT(bitmap)),
1461 BITMAP_PAGE_CLEAN); 1429 BITMAP_PAGE_PENDING);
1462 1430 bitmap->allclean = 0;
1431 }
1463 spin_unlock_irqrestore(&bitmap->lock, flags); 1432 spin_unlock_irqrestore(&bitmap->lock, flags);
1464 offset += blocks; 1433 offset += blocks;
1465 if (sectors > blocks) 1434 if (sectors > blocks)
@@ -1495,7 +1464,6 @@ static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t
1495 } 1464 }
1496 } 1465 }
1497 spin_unlock_irq(&bitmap->lock); 1466 spin_unlock_irq(&bitmap->lock);
1498 bitmap->allclean = 0;
1499 return rv; 1467 return rv;
1500} 1468}
1501 1469
@@ -1543,15 +1511,16 @@ void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, i
1543 if (!NEEDED(*bmc) && aborted) 1511 if (!NEEDED(*bmc) && aborted)
1544 *bmc |= NEEDED_MASK; 1512 *bmc |= NEEDED_MASK;
1545 else { 1513 else {
1546 if (*bmc <= 2) 1514 if (*bmc <= 2) {
1547 set_page_attr(bitmap, 1515 set_page_attr(bitmap,
1548 filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)), 1516 filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)),
1549 BITMAP_PAGE_CLEAN); 1517 BITMAP_PAGE_PENDING);
1518 bitmap->allclean = 0;
1519 }
1550 } 1520 }
1551 } 1521 }
1552 unlock: 1522 unlock:
1553 spin_unlock_irqrestore(&bitmap->lock, flags); 1523 spin_unlock_irqrestore(&bitmap->lock, flags);
1554 bitmap->allclean = 0;
1555} 1524}
1556EXPORT_SYMBOL(bitmap_end_sync); 1525EXPORT_SYMBOL(bitmap_end_sync);
1557 1526
@@ -1622,10 +1591,10 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int n
1622 *bmc = 1 | (needed ? NEEDED_MASK : 0); 1591 *bmc = 1 | (needed ? NEEDED_MASK : 0);
1623 bitmap_count_page(bitmap, offset, 1); 1592 bitmap_count_page(bitmap, offset, 1);
1624 page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)); 1593 page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap));
1625 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); 1594 set_page_attr(bitmap, page, BITMAP_PAGE_PENDING);
1595 bitmap->allclean = 0;
1626 } 1596 }
1627 spin_unlock_irq(&bitmap->lock); 1597 spin_unlock_irq(&bitmap->lock);
1628 bitmap->allclean = 0;
1629} 1598}
1630 1599
1631/* dirty the memory and file bits for bitmap chunks "s" to "e" */ 1600/* dirty the memory and file bits for bitmap chunks "s" to "e" */
@@ -1649,7 +1618,7 @@ void bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e)
1649/* 1618/*
1650 * flush out any pending updates 1619 * flush out any pending updates
1651 */ 1620 */
1652void bitmap_flush(mddev_t *mddev) 1621void bitmap_flush(struct mddev *mddev)
1653{ 1622{
1654 struct bitmap *bitmap = mddev->bitmap; 1623 struct bitmap *bitmap = mddev->bitmap;
1655 long sleep; 1624 long sleep;
@@ -1697,7 +1666,7 @@ static void bitmap_free(struct bitmap *bitmap)
1697 kfree(bitmap); 1666 kfree(bitmap);
1698} 1667}
1699 1668
1700void bitmap_destroy(mddev_t *mddev) 1669void bitmap_destroy(struct mddev *mddev)
1701{ 1670{
1702 struct bitmap *bitmap = mddev->bitmap; 1671 struct bitmap *bitmap = mddev->bitmap;
1703 1672
@@ -1720,7 +1689,7 @@ void bitmap_destroy(mddev_t *mddev)
1720 * initialize the bitmap structure 1689 * initialize the bitmap structure
1721 * if this returns an error, bitmap_destroy must be called to do clean up 1690 * if this returns an error, bitmap_destroy must be called to do clean up
1722 */ 1691 */
1723int bitmap_create(mddev_t *mddev) 1692int bitmap_create(struct mddev *mddev)
1724{ 1693{
1725 struct bitmap *bitmap; 1694 struct bitmap *bitmap;
1726 sector_t blocks = mddev->resync_max_sectors; 1695 sector_t blocks = mddev->resync_max_sectors;
@@ -1802,11 +1771,8 @@ int bitmap_create(mddev_t *mddev)
1802 bitmap->pages = pages; 1771 bitmap->pages = pages;
1803 bitmap->missing_pages = pages; 1772 bitmap->missing_pages = pages;
1804 1773
1805#ifdef INJECT_FATAL_FAULT_1
1806 bitmap->bp = NULL;
1807#else
1808 bitmap->bp = kzalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL); 1774 bitmap->bp = kzalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL);
1809#endif 1775
1810 err = -ENOMEM; 1776 err = -ENOMEM;
1811 if (!bitmap->bp) 1777 if (!bitmap->bp)
1812 goto error; 1778 goto error;
@@ -1824,7 +1790,7 @@ int bitmap_create(mddev_t *mddev)
1824 return err; 1790 return err;
1825} 1791}
1826 1792
1827int bitmap_load(mddev_t *mddev) 1793int bitmap_load(struct mddev *mddev)
1828{ 1794{
1829 int err = 0; 1795 int err = 0;
1830 sector_t start = 0; 1796 sector_t start = 0;
@@ -1870,7 +1836,7 @@ out:
1870EXPORT_SYMBOL_GPL(bitmap_load); 1836EXPORT_SYMBOL_GPL(bitmap_load);
1871 1837
1872static ssize_t 1838static ssize_t
1873location_show(mddev_t *mddev, char *page) 1839location_show(struct mddev *mddev, char *page)
1874{ 1840{
1875 ssize_t len; 1841 ssize_t len;
1876 if (mddev->bitmap_info.file) 1842 if (mddev->bitmap_info.file)
@@ -1884,7 +1850,7 @@ location_show(mddev_t *mddev, char *page)
1884} 1850}
1885 1851
1886static ssize_t 1852static ssize_t
1887location_store(mddev_t *mddev, const char *buf, size_t len) 1853location_store(struct mddev *mddev, const char *buf, size_t len)
1888{ 1854{
1889 1855
1890 if (mddev->pers) { 1856 if (mddev->pers) {
@@ -1961,7 +1927,7 @@ static struct md_sysfs_entry bitmap_location =
1961__ATTR(location, S_IRUGO|S_IWUSR, location_show, location_store); 1927__ATTR(location, S_IRUGO|S_IWUSR, location_show, location_store);
1962 1928
1963static ssize_t 1929static ssize_t
1964timeout_show(mddev_t *mddev, char *page) 1930timeout_show(struct mddev *mddev, char *page)
1965{ 1931{
1966 ssize_t len; 1932 ssize_t len;
1967 unsigned long secs = mddev->bitmap_info.daemon_sleep / HZ; 1933 unsigned long secs = mddev->bitmap_info.daemon_sleep / HZ;
@@ -1975,7 +1941,7 @@ timeout_show(mddev_t *mddev, char *page)
1975} 1941}
1976 1942
1977static ssize_t 1943static ssize_t
1978timeout_store(mddev_t *mddev, const char *buf, size_t len) 1944timeout_store(struct mddev *mddev, const char *buf, size_t len)
1979{ 1945{
1980 /* timeout can be set at any time */ 1946 /* timeout can be set at any time */
1981 unsigned long timeout; 1947 unsigned long timeout;
@@ -2011,13 +1977,13 @@ static struct md_sysfs_entry bitmap_timeout =
2011__ATTR(time_base, S_IRUGO|S_IWUSR, timeout_show, timeout_store); 1977__ATTR(time_base, S_IRUGO|S_IWUSR, timeout_show, timeout_store);
2012 1978
2013static ssize_t 1979static ssize_t
2014backlog_show(mddev_t *mddev, char *page) 1980backlog_show(struct mddev *mddev, char *page)
2015{ 1981{
2016 return sprintf(page, "%lu\n", mddev->bitmap_info.max_write_behind); 1982 return sprintf(page, "%lu\n", mddev->bitmap_info.max_write_behind);
2017} 1983}
2018 1984
2019static ssize_t 1985static ssize_t
2020backlog_store(mddev_t *mddev, const char *buf, size_t len) 1986backlog_store(struct mddev *mddev, const char *buf, size_t len)
2021{ 1987{
2022 unsigned long backlog; 1988 unsigned long backlog;
2023 int rv = strict_strtoul(buf, 10, &backlog); 1989 int rv = strict_strtoul(buf, 10, &backlog);
@@ -2033,13 +1999,13 @@ static struct md_sysfs_entry bitmap_backlog =
2033__ATTR(backlog, S_IRUGO|S_IWUSR, backlog_show, backlog_store); 1999__ATTR(backlog, S_IRUGO|S_IWUSR, backlog_show, backlog_store);
2034 2000
2035static ssize_t 2001static ssize_t
2036chunksize_show(mddev_t *mddev, char *page) 2002chunksize_show(struct mddev *mddev, char *page)
2037{ 2003{
2038 return sprintf(page, "%lu\n", mddev->bitmap_info.chunksize); 2004 return sprintf(page, "%lu\n", mddev->bitmap_info.chunksize);
2039} 2005}
2040 2006
2041static ssize_t 2007static ssize_t
2042chunksize_store(mddev_t *mddev, const char *buf, size_t len) 2008chunksize_store(struct mddev *mddev, const char *buf, size_t len)
2043{ 2009{
2044 /* Can only be changed when no bitmap is active */ 2010 /* Can only be changed when no bitmap is active */
2045 int rv; 2011 int rv;
@@ -2059,13 +2025,13 @@ chunksize_store(mddev_t *mddev, const char *buf, size_t len)
2059static struct md_sysfs_entry bitmap_chunksize = 2025static struct md_sysfs_entry bitmap_chunksize =
2060__ATTR(chunksize, S_IRUGO|S_IWUSR, chunksize_show, chunksize_store); 2026__ATTR(chunksize, S_IRUGO|S_IWUSR, chunksize_show, chunksize_store);
2061 2027
2062static ssize_t metadata_show(mddev_t *mddev, char *page) 2028static ssize_t metadata_show(struct mddev *mddev, char *page)
2063{ 2029{
2064 return sprintf(page, "%s\n", (mddev->bitmap_info.external 2030 return sprintf(page, "%s\n", (mddev->bitmap_info.external
2065 ? "external" : "internal")); 2031 ? "external" : "internal"));
2066} 2032}
2067 2033
2068static ssize_t metadata_store(mddev_t *mddev, const char *buf, size_t len) 2034static ssize_t metadata_store(struct mddev *mddev, const char *buf, size_t len)
2069{ 2035{
2070 if (mddev->bitmap || 2036 if (mddev->bitmap ||
2071 mddev->bitmap_info.file || 2037 mddev->bitmap_info.file ||
@@ -2083,7 +2049,7 @@ static ssize_t metadata_store(mddev_t *mddev, const char *buf, size_t len)
2083static struct md_sysfs_entry bitmap_metadata = 2049static struct md_sysfs_entry bitmap_metadata =
2084__ATTR(metadata, S_IRUGO|S_IWUSR, metadata_show, metadata_store); 2050__ATTR(metadata, S_IRUGO|S_IWUSR, metadata_show, metadata_store);
2085 2051
2086static ssize_t can_clear_show(mddev_t *mddev, char *page) 2052static ssize_t can_clear_show(struct mddev *mddev, char *page)
2087{ 2053{
2088 int len; 2054 int len;
2089 if (mddev->bitmap) 2055 if (mddev->bitmap)
@@ -2094,7 +2060,7 @@ static ssize_t can_clear_show(mddev_t *mddev, char *page)
2094 return len; 2060 return len;
2095} 2061}
2096 2062
2097static ssize_t can_clear_store(mddev_t *mddev, const char *buf, size_t len) 2063static ssize_t can_clear_store(struct mddev *mddev, const char *buf, size_t len)
2098{ 2064{
2099 if (mddev->bitmap == NULL) 2065 if (mddev->bitmap == NULL)
2100 return -ENOENT; 2066 return -ENOENT;
@@ -2113,7 +2079,7 @@ static struct md_sysfs_entry bitmap_can_clear =
2113__ATTR(can_clear, S_IRUGO|S_IWUSR, can_clear_show, can_clear_store); 2079__ATTR(can_clear, S_IRUGO|S_IWUSR, can_clear_show, can_clear_store);
2114 2080
2115static ssize_t 2081static ssize_t
2116behind_writes_used_show(mddev_t *mddev, char *page) 2082behind_writes_used_show(struct mddev *mddev, char *page)
2117{ 2083{
2118 if (mddev->bitmap == NULL) 2084 if (mddev->bitmap == NULL)
2119 return sprintf(page, "0\n"); 2085 return sprintf(page, "0\n");
@@ -2122,7 +2088,7 @@ behind_writes_used_show(mddev_t *mddev, char *page)
2122} 2088}
2123 2089
2124static ssize_t 2090static ssize_t
2125behind_writes_used_reset(mddev_t *mddev, const char *buf, size_t len) 2091behind_writes_used_reset(struct mddev *mddev, const char *buf, size_t len)
2126{ 2092{
2127 if (mddev->bitmap) 2093 if (mddev->bitmap)
2128 mddev->bitmap->behind_writes_used = 0; 2094 mddev->bitmap->behind_writes_used = 0;