Lines Matching full:bitmap
3 * bitmap.c two-level bitmap (C) Peter T. Breuer (ptb@ot.uc3m.es) 2003
5 * bitmap_create - sets up the bitmap structure
6 * bitmap_destroy - destroys the bitmap structure
9 * - added disk storage for bitmap
10 * - changes to allow various bitmap chunk sizes
33 #include "md-bitmap.h"
35 static inline char *bmname(struct bitmap *bitmap) in bmname() argument
37 return bitmap->mddev ? mdname(bitmap->mddev) : "mdX"; in bmname()
50 static int md_bitmap_checkpage(struct bitmap_counts *bitmap, in md_bitmap_checkpage() argument
52 __releases(bitmap->lock) in md_bitmap_checkpage()
53 __acquires(bitmap->lock) in md_bitmap_checkpage()
57 WARN_ON_ONCE(page >= bitmap->pages); in md_bitmap_checkpage()
58 if (bitmap->bp[page].hijacked) /* it's hijacked, don't try to alloc */ in md_bitmap_checkpage()
61 if (bitmap->bp[page].map) /* page is already allocated, just return */ in md_bitmap_checkpage()
69 spin_unlock_irq(&bitmap->lock); in md_bitmap_checkpage()
84 spin_lock_irq(&bitmap->lock); in md_bitmap_checkpage()
87 pr_debug("md/bitmap: map page allocation failed, hijacking\n"); in md_bitmap_checkpage()
93 if (!bitmap->bp[page].map) in md_bitmap_checkpage()
94 bitmap->bp[page].hijacked = 1; in md_bitmap_checkpage()
95 } else if (bitmap->bp[page].map || in md_bitmap_checkpage()
96 bitmap->bp[page].hijacked) { in md_bitmap_checkpage()
103 bitmap->bp[page].map = mappage; in md_bitmap_checkpage()
104 bitmap->missing_pages--; in md_bitmap_checkpage()
112 static void md_bitmap_checkfree(struct bitmap_counts *bitmap, unsigned long page) in md_bitmap_checkfree() argument
116 if (bitmap->bp[page].count) /* page is still busy */ in md_bitmap_checkfree()
121 if (bitmap->bp[page].hijacked) { /* page was hijacked, undo this now */ in md_bitmap_checkfree()
122 bitmap->bp[page].hijacked = 0; in md_bitmap_checkfree()
123 bitmap->bp[page].map = NULL; in md_bitmap_checkfree()
126 ptr = bitmap->bp[page].map; in md_bitmap_checkfree()
127 bitmap->bp[page].map = NULL; in md_bitmap_checkfree()
128 bitmap->missing_pages++; in md_bitmap_checkfree()
134 * bitmap file handling - read and write the bitmap file and its superblock
141 /* IO operations when bitmap is stored near all superblocks */
224 static int __write_sb_page(struct md_rdev *rdev, struct bitmap *bitmap, in __write_sb_page() argument
228 struct mddev *mddev = bitmap->mddev; in __write_sb_page()
229 struct bitmap_storage *store = &bitmap->storage; in __write_sb_page()
230 unsigned int bitmap_limit = (bitmap->storage.file_pages - pg_index) << in __write_sb_page()
254 /* Bitmap could be anywhere. */ in __write_sb_page()
259 /* DATA BITMAP METADATA */ in __write_sb_page()
262 /* bitmap runs in to metadata */ in __write_sb_page()
266 /* data runs in to bitmap */ in __write_sb_page()
269 /* METADATA BITMAP DATA */ in __write_sb_page()
272 /* bitmap runs in to data */ in __write_sb_page()
280 static void write_sb_page(struct bitmap *bitmap, unsigned long pg_index, in write_sb_page() argument
283 struct mddev *mddev = bitmap->mddev; in write_sb_page()
289 if (__write_sb_page(rdev, bitmap, pg_index, page) < 0) { in write_sb_page()
290 set_bit(BITMAP_WRITE_ERROR, &bitmap->flags); in write_sb_page()
297 static void md_bitmap_file_kick(struct bitmap *bitmap);
300 static void write_file_page(struct bitmap *bitmap, struct page *page, int wait) in write_file_page() argument
305 atomic_inc(&bitmap->pending_writes); in write_file_page()
313 wait_event(bitmap->write_wait, in write_file_page()
314 atomic_read(&bitmap->pending_writes) == 0); in write_file_page()
319 struct bitmap *bitmap = bh->b_private; in end_bitmap_write() local
322 set_bit(BITMAP_WRITE_ERROR, &bitmap->flags); in end_bitmap_write()
323 if (atomic_dec_and_test(&bitmap->pending_writes)) in end_bitmap_write()
324 wake_up(&bitmap->write_wait); in end_bitmap_write()
352 struct bitmap *bitmap, unsigned long count, struct page *page) in read_file_page() argument
360 pr_debug("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE, in read_file_page()
391 bh->b_private = bitmap; in read_file_page()
392 atomic_inc(&bitmap->pending_writes); in read_file_page()
401 wait_event(bitmap->write_wait, in read_file_page()
402 atomic_read(&bitmap->pending_writes)==0); in read_file_page()
403 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in read_file_page()
407 pr_err("md: bitmap read error: (%dB @ %llu): %d\n", in read_file_page()
414 static void write_file_page(struct bitmap *bitmap, struct page *page, int wait) in write_file_page() argument
418 struct bitmap *bitmap, unsigned long count, struct page *page) in read_file_page() argument
429 * bitmap file superblock operations
435 static void filemap_write_page(struct bitmap *bitmap, unsigned long pg_index, in filemap_write_page() argument
438 struct bitmap_storage *store = &bitmap->storage; in filemap_write_page()
441 if (mddev_is_clustered(bitmap->mddev)) { in filemap_write_page()
442 /* go to node bitmap area starting point */ in filemap_write_page()
447 write_file_page(bitmap, page, wait); in filemap_write_page()
449 write_sb_page(bitmap, pg_index, page, wait); in filemap_write_page()
453 * md_bitmap_wait_writes() should be called before writing any bitmap
457 static void md_bitmap_wait_writes(struct bitmap *bitmap) in md_bitmap_wait_writes() argument
459 if (bitmap->storage.file) in md_bitmap_wait_writes()
460 wait_event(bitmap->write_wait, in md_bitmap_wait_writes()
461 atomic_read(&bitmap->pending_writes)==0); in md_bitmap_wait_writes()
466 * which is safe. The relevant bitmap blocks will in md_bitmap_wait_writes()
470 md_super_wait(bitmap->mddev); in md_bitmap_wait_writes()
475 void md_bitmap_update_sb(struct bitmap *bitmap) in md_bitmap_update_sb() argument
479 if (!bitmap || !bitmap->mddev) /* no bitmap for this array */ in md_bitmap_update_sb()
481 if (bitmap->mddev->bitmap_info.external) in md_bitmap_update_sb()
483 if (!bitmap->storage.sb_page) /* no superblock */ in md_bitmap_update_sb()
485 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_update_sb()
486 sb->events = cpu_to_le64(bitmap->mddev->events); in md_bitmap_update_sb()
487 if (bitmap->mddev->events < bitmap->events_cleared) in md_bitmap_update_sb()
489 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_update_sb()
490 sb->events_cleared = cpu_to_le64(bitmap->events_cleared); in md_bitmap_update_sb()
493 * a bitmap write error occurred but the later writes succeeded. in md_bitmap_update_sb()
495 sb->state = cpu_to_le32(bitmap->flags & ~BIT(BITMAP_WRITE_ERROR)); in md_bitmap_update_sb()
497 sb->daemon_sleep = cpu_to_le32(bitmap->mddev->bitmap_info.daemon_sleep/HZ); in md_bitmap_update_sb()
498 sb->write_behind = cpu_to_le32(bitmap->mddev->bitmap_info.max_write_behind); in md_bitmap_update_sb()
500 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in md_bitmap_update_sb()
501 sb->chunksize = cpu_to_le32(bitmap->mddev->bitmap_info.chunksize); in md_bitmap_update_sb()
502 sb->nodes = cpu_to_le32(bitmap->mddev->bitmap_info.nodes); in md_bitmap_update_sb()
503 sb->sectors_reserved = cpu_to_le32(bitmap->mddev-> in md_bitmap_update_sb()
507 if (bitmap->storage.file) in md_bitmap_update_sb()
508 write_file_page(bitmap, bitmap->storage.sb_page, 1); in md_bitmap_update_sb()
510 write_sb_page(bitmap, bitmap->storage.sb_index, in md_bitmap_update_sb()
511 bitmap->storage.sb_page, 1); in md_bitmap_update_sb()
515 /* print out the bitmap file superblock */
516 void md_bitmap_print_sb(struct bitmap *bitmap) in md_bitmap_print_sb() argument
520 if (!bitmap || !bitmap->storage.sb_page) in md_bitmap_print_sb()
522 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_print_sb()
523 pr_debug("%s: bitmap file superblock:\n", bmname(bitmap)); in md_bitmap_print_sb()
546 * @bitmap
549 * reads and verifies the on-disk bitmap superblock and populates bitmap_info.
550 * This function verifies 'bitmap_info' and populates the on-disk bitmap
555 static int md_bitmap_new_disk_sb(struct bitmap *bitmap) in md_bitmap_new_disk_sb() argument
560 bitmap->storage.sb_page = alloc_page(GFP_KERNEL | __GFP_ZERO); in md_bitmap_new_disk_sb()
561 if (bitmap->storage.sb_page == NULL) in md_bitmap_new_disk_sb()
563 bitmap->storage.sb_index = 0; in md_bitmap_new_disk_sb()
565 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_new_disk_sb()
570 chunksize = bitmap->mddev->bitmap_info.chunksize; in md_bitmap_new_disk_sb()
574 pr_warn("bitmap chunksize not a power of 2\n"); in md_bitmap_new_disk_sb()
579 daemon_sleep = bitmap->mddev->bitmap_info.daemon_sleep; in md_bitmap_new_disk_sb()
585 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; in md_bitmap_new_disk_sb()
591 write_behind = bitmap->mddev->bitmap_info.max_write_behind; in md_bitmap_new_disk_sb()
595 bitmap->mddev->bitmap_info.max_write_behind = write_behind; in md_bitmap_new_disk_sb()
597 /* keep the array size field of the bitmap superblock up to date */ in md_bitmap_new_disk_sb()
598 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in md_bitmap_new_disk_sb()
600 memcpy(sb->uuid, bitmap->mddev->uuid, 16); in md_bitmap_new_disk_sb()
602 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_new_disk_sb()
603 sb->state = cpu_to_le32(bitmap->flags); in md_bitmap_new_disk_sb()
604 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_new_disk_sb()
605 sb->events_cleared = cpu_to_le64(bitmap->mddev->events); in md_bitmap_new_disk_sb()
606 bitmap->mddev->bitmap_info.nodes = 0; in md_bitmap_new_disk_sb()
613 /* read the superblock from the bitmap file and initialize some bitmap fields */
614 static int md_bitmap_read_sb(struct bitmap *bitmap) in md_bitmap_read_sb() argument
626 if (!bitmap->storage.file && !bitmap->mddev->bitmap_info.offset) { in md_bitmap_read_sb()
630 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_read_sb()
638 bitmap->storage.sb_page = sb_page; in md_bitmap_read_sb()
642 if (bitmap->cluster_slot >= 0) { in md_bitmap_read_sb()
643 sector_t bm_blocks = bitmap->mddev->resync_max_sectors; in md_bitmap_read_sb()
646 (bitmap->mddev->bitmap_info.chunksize >> 9)); in md_bitmap_read_sb()
651 offset = bitmap->cluster_slot * (bm_blocks << 3); in md_bitmap_read_sb()
653 bitmap->cluster_slot, offset); in md_bitmap_read_sb()
656 if (bitmap->storage.file) { in md_bitmap_read_sb()
657 loff_t isize = i_size_read(bitmap->storage.file->f_mapping->host); in md_bitmap_read_sb()
660 err = read_file_page(bitmap->storage.file, 0, in md_bitmap_read_sb()
661 bitmap, bytes, sb_page); in md_bitmap_read_sb()
663 err = read_sb_page(bitmap->mddev, offset, sb_page, 0, in md_bitmap_read_sb()
677 /* verify that the bitmap-specific fields are valid */ in md_bitmap_read_sb()
684 reason = "bitmap chunksize too small"; in md_bitmap_read_sb()
686 reason = "bitmap chunksize not a power of 2"; in md_bitmap_read_sb()
692 pr_warn("%s: invalid bitmap file superblock: %s\n", in md_bitmap_read_sb()
693 bmname(bitmap), reason); in md_bitmap_read_sb()
698 * Setup nodes/clustername only if bitmap version is in md_bitmap_read_sb()
703 strscpy(bitmap->mddev->bitmap_info.cluster_name, in md_bitmap_read_sb()
707 /* keep the array size field of the bitmap superblock up to date */ in md_bitmap_read_sb()
708 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in md_bitmap_read_sb()
710 if (bitmap->mddev->persistent) { in md_bitmap_read_sb()
713 * bitmap's UUID and event counter to the mddev's in md_bitmap_read_sb()
715 if (memcmp(sb->uuid, bitmap->mddev->uuid, 16)) { in md_bitmap_read_sb()
716 pr_warn("%s: bitmap superblock UUID mismatch\n", in md_bitmap_read_sb()
717 bmname(bitmap)); in md_bitmap_read_sb()
721 if (!nodes && (events < bitmap->mddev->events)) { in md_bitmap_read_sb()
722 pr_warn("%s: bitmap file is out of date (%llu < %llu) -- forcing full recovery\n", in md_bitmap_read_sb()
723 bmname(bitmap), events, in md_bitmap_read_sb()
724 (unsigned long long) bitmap->mddev->events); in md_bitmap_read_sb()
725 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_read_sb()
730 bitmap->flags |= le32_to_cpu(sb->state); in md_bitmap_read_sb()
732 set_bit(BITMAP_HOSTENDIAN, &bitmap->flags); in md_bitmap_read_sb()
733 bitmap->events_cleared = le64_to_cpu(sb->events_cleared); in md_bitmap_read_sb()
738 if (err == 0 && nodes && (bitmap->cluster_slot < 0)) { in md_bitmap_read_sb()
740 bitmap->mddev->bitmap_info.chunksize = chunksize; in md_bitmap_read_sb()
741 err = md_setup_cluster(bitmap->mddev, nodes); in md_bitmap_read_sb()
744 bmname(bitmap), err); in md_bitmap_read_sb()
747 bitmap->cluster_slot = md_cluster_ops->slot_number(bitmap->mddev); in md_bitmap_read_sb()
753 if (test_bit(BITMAP_STALE, &bitmap->flags)) in md_bitmap_read_sb()
754 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_read_sb()
755 bitmap->mddev->bitmap_info.chunksize = chunksize; in md_bitmap_read_sb()
756 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; in md_bitmap_read_sb()
757 bitmap->mddev->bitmap_info.max_write_behind = write_behind; in md_bitmap_read_sb()
758 bitmap->mddev->bitmap_info.nodes = nodes; in md_bitmap_read_sb()
759 if (bitmap->mddev->bitmap_info.space == 0 || in md_bitmap_read_sb()
760 bitmap->mddev->bitmap_info.space > sectors_reserved) in md_bitmap_read_sb()
761 bitmap->mddev->bitmap_info.space = sectors_reserved; in md_bitmap_read_sb()
763 md_bitmap_print_sb(bitmap); in md_bitmap_read_sb()
764 if (bitmap->cluster_slot < 0) in md_bitmap_read_sb()
765 md_cluster_stop(bitmap->mddev); in md_bitmap_read_sb()
771 * general bitmap file operations
775 * on-disk bitmap:
777 * Use one bit per "chunk" (block set). We do the disk I/O on the bitmap
889 * bitmap_file_kick - if an error occurs while manipulating the bitmap file
893 static void md_bitmap_file_kick(struct bitmap *bitmap) in md_bitmap_file_kick() argument
895 if (!test_and_set_bit(BITMAP_STALE, &bitmap->flags)) { in md_bitmap_file_kick()
896 md_bitmap_update_sb(bitmap); in md_bitmap_file_kick()
898 if (bitmap->storage.file) { in md_bitmap_file_kick()
899 pr_warn("%s: kicking failed bitmap file %pD4 from array!\n", in md_bitmap_file_kick()
900 bmname(bitmap), bitmap->storage.file); in md_bitmap_file_kick()
903 pr_warn("%s: disabling internal bitmap due to errors\n", in md_bitmap_file_kick()
904 bmname(bitmap)); in md_bitmap_file_kick()
915 static inline void set_page_attr(struct bitmap *bitmap, int pnum, in set_page_attr() argument
918 set_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in set_page_attr()
921 static inline void clear_page_attr(struct bitmap *bitmap, int pnum, in clear_page_attr() argument
924 clear_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in clear_page_attr()
927 static inline int test_page_attr(struct bitmap *bitmap, int pnum, in test_page_attr() argument
930 return test_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in test_page_attr()
933 static inline int test_and_clear_page_attr(struct bitmap *bitmap, int pnum, in test_and_clear_page_attr() argument
937 bitmap->storage.filemap_attr); in test_and_clear_page_attr()
941 * to set (and eventually sync) a particular bit in the bitmap file
946 static void md_bitmap_file_set_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_set_bit() argument
951 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_set_bit()
952 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_file_set_bit()
957 if (mddev_is_clustered(bitmap->mddev)) in md_bitmap_file_set_bit()
958 node_offset = bitmap->cluster_slot * store->file_pages; in md_bitmap_file_set_bit()
960 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_set_bit()
963 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_set_bit()
967 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_set_bit()
974 set_page_attr(bitmap, index - node_offset, BITMAP_PAGE_DIRTY); in md_bitmap_file_set_bit()
977 static void md_bitmap_file_clear_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_clear_bit() argument
982 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_clear_bit()
983 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_file_clear_bit()
988 if (mddev_is_clustered(bitmap->mddev)) in md_bitmap_file_clear_bit()
989 node_offset = bitmap->cluster_slot * store->file_pages; in md_bitmap_file_clear_bit()
991 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_clear_bit()
994 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_clear_bit()
996 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_clear_bit()
1001 if (!test_page_attr(bitmap, index - node_offset, BITMAP_PAGE_NEEDWRITE)) { in md_bitmap_file_clear_bit()
1002 set_page_attr(bitmap, index - node_offset, BITMAP_PAGE_PENDING); in md_bitmap_file_clear_bit()
1003 bitmap->allclean = 0; in md_bitmap_file_clear_bit()
1007 static int md_bitmap_file_test_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_test_bit() argument
1012 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_test_bit()
1015 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_test_bit()
1018 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_test_bit()
1020 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_test_bit()
1030 * sync the dirty pages of the bitmap file to disk */
1031 void md_bitmap_unplug(struct bitmap *bitmap) in md_bitmap_unplug() argument
1037 if (!md_bitmap_enabled(bitmap)) in md_bitmap_unplug()
1042 for (i = 0; i < bitmap->storage.file_pages; i++) { in md_bitmap_unplug()
1043 dirty = test_and_clear_page_attr(bitmap, i, BITMAP_PAGE_DIRTY); in md_bitmap_unplug()
1044 need_write = test_and_clear_page_attr(bitmap, i, in md_bitmap_unplug()
1048 md_bitmap_wait_writes(bitmap); in md_bitmap_unplug()
1049 if (bitmap->mddev->queue) in md_bitmap_unplug()
1050 blk_add_trace_msg(bitmap->mddev->queue, in md_bitmap_unplug()
1053 clear_page_attr(bitmap, i, BITMAP_PAGE_PENDING); in md_bitmap_unplug()
1054 filemap_write_page(bitmap, i, false); in md_bitmap_unplug()
1059 md_bitmap_wait_writes(bitmap); in md_bitmap_unplug()
1061 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in md_bitmap_unplug()
1062 md_bitmap_file_kick(bitmap); in md_bitmap_unplug()
1068 struct bitmap *bitmap; member
1077 md_bitmap_unplug(unplug_work->bitmap); in md_bitmap_unplug_fn()
1081 void md_bitmap_unplug_async(struct bitmap *bitmap) in md_bitmap_unplug_async() argument
1087 unplug_work.bitmap = bitmap; in md_bitmap_unplug_async()
1096 static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
1099 * Initialize the in-memory bitmap from the on-disk bitmap and set up the memory
1100 * mapping of the bitmap file.
1102 * Special case: If there's no bitmap file, or if the bitmap file had been
1107 * This is used when reading an out-of-date bitmap.
1109 static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) in md_bitmap_init_from_disk() argument
1111 bool outofdate = test_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_init_from_disk()
1112 struct mddev *mddev = bitmap->mddev; in md_bitmap_init_from_disk()
1113 unsigned long chunks = bitmap->counts.chunks; in md_bitmap_init_from_disk()
1114 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_init_from_disk()
1122 /* No permanent bitmap - fill with '1s'. */ in md_bitmap_init_from_disk()
1127 int needed = ((sector_t)(i+1) << (bitmap->counts.chunkshift) in md_bitmap_init_from_disk()
1129 md_bitmap_set_memory_bits(bitmap, in md_bitmap_init_from_disk()
1130 (sector_t)i << bitmap->counts.chunkshift, in md_bitmap_init_from_disk()
1137 pr_warn("%s: bitmap file too short %lu < %lu\n", in md_bitmap_init_from_disk()
1138 bmname(bitmap), in md_bitmap_init_from_disk()
1146 node_offset = bitmap->cluster_slot * (DIV_ROUND_UP(store->bytes, PAGE_SIZE)); in md_bitmap_init_from_disk()
1159 ret = read_file_page(file, i, bitmap, count, page); in md_bitmap_init_from_disk()
1168 pr_warn("%s: bitmap file is out of date, doing full recovery\n", in md_bitmap_init_from_disk()
1169 bmname(bitmap)); in md_bitmap_init_from_disk()
1180 * If the bitmap is out of date, dirty the whole page in md_bitmap_init_from_disk()
1187 filemap_write_page(bitmap, i, true); in md_bitmap_init_from_disk()
1188 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) { in md_bitmap_init_from_disk()
1196 struct page *page = filemap_get_page(&bitmap->storage, i); in md_bitmap_init_from_disk()
1197 unsigned long bit = file_page_offset(&bitmap->storage, i); in md_bitmap_init_from_disk()
1202 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_init_from_disk()
1210 int needed = ((sector_t)(i+1) << bitmap->counts.chunkshift in md_bitmap_init_from_disk()
1212 md_bitmap_set_memory_bits(bitmap, in md_bitmap_init_from_disk()
1213 (sector_t)i << bitmap->counts.chunkshift, in md_bitmap_init_from_disk()
1219 pr_debug("%s: bitmap initialized from disk: read %lu pages, set %lu of %lu bits\n", in md_bitmap_init_from_disk()
1220 bmname(bitmap), store->file_pages, in md_bitmap_init_from_disk()
1226 pr_warn("%s: bitmap initialisation failed: %d\n", in md_bitmap_init_from_disk()
1227 bmname(bitmap), ret); in md_bitmap_init_from_disk()
1231 void md_bitmap_write_all(struct bitmap *bitmap) in md_bitmap_write_all() argument
1233 /* We don't actually write all bitmap blocks here, in md_bitmap_write_all()
1238 if (!bitmap || !bitmap->storage.filemap) in md_bitmap_write_all()
1240 if (bitmap->storage.file) in md_bitmap_write_all()
1244 for (i = 0; i < bitmap->storage.file_pages; i++) in md_bitmap_write_all()
1245 set_page_attr(bitmap, i, in md_bitmap_write_all()
1247 bitmap->allclean = 0; in md_bitmap_write_all()
1250 static void md_bitmap_count_page(struct bitmap_counts *bitmap, in md_bitmap_count_page() argument
1253 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_count_page()
1255 bitmap->bp[page].count += inc; in md_bitmap_count_page()
1256 md_bitmap_checkfree(bitmap, page); in md_bitmap_count_page()
1259 static void md_bitmap_set_pending(struct bitmap_counts *bitmap, sector_t offset) in md_bitmap_set_pending() argument
1261 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_set_pending()
1263 struct bitmap_page *bp = &bitmap->bp[page]; in md_bitmap_set_pending()
1269 static bitmap_counter_t *md_bitmap_get_counter(struct bitmap_counts *bitmap,
1292 * bitmap daemon -- periodically wakes up to clean bits and flush pages
1297 struct bitmap *bitmap; in md_bitmap_daemon_work() local
1307 bitmap = mddev->bitmap; in md_bitmap_daemon_work()
1308 if (bitmap == NULL) { in md_bitmap_daemon_work()
1312 if (time_before(jiffies, bitmap->daemon_lastrun in md_bitmap_daemon_work()
1316 bitmap->daemon_lastrun = jiffies; in md_bitmap_daemon_work()
1317 if (bitmap->allclean) { in md_bitmap_daemon_work()
1321 bitmap->allclean = 1; in md_bitmap_daemon_work()
1323 if (bitmap->mddev->queue) in md_bitmap_daemon_work()
1324 blk_add_trace_msg(bitmap->mddev->queue, in md_bitmap_daemon_work()
1331 for (j = 0; j < bitmap->storage.file_pages; j++) in md_bitmap_daemon_work()
1332 if (test_and_clear_page_attr(bitmap, j, in md_bitmap_daemon_work()
1334 set_page_attr(bitmap, j, in md_bitmap_daemon_work()
1337 if (bitmap->need_sync && in md_bitmap_daemon_work()
1342 bitmap->need_sync = 0; in md_bitmap_daemon_work()
1343 if (bitmap->storage.filemap) { in md_bitmap_daemon_work()
1344 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_daemon_work()
1346 cpu_to_le64(bitmap->events_cleared); in md_bitmap_daemon_work()
1348 set_page_attr(bitmap, 0, in md_bitmap_daemon_work()
1352 /* Now look at the bitmap counters and if any are '2' or '1', in md_bitmap_daemon_work()
1355 counts = &bitmap->counts; in md_bitmap_daemon_work()
1376 if (*bmc == 1 && !bitmap->need_sync) { in md_bitmap_daemon_work()
1380 md_bitmap_file_clear_bit(bitmap, block); in md_bitmap_daemon_work()
1384 bitmap->allclean = 0; in md_bitmap_daemon_work()
1389 md_bitmap_wait_writes(bitmap); in md_bitmap_daemon_work()
1399 j < bitmap->storage.file_pages in md_bitmap_daemon_work()
1400 && !test_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_daemon_work()
1402 if (test_page_attr(bitmap, j, in md_bitmap_daemon_work()
1406 if (bitmap->storage.filemap && in md_bitmap_daemon_work()
1407 test_and_clear_page_attr(bitmap, j, in md_bitmap_daemon_work()
1409 filemap_write_page(bitmap, j, false); in md_bitmap_daemon_work()
1413 if (bitmap->allclean == 0) in md_bitmap_daemon_work()
1418 static bitmap_counter_t *md_bitmap_get_counter(struct bitmap_counts *bitmap, in md_bitmap_get_counter() argument
1421 __releases(bitmap->lock) in md_bitmap_get_counter()
1422 __acquires(bitmap->lock) in md_bitmap_get_counter()
1428 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_get_counter()
1431 sector_t csize = ((sector_t)1) << bitmap->chunkshift; in md_bitmap_get_counter()
1434 if (page >= bitmap->pages) { in md_bitmap_get_counter()
1443 err = md_bitmap_checkpage(bitmap, page, create, 0); in md_bitmap_get_counter()
1445 if (bitmap->bp[page].hijacked || in md_bitmap_get_counter()
1446 bitmap->bp[page].map == NULL) in md_bitmap_get_counter()
1447 csize = ((sector_t)1) << (bitmap->chunkshift + in md_bitmap_get_counter()
1457 if (bitmap->bp[page].hijacked) { /* hijacked pointer */ in md_bitmap_get_counter()
1462 &bitmap->bp[page].map)[hi]; in md_bitmap_get_counter()
1465 &(bitmap->bp[page].map[pageoff]); in md_bitmap_get_counter()
1468 int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset, in md_bitmap_startwrite() argument
1471 if (!bitmap) in md_bitmap_startwrite()
1478 spin_lock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1479 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &blocks, 1); in md_bitmap_startwrite()
1481 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1491 prepare_to_wait(&bitmap->overflow_wait, &__wait, in md_bitmap_startwrite()
1493 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1495 finish_wait(&bitmap->overflow_wait, &__wait); in md_bitmap_startwrite()
1501 md_bitmap_file_set_bit(bitmap, offset); in md_bitmap_startwrite()
1502 md_bitmap_count_page(&bitmap->counts, offset, 1); in md_bitmap_startwrite()
1510 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1521 void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset, in md_bitmap_endwrite() argument
1524 if (!bitmap) in md_bitmap_endwrite()
1532 spin_lock_irqsave(&bitmap->counts.lock, flags); in md_bitmap_endwrite()
1533 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &blocks, 0); in md_bitmap_endwrite()
1535 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in md_bitmap_endwrite()
1539 if (!bitmap->mddev->degraded) { in md_bitmap_endwrite()
1540 if (bitmap->events_cleared < bitmap->mddev->events) { in md_bitmap_endwrite()
1541 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_endwrite()
1542 bitmap->need_sync = 1; in md_bitmap_endwrite()
1544 bitmap->sysfs_can_clear); in md_bitmap_endwrite()
1551 wake_up(&bitmap->overflow_wait); in md_bitmap_endwrite()
1555 md_bitmap_set_pending(&bitmap->counts, offset); in md_bitmap_endwrite()
1556 bitmap->allclean = 0; in md_bitmap_endwrite()
1558 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in md_bitmap_endwrite()
1567 static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, in __bitmap_start_sync() argument
1572 if (bitmap == NULL) {/* FIXME or bitmap set as 'failed' */ in __bitmap_start_sync()
1574 return 1; /* always resync if no bitmap */ in __bitmap_start_sync()
1576 spin_lock_irq(&bitmap->counts.lock); in __bitmap_start_sync()
1577 bmc = md_bitmap_get_counter(&bitmap->counts, offset, blocks, 0); in __bitmap_start_sync()
1591 spin_unlock_irq(&bitmap->counts.lock); in __bitmap_start_sync()
1595 int md_bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, in md_bitmap_start_sync() argument
1610 rv |= __bitmap_start_sync(bitmap, offset, in md_bitmap_start_sync()
1619 void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted) in md_bitmap_end_sync() argument
1624 if (bitmap == NULL) { in md_bitmap_end_sync()
1628 spin_lock_irqsave(&bitmap->counts.lock, flags); in md_bitmap_end_sync()
1629 bmc = md_bitmap_get_counter(&bitmap->counts, offset, blocks, 0); in md_bitmap_end_sync()
1640 md_bitmap_set_pending(&bitmap->counts, offset); in md_bitmap_end_sync()
1641 bitmap->allclean = 0; in md_bitmap_end_sync()
1646 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in md_bitmap_end_sync()
1650 void md_bitmap_close_sync(struct bitmap *bitmap) in md_bitmap_close_sync() argument
1652 /* Sync has finished, and any bitmap chunks that weren't synced in md_bitmap_close_sync()
1658 if (!bitmap) in md_bitmap_close_sync()
1660 while (sector < bitmap->mddev->resync_max_sectors) { in md_bitmap_close_sync()
1661 md_bitmap_end_sync(bitmap, sector, &blocks, 0); in md_bitmap_close_sync()
1667 void md_bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force) in md_bitmap_cond_end_sync() argument
1672 if (!bitmap) in md_bitmap_cond_end_sync()
1675 bitmap->last_end_sync = jiffies; in md_bitmap_cond_end_sync()
1678 if (!force && time_before(jiffies, (bitmap->last_end_sync in md_bitmap_cond_end_sync()
1679 + bitmap->mddev->bitmap_info.daemon_sleep))) in md_bitmap_cond_end_sync()
1681 wait_event(bitmap->mddev->recovery_wait, in md_bitmap_cond_end_sync()
1682 atomic_read(&bitmap->mddev->recovery_active) == 0); in md_bitmap_cond_end_sync()
1684 bitmap->mddev->curr_resync_completed = sector; in md_bitmap_cond_end_sync()
1685 set_bit(MD_SB_CHANGE_CLEAN, &bitmap->mddev->sb_flags); in md_bitmap_cond_end_sync()
1686 sector &= ~((1ULL << bitmap->counts.chunkshift) - 1); in md_bitmap_cond_end_sync()
1688 while (s < sector && s < bitmap->mddev->resync_max_sectors) { in md_bitmap_cond_end_sync()
1689 md_bitmap_end_sync(bitmap, s, &blocks, 0); in md_bitmap_cond_end_sync()
1692 bitmap->last_end_sync = jiffies; in md_bitmap_cond_end_sync()
1693 sysfs_notify_dirent_safe(bitmap->mddev->sysfs_completed); in md_bitmap_cond_end_sync()
1701 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_sync_with_cluster() local
1705 md_bitmap_end_sync(bitmap, sector, &blocks, 0); in md_bitmap_sync_with_cluster()
1711 md_bitmap_start_sync(bitmap, sector, &blocks, 0); in md_bitmap_sync_with_cluster()
1718 static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed) in md_bitmap_set_memory_bits() argument
1727 spin_lock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1728 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &secs, 1); in md_bitmap_set_memory_bits()
1730 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1735 md_bitmap_count_page(&bitmap->counts, offset, 1); in md_bitmap_set_memory_bits()
1736 md_bitmap_set_pending(&bitmap->counts, offset); in md_bitmap_set_memory_bits()
1737 bitmap->allclean = 0; in md_bitmap_set_memory_bits()
1741 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1744 /* dirty the memory and file bits for bitmap chunks "s" to "e" */
1745 void md_bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e) in md_bitmap_dirty_bits() argument
1750 sector_t sec = (sector_t)chunk << bitmap->counts.chunkshift; in md_bitmap_dirty_bits()
1751 md_bitmap_set_memory_bits(bitmap, sec, 1); in md_bitmap_dirty_bits()
1752 md_bitmap_file_set_bit(bitmap, sec); in md_bitmap_dirty_bits()
1753 if (sec < bitmap->mddev->recovery_cp) in md_bitmap_dirty_bits()
1758 bitmap->mddev->recovery_cp = sec; in md_bitmap_dirty_bits()
1767 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_flush() local
1770 if (!bitmap) /* there was no bitmap */ in md_bitmap_flush()
1777 bitmap->daemon_lastrun -= sleep; in md_bitmap_flush()
1779 bitmap->daemon_lastrun -= sleep; in md_bitmap_flush()
1781 bitmap->daemon_lastrun -= sleep; in md_bitmap_flush()
1785 md_bitmap_update_sb(bitmap); in md_bitmap_flush()
1791 void md_bitmap_free(struct bitmap *bitmap) in md_bitmap_free() argument
1796 if (!bitmap) /* there was no bitmap */ in md_bitmap_free()
1799 if (bitmap->sysfs_can_clear) in md_bitmap_free()
1800 sysfs_put(bitmap->sysfs_can_clear); in md_bitmap_free()
1802 if (mddev_is_clustered(bitmap->mddev) && bitmap->mddev->cluster_info && in md_bitmap_free()
1803 bitmap->cluster_slot == md_cluster_ops->slot_number(bitmap->mddev)) in md_bitmap_free()
1804 md_cluster_stop(bitmap->mddev); in md_bitmap_free()
1807 wait_event(bitmap->write_wait, in md_bitmap_free()
1808 atomic_read(&bitmap->pending_writes) == 0); in md_bitmap_free()
1810 /* release the bitmap file */ in md_bitmap_free()
1811 md_bitmap_file_unmap(&bitmap->storage); in md_bitmap_free()
1813 bp = bitmap->counts.bp; in md_bitmap_free()
1814 pages = bitmap->counts.pages; in md_bitmap_free()
1823 kfree(bitmap); in md_bitmap_free()
1829 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_start_behind_write() local
1832 if (!bitmap) in md_bitmap_start_behind_write()
1835 atomic_inc(&bitmap->behind_writes); in md_bitmap_start_behind_write()
1836 bw = atomic_read(&bitmap->behind_writes); in md_bitmap_start_behind_write()
1837 if (bw > bitmap->behind_writes_used) in md_bitmap_start_behind_write()
1838 bitmap->behind_writes_used = bw; in md_bitmap_start_behind_write()
1841 bw, bitmap->mddev->bitmap_info.max_write_behind); in md_bitmap_start_behind_write()
1847 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_end_behind_write() local
1849 if (!bitmap) in md_bitmap_end_behind_write()
1852 if (atomic_dec_and_test(&bitmap->behind_writes)) in md_bitmap_end_behind_write()
1853 wake_up(&bitmap->behind_wait); in md_bitmap_end_behind_write()
1855 atomic_read(&bitmap->behind_writes), in md_bitmap_end_behind_write()
1856 bitmap->mddev->bitmap_info.max_write_behind); in md_bitmap_end_behind_write()
1862 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_wait_behind_writes() local
1865 if (bitmap && atomic_read(&bitmap->behind_writes) > 0) { in md_bitmap_wait_behind_writes()
1869 wait_event(bitmap->behind_wait, in md_bitmap_wait_behind_writes()
1870 atomic_read(&bitmap->behind_writes) == 0); in md_bitmap_wait_behind_writes()
1876 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_destroy() local
1878 if (!bitmap) /* there was no bitmap */ in md_bitmap_destroy()
1887 mddev->bitmap = NULL; /* disconnect from the md device */ in md_bitmap_destroy()
1892 md_bitmap_free(bitmap); in md_bitmap_destroy()
1896 * initialize the bitmap structure
1898 * once mddev->bitmap is set
1900 struct bitmap *md_bitmap_create(struct mddev *mddev, int slot) in md_bitmap_create()
1902 struct bitmap *bitmap; in md_bitmap_create() local
1913 pr_notice("md/raid:%s: array with journal cannot have bitmap\n", in md_bitmap_create()
1918 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL); in md_bitmap_create()
1919 if (!bitmap) in md_bitmap_create()
1922 spin_lock_init(&bitmap->counts.lock); in md_bitmap_create()
1923 atomic_set(&bitmap->pending_writes, 0); in md_bitmap_create()
1924 init_waitqueue_head(&bitmap->write_wait); in md_bitmap_create()
1925 init_waitqueue_head(&bitmap->overflow_wait); in md_bitmap_create()
1926 init_waitqueue_head(&bitmap->behind_wait); in md_bitmap_create()
1928 bitmap->mddev = mddev; in md_bitmap_create()
1929 bitmap->cluster_slot = slot; in md_bitmap_create()
1932 bm = sysfs_get_dirent(mddev->kobj.sd, "bitmap"); in md_bitmap_create()
1934 bitmap->sysfs_can_clear = sysfs_get_dirent(bm, "can_clear"); in md_bitmap_create()
1937 bitmap->sysfs_can_clear = NULL; in md_bitmap_create()
1939 bitmap->storage.file = file; in md_bitmap_create()
1948 /* read superblock from bitmap file (this sets mddev->bitmap_info.chunksize) */ in md_bitmap_create()
1952 * instructing us to create a new on-disk bitmap instance. in md_bitmap_create()
1955 err = md_bitmap_new_disk_sb(bitmap); in md_bitmap_create()
1957 err = md_bitmap_read_sb(bitmap); in md_bitmap_create()
1969 bitmap->daemon_lastrun = jiffies; in md_bitmap_create()
1970 err = md_bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize, 1); in md_bitmap_create()
1974 pr_debug("created bitmap (%lu pages) for device %s\n", in md_bitmap_create()
1975 bitmap->counts.pages, bmname(bitmap)); in md_bitmap_create()
1977 err = test_bit(BITMAP_WRITE_ERROR, &bitmap->flags) ? -EIO : 0; in md_bitmap_create()
1981 return bitmap; in md_bitmap_create()
1983 md_bitmap_free(bitmap); in md_bitmap_create()
1992 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_load() local
1995 if (!bitmap) in md_bitmap_load()
2004 /* Clear out old bitmap info first: Either there is none, or we in md_bitmap_load()
2011 md_bitmap_start_sync(bitmap, sector, &blocks, 0); in md_bitmap_load()
2014 md_bitmap_close_sync(bitmap); in md_bitmap_load()
2017 || bitmap->events_cleared == mddev->events) in md_bitmap_load()
2023 err = md_bitmap_init_from_disk(bitmap, start); in md_bitmap_load()
2028 clear_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_load()
2031 set_bit(MD_RECOVERY_NEEDED, &bitmap->mddev->recovery); in md_bitmap_load()
2036 md_bitmap_update_sb(bitmap); in md_bitmap_load()
2038 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in md_bitmap_load()
2045 /* caller need to free returned bitmap with md_bitmap_free() */
2046 struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot) in get_bitmap_from_slot()
2049 struct bitmap *bitmap; in get_bitmap_from_slot() local
2051 bitmap = md_bitmap_create(mddev, slot); in get_bitmap_from_slot()
2052 if (IS_ERR(bitmap)) { in get_bitmap_from_slot()
2053 rv = PTR_ERR(bitmap); in get_bitmap_from_slot()
2057 rv = md_bitmap_init_from_disk(bitmap, 0); in get_bitmap_from_slot()
2059 md_bitmap_free(bitmap); in get_bitmap_from_slot()
2063 return bitmap; in get_bitmap_from_slot()
2067 /* Loads the bitmap associated with slot and copies the resync information
2068 * to our bitmap
2076 struct bitmap *bitmap; in md_bitmap_copy_from_slot() local
2078 bitmap = get_bitmap_from_slot(mddev, slot); in md_bitmap_copy_from_slot()
2079 if (IS_ERR(bitmap)) { in md_bitmap_copy_from_slot()
2080 pr_err("%s can't get bitmap from slot %d\n", __func__, slot); in md_bitmap_copy_from_slot()
2084 counts = &bitmap->counts; in md_bitmap_copy_from_slot()
2087 if (md_bitmap_file_test_bit(bitmap, block)) { in md_bitmap_copy_from_slot()
2091 md_bitmap_file_clear_bit(bitmap, block); in md_bitmap_copy_from_slot()
2092 md_bitmap_set_memory_bits(mddev->bitmap, block, 1); in md_bitmap_copy_from_slot()
2093 md_bitmap_file_set_bit(mddev->bitmap, block); in md_bitmap_copy_from_slot()
2098 md_bitmap_update_sb(bitmap); in md_bitmap_copy_from_slot()
2101 for (i = 0; i < bitmap->storage.file_pages; i++) in md_bitmap_copy_from_slot()
2102 if (test_page_attr(bitmap, i, BITMAP_PAGE_PENDING)) in md_bitmap_copy_from_slot()
2103 set_page_attr(bitmap, i, BITMAP_PAGE_NEEDWRITE); in md_bitmap_copy_from_slot()
2104 md_bitmap_unplug(bitmap); in md_bitmap_copy_from_slot()
2106 md_bitmap_unplug(mddev->bitmap); in md_bitmap_copy_from_slot()
2109 md_bitmap_free(bitmap); in md_bitmap_copy_from_slot()
2115 int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats) in md_bitmap_get_stats() argument
2120 if (!bitmap) in md_bitmap_get_stats()
2122 if (bitmap->mddev->bitmap_info.external) in md_bitmap_get_stats()
2124 if (!bitmap->storage.sb_page) /* no superblock */ in md_bitmap_get_stats()
2126 sb = kmap_local_page(bitmap->storage.sb_page); in md_bitmap_get_stats()
2130 counts = &bitmap->counts; in md_bitmap_get_stats()
2133 stats->file = bitmap->storage.file; in md_bitmap_get_stats()
2139 int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks, in md_bitmap_resize() argument
2144 * Then quiesce, copy bits, replace bitmap, and re-start in md_bitmap_resize()
2146 * This function is called both to set up the initial bitmap in md_bitmap_resize()
2147 * and to resize the bitmap while the array is active. in md_bitmap_resize()
2162 if (bitmap->storage.file && !init) { in md_bitmap_resize()
2163 pr_info("md: cannot resize file-based bitmap\n"); in md_bitmap_resize()
2172 long space = bitmap->mddev->bitmap_info.space; in md_bitmap_resize()
2178 bytes = DIV_ROUND_UP(bitmap->counts.chunks, 8); in md_bitmap_resize()
2179 if (!bitmap->mddev->bitmap_info.external) in md_bitmap_resize()
2182 bitmap->mddev->bitmap_info.space = space; in md_bitmap_resize()
2184 chunkshift = bitmap->counts.chunkshift; in md_bitmap_resize()
2191 if (!bitmap->mddev->bitmap_info.external) in md_bitmap_resize()
2200 if (bitmap->mddev->bitmap_info.offset || bitmap->mddev->bitmap_info.file) in md_bitmap_resize()
2202 !bitmap->mddev->bitmap_info.external, in md_bitmap_resize()
2203 mddev_is_clustered(bitmap->mddev) in md_bitmap_resize()
2204 ? bitmap->cluster_slot : 0); in md_bitmap_resize()
2220 bitmap->mddev->pers->quiesce(bitmap->mddev, 1); in md_bitmap_resize()
2222 store.file = bitmap->storage.file; in md_bitmap_resize()
2223 bitmap->storage.file = NULL; in md_bitmap_resize()
2225 if (store.sb_page && bitmap->storage.sb_page) in md_bitmap_resize()
2227 page_address(bitmap->storage.sb_page), in md_bitmap_resize()
2229 spin_lock_irq(&bitmap->counts.lock); in md_bitmap_resize()
2230 md_bitmap_file_unmap(&bitmap->storage); in md_bitmap_resize()
2231 bitmap->storage = store; in md_bitmap_resize()
2233 old_counts = bitmap->counts; in md_bitmap_resize()
2234 bitmap->counts.bp = new_bp; in md_bitmap_resize()
2235 bitmap->counts.pages = pages; in md_bitmap_resize()
2236 bitmap->counts.missing_pages = pages; in md_bitmap_resize()
2237 bitmap->counts.chunkshift = chunkshift; in md_bitmap_resize()
2238 bitmap->counts.chunks = chunks; in md_bitmap_resize()
2239 bitmap->mddev->bitmap_info.chunksize = 1UL << (chunkshift + in md_bitmap_resize()
2245 /* For cluster raid, need to pre-allocate bitmap */ in md_bitmap_resize()
2246 if (mddev_is_clustered(bitmap->mddev)) { in md_bitmap_resize()
2249 ret = md_bitmap_checkpage(&bitmap->counts, page, 1, 1); in md_bitmap_resize()
2260 bitmap->counts.bp = old_counts.bp; in md_bitmap_resize()
2261 bitmap->counts.pages = old_counts.pages; in md_bitmap_resize()
2262 bitmap->counts.missing_pages = old_counts.pages; in md_bitmap_resize()
2263 bitmap->counts.chunkshift = old_counts.chunkshift; in md_bitmap_resize()
2264 bitmap->counts.chunks = old_counts.chunks; in md_bitmap_resize()
2265 bitmap->mddev->bitmap_info.chunksize = in md_bitmap_resize()
2268 pr_warn("Could not pre-allocate in-memory bitmap for cluster raid\n"); in md_bitmap_resize()
2271 bitmap->counts.bp[page].count += 1; in md_bitmap_resize()
2283 bmc_new = md_bitmap_get_counter(&bitmap->counts, block, &new_blocks, 1); in md_bitmap_resize()
2292 md_bitmap_file_set_bit(bitmap, block); in md_bitmap_resize()
2296 md_bitmap_count_page(&bitmap->counts, block, 1); in md_bitmap_resize()
2297 md_bitmap_set_pending(&bitmap->counts, block); in md_bitmap_resize()
2307 if (bitmap->counts.bp != old_counts.bp) { in md_bitmap_resize()
2319 bmc = md_bitmap_get_counter(&bitmap->counts, block, &new_blocks, 1); in md_bitmap_resize()
2326 md_bitmap_count_page(&bitmap->counts, block, 1); in md_bitmap_resize()
2327 md_bitmap_set_pending(&bitmap->counts, block); in md_bitmap_resize()
2332 for (i = 0; i < bitmap->storage.file_pages; i++) in md_bitmap_resize()
2333 set_page_attr(bitmap, i, BITMAP_PAGE_DIRTY); in md_bitmap_resize()
2335 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_resize()
2338 md_bitmap_unplug(bitmap); in md_bitmap_resize()
2339 bitmap->mddev->pers->quiesce(bitmap->mddev, 0); in md_bitmap_resize()
2380 if (mddev->bitmap || mddev->bitmap_info.file || in location_store()
2382 /* bitmap already configured. Only option is to clear it */ in location_store()
2399 /* No bitmap, OK to set a location */ in location_store()
2426 struct bitmap *bitmap; in location_store() local
2427 bitmap = md_bitmap_create(mddev, -1); in location_store()
2429 if (IS_ERR(bitmap)) in location_store()
2430 rv = PTR_ERR(bitmap); in location_store()
2432 mddev->bitmap = bitmap; in location_store()
2447 /* Ensure new bitmap info is stored in in location_store()
2464 /* 'bitmap/space' is the space available at 'location' for the
2465 * bitmap. This allows the kernel to know when it is safe to
2466 * resize the bitmap to match a resized array.
2487 if (mddev->bitmap && in space_store()
2488 sectors < (mddev->bitmap->storage.bytes + 511) >> 9) in space_store()
2489 return -EFBIG; /* Bitmap is too big for this small space */ in space_store()
2596 md_bitmap_update_sb(mddev->bitmap); in backlog_store()
2614 /* Can only be changed when no bitmap is active */ in chunksize_store()
2617 if (mddev->bitmap) in chunksize_store()
2645 if (mddev->bitmap || in metadata_store()
2666 if (mddev->bitmap) in can_clear_show()
2667 len = sprintf(page, "%s\n", (mddev->bitmap->need_sync ? in can_clear_show()
2677 if (mddev->bitmap == NULL) in can_clear_store()
2680 mddev->bitmap->need_sync = 1; in can_clear_store()
2684 mddev->bitmap->need_sync = 0; in can_clear_store()
2698 if (mddev->bitmap == NULL) in behind_writes_used_show()
2702 mddev->bitmap->behind_writes_used); in behind_writes_used_show()
2710 if (mddev->bitmap) in behind_writes_used_reset()
2711 mddev->bitmap->behind_writes_used = 0; in behind_writes_used_reset()
2731 .name = "bitmap",