Lines Matching full:c

5  * Copyright (C) 2006-2008 Nokia Corporation.
21 static int dbg_populate_lsave(struct ubifs_info *c);
25 * @c: UBIFS file-system description object
30 static struct ubifs_cnode *first_dirty_cnode(const struct ubifs_info *c, struct ubifs_nnode *nnode) in first_dirty_cnode() argument
32 ubifs_assert(c, nnode); in first_dirty_cnode()
56 * @c: UBIFS file-system description object
61 static struct ubifs_cnode *next_dirty_cnode(const struct ubifs_info *c, struct ubifs_cnode *cnode) in next_dirty_cnode() argument
66 ubifs_assert(c, cnode); in next_dirty_cnode()
76 return first_dirty_cnode(c, (struct ubifs_nnode *)cnode); in next_dirty_cnode()
84 * @c: UBIFS file-system description object
88 static int get_cnodes_to_commit(struct ubifs_info *c) in get_cnodes_to_commit() argument
93 if (!c->nroot) in get_cnodes_to_commit()
96 if (!test_bit(DIRTY_CNODE, &c->nroot->flags)) in get_cnodes_to_commit()
99 c->lpt_cnext = first_dirty_cnode(c, c->nroot); in get_cnodes_to_commit()
100 cnode = c->lpt_cnext; in get_cnodes_to_commit()
105 ubifs_assert(c, !test_bit(COW_CNODE, &cnode->flags)); in get_cnodes_to_commit()
107 cnext = next_dirty_cnode(c, cnode); in get_cnodes_to_commit()
109 cnode->cnext = c->lpt_cnext; in get_cnodes_to_commit()
118 ubifs_assert(c, cnt == c->dirty_nn_cnt + c->dirty_pn_cnt); in get_cnodes_to_commit()
124 * @c: UBIFS file-system description object
129 static void upd_ltab(struct ubifs_info *c, int lnum, int free, int dirty) in upd_ltab() argument
132 lnum, c->ltab[lnum - c->lpt_first].free, in upd_ltab()
133 c->ltab[lnum - c->lpt_first].dirty, free, dirty); in upd_ltab()
134 ubifs_assert(c, lnum >= c->lpt_first && lnum <= c->lpt_last); in upd_ltab()
135 c->ltab[lnum - c->lpt_first].free = free; in upd_ltab()
136 c->ltab[lnum - c->lpt_first].dirty += dirty; in upd_ltab()
141 * @c: UBIFS file-system description object
149 static int alloc_lpt_leb(struct ubifs_info *c, int *lnum) in alloc_lpt_leb() argument
153 n = *lnum - c->lpt_first + 1; in alloc_lpt_leb()
154 for (i = n; i < c->lpt_lebs; i++) { in alloc_lpt_leb()
155 if (c->ltab[i].tgc || c->ltab[i].cmt) in alloc_lpt_leb()
157 if (c->ltab[i].free == c->leb_size) { in alloc_lpt_leb()
158 c->ltab[i].cmt = 1; in alloc_lpt_leb()
159 *lnum = i + c->lpt_first; in alloc_lpt_leb()
165 if (c->ltab[i].tgc || c->ltab[i].cmt) in alloc_lpt_leb()
167 if (c->ltab[i].free == c->leb_size) { in alloc_lpt_leb()
168 c->ltab[i].cmt = 1; in alloc_lpt_leb()
169 *lnum = i + c->lpt_first; in alloc_lpt_leb()
178 * @c: UBIFS file-system description object
182 static int layout_cnodes(struct ubifs_info *c) in layout_cnodes() argument
187 err = dbg_chk_lpt_sz(c, 0, 0); in layout_cnodes()
190 cnode = c->lpt_cnext; in layout_cnodes()
193 lnum = c->nhead_lnum; in layout_cnodes()
194 offs = c->nhead_offs; in layout_cnodes()
196 done_lsave = !c->big_lpt; in layout_cnodes()
198 if (!done_lsave && offs + c->lsave_sz <= c->leb_size) { in layout_cnodes()
200 c->lsave_lnum = lnum; in layout_cnodes()
201 c->lsave_offs = offs; in layout_cnodes()
202 offs += c->lsave_sz; in layout_cnodes()
203 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in layout_cnodes()
206 if (offs + c->ltab_sz <= c->leb_size) { in layout_cnodes()
208 c->ltab_lnum = lnum; in layout_cnodes()
209 c->ltab_offs = offs; in layout_cnodes()
210 offs += c->ltab_sz; in layout_cnodes()
211 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in layout_cnodes()
216 len = c->nnode_sz; in layout_cnodes()
217 c->dirty_nn_cnt -= 1; in layout_cnodes()
219 len = c->pnode_sz; in layout_cnodes()
220 c->dirty_pn_cnt -= 1; in layout_cnodes()
222 while (offs + len > c->leb_size) { in layout_cnodes()
223 alen = ALIGN(offs, c->min_io_size); in layout_cnodes()
224 upd_ltab(c, lnum, c->leb_size - alen, alen - offs); in layout_cnodes()
225 dbg_chk_lpt_sz(c, 2, c->leb_size - offs); in layout_cnodes()
226 err = alloc_lpt_leb(c, &lnum); in layout_cnodes()
230 ubifs_assert(c, lnum >= c->lpt_first && in layout_cnodes()
231 lnum <= c->lpt_last); in layout_cnodes()
235 c->lsave_lnum = lnum; in layout_cnodes()
236 c->lsave_offs = offs; in layout_cnodes()
237 offs += c->lsave_sz; in layout_cnodes()
238 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in layout_cnodes()
243 c->ltab_lnum = lnum; in layout_cnodes()
244 c->ltab_offs = offs; in layout_cnodes()
245 offs += c->ltab_sz; in layout_cnodes()
246 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in layout_cnodes()
255 c->lpt_lnum = lnum; in layout_cnodes()
256 c->lpt_offs = offs; in layout_cnodes()
259 dbg_chk_lpt_sz(c, 1, len); in layout_cnodes()
261 } while (cnode && cnode != c->lpt_cnext); in layout_cnodes()
265 if (offs + c->lsave_sz > c->leb_size) { in layout_cnodes()
266 alen = ALIGN(offs, c->min_io_size); in layout_cnodes()
267 upd_ltab(c, lnum, c->leb_size - alen, alen - offs); in layout_cnodes()
268 dbg_chk_lpt_sz(c, 2, c->leb_size - offs); in layout_cnodes()
269 err = alloc_lpt_leb(c, &lnum); in layout_cnodes()
273 ubifs_assert(c, lnum >= c->lpt_first && in layout_cnodes()
274 lnum <= c->lpt_last); in layout_cnodes()
277 c->lsave_lnum = lnum; in layout_cnodes()
278 c->lsave_offs = offs; in layout_cnodes()
279 offs += c->lsave_sz; in layout_cnodes()
280 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in layout_cnodes()
285 if (offs + c->ltab_sz > c->leb_size) { in layout_cnodes()
286 alen = ALIGN(offs, c->min_io_size); in layout_cnodes()
287 upd_ltab(c, lnum, c->leb_size - alen, alen - offs); in layout_cnodes()
288 dbg_chk_lpt_sz(c, 2, c->leb_size - offs); in layout_cnodes()
289 err = alloc_lpt_leb(c, &lnum); in layout_cnodes()
293 ubifs_assert(c, lnum >= c->lpt_first && in layout_cnodes()
294 lnum <= c->lpt_last); in layout_cnodes()
296 c->ltab_lnum = lnum; in layout_cnodes()
297 c->ltab_offs = offs; in layout_cnodes()
298 offs += c->ltab_sz; in layout_cnodes()
299 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in layout_cnodes()
302 alen = ALIGN(offs, c->min_io_size); in layout_cnodes()
303 upd_ltab(c, lnum, c->leb_size - alen, alen - offs); in layout_cnodes()
304 dbg_chk_lpt_sz(c, 4, alen - offs); in layout_cnodes()
305 err = dbg_chk_lpt_sz(c, 3, alen); in layout_cnodes()
311 ubifs_err(c, "LPT out of space at LEB %d:%d needing %d, done_ltab %d, done_lsave %d", in layout_cnodes()
313 ubifs_dump_lpt_info(c); in layout_cnodes()
314 ubifs_dump_lpt_lebs(c); in layout_cnodes()
321 * @c: UBIFS file-system description object
333 static int realloc_lpt_leb(struct ubifs_info *c, int *lnum) in realloc_lpt_leb() argument
337 n = *lnum - c->lpt_first + 1; in realloc_lpt_leb()
338 for (i = n; i < c->lpt_lebs; i++) in realloc_lpt_leb()
339 if (c->ltab[i].cmt) { in realloc_lpt_leb()
340 c->ltab[i].cmt = 0; in realloc_lpt_leb()
341 *lnum = i + c->lpt_first; in realloc_lpt_leb()
346 if (c->ltab[i].cmt) { in realloc_lpt_leb()
347 c->ltab[i].cmt = 0; in realloc_lpt_leb()
348 *lnum = i + c->lpt_first; in realloc_lpt_leb()
356 * @c: UBIFS file-system description object
360 static int write_cnodes(struct ubifs_info *c) in write_cnodes() argument
364 void *buf = c->lpt_buf; in write_cnodes()
366 cnode = c->lpt_cnext; in write_cnodes()
369 lnum = c->nhead_lnum; in write_cnodes()
370 offs = c->nhead_offs; in write_cnodes()
374 err = ubifs_leb_unmap(c, lnum); in write_cnodes()
379 done_lsave = !c->big_lpt; in write_cnodes()
381 if (!done_lsave && offs + c->lsave_sz <= c->leb_size) { in write_cnodes()
383 ubifs_pack_lsave(c, buf + offs, c->lsave); in write_cnodes()
384 offs += c->lsave_sz; in write_cnodes()
385 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in write_cnodes()
388 if (offs + c->ltab_sz <= c->leb_size) { in write_cnodes()
390 ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); in write_cnodes()
391 offs += c->ltab_sz; in write_cnodes()
392 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in write_cnodes()
398 len = c->nnode_sz; in write_cnodes()
400 len = c->pnode_sz; in write_cnodes()
401 while (offs + len > c->leb_size) { in write_cnodes()
404 alen = ALIGN(wlen, c->min_io_size); in write_cnodes()
406 err = ubifs_leb_write(c, lnum, buf + from, from, in write_cnodes()
411 dbg_chk_lpt_sz(c, 2, c->leb_size - offs); in write_cnodes()
412 err = realloc_lpt_leb(c, &lnum); in write_cnodes()
416 ubifs_assert(c, lnum >= c->lpt_first && in write_cnodes()
417 lnum <= c->lpt_last); in write_cnodes()
418 err = ubifs_leb_unmap(c, lnum); in write_cnodes()
424 ubifs_pack_lsave(c, buf + offs, c->lsave); in write_cnodes()
425 offs += c->lsave_sz; in write_cnodes()
426 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in write_cnodes()
431 ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); in write_cnodes()
432 offs += c->ltab_sz; in write_cnodes()
433 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in write_cnodes()
439 ubifs_pack_nnode(c, buf + offs, in write_cnodes()
442 ubifs_pack_pnode(c, buf + offs, in write_cnodes()
455 dbg_chk_lpt_sz(c, 1, len); in write_cnodes()
457 } while (cnode && cnode != c->lpt_cnext); in write_cnodes()
461 if (offs + c->lsave_sz > c->leb_size) { in write_cnodes()
463 alen = ALIGN(wlen, c->min_io_size); in write_cnodes()
465 err = ubifs_leb_write(c, lnum, buf + from, from, alen); in write_cnodes()
468 dbg_chk_lpt_sz(c, 2, c->leb_size - offs); in write_cnodes()
469 err = realloc_lpt_leb(c, &lnum); in write_cnodes()
473 ubifs_assert(c, lnum >= c->lpt_first && in write_cnodes()
474 lnum <= c->lpt_last); in write_cnodes()
475 err = ubifs_leb_unmap(c, lnum); in write_cnodes()
480 ubifs_pack_lsave(c, buf + offs, c->lsave); in write_cnodes()
481 offs += c->lsave_sz; in write_cnodes()
482 dbg_chk_lpt_sz(c, 1, c->lsave_sz); in write_cnodes()
487 if (offs + c->ltab_sz > c->leb_size) { in write_cnodes()
489 alen = ALIGN(wlen, c->min_io_size); in write_cnodes()
491 err = ubifs_leb_write(c, lnum, buf + from, from, alen); in write_cnodes()
494 dbg_chk_lpt_sz(c, 2, c->leb_size - offs); in write_cnodes()
495 err = realloc_lpt_leb(c, &lnum); in write_cnodes()
499 ubifs_assert(c, lnum >= c->lpt_first && in write_cnodes()
500 lnum <= c->lpt_last); in write_cnodes()
501 err = ubifs_leb_unmap(c, lnum); in write_cnodes()
505 ubifs_pack_ltab(c, buf + offs, c->ltab_cmt); in write_cnodes()
506 offs += c->ltab_sz; in write_cnodes()
507 dbg_chk_lpt_sz(c, 1, c->ltab_sz); in write_cnodes()
512 alen = ALIGN(wlen, c->min_io_size); in write_cnodes()
514 err = ubifs_leb_write(c, lnum, buf + from, from, alen); in write_cnodes()
518 dbg_chk_lpt_sz(c, 4, alen - wlen); in write_cnodes()
519 err = dbg_chk_lpt_sz(c, 3, ALIGN(offs, c->min_io_size)); in write_cnodes()
523 c->nhead_lnum = lnum; in write_cnodes()
524 c->nhead_offs = ALIGN(offs, c->min_io_size); in write_cnodes()
526 dbg_lp("LPT root is at %d:%d", c->lpt_lnum, c->lpt_offs); in write_cnodes()
527 dbg_lp("LPT head is at %d:%d", c->nhead_lnum, c->nhead_offs); in write_cnodes()
528 dbg_lp("LPT ltab is at %d:%d", c->ltab_lnum, c->ltab_offs); in write_cnodes()
529 if (c->big_lpt) in write_cnodes()
530 dbg_lp("LPT lsave is at %d:%d", c->lsave_lnum, c->lsave_offs); in write_cnodes()
535 ubifs_err(c, "LPT out of space mismatch at LEB %d:%d needing %d, done_ltab %d, done_lsave %d", in write_cnodes()
537 ubifs_dump_lpt_info(c); in write_cnodes()
538 ubifs_dump_lpt_lebs(c); in write_cnodes()
545 * @c: UBIFS file-system description object
552 static struct ubifs_pnode *next_pnode_to_dirty(struct ubifs_info *c, in next_pnode_to_dirty() argument
562 return ubifs_get_pnode(c, nnode, iip); in next_pnode_to_dirty()
578 nnode = ubifs_get_nnode(c, nnode, iip); in next_pnode_to_dirty()
595 nnode = ubifs_get_nnode(c, nnode, iip); in next_pnode_to_dirty()
606 return ubifs_get_pnode(c, nnode, iip); in next_pnode_to_dirty()
611 * @c: UBIFS file-system description object
614 static void add_pnode_dirt(struct ubifs_info *c, struct ubifs_pnode *pnode) in add_pnode_dirt() argument
616 ubifs_add_lpt_dirt(c, pnode->parent->nbranch[pnode->iip].lnum, in add_pnode_dirt()
617 c->pnode_sz); in add_pnode_dirt()
622 * @c: UBIFS file-system description object
625 static void do_make_pnode_dirty(struct ubifs_info *c, struct ubifs_pnode *pnode) in do_make_pnode_dirty() argument
631 c->dirty_pn_cnt += 1; in do_make_pnode_dirty()
632 add_pnode_dirt(c, pnode); in do_make_pnode_dirty()
637 c->dirty_nn_cnt += 1; in do_make_pnode_dirty()
638 ubifs_add_nnode_dirt(c, nnode); in do_make_pnode_dirty()
648 * @c: UBIFS file-system description object
657 static int make_tree_dirty(struct ubifs_info *c) in make_tree_dirty() argument
661 pnode = ubifs_pnode_lookup(c, 0); in make_tree_dirty()
666 do_make_pnode_dirty(c, pnode); in make_tree_dirty()
667 pnode = next_pnode_to_dirty(c, pnode); in make_tree_dirty()
676 * @c: UBIFS file-system description object
681 static int need_write_all(struct ubifs_info *c) in need_write_all() argument
686 for (i = 0; i < c->lpt_lebs; i++) { in need_write_all()
687 if (i + c->lpt_first == c->nhead_lnum) in need_write_all()
688 free += c->leb_size - c->nhead_offs; in need_write_all()
689 else if (c->ltab[i].free == c->leb_size) in need_write_all()
690 free += c->leb_size; in need_write_all()
691 else if (c->ltab[i].free + c->ltab[i].dirty == c->leb_size) in need_write_all()
692 free += c->leb_size; in need_write_all()
695 if (free <= c->lpt_sz * 2) in need_write_all()
702 * @c: UBIFS file-system description object
708 static void lpt_tgc_start(struct ubifs_info *c) in lpt_tgc_start() argument
712 for (i = 0; i < c->lpt_lebs; i++) { in lpt_tgc_start()
713 if (i + c->lpt_first == c->nhead_lnum) in lpt_tgc_start()
715 if (c->ltab[i].dirty > 0 && in lpt_tgc_start()
716 c->ltab[i].free + c->ltab[i].dirty == c->leb_size) { in lpt_tgc_start()
717 c->ltab[i].tgc = 1; in lpt_tgc_start()
718 c->ltab[i].free = c->leb_size; in lpt_tgc_start()
719 c->ltab[i].dirty = 0; in lpt_tgc_start()
720 dbg_lp("LEB %d", i + c->lpt_first); in lpt_tgc_start()
727 * @c: UBIFS file-system description object
734 static int lpt_tgc_end(struct ubifs_info *c) in lpt_tgc_end() argument
738 for (i = 0; i < c->lpt_lebs; i++) in lpt_tgc_end()
739 if (c->ltab[i].tgc) { in lpt_tgc_end()
740 err = ubifs_leb_unmap(c, i + c->lpt_first); in lpt_tgc_end()
743 c->ltab[i].tgc = 0; in lpt_tgc_end()
744 dbg_lp("LEB %d", i + c->lpt_first); in lpt_tgc_end()
751 * @c: the UBIFS file-system description object
761 static void populate_lsave(struct ubifs_info *c) in populate_lsave() argument
767 ubifs_assert(c, c->big_lpt); in populate_lsave()
768 if (!(c->lpt_drty_flgs & LSAVE_DIRTY)) { in populate_lsave()
769 c->lpt_drty_flgs |= LSAVE_DIRTY; in populate_lsave()
770 ubifs_add_lpt_dirt(c, c->lsave_lnum, c->lsave_sz); in populate_lsave()
773 if (dbg_populate_lsave(c)) in populate_lsave()
776 list_for_each_entry(lprops, &c->empty_list, list) { in populate_lsave()
777 c->lsave[cnt++] = lprops->lnum; in populate_lsave()
778 if (cnt >= c->lsave_cnt) in populate_lsave()
781 list_for_each_entry(lprops, &c->freeable_list, list) { in populate_lsave()
782 c->lsave[cnt++] = lprops->lnum; in populate_lsave()
783 if (cnt >= c->lsave_cnt) in populate_lsave()
786 list_for_each_entry(lprops, &c->frdi_idx_list, list) { in populate_lsave()
787 c->lsave[cnt++] = lprops->lnum; in populate_lsave()
788 if (cnt >= c->lsave_cnt) in populate_lsave()
791 heap = &c->lpt_heap[LPROPS_DIRTY_IDX - 1]; in populate_lsave()
793 c->lsave[cnt++] = heap->arr[i]->lnum; in populate_lsave()
794 if (cnt >= c->lsave_cnt) in populate_lsave()
797 heap = &c->lpt_heap[LPROPS_DIRTY - 1]; in populate_lsave()
799 c->lsave[cnt++] = heap->arr[i]->lnum; in populate_lsave()
800 if (cnt >= c->lsave_cnt) in populate_lsave()
803 heap = &c->lpt_heap[LPROPS_FREE - 1]; in populate_lsave()
805 c->lsave[cnt++] = heap->arr[i]->lnum; in populate_lsave()
806 if (cnt >= c->lsave_cnt) in populate_lsave()
810 while (cnt < c->lsave_cnt) in populate_lsave()
811 c->lsave[cnt++] = c->main_first; in populate_lsave()
816 * @c: UBIFS file-system description object
822 static struct ubifs_nnode *nnode_lookup(struct ubifs_info *c, int i) in nnode_lookup() argument
827 if (!c->nroot) { in nnode_lookup()
828 err = ubifs_read_nnode(c, NULL, 0); in nnode_lookup()
832 nnode = c->nroot; in nnode_lookup()
838 nnode = ubifs_get_nnode(c, nnode, iip); in nnode_lookup()
847 * @c: UBIFS file-system description object
853 * used only for the "big" LPT model (c->big_lpt == 1). Garbage collection
860 static int make_nnode_dirty(struct ubifs_info *c, int node_num, int lnum, in make_nnode_dirty() argument
865 nnode = nnode_lookup(c, node_num); in make_nnode_dirty()
874 } else if (c->lpt_lnum != lnum || c->lpt_offs != offs) in make_nnode_dirty()
878 c->dirty_nn_cnt += 1; in make_nnode_dirty()
879 ubifs_add_nnode_dirt(c, nnode); in make_nnode_dirty()
884 c->dirty_nn_cnt += 1; in make_nnode_dirty()
885 ubifs_add_nnode_dirt(c, nnode); in make_nnode_dirty()
896 * @c: UBIFS file-system description object
902 * used only for the "big" LPT model (c->big_lpt == 1). Garbage collection
909 static int make_pnode_dirty(struct ubifs_info *c, int node_num, int lnum, in make_pnode_dirty() argument
915 pnode = ubifs_pnode_lookup(c, node_num); in make_pnode_dirty()
921 do_make_pnode_dirty(c, pnode); in make_pnode_dirty()
927 * @c: UBIFS file-system description object
932 * used only for the "big" LPT model (c->big_lpt == 1). Garbage collection
939 static int make_ltab_dirty(struct ubifs_info *c, int lnum, int offs) in make_ltab_dirty() argument
941 if (lnum != c->ltab_lnum || offs != c->ltab_offs) in make_ltab_dirty()
943 if (!(c->lpt_drty_flgs & LTAB_DIRTY)) { in make_ltab_dirty()
944 c->lpt_drty_flgs |= LTAB_DIRTY; in make_ltab_dirty()
945 ubifs_add_lpt_dirt(c, c->ltab_lnum, c->ltab_sz); in make_ltab_dirty()
952 * @c: UBIFS file-system description object
957 * used only for the "big" LPT model (c->big_lpt == 1). Garbage collection
964 static int make_lsave_dirty(struct ubifs_info *c, int lnum, int offs) in make_lsave_dirty() argument
966 if (lnum != c->lsave_lnum || offs != c->lsave_offs) in make_lsave_dirty()
968 if (!(c->lpt_drty_flgs & LSAVE_DIRTY)) { in make_lsave_dirty()
969 c->lpt_drty_flgs |= LSAVE_DIRTY; in make_lsave_dirty()
970 ubifs_add_lpt_dirt(c, c->lsave_lnum, c->lsave_sz); in make_lsave_dirty()
977 * @c: UBIFS file-system description object
984 * used only for the "big" LPT model (c->big_lpt == 1). Garbage collection
991 static int make_node_dirty(struct ubifs_info *c, int node_type, int node_num, in make_node_dirty() argument
996 return make_nnode_dirty(c, node_num, lnum, offs); in make_node_dirty()
998 return make_pnode_dirty(c, node_num, lnum, offs); in make_node_dirty()
1000 return make_ltab_dirty(c, lnum, offs); in make_node_dirty()
1002 return make_lsave_dirty(c, lnum, offs); in make_node_dirty()
1009 * @c: UBIFS file-system description object
1012 static int get_lpt_node_len(const struct ubifs_info *c, int node_type) in get_lpt_node_len() argument
1016 return c->nnode_sz; in get_lpt_node_len()
1018 return c->pnode_sz; in get_lpt_node_len()
1020 return c->ltab_sz; in get_lpt_node_len()
1022 return c->lsave_sz; in get_lpt_node_len()
1029 * @c: UBIFS file-system description object
1033 static int get_pad_len(const struct ubifs_info *c, uint8_t *buf, int len) in get_pad_len() argument
1037 if (c->min_io_size == 1) in get_pad_len()
1039 offs = c->leb_size - len; in get_pad_len()
1040 pad_len = ALIGN(offs, c->min_io_size) - offs; in get_pad_len()
1046 * @c: UBIFS file-system description object
1050 static int get_lpt_node_type(const struct ubifs_info *c, uint8_t *buf, in get_lpt_node_type() argument
1056 node_type = ubifs_unpack_bits(c, &addr, &pos, UBIFS_LPT_TYPE_BITS); in get_lpt_node_type()
1057 *node_num = ubifs_unpack_bits(c, &addr, &pos, c->pcnt_bits); in get_lpt_node_type()
1063 * @c: UBIFS file-system description object
1069 static int is_a_node(const struct ubifs_info *c, uint8_t *buf, int len) in is_a_node() argument
1077 node_type = ubifs_unpack_bits(c, &addr, &pos, UBIFS_LPT_TYPE_BITS); in is_a_node()
1080 node_len = get_lpt_node_len(c, node_type); in is_a_node()
1085 crc = ubifs_unpack_bits(c, &addr, &pos, UBIFS_LPT_CRC_BITS); in is_a_node()
1095 * @c: UBIFS file-system description object
1099 * (c->big_lpt == 1). Garbage collection simply involves marking all the nodes
1105 static int lpt_gc_lnum(struct ubifs_info *c, int lnum) in lpt_gc_lnum() argument
1107 int err, len = c->leb_size, node_type, node_num, node_len, offs; in lpt_gc_lnum()
1108 void *buf = c->lpt_buf; in lpt_gc_lnum()
1112 err = ubifs_leb_read(c, lnum, buf, 0, c->leb_size, 1); in lpt_gc_lnum()
1117 if (!is_a_node(c, buf, len)) { in lpt_gc_lnum()
1120 pad_len = get_pad_len(c, buf, len); in lpt_gc_lnum()
1128 node_type = get_lpt_node_type(c, buf, &node_num); in lpt_gc_lnum()
1129 node_len = get_lpt_node_len(c, node_type); in lpt_gc_lnum()
1130 offs = c->leb_size - len; in lpt_gc_lnum()
1131 ubifs_assert(c, node_len != 0); in lpt_gc_lnum()
1132 mutex_lock(&c->lp_mutex); in lpt_gc_lnum()
1133 err = make_node_dirty(c, node_type, node_num, lnum, offs); in lpt_gc_lnum()
1134 mutex_unlock(&c->lp_mutex); in lpt_gc_lnum()
1145 * @c: UBIFS file-system description object
1150 static int lpt_gc(struct ubifs_info *c) in lpt_gc() argument
1154 mutex_lock(&c->lp_mutex); in lpt_gc()
1155 for (i = 0; i < c->lpt_lebs; i++) { in lpt_gc()
1156 ubifs_assert(c, !c->ltab[i].tgc); in lpt_gc()
1157 if (i + c->lpt_first == c->nhead_lnum || in lpt_gc()
1158 c->ltab[i].free + c->ltab[i].dirty == c->leb_size) in lpt_gc()
1160 if (c->ltab[i].dirty > dirty) { in lpt_gc()
1161 dirty = c->ltab[i].dirty; in lpt_gc()
1162 lnum = i + c->lpt_first; in lpt_gc()
1165 mutex_unlock(&c->lp_mutex); in lpt_gc()
1168 return lpt_gc_lnum(c, lnum); in lpt_gc()
1173 * @c: the UBIFS file-system description object
1181 int ubifs_lpt_start_commit(struct ubifs_info *c) in ubifs_lpt_start_commit() argument
1187 mutex_lock(&c->lp_mutex); in ubifs_lpt_start_commit()
1188 err = dbg_chk_lpt_free_spc(c); in ubifs_lpt_start_commit()
1191 err = dbg_check_ltab(c); in ubifs_lpt_start_commit()
1195 if (c->check_lpt_free) { in ubifs_lpt_start_commit()
1202 c->check_lpt_free = 0; in ubifs_lpt_start_commit()
1203 while (need_write_all(c)) { in ubifs_lpt_start_commit()
1204 mutex_unlock(&c->lp_mutex); in ubifs_lpt_start_commit()
1205 err = lpt_gc(c); in ubifs_lpt_start_commit()
1208 mutex_lock(&c->lp_mutex); in ubifs_lpt_start_commit()
1212 lpt_tgc_start(c); in ubifs_lpt_start_commit()
1214 if (!c->dirty_pn_cnt) { in ubifs_lpt_start_commit()
1220 if (!c->big_lpt && need_write_all(c)) { in ubifs_lpt_start_commit()
1222 err = make_tree_dirty(c); in ubifs_lpt_start_commit()
1225 lpt_tgc_start(c); in ubifs_lpt_start_commit()
1228 if (c->big_lpt) in ubifs_lpt_start_commit()
1229 populate_lsave(c); in ubifs_lpt_start_commit()
1231 cnt = get_cnodes_to_commit(c); in ubifs_lpt_start_commit()
1232 ubifs_assert(c, cnt != 0); in ubifs_lpt_start_commit()
1234 err = layout_cnodes(c); in ubifs_lpt_start_commit()
1238 err = ubifs_lpt_calc_hash(c, c->mst_node->hash_lpt); in ubifs_lpt_start_commit()
1243 memcpy(c->ltab_cmt, c->ltab, in ubifs_lpt_start_commit()
1244 sizeof(struct ubifs_lpt_lprops) * c->lpt_lebs); in ubifs_lpt_start_commit()
1245 c->lpt_drty_flgs &= ~(LTAB_DIRTY | LSAVE_DIRTY); in ubifs_lpt_start_commit()
1248 mutex_unlock(&c->lp_mutex); in ubifs_lpt_start_commit()
1254 * @c: UBIFS file-system description object
1256 static void free_obsolete_cnodes(struct ubifs_info *c) in free_obsolete_cnodes() argument
1260 cnext = c->lpt_cnext; in free_obsolete_cnodes()
1270 } while (cnext != c->lpt_cnext); in free_obsolete_cnodes()
1271 c->lpt_cnext = NULL; in free_obsolete_cnodes()
1276 * @c: the UBIFS file-system description object
1283 int ubifs_lpt_end_commit(struct ubifs_info *c) in ubifs_lpt_end_commit() argument
1289 if (!c->lpt_cnext) in ubifs_lpt_end_commit()
1292 err = write_cnodes(c); in ubifs_lpt_end_commit()
1296 mutex_lock(&c->lp_mutex); in ubifs_lpt_end_commit()
1297 free_obsolete_cnodes(c); in ubifs_lpt_end_commit()
1298 mutex_unlock(&c->lp_mutex); in ubifs_lpt_end_commit()
1305 * @c: UBIFS file-system description object
1310 int ubifs_lpt_post_commit(struct ubifs_info *c) in ubifs_lpt_post_commit() argument
1314 mutex_lock(&c->lp_mutex); in ubifs_lpt_post_commit()
1315 err = lpt_tgc_end(c); in ubifs_lpt_post_commit()
1318 if (c->big_lpt) in ubifs_lpt_post_commit()
1319 while (need_write_all(c)) { in ubifs_lpt_post_commit()
1320 mutex_unlock(&c->lp_mutex); in ubifs_lpt_post_commit()
1321 err = lpt_gc(c); in ubifs_lpt_post_commit()
1324 mutex_lock(&c->lp_mutex); in ubifs_lpt_post_commit()
1327 mutex_unlock(&c->lp_mutex); in ubifs_lpt_post_commit()
1333 * @c: UBIFS file-system description object
1339 static struct ubifs_nnode *first_nnode(struct ubifs_info *c, int *hght) in first_nnode() argument
1344 nnode = c->nroot; in first_nnode()
1348 for (h = 1; h < c->lpt_hght; h++) { in first_nnode()
1366 * @c: UBIFS file-system description object
1373 static struct ubifs_nnode *next_nnode(struct ubifs_info *c, in next_nnode() argument
1395 for (h = *hght + 1; h < c->lpt_hght; h++) { in next_nnode()
1413 * @c: UBIFS file-system description object
1416 void ubifs_lpt_free(struct ubifs_info *c, int wr_only) in ubifs_lpt_free() argument
1423 free_obsolete_cnodes(c); /* Leftover from a failed commit */ in ubifs_lpt_free()
1425 vfree(c->ltab_cmt); in ubifs_lpt_free()
1426 c->ltab_cmt = NULL; in ubifs_lpt_free()
1427 vfree(c->lpt_buf); in ubifs_lpt_free()
1428 c->lpt_buf = NULL; in ubifs_lpt_free()
1429 kfree(c->lsave); in ubifs_lpt_free()
1430 c->lsave = NULL; in ubifs_lpt_free()
1437 nnode = first_nnode(c, &hght); in ubifs_lpt_free()
1441 nnode = next_nnode(c, nnode, &hght); in ubifs_lpt_free()
1444 kfree(c->lpt_heap[i].arr); in ubifs_lpt_free()
1445 kfree(c->dirty_idx.arr); in ubifs_lpt_free()
1446 kfree(c->nroot); in ubifs_lpt_free()
1447 vfree(c->ltab); in ubifs_lpt_free()
1448 kfree(c->lpt_nod_buf); in ubifs_lpt_free()
1472 * @c: the UBIFS file-system description object
1476 static int dbg_is_nnode_dirty(struct ubifs_info *c, int lnum, int offs) in dbg_is_nnode_dirty() argument
1482 nnode = first_nnode(c, &hght); in dbg_is_nnode_dirty()
1483 for (; nnode; nnode = next_nnode(c, nnode, &hght)) { in dbg_is_nnode_dirty()
1495 if (c->lpt_lnum != lnum || c->lpt_offs != offs) in dbg_is_nnode_dirty()
1507 * @c: the UBIFS file-system description object
1511 static int dbg_is_pnode_dirty(struct ubifs_info *c, int lnum, int offs) in dbg_is_pnode_dirty() argument
1515 cnt = DIV_ROUND_UP(c->main_lebs, UBIFS_LPT_FANOUT); in dbg_is_pnode_dirty()
1521 pnode = ubifs_pnode_lookup(c, i); in dbg_is_pnode_dirty()
1536 * @c: the UBIFS file-system description object
1540 static int dbg_is_ltab_dirty(struct ubifs_info *c, int lnum, int offs) in dbg_is_ltab_dirty() argument
1542 if (lnum != c->ltab_lnum || offs != c->ltab_offs) in dbg_is_ltab_dirty()
1544 return (c->lpt_drty_flgs & LTAB_DIRTY) != 0; in dbg_is_ltab_dirty()
1549 * @c: the UBIFS file-system description object
1553 static int dbg_is_lsave_dirty(struct ubifs_info *c, int lnum, int offs) in dbg_is_lsave_dirty() argument
1555 if (lnum != c->lsave_lnum || offs != c->lsave_offs) in dbg_is_lsave_dirty()
1557 return (c->lpt_drty_flgs & LSAVE_DIRTY) != 0; in dbg_is_lsave_dirty()
1562 * @c: the UBIFS file-system description object
1567 static int dbg_is_node_dirty(struct ubifs_info *c, int node_type, int lnum, in dbg_is_node_dirty() argument
1572 return dbg_is_nnode_dirty(c, lnum, offs); in dbg_is_node_dirty()
1574 return dbg_is_pnode_dirty(c, lnum, offs); in dbg_is_node_dirty()
1576 return dbg_is_ltab_dirty(c, lnum, offs); in dbg_is_node_dirty()
1578 return dbg_is_lsave_dirty(c, lnum, offs); in dbg_is_node_dirty()
1585 * @c: the UBIFS file-system description object
1590 static int dbg_check_ltab_lnum(struct ubifs_info *c, int lnum) in dbg_check_ltab_lnum() argument
1592 int err, len = c->leb_size, dirty = 0, node_type, node_num, node_len; in dbg_check_ltab_lnum()
1596 if (!dbg_is_chk_lprops(c)) in dbg_check_ltab_lnum()
1599 buf = p = __vmalloc(c->leb_size, GFP_NOFS); in dbg_check_ltab_lnum()
1601 ubifs_err(c, "cannot allocate memory for ltab checking"); in dbg_check_ltab_lnum()
1607 err = ubifs_leb_read(c, lnum, buf, 0, c->leb_size, 1); in dbg_check_ltab_lnum()
1612 if (!is_a_node(c, p, len)) { in dbg_check_ltab_lnum()
1615 pad_len = get_pad_len(c, p, len); in dbg_check_ltab_lnum()
1623 ubifs_err(c, "invalid empty space in LEB %d at %d", in dbg_check_ltab_lnum()
1624 lnum, c->leb_size - len); in dbg_check_ltab_lnum()
1627 i = lnum - c->lpt_first; in dbg_check_ltab_lnum()
1628 if (len != c->ltab[i].free) { in dbg_check_ltab_lnum()
1629 ubifs_err(c, "invalid free space in LEB %d (free %d, expected %d)", in dbg_check_ltab_lnum()
1630 lnum, len, c->ltab[i].free); in dbg_check_ltab_lnum()
1633 if (dirty != c->ltab[i].dirty) { in dbg_check_ltab_lnum()
1634 ubifs_err(c, "invalid dirty space in LEB %d (dirty %d, expected %d)", in dbg_check_ltab_lnum()
1635 lnum, dirty, c->ltab[i].dirty); in dbg_check_ltab_lnum()
1640 node_type = get_lpt_node_type(c, p, &node_num); in dbg_check_ltab_lnum()
1641 node_len = get_lpt_node_len(c, node_type); in dbg_check_ltab_lnum()
1642 ret = dbg_is_node_dirty(c, node_type, lnum, c->leb_size - len); in dbg_check_ltab_lnum()
1657 * @c: the UBIFS file-system description object
1661 int dbg_check_ltab(struct ubifs_info *c) in dbg_check_ltab() argument
1665 if (!dbg_is_chk_lprops(c)) in dbg_check_ltab()
1669 cnt = DIV_ROUND_UP(c->main_lebs, UBIFS_LPT_FANOUT); in dbg_check_ltab()
1673 pnode = ubifs_pnode_lookup(c, i); in dbg_check_ltab()
1680 err = dbg_check_lpt_nodes(c, (struct ubifs_cnode *)c->nroot, 0, 0); in dbg_check_ltab()
1685 for (lnum = c->lpt_first; lnum <= c->lpt_last; lnum++) { in dbg_check_ltab()
1686 err = dbg_check_ltab_lnum(c, lnum); in dbg_check_ltab()
1688 ubifs_err(c, "failed at LEB %d", lnum); in dbg_check_ltab()
1699 * @c: the UBIFS file-system description object
1703 int dbg_chk_lpt_free_spc(struct ubifs_info *c) in dbg_chk_lpt_free_spc() argument
1708 if (!dbg_is_chk_lprops(c)) in dbg_chk_lpt_free_spc()
1711 for (i = 0; i < c->lpt_lebs; i++) { in dbg_chk_lpt_free_spc()
1712 if (c->ltab[i].tgc || c->ltab[i].cmt) in dbg_chk_lpt_free_spc()
1714 if (i + c->lpt_first == c->nhead_lnum) in dbg_chk_lpt_free_spc()
1715 free += c->leb_size - c->nhead_offs; in dbg_chk_lpt_free_spc()
1716 else if (c->ltab[i].free == c->leb_size) in dbg_chk_lpt_free_spc()
1717 free += c->leb_size; in dbg_chk_lpt_free_spc()
1719 if (free < c->lpt_sz) { in dbg_chk_lpt_free_spc()
1720 ubifs_err(c, "LPT space error: free %lld lpt_sz %lld", in dbg_chk_lpt_free_spc()
1721 free, c->lpt_sz); in dbg_chk_lpt_free_spc()
1722 ubifs_dump_lpt_info(c); in dbg_chk_lpt_free_spc()
1723 ubifs_dump_lpt_lebs(c); in dbg_chk_lpt_free_spc()
1732 * @c: the UBIFS file-system description object
1744 int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len) in dbg_chk_lpt_sz() argument
1746 struct ubifs_debug_info *d = c->dbg; in dbg_chk_lpt_sz()
1750 if (!dbg_is_chk_lprops(c)) in dbg_chk_lpt_sz()
1759 if (c->dirty_pn_cnt > c->pnode_cnt) { in dbg_chk_lpt_sz()
1760 ubifs_err(c, "dirty pnodes %d exceed max %d", in dbg_chk_lpt_sz()
1761 c->dirty_pn_cnt, c->pnode_cnt); in dbg_chk_lpt_sz()
1764 if (c->dirty_nn_cnt > c->nnode_cnt) { in dbg_chk_lpt_sz()
1765 ubifs_err(c, "dirty nnodes %d exceed max %d", in dbg_chk_lpt_sz()
1766 c->dirty_nn_cnt, c->nnode_cnt); in dbg_chk_lpt_sz()
1779 chk_lpt_sz = c->leb_size; in dbg_chk_lpt_sz()
1781 chk_lpt_sz += len - c->nhead_offs; in dbg_chk_lpt_sz()
1783 ubifs_err(c, "LPT wrote %lld but space used was %lld", in dbg_chk_lpt_sz()
1787 if (d->chk_lpt_sz > c->lpt_sz) { in dbg_chk_lpt_sz()
1788 ubifs_err(c, "LPT wrote %lld but lpt_sz is %lld", in dbg_chk_lpt_sz()
1789 d->chk_lpt_sz, c->lpt_sz); in dbg_chk_lpt_sz()
1793 ubifs_err(c, "LPT layout size %lld but wrote %lld", in dbg_chk_lpt_sz()
1798 ubifs_err(c, "LPT new nhead offs: expected %d was %d", in dbg_chk_lpt_sz()
1802 lpt_sz = (long long)c->pnode_cnt * c->pnode_sz; in dbg_chk_lpt_sz()
1803 lpt_sz += (long long)c->nnode_cnt * c->nnode_sz; in dbg_chk_lpt_sz()
1804 lpt_sz += c->ltab_sz; in dbg_chk_lpt_sz()
1805 if (c->big_lpt) in dbg_chk_lpt_sz()
1806 lpt_sz += c->lsave_sz; in dbg_chk_lpt_sz()
1808 ubifs_err(c, "LPT chk_lpt_sz %lld + waste %lld exceeds %lld", in dbg_chk_lpt_sz()
1813 ubifs_dump_lpt_info(c); in dbg_chk_lpt_sz()
1814 ubifs_dump_lpt_lebs(c); in dbg_chk_lpt_sz()
1834 * @c: UBIFS file-system description object
1842 static void dump_lpt_leb(const struct ubifs_info *c, int lnum) in dump_lpt_leb() argument
1844 int err, len = c->leb_size, node_type, node_num, node_len, offs; in dump_lpt_leb()
1848 buf = p = __vmalloc(c->leb_size, GFP_NOFS); in dump_lpt_leb()
1850 ubifs_err(c, "cannot allocate memory to dump LPT"); in dump_lpt_leb()
1854 err = ubifs_leb_read(c, lnum, buf, 0, c->leb_size, 1); in dump_lpt_leb()
1859 offs = c->leb_size - len; in dump_lpt_leb()
1860 if (!is_a_node(c, p, len)) { in dump_lpt_leb()
1863 pad_len = get_pad_len(c, p, len); in dump_lpt_leb()
1877 node_type = get_lpt_node_type(c, p, &node_num); in dump_lpt_leb()
1881 node_len = c->pnode_sz; in dump_lpt_leb()
1882 if (c->big_lpt) in dump_lpt_leb()
1894 node_len = c->nnode_sz; in dump_lpt_leb()
1895 if (c->big_lpt) in dump_lpt_leb()
1901 err = ubifs_unpack_nnode(c, p, &nnode); in dump_lpt_leb()
1917 node_len = c->ltab_sz; in dump_lpt_leb()
1921 node_len = c->lsave_sz; in dump_lpt_leb()
1925 ubifs_err(c, "LPT node type %d not recognized", node_type); in dump_lpt_leb()
1941 * @c: UBIFS file-system description object
1946 void ubifs_dump_lpt_lebs(const struct ubifs_info *c) in ubifs_dump_lpt_lebs() argument
1951 for (i = 0; i < c->lpt_lebs; i++) in ubifs_dump_lpt_lebs()
1952 dump_lpt_leb(c, i + c->lpt_first); in ubifs_dump_lpt_lebs()
1958 * @c: UBIFS file-system description object
1965 static int dbg_populate_lsave(struct ubifs_info *c) in dbg_populate_lsave() argument
1971 if (!dbg_is_chk_gen(c)) in dbg_populate_lsave()
1976 for (i = 0; i < c->lsave_cnt; i++) in dbg_populate_lsave()
1977 c->lsave[i] = c->main_first; in dbg_populate_lsave()
1979 list_for_each_entry(lprops, &c->empty_list, list) in dbg_populate_lsave()
1980 c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum; in dbg_populate_lsave()
1981 list_for_each_entry(lprops, &c->freeable_list, list) in dbg_populate_lsave()
1982 c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum; in dbg_populate_lsave()
1983 list_for_each_entry(lprops, &c->frdi_idx_list, list) in dbg_populate_lsave()
1984 c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum; in dbg_populate_lsave()
1986 heap = &c->lpt_heap[LPROPS_DIRTY_IDX - 1]; in dbg_populate_lsave()
1988 c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum; in dbg_populate_lsave()
1989 heap = &c->lpt_heap[LPROPS_DIRTY - 1]; in dbg_populate_lsave()
1991 c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum; in dbg_populate_lsave()
1992 heap = &c->lpt_heap[LPROPS_FREE - 1]; in dbg_populate_lsave()
1994 c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum; in dbg_populate_lsave()