Lines Matching refs:c
95 static int get_cnodes_to_commit(struct ubifs_info *c) in get_cnodes_to_commit() argument
100 if (!c->nroot) in get_cnodes_to_commit()
103 if (!test_bit(DIRTY_CNODE, &c->nroot->flags)) in get_cnodes_to_commit()
106 c->lpt_cnext = first_dirty_cnode(c->nroot); in get_cnodes_to_commit()
107 cnode = c->lpt_cnext; in get_cnodes_to_commit()
116 cnode->cnext = c->lpt_cnext; in get_cnodes_to_commit()
125 ubifs_assert(cnt == c->dirty_nn_cnt + c->dirty_pn_cnt); in get_cnodes_to_commit()
136 static void upd_ltab(struct ubifs_info *c, int lnum, int free, int dirty) in upd_ltab() argument
139 lnum, c->ltab[lnum - c->lpt_first].free, in upd_ltab()
140 c->ltab[lnum - c->lpt_first].dirty, free, dirty); in upd_ltab()
141 ubifs_assert(lnum >= c->lpt_first && lnum <= c->lpt_last); in upd_ltab()
142 c->ltab[lnum - c->lpt_first].free = free; in upd_ltab()
143 c->ltab[lnum - c->lpt_first].dirty += dirty; in upd_ltab()
156 static int alloc_lpt_leb(struct ubifs_info *c, int *lnum) in alloc_lpt_leb() argument
160 n = *lnum - c->lpt_first + 1; in alloc_lpt_leb()
161 for (i = n; i < c->lpt_lebs; i++) { in alloc_lpt_leb()
162 if (c->ltab[i].tgc || c->ltab[i].cmt) in alloc_lpt_leb()
164 if (c->ltab[i].free == c->leb_size) { in alloc_lpt_leb()
165 c->ltab[i].cmt = 1; in alloc_lpt_leb()
166 *lnum = i + c->lpt_first; in alloc_lpt_leb()
172 if (c->ltab[i].tgc || c->ltab[i].cmt) in alloc_lpt_leb()
174 if (c->ltab[i].free == c->leb_size) { in alloc_lpt_leb()
175 c->ltab[i].cmt = 1; in alloc_lpt_leb()
176 *lnum = i + c->lpt_first; in alloc_lpt_leb()
189 static int layout_cnodes(struct ubifs_info *c) in layout_cnodes() argument
194 err = dbg_chk_lpt_sz(c, 0, 0); in layout_cnodes()
197 cnode = c->lpt_cnext; in layout_cnodes()
200 lnum = c->nhead_lnum; in layout_cnodes()
201 offs = c->nhead_offs; in layout_cnodes()
203 done_lsave = !c->big_lpt; in layout_cnodes()
205 if (!done_lsave && offs + c->lsave_sz <= c->leb_size) { in layout_cnodes()
207 c->lsave_lnum = lnum; in layout_cnodes()
208 c->lsave_offs = offs; in layout_cnodes()
209 offs += c->lsave_sz; in layout_cnodes()
210 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in layout_cnodes()
213 if (offs + c->ltab_sz <= c->leb_size) { in layout_cnodes()
215 c->ltab_lnum = lnum; in layout_cnodes()
216 c->ltab_offs = offs; in layout_cnodes()
217 offs += c->ltab_sz; in layout_cnodes()
218 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in layout_cnodes()
223 len = c->nnode_sz; in layout_cnodes()
224 c->dirty_nn_cnt -= 1; in layout_cnodes()
226 len = c->pnode_sz; in layout_cnodes()
227 c->dirty_pn_cnt -= 1; in layout_cnodes()
229 while (offs + len > c->leb_size) { in layout_cnodes()
230 alen = ALIGN(offs, c->min_io_size); in layout_cnodes()
231 upd_ltab(c, lnum, c->leb_size - alen, alen - offs); in layout_cnodes()
232 dbg_chk_lpt_sz(c, 2, alen - offs); in layout_cnodes()
233 err = alloc_lpt_leb(c, &lnum); in layout_cnodes()
237 ubifs_assert(lnum >= c->lpt_first && in layout_cnodes()
238 lnum <= c->lpt_last); in layout_cnodes()
242 c->lsave_lnum = lnum; in layout_cnodes()
243 c->lsave_offs = offs; in layout_cnodes()
244 offs += c->lsave_sz; in layout_cnodes()
245 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in layout_cnodes()
250 c->ltab_lnum = lnum; in layout_cnodes()
251 c->ltab_offs = offs; in layout_cnodes()
252 offs += c->ltab_sz; in layout_cnodes()
253 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in layout_cnodes()
262 c->lpt_lnum = lnum; in layout_cnodes()
263 c->lpt_offs = offs; in layout_cnodes()
266 dbg_chk_lpt_sz(c, 1, len); in layout_cnodes()
268 } while (cnode && cnode != c->lpt_cnext); in layout_cnodes()
272 if (offs + c->lsave_sz > c->leb_size) { in layout_cnodes()
273 alen = ALIGN(offs, c->min_io_size); in layout_cnodes()
274 upd_ltab(c, lnum, c->leb_size - alen, alen - offs); in layout_cnodes()
275 dbg_chk_lpt_sz(c, 2, alen - offs); in layout_cnodes()
276 err = alloc_lpt_leb(c, &lnum); in layout_cnodes()
280 ubifs_assert(lnum >= c->lpt_first && in layout_cnodes()
281 lnum <= c->lpt_last); in layout_cnodes()
284 c->lsave_lnum = lnum; in layout_cnodes()
285 c->lsave_offs = offs; in layout_cnodes()
286 offs += c->lsave_sz; in layout_cnodes()
287 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in layout_cnodes()
292 if (offs + c->ltab_sz > c->leb_size) { in layout_cnodes()
293 alen = ALIGN(offs, c->min_io_size); in layout_cnodes()
294 upd_ltab(c, lnum, c->leb_size - alen, alen - offs); in layout_cnodes()
295 dbg_chk_lpt_sz(c, 2, alen - offs); in layout_cnodes()
296 err = alloc_lpt_leb(c, &lnum); in layout_cnodes()
300 ubifs_assert(lnum >= c->lpt_first && in layout_cnodes()
301 lnum <= c->lpt_last); in layout_cnodes()
304 c->ltab_lnum = lnum; in layout_cnodes()
305 c->ltab_offs = offs; in layout_cnodes()
306 offs += c->ltab_sz; in layout_cnodes()
307 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in layout_cnodes()
310 alen = ALIGN(offs, c->min_io_size); in layout_cnodes()
311 upd_ltab(c, lnum, c->leb_size - alen, alen - offs); in layout_cnodes()
312 dbg_chk_lpt_sz(c, 4, alen - offs); in layout_cnodes()
313 err = dbg_chk_lpt_sz(c, 3, alen); in layout_cnodes()
322 dbg_dump_lpt_info(c); in layout_cnodes()
323 dbg_dump_lpt_lebs(c); in layout_cnodes()
342 static int realloc_lpt_leb(struct ubifs_info *c, int *lnum) in realloc_lpt_leb() argument
346 n = *lnum - c->lpt_first + 1; in realloc_lpt_leb()
347 for (i = n; i < c->lpt_lebs; i++) in realloc_lpt_leb()
348 if (c->ltab[i].cmt) { in realloc_lpt_leb()
349 c->ltab[i].cmt = 0; in realloc_lpt_leb()
350 *lnum = i + c->lpt_first; in realloc_lpt_leb()
355 if (c->ltab[i].cmt) { in realloc_lpt_leb()
356 c->ltab[i].cmt = 0; in realloc_lpt_leb()
357 *lnum = i + c->lpt_first; in realloc_lpt_leb()
369 static int write_cnodes(struct ubifs_info *c) in write_cnodes() argument
373 void *buf = c->lpt_buf; in write_cnodes()
375 cnode = c->lpt_cnext; in write_cnodes()
378 lnum = c->nhead_lnum; in write_cnodes()
379 offs = c->nhead_offs; in write_cnodes()
383 err = ubifs_leb_unmap(c, lnum); in write_cnodes()
388 done_lsave = !c->big_lpt; in write_cnodes()
390 if (!done_lsave && offs + c->lsave_sz <= c->leb_size) { in write_cnodes()
392 ubifs_pack_lsave(c, buf + offs, c->lsave); in write_cnodes()
393 offs += c->lsave_sz; in write_cnodes()
394 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in write_cnodes()
397 if (offs + c->ltab_sz <= c->leb_size) { in write_cnodes()
399 ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); in write_cnodes()
400 offs += c->ltab_sz; in write_cnodes()
401 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in write_cnodes()
407 len = c->nnode_sz; in write_cnodes()
409 len = c->pnode_sz; in write_cnodes()
410 while (offs + len > c->leb_size) { in write_cnodes()
413 alen = ALIGN(wlen, c->min_io_size); in write_cnodes()
415 err = ubifs_leb_write(c, lnum, buf + from, from, in write_cnodes()
419 dbg_chk_lpt_sz(c, 4, alen - wlen); in write_cnodes()
421 dbg_chk_lpt_sz(c, 2, 0); in write_cnodes()
422 err = realloc_lpt_leb(c, &lnum); in write_cnodes()
427 ubifs_assert(lnum >= c->lpt_first && in write_cnodes()
428 lnum <= c->lpt_last); in write_cnodes()
429 err = ubifs_leb_unmap(c, lnum); in write_cnodes()
435 ubifs_pack_lsave(c, buf + offs, c->lsave); in write_cnodes()
436 offs += c->lsave_sz; in write_cnodes()
437 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in write_cnodes()
442 ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); in write_cnodes()
443 offs += c->ltab_sz; in write_cnodes()
444 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in write_cnodes()
450 ubifs_pack_nnode(c, buf + offs, in write_cnodes()
453 ubifs_pack_pnode(c, buf + offs, in write_cnodes()
466 dbg_chk_lpt_sz(c, 1, len); in write_cnodes()
468 } while (cnode && cnode != c->lpt_cnext); in write_cnodes()
472 if (offs + c->lsave_sz > c->leb_size) { in write_cnodes()
474 alen = ALIGN(wlen, c->min_io_size); in write_cnodes()
476 err = ubifs_leb_write(c, lnum, buf + from, from, alen, in write_cnodes()
480 dbg_chk_lpt_sz(c, 2, alen - wlen); in write_cnodes()
481 err = realloc_lpt_leb(c, &lnum); in write_cnodes()
485 ubifs_assert(lnum >= c->lpt_first && in write_cnodes()
486 lnum <= c->lpt_last); in write_cnodes()
487 err = ubifs_leb_unmap(c, lnum); in write_cnodes()
492 ubifs_pack_lsave(c, buf + offs, c->lsave); in write_cnodes()
493 offs += c->lsave_sz; in write_cnodes()
494 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in write_cnodes()
499 if (offs + c->ltab_sz > c->leb_size) { in write_cnodes()
501 alen = ALIGN(wlen, c->min_io_size); in write_cnodes()
503 err = ubifs_leb_write(c, lnum, buf + from, from, alen, in write_cnodes()
507 dbg_chk_lpt_sz(c, 2, alen - wlen); in write_cnodes()
508 err = realloc_lpt_leb(c, &lnum); in write_cnodes()
512 ubifs_assert(lnum >= c->lpt_first && in write_cnodes()
513 lnum <= c->lpt_last); in write_cnodes()
514 err = ubifs_leb_unmap(c, lnum); in write_cnodes()
519 ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); in write_cnodes()
520 offs += c->ltab_sz; in write_cnodes()
521 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in write_cnodes()
526 alen = ALIGN(wlen, c->min_io_size); in write_cnodes()
528 err = ubifs_leb_write(c, lnum, buf + from, from, alen, UBI_SHORTTERM); in write_cnodes()
532 dbg_chk_lpt_sz(c, 4, alen - wlen); in write_cnodes()
533 err = dbg_chk_lpt_sz(c, 3, ALIGN(offs, c->min_io_size)); in write_cnodes()
537 c->nhead_lnum = lnum; in write_cnodes()
538 c->nhead_offs = ALIGN(offs, c->min_io_size); in write_cnodes()
540 dbg_lp("LPT root is at %d:%d", c->lpt_lnum, c->lpt_offs); in write_cnodes()
541 dbg_lp("LPT head is at %d:%d", c->nhead_lnum, c->nhead_offs); in write_cnodes()
542 dbg_lp("LPT ltab is at %d:%d", c->ltab_lnum, c->ltab_offs); in write_cnodes()
543 if (c->big_lpt) in write_cnodes()
544 dbg_lp("LPT lsave is at %d:%d", c->lsave_lnum, c->lsave_offs); in write_cnodes()
552 dbg_dump_lpt_info(c); in write_cnodes()
553 dbg_dump_lpt_lebs(c); in write_cnodes()
567 static struct ubifs_pnode *next_pnode_to_dirty(struct ubifs_info *c, in next_pnode_to_dirty() argument
577 return ubifs_get_pnode(c, nnode, iip); in next_pnode_to_dirty()
593 nnode = ubifs_get_nnode(c, nnode, iip); in next_pnode_to_dirty()
610 nnode = ubifs_get_nnode(c, nnode, iip); in next_pnode_to_dirty()
621 return ubifs_get_pnode(c, nnode, iip); in next_pnode_to_dirty()
632 static struct ubifs_pnode *pnode_lookup(struct ubifs_info *c, int i) in pnode_lookup() argument
637 if (!c->nroot) { in pnode_lookup()
638 err = ubifs_read_nnode(c, NULL, 0); in pnode_lookup()
643 nnode = c->nroot; in pnode_lookup()
644 shft = c->lpt_hght * UBIFS_LPT_FANOUT_SHIFT; in pnode_lookup()
645 for (h = 1; h < c->lpt_hght; h++) { in pnode_lookup()
648 nnode = ubifs_get_nnode(c, nnode, iip); in pnode_lookup()
653 return ubifs_get_pnode(c, nnode, iip); in pnode_lookup()
661 static void add_pnode_dirt(struct ubifs_info *c, struct ubifs_pnode *pnode) in add_pnode_dirt() argument
663 ubifs_add_lpt_dirt(c, pnode->parent->nbranch[pnode->iip].lnum, in add_pnode_dirt()
664 c->pnode_sz); in add_pnode_dirt()
672 static void do_make_pnode_dirty(struct ubifs_info *c, struct ubifs_pnode *pnode) in do_make_pnode_dirty() argument
678 c->dirty_pn_cnt += 1; in do_make_pnode_dirty()
679 add_pnode_dirt(c, pnode); in do_make_pnode_dirty()
684 c->dirty_nn_cnt += 1; in do_make_pnode_dirty()
685 ubifs_add_nnode_dirt(c, nnode); in do_make_pnode_dirty()
704 static int make_tree_dirty(struct ubifs_info *c) in make_tree_dirty() argument
708 pnode = pnode_lookup(c, 0); in make_tree_dirty()
710 do_make_pnode_dirty(c, pnode); in make_tree_dirty()
711 pnode = next_pnode_to_dirty(c, pnode); in make_tree_dirty()
725 static int need_write_all(struct ubifs_info *c) in need_write_all() argument
730 for (i = 0; i < c->lpt_lebs; i++) { in need_write_all()
731 if (i + c->lpt_first == c->nhead_lnum) in need_write_all()
732 free += c->leb_size - c->nhead_offs; in need_write_all()
733 else if (c->ltab[i].free == c->leb_size) in need_write_all()
734 free += c->leb_size; in need_write_all()
735 else if (c->ltab[i].free + c->ltab[i].dirty == c->leb_size) in need_write_all()
736 free += c->leb_size; in need_write_all()
739 if (free <= c->lpt_sz * 2) in need_write_all()
752 static void lpt_tgc_start(struct ubifs_info *c) in lpt_tgc_start() argument
756 for (i = 0; i < c->lpt_lebs; i++) { in lpt_tgc_start()
757 if (i + c->lpt_first == c->nhead_lnum) in lpt_tgc_start()
759 if (c->ltab[i].dirty > 0 && in lpt_tgc_start()
760 c->ltab[i].free + c->ltab[i].dirty == c->leb_size) { in lpt_tgc_start()
761 c->ltab[i].tgc = 1; in lpt_tgc_start()
762 c->ltab[i].free = c->leb_size; in lpt_tgc_start()
763 c->ltab[i].dirty = 0; in lpt_tgc_start()
764 dbg_lp("LEB %d", i + c->lpt_first); in lpt_tgc_start()
778 static int lpt_tgc_end(struct ubifs_info *c) in lpt_tgc_end() argument
782 for (i = 0; i < c->lpt_lebs; i++) in lpt_tgc_end()
783 if (c->ltab[i].tgc) { in lpt_tgc_end()
784 err = ubifs_leb_unmap(c, i + c->lpt_first); in lpt_tgc_end()
787 c->ltab[i].tgc = 0; in lpt_tgc_end()
788 dbg_lp("LEB %d", i + c->lpt_first); in lpt_tgc_end()
805 static void populate_lsave(struct ubifs_info *c) in populate_lsave() argument
811 ubifs_assert(c->big_lpt); in populate_lsave()
812 if (!(c->lpt_drty_flgs & LSAVE_DIRTY)) { in populate_lsave()
813 c->lpt_drty_flgs |= LSAVE_DIRTY; in populate_lsave()
814 ubifs_add_lpt_dirt(c, c->lsave_lnum, c->lsave_sz); in populate_lsave()
816 list_for_each_entry(lprops, &c->empty_list, list) { in populate_lsave()
817 c->lsave[cnt++] = lprops->lnum; in populate_lsave()
818 if (cnt >= c->lsave_cnt) in populate_lsave()
821 list_for_each_entry(lprops, &c->freeable_list, list) { in populate_lsave()
822 c->lsave[cnt++] = lprops->lnum; in populate_lsave()
823 if (cnt >= c->lsave_cnt) in populate_lsave()
826 list_for_each_entry(lprops, &c->frdi_idx_list, list) { in populate_lsave()
827 c->lsave[cnt++] = lprops->lnum; in populate_lsave()
828 if (cnt >= c->lsave_cnt) in populate_lsave()
831 heap = &c->lpt_heap[LPROPS_DIRTY_IDX - 1]; in populate_lsave()
833 c->lsave[cnt++] = heap->arr[i]->lnum; in populate_lsave()
834 if (cnt >= c->lsave_cnt) in populate_lsave()
837 heap = &c->lpt_heap[LPROPS_DIRTY - 1]; in populate_lsave()
839 c->lsave[cnt++] = heap->arr[i]->lnum; in populate_lsave()
840 if (cnt >= c->lsave_cnt) in populate_lsave()
843 heap = &c->lpt_heap[LPROPS_FREE - 1]; in populate_lsave()
845 c->lsave[cnt++] = heap->arr[i]->lnum; in populate_lsave()
846 if (cnt >= c->lsave_cnt) in populate_lsave()
850 while (cnt < c->lsave_cnt) in populate_lsave()
851 c->lsave[cnt++] = c->main_first; in populate_lsave()
862 static struct ubifs_nnode *nnode_lookup(struct ubifs_info *c, int i) in nnode_lookup() argument
867 if (!c->nroot) { in nnode_lookup()
868 err = ubifs_read_nnode(c, NULL, 0); in nnode_lookup()
872 nnode = c->nroot; in nnode_lookup()
878 nnode = ubifs_get_nnode(c, nnode, iip); in nnode_lookup()
900 static int make_nnode_dirty(struct ubifs_info *c, int node_num, int lnum, in make_nnode_dirty() argument
905 nnode = nnode_lookup(c, node_num); in make_nnode_dirty()
914 } else if (c->lpt_lnum != lnum || c->lpt_offs != offs) in make_nnode_dirty()
918 c->dirty_nn_cnt += 1; in make_nnode_dirty()
919 ubifs_add_nnode_dirt(c, nnode); in make_nnode_dirty()
924 c->dirty_nn_cnt += 1; in make_nnode_dirty()
925 ubifs_add_nnode_dirt(c, nnode); in make_nnode_dirty()
949 static int make_pnode_dirty(struct ubifs_info *c, int node_num, int lnum, in make_pnode_dirty() argument
955 pnode = pnode_lookup(c, node_num); in make_pnode_dirty()
961 do_make_pnode_dirty(c, pnode); in make_pnode_dirty()
979 static int make_ltab_dirty(struct ubifs_info *c, int lnum, int offs) in make_ltab_dirty() argument
981 if (lnum != c->ltab_lnum || offs != c->ltab_offs) in make_ltab_dirty()
983 if (!(c->lpt_drty_flgs & LTAB_DIRTY)) { in make_ltab_dirty()
984 c->lpt_drty_flgs |= LTAB_DIRTY; in make_ltab_dirty()
985 ubifs_add_lpt_dirt(c, c->ltab_lnum, c->ltab_sz); in make_ltab_dirty()
1004 static int make_lsave_dirty(struct ubifs_info *c, int lnum, int offs) in make_lsave_dirty() argument
1006 if (lnum != c->lsave_lnum || offs != c->lsave_offs) in make_lsave_dirty()
1008 if (!(c->lpt_drty_flgs & LSAVE_DIRTY)) { in make_lsave_dirty()
1009 c->lpt_drty_flgs |= LSAVE_DIRTY; in make_lsave_dirty()
1010 ubifs_add_lpt_dirt(c, c->lsave_lnum, c->lsave_sz); in make_lsave_dirty()
1031 static int make_node_dirty(struct ubifs_info *c, int node_type, int node_num, in make_node_dirty() argument
1036 return make_nnode_dirty(c, node_num, lnum, offs); in make_node_dirty()
1038 return make_pnode_dirty(c, node_num, lnum, offs); in make_node_dirty()
1040 return make_ltab_dirty(c, lnum, offs); in make_node_dirty()
1042 return make_lsave_dirty(c, lnum, offs); in make_node_dirty()
1052 static int get_lpt_node_len(const struct ubifs_info *c, int node_type) in get_lpt_node_len() argument
1056 return c->nnode_sz; in get_lpt_node_len()
1058 return c->pnode_sz; in get_lpt_node_len()
1060 return c->ltab_sz; in get_lpt_node_len()
1062 return c->lsave_sz; in get_lpt_node_len()
1073 static int get_pad_len(const struct ubifs_info *c, uint8_t *buf, int len) in get_pad_len() argument
1077 if (c->min_io_size == 1) in get_pad_len()
1079 offs = c->leb_size - len; in get_pad_len()
1080 pad_len = ALIGN(offs, c->min_io_size) - offs; in get_pad_len()
1090 static int get_lpt_node_type(const struct ubifs_info *c, uint8_t *buf, in get_lpt_node_type() argument
1097 *node_num = ubifs_unpack_bits(&addr, &pos, c->pcnt_bits); in get_lpt_node_type()
1109 static int is_a_node(const struct ubifs_info *c, uint8_t *buf, int len) in is_a_node() argument
1120 node_len = get_lpt_node_len(c, node_type); in is_a_node()
1145 static int lpt_gc_lnum(struct ubifs_info *c, int lnum) in lpt_gc_lnum() argument
1147 int err, len = c->leb_size, node_type, node_num, node_len, offs; in lpt_gc_lnum()
1148 void *buf = c->lpt_buf; in lpt_gc_lnum()
1151 err = ubi_read(c->ubi, lnum, buf, 0, c->leb_size); in lpt_gc_lnum()
1157 if (!is_a_node(c, buf, len)) { in lpt_gc_lnum()
1160 pad_len = get_pad_len(c, buf, len); in lpt_gc_lnum()
1168 node_type = get_lpt_node_type(c, buf, &node_num); in lpt_gc_lnum()
1169 node_len = get_lpt_node_len(c, node_type); in lpt_gc_lnum()
1170 offs = c->leb_size - len; in lpt_gc_lnum()
1172 mutex_lock(&c->lp_mutex); in lpt_gc_lnum()
1173 err = make_node_dirty(c, node_type, node_num, lnum, offs); in lpt_gc_lnum()
1174 mutex_unlock(&c->lp_mutex); in lpt_gc_lnum()
1190 static int lpt_gc(struct ubifs_info *c) in lpt_gc() argument
1194 mutex_lock(&c->lp_mutex); in lpt_gc()
1195 for (i = 0; i < c->lpt_lebs; i++) { in lpt_gc()
1196 ubifs_assert(!c->ltab[i].tgc); in lpt_gc()
1197 if (i + c->lpt_first == c->nhead_lnum || in lpt_gc()
1198 c->ltab[i].free + c->ltab[i].dirty == c->leb_size) in lpt_gc()
1200 if (c->ltab[i].dirty > dirty) { in lpt_gc()
1201 dirty = c->ltab[i].dirty; in lpt_gc()
1202 lnum = i + c->lpt_first; in lpt_gc()
1205 mutex_unlock(&c->lp_mutex); in lpt_gc()
1208 return lpt_gc_lnum(c, lnum); in lpt_gc()
1221 int ubifs_lpt_start_commit(struct ubifs_info *c) in ubifs_lpt_start_commit() argument
1227 mutex_lock(&c->lp_mutex); in ubifs_lpt_start_commit()
1228 err = dbg_chk_lpt_free_spc(c); in ubifs_lpt_start_commit()
1231 err = dbg_check_ltab(c); in ubifs_lpt_start_commit()
1235 if (c->check_lpt_free) { in ubifs_lpt_start_commit()
1242 c->check_lpt_free = 0; in ubifs_lpt_start_commit()
1243 while (need_write_all(c)) { in ubifs_lpt_start_commit()
1244 mutex_unlock(&c->lp_mutex); in ubifs_lpt_start_commit()
1245 err = lpt_gc(c); in ubifs_lpt_start_commit()
1248 mutex_lock(&c->lp_mutex); in ubifs_lpt_start_commit()
1252 lpt_tgc_start(c); in ubifs_lpt_start_commit()
1254 if (!c->dirty_pn_cnt) { in ubifs_lpt_start_commit()
1260 if (!c->big_lpt && need_write_all(c)) { in ubifs_lpt_start_commit()
1262 err = make_tree_dirty(c); in ubifs_lpt_start_commit()
1265 lpt_tgc_start(c); in ubifs_lpt_start_commit()
1268 if (c->big_lpt) in ubifs_lpt_start_commit()
1269 populate_lsave(c); in ubifs_lpt_start_commit()
1271 cnt = get_cnodes_to_commit(c); in ubifs_lpt_start_commit()
1274 err = layout_cnodes(c); in ubifs_lpt_start_commit()
1279 memcpy(c->ltab_cmt, c->ltab, in ubifs_lpt_start_commit()
1280 sizeof(struct ubifs_lpt_lprops) * c->lpt_lebs); in ubifs_lpt_start_commit()
1281 c->lpt_drty_flgs &= ~(LTAB_DIRTY | LSAVE_DIRTY); in ubifs_lpt_start_commit()
1284 mutex_unlock(&c->lp_mutex); in ubifs_lpt_start_commit()
1292 static void free_obsolete_cnodes(struct ubifs_info *c) in free_obsolete_cnodes() argument
1296 cnext = c->lpt_cnext; in free_obsolete_cnodes()
1306 } while (cnext != c->lpt_cnext); in free_obsolete_cnodes()
1307 c->lpt_cnext = NULL; in free_obsolete_cnodes()
1319 int ubifs_lpt_end_commit(struct ubifs_info *c) in ubifs_lpt_end_commit() argument
1325 if (!c->lpt_cnext) in ubifs_lpt_end_commit()
1328 err = write_cnodes(c); in ubifs_lpt_end_commit()
1332 mutex_lock(&c->lp_mutex); in ubifs_lpt_end_commit()
1333 free_obsolete_cnodes(c); in ubifs_lpt_end_commit()
1334 mutex_unlock(&c->lp_mutex); in ubifs_lpt_end_commit()
1346 int ubifs_lpt_post_commit(struct ubifs_info *c) in ubifs_lpt_post_commit() argument
1350 mutex_lock(&c->lp_mutex); in ubifs_lpt_post_commit()
1351 err = lpt_tgc_end(c); in ubifs_lpt_post_commit()
1354 if (c->big_lpt) in ubifs_lpt_post_commit()
1355 while (need_write_all(c)) { in ubifs_lpt_post_commit()
1356 mutex_unlock(&c->lp_mutex); in ubifs_lpt_post_commit()
1357 err = lpt_gc(c); in ubifs_lpt_post_commit()
1360 mutex_lock(&c->lp_mutex); in ubifs_lpt_post_commit()
1363 mutex_unlock(&c->lp_mutex); in ubifs_lpt_post_commit()
1375 static struct ubifs_nnode *first_nnode(struct ubifs_info *c, int *hght) in first_nnode() argument
1380 nnode = c->nroot; in first_nnode()
1384 for (h = 1; h < c->lpt_hght; h++) { in first_nnode()
1409 static struct ubifs_nnode *next_nnode(struct ubifs_info *c, in next_nnode() argument
1431 for (h = *hght + 1; h < c->lpt_hght; h++) { in next_nnode()
1452 void ubifs_lpt_free(struct ubifs_info *c, int wr_only) in ubifs_lpt_free() argument
1459 free_obsolete_cnodes(c); /* Leftover from a failed commit */ in ubifs_lpt_free()
1461 vfree(c->ltab_cmt); in ubifs_lpt_free()
1462 c->ltab_cmt = NULL; in ubifs_lpt_free()
1463 vfree(c->lpt_buf); in ubifs_lpt_free()
1464 c->lpt_buf = NULL; in ubifs_lpt_free()
1465 kfree(c->lsave); in ubifs_lpt_free()
1466 c->lsave = NULL; in ubifs_lpt_free()
1473 nnode = first_nnode(c, &hght); in ubifs_lpt_free()
1477 nnode = next_nnode(c, nnode, &hght); in ubifs_lpt_free()
1480 kfree(c->lpt_heap[i].arr); in ubifs_lpt_free()
1481 kfree(c->dirty_idx.arr); in ubifs_lpt_free()
1482 kfree(c->nroot); in ubifs_lpt_free()
1483 vfree(c->ltab); in ubifs_lpt_free()
1484 kfree(c->lpt_nod_buf); in ubifs_lpt_free()
1510 static int dbg_is_nnode_dirty(struct ubifs_info *c, int lnum, int offs) in dbg_is_nnode_dirty() argument
1516 nnode = first_nnode(c, &hght); in dbg_is_nnode_dirty()
1517 for (; nnode; nnode = next_nnode(c, nnode, &hght)) { in dbg_is_nnode_dirty()
1529 if (c->lpt_lnum != lnum || c->lpt_offs != offs) in dbg_is_nnode_dirty()
1545 static int dbg_is_pnode_dirty(struct ubifs_info *c, int lnum, int offs) in dbg_is_pnode_dirty() argument
1549 cnt = DIV_ROUND_UP(c->main_lebs, UBIFS_LPT_FANOUT); in dbg_is_pnode_dirty()
1555 pnode = pnode_lookup(c, i); in dbg_is_pnode_dirty()
1574 static int dbg_is_ltab_dirty(struct ubifs_info *c, int lnum, int offs) in dbg_is_ltab_dirty() argument
1576 if (lnum != c->ltab_lnum || offs != c->ltab_offs) in dbg_is_ltab_dirty()
1578 return (c->lpt_drty_flgs & LTAB_DIRTY) != 0; in dbg_is_ltab_dirty()
1587 static int dbg_is_lsave_dirty(struct ubifs_info *c, int lnum, int offs) in dbg_is_lsave_dirty() argument
1589 if (lnum != c->lsave_lnum || offs != c->lsave_offs) in dbg_is_lsave_dirty()
1591 return (c->lpt_drty_flgs & LSAVE_DIRTY) != 0; in dbg_is_lsave_dirty()
1601 static int dbg_is_node_dirty(struct ubifs_info *c, int node_type, int lnum, in dbg_is_node_dirty() argument
1606 return dbg_is_nnode_dirty(c, lnum, offs); in dbg_is_node_dirty()
1608 return dbg_is_pnode_dirty(c, lnum, offs); in dbg_is_node_dirty()
1610 return dbg_is_ltab_dirty(c, lnum, offs); in dbg_is_node_dirty()
1612 return dbg_is_lsave_dirty(c, lnum, offs); in dbg_is_node_dirty()
1625 static int dbg_check_ltab_lnum(struct ubifs_info *c, int lnum) in dbg_check_ltab_lnum() argument
1627 int err, len = c->leb_size, dirty = 0, node_type, node_num, node_len; in dbg_check_ltab_lnum()
1629 void *buf = c->dbg->buf; in dbg_check_ltab_lnum()
1635 err = ubi_read(c->ubi, lnum, buf, 0, c->leb_size); in dbg_check_ltab_lnum()
1641 if (!is_a_node(c, buf, len)) { in dbg_check_ltab_lnum()
1644 pad_len = get_pad_len(c, buf, len); in dbg_check_ltab_lnum()
1653 lnum, c->leb_size - len); in dbg_check_ltab_lnum()
1656 i = lnum - c->lpt_first; in dbg_check_ltab_lnum()
1657 if (len != c->ltab[i].free) { in dbg_check_ltab_lnum()
1660 lnum, len, c->ltab[i].free); in dbg_check_ltab_lnum()
1663 if (dirty != c->ltab[i].dirty) { in dbg_check_ltab_lnum()
1666 lnum, dirty, c->ltab[i].dirty); in dbg_check_ltab_lnum()
1671 node_type = get_lpt_node_type(c, buf, &node_num); in dbg_check_ltab_lnum()
1672 node_len = get_lpt_node_len(c, node_type); in dbg_check_ltab_lnum()
1673 ret = dbg_is_node_dirty(c, node_type, lnum, c->leb_size - len); in dbg_check_ltab_lnum()
1687 int dbg_check_ltab(struct ubifs_info *c) in dbg_check_ltab() argument
1695 cnt = DIV_ROUND_UP(c->main_lebs, UBIFS_LPT_FANOUT); in dbg_check_ltab()
1699 pnode = pnode_lookup(c, i); in dbg_check_ltab()
1706 err = dbg_check_lpt_nodes(c, (struct ubifs_cnode *)c->nroot, 0, 0); in dbg_check_ltab()
1711 for (lnum = c->lpt_first; lnum <= c->lpt_last; lnum++) { in dbg_check_ltab()
1712 err = dbg_check_ltab_lnum(c, lnum); in dbg_check_ltab()
1729 int dbg_chk_lpt_free_spc(struct ubifs_info *c) in dbg_chk_lpt_free_spc() argument
1737 for (i = 0; i < c->lpt_lebs; i++) { in dbg_chk_lpt_free_spc()
1738 if (c->ltab[i].tgc || c->ltab[i].cmt) in dbg_chk_lpt_free_spc()
1740 if (i + c->lpt_first == c->nhead_lnum) in dbg_chk_lpt_free_spc()
1741 free += c->leb_size - c->nhead_offs; in dbg_chk_lpt_free_spc()
1742 else if (c->ltab[i].free == c->leb_size) in dbg_chk_lpt_free_spc()
1743 free += c->leb_size; in dbg_chk_lpt_free_spc()
1745 if (free < c->lpt_sz) { in dbg_chk_lpt_free_spc()
1747 free, c->lpt_sz); in dbg_chk_lpt_free_spc()
1748 dbg_dump_lpt_info(c); in dbg_chk_lpt_free_spc()
1749 dbg_dump_lpt_lebs(c); in dbg_chk_lpt_free_spc()
1764 int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len) in dbg_chk_lpt_sz() argument
1766 struct ubifs_debug_info *d = c->dbg; in dbg_chk_lpt_sz()
1779 if (c->dirty_pn_cnt > c->pnode_cnt) { in dbg_chk_lpt_sz()
1781 c->dirty_pn_cnt, c->pnode_cnt); in dbg_chk_lpt_sz()
1784 if (c->dirty_nn_cnt > c->nnode_cnt) { in dbg_chk_lpt_sz()
1786 c->dirty_nn_cnt, c->nnode_cnt); in dbg_chk_lpt_sz()
1799 chk_lpt_sz = c->leb_size; in dbg_chk_lpt_sz()
1801 chk_lpt_sz += len - c->nhead_offs; in dbg_chk_lpt_sz()
1807 if (d->chk_lpt_sz > c->lpt_sz) { in dbg_chk_lpt_sz()
1809 d->chk_lpt_sz, c->lpt_sz); in dbg_chk_lpt_sz()
1822 lpt_sz = (long long)c->pnode_cnt * c->pnode_sz; in dbg_chk_lpt_sz()
1823 lpt_sz += (long long)c->nnode_cnt * c->nnode_sz; in dbg_chk_lpt_sz()
1824 lpt_sz += c->ltab_sz; in dbg_chk_lpt_sz()
1825 if (c->big_lpt) in dbg_chk_lpt_sz()
1826 lpt_sz += c->lsave_sz; in dbg_chk_lpt_sz()
1833 dbg_dump_lpt_info(c); in dbg_chk_lpt_sz()
1834 dbg_dump_lpt_lebs(c); in dbg_chk_lpt_sz()
1862 static void dump_lpt_leb(const struct ubifs_info *c, int lnum) in dump_lpt_leb() argument
1864 int err, len = c->leb_size, node_type, node_num, node_len, offs; in dump_lpt_leb()
1865 void *buf = c->dbg->buf; in dump_lpt_leb()
1869 err = ubi_read(c->ubi, lnum, buf, 0, c->leb_size); in dump_lpt_leb()
1875 offs = c->leb_size - len; in dump_lpt_leb()
1876 if (!is_a_node(c, buf, len)) { in dump_lpt_leb()
1879 pad_len = get_pad_len(c, buf, len); in dump_lpt_leb()
1893 node_type = get_lpt_node_type(c, buf, &node_num); in dump_lpt_leb()
1897 node_len = c->pnode_sz; in dump_lpt_leb()
1898 if (c->big_lpt) in dump_lpt_leb()
1911 node_len = c->nnode_sz; in dump_lpt_leb()
1912 if (c->big_lpt) in dump_lpt_leb()
1918 err = ubifs_unpack_nnode(c, buf, &nnode); in dump_lpt_leb()
1929 node_len = c->ltab_sz; in dump_lpt_leb()
1934 node_len = c->lsave_sz; in dump_lpt_leb()
1957 void dbg_dump_lpt_lebs(const struct ubifs_info *c) in dbg_dump_lpt_lebs() argument
1963 for (i = 0; i < c->lpt_lebs; i++) in dbg_dump_lpt_lebs()
1964 dump_lpt_leb(c, i + c->lpt_first); in dbg_dump_lpt_lebs()