Lines Matching full:c
5 * Copyright (C) 2006-2008 Nokia Corporation.
30 * (c->leb_size - UBIFS_ORPH_NODE_SZ) / sizeof(__le64)
43 static int dbg_check_orphans(struct ubifs_info *c);
45 static struct ubifs_orphan *orphan_add(struct ubifs_info *c, ino_t inum, in orphan_add() argument
58 spin_lock(&c->orphan_lock); in orphan_add()
59 if (c->tot_orphans >= c->max_orphans) { in orphan_add()
60 spin_unlock(&c->orphan_lock); in orphan_add()
64 p = &c->orph_tree.rb_node; in orphan_add()
73 ubifs_err(c, "orphaned twice"); in orphan_add()
74 spin_unlock(&c->orphan_lock); in orphan_add()
79 c->tot_orphans += 1; in orphan_add()
80 c->new_orphans += 1; in orphan_add()
82 rb_insert_color(&orphan->rb, &c->orph_tree); in orphan_add()
83 list_add_tail(&orphan->list, &c->orph_list); in orphan_add()
84 list_add_tail(&orphan->new_list, &c->orph_new); in orphan_add()
91 spin_unlock(&c->orphan_lock); in orphan_add()
96 static struct ubifs_orphan *lookup_orphan(struct ubifs_info *c, ino_t inum) in lookup_orphan() argument
101 p = c->orph_tree.rb_node; in lookup_orphan()
115 static void __orphan_drop(struct ubifs_info *c, struct ubifs_orphan *o) in __orphan_drop() argument
117 rb_erase(&o->rb, &c->orph_tree); in __orphan_drop()
119 c->tot_orphans -= 1; in __orphan_drop()
123 c->new_orphans -= 1; in __orphan_drop()
129 static void orphan_delete(struct ubifs_info *c, struct ubifs_orphan *orph) in orphan_delete() argument
138 orph->dnext = c->orph_dnext; in orphan_delete()
139 c->orph_dnext = orph; in orphan_delete()
144 __orphan_drop(c, orph); in orphan_delete()
149 * @c: UBIFS file-system description object
155 int ubifs_add_orphan(struct ubifs_info *c, ino_t inum) in ubifs_add_orphan() argument
165 orphan = orphan_add(c, inum, NULL); in ubifs_add_orphan()
169 lowest_xent_key(c, &key, inum); in ubifs_add_orphan()
171 xent = ubifs_tnc_next_ent(c, &key, &nm); in ubifs_add_orphan()
184 xattr_orphan = orphan_add(c, xattr_inum, orphan); in ubifs_add_orphan()
193 key_read(c, &xent->key, &key); in ubifs_add_orphan()
202 * @c: UBIFS file-system description object
207 void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum) in ubifs_delete_orphan() argument
211 spin_lock(&c->orphan_lock); in ubifs_delete_orphan()
213 orph = lookup_orphan(c, inum); in ubifs_delete_orphan()
215 spin_unlock(&c->orphan_lock); in ubifs_delete_orphan()
216 ubifs_err(c, "missing orphan ino %lu", (unsigned long)inum); in ubifs_delete_orphan()
224 orphan_delete(c, child_orph); in ubifs_delete_orphan()
227 orphan_delete(c, orph); in ubifs_delete_orphan()
229 spin_unlock(&c->orphan_lock); in ubifs_delete_orphan()
234 * @c: UBIFS file-system description object
238 int ubifs_orphan_start_commit(struct ubifs_info *c) in ubifs_orphan_start_commit() argument
242 spin_lock(&c->orphan_lock); in ubifs_orphan_start_commit()
243 last = &c->orph_cnext; in ubifs_orphan_start_commit()
244 list_for_each_entry(orphan, &c->orph_new, new_list) { in ubifs_orphan_start_commit()
245 ubifs_assert(c, orphan->new); in ubifs_orphan_start_commit()
246 ubifs_assert(c, !orphan->cmt); in ubifs_orphan_start_commit()
253 c->cmt_orphans = c->new_orphans; in ubifs_orphan_start_commit()
254 c->new_orphans = 0; in ubifs_orphan_start_commit()
255 dbg_cmt("%d orphans to commit", c->cmt_orphans); in ubifs_orphan_start_commit()
256 INIT_LIST_HEAD(&c->orph_new); in ubifs_orphan_start_commit()
257 if (c->tot_orphans == 0) in ubifs_orphan_start_commit()
258 c->no_orphs = 1; in ubifs_orphan_start_commit()
260 c->no_orphs = 0; in ubifs_orphan_start_commit()
261 spin_unlock(&c->orphan_lock); in ubifs_orphan_start_commit()
267 * @c: UBIFS file-system description object
272 static int avail_orphs(struct ubifs_info *c) in avail_orphs() argument
276 avail_lebs = c->orph_lebs - (c->ohead_lnum - c->orph_first) - 1; in avail_orphs()
278 ((c->leb_size - UBIFS_ORPH_NODE_SZ) / sizeof(__le64)); in avail_orphs()
279 gap = c->leb_size - c->ohead_offs; in avail_orphs()
287 * @c: UBIFS file-system description object
292 static int tot_avail_orphs(struct ubifs_info *c) in tot_avail_orphs() argument
296 avail_lebs = c->orph_lebs; in tot_avail_orphs()
298 ((c->leb_size - UBIFS_ORPH_NODE_SZ) / sizeof(__le64)); in tot_avail_orphs()
304 * @c: UBIFS file-system description object
312 static int do_write_orph_node(struct ubifs_info *c, int len, int atomic) in do_write_orph_node() argument
317 ubifs_assert(c, c->ohead_offs == 0); in do_write_orph_node()
318 ubifs_prepare_node(c, c->orph_buf, len, 1); in do_write_orph_node()
319 len = ALIGN(len, c->min_io_size); in do_write_orph_node()
320 err = ubifs_leb_change(c, c->ohead_lnum, c->orph_buf, len); in do_write_orph_node()
322 if (c->ohead_offs == 0) { in do_write_orph_node()
324 err = ubifs_leb_unmap(c, c->ohead_lnum); in do_write_orph_node()
328 err = ubifs_write_node(c, c->orph_buf, len, c->ohead_lnum, in do_write_orph_node()
329 c->ohead_offs); in do_write_orph_node()
336 * @c: UBIFS file-system description object
343 static int write_orph_node(struct ubifs_info *c, int atomic) in write_orph_node() argument
349 ubifs_assert(c, c->cmt_orphans > 0); in write_orph_node()
350 gap = c->leb_size - c->ohead_offs; in write_orph_node()
352 c->ohead_lnum += 1; in write_orph_node()
353 c->ohead_offs = 0; in write_orph_node()
354 gap = c->leb_size; in write_orph_node()
355 if (c->ohead_lnum > c->orph_last) { in write_orph_node()
360 ubifs_err(c, "out of space in orphan area"); in write_orph_node()
365 if (cnt > c->cmt_orphans) in write_orph_node()
366 cnt = c->cmt_orphans; in write_orph_node()
368 ubifs_assert(c, c->orph_buf); in write_orph_node()
369 orph = c->orph_buf; in write_orph_node()
371 spin_lock(&c->orphan_lock); in write_orph_node()
372 cnext = c->orph_cnext; in write_orph_node()
375 ubifs_assert(c, orphan->cmt); in write_orph_node()
381 c->orph_cnext = cnext; in write_orph_node()
382 c->cmt_orphans -= cnt; in write_orph_node()
383 spin_unlock(&c->orphan_lock); in write_orph_node()
384 if (c->cmt_orphans) in write_orph_node()
385 orph->cmt_no = cpu_to_le64(c->cmt_no); in write_orph_node()
388 orph->cmt_no = cpu_to_le64((c->cmt_no) | (1ULL << 63)); in write_orph_node()
389 ubifs_assert(c, c->ohead_offs + len <= c->leb_size); in write_orph_node()
390 ubifs_assert(c, c->ohead_lnum >= c->orph_first); in write_orph_node()
391 ubifs_assert(c, c->ohead_lnum <= c->orph_last); in write_orph_node()
392 err = do_write_orph_node(c, len, atomic); in write_orph_node()
393 c->ohead_offs += ALIGN(len, c->min_io_size); in write_orph_node()
394 c->ohead_offs = ALIGN(c->ohead_offs, 8); in write_orph_node()
400 * @c: UBIFS file-system description object
406 static int write_orph_nodes(struct ubifs_info *c, int atomic) in write_orph_nodes() argument
410 while (c->cmt_orphans > 0) { in write_orph_nodes()
411 err = write_orph_node(c, atomic); in write_orph_nodes()
419 for (lnum = c->ohead_lnum + 1; lnum <= c->orph_last; lnum++) { in write_orph_nodes()
420 err = ubifs_leb_unmap(c, lnum); in write_orph_nodes()
430 * @c: UBIFS file-system description object
439 static int consolidate(struct ubifs_info *c) in consolidate() argument
441 int tot_avail = tot_avail_orphs(c), err = 0; in consolidate()
443 spin_lock(&c->orphan_lock); in consolidate()
445 tot_avail, c->tot_orphans); in consolidate()
446 if (c->tot_orphans - c->new_orphans <= tot_avail) { in consolidate()
451 last = &c->orph_cnext; in consolidate()
452 list_for_each_entry(orphan, &c->orph_list, list) { in consolidate()
461 ubifs_assert(c, cnt == c->tot_orphans - c->new_orphans); in consolidate()
462 c->cmt_orphans = cnt; in consolidate()
463 c->ohead_lnum = c->orph_first; in consolidate()
464 c->ohead_offs = 0; in consolidate()
470 ubifs_err(c, "out of space in orphan area"); in consolidate()
473 spin_unlock(&c->orphan_lock); in consolidate()
479 * @c: UBIFS file-system description object
484 static int commit_orphans(struct ubifs_info *c) in commit_orphans() argument
488 ubifs_assert(c, c->cmt_orphans > 0); in commit_orphans()
489 avail = avail_orphs(c); in commit_orphans()
490 if (avail < c->cmt_orphans) { in commit_orphans()
492 err = consolidate(c); in commit_orphans()
497 err = write_orph_nodes(c, atomic); in commit_orphans()
503 * @c: UBIFS file-system description object
510 static void erase_deleted(struct ubifs_info *c) in erase_deleted() argument
514 spin_lock(&c->orphan_lock); in erase_deleted()
515 dnext = c->orph_dnext; in erase_deleted()
519 ubifs_assert(c, !orphan->new); in erase_deleted()
520 ubifs_assert(c, orphan->del); in erase_deleted()
521 rb_erase(&orphan->rb, &c->orph_tree); in erase_deleted()
523 c->tot_orphans -= 1; in erase_deleted()
527 c->orph_dnext = NULL; in erase_deleted()
528 spin_unlock(&c->orphan_lock); in erase_deleted()
533 * @c: UBIFS file-system description object
537 int ubifs_orphan_end_commit(struct ubifs_info *c) in ubifs_orphan_end_commit() argument
541 if (c->cmt_orphans != 0) { in ubifs_orphan_end_commit()
542 err = commit_orphans(c); in ubifs_orphan_end_commit()
546 erase_deleted(c); in ubifs_orphan_end_commit()
547 err = dbg_check_orphans(c); in ubifs_orphan_end_commit()
553 * @c: UBIFS file-system description object
559 int ubifs_clear_orphans(struct ubifs_info *c) in ubifs_clear_orphans() argument
563 for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) { in ubifs_clear_orphans()
564 err = ubifs_leb_unmap(c, lnum); in ubifs_clear_orphans()
568 c->ohead_lnum = c->orph_first; in ubifs_clear_orphans()
569 c->ohead_offs = 0; in ubifs_clear_orphans()
575 * @c: UBIFS file-system description object
582 static int insert_dead_orphan(struct ubifs_info *c, ino_t inum) in insert_dead_orphan() argument
592 p = &c->orph_tree.rb_node; in insert_dead_orphan()
606 c->tot_orphans += 1; in insert_dead_orphan()
608 rb_insert_color(&orphan->rb, &c->orph_tree); in insert_dead_orphan()
609 list_add_tail(&orphan->list, &c->orph_list); in insert_dead_orphan()
611 orphan->dnext = c->orph_dnext; in insert_dead_orphan()
612 c->orph_dnext = orphan; in insert_dead_orphan()
614 c->new_orphans, c->tot_orphans); in insert_dead_orphan()
620 * @c: UBIFS file-system description object
630 static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb, in do_kill_orphans() argument
647 ubifs_err(c, "invalid node type %d in orphan area at %d:%d", in do_kill_orphans()
649 ubifs_dump_node(c, snod->node); in do_kill_orphans()
666 if (cmt_no > c->cmt_no) in do_kill_orphans()
667 c->cmt_no = cmt_no; in do_kill_orphans()
675 ubifs_err(c, "out of order commit number %llu in orphan node at %d:%d", in do_kill_orphans()
677 ubifs_dump_node(c, snod->node); in do_kill_orphans()
696 ino_key_init(c, &key1, inum); in do_kill_orphans()
697 err = ubifs_tnc_lookup(c, &key1, ino); in do_kill_orphans()
709 lowest_ino_key(c, &key1, inum); in do_kill_orphans()
710 highest_ino_key(c, &key2, inum); in do_kill_orphans()
712 err = ubifs_tnc_remove_range(c, &key1, &key2); in do_kill_orphans()
717 err = insert_dead_orphan(c, inum); in do_kill_orphans()
737 ubifs_ro_mode(c, err); in do_kill_orphans()
744 * @c: UBIFS file-system description object
752 static int kill_orphans(struct ubifs_info *c) in kill_orphans() argument
757 c->ohead_lnum = c->orph_first; in kill_orphans()
758 c->ohead_offs = 0; in kill_orphans()
760 if (c->no_orphs) { in kill_orphans()
765 * Orph nodes always start at c->orph_first and are written to each in kill_orphans()
775 for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) { in kill_orphans()
779 sleb = ubifs_scan(c, lnum, 0, c->sbuf, 1); in kill_orphans()
782 sleb = ubifs_recover_leb(c, lnum, 0, in kill_orphans()
783 c->sbuf, -1); in kill_orphans()
789 err = do_kill_orphans(c, sleb, &last_cmt_no, &outofdate, in kill_orphans()
796 c->ohead_lnum = lnum; in kill_orphans()
797 c->ohead_offs = sleb->endpt; in kill_orphans()
806 * @c: UBIFS file-system description object
814 int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only) in ubifs_mount_orphans() argument
818 c->max_orphans = tot_avail_orphs(c); in ubifs_mount_orphans()
821 c->orph_buf = vmalloc(c->leb_size); in ubifs_mount_orphans()
822 if (!c->orph_buf) in ubifs_mount_orphans()
827 err = kill_orphans(c); in ubifs_mount_orphans()
829 err = ubifs_clear_orphans(c); in ubifs_mount_orphans()
852 static bool dbg_find_orphan(struct ubifs_info *c, ino_t inum) in dbg_find_orphan() argument
856 spin_lock(&c->orphan_lock); in dbg_find_orphan()
857 found = !!lookup_orphan(c, inum); in dbg_find_orphan()
858 spin_unlock(&c->orphan_lock); in dbg_find_orphan()
917 static int dbg_orphan_check(struct ubifs_info *c, struct ubifs_zbranch *zbr, in dbg_orphan_check() argument
924 inum = key_inum(c, &zbr->key); in dbg_orphan_check()
927 if (key_type(c, &zbr->key) != UBIFS_INO_KEY) in dbg_orphan_check()
928 ubifs_err(c, "found orphan node ino %lu, type %d", in dbg_orphan_check()
929 (unsigned long)inum, key_type(c, &zbr->key)); in dbg_orphan_check()
932 err = ubifs_tnc_read_node(c, zbr, ci->node); in dbg_orphan_check()
934 ubifs_err(c, "node read failed, error %d", err); in dbg_orphan_check()
940 !dbg_find_orphan(c, inum)) { in dbg_orphan_check()
941 ubifs_err(c, "missing orphan, ino %lu", in dbg_orphan_check()
973 static int dbg_scan_orphans(struct ubifs_info *c, struct check_info *ci) in dbg_scan_orphans() argument
979 if (c->no_orphs) in dbg_scan_orphans()
982 buf = __vmalloc(c->leb_size, GFP_NOFS); in dbg_scan_orphans()
984 ubifs_err(c, "cannot allocate memory to check orphans"); in dbg_scan_orphans()
988 for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) { in dbg_scan_orphans()
991 sleb = ubifs_scan(c, lnum, 0, buf, 0); in dbg_scan_orphans()
1007 static int dbg_check_orphans(struct ubifs_info *c) in dbg_check_orphans() argument
1012 if (!dbg_is_chk_orph(c)) in dbg_check_orphans()
1022 ubifs_err(c, "out of memory"); in dbg_check_orphans()
1026 err = dbg_scan_orphans(c, &ci); in dbg_check_orphans()
1030 err = dbg_walk_index(c, &dbg_orphan_check, NULL, &ci); in dbg_check_orphans()
1032 ubifs_err(c, "cannot scan TNC, error %d", err); in dbg_check_orphans()
1037 ubifs_err(c, "%lu missing orphan(s)", ci.missing); in dbg_check_orphans()