diff options
Diffstat (limited to 'drivers/md/bitmap.c')
| -rw-r--r-- | drivers/md/bitmap.c | 183 |
1 files changed, 108 insertions, 75 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c index 41df4cda66e2..2fba2bbe72d8 100644 --- a/drivers/md/bitmap.c +++ b/drivers/md/bitmap.c | |||
| @@ -270,19 +270,20 @@ static struct page *read_sb_page(mddev_t *mddev, long offset, unsigned long inde | |||
| 270 | 270 | ||
| 271 | if (!page) | 271 | if (!page) |
| 272 | return ERR_PTR(-ENOMEM); | 272 | return ERR_PTR(-ENOMEM); |
| 273 | do { | ||
| 274 | ITERATE_RDEV(mddev, rdev, tmp) | ||
| 275 | if (rdev->in_sync && !rdev->faulty) | ||
| 276 | goto found; | ||
| 277 | return ERR_PTR(-EIO); | ||
| 278 | 273 | ||
| 279 | found: | 274 | ITERATE_RDEV(mddev, rdev, tmp) { |
| 275 | if (! rdev->in_sync || rdev->faulty) | ||
| 276 | continue; | ||
| 277 | |||
| 280 | target = (rdev->sb_offset << 1) + offset + index * (PAGE_SIZE/512); | 278 | target = (rdev->sb_offset << 1) + offset + index * (PAGE_SIZE/512); |
| 281 | 279 | ||
| 282 | } while (!sync_page_io(rdev->bdev, target, PAGE_SIZE, page, READ)); | 280 | if (sync_page_io(rdev->bdev, target, PAGE_SIZE, page, READ)) { |
| 281 | page->index = index; | ||
| 282 | return page; | ||
| 283 | } | ||
| 284 | } | ||
| 285 | return ERR_PTR(-EIO); | ||
| 283 | 286 | ||
| 284 | page->index = index; | ||
| 285 | return page; | ||
| 286 | } | 287 | } |
| 287 | 288 | ||
| 288 | static int write_sb_page(mddev_t *mddev, long offset, struct page *page, int wait) | 289 | static int write_sb_page(mddev_t *mddev, long offset, struct page *page, int wait) |
| @@ -437,6 +438,7 @@ void bitmap_print_sb(struct bitmap *bitmap) | |||
| 437 | printk(KERN_DEBUG " daemon sleep: %ds\n", le32_to_cpu(sb->daemon_sleep)); | 438 | printk(KERN_DEBUG " daemon sleep: %ds\n", le32_to_cpu(sb->daemon_sleep)); |
| 438 | printk(KERN_DEBUG " sync size: %llu KB\n", | 439 | printk(KERN_DEBUG " sync size: %llu KB\n", |
| 439 | (unsigned long long)le64_to_cpu(sb->sync_size)/2); | 440 | (unsigned long long)le64_to_cpu(sb->sync_size)/2); |
| 441 | printk(KERN_DEBUG "max write behind: %d\n", le32_to_cpu(sb->write_behind)); | ||
| 440 | kunmap(bitmap->sb_page); | 442 | kunmap(bitmap->sb_page); |
| 441 | } | 443 | } |
| 442 | 444 | ||
| @@ -445,7 +447,7 @@ static int bitmap_read_sb(struct bitmap *bitmap) | |||
| 445 | { | 447 | { |
| 446 | char *reason = NULL; | 448 | char *reason = NULL; |
| 447 | bitmap_super_t *sb; | 449 | bitmap_super_t *sb; |
| 448 | unsigned long chunksize, daemon_sleep; | 450 | unsigned long chunksize, daemon_sleep, write_behind; |
| 449 | unsigned long bytes_read; | 451 | unsigned long bytes_read; |
| 450 | unsigned long long events; | 452 | unsigned long long events; |
| 451 | int err = -EINVAL; | 453 | int err = -EINVAL; |
| @@ -474,6 +476,7 @@ static int bitmap_read_sb(struct bitmap *bitmap) | |||
| 474 | 476 | ||
| 475 | chunksize = le32_to_cpu(sb->chunksize); | 477 | chunksize = le32_to_cpu(sb->chunksize); |
| 476 | daemon_sleep = le32_to_cpu(sb->daemon_sleep); | 478 | daemon_sleep = le32_to_cpu(sb->daemon_sleep); |
| 479 | write_behind = le32_to_cpu(sb->write_behind); | ||
| 477 | 480 | ||
| 478 | /* verify that the bitmap-specific fields are valid */ | 481 | /* verify that the bitmap-specific fields are valid */ |
| 479 | if (sb->magic != cpu_to_le32(BITMAP_MAGIC)) | 482 | if (sb->magic != cpu_to_le32(BITMAP_MAGIC)) |
| @@ -485,7 +488,9 @@ static int bitmap_read_sb(struct bitmap *bitmap) | |||
| 485 | else if ((1 << ffz(~chunksize)) != chunksize) | 488 | else if ((1 << ffz(~chunksize)) != chunksize) |
| 486 | reason = "bitmap chunksize not a power of 2"; | 489 | reason = "bitmap chunksize not a power of 2"; |
| 487 | else if (daemon_sleep < 1 || daemon_sleep > 15) | 490 | else if (daemon_sleep < 1 || daemon_sleep > 15) |
| 488 | reason = "daemon sleep period out of range"; | 491 | reason = "daemon sleep period out of range (1-15s)"; |
| 492 | else if (write_behind > COUNTER_MAX) | ||
| 493 | reason = "write-behind limit out of range (0 - 16383)"; | ||
| 489 | if (reason) { | 494 | if (reason) { |
| 490 | printk(KERN_INFO "%s: invalid bitmap file superblock: %s\n", | 495 | printk(KERN_INFO "%s: invalid bitmap file superblock: %s\n", |
| 491 | bmname(bitmap), reason); | 496 | bmname(bitmap), reason); |
| @@ -518,8 +523,12 @@ success: | |||
| 518 | /* assign fields using values from superblock */ | 523 | /* assign fields using values from superblock */ |
| 519 | bitmap->chunksize = chunksize; | 524 | bitmap->chunksize = chunksize; |
| 520 | bitmap->daemon_sleep = daemon_sleep; | 525 | bitmap->daemon_sleep = daemon_sleep; |
| 526 | bitmap->daemon_lastrun = jiffies; | ||
| 527 | bitmap->max_write_behind = write_behind; | ||
| 521 | bitmap->flags |= sb->state; | 528 | bitmap->flags |= sb->state; |
| 522 | bitmap->events_cleared = le64_to_cpu(sb->events_cleared); | 529 | bitmap->events_cleared = le64_to_cpu(sb->events_cleared); |
| 530 | if (sb->state & BITMAP_STALE) | ||
| 531 | bitmap->events_cleared = bitmap->mddev->events; | ||
| 523 | err = 0; | 532 | err = 0; |
| 524 | out: | 533 | out: |
| 525 | kunmap(bitmap->sb_page); | 534 | kunmap(bitmap->sb_page); |
| @@ -617,7 +626,7 @@ static void bitmap_file_unmap(struct bitmap *bitmap) | |||
| 617 | page_cache_release(sb_page); | 626 | page_cache_release(sb_page); |
| 618 | } | 627 | } |
| 619 | 628 | ||
| 620 | static void bitmap_stop_daemons(struct bitmap *bitmap); | 629 | static void bitmap_stop_daemon(struct bitmap *bitmap); |
| 621 | 630 | ||
| 622 | /* dequeue the next item in a page list -- don't call from irq context */ | 631 | /* dequeue the next item in a page list -- don't call from irq context */ |
| 623 | static struct page_list *dequeue_page(struct bitmap *bitmap) | 632 | static struct page_list *dequeue_page(struct bitmap *bitmap) |
| @@ -659,7 +668,7 @@ static void bitmap_file_put(struct bitmap *bitmap) | |||
| 659 | bitmap->file = NULL; | 668 | bitmap->file = NULL; |
| 660 | spin_unlock_irqrestore(&bitmap->lock, flags); | 669 | spin_unlock_irqrestore(&bitmap->lock, flags); |
| 661 | 670 | ||
| 662 | bitmap_stop_daemons(bitmap); | 671 | bitmap_stop_daemon(bitmap); |
| 663 | 672 | ||
| 664 | drain_write_queues(bitmap); | 673 | drain_write_queues(bitmap); |
| 665 | 674 | ||
| @@ -818,7 +827,7 @@ int bitmap_unplug(struct bitmap *bitmap) | |||
| 818 | return 0; | 827 | return 0; |
| 819 | } | 828 | } |
| 820 | 829 | ||
| 821 | static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset); | 830 | static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed); |
| 822 | /* * bitmap_init_from_disk -- called at bitmap_create time to initialize | 831 | /* * bitmap_init_from_disk -- called at bitmap_create time to initialize |
| 823 | * the in-memory bitmap from the on-disk bitmap -- also, sets up the | 832 | * the in-memory bitmap from the on-disk bitmap -- also, sets up the |
| 824 | * memory mapping of the bitmap file | 833 | * memory mapping of the bitmap file |
| @@ -826,8 +835,11 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset); | |||
| 826 | * if there's no bitmap file, or if the bitmap file had been | 835 | * if there's no bitmap file, or if the bitmap file had been |
| 827 | * previously kicked from the array, we mark all the bits as | 836 | * previously kicked from the array, we mark all the bits as |
| 828 | * 1's in order to cause a full resync. | 837 | * 1's in order to cause a full resync. |
| 838 | * | ||
| 839 | * We ignore all bits for sectors that end earlier than 'start'. | ||
| 840 | * This is used when reading an out-of-date bitmap... | ||
| 829 | */ | 841 | */ |
| 830 | static int bitmap_init_from_disk(struct bitmap *bitmap) | 842 | static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) |
| 831 | { | 843 | { |
| 832 | unsigned long i, chunks, index, oldindex, bit; | 844 | unsigned long i, chunks, index, oldindex, bit; |
| 833 | struct page *page = NULL, *oldpage = NULL; | 845 | struct page *page = NULL, *oldpage = NULL; |
| @@ -914,7 +926,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap) | |||
| 914 | * whole page and write it out | 926 | * whole page and write it out |
| 915 | */ | 927 | */ |
| 916 | memset(page_address(page) + offset, 0xff, | 928 | memset(page_address(page) + offset, 0xff, |
| 917 | PAGE_SIZE - offset); | 929 | PAGE_SIZE - offset); |
| 918 | ret = write_page(bitmap, page, 1); | 930 | ret = write_page(bitmap, page, 1); |
| 919 | if (ret) { | 931 | if (ret) { |
| 920 | kunmap(page); | 932 | kunmap(page); |
| @@ -928,8 +940,11 @@ static int bitmap_init_from_disk(struct bitmap *bitmap) | |||
| 928 | } | 940 | } |
| 929 | if (test_bit(bit, page_address(page))) { | 941 | if (test_bit(bit, page_address(page))) { |
| 930 | /* if the disk bit is set, set the memory bit */ | 942 | /* if the disk bit is set, set the memory bit */ |
| 931 | bitmap_set_memory_bits(bitmap, i << CHUNK_BLOCK_SHIFT(bitmap)); | 943 | bitmap_set_memory_bits(bitmap, i << CHUNK_BLOCK_SHIFT(bitmap), |
| 944 | ((i+1) << (CHUNK_BLOCK_SHIFT(bitmap)) >= start) | ||
| 945 | ); | ||
| 932 | bit_cnt++; | 946 | bit_cnt++; |
| 947 | set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); | ||
| 933 | } | 948 | } |
| 934 | } | 949 | } |
| 935 | 950 | ||
| @@ -1141,6 +1156,9 @@ static void bitmap_writeback_daemon(mddev_t *mddev) | |||
| 1141 | err = -EINTR; | 1156 | err = -EINTR; |
| 1142 | goto out; | 1157 | goto out; |
| 1143 | } | 1158 | } |
| 1159 | if (bitmap == NULL) | ||
| 1160 | /* about to be stopped. */ | ||
| 1161 | return; | ||
| 1144 | 1162 | ||
| 1145 | PRINTK("%s: bitmap writeback daemon woke up...\n", bmname(bitmap)); | 1163 | PRINTK("%s: bitmap writeback daemon woke up...\n", bmname(bitmap)); |
| 1146 | /* wait on bitmap page writebacks */ | 1164 | /* wait on bitmap page writebacks */ |
| @@ -1170,21 +1188,12 @@ static void bitmap_writeback_daemon(mddev_t *mddev) | |||
| 1170 | } | 1188 | } |
| 1171 | } | 1189 | } |
| 1172 | 1190 | ||
| 1173 | static int bitmap_start_daemon(struct bitmap *bitmap, mdk_thread_t **ptr, | 1191 | static mdk_thread_t *bitmap_start_daemon(struct bitmap *bitmap, |
| 1174 | void (*func)(mddev_t *), char *name) | 1192 | void (*func)(mddev_t *), char *name) |
| 1175 | { | 1193 | { |
| 1176 | mdk_thread_t *daemon; | 1194 | mdk_thread_t *daemon; |
| 1177 | unsigned long flags; | ||
| 1178 | char namebuf[32]; | 1195 | char namebuf[32]; |
| 1179 | 1196 | ||
| 1180 | spin_lock_irqsave(&bitmap->lock, flags); | ||
| 1181 | *ptr = NULL; | ||
| 1182 | |||
| 1183 | if (!bitmap->file) /* no need for daemon if there's no backing file */ | ||
| 1184 | goto out_unlock; | ||
| 1185 | |||
| 1186 | spin_unlock_irqrestore(&bitmap->lock, flags); | ||
| 1187 | |||
| 1188 | #ifdef INJECT_FATAL_FAULT_2 | 1197 | #ifdef INJECT_FATAL_FAULT_2 |
| 1189 | daemon = NULL; | 1198 | daemon = NULL; |
| 1190 | #else | 1199 | #else |
| @@ -1194,47 +1203,32 @@ static int bitmap_start_daemon(struct bitmap *bitmap, mdk_thread_t **ptr, | |||
| 1194 | if (!daemon) { | 1203 | if (!daemon) { |
| 1195 | printk(KERN_ERR "%s: failed to start bitmap daemon\n", | 1204 | printk(KERN_ERR "%s: failed to start bitmap daemon\n", |
| 1196 | bmname(bitmap)); | 1205 | bmname(bitmap)); |
| 1197 | return -ECHILD; | 1206 | return ERR_PTR(-ECHILD); |
| 1198 | } | 1207 | } |
| 1199 | 1208 | ||
| 1200 | spin_lock_irqsave(&bitmap->lock, flags); | ||
| 1201 | *ptr = daemon; | ||
| 1202 | |||
| 1203 | md_wakeup_thread(daemon); /* start it running */ | 1209 | md_wakeup_thread(daemon); /* start it running */ |
| 1204 | 1210 | ||
| 1205 | PRINTK("%s: %s daemon (pid %d) started...\n", | 1211 | PRINTK("%s: %s daemon (pid %d) started...\n", |
| 1206 | bmname(bitmap), name, daemon->tsk->pid); | 1212 | bmname(bitmap), name, daemon->tsk->pid); |
| 1207 | out_unlock: | ||
| 1208 | spin_unlock_irqrestore(&bitmap->lock, flags); | ||
| 1209 | return 0; | ||
| 1210 | } | ||
| 1211 | 1213 | ||
| 1212 | static int bitmap_start_daemons(struct bitmap *bitmap) | 1214 | return daemon; |
| 1213 | { | ||
| 1214 | int err = bitmap_start_daemon(bitmap, &bitmap->writeback_daemon, | ||
| 1215 | bitmap_writeback_daemon, "bitmap_wb"); | ||
| 1216 | return err; | ||
| 1217 | } | 1215 | } |
| 1218 | 1216 | ||
| 1219 | static void bitmap_stop_daemon(struct bitmap *bitmap, mdk_thread_t **ptr) | 1217 | static void bitmap_stop_daemon(struct bitmap *bitmap) |
| 1220 | { | 1218 | { |
| 1221 | mdk_thread_t *daemon; | 1219 | /* the daemon can't stop itself... it'll just exit instead... */ |
| 1222 | unsigned long flags; | 1220 | if (bitmap->writeback_daemon && ! IS_ERR(bitmap->writeback_daemon) && |
| 1223 | 1221 | current->pid != bitmap->writeback_daemon->tsk->pid) { | |
| 1224 | spin_lock_irqsave(&bitmap->lock, flags); | 1222 | mdk_thread_t *daemon; |
| 1225 | daemon = *ptr; | 1223 | unsigned long flags; |
| 1226 | *ptr = NULL; | ||
| 1227 | spin_unlock_irqrestore(&bitmap->lock, flags); | ||
| 1228 | if (daemon) | ||
| 1229 | md_unregister_thread(daemon); /* destroy the thread */ | ||
| 1230 | } | ||
| 1231 | 1224 | ||
| 1232 | static void bitmap_stop_daemons(struct bitmap *bitmap) | 1225 | spin_lock_irqsave(&bitmap->lock, flags); |
| 1233 | { | 1226 | daemon = bitmap->writeback_daemon; |
| 1234 | /* the daemons can't stop themselves... they'll just exit instead... */ | 1227 | bitmap->writeback_daemon = NULL; |
| 1235 | if (bitmap->writeback_daemon && | 1228 | spin_unlock_irqrestore(&bitmap->lock, flags); |
| 1236 | current->pid != bitmap->writeback_daemon->tsk->pid) | 1229 | if (daemon && ! IS_ERR(daemon)) |
| 1237 | bitmap_stop_daemon(bitmap, &bitmap->writeback_daemon); | 1230 | md_unregister_thread(daemon); /* destroy the thread */ |
| 1231 | } | ||
| 1238 | } | 1232 | } |
| 1239 | 1233 | ||
| 1240 | static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, | 1234 | static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, |
| @@ -1274,9 +1268,16 @@ static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, | |||
| 1274 | } | 1268 | } |
| 1275 | } | 1269 | } |
| 1276 | 1270 | ||
| 1277 | int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors) | 1271 | int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind) |
| 1278 | { | 1272 | { |
| 1279 | if (!bitmap) return 0; | 1273 | if (!bitmap) return 0; |
| 1274 | |||
| 1275 | if (behind) { | ||
| 1276 | atomic_inc(&bitmap->behind_writes); | ||
| 1277 | PRINTK(KERN_DEBUG "inc write-behind count %d/%d\n", | ||
| 1278 | atomic_read(&bitmap->behind_writes), bitmap->max_write_behind); | ||
| 1279 | } | ||
| 1280 | |||
| 1280 | while (sectors) { | 1281 | while (sectors) { |
| 1281 | int blocks; | 1282 | int blocks; |
| 1282 | bitmap_counter_t *bmc; | 1283 | bitmap_counter_t *bmc; |
| @@ -1311,9 +1312,15 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect | |||
| 1311 | } | 1312 | } |
| 1312 | 1313 | ||
| 1313 | void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, | 1314 | void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, |
| 1314 | int success) | 1315 | int success, int behind) |
| 1315 | { | 1316 | { |
| 1316 | if (!bitmap) return; | 1317 | if (!bitmap) return; |
| 1318 | if (behind) { | ||
| 1319 | atomic_dec(&bitmap->behind_writes); | ||
| 1320 | PRINTK(KERN_DEBUG "dec write-behind count %d/%d\n", | ||
| 1321 | atomic_read(&bitmap->behind_writes), bitmap->max_write_behind); | ||
| 1322 | } | ||
| 1323 | |||
| 1317 | while (sectors) { | 1324 | while (sectors) { |
| 1318 | int blocks; | 1325 | int blocks; |
| 1319 | unsigned long flags; | 1326 | unsigned long flags; |
| @@ -1424,7 +1431,7 @@ void bitmap_close_sync(struct bitmap *bitmap) | |||
| 1424 | } | 1431 | } |
| 1425 | } | 1432 | } |
| 1426 | 1433 | ||
| 1427 | static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset) | 1434 | static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed) |
| 1428 | { | 1435 | { |
| 1429 | /* For each chunk covered by any of these sectors, set the | 1436 | /* For each chunk covered by any of these sectors, set the |
| 1430 | * counter to 1 and set resync_needed. They should all | 1437 | * counter to 1 and set resync_needed. They should all |
| @@ -1441,7 +1448,7 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset) | |||
| 1441 | } | 1448 | } |
| 1442 | if (! *bmc) { | 1449 | if (! *bmc) { |
| 1443 | struct page *page; | 1450 | struct page *page; |
| 1444 | *bmc = 1 | NEEDED_MASK; | 1451 | *bmc = 1 | (needed?NEEDED_MASK:0); |
| 1445 | bitmap_count_page(bitmap, offset, 1); | 1452 | bitmap_count_page(bitmap, offset, 1); |
| 1446 | page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)); | 1453 | page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)); |
| 1447 | set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); | 1454 | set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); |
| @@ -1476,17 +1483,14 @@ void bitmap_flush(mddev_t *mddev) | |||
| 1476 | /* | 1483 | /* |
| 1477 | * free memory that was allocated | 1484 | * free memory that was allocated |
| 1478 | */ | 1485 | */ |
| 1479 | void bitmap_destroy(mddev_t *mddev) | 1486 | static void bitmap_free(struct bitmap *bitmap) |
| 1480 | { | 1487 | { |
| 1481 | unsigned long k, pages; | 1488 | unsigned long k, pages; |
| 1482 | struct bitmap_page *bp; | 1489 | struct bitmap_page *bp; |
| 1483 | struct bitmap *bitmap = mddev->bitmap; | ||
| 1484 | 1490 | ||
| 1485 | if (!bitmap) /* there was no bitmap */ | 1491 | if (!bitmap) /* there was no bitmap */ |
| 1486 | return; | 1492 | return; |
| 1487 | 1493 | ||
| 1488 | mddev->bitmap = NULL; /* disconnect from the md device */ | ||
| 1489 | |||
| 1490 | /* release the bitmap file and kill the daemon */ | 1494 | /* release the bitmap file and kill the daemon */ |
| 1491 | bitmap_file_put(bitmap); | 1495 | bitmap_file_put(bitmap); |
| 1492 | 1496 | ||
| @@ -1504,6 +1508,17 @@ void bitmap_destroy(mddev_t *mddev) | |||
| 1504 | kfree(bp); | 1508 | kfree(bp); |
| 1505 | kfree(bitmap); | 1509 | kfree(bitmap); |
| 1506 | } | 1510 | } |
| 1511 | void bitmap_destroy(mddev_t *mddev) | ||
| 1512 | { | ||
| 1513 | struct bitmap *bitmap = mddev->bitmap; | ||
| 1514 | |||
| 1515 | if (!bitmap) /* there was no bitmap */ | ||
| 1516 | return; | ||
| 1517 | |||
| 1518 | mddev->bitmap = NULL; /* disconnect from the md device */ | ||
| 1519 | |||
| 1520 | bitmap_free(bitmap); | ||
| 1521 | } | ||
| 1507 | 1522 | ||
| 1508 | /* | 1523 | /* |
| 1509 | * initialize the bitmap structure | 1524 | * initialize the bitmap structure |
| @@ -1517,6 +1532,7 @@ int bitmap_create(mddev_t *mddev) | |||
| 1517 | unsigned long pages; | 1532 | unsigned long pages; |
| 1518 | struct file *file = mddev->bitmap_file; | 1533 | struct file *file = mddev->bitmap_file; |
| 1519 | int err; | 1534 | int err; |
| 1535 | sector_t start; | ||
| 1520 | 1536 | ||
| 1521 | BUG_ON(sizeof(bitmap_super_t) != 256); | 1537 | BUG_ON(sizeof(bitmap_super_t) != 256); |
| 1522 | 1538 | ||
| @@ -1533,15 +1549,15 @@ int bitmap_create(mddev_t *mddev) | |||
| 1533 | 1549 | ||
| 1534 | spin_lock_init(&bitmap->lock); | 1550 | spin_lock_init(&bitmap->lock); |
| 1535 | bitmap->mddev = mddev; | 1551 | bitmap->mddev = mddev; |
| 1536 | mddev->bitmap = bitmap; | ||
| 1537 | 1552 | ||
| 1538 | spin_lock_init(&bitmap->write_lock); | 1553 | spin_lock_init(&bitmap->write_lock); |
| 1539 | INIT_LIST_HEAD(&bitmap->complete_pages); | 1554 | INIT_LIST_HEAD(&bitmap->complete_pages); |
| 1540 | init_waitqueue_head(&bitmap->write_wait); | 1555 | init_waitqueue_head(&bitmap->write_wait); |
| 1541 | bitmap->write_pool = mempool_create(WRITE_POOL_SIZE, write_pool_alloc, | 1556 | bitmap->write_pool = mempool_create(WRITE_POOL_SIZE, write_pool_alloc, |
| 1542 | write_pool_free, NULL); | 1557 | write_pool_free, NULL); |
| 1558 | err = -ENOMEM; | ||
| 1543 | if (!bitmap->write_pool) | 1559 | if (!bitmap->write_pool) |
| 1544 | return -ENOMEM; | 1560 | goto error; |
| 1545 | 1561 | ||
| 1546 | bitmap->file = file; | 1562 | bitmap->file = file; |
| 1547 | bitmap->offset = mddev->bitmap_offset; | 1563 | bitmap->offset = mddev->bitmap_offset; |
| @@ -1549,7 +1565,7 @@ int bitmap_create(mddev_t *mddev) | |||
| 1549 | /* read superblock from bitmap file (this sets bitmap->chunksize) */ | 1565 | /* read superblock from bitmap file (this sets bitmap->chunksize) */ |
| 1550 | err = bitmap_read_sb(bitmap); | 1566 | err = bitmap_read_sb(bitmap); |
| 1551 | if (err) | 1567 | if (err) |
| 1552 | return err; | 1568 | goto error; |
| 1553 | 1569 | ||
| 1554 | bitmap->chunkshift = find_first_bit(&bitmap->chunksize, | 1570 | bitmap->chunkshift = find_first_bit(&bitmap->chunksize, |
| 1555 | sizeof(bitmap->chunksize)); | 1571 | sizeof(bitmap->chunksize)); |
| @@ -1573,27 +1589,44 @@ int bitmap_create(mddev_t *mddev) | |||
| 1573 | #else | 1589 | #else |
| 1574 | bitmap->bp = kmalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL); | 1590 | bitmap->bp = kmalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL); |
| 1575 | #endif | 1591 | #endif |
| 1592 | err = -ENOMEM; | ||
| 1576 | if (!bitmap->bp) | 1593 | if (!bitmap->bp) |
| 1577 | return -ENOMEM; | 1594 | goto error; |
| 1578 | memset(bitmap->bp, 0, pages * sizeof(*bitmap->bp)); | 1595 | memset(bitmap->bp, 0, pages * sizeof(*bitmap->bp)); |
| 1579 | 1596 | ||
| 1580 | bitmap->flags |= BITMAP_ACTIVE; | 1597 | bitmap->flags |= BITMAP_ACTIVE; |
| 1581 | 1598 | ||
| 1582 | /* now that we have some pages available, initialize the in-memory | 1599 | /* now that we have some pages available, initialize the in-memory |
| 1583 | * bitmap from the on-disk bitmap */ | 1600 | * bitmap from the on-disk bitmap */ |
| 1584 | err = bitmap_init_from_disk(bitmap); | 1601 | start = 0; |
| 1602 | if (mddev->degraded == 0 | ||
| 1603 | || bitmap->events_cleared == mddev->events) | ||
| 1604 | /* no need to keep dirty bits to optimise a re-add of a missing device */ | ||
| 1605 | start = mddev->recovery_cp; | ||
| 1606 | err = bitmap_init_from_disk(bitmap, start); | ||
| 1585 | 1607 | ||
| 1586 | if (err) | 1608 | if (err) |
| 1587 | return err; | 1609 | goto error; |
| 1588 | 1610 | ||
| 1589 | printk(KERN_INFO "created bitmap (%lu pages) for device %s\n", | 1611 | printk(KERN_INFO "created bitmap (%lu pages) for device %s\n", |
| 1590 | pages, bmname(bitmap)); | 1612 | pages, bmname(bitmap)); |
| 1591 | 1613 | ||
| 1592 | /* kick off the bitmap daemons */ | 1614 | mddev->bitmap = bitmap; |
| 1593 | err = bitmap_start_daemons(bitmap); | 1615 | |
| 1594 | if (err) | 1616 | if (file) |
| 1595 | return err; | 1617 | /* kick off the bitmap writeback daemon */ |
| 1618 | bitmap->writeback_daemon = | ||
| 1619 | bitmap_start_daemon(bitmap, | ||
| 1620 | bitmap_writeback_daemon, | ||
| 1621 | "bitmap_wb"); | ||
| 1622 | |||
| 1623 | if (IS_ERR(bitmap->writeback_daemon)) | ||
| 1624 | return PTR_ERR(bitmap->writeback_daemon); | ||
| 1596 | return bitmap_update_sb(bitmap); | 1625 | return bitmap_update_sb(bitmap); |
| 1626 | |||
| 1627 | error: | ||
| 1628 | bitmap_free(bitmap); | ||
| 1629 | return err; | ||
| 1597 | } | 1630 | } |
| 1598 | 1631 | ||
| 1599 | /* the bitmap API -- for raid personalities */ | 1632 | /* the bitmap API -- for raid personalities */ |
