Lines Matching refs:bitmap

33 static inline char *bmname(struct bitmap *bitmap)  in bmname()  argument
35 return bitmap->mddev ? mdname(bitmap->mddev) : "mdX"; in bmname()
48 static int bitmap_checkpage(struct bitmap_counts *bitmap, in bitmap_checkpage() argument
50 __releases(bitmap->lock) in bitmap_checkpage()
51 __acquires(bitmap->lock) in bitmap_checkpage()
55 if (page >= bitmap->pages) { in bitmap_checkpage()
63 if (bitmap->bp[page].hijacked) /* it's hijacked, don't try to alloc */ in bitmap_checkpage()
66 if (bitmap->bp[page].map) /* page is already allocated, just return */ in bitmap_checkpage()
74 spin_unlock_irq(&bitmap->lock); in bitmap_checkpage()
89 spin_lock_irq(&bitmap->lock); in bitmap_checkpage()
95 if (!bitmap->bp[page].map) in bitmap_checkpage()
96 bitmap->bp[page].hijacked = 1; in bitmap_checkpage()
97 } else if (bitmap->bp[page].map || in bitmap_checkpage()
98 bitmap->bp[page].hijacked) { in bitmap_checkpage()
106 bitmap->bp[page].map = mappage; in bitmap_checkpage()
107 bitmap->missing_pages--; in bitmap_checkpage()
115 static void bitmap_checkfree(struct bitmap_counts *bitmap, unsigned long page) in bitmap_checkfree() argument
119 if (bitmap->bp[page].count) /* page is still busy */ in bitmap_checkfree()
124 if (bitmap->bp[page].hijacked) { /* page was hijacked, undo this now */ in bitmap_checkfree()
125 bitmap->bp[page].hijacked = 0; in bitmap_checkfree()
126 bitmap->bp[page].map = NULL; in bitmap_checkfree()
129 ptr = bitmap->bp[page].map; in bitmap_checkfree()
130 bitmap->bp[page].map = NULL; in bitmap_checkfree()
131 bitmap->missing_pages++; in bitmap_checkfree()
207 static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait) in write_sb_page() argument
211 struct mddev *mddev = bitmap->mddev; in write_sb_page()
212 struct bitmap_storage *store = &bitmap->storage; in write_sb_page()
215 if (mddev_is_clustered(bitmap->mddev)) in write_sb_page()
216 node_offset = bitmap->cluster_slot * store->file_pages; in write_sb_page()
281 static void bitmap_file_kick(struct bitmap *bitmap);
285 static void write_page(struct bitmap *bitmap, struct page *page, int wait) in write_page() argument
289 if (bitmap->storage.file == NULL) { in write_page()
290 switch (write_sb_page(bitmap, page, wait)) { in write_page()
292 set_bit(BITMAP_WRITE_ERROR, &bitmap->flags); in write_page()
299 atomic_inc(&bitmap->pending_writes); in write_page()
307 wait_event(bitmap->write_wait, in write_page()
308 atomic_read(&bitmap->pending_writes)==0); in write_page()
310 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in write_page()
311 bitmap_file_kick(bitmap); in write_page()
316 struct bitmap *bitmap = bh->b_private; in end_bitmap_write() local
319 set_bit(BITMAP_WRITE_ERROR, &bitmap->flags); in end_bitmap_write()
320 if (atomic_dec_and_test(&bitmap->pending_writes)) in end_bitmap_write()
321 wake_up(&bitmap->write_wait); in end_bitmap_write()
357 struct bitmap *bitmap, in read_page() argument
393 bh->b_private = bitmap; in read_page()
394 atomic_inc(&bitmap->pending_writes); in read_page()
404 wait_event(bitmap->write_wait, in read_page()
405 atomic_read(&bitmap->pending_writes)==0); in read_page()
406 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in read_page()
422 void bitmap_update_sb(struct bitmap *bitmap) in bitmap_update_sb() argument
426 if (!bitmap || !bitmap->mddev) /* no bitmap for this array */ in bitmap_update_sb()
428 if (bitmap->mddev->bitmap_info.external) in bitmap_update_sb()
430 if (!bitmap->storage.sb_page) /* no superblock */ in bitmap_update_sb()
432 sb = kmap_atomic(bitmap->storage.sb_page); in bitmap_update_sb()
433 sb->events = cpu_to_le64(bitmap->mddev->events); in bitmap_update_sb()
434 if (bitmap->mddev->events < bitmap->events_cleared) in bitmap_update_sb()
436 bitmap->events_cleared = bitmap->mddev->events; in bitmap_update_sb()
437 sb->events_cleared = cpu_to_le64(bitmap->events_cleared); in bitmap_update_sb()
438 sb->state = cpu_to_le32(bitmap->flags); in bitmap_update_sb()
440 sb->daemon_sleep = cpu_to_le32(bitmap->mddev->bitmap_info.daemon_sleep/HZ); in bitmap_update_sb()
441 sb->write_behind = cpu_to_le32(bitmap->mddev->bitmap_info.max_write_behind); in bitmap_update_sb()
443 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in bitmap_update_sb()
444 sb->chunksize = cpu_to_le32(bitmap->mddev->bitmap_info.chunksize); in bitmap_update_sb()
445 sb->nodes = cpu_to_le32(bitmap->mddev->bitmap_info.nodes); in bitmap_update_sb()
446 sb->sectors_reserved = cpu_to_le32(bitmap->mddev-> in bitmap_update_sb()
449 write_page(bitmap, bitmap->storage.sb_page, 1); in bitmap_update_sb()
453 void bitmap_print_sb(struct bitmap *bitmap) in bitmap_print_sb() argument
457 if (!bitmap || !bitmap->storage.sb_page) in bitmap_print_sb()
459 sb = kmap_atomic(bitmap->storage.sb_page); in bitmap_print_sb()
460 printk(KERN_DEBUG "%s: bitmap file superblock:\n", bmname(bitmap)); in bitmap_print_sb()
492 static int bitmap_new_disk_sb(struct bitmap *bitmap) in bitmap_new_disk_sb() argument
497 bitmap->storage.sb_page = alloc_page(GFP_KERNEL | __GFP_ZERO); in bitmap_new_disk_sb()
498 if (bitmap->storage.sb_page == NULL) in bitmap_new_disk_sb()
500 bitmap->storage.sb_page->index = 0; in bitmap_new_disk_sb()
502 sb = kmap_atomic(bitmap->storage.sb_page); in bitmap_new_disk_sb()
507 chunksize = bitmap->mddev->bitmap_info.chunksize; in bitmap_new_disk_sb()
516 daemon_sleep = bitmap->mddev->bitmap_info.daemon_sleep; in bitmap_new_disk_sb()
523 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; in bitmap_new_disk_sb()
529 write_behind = bitmap->mddev->bitmap_info.max_write_behind; in bitmap_new_disk_sb()
533 bitmap->mddev->bitmap_info.max_write_behind = write_behind; in bitmap_new_disk_sb()
536 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in bitmap_new_disk_sb()
538 memcpy(sb->uuid, bitmap->mddev->uuid, 16); in bitmap_new_disk_sb()
540 set_bit(BITMAP_STALE, &bitmap->flags); in bitmap_new_disk_sb()
541 sb->state = cpu_to_le32(bitmap->flags); in bitmap_new_disk_sb()
542 bitmap->events_cleared = bitmap->mddev->events; in bitmap_new_disk_sb()
543 sb->events_cleared = cpu_to_le64(bitmap->mddev->events); in bitmap_new_disk_sb()
544 bitmap->mddev->bitmap_info.nodes = 0; in bitmap_new_disk_sb()
552 static int bitmap_read_sb(struct bitmap *bitmap) in bitmap_read_sb() argument
562 loff_t offset = bitmap->mddev->bitmap_info.offset; in bitmap_read_sb()
564 if (!bitmap->storage.file && !bitmap->mddev->bitmap_info.offset) { in bitmap_read_sb()
568 set_bit(BITMAP_STALE, &bitmap->flags); in bitmap_read_sb()
576 bitmap->storage.sb_page = sb_page; in bitmap_read_sb()
580 if (bitmap->cluster_slot >= 0) { in bitmap_read_sb()
581 sector_t bm_blocks = bitmap->mddev->resync_max_sectors; in bitmap_read_sb()
584 bitmap->mddev->bitmap_info.chunksize >> 9); in bitmap_read_sb()
589 offset = bitmap->mddev->bitmap_info.offset + (bitmap->cluster_slot * (bm_blocks << 3)); in bitmap_read_sb()
591 bitmap->cluster_slot, offset); in bitmap_read_sb()
594 if (bitmap->storage.file) { in bitmap_read_sb()
595 loff_t isize = i_size_read(bitmap->storage.file->f_mapping->host); in bitmap_read_sb()
598 err = read_page(bitmap->storage.file, 0, in bitmap_read_sb()
599 bitmap, bytes, sb_page); in bitmap_read_sb()
601 err = read_sb_page(bitmap->mddev, in bitmap_read_sb()
621 strlcpy(bitmap->mddev->bitmap_info.cluster_name, in bitmap_read_sb()
641 bmname(bitmap), reason); in bitmap_read_sb()
646 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in bitmap_read_sb()
648 if (bitmap->mddev->persistent) { in bitmap_read_sb()
653 if (memcmp(sb->uuid, bitmap->mddev->uuid, 16)) { in bitmap_read_sb()
656 bmname(bitmap)); in bitmap_read_sb()
660 if (!nodes && (events < bitmap->mddev->events)) { in bitmap_read_sb()
664 bmname(bitmap), events, in bitmap_read_sb()
665 (unsigned long long) bitmap->mddev->events); in bitmap_read_sb()
666 set_bit(BITMAP_STALE, &bitmap->flags); in bitmap_read_sb()
671 bitmap->flags |= le32_to_cpu(sb->state); in bitmap_read_sb()
673 set_bit(BITMAP_HOSTENDIAN, &bitmap->flags); in bitmap_read_sb()
674 bitmap->events_cleared = le64_to_cpu(sb->events_cleared); in bitmap_read_sb()
675 strlcpy(bitmap->mddev->bitmap_info.cluster_name, sb->cluster_name, 64); in bitmap_read_sb()
681 bitmap->mddev->bitmap_info.chunksize = chunksize; in bitmap_read_sb()
682 if (err == 0 && nodes && (bitmap->cluster_slot < 0)) { in bitmap_read_sb()
683 err = md_setup_cluster(bitmap->mddev, nodes); in bitmap_read_sb()
686 bmname(bitmap), err); in bitmap_read_sb()
689 bitmap->cluster_slot = md_cluster_ops->slot_number(bitmap->mddev); in bitmap_read_sb()
695 if (test_bit(BITMAP_STALE, &bitmap->flags)) in bitmap_read_sb()
696 bitmap->events_cleared = bitmap->mddev->events; in bitmap_read_sb()
697 bitmap->mddev->bitmap_info.chunksize = chunksize; in bitmap_read_sb()
698 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; in bitmap_read_sb()
699 bitmap->mddev->bitmap_info.max_write_behind = write_behind; in bitmap_read_sb()
700 bitmap->mddev->bitmap_info.nodes = nodes; in bitmap_read_sb()
701 if (bitmap->mddev->bitmap_info.space == 0 || in bitmap_read_sb()
702 bitmap->mddev->bitmap_info.space > sectors_reserved) in bitmap_read_sb()
703 bitmap->mddev->bitmap_info.space = sectors_reserved; in bitmap_read_sb()
705 bitmap_print_sb(bitmap); in bitmap_read_sb()
706 if (bitmap->cluster_slot < 0) in bitmap_read_sb()
707 md_cluster_stop(bitmap->mddev); in bitmap_read_sb()
840 static void bitmap_file_kick(struct bitmap *bitmap) in bitmap_file_kick() argument
844 if (!test_and_set_bit(BITMAP_STALE, &bitmap->flags)) { in bitmap_file_kick()
845 bitmap_update_sb(bitmap); in bitmap_file_kick()
847 if (bitmap->storage.file) { in bitmap_file_kick()
850 ptr = file_path(bitmap->storage.file, in bitmap_file_kick()
855 bmname(bitmap), IS_ERR(ptr) ? "" : ptr); in bitmap_file_kick()
861 bmname(bitmap)); in bitmap_file_kick()
872 static inline void set_page_attr(struct bitmap *bitmap, int pnum, in set_page_attr() argument
875 set_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in set_page_attr()
878 static inline void clear_page_attr(struct bitmap *bitmap, int pnum, in clear_page_attr() argument
881 clear_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in clear_page_attr()
884 static inline int test_page_attr(struct bitmap *bitmap, int pnum, in test_page_attr() argument
887 return test_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in test_page_attr()
890 static inline int test_and_clear_page_attr(struct bitmap *bitmap, int pnum, in test_and_clear_page_attr() argument
894 bitmap->storage.filemap_attr); in test_and_clear_page_attr()
903 static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block) in bitmap_file_set_bit() argument
908 unsigned long chunk = block >> bitmap->counts.chunkshift; in bitmap_file_set_bit()
910 page = filemap_get_page(&bitmap->storage, chunk); in bitmap_file_set_bit()
913 bit = file_page_offset(&bitmap->storage, chunk); in bitmap_file_set_bit()
917 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in bitmap_file_set_bit()
924 set_page_attr(bitmap, page->index, BITMAP_PAGE_DIRTY); in bitmap_file_set_bit()
927 static void bitmap_file_clear_bit(struct bitmap *bitmap, sector_t block) in bitmap_file_clear_bit() argument
932 unsigned long chunk = block >> bitmap->counts.chunkshift; in bitmap_file_clear_bit()
934 page = filemap_get_page(&bitmap->storage, chunk); in bitmap_file_clear_bit()
937 bit = file_page_offset(&bitmap->storage, chunk); in bitmap_file_clear_bit()
939 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in bitmap_file_clear_bit()
944 if (!test_page_attr(bitmap, page->index, BITMAP_PAGE_NEEDWRITE)) { in bitmap_file_clear_bit()
945 set_page_attr(bitmap, page->index, BITMAP_PAGE_PENDING); in bitmap_file_clear_bit()
946 bitmap->allclean = 0; in bitmap_file_clear_bit()
950 static int bitmap_file_test_bit(struct bitmap *bitmap, sector_t block) in bitmap_file_test_bit() argument
955 unsigned long chunk = block >> bitmap->counts.chunkshift; in bitmap_file_test_bit()
958 page = filemap_get_page(&bitmap->storage, chunk); in bitmap_file_test_bit()
961 bit = file_page_offset(&bitmap->storage, chunk); in bitmap_file_test_bit()
963 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in bitmap_file_test_bit()
975 void bitmap_unplug(struct bitmap *bitmap) in bitmap_unplug() argument
980 if (!bitmap || !bitmap->storage.filemap || in bitmap_unplug()
981 test_bit(BITMAP_STALE, &bitmap->flags)) in bitmap_unplug()
986 for (i = 0; i < bitmap->storage.file_pages; i++) { in bitmap_unplug()
987 if (!bitmap->storage.filemap) in bitmap_unplug()
989 dirty = test_and_clear_page_attr(bitmap, i, BITMAP_PAGE_DIRTY); in bitmap_unplug()
990 need_write = test_and_clear_page_attr(bitmap, i, in bitmap_unplug()
993 clear_page_attr(bitmap, i, BITMAP_PAGE_PENDING); in bitmap_unplug()
994 write_page(bitmap, bitmap->storage.filemap[i], 0); in bitmap_unplug()
997 if (bitmap->storage.file) in bitmap_unplug()
998 wait_event(bitmap->write_wait, in bitmap_unplug()
999 atomic_read(&bitmap->pending_writes)==0); in bitmap_unplug()
1001 md_super_wait(bitmap->mddev); in bitmap_unplug()
1003 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in bitmap_unplug()
1004 bitmap_file_kick(bitmap); in bitmap_unplug()
1008 static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
1020 static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) in bitmap_init_from_disk() argument
1030 struct bitmap_storage *store = &bitmap->storage; in bitmap_init_from_disk()
1032 chunks = bitmap->counts.chunks; in bitmap_init_from_disk()
1035 if (!file && !bitmap->mddev->bitmap_info.offset) { in bitmap_init_from_disk()
1041 int needed = ((sector_t)(i+1) << (bitmap->counts.chunkshift) in bitmap_init_from_disk()
1043 bitmap_set_memory_bits(bitmap, in bitmap_init_from_disk()
1044 (sector_t)i << bitmap->counts.chunkshift, in bitmap_init_from_disk()
1050 outofdate = test_bit(BITMAP_STALE, &bitmap->flags); in bitmap_init_from_disk()
1053 "recovery\n", bmname(bitmap)); in bitmap_init_from_disk()
1057 bmname(bitmap), in bitmap_init_from_disk()
1065 if (!bitmap->mddev->bitmap_info.external) in bitmap_init_from_disk()
1068 if (mddev_is_clustered(bitmap->mddev)) in bitmap_init_from_disk()
1069 node_offset = bitmap->cluster_slot * (DIV_ROUND_UP(store->bytes, PAGE_SIZE)); in bitmap_init_from_disk()
1073 index = file_page_index(&bitmap->storage, i); in bitmap_init_from_disk()
1074 bit = file_page_offset(&bitmap->storage, i); in bitmap_init_from_disk()
1084 ret = read_page(file, index, bitmap, in bitmap_init_from_disk()
1088 bitmap->mddev, in bitmap_init_from_disk()
1089 bitmap->mddev->bitmap_info.offset, in bitmap_init_from_disk()
1107 write_page(bitmap, page, 1); in bitmap_init_from_disk()
1111 &bitmap->flags)) in bitmap_init_from_disk()
1116 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in bitmap_init_from_disk()
1123 int needed = ((sector_t)(i+1) << bitmap->counts.chunkshift in bitmap_init_from_disk()
1125 bitmap_set_memory_bits(bitmap, in bitmap_init_from_disk()
1126 (sector_t)i << bitmap->counts.chunkshift, in bitmap_init_from_disk()
1135 bmname(bitmap), store->file_pages, in bitmap_init_from_disk()
1142 bmname(bitmap), ret); in bitmap_init_from_disk()
1146 void bitmap_write_all(struct bitmap *bitmap) in bitmap_write_all() argument
1153 if (!bitmap || !bitmap->storage.filemap) in bitmap_write_all()
1155 if (bitmap->storage.file) in bitmap_write_all()
1159 for (i = 0; i < bitmap->storage.file_pages; i++) in bitmap_write_all()
1160 set_page_attr(bitmap, i, in bitmap_write_all()
1162 bitmap->allclean = 0; in bitmap_write_all()
1165 static void bitmap_count_page(struct bitmap_counts *bitmap, in bitmap_count_page() argument
1168 sector_t chunk = offset >> bitmap->chunkshift; in bitmap_count_page()
1170 bitmap->bp[page].count += inc; in bitmap_count_page()
1171 bitmap_checkfree(bitmap, page); in bitmap_count_page()
1174 static void bitmap_set_pending(struct bitmap_counts *bitmap, sector_t offset) in bitmap_set_pending() argument
1176 sector_t chunk = offset >> bitmap->chunkshift; in bitmap_set_pending()
1178 struct bitmap_page *bp = &bitmap->bp[page]; in bitmap_set_pending()
1184 static bitmap_counter_t *bitmap_get_counter(struct bitmap_counts *bitmap,
1195 struct bitmap *bitmap; in bitmap_daemon_work() local
1205 bitmap = mddev->bitmap; in bitmap_daemon_work()
1206 if (bitmap == NULL) { in bitmap_daemon_work()
1210 if (time_before(jiffies, bitmap->daemon_lastrun in bitmap_daemon_work()
1214 bitmap->daemon_lastrun = jiffies; in bitmap_daemon_work()
1215 if (bitmap->allclean) { in bitmap_daemon_work()
1219 bitmap->allclean = 1; in bitmap_daemon_work()
1225 for (j = 0; j < bitmap->storage.file_pages; j++) in bitmap_daemon_work()
1226 if (test_and_clear_page_attr(bitmap, j, in bitmap_daemon_work()
1228 set_page_attr(bitmap, j, in bitmap_daemon_work()
1231 if (bitmap->need_sync && in bitmap_daemon_work()
1236 bitmap->need_sync = 0; in bitmap_daemon_work()
1237 if (bitmap->storage.filemap) { in bitmap_daemon_work()
1238 sb = kmap_atomic(bitmap->storage.sb_page); in bitmap_daemon_work()
1240 cpu_to_le64(bitmap->events_cleared); in bitmap_daemon_work()
1242 set_page_attr(bitmap, 0, in bitmap_daemon_work()
1249 counts = &bitmap->counts; in bitmap_daemon_work()
1272 if (*bmc == 1 && !bitmap->need_sync) { in bitmap_daemon_work()
1276 bitmap_file_clear_bit(bitmap, block); in bitmap_daemon_work()
1280 bitmap->allclean = 0; in bitmap_daemon_work()
1294 j < bitmap->storage.file_pages in bitmap_daemon_work()
1295 && !test_bit(BITMAP_STALE, &bitmap->flags); in bitmap_daemon_work()
1297 if (test_page_attr(bitmap, j, in bitmap_daemon_work()
1301 if (test_and_clear_page_attr(bitmap, j, in bitmap_daemon_work()
1303 write_page(bitmap, bitmap->storage.filemap[j], 0); in bitmap_daemon_work()
1308 if (bitmap->allclean == 0) in bitmap_daemon_work()
1314 static bitmap_counter_t *bitmap_get_counter(struct bitmap_counts *bitmap, in bitmap_get_counter() argument
1317 __releases(bitmap->lock) in bitmap_get_counter()
1318 __acquires(bitmap->lock) in bitmap_get_counter()
1324 sector_t chunk = offset >> bitmap->chunkshift; in bitmap_get_counter()
1330 err = bitmap_checkpage(bitmap, page, create); in bitmap_get_counter()
1332 if (bitmap->bp[page].hijacked || in bitmap_get_counter()
1333 bitmap->bp[page].map == NULL) in bitmap_get_counter()
1334 csize = ((sector_t)1) << (bitmap->chunkshift + in bitmap_get_counter()
1337 csize = ((sector_t)1) << bitmap->chunkshift; in bitmap_get_counter()
1345 if (bitmap->bp[page].hijacked) { /* hijacked pointer */ in bitmap_get_counter()
1350 &bitmap->bp[page].map)[hi]; in bitmap_get_counter()
1353 &(bitmap->bp[page].map[pageoff]); in bitmap_get_counter()
1356 int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind) in bitmap_startwrite() argument
1358 if (!bitmap) in bitmap_startwrite()
1363 atomic_inc(&bitmap->behind_writes); in bitmap_startwrite()
1364 bw = atomic_read(&bitmap->behind_writes); in bitmap_startwrite()
1365 if (bw > bitmap->behind_writes_used) in bitmap_startwrite()
1366 bitmap->behind_writes_used = bw; in bitmap_startwrite()
1369 bw, bitmap->mddev->bitmap_info.max_write_behind); in bitmap_startwrite()
1376 spin_lock_irq(&bitmap->counts.lock); in bitmap_startwrite()
1377 bmc = bitmap_get_counter(&bitmap->counts, offset, &blocks, 1); in bitmap_startwrite()
1379 spin_unlock_irq(&bitmap->counts.lock); in bitmap_startwrite()
1389 prepare_to_wait(&bitmap->overflow_wait, &__wait, in bitmap_startwrite()
1391 spin_unlock_irq(&bitmap->counts.lock); in bitmap_startwrite()
1393 finish_wait(&bitmap->overflow_wait, &__wait); in bitmap_startwrite()
1399 bitmap_file_set_bit(bitmap, offset); in bitmap_startwrite()
1400 bitmap_count_page(&bitmap->counts, offset, 1); in bitmap_startwrite()
1408 spin_unlock_irq(&bitmap->counts.lock); in bitmap_startwrite()
1420 void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, in bitmap_endwrite() argument
1423 if (!bitmap) in bitmap_endwrite()
1426 if (atomic_dec_and_test(&bitmap->behind_writes)) in bitmap_endwrite()
1427 wake_up(&bitmap->behind_wait); in bitmap_endwrite()
1429 atomic_read(&bitmap->behind_writes), in bitmap_endwrite()
1430 bitmap->mddev->bitmap_info.max_write_behind); in bitmap_endwrite()
1438 spin_lock_irqsave(&bitmap->counts.lock, flags); in bitmap_endwrite()
1439 bmc = bitmap_get_counter(&bitmap->counts, offset, &blocks, 0); in bitmap_endwrite()
1441 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in bitmap_endwrite()
1445 if (success && !bitmap->mddev->degraded && in bitmap_endwrite()
1446 bitmap->events_cleared < bitmap->mddev->events) { in bitmap_endwrite()
1447 bitmap->events_cleared = bitmap->mddev->events; in bitmap_endwrite()
1448 bitmap->need_sync = 1; in bitmap_endwrite()
1449 sysfs_notify_dirent_safe(bitmap->sysfs_can_clear); in bitmap_endwrite()
1456 wake_up(&bitmap->overflow_wait); in bitmap_endwrite()
1460 bitmap_set_pending(&bitmap->counts, offset); in bitmap_endwrite()
1461 bitmap->allclean = 0; in bitmap_endwrite()
1463 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in bitmap_endwrite()
1473 static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, in __bitmap_start_sync() argument
1478 if (bitmap == NULL) {/* FIXME or bitmap set as 'failed' */ in __bitmap_start_sync()
1482 spin_lock_irq(&bitmap->counts.lock); in __bitmap_start_sync()
1483 bmc = bitmap_get_counter(&bitmap->counts, offset, blocks, 0); in __bitmap_start_sync()
1497 spin_unlock_irq(&bitmap->counts.lock); in __bitmap_start_sync()
1501 int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, in bitmap_start_sync() argument
1516 rv |= __bitmap_start_sync(bitmap, offset, in bitmap_start_sync()
1525 void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted) in bitmap_end_sync() argument
1530 if (bitmap == NULL) { in bitmap_end_sync()
1534 spin_lock_irqsave(&bitmap->counts.lock, flags); in bitmap_end_sync()
1535 bmc = bitmap_get_counter(&bitmap->counts, offset, blocks, 0); in bitmap_end_sync()
1546 bitmap_set_pending(&bitmap->counts, offset); in bitmap_end_sync()
1547 bitmap->allclean = 0; in bitmap_end_sync()
1552 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in bitmap_end_sync()
1556 void bitmap_close_sync(struct bitmap *bitmap) in bitmap_close_sync() argument
1564 if (!bitmap) in bitmap_close_sync()
1566 while (sector < bitmap->mddev->resync_max_sectors) { in bitmap_close_sync()
1567 bitmap_end_sync(bitmap, sector, &blocks, 0); in bitmap_close_sync()
1573 void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force) in bitmap_cond_end_sync() argument
1578 if (!bitmap) in bitmap_cond_end_sync()
1581 bitmap->last_end_sync = jiffies; in bitmap_cond_end_sync()
1584 if (!force && time_before(jiffies, (bitmap->last_end_sync in bitmap_cond_end_sync()
1585 + bitmap->mddev->bitmap_info.daemon_sleep))) in bitmap_cond_end_sync()
1587 wait_event(bitmap->mddev->recovery_wait, in bitmap_cond_end_sync()
1588 atomic_read(&bitmap->mddev->recovery_active) == 0); in bitmap_cond_end_sync()
1590 bitmap->mddev->curr_resync_completed = sector; in bitmap_cond_end_sync()
1591 set_bit(MD_CHANGE_CLEAN, &bitmap->mddev->flags); in bitmap_cond_end_sync()
1592 sector &= ~((1ULL << bitmap->counts.chunkshift) - 1); in bitmap_cond_end_sync()
1594 while (s < sector && s < bitmap->mddev->resync_max_sectors) { in bitmap_cond_end_sync()
1595 bitmap_end_sync(bitmap, s, &blocks, 0); in bitmap_cond_end_sync()
1598 bitmap->last_end_sync = jiffies; in bitmap_cond_end_sync()
1599 sysfs_notify(&bitmap->mddev->kobj, NULL, "sync_completed"); in bitmap_cond_end_sync()
1603 static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed) in bitmap_set_memory_bits() argument
1612 spin_lock_irq(&bitmap->counts.lock); in bitmap_set_memory_bits()
1613 bmc = bitmap_get_counter(&bitmap->counts, offset, &secs, 1); in bitmap_set_memory_bits()
1615 spin_unlock_irq(&bitmap->counts.lock); in bitmap_set_memory_bits()
1620 bitmap_count_page(&bitmap->counts, offset, 1); in bitmap_set_memory_bits()
1621 bitmap_set_pending(&bitmap->counts, offset); in bitmap_set_memory_bits()
1622 bitmap->allclean = 0; in bitmap_set_memory_bits()
1626 spin_unlock_irq(&bitmap->counts.lock); in bitmap_set_memory_bits()
1630 void bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e) in bitmap_dirty_bits() argument
1635 sector_t sec = (sector_t)chunk << bitmap->counts.chunkshift; in bitmap_dirty_bits()
1636 bitmap_set_memory_bits(bitmap, sec, 1); in bitmap_dirty_bits()
1637 bitmap_file_set_bit(bitmap, sec); in bitmap_dirty_bits()
1638 if (sec < bitmap->mddev->recovery_cp) in bitmap_dirty_bits()
1643 bitmap->mddev->recovery_cp = sec; in bitmap_dirty_bits()
1652 struct bitmap *bitmap = mddev->bitmap; in bitmap_flush() local
1655 if (!bitmap) /* there was no bitmap */ in bitmap_flush()
1662 bitmap->daemon_lastrun -= sleep; in bitmap_flush()
1664 bitmap->daemon_lastrun -= sleep; in bitmap_flush()
1666 bitmap->daemon_lastrun -= sleep; in bitmap_flush()
1668 bitmap_update_sb(bitmap); in bitmap_flush()
1674 static void bitmap_free(struct bitmap *bitmap) in bitmap_free() argument
1679 if (!bitmap) /* there was no bitmap */ in bitmap_free()
1682 if (mddev_is_clustered(bitmap->mddev) && bitmap->mddev->cluster_info && in bitmap_free()
1683 bitmap->cluster_slot == md_cluster_ops->slot_number(bitmap->mddev)) in bitmap_free()
1684 md_cluster_stop(bitmap->mddev); in bitmap_free()
1687 wait_event(bitmap->write_wait, in bitmap_free()
1688 atomic_read(&bitmap->pending_writes) == 0); in bitmap_free()
1691 bitmap_file_unmap(&bitmap->storage); in bitmap_free()
1693 bp = bitmap->counts.bp; in bitmap_free()
1694 pages = bitmap->counts.pages; in bitmap_free()
1703 kfree(bitmap); in bitmap_free()
1708 struct bitmap *bitmap = mddev->bitmap; in bitmap_destroy() local
1710 if (!bitmap) /* there was no bitmap */ in bitmap_destroy()
1715 mddev->bitmap = NULL; /* disconnect from the md device */ in bitmap_destroy()
1721 if (bitmap->sysfs_can_clear) in bitmap_destroy()
1722 sysfs_put(bitmap->sysfs_can_clear); in bitmap_destroy()
1724 bitmap_free(bitmap); in bitmap_destroy()
1731 struct bitmap *bitmap_create(struct mddev *mddev, int slot) in bitmap_create()
1733 struct bitmap *bitmap; in bitmap_create() local
1743 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL); in bitmap_create()
1744 if (!bitmap) in bitmap_create()
1747 spin_lock_init(&bitmap->counts.lock); in bitmap_create()
1748 atomic_set(&bitmap->pending_writes, 0); in bitmap_create()
1749 init_waitqueue_head(&bitmap->write_wait); in bitmap_create()
1750 init_waitqueue_head(&bitmap->overflow_wait); in bitmap_create()
1751 init_waitqueue_head(&bitmap->behind_wait); in bitmap_create()
1753 bitmap->mddev = mddev; in bitmap_create()
1754 bitmap->cluster_slot = slot; in bitmap_create()
1759 bitmap->sysfs_can_clear = sysfs_get_dirent(bm, "can_clear"); in bitmap_create()
1762 bitmap->sysfs_can_clear = NULL; in bitmap_create()
1764 bitmap->storage.file = file; in bitmap_create()
1780 err = bitmap_new_disk_sb(bitmap); in bitmap_create()
1782 err = bitmap_read_sb(bitmap); in bitmap_create()
1794 bitmap->daemon_lastrun = jiffies; in bitmap_create()
1795 err = bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize, 1); in bitmap_create()
1800 bitmap->counts.pages, bmname(bitmap)); in bitmap_create()
1802 err = test_bit(BITMAP_WRITE_ERROR, &bitmap->flags) ? -EIO : 0; in bitmap_create()
1806 return bitmap; in bitmap_create()
1808 bitmap_free(bitmap); in bitmap_create()
1817 struct bitmap *bitmap = mddev->bitmap; in bitmap_load() local
1819 if (!bitmap) in bitmap_load()
1829 bitmap_start_sync(bitmap, sector, &blocks, 0); in bitmap_load()
1832 bitmap_close_sync(bitmap); in bitmap_load()
1835 || bitmap->events_cleared == mddev->events) in bitmap_load()
1841 err = bitmap_init_from_disk(bitmap, start); in bitmap_load()
1846 clear_bit(BITMAP_STALE, &bitmap->flags); in bitmap_load()
1849 set_bit(MD_RECOVERY_NEEDED, &bitmap->mddev->recovery); in bitmap_load()
1854 bitmap_update_sb(bitmap); in bitmap_load()
1856 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in bitmap_load()
1872 struct bitmap *bitmap = bitmap_create(mddev, slot); in bitmap_copy_from_slot() local
1874 if (IS_ERR(bitmap)) in bitmap_copy_from_slot()
1875 return PTR_ERR(bitmap); in bitmap_copy_from_slot()
1877 rv = bitmap_init_from_disk(bitmap, 0); in bitmap_copy_from_slot()
1881 counts = &bitmap->counts; in bitmap_copy_from_slot()
1884 if (bitmap_file_test_bit(bitmap, block)) { in bitmap_copy_from_slot()
1888 bitmap_file_clear_bit(bitmap, block); in bitmap_copy_from_slot()
1889 bitmap_set_memory_bits(mddev->bitmap, block, 1); in bitmap_copy_from_slot()
1890 bitmap_file_set_bit(mddev->bitmap, block); in bitmap_copy_from_slot()
1895 bitmap_update_sb(bitmap); in bitmap_copy_from_slot()
1899 for (i = 0; i < bitmap->storage.file_pages; i++) in bitmap_copy_from_slot()
1900 set_page_attr(bitmap, i, BITMAP_PAGE_DIRTY); in bitmap_copy_from_slot()
1901 bitmap_write_all(bitmap); in bitmap_copy_from_slot()
1902 bitmap_unplug(bitmap); in bitmap_copy_from_slot()
1907 bitmap_free(bitmap); in bitmap_copy_from_slot()
1913 void bitmap_status(struct seq_file *seq, struct bitmap *bitmap) in bitmap_status() argument
1918 if (!bitmap) in bitmap_status()
1921 counts = &bitmap->counts; in bitmap_status()
1923 chunk_kb = bitmap->mddev->bitmap_info.chunksize >> 10; in bitmap_status()
1930 chunk_kb ? chunk_kb : bitmap->mddev->bitmap_info.chunksize, in bitmap_status()
1932 if (bitmap->storage.file) { in bitmap_status()
1934 seq_file_path(seq, bitmap->storage.file, " \t\n"); in bitmap_status()
1940 int bitmap_resize(struct bitmap *bitmap, sector_t blocks, in bitmap_resize() argument
1968 long space = bitmap->mddev->bitmap_info.space; in bitmap_resize()
1974 bytes = DIV_ROUND_UP(bitmap->counts.chunks, 8); in bitmap_resize()
1975 if (!bitmap->mddev->bitmap_info.external) in bitmap_resize()
1978 bitmap->mddev->bitmap_info.space = space; in bitmap_resize()
1980 chunkshift = bitmap->counts.chunkshift; in bitmap_resize()
1987 if (!bitmap->mddev->bitmap_info.external) in bitmap_resize()
1995 if (bitmap->mddev->bitmap_info.offset || bitmap->mddev->bitmap_info.file) in bitmap_resize()
1997 !bitmap->mddev->bitmap_info.external, in bitmap_resize()
1998 mddev_is_clustered(bitmap->mddev) in bitmap_resize()
1999 ? bitmap->cluster_slot : 0); in bitmap_resize()
2013 bitmap->mddev->pers->quiesce(bitmap->mddev, 1); in bitmap_resize()
2015 store.file = bitmap->storage.file; in bitmap_resize()
2016 bitmap->storage.file = NULL; in bitmap_resize()
2018 if (store.sb_page && bitmap->storage.sb_page) in bitmap_resize()
2020 page_address(bitmap->storage.sb_page), in bitmap_resize()
2022 bitmap_file_unmap(&bitmap->storage); in bitmap_resize()
2023 bitmap->storage = store; in bitmap_resize()
2025 old_counts = bitmap->counts; in bitmap_resize()
2026 bitmap->counts.bp = new_bp; in bitmap_resize()
2027 bitmap->counts.pages = pages; in bitmap_resize()
2028 bitmap->counts.missing_pages = pages; in bitmap_resize()
2029 bitmap->counts.chunkshift = chunkshift; in bitmap_resize()
2030 bitmap->counts.chunks = chunks; in bitmap_resize()
2031 bitmap->mddev->bitmap_info.chunksize = 1 << (chunkshift + in bitmap_resize()
2037 spin_lock_irq(&bitmap->counts.lock); in bitmap_resize()
2047 bmc_new = bitmap_get_counter(&bitmap->counts, block, in bitmap_resize()
2055 bitmap_file_set_bit(bitmap, block); in bitmap_resize()
2059 bitmap_count_page(&bitmap->counts, in bitmap_resize()
2061 bitmap_set_pending(&bitmap->counts, in bitmap_resize()
2075 bmc = bitmap_get_counter(&bitmap->counts, block, in bitmap_resize()
2083 bitmap_count_page(&bitmap->counts, in bitmap_resize()
2085 bitmap_set_pending(&bitmap->counts, in bitmap_resize()
2091 for (i = 0; i < bitmap->storage.file_pages; i++) in bitmap_resize()
2092 set_page_attr(bitmap, i, BITMAP_PAGE_DIRTY); in bitmap_resize()
2094 spin_unlock_irq(&bitmap->counts.lock); in bitmap_resize()
2097 bitmap_unplug(bitmap); in bitmap_resize()
2098 bitmap->mddev->pers->quiesce(bitmap->mddev, 0); in bitmap_resize()
2131 if (mddev->bitmap || mddev->bitmap_info.file || in location_store()
2171 struct bitmap *bitmap; in location_store() local
2173 bitmap = bitmap_create(mddev, -1); in location_store()
2174 if (IS_ERR(bitmap)) in location_store()
2175 rv = PTR_ERR(bitmap); in location_store()
2177 mddev->bitmap = bitmap; in location_store()
2226 if (mddev->bitmap && in space_store()
2227 sectors < (mddev->bitmap->storage.bytes + 511) >> 9) in space_store()
2324 if (mddev->bitmap) in chunksize_store()
2349 if (mddev->bitmap || in metadata_store()
2370 if (mddev->bitmap) in can_clear_show()
2371 len = sprintf(page, "%s\n", (mddev->bitmap->need_sync ? in can_clear_show()
2381 if (mddev->bitmap == NULL) in can_clear_store()
2384 mddev->bitmap->need_sync = 1; in can_clear_store()
2388 mddev->bitmap->need_sync = 0; in can_clear_store()
2402 if (mddev->bitmap == NULL) in behind_writes_used_show()
2406 mddev->bitmap->behind_writes_used); in behind_writes_used_show()
2414 if (mddev->bitmap) in behind_writes_used_reset()
2415 mddev->bitmap->behind_writes_used = 0; in behind_writes_used_reset()