Lines Matching refs:c

97 static int set_bud_lprops(struct ubifs_info *c, struct bud_entry *b)  in set_bud_lprops()  argument
102 ubifs_get_lprops(c); in set_bud_lprops()
104 lp = ubifs_lpt_lookup_dirty(c, b->bud->lnum); in set_bud_lprops()
111 if (b->bud->start == 0 && (lp->free != c->leb_size || lp->dirty != 0)) { in set_bud_lprops()
135 dirty -= c->leb_size - lp->free; in set_bud_lprops()
148 lp = ubifs_change_lp(c, lp, b->free, dirty + b->dirty, in set_bud_lprops()
156 err = ubifs_wbuf_seek_nolock(&c->jheads[b->bud->jhead].wbuf, in set_bud_lprops()
157 b->bud->lnum, c->leb_size - b->free); in set_bud_lprops()
160 ubifs_release_lprops(c); in set_bud_lprops()
171 static int set_buds_lprops(struct ubifs_info *c) in set_buds_lprops() argument
176 list_for_each_entry(b, &c->replay_buds, list) { in set_buds_lprops()
177 err = set_bud_lprops(c, b); in set_buds_lprops()
190 static int trun_remove_range(struct ubifs_info *c, struct replay_entry *r) in trun_remove_range() argument
204 ino = key_inum(c, &r->key); in trun_remove_range()
206 data_key_init(c, &min_key, ino, min_blk); in trun_remove_range()
207 data_key_init(c, &max_key, ino, max_blk); in trun_remove_range()
209 return ubifs_tnc_remove_range(c, &min_key, &max_key); in trun_remove_range()
219 static int apply_replay_entry(struct ubifs_info *c, struct replay_entry *r) in apply_replay_entry() argument
227 c->replay_sqnum = r->sqnum; in apply_replay_entry()
229 if (is_hash_key(c, &r->key)) { in apply_replay_entry()
231 err = ubifs_tnc_remove_nm(c, &r->key, &r->nm); in apply_replay_entry()
233 err = ubifs_tnc_add_nm(c, &r->key, r->lnum, r->offs, in apply_replay_entry()
237 switch (key_type(c, &r->key)) { in apply_replay_entry()
240 ino_t inum = key_inum(c, &r->key); in apply_replay_entry()
242 err = ubifs_tnc_remove_ino(c, inum); in apply_replay_entry()
246 err = trun_remove_range(c, r); in apply_replay_entry()
249 err = ubifs_tnc_remove(c, &r->key); in apply_replay_entry()
253 err = ubifs_tnc_add(c, &r->key, r->lnum, r->offs, in apply_replay_entry()
258 if (c->need_recovery) in apply_replay_entry()
259 err = ubifs_recover_size_accum(c, &r->key, r->deletion, in apply_replay_entry()
300 static int apply_replay_list(struct ubifs_info *c) in apply_replay_list() argument
305 list_sort(c, &c->replay_list, &replay_entries_cmp); in apply_replay_list()
307 list_for_each_entry(r, &c->replay_list, list) { in apply_replay_list()
310 err = apply_replay_entry(c, r); in apply_replay_list()
324 static void destroy_replay_list(struct ubifs_info *c) in destroy_replay_list() argument
328 list_for_each_entry_safe(r, tmp, &c->replay_list, list) { in destroy_replay_list()
329 if (is_hash_key(c, &r->key)) in destroy_replay_list()
356 static int insert_node(struct ubifs_info *c, int lnum, int offs, int len, in insert_node() argument
365 if (key_inum(c, key) >= c->highest_inum) in insert_node()
366 c->highest_inum = key_inum(c, key); in insert_node()
379 key_copy(c, key, &r->key); in insert_node()
383 list_add_tail(&r->list, &c->replay_list); in insert_node()
404 static int insert_dent(struct ubifs_info *c, int lnum, int offs, int len, in insert_dent() argument
412 if (key_inum(c, key) >= c->highest_inum) in insert_dent()
413 c->highest_inum = key_inum(c, key); in insert_dent()
432 key_copy(c, key, &r->key); in insert_dent()
438 list_add_tail(&r->list, &c->replay_list); in insert_dent()
450 int ubifs_validate_entry(struct ubifs_info *c, in ubifs_validate_entry() argument
453 int key_type = key_type_flash(c, dent->key); in ubifs_validate_entry()
461 ubifs_err(c, "bad %s node", key_type == UBIFS_DENT_KEY ? in ubifs_validate_entry()
467 ubifs_err(c, "bad key type %d", key_type); in ubifs_validate_entry()
484 static int is_last_bud(struct ubifs_info *c, struct ubifs_bud *bud) in is_last_bud() argument
486 struct ubifs_jhead *jh = &c->jheads[bud->jhead]; in is_last_bud()
525 err = ubifs_leb_read(c, next->lnum, (char *)&data, next->start, 4, 1); in is_last_bud()
541 static int replay_bud(struct ubifs_info *c, struct bud_entry *b) in replay_bud() argument
543 int is_last = is_last_bud(c, b->bud); in replay_bud()
551 if (c->need_recovery && is_last) in replay_bud()
558 sleb = ubifs_recover_leb(c, lnum, offs, c->sbuf, b->bud->jhead); in replay_bud()
560 sleb = ubifs_scan(c, lnum, offs, c->sbuf, 0); in replay_bud()
592 ubifs_err(c, "file system's life ended"); in replay_bud()
596 if (snod->sqnum > c->max_sqnum) in replay_bud()
597 c->max_sqnum = snod->sqnum; in replay_bud()
607 err = insert_node(c, lnum, snod->offs, snod->len, in replay_bud()
616 key_block(c, &snod->key) * in replay_bud()
619 err = insert_node(c, lnum, snod->offs, snod->len, in replay_bud()
629 err = ubifs_validate_entry(c, dent); in replay_bud()
633 err = insert_dent(c, lnum, snod->offs, snod->len, in replay_bud()
647 if (old_size < 0 || old_size > c->max_inode_sz || in replay_bud()
648 new_size < 0 || new_size > c->max_inode_sz || in replay_bud()
650 ubifs_err(c, "bad truncation node"); in replay_bud()
658 trun_key_init(c, &key, le32_to_cpu(trun->inum)); in replay_bud()
659 err = insert_node(c, lnum, snod->offs, snod->len, in replay_bud()
665 ubifs_err(c, "unexpected node type %d in bud LEB %d:%d", in replay_bud()
674 ubifs_assert(ubifs_search_bud(c, lnum)); in replay_bud()
676 ubifs_assert(sleb->endpt % c->min_io_size == 0); in replay_bud()
679 b->free = c->leb_size - sleb->endpt; in replay_bud()
688 ubifs_err(c, "bad node is at LEB %d:%d", lnum, snod->offs); in replay_bud()
689 ubifs_dump_node(c, snod->node); in replay_bud()
701 static int replay_buds(struct ubifs_info *c) in replay_buds() argument
707 list_for_each_entry(b, &c->replay_buds, list) { in replay_buds()
708 err = replay_bud(c, b); in replay_buds()
723 static void destroy_bud_list(struct ubifs_info *c) in destroy_bud_list() argument
727 while (!list_empty(&c->replay_buds)) { in destroy_bud_list()
728 b = list_entry(c->replay_buds.next, struct bud_entry, list); in destroy_bud_list()
745 static int add_replay_bud(struct ubifs_info *c, int lnum, int offs, int jhead, in add_replay_bud() argument
766 ubifs_add_bud(c, bud); in add_replay_bud()
770 list_add_tail(&b->list, &c->replay_buds); in add_replay_bud()
786 static int validate_ref(struct ubifs_info *c, const struct ubifs_ref_node *ref) in validate_ref() argument
798 if (jhead >= c->jhead_cnt || lnum >= c->leb_cnt || in validate_ref()
799 lnum < c->main_first || offs > c->leb_size || in validate_ref()
800 offs & (c->min_io_size - 1)) in validate_ref()
804 bud = ubifs_search_bud(c, lnum); in validate_ref()
808 ubifs_err(c, "bud at LEB %d:%d was already referred", lnum, offs); in validate_ref()
826 static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf) in replay_log_leb() argument
834 sleb = ubifs_scan(c, lnum, offs, sbuf, c->need_recovery); in replay_log_leb()
836 if (PTR_ERR(sleb) != -EUCLEAN || !c->need_recovery) in replay_log_leb()
843 sleb = ubifs_recover_log_leb(c, lnum, offs, sbuf); in replay_log_leb()
855 if (c->cs_sqnum == 0) { in replay_log_leb()
864 ubifs_err(c, "first log node at LEB %d:%d is not CS node", in replay_log_leb()
868 if (le64_to_cpu(node->cmt_no) != c->cmt_no) { in replay_log_leb()
869 ubifs_err(c, "first CS node at LEB %d:%d has wrong commit number %llu expected %llu", in replay_log_leb()
872 c->cmt_no); in replay_log_leb()
876 c->cs_sqnum = le64_to_cpu(node->ch.sqnum); in replay_log_leb()
877 dbg_mnt("commit start sqnum %llu", c->cs_sqnum); in replay_log_leb()
880 if (snod->sqnum < c->cs_sqnum) { in replay_log_leb()
894 ubifs_err(c, "first node is not at zero offset"); in replay_log_leb()
902 ubifs_err(c, "file system's life ended"); in replay_log_leb()
906 if (snod->sqnum < c->cs_sqnum) { in replay_log_leb()
907 ubifs_err(c, "bad sqnum %llu, commit sqnum %llu", in replay_log_leb()
908 snod->sqnum, c->cs_sqnum); in replay_log_leb()
912 if (snod->sqnum > c->max_sqnum) in replay_log_leb()
913 c->max_sqnum = snod->sqnum; in replay_log_leb()
919 err = validate_ref(c, ref); in replay_log_leb()
925 err = add_replay_bud(c, le32_to_cpu(ref->lnum), in replay_log_leb()
937 ubifs_err(c, "unexpected node in log"); in replay_log_leb()
942 ubifs_err(c, "unexpected node in log"); in replay_log_leb()
947 if (sleb->endpt || c->lhead_offs >= c->leb_size) { in replay_log_leb()
948 c->lhead_lnum = lnum; in replay_log_leb()
949 c->lhead_offs = sleb->endpt; in replay_log_leb()
958 ubifs_err(c, "log error detected while replaying the log at LEB %d:%d", in replay_log_leb()
960 ubifs_dump_node(c, snod->node); in replay_log_leb()
972 static int take_ihead(struct ubifs_info *c) in take_ihead() argument
977 ubifs_get_lprops(c); in take_ihead()
979 lp = ubifs_lpt_lookup_dirty(c, c->ihead_lnum); in take_ihead()
987 lp = ubifs_change_lp(c, lp, LPROPS_NC, LPROPS_NC, in take_ihead()
996 ubifs_release_lprops(c); in take_ihead()
1008 int ubifs_replay_journal(struct ubifs_info *c) in ubifs_replay_journal() argument
1015 free = take_ihead(c); in ubifs_replay_journal()
1019 if (c->ihead_offs != c->leb_size - free) { in ubifs_replay_journal()
1020 ubifs_err(c, "bad index head LEB %d:%d", c->ihead_lnum, in ubifs_replay_journal()
1021 c->ihead_offs); in ubifs_replay_journal()
1026 c->replaying = 1; in ubifs_replay_journal()
1027 lnum = c->ltail_lnum = c->lhead_lnum; in ubifs_replay_journal()
1030 err = replay_log_leb(c, lnum, 0, c->sbuf); in ubifs_replay_journal()
1032 if (lnum != c->lhead_lnum) in ubifs_replay_journal()
1043 ubifs_err(c, "no UBIFS nodes found at the log head LEB %d:%d, possibly corrupted", in ubifs_replay_journal()
1049 lnum = ubifs_next_log_lnum(c, lnum); in ubifs_replay_journal()
1050 } while (lnum != c->ltail_lnum); in ubifs_replay_journal()
1052 err = replay_buds(c); in ubifs_replay_journal()
1056 err = apply_replay_list(c); in ubifs_replay_journal()
1060 err = set_buds_lprops(c); in ubifs_replay_journal()
1070 c->bi.uncommitted_idx = atomic_long_read(&c->dirty_zn_cnt); in ubifs_replay_journal()
1071 c->bi.uncommitted_idx *= c->max_idx_node_sz; in ubifs_replay_journal()
1073 ubifs_assert(c->bud_bytes <= c->max_bud_bytes || c->need_recovery); in ubifs_replay_journal()
1075 c->lhead_lnum, c->lhead_offs, c->max_sqnum, in ubifs_replay_journal()
1076 (unsigned long)c->highest_inum); in ubifs_replay_journal()
1078 destroy_replay_list(c); in ubifs_replay_journal()
1079 destroy_bud_list(c); in ubifs_replay_journal()
1080 c->replaying = 0; in ubifs_replay_journal()