Lines Matching refs:c
62 static void move_up_lpt_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, in move_up_lpt_heap() argument
99 static void adjust_lpt_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, in adjust_lpt_heap() argument
178 static int add_to_lpt_heap(struct ubifs_info *c, struct ubifs_lprops *lprops, in add_to_lpt_heap() argument
181 struct ubifs_lpt_heap *heap = &c->lpt_heap[cat - 1]; in add_to_lpt_heap()
190 ubifs_assert(c, cpos >= b); in add_to_lpt_heap()
191 ubifs_assert(c, cpos < LPT_HEAP_SZ); in add_to_lpt_heap()
192 ubifs_assert(c, cpos < heap->cnt); in add_to_lpt_heap()
202 list_add(&lp->list, &c->uncat_list); in add_to_lpt_heap()
205 move_up_lpt_heap(c, heap, lprops, cat); in add_to_lpt_heap()
206 dbg_check_heap(c, heap, cat, lprops->hpos); in add_to_lpt_heap()
209 dbg_check_heap(c, heap, cat, -1); in add_to_lpt_heap()
214 move_up_lpt_heap(c, heap, lprops, cat); in add_to_lpt_heap()
215 dbg_check_heap(c, heap, cat, lprops->hpos); in add_to_lpt_heap()
226 static void remove_from_lpt_heap(struct ubifs_info *c, in remove_from_lpt_heap() argument
232 heap = &c->lpt_heap[cat - 1]; in remove_from_lpt_heap()
233 ubifs_assert(c, hpos >= 0 && hpos < heap->cnt); in remove_from_lpt_heap()
234 ubifs_assert(c, heap->arr[hpos] == lprops); in remove_from_lpt_heap()
239 adjust_lpt_heap(c, heap, heap->arr[hpos], hpos, cat); in remove_from_lpt_heap()
241 dbg_check_heap(c, heap, cat, -1); in remove_from_lpt_heap()
255 static void lpt_heap_replace(struct ubifs_info *c, in lpt_heap_replace() argument
261 heap = &c->lpt_heap[cat - 1]; in lpt_heap_replace()
273 void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops, in ubifs_add_to_cat() argument
280 if (add_to_lpt_heap(c, lprops, cat)) in ubifs_add_to_cat()
286 list_add(&lprops->list, &c->uncat_list); in ubifs_add_to_cat()
289 list_add(&lprops->list, &c->empty_list); in ubifs_add_to_cat()
292 list_add(&lprops->list, &c->freeable_list); in ubifs_add_to_cat()
293 c->freeable_cnt += 1; in ubifs_add_to_cat()
296 list_add(&lprops->list, &c->frdi_idx_list); in ubifs_add_to_cat()
299 ubifs_assert(c, 0); in ubifs_add_to_cat()
304 c->in_a_category_cnt += 1; in ubifs_add_to_cat()
305 ubifs_assert(c, c->in_a_category_cnt <= c->main_lebs); in ubifs_add_to_cat()
316 static void ubifs_remove_from_cat(struct ubifs_info *c, in ubifs_remove_from_cat() argument
323 remove_from_lpt_heap(c, lprops, cat); in ubifs_remove_from_cat()
326 c->freeable_cnt -= 1; in ubifs_remove_from_cat()
327 ubifs_assert(c, c->freeable_cnt >= 0); in ubifs_remove_from_cat()
332 ubifs_assert(c, !list_empty(&lprops->list)); in ubifs_remove_from_cat()
336 ubifs_assert(c, 0); in ubifs_remove_from_cat()
339 c->in_a_category_cnt -= 1; in ubifs_remove_from_cat()
340 ubifs_assert(c, c->in_a_category_cnt >= 0); in ubifs_remove_from_cat()
353 void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops, in ubifs_replace_cat() argument
363 lpt_heap_replace(c, new_lprops, cat); in ubifs_replace_cat()
372 ubifs_assert(c, 0); in ubifs_replace_cat()
385 void ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops) in ubifs_ensure_cat() argument
391 cat = ubifs_categorize_lprops(c, lprops); in ubifs_ensure_cat()
394 ubifs_remove_from_cat(c, lprops, LPROPS_UNCAT); in ubifs_ensure_cat()
395 ubifs_add_to_cat(c, lprops, cat); in ubifs_ensure_cat()
408 int ubifs_categorize_lprops(const struct ubifs_info *c, in ubifs_categorize_lprops() argument
414 if (lprops->free == c->leb_size) { in ubifs_categorize_lprops()
415 ubifs_assert(c, !(lprops->flags & LPROPS_INDEX)); in ubifs_categorize_lprops()
419 if (lprops->free + lprops->dirty == c->leb_size) { in ubifs_categorize_lprops()
427 if (lprops->dirty + lprops->free >= c->min_idx_node_sz) in ubifs_categorize_lprops()
430 if (lprops->dirty >= c->dead_wm && in ubifs_categorize_lprops()
448 static void change_category(struct ubifs_info *c, struct ubifs_lprops *lprops) in change_category() argument
451 int new_cat = ubifs_categorize_lprops(c, lprops); in change_category()
459 heap = &c->lpt_heap[new_cat - 1]; in change_category()
460 adjust_lpt_heap(c, heap, lprops, lprops->hpos, new_cat); in change_category()
462 ubifs_remove_from_cat(c, lprops, old_cat); in change_category()
463 ubifs_add_to_cat(c, lprops, new_cat); in change_category()
479 int ubifs_calc_dark(const struct ubifs_info *c, int spc) in ubifs_calc_dark() argument
481 ubifs_assert(c, !(spc & 7)); in ubifs_calc_dark()
483 if (spc < c->dark_wm) in ubifs_calc_dark()
491 if (spc - c->dark_wm < MIN_WRITE_SZ) in ubifs_calc_dark()
494 return c->dark_wm; in ubifs_calc_dark()
502 static int is_lprops_dirty(struct ubifs_info *c, struct ubifs_lprops *lprops) in is_lprops_dirty() argument
507 pos = (lprops->lnum - c->main_first) & (UBIFS_LPT_FANOUT - 1); in is_lprops_dirty()
532 const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c, in ubifs_change_lp() argument
546 ubifs_assert(c, mutex_is_locked(&c->lp_mutex)); in ubifs_change_lp()
547 ubifs_assert(c, c->lst.empty_lebs >= 0 && in ubifs_change_lp()
548 c->lst.empty_lebs <= c->main_lebs); in ubifs_change_lp()
549 ubifs_assert(c, c->freeable_cnt >= 0); in ubifs_change_lp()
550 ubifs_assert(c, c->freeable_cnt <= c->main_lebs); in ubifs_change_lp()
551 ubifs_assert(c, c->lst.taken_empty_lebs >= 0); in ubifs_change_lp()
552 ubifs_assert(c, c->lst.taken_empty_lebs <= c->lst.empty_lebs); in ubifs_change_lp()
553 ubifs_assert(c, !(c->lst.total_free & 7) && !(c->lst.total_dirty & 7)); in ubifs_change_lp()
554 ubifs_assert(c, !(c->lst.total_dead & 7) && !(c->lst.total_dark & 7)); in ubifs_change_lp()
555 ubifs_assert(c, !(c->lst.total_used & 7)); in ubifs_change_lp()
556 ubifs_assert(c, free == LPROPS_NC || free >= 0); in ubifs_change_lp()
557 ubifs_assert(c, dirty == LPROPS_NC || dirty >= 0); in ubifs_change_lp()
559 if (!is_lprops_dirty(c, lprops)) { in ubifs_change_lp()
560 lprops = ubifs_lpt_lookup_dirty(c, lprops->lnum); in ubifs_change_lp()
564 ubifs_assert(c, lprops == ubifs_lpt_lookup_dirty(c, lprops->lnum)); in ubifs_change_lp()
566 ubifs_assert(c, !(lprops->free & 7) && !(lprops->dirty & 7)); in ubifs_change_lp()
568 spin_lock(&c->space_lock); in ubifs_change_lp()
569 if ((lprops->flags & LPROPS_TAKEN) && lprops->free == c->leb_size) in ubifs_change_lp()
570 c->lst.taken_empty_lebs -= 1; in ubifs_change_lp()
576 if (old_spc < c->dead_wm) in ubifs_change_lp()
577 c->lst.total_dead -= old_spc; in ubifs_change_lp()
579 c->lst.total_dark -= ubifs_calc_dark(c, old_spc); in ubifs_change_lp()
581 c->lst.total_used -= c->leb_size - old_spc; in ubifs_change_lp()
586 c->lst.total_free += free - lprops->free; in ubifs_change_lp()
589 if (free == c->leb_size) { in ubifs_change_lp()
590 if (lprops->free != c->leb_size) in ubifs_change_lp()
591 c->lst.empty_lebs += 1; in ubifs_change_lp()
592 } else if (lprops->free == c->leb_size) in ubifs_change_lp()
593 c->lst.empty_lebs -= 1; in ubifs_change_lp()
599 c->lst.total_dirty += dirty - lprops->dirty; in ubifs_change_lp()
607 c->lst.idx_lebs -= 1; in ubifs_change_lp()
609 c->lst.idx_lebs += 1; in ubifs_change_lp()
617 if (new_spc < c->dead_wm) in ubifs_change_lp()
618 c->lst.total_dead += new_spc; in ubifs_change_lp()
620 c->lst.total_dark += ubifs_calc_dark(c, new_spc); in ubifs_change_lp()
622 c->lst.total_used += c->leb_size - new_spc; in ubifs_change_lp()
625 if ((lprops->flags & LPROPS_TAKEN) && lprops->free == c->leb_size) in ubifs_change_lp()
626 c->lst.taken_empty_lebs += 1; in ubifs_change_lp()
628 change_category(c, lprops); in ubifs_change_lp()
629 c->idx_gc_cnt += idx_gc_cnt; in ubifs_change_lp()
630 spin_unlock(&c->space_lock); in ubifs_change_lp()
639 void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst) in ubifs_get_lp_stats() argument
641 spin_lock(&c->space_lock); in ubifs_get_lp_stats()
642 memcpy(lst, &c->lst, sizeof(struct ubifs_lp_stats)); in ubifs_get_lp_stats()
643 spin_unlock(&c->space_lock); in ubifs_get_lp_stats()
661 int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty, in ubifs_change_one_lp() argument
667 ubifs_get_lprops(c); in ubifs_change_one_lp()
669 lp = ubifs_lpt_lookup_dirty(c, lnum); in ubifs_change_one_lp()
676 lp = ubifs_change_lp(c, lp, free, dirty, flags, idx_gc_cnt); in ubifs_change_one_lp()
681 ubifs_release_lprops(c); in ubifs_change_one_lp()
683 ubifs_err(c, "cannot change properties of LEB %d, error %d", in ubifs_change_one_lp()
700 int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty, in ubifs_update_one_lp() argument
706 ubifs_get_lprops(c); in ubifs_update_one_lp()
708 lp = ubifs_lpt_lookup_dirty(c, lnum); in ubifs_update_one_lp()
715 lp = ubifs_change_lp(c, lp, free, lp->dirty + dirty, flags, 0); in ubifs_update_one_lp()
720 ubifs_release_lprops(c); in ubifs_update_one_lp()
722 ubifs_err(c, "cannot update properties of LEB %d, error %d", in ubifs_update_one_lp()
737 int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp) in ubifs_read_one_lp() argument
742 ubifs_get_lprops(c); in ubifs_read_one_lp()
744 lpp = ubifs_lpt_lookup(c, lnum); in ubifs_read_one_lp()
747 ubifs_err(c, "cannot read properties of LEB %d, error %d", in ubifs_read_one_lp()
755 ubifs_release_lprops(c); in ubifs_read_one_lp()
766 const struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c) in ubifs_fast_find_free() argument
771 ubifs_assert(c, mutex_is_locked(&c->lp_mutex)); in ubifs_fast_find_free()
773 heap = &c->lpt_heap[LPROPS_FREE - 1]; in ubifs_fast_find_free()
778 ubifs_assert(c, !(lprops->flags & LPROPS_TAKEN)); in ubifs_fast_find_free()
779 ubifs_assert(c, !(lprops->flags & LPROPS_INDEX)); in ubifs_fast_find_free()
790 const struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c) in ubifs_fast_find_empty() argument
794 ubifs_assert(c, mutex_is_locked(&c->lp_mutex)); in ubifs_fast_find_empty()
796 if (list_empty(&c->empty_list)) in ubifs_fast_find_empty()
799 lprops = list_entry(c->empty_list.next, struct ubifs_lprops, list); in ubifs_fast_find_empty()
800 ubifs_assert(c, !(lprops->flags & LPROPS_TAKEN)); in ubifs_fast_find_empty()
801 ubifs_assert(c, !(lprops->flags & LPROPS_INDEX)); in ubifs_fast_find_empty()
802 ubifs_assert(c, lprops->free == c->leb_size); in ubifs_fast_find_empty()
813 const struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c) in ubifs_fast_find_freeable() argument
817 ubifs_assert(c, mutex_is_locked(&c->lp_mutex)); in ubifs_fast_find_freeable()
819 if (list_empty(&c->freeable_list)) in ubifs_fast_find_freeable()
822 lprops = list_entry(c->freeable_list.next, struct ubifs_lprops, list); in ubifs_fast_find_freeable()
823 ubifs_assert(c, !(lprops->flags & LPROPS_TAKEN)); in ubifs_fast_find_freeable()
824 ubifs_assert(c, !(lprops->flags & LPROPS_INDEX)); in ubifs_fast_find_freeable()
825 ubifs_assert(c, lprops->free + lprops->dirty == c->leb_size); in ubifs_fast_find_freeable()
826 ubifs_assert(c, c->freeable_cnt > 0); in ubifs_fast_find_freeable()
837 const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c) in ubifs_fast_find_frdi_idx() argument
841 ubifs_assert(c, mutex_is_locked(&c->lp_mutex)); in ubifs_fast_find_frdi_idx()
843 if (list_empty(&c->frdi_idx_list)) in ubifs_fast_find_frdi_idx()
846 lprops = list_entry(c->frdi_idx_list.next, struct ubifs_lprops, list); in ubifs_fast_find_frdi_idx()
847 ubifs_assert(c, !(lprops->flags & LPROPS_TAKEN)); in ubifs_fast_find_frdi_idx()
848 ubifs_assert(c, (lprops->flags & LPROPS_INDEX)); in ubifs_fast_find_frdi_idx()
849 ubifs_assert(c, lprops->free + lprops->dirty == c->leb_size); in ubifs_fast_find_frdi_idx()
863 int dbg_check_cats(struct ubifs_info *c) in dbg_check_cats() argument
869 if (!dbg_is_chk_gen(c) && !dbg_is_chk_lprops(c)) in dbg_check_cats()
872 list_for_each_entry(lprops, &c->empty_list, list) { in dbg_check_cats()
873 if (lprops->free != c->leb_size) { in dbg_check_cats()
874 ubifs_err(c, "non-empty LEB %d on empty list (free %d dirty %d flags %d)", in dbg_check_cats()
880 ubifs_err(c, "taken LEB %d on empty list (free %d dirty %d flags %d)", in dbg_check_cats()
888 list_for_each_entry(lprops, &c->freeable_list, list) { in dbg_check_cats()
889 if (lprops->free + lprops->dirty != c->leb_size) { in dbg_check_cats()
890 ubifs_err(c, "non-freeable LEB %d on freeable list (free %d dirty %d flags %d)", in dbg_check_cats()
896 ubifs_err(c, "taken LEB %d on freeable list (free %d dirty %d flags %d)", in dbg_check_cats()
903 if (i != c->freeable_cnt) { in dbg_check_cats()
904 ubifs_err(c, "freeable list count %d expected %d", i, in dbg_check_cats()
905 c->freeable_cnt); in dbg_check_cats()
910 list_for_each(pos, &c->idx_gc) in dbg_check_cats()
912 if (i != c->idx_gc_cnt) { in dbg_check_cats()
913 ubifs_err(c, "idx_gc list count %d expected %d", i, in dbg_check_cats()
914 c->idx_gc_cnt); in dbg_check_cats()
918 list_for_each_entry(lprops, &c->frdi_idx_list, list) { in dbg_check_cats()
919 if (lprops->free + lprops->dirty != c->leb_size) { in dbg_check_cats()
920 ubifs_err(c, "non-freeable LEB %d on frdi_idx list (free %d dirty %d flags %d)", in dbg_check_cats()
926 ubifs_err(c, "taken LEB %d on frdi_idx list (free %d dirty %d flags %d)", in dbg_check_cats()
932 ubifs_err(c, "non-index LEB %d on frdi_idx list (free %d dirty %d flags %d)", in dbg_check_cats()
940 struct ubifs_lpt_heap *heap = &c->lpt_heap[cat - 1]; in dbg_check_cats()
945 ubifs_err(c, "null ptr in LPT heap cat %d", cat); in dbg_check_cats()
949 ubifs_err(c, "bad ptr in LPT heap cat %d", cat); in dbg_check_cats()
953 ubifs_err(c, "taken LEB in LPT heap cat %d", cat); in dbg_check_cats()
962 void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat, in dbg_check_heap() argument
967 if (!dbg_is_chk_gen(c) && !dbg_is_chk_lprops(c)) in dbg_check_heap()
983 lp = ubifs_lpt_lookup(c, lprops->lnum); in dbg_check_heap()
989 ubifs_err(c, "lprops %zx lp %zx lprops->lnum %d lp->lnum %d", in dbg_check_heap()
1009 ubifs_err(c, "failed cat %d hpos %d err %d", cat, i, err); in dbg_check_heap()
1011 ubifs_dump_heap(c, heap, cat); in dbg_check_heap()
1027 static int scan_check_cb(struct ubifs_info *c, in scan_check_cb() argument
1038 cat = ubifs_categorize_lprops(c, lp); in scan_check_cb()
1040 ubifs_err(c, "bad LEB category %d expected %d", in scan_check_cb()
1052 list = &c->empty_list; in scan_check_cb()
1055 list = &c->freeable_list; in scan_check_cb()
1058 list = &c->frdi_idx_list; in scan_check_cb()
1061 list = &c->uncat_list; in scan_check_cb()
1075 ubifs_err(c, "bad LPT list (category %d)", cat); in scan_check_cb()
1083 struct ubifs_lpt_heap *heap = &c->lpt_heap[cat - 1]; in scan_check_cb()
1087 ubifs_err(c, "bad LPT heap (category %d)", cat); in scan_check_cb()
1096 if (lp->free == c->leb_size) { in scan_check_cb()
1098 lst->total_free += c->leb_size; in scan_check_cb()
1099 lst->total_dark += ubifs_calc_dark(c, c->leb_size); in scan_check_cb()
1102 if (lp->free + lp->dirty == c->leb_size && in scan_check_cb()
1106 lst->total_dark += ubifs_calc_dark(c, c->leb_size); in scan_check_cb()
1110 buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); in scan_check_cb()
1114 sleb = ubifs_scan(c, lnum, 0, buf, 0); in scan_check_cb()
1118 ubifs_dump_lprops(c); in scan_check_cb()
1119 ubifs_dump_budg(c, &c->bi); in scan_check_cb()
1134 ubifs_err(c, "indexing node in data LEB %d:%d", in scan_check_cb()
1142 key_read(c, ubifs_idx_key(c, idx), &snod->key); in scan_check_cb()
1146 found = ubifs_tnc_has_node(c, &snod->key, level, lnum, in scan_check_cb()
1155 free = c->leb_size - sleb->endpt; in scan_check_cb()
1158 if (free > c->leb_size || free < 0 || dirty > c->leb_size || in scan_check_cb()
1160 ubifs_err(c, "bad calculated accounting for LEB %d: free %d, dirty %d", in scan_check_cb()
1165 if (lp->free + lp->dirty == c->leb_size && in scan_check_cb()
1166 free + dirty == c->leb_size) in scan_check_cb()
1168 (!is_idx && free == c->leb_size) || in scan_check_cb()
1169 lp->free == c->leb_size) { in scan_check_cb()
1183 lnum != c->ihead_lnum) { in scan_check_cb()
1203 if (free == c->leb_size) in scan_check_cb()
1207 ubifs_err(c, "indexing node without indexing flag"); in scan_check_cb()
1213 ubifs_err(c, "data node with indexing flag"); in scan_check_cb()
1217 if (free == c->leb_size) in scan_check_cb()
1224 lst->total_used += c->leb_size - free - dirty; in scan_check_cb()
1231 if (spc < c->dead_wm) in scan_check_cb()
1234 lst->total_dark += ubifs_calc_dark(c, spc); in scan_check_cb()
1242 ubifs_err(c, "bad accounting of LEB %d: free %d, dirty %d flags %#x, should be free %d, dirty %d", in scan_check_cb()
1244 ubifs_dump_leb(c, lnum); in scan_check_cb()
1264 int dbg_check_lprops(struct ubifs_info *c) in dbg_check_lprops() argument
1269 if (!dbg_is_chk_lprops(c)) in dbg_check_lprops()
1276 for (i = 0; i < c->jhead_cnt; i++) { in dbg_check_lprops()
1277 err = ubifs_wbuf_sync(&c->jheads[i].wbuf); in dbg_check_lprops()
1283 err = ubifs_lpt_scan_nolock(c, c->main_first, c->leb_cnt - 1, in dbg_check_lprops()
1289 if (lst.empty_lebs != c->lst.empty_lebs || in dbg_check_lprops()
1290 lst.idx_lebs != c->lst.idx_lebs || in dbg_check_lprops()
1291 lst.total_free != c->lst.total_free || in dbg_check_lprops()
1292 lst.total_dirty != c->lst.total_dirty || in dbg_check_lprops()
1293 lst.total_used != c->lst.total_used) { in dbg_check_lprops()
1294 ubifs_err(c, "bad overall accounting"); in dbg_check_lprops()
1295 …ubifs_err(c, "calculated: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, total_use… in dbg_check_lprops()
1298 …ubifs_err(c, "read from lprops: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, tot… in dbg_check_lprops()
1299 c->lst.empty_lebs, c->lst.idx_lebs, c->lst.total_free, in dbg_check_lprops()
1300 c->lst.total_dirty, c->lst.total_used); in dbg_check_lprops()
1305 if (lst.total_dead != c->lst.total_dead || in dbg_check_lprops()
1306 lst.total_dark != c->lst.total_dark) { in dbg_check_lprops()
1307 ubifs_err(c, "bad dead/dark space accounting"); in dbg_check_lprops()
1308 ubifs_err(c, "calculated: total_dead %lld, total_dark %lld", in dbg_check_lprops()
1310 ubifs_err(c, "read from lprops: total_dead %lld, total_dark %lld", in dbg_check_lprops()
1311 c->lst.total_dead, c->lst.total_dark); in dbg_check_lprops()
1316 err = dbg_check_cats(c); in dbg_check_lprops()