Lines Matching refs:c
33 static int dbg_check_bud_bytes(struct ubifs_info *c);
35 #define dbg_check_bud_bytes(c) 0 argument
46 struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum) in ubifs_search_bud() argument
51 spin_lock(&c->buds_lock); in ubifs_search_bud()
52 p = c->buds.rb_node; in ubifs_search_bud()
60 spin_unlock(&c->buds_lock); in ubifs_search_bud()
64 spin_unlock(&c->buds_lock); in ubifs_search_bud()
75 struct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum) in ubifs_get_wbuf() argument
81 if (!c->jheads) in ubifs_get_wbuf()
84 spin_lock(&c->buds_lock); in ubifs_get_wbuf()
85 p = c->buds.rb_node; in ubifs_get_wbuf()
94 spin_unlock(&c->buds_lock); in ubifs_get_wbuf()
95 return &c->jheads[jhead].wbuf; in ubifs_get_wbuf()
98 spin_unlock(&c->buds_lock); in ubifs_get_wbuf()
107 static inline int next_log_lnum(const struct ubifs_info *c, int lnum) in next_log_lnum() argument
110 if (lnum > c->log_last) in next_log_lnum()
120 static inline long long empty_log_bytes(const struct ubifs_info *c) in empty_log_bytes() argument
124 h = (long long)c->lhead_lnum * c->leb_size + c->lhead_offs; in empty_log_bytes()
125 t = (long long)c->ltail_lnum * c->leb_size; in empty_log_bytes()
128 return c->log_bytes - h + t; in empty_log_bytes()
138 void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud) in ubifs_add_bud() argument
144 spin_lock(&c->buds_lock); in ubifs_add_bud()
145 p = &c->buds.rb_node; in ubifs_add_bud()
157 rb_insert_color(&bud->rb, &c->buds); in ubifs_add_bud()
158 if (c->jheads) { in ubifs_add_bud()
159 jhead = &c->jheads[bud->jhead]; in ubifs_add_bud()
162 ubifs_assert(c->replaying && (c->vfs_sb->s_flags & MS_RDONLY)); in ubifs_add_bud()
170 c->bud_bytes += c->leb_size - bud->start; in ubifs_add_bud()
173 bud->start, bud->jhead, c->bud_bytes); in ubifs_add_bud()
174 spin_unlock(&c->buds_lock); in ubifs_add_bud()
181 void ubifs_create_buds_lists(struct ubifs_info *c) in ubifs_create_buds_lists() argument
185 spin_lock(&c->buds_lock); in ubifs_create_buds_lists()
186 p = rb_first(&c->buds); in ubifs_create_buds_lists()
189 struct ubifs_jhead *jhead = &c->jheads[bud->jhead]; in ubifs_create_buds_lists()
194 spin_unlock(&c->buds_lock); in ubifs_create_buds_lists()
210 int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs) in ubifs_add_bud_to_log() argument
219 ref = kzalloc(c->ref_node_alsz, GFP_NOFS); in ubifs_add_bud_to_log()
225 mutex_lock(&c->log_mutex); in ubifs_add_bud_to_log()
227 if (c->ro_media) { in ubifs_add_bud_to_log()
233 if (empty_log_bytes(c) - c->ref_node_alsz < c->min_log_bytes) { in ubifs_add_bud_to_log()
235 empty_log_bytes(c), c->min_log_bytes); in ubifs_add_bud_to_log()
236 ubifs_commit_required(c); in ubifs_add_bud_to_log()
250 if (c->bud_bytes + c->leb_size - offs > c->max_bud_bytes) { in ubifs_add_bud_to_log()
252 c->bud_bytes, c->max_bud_bytes); in ubifs_add_bud_to_log()
253 ubifs_commit_required(c); in ubifs_add_bud_to_log()
263 if (c->bud_bytes >= c->bg_bud_bytes && in ubifs_add_bud_to_log()
264 c->cmt_state == COMMIT_RESTING) { in ubifs_add_bud_to_log()
266 c->bud_bytes, c->max_bud_bytes); in ubifs_add_bud_to_log()
267 ubifs_request_bg_commit(c); in ubifs_add_bud_to_log()
279 if (c->lhead_offs > c->leb_size - c->ref_node_alsz) { in ubifs_add_bud_to_log()
280 c->lhead_lnum = next_log_lnum(c, c->lhead_lnum); in ubifs_add_bud_to_log()
281 c->lhead_offs = 0; in ubifs_add_bud_to_log()
284 if (c->lhead_offs == 0) { in ubifs_add_bud_to_log()
286 err = ubifs_leb_unmap(c, c->lhead_lnum); in ubifs_add_bud_to_log()
299 err = ubi_leb_map(c->ubi, bud->lnum, UBI_SHORTTERM); in ubifs_add_bud_to_log()
305 c->lhead_lnum, c->lhead_offs); in ubifs_add_bud_to_log()
306 err = ubifs_write_node(c, ref, UBIFS_REF_NODE_SZ, c->lhead_lnum, in ubifs_add_bud_to_log()
307 c->lhead_offs, UBI_SHORTTERM); in ubifs_add_bud_to_log()
311 c->lhead_offs += c->ref_node_alsz; in ubifs_add_bud_to_log()
313 ubifs_add_bud(c, bud); in ubifs_add_bud_to_log()
315 mutex_unlock(&c->log_mutex); in ubifs_add_bud_to_log()
321 ubifs_ro_mode(c, err); in ubifs_add_bud_to_log()
322 mutex_unlock(&c->log_mutex); in ubifs_add_bud_to_log()
335 static void remove_buds(struct ubifs_info *c) in remove_buds() argument
339 ubifs_assert(list_empty(&c->old_buds)); in remove_buds()
340 c->cmt_bud_bytes = 0; in remove_buds()
341 spin_lock(&c->buds_lock); in remove_buds()
342 p = rb_first(&c->buds); in remove_buds()
350 wbuf = &c->jheads[bud->jhead].wbuf; in remove_buds()
357 c->cmt_bud_bytes += wbuf->offs - bud->start; in remove_buds()
361 c->cmt_bud_bytes); in remove_buds()
364 c->cmt_bud_bytes += c->leb_size - bud->start; in remove_buds()
367 bud->jhead, c->leb_size - bud->start, in remove_buds()
368 c->cmt_bud_bytes); in remove_buds()
369 rb_erase(p1, &c->buds); in remove_buds()
378 list_add(&bud->list, &c->old_buds); in remove_buds()
381 spin_unlock(&c->buds_lock); in remove_buds()
397 int ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum) in ubifs_log_start_commit() argument
404 err = dbg_check_bud_bytes(c); in ubifs_log_start_commit()
408 max_len = UBIFS_CS_NODE_SZ + c->jhead_cnt * UBIFS_REF_NODE_SZ; in ubifs_log_start_commit()
409 max_len = ALIGN(max_len, c->min_io_size); in ubifs_log_start_commit()
415 cs->cmt_no = cpu_to_le64(c->cmt_no); in ubifs_log_start_commit()
416 ubifs_prepare_node(c, cs, UBIFS_CS_NODE_SZ, 0); in ubifs_log_start_commit()
426 for (i = 0; i < c->jhead_cnt; i++) { in ubifs_log_start_commit()
427 int lnum = c->jheads[i].wbuf.lnum; in ubifs_log_start_commit()
428 int offs = c->jheads[i].wbuf.offs; in ubifs_log_start_commit()
430 if (lnum == -1 || offs == c->leb_size) in ubifs_log_start_commit()
440 ubifs_prepare_node(c, ref, UBIFS_REF_NODE_SZ, 0); in ubifs_log_start_commit()
444 ubifs_pad(c, buf + len, ALIGN(len, c->min_io_size) - len); in ubifs_log_start_commit()
447 if (c->lhead_offs) { in ubifs_log_start_commit()
448 c->lhead_lnum = next_log_lnum(c, c->lhead_lnum); in ubifs_log_start_commit()
449 c->lhead_offs = 0; in ubifs_log_start_commit()
452 if (c->lhead_offs == 0) { in ubifs_log_start_commit()
454 err = ubifs_leb_unmap(c, c->lhead_lnum); in ubifs_log_start_commit()
459 len = ALIGN(len, c->min_io_size); in ubifs_log_start_commit()
460 dbg_log("writing commit start at LEB %d:0, len %d", c->lhead_lnum, len); in ubifs_log_start_commit()
461 err = ubifs_leb_write(c, c->lhead_lnum, cs, 0, len, UBI_SHORTTERM); in ubifs_log_start_commit()
465 *ltail_lnum = c->lhead_lnum; in ubifs_log_start_commit()
467 c->lhead_offs += len; in ubifs_log_start_commit()
468 if (c->lhead_offs == c->leb_size) { in ubifs_log_start_commit()
469 c->lhead_lnum = next_log_lnum(c, c->lhead_lnum); in ubifs_log_start_commit()
470 c->lhead_offs = 0; in ubifs_log_start_commit()
473 remove_buds(c); in ubifs_log_start_commit()
479 c->min_log_bytes = 0; in ubifs_log_start_commit()
496 int ubifs_log_end_commit(struct ubifs_info *c, int ltail_lnum) in ubifs_log_end_commit() argument
505 mutex_lock(&c->log_mutex); in ubifs_log_end_commit()
508 c->ltail_lnum, ltail_lnum); in ubifs_log_end_commit()
510 c->ltail_lnum = ltail_lnum; in ubifs_log_end_commit()
515 c->min_log_bytes = c->leb_size; in ubifs_log_end_commit()
517 spin_lock(&c->buds_lock); in ubifs_log_end_commit()
518 c->bud_bytes -= c->cmt_bud_bytes; in ubifs_log_end_commit()
519 spin_unlock(&c->buds_lock); in ubifs_log_end_commit()
521 err = dbg_check_bud_bytes(c); in ubifs_log_end_commit()
523 mutex_unlock(&c->log_mutex); in ubifs_log_end_commit()
540 int ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum) in ubifs_log_post_commit() argument
544 while (!list_empty(&c->old_buds)) { in ubifs_log_post_commit()
547 bud = list_entry(c->old_buds.next, struct ubifs_bud, list); in ubifs_log_post_commit()
548 err = ubifs_return_leb(c, bud->lnum); in ubifs_log_post_commit()
554 mutex_lock(&c->log_mutex); in ubifs_log_post_commit()
555 for (lnum = old_ltail_lnum; lnum != c->ltail_lnum; in ubifs_log_post_commit()
556 lnum = next_log_lnum(c, lnum)) { in ubifs_log_post_commit()
558 err = ubifs_leb_unmap(c, lnum); in ubifs_log_post_commit()
563 mutex_unlock(&c->log_mutex); in ubifs_log_post_commit()
652 static int add_node(struct ubifs_info *c, void *buf, int *lnum, int *offs, in add_node() argument
656 int len = le32_to_cpu(ch->len), remains = c->leb_size - *offs; in add_node()
659 int sz = ALIGN(*offs, c->min_io_size), err; in add_node()
661 ubifs_pad(c, buf + *offs, sz - *offs); in add_node()
662 err = ubifs_leb_change(c, *lnum, buf, sz, UBI_SHORTTERM); in add_node()
665 *lnum = next_log_lnum(c, *lnum); in add_node()
683 int ubifs_consolidate_log(struct ubifs_info *c) in ubifs_consolidate_log() argument
691 dbg_rcvry("log tail LEB %d, log head LEB %d", c->ltail_lnum, in ubifs_consolidate_log()
692 c->lhead_lnum); in ubifs_consolidate_log()
693 buf = vmalloc(c->leb_size); in ubifs_consolidate_log()
696 lnum = c->ltail_lnum; in ubifs_consolidate_log()
699 sleb = ubifs_scan(c, lnum, 0, c->sbuf); in ubifs_consolidate_log()
714 err = add_node(c, buf, &write_lnum, in ubifs_consolidate_log()
724 err = add_node(c, buf, &write_lnum, &offs, in ubifs_consolidate_log()
733 if (lnum == c->lhead_lnum) in ubifs_consolidate_log()
735 lnum = next_log_lnum(c, lnum); in ubifs_consolidate_log()
738 int sz = ALIGN(offs, c->min_io_size); in ubifs_consolidate_log()
740 ubifs_pad(c, buf + offs, sz - offs); in ubifs_consolidate_log()
741 err = ubifs_leb_change(c, write_lnum, buf, sz, UBI_SHORTTERM); in ubifs_consolidate_log()
744 offs = ALIGN(offs, c->min_io_size); in ubifs_consolidate_log()
748 if (write_lnum == c->lhead_lnum) { in ubifs_consolidate_log()
755 lnum = next_log_lnum(c, lnum); in ubifs_consolidate_log()
756 err = ubifs_leb_unmap(c, lnum); in ubifs_consolidate_log()
759 } while (lnum != c->lhead_lnum); in ubifs_consolidate_log()
760 c->lhead_lnum = write_lnum; in ubifs_consolidate_log()
761 c->lhead_offs = offs; in ubifs_consolidate_log()
762 dbg_rcvry("new log head at %d:%d", c->lhead_lnum, c->lhead_offs); in ubifs_consolidate_log()
783 static int dbg_check_bud_bytes(struct ubifs_info *c) in dbg_check_bud_bytes() argument
792 spin_lock(&c->buds_lock); in dbg_check_bud_bytes()
793 for (i = 0; i < c->jhead_cnt; i++) in dbg_check_bud_bytes()
794 list_for_each_entry(bud, &c->jheads[i].buds_list, list) in dbg_check_bud_bytes()
795 bud_bytes += c->leb_size - bud->start; in dbg_check_bud_bytes()
797 if (c->bud_bytes != bud_bytes) { in dbg_check_bud_bytes()
799 c->bud_bytes, bud_bytes); in dbg_check_bud_bytes()
802 spin_unlock(&c->buds_lock); in dbg_check_bud_bytes()