• Home
  • Raw
  • Download

Lines Matching refs:c

36 static int make_idx_node(struct ubifs_info *c, struct ubifs_idx_node *idx,  in make_idx_node()  argument
47 struct ubifs_branch *br = ubifs_idx_branch(c, idx, i); in make_idx_node()
50 key_write_idx(c, &zbr->key, &br->key); in make_idx_node()
56 dbg_dump_znode(c, znode); in make_idx_node()
58 dbg_dump_znode(c, zbr->znode); in make_idx_node()
61 ubifs_prepare_node(c, idx, len, 0); in make_idx_node()
69 err = insert_old_idx_znode(c, znode); in make_idx_node()
81 c->zroot.lnum = lnum; in make_idx_node()
82 c->zroot.offs = offs; in make_idx_node()
83 c->zroot.len = len; in make_idx_node()
85 c->calc_idx_sz += ALIGN(len, 8); in make_idx_node()
87 atomic_long_dec(&c->dirty_zn_cnt); in make_idx_node()
108 static int fill_gap(struct ubifs_info *c, int lnum, int gap_start, int gap_end, in fill_gap() argument
122 while (c->enext) { in fill_gap()
123 len = ubifs_idx_node_sz(c, c->enext->child_cnt); in fill_gap()
125 struct ubifs_znode *znode = c->enext; in fill_gap()
130 err = make_idx_node(c, c->ileb_buf + gap_pos, znode, in fill_gap()
136 c->enext = znode->cnext; in fill_gap()
137 if (c->enext == c->cnext) in fill_gap()
138 c->enext = NULL; in fill_gap()
143 if (gap_end == c->leb_size) { in fill_gap()
144 c->ileb_len = ALIGN(gap_pos, c->min_io_size); in fill_gap()
146 pad_len = c->ileb_len - gap_pos; in fill_gap()
152 ubifs_pad(c, c->ileb_buf + gap_pos, pad_len); in fill_gap()
165 static int find_old_idx(struct ubifs_info *c, int lnum, int offs) in find_old_idx() argument
170 p = c->old_idx.rb_node; in find_old_idx()
200 static int is_idx_node_in_use(struct ubifs_info *c, union ubifs_key *key, in is_idx_node_in_use() argument
205 ret = is_idx_node_in_tnc(c, key, level, lnum, offs); in is_idx_node_in_use()
209 if (find_old_idx(c, lnum, offs)) in is_idx_node_in_use()
226 static int layout_leb_in_gaps(struct ubifs_info *c, int *p) in layout_leb_in_gaps() argument
234 lnum = ubifs_find_dirty_idx_leb(c); in layout_leb_in_gaps()
248 sleb = ubifs_scan(c, lnum, 0, c->ileb_buf); in layout_leb_in_gaps()
249 c->ileb_len = 0; in layout_leb_in_gaps()
259 key_read(c, ubifs_idx_key(c, idx), &snod->key); in layout_leb_in_gaps()
262 in_use = is_idx_node_in_use(c, &snod->key, level, lnum, in layout_leb_in_gaps()
279 written = fill_gap(c, lnum, gap_start, gap_end, &dirt); in layout_leb_in_gaps()
289 c->ileb_len = c->leb_size; in layout_leb_in_gaps()
290 gap_end = c->leb_size; in layout_leb_in_gaps()
292 written = fill_gap(c, lnum, gap_start, gap_end, &dirt); in layout_leb_in_gaps()
300 err = ubifs_read_one_lp(c, lnum, &lp); in layout_leb_in_gaps()
303 if (lp.free == c->leb_size) { in layout_leb_in_gaps()
308 err = ubifs_change_one_lp(c, lnum, in layout_leb_in_gaps()
309 c->leb_size - c->ileb_len, in layout_leb_in_gaps()
316 err = ubifs_change_one_lp(c, lnum, c->leb_size - c->ileb_len, dirt, in layout_leb_in_gaps()
320 err = ubifs_leb_change(c, lnum, c->ileb_buf, c->ileb_len, in layout_leb_in_gaps()
337 static int get_leb_cnt(struct ubifs_info *c, int cnt) in get_leb_cnt() argument
342 cnt -= (c->leb_size - c->ihead_offs) / c->max_idx_node_sz; in get_leb_cnt()
345 d = c->leb_size / c->max_idx_node_sz; in get_leb_cnt()
359 static int layout_in_gaps(struct ubifs_info *c, int cnt) in layout_in_gaps() argument
365 c->gap_lebs = kmalloc(sizeof(int) * (c->lst.idx_lebs + 1), GFP_NOFS); in layout_in_gaps()
366 if (!c->gap_lebs) in layout_in_gaps()
369 p = c->gap_lebs; in layout_in_gaps()
371 ubifs_assert(p < c->gap_lebs + sizeof(int) * c->lst.idx_lebs); in layout_in_gaps()
372 written = layout_leb_in_gaps(c, p); in layout_in_gaps()
376 kfree(c->gap_lebs); in layout_in_gaps()
377 c->gap_lebs = NULL; in layout_in_gaps()
386 spin_lock(&c->space_lock); in layout_in_gaps()
387 dbg_dump_budg(c); in layout_in_gaps()
388 spin_unlock(&c->space_lock); in layout_in_gaps()
389 dbg_dump_lprops(c); in layout_in_gaps()
397 leb_needed_cnt = get_leb_cnt(c, cnt); in layout_in_gaps()
399 leb_needed_cnt, c->ileb_cnt); in layout_in_gaps()
400 } while (leb_needed_cnt > c->ileb_cnt); in layout_in_gaps()
414 static int layout_in_empty_space(struct ubifs_info *c) in layout_in_empty_space() argument
420 cnext = c->enext; in layout_in_empty_space()
424 lnum = c->ihead_lnum; in layout_in_empty_space()
425 buf_offs = c->ihead_offs; in layout_in_empty_space()
427 buf_len = ubifs_idx_node_sz(c, c->fanout); in layout_in_empty_space()
428 buf_len = ALIGN(buf_len, c->min_io_size); in layout_in_empty_space()
433 next_len = ubifs_idx_node_sz(c, cnext->child_cnt); in layout_in_empty_space()
434 if (buf_offs + next_len > c->leb_size) in layout_in_empty_space()
440 len = ubifs_idx_node_sz(c, znode->child_cnt); in layout_in_empty_space()
444 if (c->ileb_nxt >= c->ileb_cnt) { in layout_in_empty_space()
448 lnum = c->ilebs[c->ileb_nxt++]; in layout_in_empty_space()
474 c->zroot.lnum = lnum; in layout_in_empty_space()
475 c->zroot.offs = offs; in layout_in_empty_space()
476 c->zroot.len = len; in layout_in_empty_space()
478 c->calc_idx_sz += ALIGN(len, 8); in layout_in_empty_space()
484 atomic_long_dec(&c->dirty_zn_cnt); in layout_in_empty_space()
491 if (cnext == c->cnext) in layout_in_empty_space()
494 next_len = ubifs_idx_node_sz(c, cnext->child_cnt); in layout_in_empty_space()
496 if (c->min_io_size == 1) { in layout_in_empty_space()
499 if (buf_offs + next_len <= c->leb_size) in layout_in_empty_space()
501 err = ubifs_update_one_lp(c, lnum, 0, in layout_in_empty_space()
502 c->leb_size - buf_offs, 0, 0); in layout_in_empty_space()
508 err = ubifs_update_one_lp(c, lnum, in layout_in_empty_space()
509 c->leb_size - buf_offs, 0, 0, 0); in layout_in_empty_space()
521 buf_offs + used + next_len <= c->leb_size && in layout_in_empty_space()
526 buf_offs + used + next_len <= c->leb_size) in layout_in_empty_space()
529 blen = ALIGN(wlen, c->min_io_size); in layout_in_empty_space()
534 if (buf_offs + next_len > c->leb_size) { in layout_in_empty_space()
535 err = ubifs_update_one_lp(c, lnum, in layout_in_empty_space()
536 c->leb_size - buf_offs, blen - used, in layout_in_empty_space()
548 err = ubifs_update_one_lp(c, lnum, c->leb_size - buf_offs, in layout_in_empty_space()
556 c->dbg->new_ihead_lnum = lnum; in layout_in_empty_space()
557 c->dbg->new_ihead_offs = buf_offs; in layout_in_empty_space()
576 static int layout_commit(struct ubifs_info *c, int no_space, int cnt) in layout_commit() argument
581 err = layout_in_gaps(c, cnt); in layout_commit()
585 err = layout_in_empty_space(c); in layout_commit()
650 static int get_znodes_to_commit(struct ubifs_info *c) in get_znodes_to_commit() argument
655 c->cnext = find_first_dirty(c->zroot.znode); in get_znodes_to_commit()
656 znode = c->enext = c->cnext; in get_znodes_to_commit()
668 znode->cnext = c->cnext; in get_znodes_to_commit()
676 ubifs_assert(cnt == atomic_long_read(&c->dirty_zn_cnt)); in get_znodes_to_commit()
689 static int alloc_idx_lebs(struct ubifs_info *c, int cnt) in alloc_idx_lebs() argument
693 c->ileb_cnt = 0; in alloc_idx_lebs()
694 c->ileb_nxt = 0; in alloc_idx_lebs()
695 leb_cnt = get_leb_cnt(c, cnt); in alloc_idx_lebs()
699 c->ilebs = kmalloc(leb_cnt * sizeof(int), GFP_NOFS); in alloc_idx_lebs()
700 if (!c->ilebs) in alloc_idx_lebs()
703 lnum = ubifs_find_free_leb_for_idx(c); in alloc_idx_lebs()
706 c->ilebs[c->ileb_cnt++] = lnum; in alloc_idx_lebs()
723 static int free_unused_idx_lebs(struct ubifs_info *c) in free_unused_idx_lebs() argument
727 for (i = c->ileb_nxt; i < c->ileb_cnt; i++) { in free_unused_idx_lebs()
728 lnum = c->ilebs[i]; in free_unused_idx_lebs()
730 er = ubifs_change_one_lp(c, lnum, LPROPS_NC, LPROPS_NC, 0, in free_unused_idx_lebs()
744 static int free_idx_lebs(struct ubifs_info *c) in free_idx_lebs() argument
748 err = free_unused_idx_lebs(c); in free_idx_lebs()
749 kfree(c->ilebs); in free_idx_lebs()
750 c->ilebs = NULL; in free_idx_lebs()
764 int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot) in ubifs_tnc_start_commit() argument
768 mutex_lock(&c->tnc_mutex); in ubifs_tnc_start_commit()
769 err = dbg_check_tnc(c, 1); in ubifs_tnc_start_commit()
772 cnt = get_znodes_to_commit(c); in ubifs_tnc_start_commit()
776 err = alloc_idx_lebs(c, cnt); in ubifs_tnc_start_commit()
781 err = layout_commit(c, no_space, cnt); in ubifs_tnc_start_commit()
784 ubifs_assert(atomic_long_read(&c->dirty_zn_cnt) == 0); in ubifs_tnc_start_commit()
785 err = free_unused_idx_lebs(c); in ubifs_tnc_start_commit()
789 destroy_old_idx(c); in ubifs_tnc_start_commit()
790 memcpy(zroot, &c->zroot, sizeof(struct ubifs_zbranch)); in ubifs_tnc_start_commit()
792 err = ubifs_save_dirty_idx_lnums(c); in ubifs_tnc_start_commit()
796 spin_lock(&c->space_lock); in ubifs_tnc_start_commit()
805 ubifs_assert(c->min_idx_lebs == ubifs_calc_min_idx_lebs(c)); in ubifs_tnc_start_commit()
806 c->old_idx_sz = c->calc_idx_sz; in ubifs_tnc_start_commit()
807 c->budg_uncommitted_idx = 0; in ubifs_tnc_start_commit()
808 c->min_idx_lebs = ubifs_calc_min_idx_lebs(c); in ubifs_tnc_start_commit()
809 spin_unlock(&c->space_lock); in ubifs_tnc_start_commit()
810 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_start_commit()
812 dbg_cmt("number of index LEBs %d", c->lst.idx_lebs); in ubifs_tnc_start_commit()
813 dbg_cmt("size of index %llu", c->calc_idx_sz); in ubifs_tnc_start_commit()
817 free_idx_lebs(c); in ubifs_tnc_start_commit()
819 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_start_commit()
830 static int write_index(struct ubifs_info *c) in write_index() argument
837 cnext = c->enext; in write_index()
845 lnum = c->ihead_lnum; in write_index()
846 buf_offs = c->ihead_offs; in write_index()
849 buf_len = ALIGN(c->max_idx_node_sz, c->min_io_size); in write_index()
854 next_len = ubifs_idx_node_sz(c, cnext->child_cnt); in write_index()
855 if (buf_offs + next_len > c->leb_size) { in write_index()
856 err = ubifs_update_one_lp(c, lnum, LPROPS_NC, 0, 0, in write_index()
867 idx = c->cbuf + used; in write_index()
874 struct ubifs_branch *br = ubifs_idx_branch(c, idx, i); in write_index()
877 key_write_idx(c, &zbr->key, &br->key); in write_index()
883 dbg_dump_znode(c, znode); in write_index()
885 dbg_dump_znode(c, zbr->znode); in write_index()
888 len = ubifs_idx_node_sz(c, znode->child_cnt); in write_index()
889 ubifs_prepare_node(c, idx, len, 0); in write_index()
893 lnum = c->ilebs[lnum_pos++]; in write_index()
938 if (cnext == c->cnext) in write_index()
941 next_len = ubifs_idx_node_sz(c, cnext->child_cnt); in write_index()
943 if (c->min_io_size == 1) { in write_index()
948 err = ubifs_leb_write(c, lnum, c->cbuf, buf_offs, in write_index()
956 if (buf_offs + next_len > c->leb_size) { in write_index()
957 err = ubifs_update_one_lp(c, lnum, in write_index()
968 if (next_len && nxt_offs <= c->leb_size) { in write_index()
975 blen = ALIGN(wlen, c->min_io_size); in write_index()
976 ubifs_pad(c, c->cbuf + wlen, blen - wlen); in write_index()
982 err = ubifs_leb_write(c, lnum, c->cbuf, buf_offs, in write_index()
988 if (nxt_offs > c->leb_size) { in write_index()
989 err = ubifs_update_one_lp(c, lnum, in write_index()
999 memmove(c->cbuf, c->cbuf + blen, used); in write_index()
1007 if (lnum != c->dbg->new_ihead_lnum || in write_index()
1008 buf_offs != c->dbg->new_ihead_offs) { in write_index()
1014 c->ihead_lnum = lnum; in write_index()
1015 c->ihead_offs = buf_offs; in write_index()
1026 static void free_obsolete_znodes(struct ubifs_info *c) in free_obsolete_znodes() argument
1030 cnext = c->cnext; in free_obsolete_znodes()
1038 atomic_long_inc(&c->clean_zn_cnt); in free_obsolete_znodes()
1041 } while (cnext != c->cnext); in free_obsolete_znodes()
1051 static int return_gap_lebs(struct ubifs_info *c) in return_gap_lebs() argument
1055 if (!c->gap_lebs) in return_gap_lebs()
1059 for (p = c->gap_lebs; *p != -1; p++) { in return_gap_lebs()
1060 err = ubifs_change_one_lp(c, *p, LPROPS_NC, LPROPS_NC, 0, in return_gap_lebs()
1066 kfree(c->gap_lebs); in return_gap_lebs()
1067 c->gap_lebs = NULL; in return_gap_lebs()
1077 int ubifs_tnc_end_commit(struct ubifs_info *c) in ubifs_tnc_end_commit() argument
1081 if (!c->cnext) in ubifs_tnc_end_commit()
1084 err = return_gap_lebs(c); in ubifs_tnc_end_commit()
1088 err = write_index(c); in ubifs_tnc_end_commit()
1092 mutex_lock(&c->tnc_mutex); in ubifs_tnc_end_commit()
1094 dbg_cmt("TNC height is %d", c->zroot.znode->level + 1); in ubifs_tnc_end_commit()
1096 free_obsolete_znodes(c); in ubifs_tnc_end_commit()
1098 c->cnext = NULL; in ubifs_tnc_end_commit()
1099 kfree(c->ilebs); in ubifs_tnc_end_commit()
1100 c->ilebs = NULL; in ubifs_tnc_end_commit()
1102 mutex_unlock(&c->tnc_mutex); in ubifs_tnc_end_commit()