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()
251 /* Bitmap could be anywhere. */ in __write_sb_page()
256 /* DATA BITMAP METADATA */ in __write_sb_page()
259 /* bitmap runs in to metadata */ in __write_sb_page()
263 /* data runs in to bitmap */ in __write_sb_page()
266 /* METADATA BITMAP DATA */ in __write_sb_page()
269 /* bitmap runs in to data */ in __write_sb_page()
272 /* DATA METADATA BITMAP - no problems */ in __write_sb_page()
279 static void write_sb_page(struct bitmap *bitmap, unsigned long pg_index, in write_sb_page() argument
282 struct mddev *mddev = bitmap->mddev; in write_sb_page()
288 if (__write_sb_page(rdev, bitmap, pg_index, page) < 0) { in write_sb_page()
289 set_bit(BITMAP_WRITE_ERROR, &bitmap->flags); in write_sb_page()
296 static void md_bitmap_file_kick(struct bitmap *bitmap);
299 static void write_file_page(struct bitmap *bitmap, struct page *page, int wait) in write_file_page() argument
304 atomic_inc(&bitmap->pending_writes); in write_file_page()
312 wait_event(bitmap->write_wait, in write_file_page()
313 atomic_read(&bitmap->pending_writes) == 0); in write_file_page()
318 struct bitmap *bitmap = bh->b_private; in end_bitmap_write() local
321 set_bit(BITMAP_WRITE_ERROR, &bitmap->flags); in end_bitmap_write()
322 if (atomic_dec_and_test(&bitmap->pending_writes)) in end_bitmap_write()
323 wake_up(&bitmap->write_wait); in end_bitmap_write()
351 struct bitmap *bitmap, unsigned long count, struct page *page) in read_file_page() argument
359 pr_debug("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE, in read_file_page()
390 bh->b_private = bitmap; in read_file_page()
391 atomic_inc(&bitmap->pending_writes); in read_file_page()
400 wait_event(bitmap->write_wait, in read_file_page()
401 atomic_read(&bitmap->pending_writes)==0); in read_file_page()
402 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in read_file_page()
406 pr_err("md: bitmap read error: (%dB @ %llu): %d\n", in read_file_page()
413 static void write_file_page(struct bitmap *bitmap, struct page *page, int wait) in write_file_page() argument
417 struct bitmap *bitmap, unsigned long count, struct page *page) in read_file_page() argument
428 * bitmap file superblock operations
434 static void filemap_write_page(struct bitmap *bitmap, unsigned long pg_index, in filemap_write_page() argument
437 struct bitmap_storage *store = &bitmap->storage; in filemap_write_page()
440 if (mddev_is_clustered(bitmap->mddev)) { in filemap_write_page()
441 pg_index += bitmap->cluster_slot * in filemap_write_page()
446 write_file_page(bitmap, page, wait); in filemap_write_page()
448 write_sb_page(bitmap, pg_index, page, wait); in filemap_write_page()
452 * md_bitmap_wait_writes() should be called before writing any bitmap
456 static void md_bitmap_wait_writes(struct bitmap *bitmap) in md_bitmap_wait_writes() argument
458 if (bitmap->storage.file) in md_bitmap_wait_writes()
459 wait_event(bitmap->write_wait, in md_bitmap_wait_writes()
460 atomic_read(&bitmap->pending_writes)==0); in md_bitmap_wait_writes()
465 * which is safe. The relevant bitmap blocks will in md_bitmap_wait_writes()
469 md_super_wait(bitmap->mddev); in md_bitmap_wait_writes()
474 void md_bitmap_update_sb(struct bitmap *bitmap) in md_bitmap_update_sb() argument
478 if (!bitmap || !bitmap->mddev) /* no bitmap for this array */ in md_bitmap_update_sb()
480 if (bitmap->mddev->bitmap_info.external) in md_bitmap_update_sb()
482 if (!bitmap->storage.sb_page) /* no superblock */ in md_bitmap_update_sb()
484 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_update_sb()
485 sb->events = cpu_to_le64(bitmap->mddev->events); in md_bitmap_update_sb()
486 if (bitmap->mddev->events < bitmap->events_cleared) in md_bitmap_update_sb()
488 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_update_sb()
489 sb->events_cleared = cpu_to_le64(bitmap->events_cleared); in md_bitmap_update_sb()
492 * a bitmap write error occurred but the later writes succeeded. in md_bitmap_update_sb()
494 sb->state = cpu_to_le32(bitmap->flags & ~BIT(BITMAP_WRITE_ERROR)); in md_bitmap_update_sb()
496 sb->daemon_sleep = cpu_to_le32(bitmap->mddev->bitmap_info.daemon_sleep/HZ); in md_bitmap_update_sb()
497 sb->write_behind = cpu_to_le32(bitmap->mddev->bitmap_info.max_write_behind); in md_bitmap_update_sb()
499 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in md_bitmap_update_sb()
500 sb->chunksize = cpu_to_le32(bitmap->mddev->bitmap_info.chunksize); in md_bitmap_update_sb()
501 sb->nodes = cpu_to_le32(bitmap->mddev->bitmap_info.nodes); in md_bitmap_update_sb()
502 sb->sectors_reserved = cpu_to_le32(bitmap->mddev-> in md_bitmap_update_sb()
506 if (bitmap->storage.file) in md_bitmap_update_sb()
507 write_file_page(bitmap, bitmap->storage.sb_page, 1); in md_bitmap_update_sb()
509 write_sb_page(bitmap, bitmap->storage.sb_index, in md_bitmap_update_sb()
510 bitmap->storage.sb_page, 1); in md_bitmap_update_sb()
514 /* print out the bitmap file superblock */
515 void md_bitmap_print_sb(struct bitmap *bitmap) in md_bitmap_print_sb() argument
519 if (!bitmap || !bitmap->storage.sb_page) in md_bitmap_print_sb()
521 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_print_sb()
522 pr_debug("%s: bitmap file superblock:\n", bmname(bitmap)); in md_bitmap_print_sb()
545 * @bitmap
548 * reads and verifies the on-disk bitmap superblock and populates bitmap_info.
549 * This function verifies 'bitmap_info' and populates the on-disk bitmap
554 static int md_bitmap_new_disk_sb(struct bitmap *bitmap) in md_bitmap_new_disk_sb() argument
559 bitmap->storage.sb_page = alloc_page(GFP_KERNEL | __GFP_ZERO); in md_bitmap_new_disk_sb()
560 if (bitmap->storage.sb_page == NULL) in md_bitmap_new_disk_sb()
562 bitmap->storage.sb_index = 0; in md_bitmap_new_disk_sb()
564 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_new_disk_sb()
569 chunksize = bitmap->mddev->bitmap_info.chunksize; in md_bitmap_new_disk_sb()
573 pr_warn("bitmap chunksize not a power of 2\n"); in md_bitmap_new_disk_sb()
578 daemon_sleep = bitmap->mddev->bitmap_info.daemon_sleep; in md_bitmap_new_disk_sb()
584 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; in md_bitmap_new_disk_sb()
590 write_behind = bitmap->mddev->bitmap_info.max_write_behind; in md_bitmap_new_disk_sb()
594 bitmap->mddev->bitmap_info.max_write_behind = write_behind; in md_bitmap_new_disk_sb()
596 /* keep the array size field of the bitmap superblock up to date */ in md_bitmap_new_disk_sb()
597 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in md_bitmap_new_disk_sb()
599 memcpy(sb->uuid, bitmap->mddev->uuid, 16); in md_bitmap_new_disk_sb()
601 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_new_disk_sb()
602 sb->state = cpu_to_le32(bitmap->flags); in md_bitmap_new_disk_sb()
603 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_new_disk_sb()
604 sb->events_cleared = cpu_to_le64(bitmap->mddev->events); in md_bitmap_new_disk_sb()
605 bitmap->mddev->bitmap_info.nodes = 0; in md_bitmap_new_disk_sb()
612 /* read the superblock from the bitmap file and initialize some bitmap fields */
613 static int md_bitmap_read_sb(struct bitmap *bitmap) in md_bitmap_read_sb() argument
625 if (!bitmap->storage.file && !bitmap->mddev->bitmap_info.offset) { in md_bitmap_read_sb()
629 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_read_sb()
637 bitmap->storage.sb_page = sb_page; in md_bitmap_read_sb()
641 if (bitmap->cluster_slot >= 0) { in md_bitmap_read_sb()
642 sector_t bm_blocks = bitmap->mddev->resync_max_sectors; in md_bitmap_read_sb()
645 (bitmap->mddev->bitmap_info.chunksize >> 9)); in md_bitmap_read_sb()
650 offset = bitmap->cluster_slot * (bm_blocks << 3); in md_bitmap_read_sb()
652 bitmap->cluster_slot, offset); in md_bitmap_read_sb()
655 if (bitmap->storage.file) { in md_bitmap_read_sb()
656 loff_t isize = i_size_read(bitmap->storage.file->f_mapping->host); in md_bitmap_read_sb()
659 err = read_file_page(bitmap->storage.file, 0, in md_bitmap_read_sb()
660 bitmap, bytes, sb_page); in md_bitmap_read_sb()
662 err = read_sb_page(bitmap->mddev, offset, sb_page, 0, in md_bitmap_read_sb()
676 /* verify that the bitmap-specific fields are valid */ in md_bitmap_read_sb()
683 reason = "bitmap chunksize too small"; in md_bitmap_read_sb()
685 reason = "bitmap chunksize not a power of 2"; in md_bitmap_read_sb()
691 pr_warn("%s: invalid bitmap file superblock: %s\n", in md_bitmap_read_sb()
692 bmname(bitmap), reason); in md_bitmap_read_sb()
697 * Setup nodes/clustername only if bitmap version is in md_bitmap_read_sb()
702 strscpy(bitmap->mddev->bitmap_info.cluster_name, in md_bitmap_read_sb()
706 /* keep the array size field of the bitmap superblock up to date */ in md_bitmap_read_sb()
707 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in md_bitmap_read_sb()
709 if (bitmap->mddev->persistent) { in md_bitmap_read_sb()
712 * bitmap's UUID and event counter to the mddev's in md_bitmap_read_sb()
714 if (memcmp(sb->uuid, bitmap->mddev->uuid, 16)) { in md_bitmap_read_sb()
715 pr_warn("%s: bitmap superblock UUID mismatch\n", in md_bitmap_read_sb()
716 bmname(bitmap)); in md_bitmap_read_sb()
720 if (!nodes && (events < bitmap->mddev->events)) { in md_bitmap_read_sb()
721 pr_warn("%s: bitmap file is out of date (%llu < %llu) -- forcing full recovery\n", in md_bitmap_read_sb()
722 bmname(bitmap), events, in md_bitmap_read_sb()
723 (unsigned long long) bitmap->mddev->events); in md_bitmap_read_sb()
724 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_read_sb()
729 bitmap->flags |= le32_to_cpu(sb->state); in md_bitmap_read_sb()
731 set_bit(BITMAP_HOSTENDIAN, &bitmap->flags); in md_bitmap_read_sb()
732 bitmap->events_cleared = le64_to_cpu(sb->events_cleared); in md_bitmap_read_sb()
737 if (err == 0 && nodes && (bitmap->cluster_slot < 0)) { in md_bitmap_read_sb()
739 bitmap->mddev->bitmap_info.chunksize = chunksize; in md_bitmap_read_sb()
740 err = md_setup_cluster(bitmap->mddev, nodes); in md_bitmap_read_sb()
743 bmname(bitmap), err); in md_bitmap_read_sb()
746 bitmap->cluster_slot = md_cluster_ops->slot_number(bitmap->mddev); in md_bitmap_read_sb()
752 if (test_bit(BITMAP_STALE, &bitmap->flags)) in md_bitmap_read_sb()
753 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_read_sb()
754 bitmap->mddev->bitmap_info.chunksize = chunksize; in md_bitmap_read_sb()
755 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; in md_bitmap_read_sb()
756 bitmap->mddev->bitmap_info.max_write_behind = write_behind; in md_bitmap_read_sb()
757 bitmap->mddev->bitmap_info.nodes = nodes; in md_bitmap_read_sb()
758 if (bitmap->mddev->bitmap_info.space == 0 || in md_bitmap_read_sb()
759 bitmap->mddev->bitmap_info.space > sectors_reserved) in md_bitmap_read_sb()
760 bitmap->mddev->bitmap_info.space = sectors_reserved; in md_bitmap_read_sb()
762 md_bitmap_print_sb(bitmap); in md_bitmap_read_sb()
763 if (bitmap->cluster_slot < 0) in md_bitmap_read_sb()
764 md_cluster_stop(bitmap->mddev); in md_bitmap_read_sb()
770 * general bitmap file operations
774 * on-disk bitmap:
776 * Use one bit per "chunk" (block set). We do the disk I/O on the bitmap
888 * bitmap_file_kick - if an error occurs while manipulating the bitmap file
892 static void md_bitmap_file_kick(struct bitmap *bitmap) in md_bitmap_file_kick() argument
894 if (!test_and_set_bit(BITMAP_STALE, &bitmap->flags)) { in md_bitmap_file_kick()
895 md_bitmap_update_sb(bitmap); in md_bitmap_file_kick()
897 if (bitmap->storage.file) { in md_bitmap_file_kick()
898 pr_warn("%s: kicking failed bitmap file %pD4 from array!\n", in md_bitmap_file_kick()
899 bmname(bitmap), bitmap->storage.file); in md_bitmap_file_kick()
902 pr_warn("%s: disabling internal bitmap due to errors\n", in md_bitmap_file_kick()
903 bmname(bitmap)); in md_bitmap_file_kick()
914 static inline void set_page_attr(struct bitmap *bitmap, int pnum, in set_page_attr() argument
917 set_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in set_page_attr()
920 static inline void clear_page_attr(struct bitmap *bitmap, int pnum, in clear_page_attr() argument
923 clear_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in clear_page_attr()
926 static inline int test_page_attr(struct bitmap *bitmap, int pnum, in test_page_attr() argument
929 return test_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in test_page_attr()
932 static inline int test_and_clear_page_attr(struct bitmap *bitmap, int pnum, in test_and_clear_page_attr() argument
936 bitmap->storage.filemap_attr); in test_and_clear_page_attr()
940 * to set (and eventually sync) a particular bit in the bitmap file
945 static void md_bitmap_file_set_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_set_bit() argument
950 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_set_bit()
951 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_file_set_bit()
955 if (mddev_is_clustered(bitmap->mddev)) in md_bitmap_file_set_bit()
956 node_offset = bitmap->cluster_slot * store->file_pages; in md_bitmap_file_set_bit()
958 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_set_bit()
961 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_set_bit()
965 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_set_bit()
972 set_page_attr(bitmap, index - node_offset, BITMAP_PAGE_DIRTY); in md_bitmap_file_set_bit()
975 static void md_bitmap_file_clear_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_clear_bit() argument
980 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_clear_bit()
981 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_file_clear_bit()
985 if (mddev_is_clustered(bitmap->mddev)) in md_bitmap_file_clear_bit()
986 node_offset = bitmap->cluster_slot * store->file_pages; in md_bitmap_file_clear_bit()
988 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_clear_bit()
991 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_clear_bit()
993 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_clear_bit()
998 if (!test_page_attr(bitmap, index - node_offset, BITMAP_PAGE_NEEDWRITE)) { in md_bitmap_file_clear_bit()
999 set_page_attr(bitmap, index - node_offset, BITMAP_PAGE_PENDING); in md_bitmap_file_clear_bit()
1000 bitmap->allclean = 0; in md_bitmap_file_clear_bit()
1004 static int md_bitmap_file_test_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_test_bit() argument
1009 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_test_bit()
1012 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_test_bit()
1015 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_test_bit()
1017 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_test_bit()
1027 * sync the dirty pages of the bitmap file to disk */
1028 void md_bitmap_unplug(struct bitmap *bitmap) in md_bitmap_unplug() argument
1034 if (!md_bitmap_enabled(bitmap)) in md_bitmap_unplug()
1039 for (i = 0; i < bitmap->storage.file_pages; i++) { in md_bitmap_unplug()
1040 dirty = test_and_clear_page_attr(bitmap, i, BITMAP_PAGE_DIRTY); in md_bitmap_unplug()
1041 need_write = test_and_clear_page_attr(bitmap, i, in md_bitmap_unplug()
1045 md_bitmap_wait_writes(bitmap); in md_bitmap_unplug()
1046 if (bitmap->mddev->queue) in md_bitmap_unplug()
1047 blk_add_trace_msg(bitmap->mddev->queue, in md_bitmap_unplug()
1050 clear_page_attr(bitmap, i, BITMAP_PAGE_PENDING); in md_bitmap_unplug()
1051 filemap_write_page(bitmap, i, false); in md_bitmap_unplug()
1056 md_bitmap_wait_writes(bitmap); in md_bitmap_unplug()
1058 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in md_bitmap_unplug()
1059 md_bitmap_file_kick(bitmap); in md_bitmap_unplug()
1065 struct bitmap *bitmap; member
1074 md_bitmap_unplug(unplug_work->bitmap); in md_bitmap_unplug_fn()
1078 void md_bitmap_unplug_async(struct bitmap *bitmap) in md_bitmap_unplug_async() argument
1084 unplug_work.bitmap = bitmap; in md_bitmap_unplug_async()
1092 static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
1095 * Initialize the in-memory bitmap from the on-disk bitmap and set up the memory
1096 * mapping of the bitmap file.
1098 * Special case: If there's no bitmap file, or if the bitmap file had been
1103 * This is used when reading an out-of-date bitmap.
1105 static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) in md_bitmap_init_from_disk() argument
1107 bool outofdate = test_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_init_from_disk()
1108 struct mddev *mddev = bitmap->mddev; in md_bitmap_init_from_disk()
1109 unsigned long chunks = bitmap->counts.chunks; in md_bitmap_init_from_disk()
1110 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_init_from_disk()
1118 /* No permanent bitmap - fill with '1s'. */ in md_bitmap_init_from_disk()
1123 int needed = ((sector_t)(i+1) << (bitmap->counts.chunkshift) in md_bitmap_init_from_disk()
1125 md_bitmap_set_memory_bits(bitmap, in md_bitmap_init_from_disk()
1126 (sector_t)i << bitmap->counts.chunkshift, in md_bitmap_init_from_disk()
1133 pr_warn("%s: bitmap file too short %lu < %lu\n", in md_bitmap_init_from_disk()
1134 bmname(bitmap), in md_bitmap_init_from_disk()
1142 node_offset = bitmap->cluster_slot * (DIV_ROUND_UP(store->bytes, PAGE_SIZE)); in md_bitmap_init_from_disk()
1155 ret = read_file_page(file, i, bitmap, count, page); in md_bitmap_init_from_disk()
1164 pr_warn("%s: bitmap file is out of date, doing full recovery\n", in md_bitmap_init_from_disk()
1165 bmname(bitmap)); in md_bitmap_init_from_disk()
1176 * If the bitmap is out of date, dirty the whole page in md_bitmap_init_from_disk()
1183 filemap_write_page(bitmap, i, true); in md_bitmap_init_from_disk()
1184 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) { in md_bitmap_init_from_disk()
1192 struct page *page = filemap_get_page(&bitmap->storage, i); in md_bitmap_init_from_disk()
1193 unsigned long bit = file_page_offset(&bitmap->storage, i); in md_bitmap_init_from_disk()
1198 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_init_from_disk()
1206 int needed = ((sector_t)(i+1) << bitmap->counts.chunkshift in md_bitmap_init_from_disk()
1208 md_bitmap_set_memory_bits(bitmap, in md_bitmap_init_from_disk()
1209 (sector_t)i << bitmap->counts.chunkshift, in md_bitmap_init_from_disk()
1215 pr_debug("%s: bitmap initialized from disk: read %lu pages, set %lu of %lu bits\n", in md_bitmap_init_from_disk()
1216 bmname(bitmap), store->file_pages, in md_bitmap_init_from_disk()
1222 pr_warn("%s: bitmap initialisation failed: %d\n", in md_bitmap_init_from_disk()
1223 bmname(bitmap), ret); in md_bitmap_init_from_disk()
1227 void md_bitmap_write_all(struct bitmap *bitmap) in md_bitmap_write_all() argument
1229 /* We don't actually write all bitmap blocks here, in md_bitmap_write_all()
1234 if (!bitmap || !bitmap->storage.filemap) in md_bitmap_write_all()
1236 if (bitmap->storage.file) in md_bitmap_write_all()
1240 for (i = 0; i < bitmap->storage.file_pages; i++) in md_bitmap_write_all()
1241 set_page_attr(bitmap, i, in md_bitmap_write_all()
1243 bitmap->allclean = 0; in md_bitmap_write_all()
1246 static void md_bitmap_count_page(struct bitmap_counts *bitmap, in md_bitmap_count_page() argument
1249 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_count_page()
1251 bitmap->bp[page].count += inc; in md_bitmap_count_page()
1252 md_bitmap_checkfree(bitmap, page); in md_bitmap_count_page()
1255 static void md_bitmap_set_pending(struct bitmap_counts *bitmap, sector_t offset) in md_bitmap_set_pending() argument
1257 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_set_pending()
1259 struct bitmap_page *bp = &bitmap->bp[page]; in md_bitmap_set_pending()
1265 static bitmap_counter_t *md_bitmap_get_counter(struct bitmap_counts *bitmap,
1288 * bitmap daemon -- periodically wakes up to clean bits and flush pages
1293 struct bitmap *bitmap; in md_bitmap_daemon_work() local
1303 bitmap = mddev->bitmap; in md_bitmap_daemon_work()
1304 if (bitmap == NULL) { in md_bitmap_daemon_work()
1308 if (time_before(jiffies, bitmap->daemon_lastrun in md_bitmap_daemon_work()
1312 bitmap->daemon_lastrun = jiffies; in md_bitmap_daemon_work()
1313 if (bitmap->allclean) { in md_bitmap_daemon_work()
1317 bitmap->allclean = 1; in md_bitmap_daemon_work()
1319 if (bitmap->mddev->queue) in md_bitmap_daemon_work()
1320 blk_add_trace_msg(bitmap->mddev->queue, in md_bitmap_daemon_work()
1327 for (j = 0; j < bitmap->storage.file_pages; j++) in md_bitmap_daemon_work()
1328 if (test_and_clear_page_attr(bitmap, j, in md_bitmap_daemon_work()
1330 set_page_attr(bitmap, j, in md_bitmap_daemon_work()
1333 if (bitmap->need_sync && in md_bitmap_daemon_work()
1338 bitmap->need_sync = 0; in md_bitmap_daemon_work()
1339 if (bitmap->storage.filemap) { in md_bitmap_daemon_work()
1340 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_daemon_work()
1342 cpu_to_le64(bitmap->events_cleared); in md_bitmap_daemon_work()
1344 set_page_attr(bitmap, 0, in md_bitmap_daemon_work()
1348 /* Now look at the bitmap counters and if any are '2' or '1', in md_bitmap_daemon_work()
1351 counts = &bitmap->counts; in md_bitmap_daemon_work()
1372 if (*bmc == 1 && !bitmap->need_sync) { in md_bitmap_daemon_work()
1376 md_bitmap_file_clear_bit(bitmap, block); in md_bitmap_daemon_work()
1380 bitmap->allclean = 0; in md_bitmap_daemon_work()
1385 md_bitmap_wait_writes(bitmap); in md_bitmap_daemon_work()
1395 j < bitmap->storage.file_pages in md_bitmap_daemon_work()
1396 && !test_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_daemon_work()
1398 if (test_page_attr(bitmap, j, in md_bitmap_daemon_work()
1402 if (bitmap->storage.filemap && in md_bitmap_daemon_work()
1403 test_and_clear_page_attr(bitmap, j, in md_bitmap_daemon_work()
1405 filemap_write_page(bitmap, j, false); in md_bitmap_daemon_work()
1409 if (bitmap->allclean == 0) in md_bitmap_daemon_work()
1414 static bitmap_counter_t *md_bitmap_get_counter(struct bitmap_counts *bitmap, in md_bitmap_get_counter() argument
1417 __releases(bitmap->lock) in md_bitmap_get_counter()
1418 __acquires(bitmap->lock) in md_bitmap_get_counter()
1424 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_get_counter()
1430 if (page >= bitmap->pages) { in md_bitmap_get_counter()
1438 err = md_bitmap_checkpage(bitmap, page, create, 0); in md_bitmap_get_counter()
1440 if (bitmap->bp[page].hijacked || in md_bitmap_get_counter()
1441 bitmap->bp[page].map == NULL) in md_bitmap_get_counter()
1442 csize = ((sector_t)1) << (bitmap->chunkshift + in md_bitmap_get_counter()
1445 csize = ((sector_t)1) << bitmap->chunkshift; in md_bitmap_get_counter()
1453 if (bitmap->bp[page].hijacked) { /* hijacked pointer */ in md_bitmap_get_counter()
1458 &bitmap->bp[page].map)[hi]; in md_bitmap_get_counter()
1461 &(bitmap->bp[page].map[pageoff]); in md_bitmap_get_counter()
1464 int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind) in md_bitmap_startwrite() argument
1466 if (!bitmap) in md_bitmap_startwrite()
1471 atomic_inc(&bitmap->behind_writes); in md_bitmap_startwrite()
1472 bw = atomic_read(&bitmap->behind_writes); in md_bitmap_startwrite()
1473 if (bw > bitmap->behind_writes_used) in md_bitmap_startwrite()
1474 bitmap->behind_writes_used = bw; in md_bitmap_startwrite()
1477 bw, bitmap->mddev->bitmap_info.max_write_behind); in md_bitmap_startwrite()
1484 spin_lock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1485 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &blocks, 1); in md_bitmap_startwrite()
1487 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1497 prepare_to_wait(&bitmap->overflow_wait, &__wait, in md_bitmap_startwrite()
1499 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1501 finish_wait(&bitmap->overflow_wait, &__wait); in md_bitmap_startwrite()
1507 md_bitmap_file_set_bit(bitmap, offset); in md_bitmap_startwrite()
1508 md_bitmap_count_page(&bitmap->counts, offset, 1); in md_bitmap_startwrite()
1516 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1528 void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset, in md_bitmap_endwrite() argument
1531 if (!bitmap) in md_bitmap_endwrite()
1534 if (atomic_dec_and_test(&bitmap->behind_writes)) in md_bitmap_endwrite()
1535 wake_up(&bitmap->behind_wait); in md_bitmap_endwrite()
1537 atomic_read(&bitmap->behind_writes), in md_bitmap_endwrite()
1538 bitmap->mddev->bitmap_info.max_write_behind); in md_bitmap_endwrite()
1546 spin_lock_irqsave(&bitmap->counts.lock, flags); in md_bitmap_endwrite()
1547 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &blocks, 0); in md_bitmap_endwrite()
1549 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in md_bitmap_endwrite()
1553 if (success && !bitmap->mddev->degraded && in md_bitmap_endwrite()
1554 bitmap->events_cleared < bitmap->mddev->events) { in md_bitmap_endwrite()
1555 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_endwrite()
1556 bitmap->need_sync = 1; in md_bitmap_endwrite()
1557 sysfs_notify_dirent_safe(bitmap->sysfs_can_clear); in md_bitmap_endwrite()
1564 wake_up(&bitmap->overflow_wait); in md_bitmap_endwrite()
1568 md_bitmap_set_pending(&bitmap->counts, offset); in md_bitmap_endwrite()
1569 bitmap->allclean = 0; in md_bitmap_endwrite()
1571 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in md_bitmap_endwrite()
1581 static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, in __bitmap_start_sync() argument
1586 if (bitmap == NULL) {/* FIXME or bitmap set as 'failed' */ in __bitmap_start_sync()
1588 return 1; /* always resync if no bitmap */ in __bitmap_start_sync()
1590 spin_lock_irq(&bitmap->counts.lock); in __bitmap_start_sync()
1591 bmc = md_bitmap_get_counter(&bitmap->counts, offset, blocks, 0); in __bitmap_start_sync()
1605 spin_unlock_irq(&bitmap->counts.lock); in __bitmap_start_sync()
1609 int md_bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, in md_bitmap_start_sync() argument
1624 rv |= __bitmap_start_sync(bitmap, offset, in md_bitmap_start_sync()
1633 void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted) in md_bitmap_end_sync() argument
1638 if (bitmap == NULL) { in md_bitmap_end_sync()
1642 spin_lock_irqsave(&bitmap->counts.lock, flags); in md_bitmap_end_sync()
1643 bmc = md_bitmap_get_counter(&bitmap->counts, offset, blocks, 0); in md_bitmap_end_sync()
1654 md_bitmap_set_pending(&bitmap->counts, offset); in md_bitmap_end_sync()
1655 bitmap->allclean = 0; in md_bitmap_end_sync()
1660 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in md_bitmap_end_sync()
1664 void md_bitmap_close_sync(struct bitmap *bitmap) in md_bitmap_close_sync() argument
1666 /* Sync has finished, and any bitmap chunks that weren't synced in md_bitmap_close_sync()
1672 if (!bitmap) in md_bitmap_close_sync()
1674 while (sector < bitmap->mddev->resync_max_sectors) { in md_bitmap_close_sync()
1675 md_bitmap_end_sync(bitmap, sector, &blocks, 0); in md_bitmap_close_sync()
1681 void md_bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force) in md_bitmap_cond_end_sync() argument
1686 if (!bitmap) in md_bitmap_cond_end_sync()
1689 bitmap->last_end_sync = jiffies; in md_bitmap_cond_end_sync()
1692 if (!force && time_before(jiffies, (bitmap->last_end_sync in md_bitmap_cond_end_sync()
1693 + bitmap->mddev->bitmap_info.daemon_sleep))) in md_bitmap_cond_end_sync()
1695 wait_event(bitmap->mddev->recovery_wait, in md_bitmap_cond_end_sync()
1696 atomic_read(&bitmap->mddev->recovery_active) == 0); in md_bitmap_cond_end_sync()
1698 bitmap->mddev->curr_resync_completed = sector; in md_bitmap_cond_end_sync()
1699 set_bit(MD_SB_CHANGE_CLEAN, &bitmap->mddev->sb_flags); in md_bitmap_cond_end_sync()
1700 sector &= ~((1ULL << bitmap->counts.chunkshift) - 1); in md_bitmap_cond_end_sync()
1702 while (s < sector && s < bitmap->mddev->resync_max_sectors) { in md_bitmap_cond_end_sync()
1703 md_bitmap_end_sync(bitmap, s, &blocks, 0); in md_bitmap_cond_end_sync()
1706 bitmap->last_end_sync = jiffies; in md_bitmap_cond_end_sync()
1707 sysfs_notify_dirent_safe(bitmap->mddev->sysfs_completed); in md_bitmap_cond_end_sync()
1715 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_sync_with_cluster() local
1719 md_bitmap_end_sync(bitmap, sector, &blocks, 0); in md_bitmap_sync_with_cluster()
1725 md_bitmap_start_sync(bitmap, sector, &blocks, 0); in md_bitmap_sync_with_cluster()
1732 static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed) in md_bitmap_set_memory_bits() argument
1741 spin_lock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1742 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &secs, 1); in md_bitmap_set_memory_bits()
1744 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1749 md_bitmap_count_page(&bitmap->counts, offset, 1); in md_bitmap_set_memory_bits()
1750 md_bitmap_set_pending(&bitmap->counts, offset); in md_bitmap_set_memory_bits()
1751 bitmap->allclean = 0; in md_bitmap_set_memory_bits()
1755 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1758 /* dirty the memory and file bits for bitmap chunks "s" to "e" */
1759 void md_bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e) in md_bitmap_dirty_bits() argument
1764 sector_t sec = (sector_t)chunk << bitmap->counts.chunkshift; in md_bitmap_dirty_bits()
1765 md_bitmap_set_memory_bits(bitmap, sec, 1); in md_bitmap_dirty_bits()
1766 md_bitmap_file_set_bit(bitmap, sec); in md_bitmap_dirty_bits()
1767 if (sec < bitmap->mddev->recovery_cp) in md_bitmap_dirty_bits()
1772 bitmap->mddev->recovery_cp = sec; in md_bitmap_dirty_bits()
1781 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_flush() local
1784 if (!bitmap) /* there was no bitmap */ in md_bitmap_flush()
1791 bitmap->daemon_lastrun -= sleep; in md_bitmap_flush()
1793 bitmap->daemon_lastrun -= sleep; in md_bitmap_flush()
1795 bitmap->daemon_lastrun -= sleep; in md_bitmap_flush()
1799 md_bitmap_update_sb(bitmap); in md_bitmap_flush()
1805 void md_bitmap_free(struct bitmap *bitmap) in md_bitmap_free() argument
1810 if (!bitmap) /* there was no bitmap */ in md_bitmap_free()
1813 if (bitmap->sysfs_can_clear) in md_bitmap_free()
1814 sysfs_put(bitmap->sysfs_can_clear); in md_bitmap_free()
1816 if (mddev_is_clustered(bitmap->mddev) && bitmap->mddev->cluster_info && in md_bitmap_free()
1817 bitmap->cluster_slot == md_cluster_ops->slot_number(bitmap->mddev)) in md_bitmap_free()
1818 md_cluster_stop(bitmap->mddev); in md_bitmap_free()
1821 wait_event(bitmap->write_wait, in md_bitmap_free()
1822 atomic_read(&bitmap->pending_writes) == 0); in md_bitmap_free()
1824 /* release the bitmap file */ in md_bitmap_free()
1825 md_bitmap_file_unmap(&bitmap->storage); in md_bitmap_free()
1827 bp = bitmap->counts.bp; in md_bitmap_free()
1828 pages = bitmap->counts.pages; in md_bitmap_free()
1837 kfree(bitmap); in md_bitmap_free()
1843 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_wait_behind_writes() local
1846 if (bitmap && atomic_read(&bitmap->behind_writes) > 0) { in md_bitmap_wait_behind_writes()
1850 wait_event(bitmap->behind_wait, in md_bitmap_wait_behind_writes()
1851 atomic_read(&bitmap->behind_writes) == 0); in md_bitmap_wait_behind_writes()
1857 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_destroy() local
1859 if (!bitmap) /* there was no bitmap */ in md_bitmap_destroy()
1868 mddev->bitmap = NULL; /* disconnect from the md device */ in md_bitmap_destroy()
1873 md_bitmap_free(bitmap); in md_bitmap_destroy()
1877 * initialize the bitmap structure
1879 * once mddev->bitmap is set
1881 struct bitmap *md_bitmap_create(struct mddev *mddev, int slot) in md_bitmap_create()
1883 struct bitmap *bitmap; in md_bitmap_create() local
1894 pr_notice("md/raid:%s: array with journal cannot have bitmap\n", in md_bitmap_create()
1899 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL); in md_bitmap_create()
1900 if (!bitmap) in md_bitmap_create()
1903 spin_lock_init(&bitmap->counts.lock); in md_bitmap_create()
1904 atomic_set(&bitmap->pending_writes, 0); in md_bitmap_create()
1905 init_waitqueue_head(&bitmap->write_wait); in md_bitmap_create()
1906 init_waitqueue_head(&bitmap->overflow_wait); in md_bitmap_create()
1907 init_waitqueue_head(&bitmap->behind_wait); in md_bitmap_create()
1909 bitmap->mddev = mddev; in md_bitmap_create()
1910 bitmap->cluster_slot = slot; in md_bitmap_create()
1913 bm = sysfs_get_dirent(mddev->kobj.sd, "bitmap"); in md_bitmap_create()
1915 bitmap->sysfs_can_clear = sysfs_get_dirent(bm, "can_clear"); in md_bitmap_create()
1918 bitmap->sysfs_can_clear = NULL; in md_bitmap_create()
1920 bitmap->storage.file = file; in md_bitmap_create()
1929 /* read superblock from bitmap file (this sets mddev->bitmap_info.chunksize) */ in md_bitmap_create()
1933 * instructing us to create a new on-disk bitmap instance. in md_bitmap_create()
1936 err = md_bitmap_new_disk_sb(bitmap); in md_bitmap_create()
1938 err = md_bitmap_read_sb(bitmap); in md_bitmap_create()
1950 bitmap->daemon_lastrun = jiffies; in md_bitmap_create()
1951 err = md_bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize, 1); in md_bitmap_create()
1955 pr_debug("created bitmap (%lu pages) for device %s\n", in md_bitmap_create()
1956 bitmap->counts.pages, bmname(bitmap)); in md_bitmap_create()
1958 err = test_bit(BITMAP_WRITE_ERROR, &bitmap->flags) ? -EIO : 0; in md_bitmap_create()
1962 return bitmap; in md_bitmap_create()
1964 md_bitmap_free(bitmap); in md_bitmap_create()
1973 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_load() local
1976 if (!bitmap) in md_bitmap_load()
1985 /* Clear out old bitmap info first: Either there is none, or we in md_bitmap_load()
1992 md_bitmap_start_sync(bitmap, sector, &blocks, 0); in md_bitmap_load()
1995 md_bitmap_close_sync(bitmap); in md_bitmap_load()
1998 || bitmap->events_cleared == mddev->events) in md_bitmap_load()
2004 err = md_bitmap_init_from_disk(bitmap, start); in md_bitmap_load()
2009 clear_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_load()
2012 set_bit(MD_RECOVERY_NEEDED, &bitmap->mddev->recovery); in md_bitmap_load()
2017 md_bitmap_update_sb(bitmap); in md_bitmap_load()
2019 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in md_bitmap_load()
2026 /* caller need to free returned bitmap with md_bitmap_free() */
2027 struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot) in get_bitmap_from_slot()
2030 struct bitmap *bitmap; in get_bitmap_from_slot() local
2032 bitmap = md_bitmap_create(mddev, slot); in get_bitmap_from_slot()
2033 if (IS_ERR(bitmap)) { in get_bitmap_from_slot()
2034 rv = PTR_ERR(bitmap); in get_bitmap_from_slot()
2038 rv = md_bitmap_init_from_disk(bitmap, 0); in get_bitmap_from_slot()
2040 md_bitmap_free(bitmap); in get_bitmap_from_slot()
2044 return bitmap; in get_bitmap_from_slot()
2048 /* Loads the bitmap associated with slot and copies the resync information
2049 * to our bitmap
2057 struct bitmap *bitmap; in md_bitmap_copy_from_slot() local
2059 bitmap = get_bitmap_from_slot(mddev, slot); in md_bitmap_copy_from_slot()
2060 if (IS_ERR(bitmap)) { in md_bitmap_copy_from_slot()
2061 pr_err("%s can't get bitmap from slot %d\n", __func__, slot); in md_bitmap_copy_from_slot()
2065 counts = &bitmap->counts; in md_bitmap_copy_from_slot()
2068 if (md_bitmap_file_test_bit(bitmap, block)) { in md_bitmap_copy_from_slot()
2072 md_bitmap_file_clear_bit(bitmap, block); in md_bitmap_copy_from_slot()
2073 md_bitmap_set_memory_bits(mddev->bitmap, block, 1); in md_bitmap_copy_from_slot()
2074 md_bitmap_file_set_bit(mddev->bitmap, block); in md_bitmap_copy_from_slot()
2079 md_bitmap_update_sb(bitmap); in md_bitmap_copy_from_slot()
2082 for (i = 0; i < bitmap->storage.file_pages; i++) in md_bitmap_copy_from_slot()
2083 if (test_page_attr(bitmap, i, BITMAP_PAGE_PENDING)) in md_bitmap_copy_from_slot()
2084 set_page_attr(bitmap, i, BITMAP_PAGE_NEEDWRITE); in md_bitmap_copy_from_slot()
2085 md_bitmap_unplug(bitmap); in md_bitmap_copy_from_slot()
2087 md_bitmap_unplug(mddev->bitmap); in md_bitmap_copy_from_slot()
2090 md_bitmap_free(bitmap); in md_bitmap_copy_from_slot()
2097 void md_bitmap_status(struct seq_file *seq, struct bitmap *bitmap) in md_bitmap_status() argument
2102 if (!bitmap) in md_bitmap_status()
2105 counts = &bitmap->counts; in md_bitmap_status()
2107 chunk_kb = bitmap->mddev->bitmap_info.chunksize >> 10; in md_bitmap_status()
2108 seq_printf(seq, "bitmap: %lu/%lu pages [%luKB], " in md_bitmap_status()
2114 chunk_kb ? chunk_kb : bitmap->mddev->bitmap_info.chunksize, in md_bitmap_status()
2116 if (bitmap->storage.file) { in md_bitmap_status()
2118 seq_file_path(seq, bitmap->storage.file, " \t\n"); in md_bitmap_status()
2124 int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks, in md_bitmap_resize() argument
2129 * Then quiesce, copy bits, replace bitmap, and re-start in md_bitmap_resize()
2131 * This function is called both to set up the initial bitmap in md_bitmap_resize()
2132 * and to resize the bitmap while the array is active. in md_bitmap_resize()
2147 if (bitmap->storage.file && !init) { in md_bitmap_resize()
2148 pr_info("md: cannot resize file-based bitmap\n"); in md_bitmap_resize()
2157 long space = bitmap->mddev->bitmap_info.space; in md_bitmap_resize()
2163 bytes = DIV_ROUND_UP(bitmap->counts.chunks, 8); in md_bitmap_resize()
2164 if (!bitmap->mddev->bitmap_info.external) in md_bitmap_resize()
2167 bitmap->mddev->bitmap_info.space = space; in md_bitmap_resize()
2169 chunkshift = bitmap->counts.chunkshift; in md_bitmap_resize()
2176 if (!bitmap->mddev->bitmap_info.external) in md_bitmap_resize()
2185 if (bitmap->mddev->bitmap_info.offset || bitmap->mddev->bitmap_info.file) in md_bitmap_resize()
2187 !bitmap->mddev->bitmap_info.external, in md_bitmap_resize()
2188 mddev_is_clustered(bitmap->mddev) in md_bitmap_resize()
2189 ? bitmap->cluster_slot : 0); in md_bitmap_resize()
2205 bitmap->mddev->pers->quiesce(bitmap->mddev, 1); in md_bitmap_resize()
2207 store.file = bitmap->storage.file; in md_bitmap_resize()
2208 bitmap->storage.file = NULL; in md_bitmap_resize()
2210 if (store.sb_page && bitmap->storage.sb_page) in md_bitmap_resize()
2212 page_address(bitmap->storage.sb_page), in md_bitmap_resize()
2214 spin_lock_irq(&bitmap->counts.lock); in md_bitmap_resize()
2215 md_bitmap_file_unmap(&bitmap->storage); in md_bitmap_resize()
2216 bitmap->storage = store; in md_bitmap_resize()
2218 old_counts = bitmap->counts; in md_bitmap_resize()
2219 bitmap->counts.bp = new_bp; in md_bitmap_resize()
2220 bitmap->counts.pages = pages; in md_bitmap_resize()
2221 bitmap->counts.missing_pages = pages; in md_bitmap_resize()
2222 bitmap->counts.chunkshift = chunkshift; in md_bitmap_resize()
2223 bitmap->counts.chunks = chunks; in md_bitmap_resize()
2224 bitmap->mddev->bitmap_info.chunksize = 1UL << (chunkshift + in md_bitmap_resize()
2230 /* For cluster raid, need to pre-allocate bitmap */ in md_bitmap_resize()
2231 if (mddev_is_clustered(bitmap->mddev)) { in md_bitmap_resize()
2234 ret = md_bitmap_checkpage(&bitmap->counts, page, 1, 1); in md_bitmap_resize()
2245 bitmap->counts.bp = old_counts.bp; in md_bitmap_resize()
2246 bitmap->counts.pages = old_counts.pages; in md_bitmap_resize()
2247 bitmap->counts.missing_pages = old_counts.pages; in md_bitmap_resize()
2248 bitmap->counts.chunkshift = old_counts.chunkshift; in md_bitmap_resize()
2249 bitmap->counts.chunks = old_counts.chunks; in md_bitmap_resize()
2250 bitmap->mddev->bitmap_info.chunksize = in md_bitmap_resize()
2253 pr_warn("Could not pre-allocate in-memory bitmap for cluster raid\n"); in md_bitmap_resize()
2256 bitmap->counts.bp[page].count += 1; in md_bitmap_resize()
2268 bmc_new = md_bitmap_get_counter(&bitmap->counts, block, &new_blocks, 1); in md_bitmap_resize()
2277 md_bitmap_file_set_bit(bitmap, block); in md_bitmap_resize()
2281 md_bitmap_count_page(&bitmap->counts, block, 1); in md_bitmap_resize()
2282 md_bitmap_set_pending(&bitmap->counts, block); in md_bitmap_resize()
2292 if (bitmap->counts.bp != old_counts.bp) { in md_bitmap_resize()
2304 bmc = md_bitmap_get_counter(&bitmap->counts, block, &new_blocks, 1); in md_bitmap_resize()
2311 md_bitmap_count_page(&bitmap->counts, block, 1); in md_bitmap_resize()
2312 md_bitmap_set_pending(&bitmap->counts, block); in md_bitmap_resize()
2317 for (i = 0; i < bitmap->storage.file_pages; i++) in md_bitmap_resize()
2318 set_page_attr(bitmap, i, BITMAP_PAGE_DIRTY); in md_bitmap_resize()
2320 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_resize()
2323 md_bitmap_unplug(bitmap); in md_bitmap_resize()
2324 bitmap->mddev->pers->quiesce(bitmap->mddev, 0); in md_bitmap_resize()
2362 if (mddev->bitmap || mddev->bitmap_info.file || in location_store()
2364 /* bitmap already configured. Only option is to clear it */ in location_store()
2378 /* No bitmap, OK to set a location */ in location_store()
2380 struct bitmap *bitmap; in location_store() local
2407 bitmap = md_bitmap_create(mddev, -1); in location_store()
2408 if (IS_ERR(bitmap)) { in location_store()
2409 rv = PTR_ERR(bitmap); in location_store()
2413 mddev->bitmap = bitmap; in location_store()
2423 /* Ensure new bitmap info is stored in in location_store()
2440 /* 'bitmap/space' is the space available at 'location' for the
2441 * bitmap. This allows the kernel to know when it is safe to
2442 * resize the bitmap to match a resized array.
2463 if (mddev->bitmap && in space_store()
2464 sectors < (mddev->bitmap->storage.bytes + 511) >> 9) in space_store()
2465 return -EFBIG; /* Bitmap is too big for this small space */ in space_store()
2572 md_bitmap_update_sb(mddev->bitmap); in backlog_store()
2590 /* Can only be changed when no bitmap is active */ in chunksize_store()
2593 if (mddev->bitmap) in chunksize_store()
2621 if (mddev->bitmap || in metadata_store()
2642 if (mddev->bitmap) in can_clear_show()
2643 len = sprintf(page, "%s\n", (mddev->bitmap->need_sync ? in can_clear_show()
2653 if (mddev->bitmap == NULL) in can_clear_store()
2656 mddev->bitmap->need_sync = 1; in can_clear_store()
2660 mddev->bitmap->need_sync = 0; in can_clear_store()
2674 if (mddev->bitmap == NULL) in behind_writes_used_show()
2678 mddev->bitmap->behind_writes_used); in behind_writes_used_show()
2686 if (mddev->bitmap) in behind_writes_used_reset()
2687 mddev->bitmap->behind_writes_used = 0; in behind_writes_used_reset()
2707 .name = "bitmap",