Lines Matching refs:c

91 static int set_bud_lprops(struct ubifs_info *c, struct bud_entry *b)  in set_bud_lprops()  argument
96 ubifs_get_lprops(c); in set_bud_lprops()
98 lp = ubifs_lpt_lookup_dirty(c, b->bud->lnum); in set_bud_lprops()
105 if (b->bud->start == 0 && (lp->free != c->leb_size || lp->dirty != 0)) { in set_bud_lprops()
129 dirty -= c->leb_size - lp->free; in set_bud_lprops()
142 lp = ubifs_change_lp(c, lp, b->free, dirty + b->dirty, in set_bud_lprops()
150 err = ubifs_wbuf_seek_nolock(&c->jheads[b->bud->jhead].wbuf, in set_bud_lprops()
151 b->bud->lnum, c->leb_size - b->free); in set_bud_lprops()
154 ubifs_release_lprops(c); in set_bud_lprops()
165 static int set_buds_lprops(struct ubifs_info *c) in set_buds_lprops() argument
170 list_for_each_entry(b, &c->replay_buds, list) { in set_buds_lprops()
171 err = set_bud_lprops(c, b); in set_buds_lprops()
184 static int trun_remove_range(struct ubifs_info *c, struct replay_entry *r) in trun_remove_range() argument
198 ino = key_inum(c, &r->key); in trun_remove_range()
200 data_key_init(c, &min_key, ino, min_blk); in trun_remove_range()
201 data_key_init(c, &max_key, ino, max_blk); in trun_remove_range()
203 return ubifs_tnc_remove_range(c, &min_key, &max_key); in trun_remove_range()
213 static int apply_replay_entry(struct ubifs_info *c, struct replay_entry *r) in apply_replay_entry() argument
221 c->replay_sqnum = r->sqnum; in apply_replay_entry()
223 if (is_hash_key(c, &r->key)) { in apply_replay_entry()
225 err = ubifs_tnc_remove_nm(c, &r->key, &r->nm); in apply_replay_entry()
227 err = ubifs_tnc_add_nm(c, &r->key, r->lnum, r->offs, in apply_replay_entry()
231 switch (key_type(c, &r->key)) { in apply_replay_entry()
234 ino_t inum = key_inum(c, &r->key); in apply_replay_entry()
236 err = ubifs_tnc_remove_ino(c, inum); in apply_replay_entry()
240 err = trun_remove_range(c, r); in apply_replay_entry()
243 err = ubifs_tnc_remove(c, &r->key); in apply_replay_entry()
247 err = ubifs_tnc_add(c, &r->key, r->lnum, r->offs, in apply_replay_entry()
252 if (c->need_recovery) in apply_replay_entry()
253 err = ubifs_recover_size_accum(c, &r->key, r->deletion, in apply_replay_entry()
294 static int apply_replay_list(struct ubifs_info *c) in apply_replay_list() argument
299 list_sort(c, &c->replay_list, &replay_entries_cmp); in apply_replay_list()
301 list_for_each_entry(r, &c->replay_list, list) { in apply_replay_list()
304 err = apply_replay_entry(c, r); in apply_replay_list()
318 static void destroy_replay_list(struct ubifs_info *c) in destroy_replay_list() argument
322 list_for_each_entry_safe(r, tmp, &c->replay_list, list) { in destroy_replay_list()
323 if (is_hash_key(c, &r->key)) in destroy_replay_list()
350 static int insert_node(struct ubifs_info *c, int lnum, int offs, int len, in insert_node() argument
359 if (key_inum(c, key) >= c->highest_inum) in insert_node()
360 c->highest_inum = key_inum(c, key); in insert_node()
373 key_copy(c, key, &r->key); in insert_node()
377 list_add_tail(&r->list, &c->replay_list); in insert_node()
398 static int insert_dent(struct ubifs_info *c, int lnum, int offs, int len, in insert_dent() argument
406 if (key_inum(c, key) >= c->highest_inum) in insert_dent()
407 c->highest_inum = key_inum(c, key); in insert_dent()
426 key_copy(c, key, &r->key); in insert_dent()
432 list_add_tail(&r->list, &c->replay_list); in insert_dent()
444 int ubifs_validate_entry(struct ubifs_info *c, in ubifs_validate_entry() argument
447 int key_type = key_type_flash(c, dent->key); in ubifs_validate_entry()
455 ubifs_err(c, "bad %s node", key_type == UBIFS_DENT_KEY ? in ubifs_validate_entry()
461 ubifs_err(c, "bad key type %d", key_type); in ubifs_validate_entry()
478 static int is_last_bud(struct ubifs_info *c, struct ubifs_bud *bud) in is_last_bud() argument
480 struct ubifs_jhead *jh = &c->jheads[bud->jhead]; in is_last_bud()
519 err = ubifs_leb_read(c, next->lnum, (char *)&data, next->start, 4, 1); in is_last_bud()
535 static int replay_bud(struct ubifs_info *c, struct bud_entry *b) in replay_bud() argument
537 int is_last = is_last_bud(c, b->bud); in replay_bud()
545 if (c->need_recovery && is_last) in replay_bud()
552 sleb = ubifs_recover_leb(c, lnum, offs, c->sbuf, b->bud->jhead); in replay_bud()
554 sleb = ubifs_scan(c, lnum, offs, c->sbuf, 0); in replay_bud()
586 ubifs_err(c, "file system's life ended"); in replay_bud()
590 if (snod->sqnum > c->max_sqnum) in replay_bud()
591 c->max_sqnum = snod->sqnum; in replay_bud()
601 err = insert_node(c, lnum, snod->offs, snod->len, in replay_bud()
610 key_block(c, &snod->key) * in replay_bud()
613 err = insert_node(c, lnum, snod->offs, snod->len, in replay_bud()
623 err = ubifs_validate_entry(c, dent); in replay_bud()
627 err = insert_dent(c, lnum, snod->offs, snod->len, in replay_bud()
641 if (old_size < 0 || old_size > c->max_inode_sz || in replay_bud()
642 new_size < 0 || new_size > c->max_inode_sz || in replay_bud()
644 ubifs_err(c, "bad truncation node"); in replay_bud()
652 trun_key_init(c, &key, le32_to_cpu(trun->inum)); in replay_bud()
653 err = insert_node(c, lnum, snod->offs, snod->len, in replay_bud()
659 ubifs_err(c, "unexpected node type %d in bud LEB %d:%d", in replay_bud()
668 ubifs_assert(ubifs_search_bud(c, lnum)); in replay_bud()
670 ubifs_assert(sleb->endpt % c->min_io_size == 0); in replay_bud()
673 b->free = c->leb_size - sleb->endpt; in replay_bud()
682 ubifs_err(c, "bad node is at LEB %d:%d", lnum, snod->offs); in replay_bud()
683 ubifs_dump_node(c, snod->node); in replay_bud()
695 static int replay_buds(struct ubifs_info *c) in replay_buds() argument
701 list_for_each_entry(b, &c->replay_buds, list) { in replay_buds()
702 err = replay_bud(c, b); in replay_buds()
717 static void destroy_bud_list(struct ubifs_info *c) in destroy_bud_list() argument
721 while (!list_empty(&c->replay_buds)) { in destroy_bud_list()
722 b = list_entry(c->replay_buds.next, struct bud_entry, list); in destroy_bud_list()
739 static int add_replay_bud(struct ubifs_info *c, int lnum, int offs, int jhead, in add_replay_bud() argument
760 ubifs_add_bud(c, bud); in add_replay_bud()
764 list_add_tail(&b->list, &c->replay_buds); in add_replay_bud()
780 static int validate_ref(struct ubifs_info *c, const struct ubifs_ref_node *ref) in validate_ref() argument
792 if (jhead >= c->jhead_cnt || lnum >= c->leb_cnt || in validate_ref()
793 lnum < c->main_first || offs > c->leb_size || in validate_ref()
794 offs & (c->min_io_size - 1)) in validate_ref()
798 bud = ubifs_search_bud(c, lnum); in validate_ref()
802 ubifs_err(c, "bud at LEB %d:%d was already referred", lnum, offs); in validate_ref()
820 static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf) in replay_log_leb() argument
828 sleb = ubifs_scan(c, lnum, offs, sbuf, c->need_recovery); in replay_log_leb()
830 if (PTR_ERR(sleb) != -EUCLEAN || !c->need_recovery) in replay_log_leb()
837 sleb = ubifs_recover_log_leb(c, lnum, offs, sbuf); in replay_log_leb()
849 if (c->cs_sqnum == 0) { in replay_log_leb()
858 ubifs_err(c, "first log node at LEB %d:%d is not CS node", in replay_log_leb()
862 if (le64_to_cpu(node->cmt_no) != c->cmt_no) { in replay_log_leb()
863 ubifs_err(c, "first CS node at LEB %d:%d has wrong commit number %llu expected %llu", in replay_log_leb()
866 c->cmt_no); in replay_log_leb()
870 c->cs_sqnum = le64_to_cpu(node->ch.sqnum); in replay_log_leb()
871 dbg_mnt("commit start sqnum %llu", c->cs_sqnum); in replay_log_leb()
874 if (snod->sqnum < c->cs_sqnum) { in replay_log_leb()
888 ubifs_err(c, "first node is not at zero offset"); in replay_log_leb()
896 ubifs_err(c, "file system's life ended"); in replay_log_leb()
900 if (snod->sqnum < c->cs_sqnum) { in replay_log_leb()
901 ubifs_err(c, "bad sqnum %llu, commit sqnum %llu", in replay_log_leb()
902 snod->sqnum, c->cs_sqnum); in replay_log_leb()
906 if (snod->sqnum > c->max_sqnum) in replay_log_leb()
907 c->max_sqnum = snod->sqnum; in replay_log_leb()
913 err = validate_ref(c, ref); in replay_log_leb()
919 err = add_replay_bud(c, le32_to_cpu(ref->lnum), in replay_log_leb()
931 ubifs_err(c, "unexpected node in log"); in replay_log_leb()
936 ubifs_err(c, "unexpected node in log"); in replay_log_leb()
941 if (sleb->endpt || c->lhead_offs >= c->leb_size) { in replay_log_leb()
942 c->lhead_lnum = lnum; in replay_log_leb()
943 c->lhead_offs = sleb->endpt; in replay_log_leb()
952 ubifs_err(c, "log error detected while replaying the log at LEB %d:%d", in replay_log_leb()
954 ubifs_dump_node(c, snod->node); in replay_log_leb()
966 static int take_ihead(struct ubifs_info *c) in take_ihead() argument
971 ubifs_get_lprops(c); in take_ihead()
973 lp = ubifs_lpt_lookup_dirty(c, c->ihead_lnum); in take_ihead()
981 lp = ubifs_change_lp(c, lp, LPROPS_NC, LPROPS_NC, in take_ihead()
990 ubifs_release_lprops(c); in take_ihead()
1002 int ubifs_replay_journal(struct ubifs_info *c) in ubifs_replay_journal() argument
1009 free = take_ihead(c); in ubifs_replay_journal()
1013 if (c->ihead_offs != c->leb_size - free) { in ubifs_replay_journal()
1014 ubifs_err(c, "bad index head LEB %d:%d", c->ihead_lnum, in ubifs_replay_journal()
1015 c->ihead_offs); in ubifs_replay_journal()
1020 c->replaying = 1; in ubifs_replay_journal()
1021 lnum = c->ltail_lnum = c->lhead_lnum; in ubifs_replay_journal()
1024 err = replay_log_leb(c, lnum, 0, c->sbuf); in ubifs_replay_journal()
1026 if (lnum != c->lhead_lnum) in ubifs_replay_journal()
1037 ubifs_err(c, "no UBIFS nodes found at the log head LEB %d:%d, possibly corrupted", in ubifs_replay_journal()
1043 lnum = ubifs_next_log_lnum(c, lnum); in ubifs_replay_journal()
1044 } while (lnum != c->ltail_lnum); in ubifs_replay_journal()
1046 err = replay_buds(c); in ubifs_replay_journal()
1050 err = apply_replay_list(c); in ubifs_replay_journal()
1054 err = set_buds_lprops(c); in ubifs_replay_journal()
1064 c->bi.uncommitted_idx = atomic_long_read(&c->dirty_zn_cnt); in ubifs_replay_journal()
1065 c->bi.uncommitted_idx *= c->max_idx_node_sz; in ubifs_replay_journal()
1067 ubifs_assert(c->bud_bytes <= c->max_bud_bytes || c->need_recovery); in ubifs_replay_journal()
1069 c->lhead_lnum, c->lhead_offs, c->max_sqnum, in ubifs_replay_journal()
1070 (unsigned long)c->highest_inum); in ubifs_replay_journal()
1072 destroy_replay_list(c); in ubifs_replay_journal()
1073 destroy_bud_list(c); in ubifs_replay_journal()
1074 c->replaying = 0; in ubifs_replay_journal()