Lines Matching refs:bitmap
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 if (page >= bitmap->pages) { in md_bitmap_checkpage()
65 if (bitmap->bp[page].hijacked) /* it's hijacked, don't try to alloc */ in md_bitmap_checkpage()
68 if (bitmap->bp[page].map) /* page is already allocated, just return */ in md_bitmap_checkpage()
76 spin_unlock_irq(&bitmap->lock); in md_bitmap_checkpage()
91 spin_lock_irq(&bitmap->lock); in md_bitmap_checkpage()
100 if (!bitmap->bp[page].map) in md_bitmap_checkpage()
101 bitmap->bp[page].hijacked = 1; in md_bitmap_checkpage()
102 } else if (bitmap->bp[page].map || in md_bitmap_checkpage()
103 bitmap->bp[page].hijacked) { in md_bitmap_checkpage()
110 bitmap->bp[page].map = mappage; in md_bitmap_checkpage()
111 bitmap->missing_pages--; in md_bitmap_checkpage()
119 static void md_bitmap_checkfree(struct bitmap_counts *bitmap, unsigned long page) in md_bitmap_checkfree() argument
123 if (bitmap->bp[page].count) /* page is still busy */ in md_bitmap_checkfree()
128 if (bitmap->bp[page].hijacked) { /* page was hijacked, undo this now */ in md_bitmap_checkfree()
129 bitmap->bp[page].hijacked = 0; in md_bitmap_checkfree()
130 bitmap->bp[page].map = NULL; in md_bitmap_checkfree()
133 ptr = bitmap->bp[page].map; in md_bitmap_checkfree()
134 bitmap->bp[page].map = NULL; in md_bitmap_checkfree()
135 bitmap->missing_pages++; in md_bitmap_checkfree()
212 static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait) in write_sb_page() argument
216 struct mddev *mddev = bitmap->mddev; in write_sb_page()
217 struct bitmap_storage *store = &bitmap->storage; in write_sb_page()
284 static void md_bitmap_file_kick(struct bitmap *bitmap);
288 static void write_page(struct bitmap *bitmap, struct page *page, int wait) in write_page() argument
292 if (bitmap->storage.file == NULL) { in write_page()
293 switch (write_sb_page(bitmap, page, wait)) { in write_page()
295 set_bit(BITMAP_WRITE_ERROR, &bitmap->flags); in write_page()
302 atomic_inc(&bitmap->pending_writes); in write_page()
310 wait_event(bitmap->write_wait, in write_page()
311 atomic_read(&bitmap->pending_writes)==0); in write_page()
313 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in write_page()
314 md_bitmap_file_kick(bitmap); in write_page()
319 struct bitmap *bitmap = bh->b_private; in end_bitmap_write() local
322 set_bit(BITMAP_WRITE_ERROR, &bitmap->flags); in end_bitmap_write()
323 if (atomic_dec_and_test(&bitmap->pending_writes)) in end_bitmap_write()
324 wake_up(&bitmap->write_wait); in end_bitmap_write()
352 struct bitmap *bitmap, 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()
426 static void md_bitmap_wait_writes(struct bitmap *bitmap) in md_bitmap_wait_writes() argument
428 if (bitmap->storage.file) in md_bitmap_wait_writes()
429 wait_event(bitmap->write_wait, in md_bitmap_wait_writes()
430 atomic_read(&bitmap->pending_writes)==0); in md_bitmap_wait_writes()
439 md_super_wait(bitmap->mddev); in md_bitmap_wait_writes()
444 void md_bitmap_update_sb(struct bitmap *bitmap) in md_bitmap_update_sb() argument
448 if (!bitmap || !bitmap->mddev) /* no bitmap for this array */ in md_bitmap_update_sb()
450 if (bitmap->mddev->bitmap_info.external) in md_bitmap_update_sb()
452 if (!bitmap->storage.sb_page) /* no superblock */ in md_bitmap_update_sb()
454 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_update_sb()
455 sb->events = cpu_to_le64(bitmap->mddev->events); in md_bitmap_update_sb()
456 if (bitmap->mddev->events < bitmap->events_cleared) in md_bitmap_update_sb()
458 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_update_sb()
459 sb->events_cleared = cpu_to_le64(bitmap->events_cleared); in md_bitmap_update_sb()
464 sb->state = cpu_to_le32(bitmap->flags & ~BIT(BITMAP_WRITE_ERROR)); in md_bitmap_update_sb()
466 sb->daemon_sleep = cpu_to_le32(bitmap->mddev->bitmap_info.daemon_sleep/HZ); in md_bitmap_update_sb()
467 sb->write_behind = cpu_to_le32(bitmap->mddev->bitmap_info.max_write_behind); in md_bitmap_update_sb()
469 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in md_bitmap_update_sb()
470 sb->chunksize = cpu_to_le32(bitmap->mddev->bitmap_info.chunksize); in md_bitmap_update_sb()
471 sb->nodes = cpu_to_le32(bitmap->mddev->bitmap_info.nodes); in md_bitmap_update_sb()
472 sb->sectors_reserved = cpu_to_le32(bitmap->mddev-> in md_bitmap_update_sb()
475 write_page(bitmap, bitmap->storage.sb_page, 1); in md_bitmap_update_sb()
480 void md_bitmap_print_sb(struct bitmap *bitmap) in md_bitmap_print_sb() argument
484 if (!bitmap || !bitmap->storage.sb_page) in md_bitmap_print_sb()
486 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_print_sb()
487 pr_debug("%s: bitmap file superblock:\n", bmname(bitmap)); in md_bitmap_print_sb()
519 static int md_bitmap_new_disk_sb(struct bitmap *bitmap) in md_bitmap_new_disk_sb() argument
524 bitmap->storage.sb_page = alloc_page(GFP_KERNEL | __GFP_ZERO); in md_bitmap_new_disk_sb()
525 if (bitmap->storage.sb_page == NULL) in md_bitmap_new_disk_sb()
527 bitmap->storage.sb_page->index = 0; in md_bitmap_new_disk_sb()
529 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_new_disk_sb()
534 chunksize = bitmap->mddev->bitmap_info.chunksize; in md_bitmap_new_disk_sb()
543 daemon_sleep = bitmap->mddev->bitmap_info.daemon_sleep; in md_bitmap_new_disk_sb()
549 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; in md_bitmap_new_disk_sb()
555 write_behind = bitmap->mddev->bitmap_info.max_write_behind; in md_bitmap_new_disk_sb()
559 bitmap->mddev->bitmap_info.max_write_behind = write_behind; in md_bitmap_new_disk_sb()
562 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in md_bitmap_new_disk_sb()
564 memcpy(sb->uuid, bitmap->mddev->uuid, 16); in md_bitmap_new_disk_sb()
566 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_new_disk_sb()
567 sb->state = cpu_to_le32(bitmap->flags); in md_bitmap_new_disk_sb()
568 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_new_disk_sb()
569 sb->events_cleared = cpu_to_le64(bitmap->mddev->events); in md_bitmap_new_disk_sb()
570 bitmap->mddev->bitmap_info.nodes = 0; in md_bitmap_new_disk_sb()
578 static int md_bitmap_read_sb(struct bitmap *bitmap) in md_bitmap_read_sb() argument
588 loff_t offset = bitmap->mddev->bitmap_info.offset; in md_bitmap_read_sb()
590 if (!bitmap->storage.file && !bitmap->mddev->bitmap_info.offset) { in md_bitmap_read_sb()
594 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_read_sb()
602 bitmap->storage.sb_page = sb_page; in md_bitmap_read_sb()
606 if (bitmap->cluster_slot >= 0) { in md_bitmap_read_sb()
607 sector_t bm_blocks = bitmap->mddev->resync_max_sectors; in md_bitmap_read_sb()
610 (bitmap->mddev->bitmap_info.chunksize >> 9)); in md_bitmap_read_sb()
615 offset = bitmap->mddev->bitmap_info.offset + (bitmap->cluster_slot * (bm_blocks << 3)); in md_bitmap_read_sb()
617 bitmap->cluster_slot, offset); in md_bitmap_read_sb()
620 if (bitmap->storage.file) { in md_bitmap_read_sb()
621 loff_t isize = i_size_read(bitmap->storage.file->f_mapping->host); in md_bitmap_read_sb()
624 err = read_page(bitmap->storage.file, 0, in md_bitmap_read_sb()
625 bitmap, bytes, sb_page); in md_bitmap_read_sb()
627 err = read_sb_page(bitmap->mddev, in md_bitmap_read_sb()
659 bmname(bitmap), reason); in md_bitmap_read_sb()
669 strlcpy(bitmap->mddev->bitmap_info.cluster_name, in md_bitmap_read_sb()
674 sb->sync_size = cpu_to_le64(bitmap->mddev->resync_max_sectors); in md_bitmap_read_sb()
676 if (bitmap->mddev->persistent) { in md_bitmap_read_sb()
681 if (memcmp(sb->uuid, bitmap->mddev->uuid, 16)) { in md_bitmap_read_sb()
683 bmname(bitmap)); in md_bitmap_read_sb()
687 if (!nodes && (events < bitmap->mddev->events)) { in md_bitmap_read_sb()
689 bmname(bitmap), events, in md_bitmap_read_sb()
690 (unsigned long long) bitmap->mddev->events); in md_bitmap_read_sb()
691 set_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_read_sb()
696 bitmap->flags |= le32_to_cpu(sb->state); in md_bitmap_read_sb()
698 set_bit(BITMAP_HOSTENDIAN, &bitmap->flags); in md_bitmap_read_sb()
699 bitmap->events_cleared = le64_to_cpu(sb->events_cleared); in md_bitmap_read_sb()
700 strlcpy(bitmap->mddev->bitmap_info.cluster_name, sb->cluster_name, 64); in md_bitmap_read_sb()
705 if (err == 0 && nodes && (bitmap->cluster_slot < 0)) { in md_bitmap_read_sb()
707 bitmap->mddev->bitmap_info.chunksize = chunksize; in md_bitmap_read_sb()
708 err = md_setup_cluster(bitmap->mddev, nodes); in md_bitmap_read_sb()
711 bmname(bitmap), err); in md_bitmap_read_sb()
714 bitmap->cluster_slot = md_cluster_ops->slot_number(bitmap->mddev); in md_bitmap_read_sb()
720 if (test_bit(BITMAP_STALE, &bitmap->flags)) in md_bitmap_read_sb()
721 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_read_sb()
722 bitmap->mddev->bitmap_info.chunksize = chunksize; in md_bitmap_read_sb()
723 bitmap->mddev->bitmap_info.daemon_sleep = daemon_sleep; in md_bitmap_read_sb()
724 bitmap->mddev->bitmap_info.max_write_behind = write_behind; in md_bitmap_read_sb()
725 bitmap->mddev->bitmap_info.nodes = nodes; in md_bitmap_read_sb()
726 if (bitmap->mddev->bitmap_info.space == 0 || in md_bitmap_read_sb()
727 bitmap->mddev->bitmap_info.space > sectors_reserved) in md_bitmap_read_sb()
728 bitmap->mddev->bitmap_info.space = sectors_reserved; in md_bitmap_read_sb()
730 md_bitmap_print_sb(bitmap); in md_bitmap_read_sb()
731 if (bitmap->cluster_slot < 0) in md_bitmap_read_sb()
732 md_cluster_stop(bitmap->mddev); in md_bitmap_read_sb()
865 static void md_bitmap_file_kick(struct bitmap *bitmap) in md_bitmap_file_kick() argument
869 if (!test_and_set_bit(BITMAP_STALE, &bitmap->flags)) { in md_bitmap_file_kick()
870 md_bitmap_update_sb(bitmap); in md_bitmap_file_kick()
872 if (bitmap->storage.file) { in md_bitmap_file_kick()
875 ptr = file_path(bitmap->storage.file, in md_bitmap_file_kick()
879 bmname(bitmap), IS_ERR(ptr) ? "" : ptr); in md_bitmap_file_kick()
884 bmname(bitmap)); in md_bitmap_file_kick()
895 static inline void set_page_attr(struct bitmap *bitmap, int pnum, in set_page_attr() argument
898 set_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in set_page_attr()
901 static inline void clear_page_attr(struct bitmap *bitmap, int pnum, in clear_page_attr() argument
904 clear_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in clear_page_attr()
907 static inline int test_page_attr(struct bitmap *bitmap, int pnum, in test_page_attr() argument
910 return test_bit((pnum<<2) + attr, bitmap->storage.filemap_attr); in test_page_attr()
913 static inline int test_and_clear_page_attr(struct bitmap *bitmap, int pnum, in test_and_clear_page_attr() argument
917 bitmap->storage.filemap_attr); in test_and_clear_page_attr()
926 static void md_bitmap_file_set_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_set_bit() argument
931 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_set_bit()
932 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_file_set_bit()
935 if (mddev_is_clustered(bitmap->mddev)) in md_bitmap_file_set_bit()
936 node_offset = bitmap->cluster_slot * store->file_pages; in md_bitmap_file_set_bit()
938 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_set_bit()
941 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_set_bit()
945 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_set_bit()
952 set_page_attr(bitmap, page->index - node_offset, BITMAP_PAGE_DIRTY); in md_bitmap_file_set_bit()
955 static void md_bitmap_file_clear_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_clear_bit() argument
960 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_clear_bit()
961 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_file_clear_bit()
964 if (mddev_is_clustered(bitmap->mddev)) in md_bitmap_file_clear_bit()
965 node_offset = bitmap->cluster_slot * store->file_pages; in md_bitmap_file_clear_bit()
967 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_clear_bit()
970 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_clear_bit()
972 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_clear_bit()
977 if (!test_page_attr(bitmap, page->index - node_offset, BITMAP_PAGE_NEEDWRITE)) { in md_bitmap_file_clear_bit()
978 set_page_attr(bitmap, page->index - node_offset, BITMAP_PAGE_PENDING); in md_bitmap_file_clear_bit()
979 bitmap->allclean = 0; in md_bitmap_file_clear_bit()
983 static int md_bitmap_file_test_bit(struct bitmap *bitmap, sector_t block) in md_bitmap_file_test_bit() argument
988 unsigned long chunk = block >> bitmap->counts.chunkshift; in md_bitmap_file_test_bit()
991 page = filemap_get_page(&bitmap->storage, chunk); in md_bitmap_file_test_bit()
994 bit = file_page_offset(&bitmap->storage, chunk); in md_bitmap_file_test_bit()
996 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_file_test_bit()
1008 void md_bitmap_unplug(struct bitmap *bitmap) in md_bitmap_unplug() argument
1014 if (!bitmap || !bitmap->storage.filemap || in md_bitmap_unplug()
1015 test_bit(BITMAP_STALE, &bitmap->flags)) in md_bitmap_unplug()
1020 for (i = 0; i < bitmap->storage.file_pages; i++) { in md_bitmap_unplug()
1021 dirty = test_and_clear_page_attr(bitmap, i, BITMAP_PAGE_DIRTY); in md_bitmap_unplug()
1022 need_write = test_and_clear_page_attr(bitmap, i, in md_bitmap_unplug()
1026 md_bitmap_wait_writes(bitmap); in md_bitmap_unplug()
1027 if (bitmap->mddev->queue) in md_bitmap_unplug()
1028 blk_add_trace_msg(bitmap->mddev->queue, in md_bitmap_unplug()
1031 clear_page_attr(bitmap, i, BITMAP_PAGE_PENDING); in md_bitmap_unplug()
1032 write_page(bitmap, bitmap->storage.filemap[i], 0); in md_bitmap_unplug()
1037 md_bitmap_wait_writes(bitmap); in md_bitmap_unplug()
1039 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in md_bitmap_unplug()
1040 md_bitmap_file_kick(bitmap); in md_bitmap_unplug()
1044 static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
1056 static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start) in md_bitmap_init_from_disk() argument
1066 struct bitmap_storage *store = &bitmap->storage; in md_bitmap_init_from_disk()
1068 chunks = bitmap->counts.chunks; in md_bitmap_init_from_disk()
1071 if (!file && !bitmap->mddev->bitmap_info.offset) { in md_bitmap_init_from_disk()
1077 int needed = ((sector_t)(i+1) << (bitmap->counts.chunkshift) in md_bitmap_init_from_disk()
1079 md_bitmap_set_memory_bits(bitmap, in md_bitmap_init_from_disk()
1080 (sector_t)i << bitmap->counts.chunkshift, in md_bitmap_init_from_disk()
1086 outofdate = test_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_init_from_disk()
1088 pr_warn("%s: bitmap file is out of date, doing full recovery\n", bmname(bitmap)); in md_bitmap_init_from_disk()
1092 bmname(bitmap), in md_bitmap_init_from_disk()
1100 if (!bitmap->mddev->bitmap_info.external) in md_bitmap_init_from_disk()
1103 if (mddev_is_clustered(bitmap->mddev)) in md_bitmap_init_from_disk()
1104 node_offset = bitmap->cluster_slot * (DIV_ROUND_UP(store->bytes, PAGE_SIZE)); in md_bitmap_init_from_disk()
1108 index = file_page_index(&bitmap->storage, i); in md_bitmap_init_from_disk()
1109 bit = file_page_offset(&bitmap->storage, i); in md_bitmap_init_from_disk()
1119 ret = read_page(file, index, bitmap, in md_bitmap_init_from_disk()
1123 bitmap->mddev, in md_bitmap_init_from_disk()
1124 bitmap->mddev->bitmap_info.offset, in md_bitmap_init_from_disk()
1142 write_page(bitmap, page, 1); in md_bitmap_init_from_disk()
1146 &bitmap->flags)) in md_bitmap_init_from_disk()
1151 if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags)) in md_bitmap_init_from_disk()
1158 int needed = ((sector_t)(i+1) << bitmap->counts.chunkshift in md_bitmap_init_from_disk()
1160 md_bitmap_set_memory_bits(bitmap, in md_bitmap_init_from_disk()
1161 (sector_t)i << bitmap->counts.chunkshift, in md_bitmap_init_from_disk()
1169 bmname(bitmap), store->file_pages, in md_bitmap_init_from_disk()
1176 bmname(bitmap), ret); in md_bitmap_init_from_disk()
1180 void md_bitmap_write_all(struct bitmap *bitmap) in md_bitmap_write_all() argument
1187 if (!bitmap || !bitmap->storage.filemap) in md_bitmap_write_all()
1189 if (bitmap->storage.file) in md_bitmap_write_all()
1193 for (i = 0; i < bitmap->storage.file_pages; i++) in md_bitmap_write_all()
1194 set_page_attr(bitmap, i, in md_bitmap_write_all()
1196 bitmap->allclean = 0; in md_bitmap_write_all()
1199 static void md_bitmap_count_page(struct bitmap_counts *bitmap, in md_bitmap_count_page() argument
1202 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_count_page()
1204 bitmap->bp[page].count += inc; in md_bitmap_count_page()
1205 md_bitmap_checkfree(bitmap, page); in md_bitmap_count_page()
1208 static void md_bitmap_set_pending(struct bitmap_counts *bitmap, sector_t offset) in md_bitmap_set_pending() argument
1210 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_set_pending()
1212 struct bitmap_page *bp = &bitmap->bp[page]; in md_bitmap_set_pending()
1218 static bitmap_counter_t *md_bitmap_get_counter(struct bitmap_counts *bitmap,
1229 struct bitmap *bitmap; in md_bitmap_daemon_work() local
1239 bitmap = mddev->bitmap; in md_bitmap_daemon_work()
1240 if (bitmap == NULL) { in md_bitmap_daemon_work()
1244 if (time_before(jiffies, bitmap->daemon_lastrun in md_bitmap_daemon_work()
1248 bitmap->daemon_lastrun = jiffies; in md_bitmap_daemon_work()
1249 if (bitmap->allclean) { in md_bitmap_daemon_work()
1253 bitmap->allclean = 1; in md_bitmap_daemon_work()
1255 if (bitmap->mddev->queue) in md_bitmap_daemon_work()
1256 blk_add_trace_msg(bitmap->mddev->queue, in md_bitmap_daemon_work()
1263 for (j = 0; j < bitmap->storage.file_pages; j++) in md_bitmap_daemon_work()
1264 if (test_and_clear_page_attr(bitmap, j, in md_bitmap_daemon_work()
1266 set_page_attr(bitmap, j, in md_bitmap_daemon_work()
1269 if (bitmap->need_sync && in md_bitmap_daemon_work()
1274 bitmap->need_sync = 0; in md_bitmap_daemon_work()
1275 if (bitmap->storage.filemap) { in md_bitmap_daemon_work()
1276 sb = kmap_atomic(bitmap->storage.sb_page); in md_bitmap_daemon_work()
1278 cpu_to_le64(bitmap->events_cleared); in md_bitmap_daemon_work()
1280 set_page_attr(bitmap, 0, in md_bitmap_daemon_work()
1287 counts = &bitmap->counts; in md_bitmap_daemon_work()
1308 if (*bmc == 1 && !bitmap->need_sync) { in md_bitmap_daemon_work()
1312 md_bitmap_file_clear_bit(bitmap, block); in md_bitmap_daemon_work()
1316 bitmap->allclean = 0; in md_bitmap_daemon_work()
1321 md_bitmap_wait_writes(bitmap); in md_bitmap_daemon_work()
1331 j < bitmap->storage.file_pages in md_bitmap_daemon_work()
1332 && !test_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_daemon_work()
1334 if (test_page_attr(bitmap, j, in md_bitmap_daemon_work()
1338 if (bitmap->storage.filemap && in md_bitmap_daemon_work()
1339 test_and_clear_page_attr(bitmap, j, in md_bitmap_daemon_work()
1341 write_page(bitmap, bitmap->storage.filemap[j], 0); in md_bitmap_daemon_work()
1346 if (bitmap->allclean == 0) in md_bitmap_daemon_work()
1352 static bitmap_counter_t *md_bitmap_get_counter(struct bitmap_counts *bitmap, in md_bitmap_get_counter() argument
1355 __releases(bitmap->lock) in md_bitmap_get_counter()
1356 __acquires(bitmap->lock) in md_bitmap_get_counter()
1362 sector_t chunk = offset >> bitmap->chunkshift; in md_bitmap_get_counter()
1368 err = md_bitmap_checkpage(bitmap, page, create, 0); in md_bitmap_get_counter()
1370 if (bitmap->bp[page].hijacked || in md_bitmap_get_counter()
1371 bitmap->bp[page].map == NULL) in md_bitmap_get_counter()
1372 csize = ((sector_t)1) << (bitmap->chunkshift + in md_bitmap_get_counter()
1375 csize = ((sector_t)1) << bitmap->chunkshift; in md_bitmap_get_counter()
1383 if (bitmap->bp[page].hijacked) { /* hijacked pointer */ in md_bitmap_get_counter()
1388 &bitmap->bp[page].map)[hi]; in md_bitmap_get_counter()
1391 &(bitmap->bp[page].map[pageoff]); in md_bitmap_get_counter()
1394 int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind) in md_bitmap_startwrite() argument
1396 if (!bitmap) in md_bitmap_startwrite()
1401 atomic_inc(&bitmap->behind_writes); in md_bitmap_startwrite()
1402 bw = atomic_read(&bitmap->behind_writes); in md_bitmap_startwrite()
1403 if (bw > bitmap->behind_writes_used) in md_bitmap_startwrite()
1404 bitmap->behind_writes_used = bw; in md_bitmap_startwrite()
1407 bw, bitmap->mddev->bitmap_info.max_write_behind); in md_bitmap_startwrite()
1414 spin_lock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1415 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &blocks, 1); in md_bitmap_startwrite()
1417 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1427 prepare_to_wait(&bitmap->overflow_wait, &__wait, in md_bitmap_startwrite()
1429 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1431 finish_wait(&bitmap->overflow_wait, &__wait); in md_bitmap_startwrite()
1437 md_bitmap_file_set_bit(bitmap, offset); in md_bitmap_startwrite()
1438 md_bitmap_count_page(&bitmap->counts, offset, 1); in md_bitmap_startwrite()
1446 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_startwrite()
1458 void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset, in md_bitmap_endwrite() argument
1461 if (!bitmap) in md_bitmap_endwrite()
1464 if (atomic_dec_and_test(&bitmap->behind_writes)) in md_bitmap_endwrite()
1465 wake_up(&bitmap->behind_wait); in md_bitmap_endwrite()
1467 atomic_read(&bitmap->behind_writes), in md_bitmap_endwrite()
1468 bitmap->mddev->bitmap_info.max_write_behind); in md_bitmap_endwrite()
1476 spin_lock_irqsave(&bitmap->counts.lock, flags); in md_bitmap_endwrite()
1477 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &blocks, 0); in md_bitmap_endwrite()
1479 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in md_bitmap_endwrite()
1483 if (success && !bitmap->mddev->degraded && in md_bitmap_endwrite()
1484 bitmap->events_cleared < bitmap->mddev->events) { in md_bitmap_endwrite()
1485 bitmap->events_cleared = bitmap->mddev->events; in md_bitmap_endwrite()
1486 bitmap->need_sync = 1; in md_bitmap_endwrite()
1487 sysfs_notify_dirent_safe(bitmap->sysfs_can_clear); in md_bitmap_endwrite()
1494 wake_up(&bitmap->overflow_wait); in md_bitmap_endwrite()
1498 md_bitmap_set_pending(&bitmap->counts, offset); in md_bitmap_endwrite()
1499 bitmap->allclean = 0; in md_bitmap_endwrite()
1501 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in md_bitmap_endwrite()
1511 static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, in __bitmap_start_sync() argument
1516 if (bitmap == NULL) {/* FIXME or bitmap set as 'failed' */ in __bitmap_start_sync()
1520 spin_lock_irq(&bitmap->counts.lock); in __bitmap_start_sync()
1521 bmc = md_bitmap_get_counter(&bitmap->counts, offset, blocks, 0); in __bitmap_start_sync()
1535 spin_unlock_irq(&bitmap->counts.lock); in __bitmap_start_sync()
1539 int md_bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, in md_bitmap_start_sync() argument
1554 rv |= __bitmap_start_sync(bitmap, offset, in md_bitmap_start_sync()
1563 void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted) in md_bitmap_end_sync() argument
1568 if (bitmap == NULL) { in md_bitmap_end_sync()
1572 spin_lock_irqsave(&bitmap->counts.lock, flags); in md_bitmap_end_sync()
1573 bmc = md_bitmap_get_counter(&bitmap->counts, offset, blocks, 0); in md_bitmap_end_sync()
1584 md_bitmap_set_pending(&bitmap->counts, offset); in md_bitmap_end_sync()
1585 bitmap->allclean = 0; in md_bitmap_end_sync()
1590 spin_unlock_irqrestore(&bitmap->counts.lock, flags); in md_bitmap_end_sync()
1594 void md_bitmap_close_sync(struct bitmap *bitmap) in md_bitmap_close_sync() argument
1602 if (!bitmap) in md_bitmap_close_sync()
1604 while (sector < bitmap->mddev->resync_max_sectors) { in md_bitmap_close_sync()
1605 md_bitmap_end_sync(bitmap, sector, &blocks, 0); in md_bitmap_close_sync()
1611 void md_bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force) in md_bitmap_cond_end_sync() argument
1616 if (!bitmap) in md_bitmap_cond_end_sync()
1619 bitmap->last_end_sync = jiffies; in md_bitmap_cond_end_sync()
1622 if (!force && time_before(jiffies, (bitmap->last_end_sync in md_bitmap_cond_end_sync()
1623 + bitmap->mddev->bitmap_info.daemon_sleep))) in md_bitmap_cond_end_sync()
1625 wait_event(bitmap->mddev->recovery_wait, in md_bitmap_cond_end_sync()
1626 atomic_read(&bitmap->mddev->recovery_active) == 0); in md_bitmap_cond_end_sync()
1628 bitmap->mddev->curr_resync_completed = sector; in md_bitmap_cond_end_sync()
1629 set_bit(MD_SB_CHANGE_CLEAN, &bitmap->mddev->sb_flags); in md_bitmap_cond_end_sync()
1630 sector &= ~((1ULL << bitmap->counts.chunkshift) - 1); in md_bitmap_cond_end_sync()
1632 while (s < sector && s < bitmap->mddev->resync_max_sectors) { in md_bitmap_cond_end_sync()
1633 md_bitmap_end_sync(bitmap, s, &blocks, 0); in md_bitmap_cond_end_sync()
1636 bitmap->last_end_sync = jiffies; in md_bitmap_cond_end_sync()
1637 sysfs_notify_dirent_safe(bitmap->mddev->sysfs_completed); in md_bitmap_cond_end_sync()
1645 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_sync_with_cluster() local
1649 md_bitmap_end_sync(bitmap, sector, &blocks, 0); in md_bitmap_sync_with_cluster()
1655 md_bitmap_start_sync(bitmap, sector, &blocks, 0); in md_bitmap_sync_with_cluster()
1662 static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed) in md_bitmap_set_memory_bits() argument
1671 spin_lock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1672 bmc = md_bitmap_get_counter(&bitmap->counts, offset, &secs, 1); in md_bitmap_set_memory_bits()
1674 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1679 md_bitmap_count_page(&bitmap->counts, offset, 1); in md_bitmap_set_memory_bits()
1680 md_bitmap_set_pending(&bitmap->counts, offset); in md_bitmap_set_memory_bits()
1681 bitmap->allclean = 0; in md_bitmap_set_memory_bits()
1685 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_set_memory_bits()
1689 void md_bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e) in md_bitmap_dirty_bits() argument
1694 sector_t sec = (sector_t)chunk << bitmap->counts.chunkshift; in md_bitmap_dirty_bits()
1695 md_bitmap_set_memory_bits(bitmap, sec, 1); in md_bitmap_dirty_bits()
1696 md_bitmap_file_set_bit(bitmap, sec); in md_bitmap_dirty_bits()
1697 if (sec < bitmap->mddev->recovery_cp) in md_bitmap_dirty_bits()
1702 bitmap->mddev->recovery_cp = sec; in md_bitmap_dirty_bits()
1711 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_flush() local
1714 if (!bitmap) /* there was no bitmap */ in md_bitmap_flush()
1721 bitmap->daemon_lastrun -= sleep; in md_bitmap_flush()
1723 bitmap->daemon_lastrun -= sleep; in md_bitmap_flush()
1725 bitmap->daemon_lastrun -= sleep; in md_bitmap_flush()
1729 md_bitmap_update_sb(bitmap); in md_bitmap_flush()
1735 void md_bitmap_free(struct bitmap *bitmap) in md_bitmap_free() argument
1740 if (!bitmap) /* there was no bitmap */ in md_bitmap_free()
1743 if (bitmap->sysfs_can_clear) in md_bitmap_free()
1744 sysfs_put(bitmap->sysfs_can_clear); in md_bitmap_free()
1746 if (mddev_is_clustered(bitmap->mddev) && bitmap->mddev->cluster_info && in md_bitmap_free()
1747 bitmap->cluster_slot == md_cluster_ops->slot_number(bitmap->mddev)) in md_bitmap_free()
1748 md_cluster_stop(bitmap->mddev); in md_bitmap_free()
1751 wait_event(bitmap->write_wait, in md_bitmap_free()
1752 atomic_read(&bitmap->pending_writes) == 0); in md_bitmap_free()
1755 md_bitmap_file_unmap(&bitmap->storage); in md_bitmap_free()
1757 bp = bitmap->counts.bp; in md_bitmap_free()
1758 pages = bitmap->counts.pages; in md_bitmap_free()
1767 kfree(bitmap); in md_bitmap_free()
1773 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_wait_behind_writes() local
1776 if (bitmap && atomic_read(&bitmap->behind_writes) > 0) { in md_bitmap_wait_behind_writes()
1780 wait_event(bitmap->behind_wait, in md_bitmap_wait_behind_writes()
1781 atomic_read(&bitmap->behind_writes) == 0); in md_bitmap_wait_behind_writes()
1787 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_destroy() local
1789 if (!bitmap) /* there was no bitmap */ in md_bitmap_destroy()
1798 mddev->bitmap = NULL; /* disconnect from the md device */ in md_bitmap_destroy()
1804 md_bitmap_free(bitmap); in md_bitmap_destroy()
1812 struct bitmap *md_bitmap_create(struct mddev *mddev, int slot) in md_bitmap_create()
1814 struct bitmap *bitmap; in md_bitmap_create() local
1830 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL); in md_bitmap_create()
1831 if (!bitmap) in md_bitmap_create()
1834 spin_lock_init(&bitmap->counts.lock); in md_bitmap_create()
1835 atomic_set(&bitmap->pending_writes, 0); in md_bitmap_create()
1836 init_waitqueue_head(&bitmap->write_wait); in md_bitmap_create()
1837 init_waitqueue_head(&bitmap->overflow_wait); in md_bitmap_create()
1838 init_waitqueue_head(&bitmap->behind_wait); in md_bitmap_create()
1840 bitmap->mddev = mddev; in md_bitmap_create()
1841 bitmap->cluster_slot = slot; in md_bitmap_create()
1846 bitmap->sysfs_can_clear = sysfs_get_dirent(bm, "can_clear"); in md_bitmap_create()
1849 bitmap->sysfs_can_clear = NULL; in md_bitmap_create()
1851 bitmap->storage.file = file; in md_bitmap_create()
1867 err = md_bitmap_new_disk_sb(bitmap); in md_bitmap_create()
1869 err = md_bitmap_read_sb(bitmap); in md_bitmap_create()
1881 bitmap->daemon_lastrun = jiffies; in md_bitmap_create()
1882 err = md_bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize, 1); in md_bitmap_create()
1887 bitmap->counts.pages, bmname(bitmap)); in md_bitmap_create()
1889 err = test_bit(BITMAP_WRITE_ERROR, &bitmap->flags) ? -EIO : 0; in md_bitmap_create()
1893 return bitmap; in md_bitmap_create()
1895 md_bitmap_free(bitmap); in md_bitmap_create()
1904 struct bitmap *bitmap = mddev->bitmap; in md_bitmap_load() local
1907 if (!bitmap) in md_bitmap_load()
1923 md_bitmap_start_sync(bitmap, sector, &blocks, 0); in md_bitmap_load()
1926 md_bitmap_close_sync(bitmap); in md_bitmap_load()
1929 || bitmap->events_cleared == mddev->events) in md_bitmap_load()
1935 err = md_bitmap_init_from_disk(bitmap, start); in md_bitmap_load()
1940 clear_bit(BITMAP_STALE, &bitmap->flags); in md_bitmap_load()
1943 set_bit(MD_RECOVERY_NEEDED, &bitmap->mddev->recovery); in md_bitmap_load()
1948 md_bitmap_update_sb(bitmap); in md_bitmap_load()
1950 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) in md_bitmap_load()
1958 struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot) in get_bitmap_from_slot()
1961 struct bitmap *bitmap; in get_bitmap_from_slot() local
1963 bitmap = md_bitmap_create(mddev, slot); in get_bitmap_from_slot()
1964 if (IS_ERR(bitmap)) { in get_bitmap_from_slot()
1965 rv = PTR_ERR(bitmap); in get_bitmap_from_slot()
1969 rv = md_bitmap_init_from_disk(bitmap, 0); in get_bitmap_from_slot()
1971 md_bitmap_free(bitmap); in get_bitmap_from_slot()
1975 return bitmap; in get_bitmap_from_slot()
1988 struct bitmap *bitmap; in md_bitmap_copy_from_slot() local
1990 bitmap = get_bitmap_from_slot(mddev, slot); in md_bitmap_copy_from_slot()
1991 if (IS_ERR(bitmap)) { in md_bitmap_copy_from_slot()
1996 counts = &bitmap->counts; in md_bitmap_copy_from_slot()
1999 if (md_bitmap_file_test_bit(bitmap, block)) { in md_bitmap_copy_from_slot()
2003 md_bitmap_file_clear_bit(bitmap, block); in md_bitmap_copy_from_slot()
2004 md_bitmap_set_memory_bits(mddev->bitmap, block, 1); in md_bitmap_copy_from_slot()
2005 md_bitmap_file_set_bit(mddev->bitmap, block); in md_bitmap_copy_from_slot()
2010 md_bitmap_update_sb(bitmap); in md_bitmap_copy_from_slot()
2013 for (i = 0; i < bitmap->storage.file_pages; i++) in md_bitmap_copy_from_slot()
2014 if (test_page_attr(bitmap, i, BITMAP_PAGE_PENDING)) in md_bitmap_copy_from_slot()
2015 set_page_attr(bitmap, i, BITMAP_PAGE_NEEDWRITE); in md_bitmap_copy_from_slot()
2016 md_bitmap_unplug(bitmap); in md_bitmap_copy_from_slot()
2018 md_bitmap_unplug(mddev->bitmap); in md_bitmap_copy_from_slot()
2021 md_bitmap_free(bitmap); in md_bitmap_copy_from_slot()
2028 void md_bitmap_status(struct seq_file *seq, struct bitmap *bitmap) in md_bitmap_status() argument
2033 if (!bitmap) in md_bitmap_status()
2036 counts = &bitmap->counts; in md_bitmap_status()
2038 chunk_kb = bitmap->mddev->bitmap_info.chunksize >> 10; in md_bitmap_status()
2045 chunk_kb ? chunk_kb : bitmap->mddev->bitmap_info.chunksize, in md_bitmap_status()
2047 if (bitmap->storage.file) { in md_bitmap_status()
2049 seq_file_path(seq, bitmap->storage.file, " \t\n"); in md_bitmap_status()
2055 int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks, in md_bitmap_resize() argument
2078 if (bitmap->storage.file && !init) { in md_bitmap_resize()
2088 long space = bitmap->mddev->bitmap_info.space; in md_bitmap_resize()
2094 bytes = DIV_ROUND_UP(bitmap->counts.chunks, 8); in md_bitmap_resize()
2095 if (!bitmap->mddev->bitmap_info.external) in md_bitmap_resize()
2098 bitmap->mddev->bitmap_info.space = space; in md_bitmap_resize()
2100 chunkshift = bitmap->counts.chunkshift; in md_bitmap_resize()
2107 if (!bitmap->mddev->bitmap_info.external) in md_bitmap_resize()
2115 if (bitmap->mddev->bitmap_info.offset || bitmap->mddev->bitmap_info.file) in md_bitmap_resize()
2117 !bitmap->mddev->bitmap_info.external, in md_bitmap_resize()
2118 mddev_is_clustered(bitmap->mddev) in md_bitmap_resize()
2119 ? bitmap->cluster_slot : 0); in md_bitmap_resize()
2135 bitmap->mddev->pers->quiesce(bitmap->mddev, 1); in md_bitmap_resize()
2137 store.file = bitmap->storage.file; in md_bitmap_resize()
2138 bitmap->storage.file = NULL; in md_bitmap_resize()
2140 if (store.sb_page && bitmap->storage.sb_page) in md_bitmap_resize()
2142 page_address(bitmap->storage.sb_page), in md_bitmap_resize()
2144 spin_lock_irq(&bitmap->counts.lock); in md_bitmap_resize()
2145 md_bitmap_file_unmap(&bitmap->storage); in md_bitmap_resize()
2146 bitmap->storage = store; in md_bitmap_resize()
2148 old_counts = bitmap->counts; in md_bitmap_resize()
2149 bitmap->counts.bp = new_bp; in md_bitmap_resize()
2150 bitmap->counts.pages = pages; in md_bitmap_resize()
2151 bitmap->counts.missing_pages = pages; in md_bitmap_resize()
2152 bitmap->counts.chunkshift = chunkshift; in md_bitmap_resize()
2153 bitmap->counts.chunks = chunks; in md_bitmap_resize()
2154 bitmap->mddev->bitmap_info.chunksize = 1 << (chunkshift + in md_bitmap_resize()
2161 if (mddev_is_clustered(bitmap->mddev)) { in md_bitmap_resize()
2164 ret = md_bitmap_checkpage(&bitmap->counts, page, 1, 1); in md_bitmap_resize()
2175 bitmap->counts.bp = old_counts.bp; in md_bitmap_resize()
2176 bitmap->counts.pages = old_counts.pages; in md_bitmap_resize()
2177 bitmap->counts.missing_pages = old_counts.pages; in md_bitmap_resize()
2178 bitmap->counts.chunkshift = old_counts.chunkshift; in md_bitmap_resize()
2179 bitmap->counts.chunks = old_counts.chunks; in md_bitmap_resize()
2180 bitmap->mddev->bitmap_info.chunksize = 1 << (old_counts.chunkshift + in md_bitmap_resize()
2186 bitmap->counts.bp[page].count += 1; in md_bitmap_resize()
2198 bmc_new = md_bitmap_get_counter(&bitmap->counts, block, &new_blocks, 1); in md_bitmap_resize()
2205 md_bitmap_file_set_bit(bitmap, block); in md_bitmap_resize()
2209 md_bitmap_count_page(&bitmap->counts, block, 1); in md_bitmap_resize()
2210 md_bitmap_set_pending(&bitmap->counts, block); in md_bitmap_resize()
2219 if (bitmap->counts.bp != old_counts.bp) { in md_bitmap_resize()
2231 bmc = md_bitmap_get_counter(&bitmap->counts, block, &new_blocks, 1); in md_bitmap_resize()
2238 md_bitmap_count_page(&bitmap->counts, block, 1); in md_bitmap_resize()
2239 md_bitmap_set_pending(&bitmap->counts, block); in md_bitmap_resize()
2244 for (i = 0; i < bitmap->storage.file_pages; i++) in md_bitmap_resize()
2245 set_page_attr(bitmap, i, BITMAP_PAGE_DIRTY); in md_bitmap_resize()
2247 spin_unlock_irq(&bitmap->counts.lock); in md_bitmap_resize()
2250 md_bitmap_unplug(bitmap); in md_bitmap_resize()
2251 bitmap->mddev->pers->quiesce(bitmap->mddev, 0); in md_bitmap_resize()
2292 if (mddev->bitmap || mddev->bitmap_info.file || in location_store()
2338 struct bitmap *bitmap; in location_store() local
2339 bitmap = md_bitmap_create(mddev, -1); in location_store()
2341 if (IS_ERR(bitmap)) in location_store()
2342 rv = PTR_ERR(bitmap); in location_store()
2344 mddev->bitmap = bitmap; in location_store()
2399 if (mddev->bitmap && in space_store()
2400 sectors < (mddev->bitmap->storage.bytes + 511) >> 9) in space_store()
2492 md_bitmap_update_sb(mddev->bitmap); in backlog_store()
2511 if (mddev->bitmap) in chunksize_store()
2536 if (mddev->bitmap || in metadata_store()
2557 if (mddev->bitmap) in can_clear_show()
2558 len = sprintf(page, "%s\n", (mddev->bitmap->need_sync ? in can_clear_show()
2568 if (mddev->bitmap == NULL) in can_clear_store()
2571 mddev->bitmap->need_sync = 1; in can_clear_store()
2575 mddev->bitmap->need_sync = 0; in can_clear_store()
2589 if (mddev->bitmap == NULL) in behind_writes_used_show()
2593 mddev->bitmap->behind_writes_used); in behind_writes_used_show()
2601 if (mddev->bitmap) in behind_writes_used_reset()
2602 mddev->bitmap->behind_writes_used = 0; in behind_writes_used_reset()