Lines Matching refs:llbitmap

49  * llbitmap state machine: transitions between states
104 * By default, the old bitmap framework will recover all data, and llbitmap
133 * While creating bitmap, all pages will be allocated and read for llbitmap,
256 struct llbitmap {
290 struct llbitmap *llbitmap;
352 static enum llbitmap_state llbitmap_read(struct llbitmap *llbitmap, loff_t pos)
361 return llbitmap->pctl[idx]->state[offset];
365 static void llbitmap_infect_dirty_bits(struct llbitmap *llbitmap,
369 bool level_456 = raid_is_456(llbitmap->mddev);
370 unsigned int io_size = llbitmap->io_size;
385 static void llbitmap_set_page_dirty(struct llbitmap *llbitmap, int idx,
388 struct llbitmap_page_ctl *pctl = llbitmap->pctl[idx];
389 unsigned int io_size = llbitmap->io_size;
401 if (llbitmap->mddev->degraded) {
410 * within the same sector are modified within llbitmap->barrier_idle,
414 llbitmap_infect_dirty_bits(llbitmap, pctl, block);
423 llbitmap_infect_dirty_bits(llbitmap, pctl, block);
429 static void llbitmap_write(struct llbitmap *llbitmap, enum llbitmap_state state,
439 llbitmap->pctl[idx]->state[bit] = state;
441 llbitmap_set_page_dirty(llbitmap, idx, bit);
444 static struct page *llbitmap_read_page(struct llbitmap *llbitmap, int idx)
446 struct mddev *mddev = llbitmap->mddev;
450 if (llbitmap->pctl && llbitmap->pctl[idx])
451 page = llbitmap->pctl[idx]->page;
479 static void llbitmap_write_page(struct llbitmap *llbitmap, int idx)
481 struct page *page = llbitmap->pctl[idx]->page;
482 struct mddev *mddev = llbitmap->mddev;
486 for (block = 0; block < llbitmap->blocks_per_page; block++) {
487 struct llbitmap_page_ctl *pctl = llbitmap->pctl[idx];
494 sector_t bit_sector = llbitmap->io_size >> SECTOR_SHIFT;
503 llbitmap->io_size, page,
504 block * llbitmap->io_size);
517 static void llbitmap_free_pages(struct llbitmap *llbitmap)
521 if (!llbitmap->pctl)
524 for (i = 0; i < llbitmap->nr_pages; i++) {
525 struct llbitmap_page_ctl *pctl = llbitmap->pctl[i];
534 kfree(llbitmap->pctl[0]);
535 kfree(llbitmap->pctl);
536 llbitmap->pctl = NULL;
539 static int llbitmap_cache_pages(struct llbitmap *llbitmap)
542 unsigned int nr_pages = DIV_ROUND_UP(llbitmap->chunks +
545 llbitmap->blocks_per_page));
548 llbitmap->pctl = kmalloc_array(nr_pages, sizeof(void *),
550 if (!llbitmap->pctl)
556 kfree(llbitmap->pctl);
560 llbitmap->nr_pages = nr_pages;
563 struct page *page = llbitmap_read_page(llbitmap, i);
565 llbitmap->pctl[i] = pctl;
568 llbitmap_free_pages(llbitmap);
575 llbitmap_free_pages(llbitmap);
587 static void llbitmap_init_state(struct llbitmap *llbitmap)
592 if (test_and_clear_bit(BITMAP_CLEAN, &llbitmap->flags))
595 for (i = 0; i < llbitmap->chunks; i++)
596 llbitmap_write(llbitmap, state, i);
600 static enum llbitmap_state llbitmap_state_machine(struct llbitmap *llbitmap,
605 struct mddev *mddev = llbitmap->mddev;
607 bool level_456 = raid_is_456(llbitmap->mddev);
611 if (test_bit(BITMAP_WRITE_ERROR, &llbitmap->flags))
615 llbitmap_init_state(llbitmap);
620 enum llbitmap_state c = llbitmap_read(llbitmap, start);
659 llbitmap_write(llbitmap, state, start);
664 !timer_pending(&llbitmap->pending_timer))
665 mod_timer(&llbitmap->pending_timer,
687 static void llbitmap_raise_barrier(struct llbitmap *llbitmap, int page_idx)
689 struct llbitmap_page_ctl *pctl = llbitmap->pctl[page_idx];
693 WRITE_ONCE(pctl->expire, jiffies + llbitmap->barrier_idle * HZ);
701 static void llbitmap_release_barrier(struct llbitmap *llbitmap, int page_idx)
703 struct llbitmap_page_ctl *pctl = llbitmap->pctl[page_idx];
708 static int llbitmap_suspend_timeout(struct llbitmap *llbitmap, int page_idx)
710 struct llbitmap_page_ctl *pctl = llbitmap->pctl[page_idx];
715 llbitmap->mddev->bitmap_info.daemon_sleep * HZ)) {
723 static void llbitmap_resume(struct llbitmap *llbitmap, int page_idx)
725 struct llbitmap_page_ctl *pctl = llbitmap->pctl[page_idx];
735 pr_notice("md/llbitmap: %s: array with journal cannot have bitmap\n",
742 pr_notice("md/llbitmap: %s: no space for bitmap\n",
749 pr_notice("md/llbitmap: %s: array must be persistent\n",
755 pr_notice("md/llbitmap: %s: doesn't support bitmap file\n",
761 pr_notice("md/llbitmap: %s: doesn't support external metadata\n",
767 pr_notice("md/llbitmap: %s: doesn't support dm-raid\n",
775 static int llbitmap_init(struct llbitmap *llbitmap)
777 struct mddev *mddev = llbitmap->mddev;
789 llbitmap->barrier_idle = DEFAULT_BARRIER_IDLE;
790 llbitmap->chunkshift = ffz(~chunksize);
791 llbitmap->chunksize = chunksize;
792 llbitmap->chunks = chunks;
795 ret = llbitmap_cache_pages(llbitmap);
799 llbitmap_state_machine(llbitmap, 0, llbitmap->chunks - 1,
801 /* flush initial llbitmap to disk */
807 static int llbitmap_read_sb(struct llbitmap *llbitmap)
809 struct mddev *mddev = llbitmap->mddev;
818 pr_err("md/llbitmap: %s: no super block found", mdname(mddev));
822 sb_page = llbitmap_read_page(llbitmap, 0);
824 pr_err("md/llbitmap: %s: read super block failed",
831 pr_err("md/llbitmap: %s: invalid super block magic number",
837 pr_err("md/llbitmap: %s: invalid super block version",
843 pr_err("md/llbitmap: %s: bitmap superblock UUID mismatch\n",
856 llbitmap->flags = le32_to_cpu(sb->state);
857 if (test_and_clear_bit(BITMAP_FIRST_USE, &llbitmap->flags)) {
858 ret = llbitmap_init(llbitmap);
864 pr_err("md/llbitmap: %s: chunksize not a power of 2",
871 pr_err("md/llbitmap: %s: chunksize too small %lu < %llu / %lu",
879 pr_err("md/llbitmap: %s: daemon sleep %lu period out of range",
886 pr_warn("md/llbitmap :%s: bitmap file is out of date (%lu < %llu) -- forcing full recovery",
888 set_bit(BITMAP_STALE, &llbitmap->flags);
895 llbitmap->barrier_idle = DEFAULT_BARRIER_IDLE;
896 llbitmap->chunksize = chunksize;
897 llbitmap->chunks = DIV_ROUND_UP_SECTOR_T(mddev->resync_max_sectors, chunksize);
898 llbitmap->chunkshift = ffz(~chunksize);
899 ret = llbitmap_cache_pages(llbitmap);
909 struct llbitmap *llbitmap =
910 container_of(pending_timer, struct llbitmap, pending_timer);
912 if (work_busy(&llbitmap->daemon_work)) {
913 pr_warn("md/llbitmap: %s daemon_work not finished in %lu seconds\n",
914 mdname(llbitmap->mddev),
915 llbitmap->mddev->bitmap_info.daemon_sleep);
916 set_bit(BITMAP_DAEMON_BUSY, &llbitmap->flags);
920 queue_work(md_llbitmap_io_wq, &llbitmap->daemon_work);
925 struct llbitmap *llbitmap =
926 container_of(work, struct llbitmap, daemon_work);
932 if (llbitmap->mddev->degraded)
936 end = min(llbitmap->chunks, PAGE_SIZE - BITMAP_DATA_OFFSET) - 1;
939 for (idx = 0; idx < llbitmap->nr_pages; idx++) {
940 struct llbitmap_page_ctl *pctl = llbitmap->pctl[idx];
944 end = min(end + PAGE_SIZE, llbitmap->chunks - 1);
953 if (llbitmap_suspend_timeout(llbitmap, idx) < 0) {
954 pr_warn("md/llbitmap: %s: %s waiting for page %d timeout\n",
955 mdname(llbitmap->mddev), __func__, idx);
959 llbitmap_state_machine(llbitmap, start, end, BitmapActionDaemon);
960 llbitmap_resume(llbitmap, idx);
967 if (test_and_clear_bit(BITMAP_DAEMON_BUSY, &llbitmap->flags))
972 mod_timer(&llbitmap->pending_timer,
973 jiffies + llbitmap->mddev->bitmap_info.daemon_sleep * HZ);
978 struct llbitmap *llbitmap;
985 llbitmap = kzalloc_obj(*llbitmap);
986 if (!llbitmap)
989 llbitmap->mddev = mddev;
990 llbitmap->io_size = bdev_logical_block_size(mddev->gendisk->part0);
991 llbitmap->blocks_per_page = PAGE_SIZE / llbitmap->io_size;
993 timer_setup(&llbitmap->pending_timer, llbitmap_pending_timer_fn, 0);
994 INIT_WORK(&llbitmap->daemon_work, md_llbitmap_daemon_fn);
995 atomic_set(&llbitmap->behind_writes, 0);
996 init_waitqueue_head(&llbitmap->behind_wait);
999 mddev->bitmap = llbitmap;
1000 ret = llbitmap_read_sb(llbitmap);
1003 kfree(llbitmap);
1012 struct llbitmap *llbitmap = mddev->bitmap;
1016 chunksize = llbitmap->chunksize;
1025 llbitmap->chunkshift = ffz(~chunksize);
1026 llbitmap->chunksize = chunksize;
1027 llbitmap->chunks = chunks;
1035 struct llbitmap *llbitmap = mddev->bitmap;
1037 if (test_and_clear_bit(BITMAP_STALE, &llbitmap->flags))
1040 llbitmap_state_machine(llbitmap, 0, llbitmap->chunks - 1, action);
1046 struct llbitmap *llbitmap = mddev->bitmap;
1048 if (!llbitmap)
1053 timer_delete_sync(&llbitmap->pending_timer);
1058 llbitmap_free_pages(llbitmap);
1059 kfree(llbitmap);
1066 struct llbitmap *llbitmap = mddev->bitmap;
1067 unsigned long start = offset >> llbitmap->chunkshift;
1068 unsigned long end = (offset + sectors - 1) >> llbitmap->chunkshift;
1072 llbitmap_state_machine(llbitmap, start, end, BitmapActionStartwrite);
1075 llbitmap_raise_barrier(llbitmap, page_start);
1083 struct llbitmap *llbitmap = mddev->bitmap;
1084 unsigned long start = offset >> llbitmap->chunkshift;
1085 unsigned long end = (offset + sectors - 1) >> llbitmap->chunkshift;
1090 llbitmap_release_barrier(llbitmap, page_start);
1098 struct llbitmap *llbitmap = mddev->bitmap;
1099 unsigned long start = DIV_ROUND_UP_SECTOR_T(offset, llbitmap->chunksize);
1100 unsigned long end = (offset + sectors - 1) >> llbitmap->chunkshift;
1104 llbitmap_state_machine(llbitmap, start, end, BitmapActionDiscard);
1107 llbitmap_raise_barrier(llbitmap, page_start);
1115 struct llbitmap *llbitmap = mddev->bitmap;
1116 unsigned long start = DIV_ROUND_UP_SECTOR_T(offset, llbitmap->chunksize);
1117 unsigned long end = (offset + sectors - 1) >> llbitmap->chunkshift;
1122 llbitmap_release_barrier(llbitmap, page_start);
1131 struct llbitmap *llbitmap = unplug_work->llbitmap;
1137 for (i = 0; i < llbitmap->nr_pages; i++) {
1138 if (!test_bit(LLPageDirty, &llbitmap->pctl[i]->flags) ||
1139 !test_and_clear_bit(LLPageDirty, &llbitmap->pctl[i]->flags))
1142 llbitmap_write_page(llbitmap, i);
1146 md_super_wait(llbitmap->mddev);
1150 static bool llbitmap_dirty(struct llbitmap *llbitmap)
1154 for (i = 0; i < llbitmap->nr_pages; i++)
1155 if (test_bit(LLPageDirty, &llbitmap->pctl[i]->flags))
1164 struct llbitmap *llbitmap = mddev->bitmap;
1166 .llbitmap = llbitmap,
1170 if (!llbitmap_dirty(llbitmap))
1192 struct llbitmap *llbitmap = mddev->bitmap;
1197 for (i = 0; i < llbitmap->nr_pages; i++) {
1198 struct llbitmap_page_ctl *pctl = llbitmap->pctl[i];
1202 bitmap_fill(pctl->dirty, llbitmap->blocks_per_page);
1203 llbitmap_write_page(llbitmap, i);
1206 md_super_wait(llbitmap->mddev);
1211 struct llbitmap *llbitmap = mddev->bitmap;
1214 for (i = 0; i < llbitmap->nr_pages; i++)
1215 set_bit(LLPageFlush, &llbitmap->pctl[i]->flags);
1217 timer_delete_sync(&llbitmap->pending_timer);
1218 queue_work(md_llbitmap_io_wq, &llbitmap->daemon_work);
1219 flush_work(&llbitmap->daemon_work);
1227 struct llbitmap *llbitmap = mddev->bitmap;
1228 unsigned long p = offset >> llbitmap->chunkshift;
1229 enum llbitmap_state c = llbitmap_read(llbitmap, p);
1236 struct llbitmap *llbitmap = mddev->bitmap;
1237 unsigned long p = offset >> llbitmap->chunkshift;
1238 int blocks = llbitmap->chunksize - (offset & (llbitmap->chunksize - 1));
1239 enum llbitmap_state c = llbitmap_read(llbitmap, p);
1261 struct llbitmap *llbitmap = mddev->bitmap;
1262 unsigned long p = offset >> llbitmap->chunkshift;
1268 *blocks = llbitmap->chunksize - (offset & (llbitmap->chunksize - 1));
1269 return llbitmap_state_machine(llbitmap, p, p,
1277 struct llbitmap *llbitmap = mddev->bitmap;
1278 unsigned long p = offset >> llbitmap->chunkshift;
1280 *blocks = llbitmap->chunksize - (offset & (llbitmap->chunksize - 1));
1281 llbitmap_state_machine(llbitmap, p, llbitmap->chunks - 1,
1288 struct llbitmap *llbitmap = mddev->bitmap;
1291 for (i = 0; i < llbitmap->nr_pages; i++) {
1292 struct llbitmap_page_ctl *pctl = llbitmap->pctl[i];
1298 llbitmap_state_machine(llbitmap, 0, llbitmap->chunks - 1,
1309 struct llbitmap *llbitmap = mddev->bitmap;
1312 llbitmap->last_end_sync = jiffies;
1316 if (time_before(jiffies, llbitmap->last_end_sync +
1324 llbitmap_state_machine(llbitmap, 0, sector >> llbitmap->chunkshift,
1328 llbitmap->last_end_sync = jiffies;
1334 struct llbitmap *llbitmap = data;
1336 return llbitmap && !test_bit(BITMAP_WRITE_ERROR, &llbitmap->flags);
1345 static void llbitmap_write_sb(struct llbitmap *llbitmap)
1347 int nr_blocks = DIV_ROUND_UP(BITMAP_DATA_OFFSET, llbitmap->io_size);
1349 bitmap_fill(llbitmap->pctl[0]->dirty, nr_blocks);
1350 llbitmap_write_page(llbitmap, 0);
1351 md_super_wait(llbitmap->mddev);
1356 struct llbitmap *llbitmap = data;
1357 struct mddev *mddev = llbitmap->mddev;
1361 if (test_bit(BITMAP_WRITE_ERROR, &llbitmap->flags))
1364 sb_page = llbitmap_read_page(llbitmap, 0);
1368 set_bit(BITMAP_WRITE_ERROR, &llbitmap->flags);
1372 if (mddev->events < llbitmap->events_cleared)
1373 llbitmap->events_cleared = mddev->events;
1377 sb->state = cpu_to_le32(llbitmap->flags);
1378 sb->chunksize = cpu_to_le32(llbitmap->chunksize);
1380 sb->events_cleared = cpu_to_le64(llbitmap->events_cleared);
1385 llbitmap_write_sb(llbitmap);
1390 struct llbitmap *llbitmap = data;
1395 stats->pages = llbitmap->nr_pages;
1396 stats->file_pages = llbitmap->nr_pages;
1398 stats->behind_writes = atomic_read(&llbitmap->behind_writes);
1399 stats->behind_wait = wq_has_sleeper(&llbitmap->behind_wait);
1400 stats->events_cleared = llbitmap->events_cleared;
1409 struct llbitmap *llbitmap = mddev->bitmap;
1411 for (i = 0; i < llbitmap->nr_pages; i++) {
1412 struct llbitmap_page_ctl *pctl = llbitmap->pctl[i];
1415 bitmap_fill(pctl->dirty, llbitmap->blocks_per_page);
1421 struct llbitmap *llbitmap = mddev->bitmap;
1423 atomic_inc(&llbitmap->behind_writes);
1428 struct llbitmap *llbitmap = mddev->bitmap;
1430 if (atomic_dec_and_test(&llbitmap->behind_writes))
1431 wake_up(&llbitmap->behind_wait);
1436 struct llbitmap *llbitmap = mddev->bitmap;
1438 if (!llbitmap)
1441 wait_event(llbitmap->behind_wait,
1442 atomic_read(&llbitmap->behind_writes) == 0);
1448 struct llbitmap *llbitmap;
1453 llbitmap = mddev->bitmap;
1454 if (!llbitmap || !llbitmap->pctl) {
1459 if (test_bit(BITMAP_WRITE_ERROR, &llbitmap->flags)) {
1464 while (start < llbitmap->chunks) {
1465 enum llbitmap_state c = llbitmap_read(llbitmap, start);
1485 struct llbitmap *llbitmap;
1489 llbitmap = mddev->bitmap;
1490 if (!llbitmap) {
1496 llbitmap->chunksize, llbitmap->chunkshift,
1497 llbitmap->chunks, mddev->bitmap_info.offset,
1498 llbitmap->mddev->bitmap_info.daemon_sleep);
1530 struct llbitmap *llbitmap = mddev->bitmap;
1532 return sprintf(page, "%lu\n", llbitmap->barrier_idle);
1538 struct llbitmap *llbitmap = mddev->bitmap;
1545 llbitmap->barrier_idle = timeout;
1560 .name = "llbitmap",
1568 .name = "llbitmap",