Lines Matching refs:c

55 static int dbg_check_orphans(struct ubifs_info *c);
65 int ubifs_add_orphan(struct ubifs_info *c, ino_t inum) in ubifs_add_orphan() argument
76 spin_lock(&c->orphan_lock); in ubifs_add_orphan()
77 if (c->tot_orphans >= c->max_orphans) { in ubifs_add_orphan()
78 spin_unlock(&c->orphan_lock); in ubifs_add_orphan()
82 p = &c->orph_tree.rb_node; in ubifs_add_orphan()
91 ubifs_err(c, "orphaned twice"); in ubifs_add_orphan()
92 spin_unlock(&c->orphan_lock); in ubifs_add_orphan()
97 c->tot_orphans += 1; in ubifs_add_orphan()
98 c->new_orphans += 1; in ubifs_add_orphan()
100 rb_insert_color(&orphan->rb, &c->orph_tree); in ubifs_add_orphan()
101 list_add_tail(&orphan->list, &c->orph_list); in ubifs_add_orphan()
102 list_add_tail(&orphan->new_list, &c->orph_new); in ubifs_add_orphan()
103 spin_unlock(&c->orphan_lock); in ubifs_add_orphan()
115 void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum) in ubifs_delete_orphan() argument
120 spin_lock(&c->orphan_lock); in ubifs_delete_orphan()
121 p = c->orph_tree.rb_node; in ubifs_delete_orphan()
130 spin_unlock(&c->orphan_lock); in ubifs_delete_orphan()
137 o->dnext = c->orph_dnext; in ubifs_delete_orphan()
138 c->orph_dnext = o; in ubifs_delete_orphan()
139 spin_unlock(&c->orphan_lock); in ubifs_delete_orphan()
144 rb_erase(p, &c->orph_tree); in ubifs_delete_orphan()
146 c->tot_orphans -= 1; in ubifs_delete_orphan()
149 c->new_orphans -= 1; in ubifs_delete_orphan()
151 spin_unlock(&c->orphan_lock); in ubifs_delete_orphan()
157 spin_unlock(&c->orphan_lock); in ubifs_delete_orphan()
158 ubifs_err(c, "missing orphan ino %lu", (unsigned long)inum); in ubifs_delete_orphan()
168 int ubifs_orphan_start_commit(struct ubifs_info *c) in ubifs_orphan_start_commit() argument
172 spin_lock(&c->orphan_lock); in ubifs_orphan_start_commit()
173 last = &c->orph_cnext; in ubifs_orphan_start_commit()
174 list_for_each_entry(orphan, &c->orph_new, new_list) { in ubifs_orphan_start_commit()
183 c->cmt_orphans = c->new_orphans; in ubifs_orphan_start_commit()
184 c->new_orphans = 0; in ubifs_orphan_start_commit()
185 dbg_cmt("%d orphans to commit", c->cmt_orphans); in ubifs_orphan_start_commit()
186 INIT_LIST_HEAD(&c->orph_new); in ubifs_orphan_start_commit()
187 if (c->tot_orphans == 0) in ubifs_orphan_start_commit()
188 c->no_orphs = 1; in ubifs_orphan_start_commit()
190 c->no_orphs = 0; in ubifs_orphan_start_commit()
191 spin_unlock(&c->orphan_lock); in ubifs_orphan_start_commit()
202 static int avail_orphs(struct ubifs_info *c) in avail_orphs() argument
206 avail_lebs = c->orph_lebs - (c->ohead_lnum - c->orph_first) - 1; in avail_orphs()
208 ((c->leb_size - UBIFS_ORPH_NODE_SZ) / sizeof(__le64)); in avail_orphs()
209 gap = c->leb_size - c->ohead_offs; in avail_orphs()
222 static int tot_avail_orphs(struct ubifs_info *c) in tot_avail_orphs() argument
226 avail_lebs = c->orph_lebs; in tot_avail_orphs()
228 ((c->leb_size - UBIFS_ORPH_NODE_SZ) / sizeof(__le64)); in tot_avail_orphs()
242 static int do_write_orph_node(struct ubifs_info *c, int len, int atomic) in do_write_orph_node() argument
247 ubifs_assert(c->ohead_offs == 0); in do_write_orph_node()
248 ubifs_prepare_node(c, c->orph_buf, len, 1); in do_write_orph_node()
249 len = ALIGN(len, c->min_io_size); in do_write_orph_node()
250 err = ubifs_leb_change(c, c->ohead_lnum, c->orph_buf, len); in do_write_orph_node()
252 if (c->ohead_offs == 0) { in do_write_orph_node()
254 err = ubifs_leb_unmap(c, c->ohead_lnum); in do_write_orph_node()
258 err = ubifs_write_node(c, c->orph_buf, len, c->ohead_lnum, in do_write_orph_node()
259 c->ohead_offs); in do_write_orph_node()
273 static int write_orph_node(struct ubifs_info *c, int atomic) in write_orph_node() argument
279 ubifs_assert(c->cmt_orphans > 0); in write_orph_node()
280 gap = c->leb_size - c->ohead_offs; in write_orph_node()
282 c->ohead_lnum += 1; in write_orph_node()
283 c->ohead_offs = 0; in write_orph_node()
284 gap = c->leb_size; in write_orph_node()
285 if (c->ohead_lnum > c->orph_last) { in write_orph_node()
290 ubifs_err(c, "out of space in orphan area"); in write_orph_node()
295 if (cnt > c->cmt_orphans) in write_orph_node()
296 cnt = c->cmt_orphans; in write_orph_node()
298 ubifs_assert(c->orph_buf); in write_orph_node()
299 orph = c->orph_buf; in write_orph_node()
301 spin_lock(&c->orphan_lock); in write_orph_node()
302 cnext = c->orph_cnext; in write_orph_node()
311 c->orph_cnext = cnext; in write_orph_node()
312 c->cmt_orphans -= cnt; in write_orph_node()
313 spin_unlock(&c->orphan_lock); in write_orph_node()
314 if (c->cmt_orphans) in write_orph_node()
315 orph->cmt_no = cpu_to_le64(c->cmt_no); in write_orph_node()
318 orph->cmt_no = cpu_to_le64((c->cmt_no) | (1ULL << 63)); in write_orph_node()
319 ubifs_assert(c->ohead_offs + len <= c->leb_size); in write_orph_node()
320 ubifs_assert(c->ohead_lnum >= c->orph_first); in write_orph_node()
321 ubifs_assert(c->ohead_lnum <= c->orph_last); in write_orph_node()
322 err = do_write_orph_node(c, len, atomic); in write_orph_node()
323 c->ohead_offs += ALIGN(len, c->min_io_size); in write_orph_node()
324 c->ohead_offs = ALIGN(c->ohead_offs, 8); in write_orph_node()
336 static int write_orph_nodes(struct ubifs_info *c, int atomic) in write_orph_nodes() argument
340 while (c->cmt_orphans > 0) { in write_orph_nodes()
341 err = write_orph_node(c, atomic); in write_orph_nodes()
349 for (lnum = c->ohead_lnum + 1; lnum <= c->orph_last; lnum++) { in write_orph_nodes()
350 err = ubifs_leb_unmap(c, lnum); in write_orph_nodes()
369 static int consolidate(struct ubifs_info *c) in consolidate() argument
371 int tot_avail = tot_avail_orphs(c), err = 0; in consolidate()
373 spin_lock(&c->orphan_lock); in consolidate()
375 tot_avail, c->tot_orphans); in consolidate()
376 if (c->tot_orphans - c->new_orphans <= tot_avail) { in consolidate()
381 last = &c->orph_cnext; in consolidate()
382 list_for_each_entry(orphan, &c->orph_list, list) { in consolidate()
391 ubifs_assert(cnt == c->tot_orphans - c->new_orphans); in consolidate()
392 c->cmt_orphans = cnt; in consolidate()
393 c->ohead_lnum = c->orph_first; in consolidate()
394 c->ohead_offs = 0; in consolidate()
400 ubifs_err(c, "out of space in orphan area"); in consolidate()
403 spin_unlock(&c->orphan_lock); in consolidate()
414 static int commit_orphans(struct ubifs_info *c) in commit_orphans() argument
418 ubifs_assert(c->cmt_orphans > 0); in commit_orphans()
419 avail = avail_orphs(c); in commit_orphans()
420 if (avail < c->cmt_orphans) { in commit_orphans()
422 err = consolidate(c); in commit_orphans()
427 err = write_orph_nodes(c, atomic); in commit_orphans()
440 static void erase_deleted(struct ubifs_info *c) in erase_deleted() argument
444 spin_lock(&c->orphan_lock); in erase_deleted()
445 dnext = c->orph_dnext; in erase_deleted()
451 rb_erase(&orphan->rb, &c->orph_tree); in erase_deleted()
453 c->tot_orphans -= 1; in erase_deleted()
457 c->orph_dnext = NULL; in erase_deleted()
458 spin_unlock(&c->orphan_lock); in erase_deleted()
467 int ubifs_orphan_end_commit(struct ubifs_info *c) in ubifs_orphan_end_commit() argument
471 if (c->cmt_orphans != 0) { in ubifs_orphan_end_commit()
472 err = commit_orphans(c); in ubifs_orphan_end_commit()
476 erase_deleted(c); in ubifs_orphan_end_commit()
477 err = dbg_check_orphans(c); in ubifs_orphan_end_commit()
489 int ubifs_clear_orphans(struct ubifs_info *c) in ubifs_clear_orphans() argument
493 for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) { in ubifs_clear_orphans()
494 err = ubifs_leb_unmap(c, lnum); in ubifs_clear_orphans()
498 c->ohead_lnum = c->orph_first; in ubifs_clear_orphans()
499 c->ohead_offs = 0; in ubifs_clear_orphans()
512 static int insert_dead_orphan(struct ubifs_info *c, ino_t inum) in insert_dead_orphan() argument
522 p = &c->orph_tree.rb_node; in insert_dead_orphan()
536 c->tot_orphans += 1; in insert_dead_orphan()
538 rb_insert_color(&orphan->rb, &c->orph_tree); in insert_dead_orphan()
539 list_add_tail(&orphan->list, &c->orph_list); in insert_dead_orphan()
541 orphan->dnext = c->orph_dnext; in insert_dead_orphan()
542 c->orph_dnext = orphan; in insert_dead_orphan()
544 c->new_orphans, c->tot_orphans); in insert_dead_orphan()
560 static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb, in do_kill_orphans() argument
572 ubifs_err(c, "invalid node type %d in orphan area at %d:%d", in do_kill_orphans()
574 ubifs_dump_node(c, snod->node); in do_kill_orphans()
590 if (cmt_no > c->cmt_no) in do_kill_orphans()
591 c->cmt_no = cmt_no; in do_kill_orphans()
599 ubifs_err(c, "out of order commit number %llu in orphan node at %d:%d", in do_kill_orphans()
601 ubifs_dump_node(c, snod->node); in do_kill_orphans()
617 err = ubifs_tnc_remove_ino(c, inum); in do_kill_orphans()
620 err = insert_dead_orphan(c, inum); in do_kill_orphans()
647 static int kill_orphans(struct ubifs_info *c) in kill_orphans() argument
652 c->ohead_lnum = c->orph_first; in kill_orphans()
653 c->ohead_offs = 0; in kill_orphans()
655 if (c->no_orphs) { in kill_orphans()
670 for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) { in kill_orphans()
674 sleb = ubifs_scan(c, lnum, 0, c->sbuf, 1); in kill_orphans()
677 sleb = ubifs_recover_leb(c, lnum, 0, in kill_orphans()
678 c->sbuf, -1); in kill_orphans()
684 err = do_kill_orphans(c, sleb, &last_cmt_no, &outofdate, in kill_orphans()
691 c->ohead_lnum = lnum; in kill_orphans()
692 c->ohead_offs = sleb->endpt; in kill_orphans()
709 int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only) in ubifs_mount_orphans() argument
713 c->max_orphans = tot_avail_orphs(c); in ubifs_mount_orphans()
716 c->orph_buf = vmalloc(c->leb_size); in ubifs_mount_orphans()
717 if (!c->orph_buf) in ubifs_mount_orphans()
722 err = kill_orphans(c); in ubifs_mount_orphans()
724 err = ubifs_clear_orphans(c); in ubifs_mount_orphans()
747 static int dbg_find_orphan(struct ubifs_info *c, ino_t inum) in dbg_find_orphan() argument
752 spin_lock(&c->orphan_lock); in dbg_find_orphan()
753 p = c->orph_tree.rb_node; in dbg_find_orphan()
761 spin_unlock(&c->orphan_lock); in dbg_find_orphan()
765 spin_unlock(&c->orphan_lock); in dbg_find_orphan()
823 static int dbg_orphan_check(struct ubifs_info *c, struct ubifs_zbranch *zbr, in dbg_orphan_check() argument
830 inum = key_inum(c, &zbr->key); in dbg_orphan_check()
833 if (key_type(c, &zbr->key) != UBIFS_INO_KEY) in dbg_orphan_check()
834 ubifs_err(c, "found orphan node ino %lu, type %d", in dbg_orphan_check()
835 (unsigned long)inum, key_type(c, &zbr->key)); in dbg_orphan_check()
838 err = ubifs_tnc_read_node(c, zbr, ci->node); in dbg_orphan_check()
840 ubifs_err(c, "node read failed, error %d", err); in dbg_orphan_check()
846 !dbg_find_orphan(c, inum)) { in dbg_orphan_check()
847 ubifs_err(c, "missing orphan, ino %lu", in dbg_orphan_check()
879 static int dbg_scan_orphans(struct ubifs_info *c, struct check_info *ci) in dbg_scan_orphans() argument
885 if (c->no_orphs) in dbg_scan_orphans()
888 buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); in dbg_scan_orphans()
890 ubifs_err(c, "cannot allocate memory to check orphans"); in dbg_scan_orphans()
894 for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) { in dbg_scan_orphans()
897 sleb = ubifs_scan(c, lnum, 0, buf, 0); in dbg_scan_orphans()
913 static int dbg_check_orphans(struct ubifs_info *c) in dbg_check_orphans() argument
918 if (!dbg_is_chk_orph(c)) in dbg_check_orphans()
928 ubifs_err(c, "out of memory"); in dbg_check_orphans()
932 err = dbg_scan_orphans(c, &ci); in dbg_check_orphans()
936 err = dbg_walk_index(c, &dbg_orphan_check, NULL, &ci); in dbg_check_orphans()
938 ubifs_err(c, "cannot scan TNC, error %d", err); in dbg_check_orphans()
943 ubifs_err(c, "%lu missing orphan(s)", ci.missing); in dbg_check_orphans()