diff options
Diffstat (limited to 'drivers/md/bitmap.c')
-rw-r--r-- | drivers/md/bitmap.c | 165 |
1 files changed, 125 insertions, 40 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c index e4fb58db5454..574b09afedd3 100644 --- a/drivers/md/bitmap.c +++ b/drivers/md/bitmap.c | |||
@@ -210,11 +210,11 @@ static struct page *read_sb_page(mddev_t *mddev, loff_t offset, | |||
210 | || test_bit(Faulty, &rdev->flags)) | 210 | || test_bit(Faulty, &rdev->flags)) |
211 | continue; | 211 | continue; |
212 | 212 | ||
213 | target = rdev->sb_start + offset + index * (PAGE_SIZE/512); | 213 | target = offset + index * (PAGE_SIZE/512); |
214 | 214 | ||
215 | if (sync_page_io(rdev->bdev, target, | 215 | if (sync_page_io(rdev, target, |
216 | roundup(size, bdev_logical_block_size(rdev->bdev)), | 216 | roundup(size, bdev_logical_block_size(rdev->bdev)), |
217 | page, READ)) { | 217 | page, READ, true)) { |
218 | page->index = index; | 218 | page->index = index; |
219 | attach_page_buffers(page, NULL); /* so that free_buffer will | 219 | attach_page_buffers(page, NULL); /* so that free_buffer will |
220 | * quietly no-op */ | 220 | * quietly no-op */ |
@@ -264,14 +264,18 @@ static mdk_rdev_t *next_active_rdev(mdk_rdev_t *rdev, mddev_t *mddev) | |||
264 | static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait) | 264 | static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait) |
265 | { | 265 | { |
266 | mdk_rdev_t *rdev = NULL; | 266 | mdk_rdev_t *rdev = NULL; |
267 | struct block_device *bdev; | ||
267 | mddev_t *mddev = bitmap->mddev; | 268 | mddev_t *mddev = bitmap->mddev; |
268 | 269 | ||
269 | while ((rdev = next_active_rdev(rdev, mddev)) != NULL) { | 270 | while ((rdev = next_active_rdev(rdev, mddev)) != NULL) { |
270 | int size = PAGE_SIZE; | 271 | int size = PAGE_SIZE; |
271 | loff_t offset = mddev->bitmap_info.offset; | 272 | loff_t offset = mddev->bitmap_info.offset; |
273 | |||
274 | bdev = (rdev->meta_bdev) ? rdev->meta_bdev : rdev->bdev; | ||
275 | |||
272 | if (page->index == bitmap->file_pages-1) | 276 | if (page->index == bitmap->file_pages-1) |
273 | size = roundup(bitmap->last_page_size, | 277 | size = roundup(bitmap->last_page_size, |
274 | bdev_logical_block_size(rdev->bdev)); | 278 | bdev_logical_block_size(bdev)); |
275 | /* Just make sure we aren't corrupting data or | 279 | /* Just make sure we aren't corrupting data or |
276 | * metadata | 280 | * metadata |
277 | */ | 281 | */ |
@@ -343,7 +347,7 @@ static void write_page(struct bitmap *bitmap, struct page *page, int wait) | |||
343 | atomic_inc(&bitmap->pending_writes); | 347 | atomic_inc(&bitmap->pending_writes); |
344 | set_buffer_locked(bh); | 348 | set_buffer_locked(bh); |
345 | set_buffer_mapped(bh); | 349 | set_buffer_mapped(bh); |
346 | submit_bh(WRITE, bh); | 350 | submit_bh(WRITE | REQ_SYNC, bh); |
347 | bh = bh->b_this_page; | 351 | bh = bh->b_this_page; |
348 | } | 352 | } |
349 | 353 | ||
@@ -489,11 +493,11 @@ void bitmap_update_sb(struct bitmap *bitmap) | |||
489 | spin_unlock_irqrestore(&bitmap->lock, flags); | 493 | spin_unlock_irqrestore(&bitmap->lock, flags); |
490 | sb = kmap_atomic(bitmap->sb_page, KM_USER0); | 494 | sb = kmap_atomic(bitmap->sb_page, KM_USER0); |
491 | sb->events = cpu_to_le64(bitmap->mddev->events); | 495 | sb->events = cpu_to_le64(bitmap->mddev->events); |
492 | if (bitmap->mddev->events < bitmap->events_cleared) { | 496 | if (bitmap->mddev->events < bitmap->events_cleared) |
493 | /* rocking back to read-only */ | 497 | /* rocking back to read-only */ |
494 | bitmap->events_cleared = bitmap->mddev->events; | 498 | bitmap->events_cleared = bitmap->mddev->events; |
495 | sb->events_cleared = cpu_to_le64(bitmap->events_cleared); | 499 | sb->events_cleared = cpu_to_le64(bitmap->events_cleared); |
496 | } | 500 | sb->state = cpu_to_le32(bitmap->flags); |
497 | /* Just in case these have been changed via sysfs: */ | 501 | /* Just in case these have been changed via sysfs: */ |
498 | sb->daemon_sleep = cpu_to_le32(bitmap->mddev->bitmap_info.daemon_sleep/HZ); | 502 | sb->daemon_sleep = cpu_to_le32(bitmap->mddev->bitmap_info.daemon_sleep/HZ); |
499 | sb->write_behind = cpu_to_le32(bitmap->mddev->bitmap_info.max_write_behind); | 503 | sb->write_behind = cpu_to_le32(bitmap->mddev->bitmap_info.max_write_behind); |
@@ -530,6 +534,82 @@ void bitmap_print_sb(struct bitmap *bitmap) | |||
530 | kunmap_atomic(sb, KM_USER0); | 534 | kunmap_atomic(sb, KM_USER0); |
531 | } | 535 | } |
532 | 536 | ||
537 | /* | ||
538 | * bitmap_new_disk_sb | ||
539 | * @bitmap | ||
540 | * | ||
541 | * This function is somewhat the reverse of bitmap_read_sb. bitmap_read_sb | ||
542 | * reads and verifies the on-disk bitmap superblock and populates bitmap_info. | ||
543 | * This function verifies 'bitmap_info' and populates the on-disk bitmap | ||
544 | * structure, which is to be written to disk. | ||
545 | * | ||
546 | * Returns: 0 on success, -Exxx on error | ||
547 | */ | ||
548 | static int bitmap_new_disk_sb(struct bitmap *bitmap) | ||
549 | { | ||
550 | bitmap_super_t *sb; | ||
551 | unsigned long chunksize, daemon_sleep, write_behind; | ||
552 | int err = -EINVAL; | ||
553 | |||
554 | bitmap->sb_page = alloc_page(GFP_KERNEL); | ||
555 | if (IS_ERR(bitmap->sb_page)) { | ||
556 | err = PTR_ERR(bitmap->sb_page); | ||
557 | bitmap->sb_page = NULL; | ||
558 | return err; | ||
559 | } | ||
560 | bitmap->sb_page->index = 0; | ||
561 | |||
562 | sb = kmap_atomic(bitmap->sb_page, KM_USER0); | ||
563 | |||
564 | sb->magic = cpu_to_le32(BITMAP_MAGIC); | ||
565 | sb->version = cpu_to_le32(BITMAP_MAJOR_HI); | ||
566 | |||
567 | chunksize = bitmap->mddev->bitmap_info.chunksize; | ||
568 | BUG_ON(!chunksize); | ||
569 | if (!is_power_of_2(chunksize)) { | ||
570 | kunmap_atomic(sb, KM_USER0); | ||
571 | printk(KERN_ERR "bitmap chunksize not a power of 2\n"); | ||
572 | return -EINVAL; | ||
573 | } | ||
574 | sb->chunksize = cpu_to_le32(chunksize); | ||
575 | |||
576 | daemon_sleep = bitmap->mddev->bitmap_info.daemon_sleep; | ||
577 | if (!daemon_sleep || | ||
578 | (daemon_sleep < 1) || (daemon_sleep > MAX_SCHEDULE_TIMEOUT)) { | ||
579 | printk(KERN_INFO "Choosing daemon_sleep default (5 sec)\n"); | ||
580 | daemon_sleep = 5 * HZ; | ||
581 | } | ||
582 | sb->daemon_sleep = cpu_to_le32(daemon_sleep); | ||
583 | bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; | ||
584 | |||
585 | /* | ||
586 | * FIXME: write_behind for RAID1. If not specified, what | ||
587 | * is a good choice? We choose COUNTER_MAX / 2 arbitrarily. | ||
588 | */ | ||
589 | write_behind = bitmap->mddev->bitmap_info.max_write_behind; | ||
590 | if (write_behind > COUNTER_MAX) | ||
591 | write_behind = COUNTER_MAX / 2; | ||
592 | sb->write_behind = cpu_to_le32(write_behind); | ||
593 | bitmap->mddev->bitmap_info.max_write_behind = write_behind; | ||
594 | |||
595 | /* keep the array size field of the bitmap superblock up to date */ | ||
596 | sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); | ||
597 | |||
598 | memcpy(sb->uuid, bitmap->mddev->uuid, 16); | ||
599 | |||
600 | bitmap->flags |= BITMAP_STALE; | ||
601 | sb->state |= cpu_to_le32(BITMAP_STALE); | ||
602 | bitmap->events_cleared = bitmap->mddev->events; | ||
603 | sb->events_cleared = cpu_to_le64(bitmap->mddev->events); | ||
604 | |||
605 | bitmap->flags |= BITMAP_HOSTENDIAN; | ||
606 | sb->version = cpu_to_le32(BITMAP_MAJOR_HOSTENDIAN); | ||
607 | |||
608 | kunmap_atomic(sb, KM_USER0); | ||
609 | |||
610 | return 0; | ||
611 | } | ||
612 | |||
533 | /* read the superblock from the bitmap file and initialize some bitmap fields */ | 613 | /* read the superblock from the bitmap file and initialize some bitmap fields */ |
534 | static int bitmap_read_sb(struct bitmap *bitmap) | 614 | static int bitmap_read_sb(struct bitmap *bitmap) |
535 | { | 615 | { |
@@ -571,7 +651,7 @@ static int bitmap_read_sb(struct bitmap *bitmap) | |||
571 | reason = "unrecognized superblock version"; | 651 | reason = "unrecognized superblock version"; |
572 | else if (chunksize < 512) | 652 | else if (chunksize < 512) |
573 | reason = "bitmap chunksize too small"; | 653 | reason = "bitmap chunksize too small"; |
574 | else if ((1 << ffz(~chunksize)) != chunksize) | 654 | else if (!is_power_of_2(chunksize)) |
575 | reason = "bitmap chunksize not a power of 2"; | 655 | reason = "bitmap chunksize not a power of 2"; |
576 | else if (daemon_sleep < 1 || daemon_sleep > MAX_SCHEDULE_TIMEOUT) | 656 | else if (daemon_sleep < 1 || daemon_sleep > MAX_SCHEDULE_TIMEOUT) |
577 | reason = "daemon sleep period out of range"; | 657 | reason = "daemon sleep period out of range"; |
@@ -614,7 +694,7 @@ success: | |||
614 | if (le32_to_cpu(sb->version) == BITMAP_MAJOR_HOSTENDIAN) | 694 | if (le32_to_cpu(sb->version) == BITMAP_MAJOR_HOSTENDIAN) |
615 | bitmap->flags |= BITMAP_HOSTENDIAN; | 695 | bitmap->flags |= BITMAP_HOSTENDIAN; |
616 | bitmap->events_cleared = le64_to_cpu(sb->events_cleared); | 696 | bitmap->events_cleared = le64_to_cpu(sb->events_cleared); |
617 | if (sb->state & cpu_to_le32(BITMAP_STALE)) | 697 | if (bitmap->flags & BITMAP_STALE) |
618 | bitmap->events_cleared = bitmap->mddev->events; | 698 | bitmap->events_cleared = bitmap->mddev->events; |
619 | err = 0; | 699 | err = 0; |
620 | out: | 700 | out: |
@@ -648,9 +728,11 @@ static int bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits, | |||
648 | switch (op) { | 728 | switch (op) { |
649 | case MASK_SET: | 729 | case MASK_SET: |
650 | sb->state |= cpu_to_le32(bits); | 730 | sb->state |= cpu_to_le32(bits); |
731 | bitmap->flags |= bits; | ||
651 | break; | 732 | break; |
652 | case MASK_UNSET: | 733 | case MASK_UNSET: |
653 | sb->state &= cpu_to_le32(~bits); | 734 | sb->state &= cpu_to_le32(~bits); |
735 | bitmap->flags &= ~bits; | ||
654 | break; | 736 | break; |
655 | default: | 737 | default: |
656 | BUG(); | 738 | BUG(); |
@@ -850,7 +932,7 @@ static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block) | |||
850 | if (bitmap->flags & BITMAP_HOSTENDIAN) | 932 | if (bitmap->flags & BITMAP_HOSTENDIAN) |
851 | set_bit(bit, kaddr); | 933 | set_bit(bit, kaddr); |
852 | else | 934 | else |
853 | ext2_set_bit(bit, kaddr); | 935 | __test_and_set_bit_le(bit, kaddr); |
854 | kunmap_atomic(kaddr, KM_USER0); | 936 | kunmap_atomic(kaddr, KM_USER0); |
855 | PRINTK("set file bit %lu page %lu\n", bit, page->index); | 937 | PRINTK("set file bit %lu page %lu\n", bit, page->index); |
856 | } | 938 | } |
@@ -1046,7 +1128,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) | |||
1046 | if (bitmap->flags & BITMAP_HOSTENDIAN) | 1128 | if (bitmap->flags & BITMAP_HOSTENDIAN) |
1047 | b = test_bit(bit, paddr); | 1129 | b = test_bit(bit, paddr); |
1048 | else | 1130 | else |
1049 | b = ext2_test_bit(bit, paddr); | 1131 | b = test_bit_le(bit, paddr); |
1050 | kunmap_atomic(paddr, KM_USER0); | 1132 | kunmap_atomic(paddr, KM_USER0); |
1051 | if (b) { | 1133 | if (b) { |
1052 | /* if the disk bit is set, set the memory bit */ | 1134 | /* if the disk bit is set, set the memory bit */ |
@@ -1070,8 +1152,8 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) | |||
1070 | } | 1152 | } |
1071 | 1153 | ||
1072 | printk(KERN_INFO "%s: bitmap initialized from disk: " | 1154 | printk(KERN_INFO "%s: bitmap initialized from disk: " |
1073 | "read %lu/%lu pages, set %lu bits\n", | 1155 | "read %lu/%lu pages, set %lu of %lu bits\n", |
1074 | bmname(bitmap), bitmap->file_pages, num_pages, bit_cnt); | 1156 | bmname(bitmap), bitmap->file_pages, num_pages, bit_cnt, chunks); |
1075 | 1157 | ||
1076 | return 0; | 1158 | return 0; |
1077 | 1159 | ||
@@ -1101,7 +1183,7 @@ static void bitmap_count_page(struct bitmap *bitmap, sector_t offset, int inc) | |||
1101 | bitmap_checkfree(bitmap, page); | 1183 | bitmap_checkfree(bitmap, page); |
1102 | } | 1184 | } |
1103 | static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, | 1185 | static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, |
1104 | sector_t offset, int *blocks, | 1186 | sector_t offset, sector_t *blocks, |
1105 | int create); | 1187 | int create); |
1106 | 1188 | ||
1107 | /* | 1189 | /* |
@@ -1115,7 +1197,7 @@ void bitmap_daemon_work(mddev_t *mddev) | |||
1115 | unsigned long j; | 1197 | unsigned long j; |
1116 | unsigned long flags; | 1198 | unsigned long flags; |
1117 | struct page *page = NULL, *lastpage = NULL; | 1199 | struct page *page = NULL, *lastpage = NULL; |
1118 | int blocks; | 1200 | sector_t blocks; |
1119 | void *paddr; | 1201 | void *paddr; |
1120 | struct dm_dirty_log *log = mddev->bitmap_info.log; | 1202 | struct dm_dirty_log *log = mddev->bitmap_info.log; |
1121 | 1203 | ||
@@ -1222,7 +1304,7 @@ void bitmap_daemon_work(mddev_t *mddev) | |||
1222 | clear_bit(file_page_offset(bitmap, j), | 1304 | clear_bit(file_page_offset(bitmap, j), |
1223 | paddr); | 1305 | paddr); |
1224 | else | 1306 | else |
1225 | ext2_clear_bit(file_page_offset(bitmap, j), | 1307 | __test_and_clear_bit_le(file_page_offset(bitmap, j), |
1226 | paddr); | 1308 | paddr); |
1227 | kunmap_atomic(paddr, KM_USER0); | 1309 | kunmap_atomic(paddr, KM_USER0); |
1228 | } else | 1310 | } else |
@@ -1258,7 +1340,7 @@ void bitmap_daemon_work(mddev_t *mddev) | |||
1258 | } | 1340 | } |
1259 | 1341 | ||
1260 | static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, | 1342 | static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, |
1261 | sector_t offset, int *blocks, | 1343 | sector_t offset, sector_t *blocks, |
1262 | int create) | 1344 | int create) |
1263 | __releases(bitmap->lock) | 1345 | __releases(bitmap->lock) |
1264 | __acquires(bitmap->lock) | 1346 | __acquires(bitmap->lock) |
@@ -1316,7 +1398,7 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect | |||
1316 | } | 1398 | } |
1317 | 1399 | ||
1318 | while (sectors) { | 1400 | while (sectors) { |
1319 | int blocks; | 1401 | sector_t blocks; |
1320 | bitmap_counter_t *bmc; | 1402 | bitmap_counter_t *bmc; |
1321 | 1403 | ||
1322 | spin_lock_irq(&bitmap->lock); | 1404 | spin_lock_irq(&bitmap->lock); |
@@ -1326,7 +1408,7 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect | |||
1326 | return 0; | 1408 | return 0; |
1327 | } | 1409 | } |
1328 | 1410 | ||
1329 | if (unlikely((*bmc & COUNTER_MAX) == COUNTER_MAX)) { | 1411 | if (unlikely(COUNTER(*bmc) == COUNTER_MAX)) { |
1330 | DEFINE_WAIT(__wait); | 1412 | DEFINE_WAIT(__wait); |
1331 | /* note that it is safe to do the prepare_to_wait | 1413 | /* note that it is safe to do the prepare_to_wait |
1332 | * after the test as long as we do it before dropping | 1414 | * after the test as long as we do it before dropping |
@@ -1335,8 +1417,7 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect | |||
1335 | prepare_to_wait(&bitmap->overflow_wait, &__wait, | 1417 | prepare_to_wait(&bitmap->overflow_wait, &__wait, |
1336 | TASK_UNINTERRUPTIBLE); | 1418 | TASK_UNINTERRUPTIBLE); |
1337 | spin_unlock_irq(&bitmap->lock); | 1419 | spin_unlock_irq(&bitmap->lock); |
1338 | md_unplug(bitmap->mddev); | 1420 | io_schedule(); |
1339 | schedule(); | ||
1340 | finish_wait(&bitmap->overflow_wait, &__wait); | 1421 | finish_wait(&bitmap->overflow_wait, &__wait); |
1341 | continue; | 1422 | continue; |
1342 | } | 1423 | } |
@@ -1381,7 +1462,7 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto | |||
1381 | success = 0; | 1462 | success = 0; |
1382 | 1463 | ||
1383 | while (sectors) { | 1464 | while (sectors) { |
1384 | int blocks; | 1465 | sector_t blocks; |
1385 | unsigned long flags; | 1466 | unsigned long flags; |
1386 | bitmap_counter_t *bmc; | 1467 | bitmap_counter_t *bmc; |
1387 | 1468 | ||
@@ -1399,10 +1480,10 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto | |||
1399 | sysfs_notify_dirent_safe(bitmap->sysfs_can_clear); | 1480 | sysfs_notify_dirent_safe(bitmap->sysfs_can_clear); |
1400 | } | 1481 | } |
1401 | 1482 | ||
1402 | if (!success && ! (*bmc & NEEDED_MASK)) | 1483 | if (!success && !NEEDED(*bmc)) |
1403 | *bmc |= NEEDED_MASK; | 1484 | *bmc |= NEEDED_MASK; |
1404 | 1485 | ||
1405 | if ((*bmc & COUNTER_MAX) == COUNTER_MAX) | 1486 | if (COUNTER(*bmc) == COUNTER_MAX) |
1406 | wake_up(&bitmap->overflow_wait); | 1487 | wake_up(&bitmap->overflow_wait); |
1407 | 1488 | ||
1408 | (*bmc)--; | 1489 | (*bmc)--; |
@@ -1423,7 +1504,7 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto | |||
1423 | } | 1504 | } |
1424 | EXPORT_SYMBOL(bitmap_endwrite); | 1505 | EXPORT_SYMBOL(bitmap_endwrite); |
1425 | 1506 | ||
1426 | static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks, | 1507 | static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, |
1427 | int degraded) | 1508 | int degraded) |
1428 | { | 1509 | { |
1429 | bitmap_counter_t *bmc; | 1510 | bitmap_counter_t *bmc; |
@@ -1452,7 +1533,7 @@ static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *bloc | |||
1452 | return rv; | 1533 | return rv; |
1453 | } | 1534 | } |
1454 | 1535 | ||
1455 | int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks, | 1536 | int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, |
1456 | int degraded) | 1537 | int degraded) |
1457 | { | 1538 | { |
1458 | /* bitmap_start_sync must always report on multiples of whole | 1539 | /* bitmap_start_sync must always report on multiples of whole |
@@ -1463,7 +1544,7 @@ int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks, | |||
1463 | * Return the 'or' of the result. | 1544 | * Return the 'or' of the result. |
1464 | */ | 1545 | */ |
1465 | int rv = 0; | 1546 | int rv = 0; |
1466 | int blocks1; | 1547 | sector_t blocks1; |
1467 | 1548 | ||
1468 | *blocks = 0; | 1549 | *blocks = 0; |
1469 | while (*blocks < (PAGE_SIZE>>9)) { | 1550 | while (*blocks < (PAGE_SIZE>>9)) { |
@@ -1476,7 +1557,7 @@ int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks, | |||
1476 | } | 1557 | } |
1477 | EXPORT_SYMBOL(bitmap_start_sync); | 1558 | EXPORT_SYMBOL(bitmap_start_sync); |
1478 | 1559 | ||
1479 | void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int aborted) | 1560 | void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted) |
1480 | { | 1561 | { |
1481 | bitmap_counter_t *bmc; | 1562 | bitmap_counter_t *bmc; |
1482 | unsigned long flags; | 1563 | unsigned long flags; |
@@ -1515,7 +1596,7 @@ void bitmap_close_sync(struct bitmap *bitmap) | |||
1515 | * RESYNC bit wherever it is still on | 1596 | * RESYNC bit wherever it is still on |
1516 | */ | 1597 | */ |
1517 | sector_t sector = 0; | 1598 | sector_t sector = 0; |
1518 | int blocks; | 1599 | sector_t blocks; |
1519 | if (!bitmap) | 1600 | if (!bitmap) |
1520 | return; | 1601 | return; |
1521 | while (sector < bitmap->mddev->resync_max_sectors) { | 1602 | while (sector < bitmap->mddev->resync_max_sectors) { |
@@ -1528,7 +1609,7 @@ EXPORT_SYMBOL(bitmap_close_sync); | |||
1528 | void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector) | 1609 | void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector) |
1529 | { | 1610 | { |
1530 | sector_t s = 0; | 1611 | sector_t s = 0; |
1531 | int blocks; | 1612 | sector_t blocks; |
1532 | 1613 | ||
1533 | if (!bitmap) | 1614 | if (!bitmap) |
1534 | return; | 1615 | return; |
@@ -1542,7 +1623,7 @@ void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector) | |||
1542 | wait_event(bitmap->mddev->recovery_wait, | 1623 | wait_event(bitmap->mddev->recovery_wait, |
1543 | atomic_read(&bitmap->mddev->recovery_active) == 0); | 1624 | atomic_read(&bitmap->mddev->recovery_active) == 0); |
1544 | 1625 | ||
1545 | bitmap->mddev->curr_resync_completed = bitmap->mddev->curr_resync; | 1626 | bitmap->mddev->curr_resync_completed = sector; |
1546 | set_bit(MD_CHANGE_CLEAN, &bitmap->mddev->flags); | 1627 | set_bit(MD_CHANGE_CLEAN, &bitmap->mddev->flags); |
1547 | sector &= ~((1ULL << CHUNK_BLOCK_SHIFT(bitmap)) - 1); | 1628 | sector &= ~((1ULL << CHUNK_BLOCK_SHIFT(bitmap)) - 1); |
1548 | s = 0; | 1629 | s = 0; |
@@ -1562,7 +1643,7 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int n | |||
1562 | * be 0 at this point | 1643 | * be 0 at this point |
1563 | */ | 1644 | */ |
1564 | 1645 | ||
1565 | int secs; | 1646 | sector_t secs; |
1566 | bitmap_counter_t *bmc; | 1647 | bitmap_counter_t *bmc; |
1567 | spin_lock_irq(&bitmap->lock); | 1648 | spin_lock_irq(&bitmap->lock); |
1568 | bmc = bitmap_get_counter(bitmap, offset, &secs, 1); | 1649 | bmc = bitmap_get_counter(bitmap, offset, &secs, 1); |
@@ -1723,9 +1804,16 @@ int bitmap_create(mddev_t *mddev) | |||
1723 | vfs_fsync(file, 1); | 1804 | vfs_fsync(file, 1); |
1724 | } | 1805 | } |
1725 | /* read superblock from bitmap file (this sets mddev->bitmap_info.chunksize) */ | 1806 | /* read superblock from bitmap file (this sets mddev->bitmap_info.chunksize) */ |
1726 | if (!mddev->bitmap_info.external) | 1807 | if (!mddev->bitmap_info.external) { |
1727 | err = bitmap_read_sb(bitmap); | 1808 | /* |
1728 | else { | 1809 | * If 'MD_ARRAY_FIRST_USE' is set, then device-mapper is |
1810 | * instructing us to create a new on-disk bitmap instance. | ||
1811 | */ | ||
1812 | if (test_and_clear_bit(MD_ARRAY_FIRST_USE, &mddev->flags)) | ||
1813 | err = bitmap_new_disk_sb(bitmap); | ||
1814 | else | ||
1815 | err = bitmap_read_sb(bitmap); | ||
1816 | } else { | ||
1729 | err = 0; | 1817 | err = 0; |
1730 | if (mddev->bitmap_info.chunksize == 0 || | 1818 | if (mddev->bitmap_info.chunksize == 0 || |
1731 | mddev->bitmap_info.daemon_sleep == 0) | 1819 | mddev->bitmap_info.daemon_sleep == 0) |
@@ -1749,9 +1837,6 @@ int bitmap_create(mddev_t *mddev) | |||
1749 | bitmap->chunks = chunks; | 1837 | bitmap->chunks = chunks; |
1750 | bitmap->pages = pages; | 1838 | bitmap->pages = pages; |
1751 | bitmap->missing_pages = pages; | 1839 | bitmap->missing_pages = pages; |
1752 | bitmap->counter_bits = COUNTER_BITS; | ||
1753 | |||
1754 | bitmap->syncchunk = ~0UL; | ||
1755 | 1840 | ||
1756 | #ifdef INJECT_FATAL_FAULT_1 | 1841 | #ifdef INJECT_FATAL_FAULT_1 |
1757 | bitmap->bp = NULL; | 1842 | bitmap->bp = NULL; |
@@ -1790,7 +1875,7 @@ int bitmap_load(mddev_t *mddev) | |||
1790 | * All chunks should be clean, but some might need_sync. | 1875 | * All chunks should be clean, but some might need_sync. |
1791 | */ | 1876 | */ |
1792 | while (sector < mddev->resync_max_sectors) { | 1877 | while (sector < mddev->resync_max_sectors) { |
1793 | int blocks; | 1878 | sector_t blocks; |
1794 | bitmap_start_sync(bitmap, sector, &blocks, 0); | 1879 | bitmap_start_sync(bitmap, sector, &blocks, 0); |
1795 | sector += blocks; | 1880 | sector += blocks; |
1796 | } | 1881 | } |