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
34 #include "md-bitmap.h"
38 * in-memory bitmap:
126 * bitmap structures:
129 /* the in-memory bitmap is represented by bitmap_pages */
151 /* the main bitmap structure - one per mddev */
152 struct bitmap { struct
157 /* total number of pages in the bitmap */
167 struct mddev *mddev; /* the md device that the bitmap is for */ argument
175 /* cached copy of the bitmap file superblock */ argument
184 /* total bytes in the bitmap */
197 * the bitmap daemon - periodically wakes up and sweeps the bitmap argument
202 * when we lasted called end_sync to update bitmap with resync argument
207 /* pending writes to the bitmap file */ argument
220 static int __bitmap_resize(struct bitmap *bitmap, sector_t blocks, argument
223 static inline char *bmname(struct bitmap *bitmap) in bmname() argument
225 return bitmap->mddev ? mdname(bitmap->mddev) : "mdX"; in bmname()
230 struct bitmap *bitmap = data; in bitmap_enabled() local
236 * If caller want to flush bitmap pages to underlying disks, check if in bitmap_enabled()
239 return !test_bit(BITMAP_STALE, &bitmap->flags) && in bitmap_enabled()
240 bitmap->storage.filemap != NULL; in bitmap_enabled()
253 static int md_bitmap_checkpage(struct bitmap_counts *bitmap, in md_bitmap_checkpage() argument
255 __releases(bitmap->lock) in md_bitmap_checkpage()
256 __acquires(bitmap->lock) in md_bitmap_checkpage()
260 WARN_ON_ONCE(page >= bitmap->pages); in md_bitmap_checkpage()
261 if (bitmap->bp[page].hijacked) /* it's hijacked, don't try to alloc */ in md_bitmap_checkpage()
264 if (bitmap->bp[page].map) /* page is already allocated, just return */ in md_bitmap_checkpage()
272 spin_unlock_irq(&bitmap->lock); in md_bitmap_checkpage()
287 spin_lock_irq(&bitmap->lock); in md_bitmap_checkpage()
290 pr_debug("md/bitmap: map page allocation failed, hijacking\n"); in md_bitmap_checkpage()
296 if (!bitmap->bp[page].map) in md_bitmap_checkpage()
297 bitmap->bp[page].hijacked = 1; in md_bitmap_checkpage()
298 } else if (bitmap->bp[page].map || in md_bitmap_checkpage()
299 bitmap->bp[page].hijacked) { in md_bitmap_checkpage()
306 bitmap->bp[page].map = mappage; in md_bitmap_checkpage()
307 bitmap->missing_pages--; in md_bitmap_checkpage()
315 static void md_bitmap_checkfree(struct bitmap_counts *bitmap, unsigned long page) in md_bitmap_checkfree() argument
319 if (bitmap->bp[page].count) /* page is still busy */ in md_bitmap_checkfree()
324 if (bitmap->bp[page].hijacked) { /* page was hijacked, undo this now */ in md_bitmap_checkfree()
325 bitmap->bp[page].hijacked = 0; in md_bitmap_checkfree()
326 bitmap->bp[page].map = NULL; in md_bitmap_checkfree()
329 ptr = bitmap->bp[page].map; in md_bitmap_checkfree()
330 bitmap->bp[page].map = NULL; in md_bitmap_checkfree()
331 bitmap->missing_pages++; in md_bitmap_checkfree()
337 * bitmap file handling - read and write the bitmap file and its superblock
344 /* IO operations when bitmap is stored near all superblocks */
427 static int __write_sb_page(struct md_rdev *rdev, struct bitmap *bitmap, in __write_sb_page() argument
431 struct mddev *mddev = bitmap->mddev; in __write_sb_page()
432 struct bitmap_storage *store = &bitmap->storage; in __write_sb_page()
433 unsigned long num_pages = bitmap->storage.file_pages; in __write_sb_page()
457 /* Bitmap could be anywhere. */ in __write_sb_page()
462 /* DATA BITMAP METADATA */ in __write_sb_page()
465 /* bitmap runs in to metadata */ in __write_sb_page()
469 /* data runs in to bitmap */ in __write_sb_page()
472 /* METADATA BITMAP DATA */ in __write_sb_page()
475 /* bitmap runs in to data */ in __write_sb_page()
484 static void write_sb_page(struct bitmap *bitmap, unsigned long pg_index, in write_sb_page() argument
487 struct mddev *mddev = bitmap->mddev; in write_sb_page()
493 if (__write_sb_page(rdev, bitmap, pg_index, page) < 0) { in write_sb_page()
494 set_bit(BITMAP_WRITE_ERROR, &bitmap->flags); in write_sb_page()
501 static void md_bitmap_file_kick(struct bitmap *bitmap);
504 static void write_file_page(struct bitmap *bitmap, struct page *page, int wait) in write_file_page() argument
509 atomic_inc(&bitmap->pending_writes); in write_file_page()
517 wait_event(bitmap->write_wait, in write_file_page()
518 atomic_read(&bitmap->pending_writes) == 0); in write_file_page()
523 struct bitmap *bitmap = bh->b_private; in end_bitmap_write() local
526 set_bit(BITMAP_WRITE_ERROR, &bitmap->flags); in end_bitmap_write()
527 if (atomic_dec_and_test(&bitmap->pending_writes)) in end_bitmap_write()
528 wake_up(&bitmap->write_wait); in end_bitmap_write()
556 struct bitmap *bitmap, unsigned long count, struct page *page) in read_file_page() argument
564 pr_debug("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE, in read_file_page()
595 bh->b_private = bitmap; in read_file_page()
596 atomic_inc(&bitmap->pending_writes); in read_file_page()
605 wait_event(bitmap->write_wait, in read_file_page()
606 atomic_read(&bitmap->pending_writes)==0); in read_file_page()
607 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in read_file_page()
611 pr_err("md: bitmap read error: (%dB @ %llu): %d\n", in read_file_page()
618 static void write_file_page(struct bitmap *bitmap, struct page *page, int wait) in write_file_page() argument
622 struct bitmap *bitmap, unsigned long count, struct page *page) in read_file_page() argument
633 * bitmap file superblock operations
639 static void filemap_write_page(struct bitmap *bitmap, unsigned long pg_index, in filemap_write_page() argument
642 struct bitmap_storage *store = &bitmap->storage; in filemap_write_page()
645 if (mddev_is_clustered(bitmap->mddev)) { in filemap_write_page()
646 /* go to node bitmap area starting point */ in filemap_write_page()
651 write_file_page(bitmap, page, wait); in filemap_write_page()
653 write_sb_page(bitmap, pg_index, page, wait); in filemap_write_page()
657 * md_bitmap_wait_writes() should be called before writing any bitmap
661 static void md_bitmap_wait_writes(struct bitmap *bitmap) in md_bitmap_wait_writes() argument
663 if (bitmap->storage.file) in md_bitmap_wait_writes()
664 wait_event(bitmap->write_wait, in md_bitmap_wait_writes()
665 atomic_read(&bitmap->pending_writes)==0); in md_bitmap_wait_writes()
670 * which is safe. The relevant bitmap blocks will in md_bitmap_wait_writes()
674 md_super_wait(bitmap->mddev); in md_bitmap_wait_writes()
682 struct bitmap *bitmap = data; in bitmap_update_sb() local
684 if (!bitmap || !bitmap->mddev) /* no bitmap for this array */ in bitmap_update_sb()
686 if (bitmap->mddev->bitmap_info.external) in bitmap_update_sb()
688 if (!bitmap->storage.sb_page) /* no superblock */ in bitmap_update_sb()
690 sb = kmap_local_page(bitmap->storage.sb_page); in bitmap_update_sb()
691 sb->events = cpu_to_le64(bitmap->mddev->events); in bitmap_update_sb()
692 if (bitmap->mddev->events < bitmap->events_cleared) in bitmap_update_sb()
694 bitmap->events_cleared = bitmap->mddev->events; in bitmap_update_sb()
695 sb->events_cleared = cpu_to_le64(bitmap->events_cleared); in bitmap_update_sb()
698 * a bitmap write error occurred but the later writes succeeded. in bitmap_update_sb()
700 sb->state = cpu_to_le32(bitmap->flags & ~BIT(BITMAP_WRITE_ERROR)); in bitmap_update_sb()
702 sb->daemon_sleep = cpu_to_le32(bitmap->mddev->bitmap_info.daemon_sleep/HZ); in bitmap_update_sb()
703 sb->write_behind = cpu_to_le32(bitmap->mddev->bitmap_info.max_write_behind); in bitmap_update_sb()
705 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in bitmap_update_sb()
706 sb->chunksize = cpu_to_le32(bitmap->mddev->bitmap_info.chunksize); in bitmap_update_sb()
707 sb->nodes = cpu_to_le32(bitmap->mddev->bitmap_info.nodes); in bitmap_update_sb()
708 sb->sectors_reserved = cpu_to_le32(bitmap->mddev-> in bitmap_update_sb()
712 if (bitmap->storage.file) in bitmap_update_sb()
713 write_file_page(bitmap, bitmap->storage.sb_page, 1); in bitmap_update_sb()
715 write_sb_page(bitmap, bitmap->storage.sb_index, in bitmap_update_sb()
716 bitmap->storage.sb_page, 1); in bitmap_update_sb()
719 static void bitmap_print_sb(struct bitmap *bitmap) in bitmap_print_sb() argument
723 if (!bitmap || !bitmap->storage.sb_page) in bitmap_print_sb()
725 sb = kmap_local_page(bitmap->storage.sb_page); in bitmap_print_sb()
726 pr_debug("%s: bitmap file superblock:\n", bmname(bitmap)); in bitmap_print_sb()
749 * @bitmap
752 * reads and verifies the on-disk bitmap superblock and populates bitmap_info.
753 * This function verifies 'bitmap_info' and populates the on-disk bitmap
758 static int md_bitmap_new_disk_sb(struct bitmap *bitmap) in md_bitmap_new_disk_sb() argument
763 bitmap->storage.sb_page = alloc_page(GFP_KERNEL | __GFP_ZERO); in md_bitmap_new_disk_sb()
764 if (bitmap->storage.sb_page == NULL) in md_bitmap_new_disk_sb()
766 bitmap->storage.sb_index = 0; in md_bitmap_new_disk_sb()
768 sb = kmap_local_page(bitmap->storage.sb_page); in md_bitmap_new_disk_sb()
773 chunksize = bitmap->mddev->bitmap_info.chunksize; in md_bitmap_new_disk_sb()
777 pr_warn("bitmap chunksize not a power of 2\n"); in md_bitmap_new_disk_sb()
782 daemon_sleep = bitmap->mddev->bitmap_info.daemon_sleep; in md_bitmap_new_disk_sb()
788 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; in md_bitmap_new_disk_sb()
794 write_behind = bitmap->mddev->bitmap_info.max_write_behind; in md_bitmap_new_disk_sb()
798 bitmap->mddev->bitmap_info.max_write_behind = write_behind; in md_bitmap_new_disk_sb()
800 /* keep the array size field of the bitmap superblock up to date */ in md_bitmap_new_disk_sb()
801 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in md_bitmap_new_disk_sb()
803 memcpy(sb->uuid, bitmap->mddev->uuid, 16); in md_bitmap_new_disk_sb()
805 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_new_disk_sb()
806 sb->state = cpu_to_le32(bitmap->flags); in md_bitmap_new_disk_sb()
807 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_new_disk_sb()
808 sb->events_cleared = cpu_to_le64(bitmap->mddev->events); in md_bitmap_new_disk_sb()
809 bitmap->mddev->bitmap_info.nodes = 0; in md_bitmap_new_disk_sb()
816 /* read the superblock from the bitmap file and initialize some bitmap fields */
817 static int md_bitmap_read_sb(struct bitmap *bitmap) in md_bitmap_read_sb() argument
829 if (!bitmap->storage.file && !bitmap->mddev->bitmap_info.offset) { in md_bitmap_read_sb()
833 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_read_sb()
841 bitmap->storage.sb_page = sb_page; in md_bitmap_read_sb()
845 if (bitmap->cluster_slot >= 0) { in md_bitmap_read_sb()
846 sector_t bm_blocks = bitmap->mddev->resync_max_sectors; in md_bitmap_read_sb()
849 (bitmap->mddev->bitmap_info.chunksize >> 9)); in md_bitmap_read_sb()
854 offset = bitmap->cluster_slot * (bm_blocks << 3); in md_bitmap_read_sb()
856 bitmap->cluster_slot, offset); in md_bitmap_read_sb()
859 if (bitmap->storage.file) { in md_bitmap_read_sb()
860 loff_t isize = i_size_read(bitmap->storage.file->f_mapping->host); in md_bitmap_read_sb()
863 err = read_file_page(bitmap->storage.file, 0, in md_bitmap_read_sb()
864 bitmap, bytes, sb_page); in md_bitmap_read_sb()
866 err = read_sb_page(bitmap->mddev, offset, sb_page, 0, in md_bitmap_read_sb()
880 /* verify that the bitmap-specific fields are valid */ in md_bitmap_read_sb()
887 reason = "bitmap chunksize too small"; in md_bitmap_read_sb()
889 reason = "bitmap chunksize not a power of 2"; in md_bitmap_read_sb()
895 pr_warn("%s: invalid bitmap file superblock: %s\n", in md_bitmap_read_sb()
896 bmname(bitmap), reason); in md_bitmap_read_sb()
901 * Setup nodes/clustername only if bitmap version is in md_bitmap_read_sb()
906 strscpy(bitmap->mddev->bitmap_info.cluster_name, in md_bitmap_read_sb()
910 /* keep the array size field of the bitmap superblock up to date */ in md_bitmap_read_sb()
911 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in md_bitmap_read_sb()
913 if (bitmap->mddev->persistent) { in md_bitmap_read_sb()
916 * bitmap's UUID and event counter to the mddev's in md_bitmap_read_sb()
918 if (memcmp(sb->uuid, bitmap->mddev->uuid, 16)) { in md_bitmap_read_sb()
919 pr_warn("%s: bitmap superblock UUID mismatch\n", in md_bitmap_read_sb()
920 bmname(bitmap)); in md_bitmap_read_sb()
924 if (!nodes && (events < bitmap->mddev->events)) { in md_bitmap_read_sb()
925 pr_warn("%s: bitmap file is out of date (%llu < %llu) -- forcing full recovery\n", in md_bitmap_read_sb()
926 bmname(bitmap), events, in md_bitmap_read_sb()
927 (unsigned long long) bitmap->mddev->events); in md_bitmap_read_sb()
928 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_read_sb()
933 bitmap->flags |= le32_to_cpu(sb->state); in md_bitmap_read_sb()
935 set_bit(BITMAP_HOSTENDIAN, &bitmap->flags); in md_bitmap_read_sb()
936 bitmap->events_cleared = le64_to_cpu(sb->events_cleared); in md_bitmap_read_sb()
941 if (err == 0 && nodes && (bitmap->cluster_slot < 0)) { in md_bitmap_read_sb()
943 bitmap->mddev->bitmap_info.chunksize = chunksize; in md_bitmap_read_sb()
944 err = md_setup_cluster(bitmap->mddev, nodes); in md_bitmap_read_sb()
947 bmname(bitmap), err); in md_bitmap_read_sb()
950 bitmap->cluster_slot = bitmap->mddev->cluster_ops->slot_number(bitmap->mddev); in md_bitmap_read_sb()
956 if (test_bit(BITMAP_STALE, &bitmap->flags)) in md_bitmap_read_sb()
957 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_read_sb()
958 bitmap->mddev->bitmap_info.chunksize = chunksize; in md_bitmap_read_sb()
959 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; in md_bitmap_read_sb()
960 bitmap->mddev->bitmap_info.max_write_behind = write_behind; in md_bitmap_read_sb()
961 bitmap->mddev->bitmap_info.nodes = nodes; in md_bitmap_read_sb()
962 if (bitmap->mddev->bitmap_info.space == 0 || in md_bitmap_read_sb()
963 bitmap->mddev->bitmap_info.space > sectors_reserved) in md_bitmap_read_sb()
964 bitmap->mddev->bitmap_info.space = sectors_reserved; in md_bitmap_read_sb()
966 bitmap_print_sb(bitmap); in md_bitmap_read_sb()
967 if (bitmap->cluster_slot < 0) in md_bitmap_read_sb()
968 md_cluster_stop(bitmap->mddev); in md_bitmap_read_sb()
974 * general bitmap file operations
978 * on-disk bitmap:
980 * Use one bit per "chunk" (block set). We do the disk I/O on the bitmap
1091 * bitmap_file_kick - if an error occurs while manipulating the bitmap file
1095 static void md_bitmap_file_kick(struct bitmap *bitmap) in md_bitmap_file_kick() argument
1097 if (!test_and_set_bit(BITMAP_STALE, &bitmap->flags)) { in md_bitmap_file_kick()
1098 bitmap_update_sb(bitmap); in md_bitmap_file_kick()
1100 if (bitmap->storage.file) { in md_bitmap_file_kick()
1101 pr_warn("%s: kicking failed bitmap file %pD4 from array!\n", in md_bitmap_file_kick()
1102 bmname(bitmap), bitmap->storage.file); in md_bitmap_file_kick()
1105 pr_warn("%s: disabling internal bitmap due to errors\n", in md_bitmap_file_kick()
1106 bmname(bitmap)); in md_bitmap_file_kick()
1117 static inline void set_page_attr(struct bitmap *bitmap, int pnum, in set_page_attr() argument
1120 set_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in set_page_attr()
1123 static inline void clear_page_attr(struct bitmap *bitmap, int pnum, in clear_page_attr() argument
1126 clear_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in clear_page_attr()
1129 static inline int test_page_attr(struct bitmap *bitmap, int pnum, in test_page_attr() argument
1132 return test_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in test_page_attr()
1135 static inline int test_and_clear_page_attr(struct bitmap *bitmap, int pnum, in test_and_clear_page_attr() argument
1139 bitmap->storage.filemap_attr); in test_and_clear_page_attr()
1143 * to set (and eventually sync) a particular bit in the bitmap file
1148 static void md_bitmap_file_set_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_set_bit() argument
1153 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_set_bit()
1154 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_file_set_bit()
1159 if (mddev_is_clustered(bitmap->mddev)) in md_bitmap_file_set_bit()
1160 node_offset = bitmap->cluster_slot * store->file_pages; in md_bitmap_file_set_bit()
1162 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_set_bit()
1165 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_set_bit()
1169 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_set_bit()
1176 set_page_attr(bitmap, index - node_offset, BITMAP_PAGE_DIRTY); in md_bitmap_file_set_bit()
1179 static void md_bitmap_file_clear_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_clear_bit() argument
1184 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_clear_bit()
1185 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_file_clear_bit()
1190 if (mddev_is_clustered(bitmap->mddev)) in md_bitmap_file_clear_bit()
1191 node_offset = bitmap->cluster_slot * store->file_pages; in md_bitmap_file_clear_bit()
1193 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_clear_bit()
1196 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_clear_bit()
1198 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_clear_bit()
1203 if (!test_page_attr(bitmap, index - node_offset, BITMAP_PAGE_NEEDWRITE)) { in md_bitmap_file_clear_bit()
1204 set_page_attr(bitmap, index - node_offset, BITMAP_PAGE_PENDING); in md_bitmap_file_clear_bit()
1205 bitmap->allclean = 0; in md_bitmap_file_clear_bit()
1209 static int md_bitmap_file_test_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_test_bit() argument
1214 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_test_bit()
1217 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_test_bit()
1220 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_test_bit()
1222 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_test_bit()
1232 * sync the dirty pages of the bitmap file to disk */
1233 static void __bitmap_unplug(struct bitmap *bitmap) in __bitmap_unplug() argument
1239 if (!bitmap_enabled(bitmap, true)) in __bitmap_unplug()
1244 for (i = 0; i < bitmap->storage.file_pages; i++) { in __bitmap_unplug()
1245 dirty = test_and_clear_page_attr(bitmap, i, BITMAP_PAGE_DIRTY); in __bitmap_unplug()
1246 need_write = test_and_clear_page_attr(bitmap, i, in __bitmap_unplug()
1250 md_bitmap_wait_writes(bitmap); in __bitmap_unplug()
1251 mddev_add_trace_msg(bitmap->mddev, in __bitmap_unplug()
1254 clear_page_attr(bitmap, i, BITMAP_PAGE_PENDING); in __bitmap_unplug()
1255 filemap_write_page(bitmap, i, false); in __bitmap_unplug()
1260 md_bitmap_wait_writes(bitmap); in __bitmap_unplug()
1262 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in __bitmap_unplug()
1263 md_bitmap_file_kick(bitmap); in __bitmap_unplug()
1268 struct bitmap *bitmap; member
1277 __bitmap_unplug(unplug_work->bitmap); in md_bitmap_unplug_fn()
1281 static void bitmap_unplug_async(struct bitmap *bitmap) in bitmap_unplug_async() argument
1287 unplug_work.bitmap = bitmap; in bitmap_unplug_async()
1297 struct bitmap *bitmap = mddev->bitmap; in bitmap_unplug() local
1299 if (!bitmap) in bitmap_unplug()
1303 __bitmap_unplug(bitmap); in bitmap_unplug()
1305 bitmap_unplug_async(bitmap); in bitmap_unplug()
1308 static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
1311 * Initialize the in-memory bitmap from the on-disk bitmap and set up the memory
1312 * mapping of the bitmap file.
1314 * Special case: If there's no bitmap file, or if the bitmap file had been
1319 * This is used when reading an out-of-date bitmap.
1321 static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) in md_bitmap_init_from_disk() argument
1323 bool outofdate = test_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_init_from_disk()
1324 struct mddev *mddev = bitmap->mddev; in md_bitmap_init_from_disk()
1325 unsigned long chunks = bitmap->counts.chunks; in md_bitmap_init_from_disk()
1326 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_init_from_disk()
1334 /* No permanent bitmap - fill with '1s'. */ in md_bitmap_init_from_disk()
1339 int needed = ((sector_t)(i+1) << (bitmap->counts.chunkshift) in md_bitmap_init_from_disk()
1341 md_bitmap_set_memory_bits(bitmap, in md_bitmap_init_from_disk()
1342 (sector_t)i << bitmap->counts.chunkshift, in md_bitmap_init_from_disk()
1349 pr_warn("%s: bitmap file too short %lu < %lu\n", in md_bitmap_init_from_disk()
1350 bmname(bitmap), in md_bitmap_init_from_disk()
1358 node_offset = bitmap->cluster_slot * (DIV_ROUND_UP(store->bytes, PAGE_SIZE)); in md_bitmap_init_from_disk()
1371 ret = read_file_page(file, i, bitmap, count, page); in md_bitmap_init_from_disk()
1380 pr_warn("%s: bitmap file is out of date, doing full recovery\n", in md_bitmap_init_from_disk()
1381 bmname(bitmap)); in md_bitmap_init_from_disk()
1392 * If the bitmap is out of date, dirty the whole page in md_bitmap_init_from_disk()
1399 filemap_write_page(bitmap, i, true); in md_bitmap_init_from_disk()
1400 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) { in md_bitmap_init_from_disk()
1408 struct page *page = filemap_get_page(&bitmap->storage, i); in md_bitmap_init_from_disk()
1409 unsigned long bit = file_page_offset(&bitmap->storage, i); in md_bitmap_init_from_disk()
1414 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_init_from_disk()
1422 int needed = ((sector_t)(i+1) << bitmap->counts.chunkshift in md_bitmap_init_from_disk()
1424 md_bitmap_set_memory_bits(bitmap, in md_bitmap_init_from_disk()
1425 (sector_t)i << bitmap->counts.chunkshift, in md_bitmap_init_from_disk()
1431 pr_debug("%s: bitmap initialized from disk: read %lu pages, set %lu of %lu bits\n", in md_bitmap_init_from_disk()
1432 bmname(bitmap), store->file_pages, in md_bitmap_init_from_disk()
1438 pr_warn("%s: bitmap initialisation failed: %d\n", in md_bitmap_init_from_disk()
1439 bmname(bitmap), ret); in md_bitmap_init_from_disk()
1443 /* just flag bitmap pages as needing to be written. */
1447 struct bitmap *bitmap = mddev->bitmap; in bitmap_write_all() local
1449 if (!bitmap || !bitmap->storage.filemap) in bitmap_write_all()
1453 if (bitmap->storage.file) in bitmap_write_all()
1456 for (i = 0; i < bitmap->storage.file_pages; i++) in bitmap_write_all()
1457 set_page_attr(bitmap, i, BITMAP_PAGE_NEEDWRITE); in bitmap_write_all()
1458 bitmap->allclean = 0; in bitmap_write_all()
1461 static void md_bitmap_count_page(struct bitmap_counts *bitmap, in md_bitmap_count_page() argument
1464 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_count_page()
1466 bitmap->bp[page].count += inc; in md_bitmap_count_page()
1467 md_bitmap_checkfree(bitmap, page); in md_bitmap_count_page()
1470 static void md_bitmap_set_pending(struct bitmap_counts *bitmap, sector_t offset) in md_bitmap_set_pending() argument
1472 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_set_pending()
1474 struct bitmap_page *bp = &bitmap->bp[page]; in md_bitmap_set_pending()
1480 static bitmap_counter_t *md_bitmap_get_counter(struct bitmap_counts *bitmap,
1503 * bitmap daemon -- periodically wakes up to clean bits and flush pages
1508 struct bitmap *bitmap; in bitmap_daemon_work() local
1518 bitmap = mddev->bitmap; in bitmap_daemon_work()
1519 if (bitmap == NULL) { in bitmap_daemon_work()
1523 if (time_before(jiffies, bitmap->daemon_lastrun in bitmap_daemon_work()
1527 bitmap->daemon_lastrun = jiffies; in bitmap_daemon_work()
1528 if (bitmap->allclean) { in bitmap_daemon_work()
1532 bitmap->allclean = 1; in bitmap_daemon_work()
1534 mddev_add_trace_msg(bitmap->mddev, "md bitmap_daemon_work"); in bitmap_daemon_work()
1540 for (j = 0; j < bitmap->storage.file_pages; j++) in bitmap_daemon_work()
1541 if (test_and_clear_page_attr(bitmap, j, in bitmap_daemon_work()
1543 set_page_attr(bitmap, j, in bitmap_daemon_work()
1546 if (bitmap->need_sync && in bitmap_daemon_work()
1551 bitmap->need_sync = 0; in bitmap_daemon_work()
1552 if (bitmap->storage.filemap) { in bitmap_daemon_work()
1553 sb = kmap_local_page(bitmap->storage.sb_page); in bitmap_daemon_work()
1555 cpu_to_le64(bitmap->events_cleared); in bitmap_daemon_work()
1557 set_page_attr(bitmap, 0, in bitmap_daemon_work()
1561 /* Now look at the bitmap counters and if any are '2' or '1', in bitmap_daemon_work()
1564 counts = &bitmap->counts; in bitmap_daemon_work()
1585 if (*bmc == 1 && !bitmap->need_sync) { in bitmap_daemon_work()
1589 md_bitmap_file_clear_bit(bitmap, block); in bitmap_daemon_work()
1593 bitmap->allclean = 0; in bitmap_daemon_work()
1598 md_bitmap_wait_writes(bitmap); in bitmap_daemon_work()
1608 j < bitmap->storage.file_pages in bitmap_daemon_work()
1609 && !test_bit(BITMAP_STALE, &bitmap->flags); in bitmap_daemon_work()
1611 if (test_page_attr(bitmap, j, in bitmap_daemon_work()
1615 if (bitmap->storage.filemap && in bitmap_daemon_work()
1616 test_and_clear_page_attr(bitmap, j, in bitmap_daemon_work()
1618 filemap_write_page(bitmap, j, false); in bitmap_daemon_work()
1622 if (bitmap->allclean == 0) in bitmap_daemon_work()
1627 static bitmap_counter_t *md_bitmap_get_counter(struct bitmap_counts *bitmap, in md_bitmap_get_counter() argument
1630 __releases(bitmap->lock) in md_bitmap_get_counter()
1631 __acquires(bitmap->lock) in md_bitmap_get_counter()
1637 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_get_counter()
1640 sector_t csize = ((sector_t)1) << bitmap->chunkshift; in md_bitmap_get_counter()
1643 if (page >= bitmap->pages) { in md_bitmap_get_counter()
1652 err = md_bitmap_checkpage(bitmap, page, create, 0); in md_bitmap_get_counter()
1654 if (bitmap->bp[page].hijacked || in md_bitmap_get_counter()
1655 bitmap->bp[page].map == NULL) in md_bitmap_get_counter()
1656 csize = ((sector_t)1) << (bitmap->chunkshift + in md_bitmap_get_counter()
1666 if (bitmap->bp[page].hijacked) { /* hijacked pointer */ in md_bitmap_get_counter()
1671 &bitmap->bp[page].map)[hi]; in md_bitmap_get_counter()
1674 &(bitmap->bp[page].map[pageoff]); in md_bitmap_get_counter()
1680 struct bitmap *bitmap = mddev->bitmap; in bitmap_start_write() local
1682 if (!bitmap) in bitmap_start_write()
1689 spin_lock_irq(&bitmap->counts.lock); in bitmap_start_write()
1690 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &blocks, 1); in bitmap_start_write()
1692 spin_unlock_irq(&bitmap->counts.lock); in bitmap_start_write()
1702 prepare_to_wait(&bitmap->overflow_wait, &__wait, in bitmap_start_write()
1704 spin_unlock_irq(&bitmap->counts.lock); in bitmap_start_write()
1706 finish_wait(&bitmap->overflow_wait, &__wait); in bitmap_start_write()
1712 md_bitmap_file_set_bit(bitmap, offset); in bitmap_start_write()
1713 md_bitmap_count_page(&bitmap->counts, offset, 1); in bitmap_start_write()
1721 spin_unlock_irq(&bitmap->counts.lock); in bitmap_start_write()
1734 struct bitmap *bitmap = mddev->bitmap; in bitmap_end_write() local
1736 if (!bitmap) in bitmap_end_write()
1744 spin_lock_irqsave(&bitmap->counts.lock, flags); in bitmap_end_write()
1745 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &blocks, 0); in bitmap_end_write()
1747 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in bitmap_end_write()
1751 if (!bitmap->mddev->degraded) { in bitmap_end_write()
1752 if (bitmap->events_cleared < bitmap->mddev->events) { in bitmap_end_write()
1753 bitmap->events_cleared = bitmap->mddev->events; in bitmap_end_write()
1754 bitmap->need_sync = 1; in bitmap_end_write()
1756 bitmap->sysfs_can_clear); in bitmap_end_write()
1763 wake_up(&bitmap->overflow_wait); in bitmap_end_write()
1767 md_bitmap_set_pending(&bitmap->counts, offset); in bitmap_end_write()
1768 bitmap->allclean = 0; in bitmap_end_write()
1770 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in bitmap_end_write()
1779 static bool __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, in __bitmap_start_sync() argument
1785 spin_lock_irq(&bitmap->counts.lock); in __bitmap_start_sync()
1786 bmc = md_bitmap_get_counter(&bitmap->counts, offset, blocks, 0); in __bitmap_start_sync()
1799 spin_unlock_irq(&bitmap->counts.lock); in __bitmap_start_sync()
1819 rv |= __bitmap_start_sync(mddev->bitmap, offset, in bitmap_start_sync()
1828 static void __bitmap_end_sync(struct bitmap *bitmap, sector_t offset, in __bitmap_end_sync() argument
1834 spin_lock_irqsave(&bitmap->counts.lock, flags); in __bitmap_end_sync()
1835 bmc = md_bitmap_get_counter(&bitmap->counts, offset, blocks, 0); in __bitmap_end_sync()
1846 md_bitmap_set_pending(&bitmap->counts, offset); in __bitmap_end_sync()
1847 bitmap->allclean = 0; in __bitmap_end_sync()
1852 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in __bitmap_end_sync()
1858 __bitmap_end_sync(mddev->bitmap, offset, blocks, true); in bitmap_end_sync()
1863 /* Sync has finished, and any bitmap chunks that weren't synced in bitmap_close_sync()
1869 struct bitmap *bitmap = mddev->bitmap; in bitmap_close_sync() local
1871 if (!bitmap) in bitmap_close_sync()
1874 while (sector < bitmap->mddev->resync_max_sectors) { in bitmap_close_sync()
1875 __bitmap_end_sync(bitmap, sector, &blocks, false); in bitmap_close_sync()
1885 struct bitmap *bitmap = mddev->bitmap; in bitmap_cond_end_sync() local
1887 if (!bitmap) in bitmap_cond_end_sync()
1890 bitmap->last_end_sync = jiffies; in bitmap_cond_end_sync()
1893 if (!force && time_before(jiffies, (bitmap->last_end_sync in bitmap_cond_end_sync()
1894 + bitmap->mddev->bitmap_info.daemon_sleep))) in bitmap_cond_end_sync()
1896 wait_event(bitmap->mddev->recovery_wait, in bitmap_cond_end_sync()
1897 atomic_read(&bitmap->mddev->recovery_active) == 0); in bitmap_cond_end_sync()
1899 bitmap->mddev->curr_resync_completed = sector; in bitmap_cond_end_sync()
1900 set_bit(MD_SB_CHANGE_CLEAN, &bitmap->mddev->sb_flags); in bitmap_cond_end_sync()
1901 sector &= ~((1ULL << bitmap->counts.chunkshift) - 1); in bitmap_cond_end_sync()
1903 while (s < sector && s < bitmap->mddev->resync_max_sectors) { in bitmap_cond_end_sync()
1904 __bitmap_end_sync(bitmap, s, &blocks, false); in bitmap_cond_end_sync()
1907 bitmap->last_end_sync = jiffies; in bitmap_cond_end_sync()
1908 sysfs_notify_dirent_safe(bitmap->mddev->sysfs_completed); in bitmap_cond_end_sync()
1915 struct bitmap *bitmap = mddev->bitmap; in bitmap_sync_with_cluster() local
1919 __bitmap_end_sync(bitmap, sector, &blocks, false); in bitmap_sync_with_cluster()
1931 static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed) in md_bitmap_set_memory_bits() argument
1940 spin_lock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1941 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &secs, 1); in md_bitmap_set_memory_bits()
1943 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1948 md_bitmap_count_page(&bitmap->counts, offset, 1); in md_bitmap_set_memory_bits()
1949 md_bitmap_set_pending(&bitmap->counts, offset); in md_bitmap_set_memory_bits()
1950 bitmap->allclean = 0; in md_bitmap_set_memory_bits()
1954 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1957 /* dirty the memory and file bits for bitmap chunks "s" to "e" */
1962 struct bitmap *bitmap = mddev->bitmap; in bitmap_dirty_bits() local
1964 if (!bitmap) in bitmap_dirty_bits()
1968 sector_t sec = (sector_t)chunk << bitmap->counts.chunkshift; in bitmap_dirty_bits()
1970 md_bitmap_set_memory_bits(bitmap, sec, 1); in bitmap_dirty_bits()
1971 md_bitmap_file_set_bit(bitmap, sec); in bitmap_dirty_bits()
1972 if (sec < bitmap->mddev->resync_offset) in bitmap_dirty_bits()
1977 bitmap->mddev->resync_offset = sec; in bitmap_dirty_bits()
1983 struct bitmap *bitmap = mddev->bitmap; in bitmap_flush() local
1986 if (!bitmap) /* there was no bitmap */ in bitmap_flush()
1993 bitmap->daemon_lastrun -= sleep; in bitmap_flush()
1995 bitmap->daemon_lastrun -= sleep; in bitmap_flush()
1997 bitmap->daemon_lastrun -= sleep; in bitmap_flush()
2001 bitmap_update_sb(bitmap); in bitmap_flush()
2008 struct bitmap *bitmap = data; in md_bitmap_free() local
2010 if (!bitmap) /* there was no bitmap */ in md_bitmap_free()
2013 if (bitmap->sysfs_can_clear) in md_bitmap_free()
2014 sysfs_put(bitmap->sysfs_can_clear); in md_bitmap_free()
2016 if (mddev_is_clustered(bitmap->mddev) && bitmap->mddev->cluster_info && in md_bitmap_free()
2017 bitmap->cluster_slot == bitmap->mddev->cluster_ops->slot_number(bitmap->mddev)) in md_bitmap_free()
2018 md_cluster_stop(bitmap->mddev); in md_bitmap_free()
2021 wait_event(bitmap->write_wait, in md_bitmap_free()
2022 atomic_read(&bitmap->pending_writes) == 0); in md_bitmap_free()
2024 /* release the bitmap file */ in md_bitmap_free()
2025 md_bitmap_file_unmap(&bitmap->storage); in md_bitmap_free()
2027 bp = bitmap->counts.bp; in md_bitmap_free()
2028 pages = bitmap->counts.pages; in md_bitmap_free()
2037 kfree(bitmap); in md_bitmap_free()
2042 struct bitmap *bitmap = mddev->bitmap; in bitmap_start_behind_write() local
2045 atomic_inc(&bitmap->behind_writes); in bitmap_start_behind_write()
2046 bw = atomic_read(&bitmap->behind_writes); in bitmap_start_behind_write()
2047 if (bw > bitmap->behind_writes_used) in bitmap_start_behind_write()
2048 bitmap->behind_writes_used = bw; in bitmap_start_behind_write()
2051 bw, bitmap->mddev->bitmap_info.max_write_behind); in bitmap_start_behind_write()
2056 struct bitmap *bitmap = mddev->bitmap; in bitmap_end_behind_write() local
2058 if (atomic_dec_and_test(&bitmap->behind_writes)) in bitmap_end_behind_write()
2059 wake_up(&bitmap->behind_wait); in bitmap_end_behind_write()
2061 atomic_read(&bitmap->behind_writes), in bitmap_end_behind_write()
2062 bitmap->mddev->bitmap_info.max_write_behind); in bitmap_end_behind_write()
2067 struct bitmap *bitmap = mddev->bitmap; in bitmap_wait_behind_writes() local
2070 if (bitmap && atomic_read(&bitmap->behind_writes) > 0) { in bitmap_wait_behind_writes()
2074 wait_event(bitmap->behind_wait, in bitmap_wait_behind_writes()
2075 atomic_read(&bitmap->behind_writes) == 0); in bitmap_wait_behind_writes()
2081 struct bitmap *bitmap = mddev->bitmap; in bitmap_destroy() local
2083 if (!bitmap) /* there was no bitmap */ in bitmap_destroy()
2092 mddev->bitmap = NULL; /* disconnect from the md device */ in bitmap_destroy()
2097 md_bitmap_free(bitmap); in bitmap_destroy()
2101 * initialize the bitmap structure
2103 * once mddev->bitmap is set
2105 static struct bitmap *__bitmap_create(struct mddev *mddev, int slot) in __bitmap_create()
2107 struct bitmap *bitmap; in __bitmap_create() local
2118 pr_notice("md/raid:%s: array with journal cannot have bitmap\n", in __bitmap_create()
2123 bitmap = kzalloc_obj(*bitmap); in __bitmap_create()
2124 if (!bitmap) in __bitmap_create()
2127 spin_lock_init(&bitmap->counts.lock); in __bitmap_create()
2128 atomic_set(&bitmap->pending_writes, 0); in __bitmap_create()
2129 init_waitqueue_head(&bitmap->write_wait); in __bitmap_create()
2130 init_waitqueue_head(&bitmap->overflow_wait); in __bitmap_create()
2131 init_waitqueue_head(&bitmap->behind_wait); in __bitmap_create()
2133 bitmap->mddev = mddev; in __bitmap_create()
2134 bitmap->cluster_slot = slot; in __bitmap_create()
2137 bm = sysfs_get_dirent(mddev->kobj.sd, "bitmap"); in __bitmap_create()
2139 bitmap->sysfs_can_clear = sysfs_get_dirent(bm, "can_clear"); in __bitmap_create()
2142 bitmap->sysfs_can_clear = NULL; in __bitmap_create()
2144 bitmap->storage.file = file; in __bitmap_create()
2153 /* read superblock from bitmap file (this sets mddev->bitmap_info.chunksize) */ in __bitmap_create()
2157 * instructing us to create a new on-disk bitmap instance. in __bitmap_create()
2160 err = md_bitmap_new_disk_sb(bitmap); in __bitmap_create()
2162 err = md_bitmap_read_sb(bitmap); in __bitmap_create()
2174 bitmap->daemon_lastrun = jiffies; in __bitmap_create()
2175 err = __bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize, in __bitmap_create()
2180 pr_debug("created bitmap (%lu pages) for device %s\n", in __bitmap_create()
2181 bitmap->counts.pages, bmname(bitmap)); in __bitmap_create()
2183 err = test_bit(BITMAP_WRITE_ERROR, &bitmap->flags) ? -EIO : 0; in __bitmap_create()
2187 return bitmap; in __bitmap_create()
2189 md_bitmap_free(bitmap); in __bitmap_create()
2195 struct bitmap *bitmap = __bitmap_create(mddev, -1); in bitmap_create() local
2197 if (IS_ERR(bitmap)) in bitmap_create()
2198 return PTR_ERR(bitmap); in bitmap_create()
2200 mddev->bitmap = bitmap; in bitmap_create()
2209 struct bitmap *bitmap = mddev->bitmap; in bitmap_load() local
2212 if (!bitmap) in bitmap_load()
2221 /* Clear out old bitmap info first: Either there is none, or we in bitmap_load()
2234 || bitmap->events_cleared == mddev->events) in bitmap_load()
2240 err = md_bitmap_init_from_disk(bitmap, start); in bitmap_load()
2245 clear_bit(BITMAP_STALE, &bitmap->flags); in bitmap_load()
2248 set_bit(MD_RECOVERY_NEEDED, &bitmap->mddev->recovery); in bitmap_load()
2253 bitmap_update_sb(bitmap); in bitmap_load()
2255 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in bitmap_load()
2261 /* caller need to free returned bitmap with md_bitmap_free() */
2265 struct bitmap *bitmap; in bitmap_get_from_slot() local
2267 bitmap = __bitmap_create(mddev, slot); in bitmap_get_from_slot()
2268 if (IS_ERR(bitmap)) { in bitmap_get_from_slot()
2269 rv = PTR_ERR(bitmap); in bitmap_get_from_slot()
2273 rv = md_bitmap_init_from_disk(bitmap, 0); in bitmap_get_from_slot()
2275 md_bitmap_free(bitmap); in bitmap_get_from_slot()
2279 return bitmap; in bitmap_get_from_slot()
2282 /* Loads the bitmap associated with slot and copies the resync information
2283 * to our bitmap
2291 struct bitmap *bitmap; in bitmap_copy_from_slot() local
2293 bitmap = bitmap_get_from_slot(mddev, slot); in bitmap_copy_from_slot()
2294 if (IS_ERR(bitmap)) { in bitmap_copy_from_slot()
2295 pr_err("%s can't get bitmap from slot %d\n", __func__, slot); in bitmap_copy_from_slot()
2299 counts = &bitmap->counts; in bitmap_copy_from_slot()
2302 if (md_bitmap_file_test_bit(bitmap, block)) { in bitmap_copy_from_slot()
2306 md_bitmap_file_clear_bit(bitmap, block); in bitmap_copy_from_slot()
2307 md_bitmap_set_memory_bits(mddev->bitmap, block, 1); in bitmap_copy_from_slot()
2308 md_bitmap_file_set_bit(mddev->bitmap, block); in bitmap_copy_from_slot()
2313 bitmap_update_sb(bitmap); in bitmap_copy_from_slot()
2316 for (i = 0; i < bitmap->storage.file_pages; i++) in bitmap_copy_from_slot()
2317 if (test_page_attr(bitmap, i, BITMAP_PAGE_PENDING)) in bitmap_copy_from_slot()
2318 set_page_attr(bitmap, i, BITMAP_PAGE_NEEDWRITE); in bitmap_copy_from_slot()
2319 __bitmap_unplug(bitmap); in bitmap_copy_from_slot()
2321 __bitmap_unplug(mddev->bitmap); in bitmap_copy_from_slot()
2324 md_bitmap_free(bitmap); in bitmap_copy_from_slot()
2331 struct bitmap *bitmap = data; in bitmap_set_pages() local
2333 bitmap->counts.pages = pages; in bitmap_set_pages()
2340 struct bitmap *bitmap = data; in bitmap_get_stats() local
2343 if (!bitmap) in bitmap_get_stats()
2345 if (!bitmap->storage.sb_page) in bitmap_get_stats()
2347 sb = kmap_local_page(bitmap->storage.sb_page); in bitmap_get_stats()
2351 counts = &bitmap->counts; in bitmap_get_stats()
2355 storage = &bitmap->storage; in bitmap_get_stats()
2359 stats->behind_writes = atomic_read(&bitmap->behind_writes); in bitmap_get_stats()
2360 stats->behind_wait = wq_has_sleeper(&bitmap->behind_wait); in bitmap_get_stats()
2361 stats->events_cleared = bitmap->events_cleared; in bitmap_get_stats()
2365 static int __bitmap_resize(struct bitmap *bitmap, sector_t blocks, in __bitmap_resize() argument
2370 * Then quiesce, copy bits, replace bitmap, and re-start in __bitmap_resize()
2372 * This function is called both to set up the initial bitmap in __bitmap_resize()
2373 * and to resize the bitmap while the array is active. in __bitmap_resize()
2388 if (bitmap->storage.file && !init) { in __bitmap_resize()
2389 pr_info("md: cannot resize file-based bitmap\n"); in __bitmap_resize()
2398 long space = bitmap->mddev->bitmap_info.space; in __bitmap_resize()
2404 bytes = DIV_ROUND_UP(bitmap->counts.chunks, 8); in __bitmap_resize()
2405 if (!bitmap->mddev->bitmap_info.external) in __bitmap_resize()
2408 bitmap->mddev->bitmap_info.space = space; in __bitmap_resize()
2410 chunkshift = bitmap->counts.chunkshift; in __bitmap_resize()
2417 if (!bitmap->mddev->bitmap_info.external) in __bitmap_resize()
2426 if (bitmap->mddev->bitmap_info.offset || bitmap->mddev->bitmap_info.file) in __bitmap_resize()
2428 !bitmap->mddev->bitmap_info.external, in __bitmap_resize()
2429 mddev_is_clustered(bitmap->mddev) in __bitmap_resize()
2430 ? bitmap->cluster_slot : 0); in __bitmap_resize()
2446 bitmap->mddev->pers->quiesce(bitmap->mddev, 1); in __bitmap_resize()
2448 store.file = bitmap->storage.file; in __bitmap_resize()
2449 bitmap->storage.file = NULL; in __bitmap_resize()
2451 if (store.sb_page && bitmap->storage.sb_page) in __bitmap_resize()
2453 page_address(bitmap->storage.sb_page), in __bitmap_resize()
2455 mutex_lock(&bitmap->mddev->bitmap_info.mutex); in __bitmap_resize()
2456 spin_lock_irq(&bitmap->counts.lock); in __bitmap_resize()
2457 md_bitmap_file_unmap(&bitmap->storage); in __bitmap_resize()
2458 bitmap->storage = store; in __bitmap_resize()
2460 old_counts = bitmap->counts; in __bitmap_resize()
2461 bitmap->counts.bp = new_bp; in __bitmap_resize()
2462 bitmap->counts.pages = pages; in __bitmap_resize()
2463 bitmap->counts.missing_pages = pages; in __bitmap_resize()
2464 bitmap->counts.chunkshift = chunkshift; in __bitmap_resize()
2465 bitmap->counts.chunks = chunks; in __bitmap_resize()
2466 bitmap->mddev->bitmap_info.chunksize = 1UL << (chunkshift + in __bitmap_resize()
2472 /* For cluster raid, need to pre-allocate bitmap */ in __bitmap_resize()
2473 if (mddev_is_clustered(bitmap->mddev)) { in __bitmap_resize()
2476 ret = md_bitmap_checkpage(&bitmap->counts, page, 1, 1); in __bitmap_resize()
2487 bitmap->counts.bp = old_counts.bp; in __bitmap_resize()
2488 bitmap->counts.pages = old_counts.pages; in __bitmap_resize()
2489 bitmap->counts.missing_pages = old_counts.pages; in __bitmap_resize()
2490 bitmap->counts.chunkshift = old_counts.chunkshift; in __bitmap_resize()
2491 bitmap->counts.chunks = old_counts.chunks; in __bitmap_resize()
2492 bitmap->mddev->bitmap_info.chunksize = in __bitmap_resize()
2495 pr_warn("Could not pre-allocate in-memory bitmap for cluster raid\n"); in __bitmap_resize()
2498 bitmap->counts.bp[page].count += 1; in __bitmap_resize()
2510 bmc_new = md_bitmap_get_counter(&bitmap->counts, block, &new_blocks, 1); in __bitmap_resize()
2519 md_bitmap_file_set_bit(bitmap, block); in __bitmap_resize()
2523 md_bitmap_count_page(&bitmap->counts, block, 1); in __bitmap_resize()
2524 md_bitmap_set_pending(&bitmap->counts, block); in __bitmap_resize()
2534 if (bitmap->counts.bp != old_counts.bp) { in __bitmap_resize()
2546 bmc = md_bitmap_get_counter(&bitmap->counts, block, &new_blocks, 1); in __bitmap_resize()
2553 md_bitmap_count_page(&bitmap->counts, block, 1); in __bitmap_resize()
2554 md_bitmap_set_pending(&bitmap->counts, block); in __bitmap_resize()
2559 for (i = 0; i < bitmap->storage.file_pages; i++) in __bitmap_resize()
2560 set_page_attr(bitmap, i, BITMAP_PAGE_DIRTY); in __bitmap_resize()
2562 spin_unlock_irq(&bitmap->counts.lock); in __bitmap_resize()
2563 mutex_unlock(&bitmap->mddev->bitmap_info.mutex); in __bitmap_resize()
2565 __bitmap_unplug(bitmap); in __bitmap_resize()
2566 bitmap->mddev->pers->quiesce(bitmap->mddev, 0); in __bitmap_resize()
2575 struct bitmap *bitmap = mddev->bitmap; in bitmap_resize() local
2577 if (!bitmap) in bitmap_resize()
2580 return __bitmap_resize(bitmap, blocks, chunksize, false); in bitmap_resize()
2613 if (mddev->bitmap || mddev->bitmap_info.file || in location_store()
2615 /* bitmap already configured. Only option is to clear it */ in location_store()
2629 /* No bitmap, OK to set a location */ in location_store()
2670 /* Ensure new bitmap info is stored in in location_store()
2687 /* 'bitmap/space' is the space available at 'location' for the
2688 * bitmap. This allows the kernel to know when it is safe to
2689 * resize the bitmap to match a resized array.
2700 struct bitmap *bitmap; in space_store() local
2711 bitmap = mddev->bitmap; in space_store()
2712 if (bitmap && sectors < (bitmap->storage.bytes + 511) >> 9) in space_store()
2713 return -EFBIG; /* Bitmap is too big for this small space */ in space_store()
2820 bitmap_update_sb(mddev->bitmap); in backlog_store()
2838 /* Can only be changed when no bitmap is active */ in chunksize_store()
2841 if (mddev->bitmap) in chunksize_store()
2869 if (mddev->bitmap || in metadata_store()
2889 struct bitmap *bitmap; in can_clear_show() local
2892 bitmap = mddev->bitmap; in can_clear_show()
2893 if (bitmap) in can_clear_show()
2894 len = sprintf(page, "%s\n", (bitmap->need_sync ? "false" : in can_clear_show()
2904 struct bitmap *bitmap = mddev->bitmap; in can_clear_store() local
2906 if (!bitmap) in can_clear_store()
2910 bitmap->need_sync = 1; in can_clear_store()
2917 bitmap->need_sync = 0; in can_clear_store()
2931 struct bitmap *bitmap; in behind_writes_used_show() local
2934 bitmap = mddev->bitmap; in behind_writes_used_show()
2935 if (!bitmap) in behind_writes_used_show()
2938 ret = sprintf(page, "%lu\n", bitmap->behind_writes_used); in behind_writes_used_show()
2947 struct bitmap *bitmap = mddev->bitmap; in behind_writes_used_reset() local
2949 if (bitmap) in behind_writes_used_reset()
2950 bitmap->behind_writes_used = 0; in behind_writes_used_reset()
2971 .name = "bitmap",
2979 .name = "bitmap",