This is the 3/18 step of fsck. Handle orphan nodes, update TNC & LPT.
There could be following steps and possible errors:
Step 1. scan orphan LEB, get all orphan nodes
a. corrupted scanning data in orphan area: danger mode and normal mode
with 'yes' answer will drop orphan LEB, other modes will exit.
Step 2. parse orphan node, find the original inode for each inum
a. corrupted node searched from TNC: skip node for danger mode and
normal mode with 'yes' answer, other modes will exit.
b. corrupted index node read from TNC: danger mode with rebuild_fs and
normal mode with 'yes' answer will turn to rebuild filesystem, other
modes will exit.
Step 4. remove inode for each inum, update TNC & LPT
a. corrupted index node read from TNC: danger mode with rebuild_fs and
normal mode with 'yes' answer will turn to rebuild filesystem, other
modes will exit.
b. corrupted lpt: Set %FR_LPT_CORRUPTED for lpt status. Ignore the
error.
c. incorrect lpt: Set %FR_LPT_INCORRECT for lpt status. Ignore the
error.
d. If lpt status is not empty, skip updating lpt.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
static const unsigned int reason_mapping_table[] = {
BUD_CORRUPTED, /* FR_H_BUD_CORRUPTED */
TNC_DATA_CORRUPTED, /* FR_H_TNC_DATA_CORRUPTED */
+ ORPHAN_CORRUPTED, /* FR_H_ORPHAN_CORRUPTED */
};
static bool fsck_handle_failure(const struct ubifs_info *c, unsigned int reason,
* Init: Read superblock
* Step 1: Read master & init lpt
* Step 2: Replay journal
+ * Step 3: Handle orphan nodes
*/
err = ubifs_load_filesystem(c);
if (err) {
/* Types of inconsistent problems */
enum { SB_CORRUPTED = 0, MST_CORRUPTED, LOG_CORRUPTED, BUD_CORRUPTED,
- TNC_CORRUPTED, TNC_DATA_CORRUPTED };
+ TNC_CORRUPTED, TNC_DATA_CORRUPTED, ORPHAN_CORRUPTED };
struct scanned_file;
/* Calculate 'min_idx_lebs' after journal replay */
c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
+ log_out(c, "Handle orphan nodes");
+ err = ubifs_mount_orphans(c, c->need_recovery, c->ro_mount);
+ if (err) {
+ unsigned int reason = get_failure_reason_callback(c);
+
+ clear_failure_reason_callback(c);
+ if (reason & FR_TNC_CORRUPTED) {
+ if (fix_problem(c, TNC_CORRUPTED, NULL))
+ FSCK(c)->try_rebuild = true;
+ } else {
+ ubifs_assert(c, reason == 0);
+ exit_code |= FSCK_ERROR;
+ }
+ goto out_orphans;
+ }
+
c->mounting = 0;
return 0;
+out_orphans:
+ free_orphans(c);
out_journal:
destroy_journal(c);
out_lpt:
{
destroy_journal(c);
free_wbufs(c);
+ free_orphans(c);
ubifs_lpt_free(c, 0);
c->max_sqnum = 0;
{PROBLEM_FIXABLE | PROBLEM_MUST_FIX | PROBLEM_DROP_DATA, "Corrupted bud LEB"}, // BUD_CORRUPTED
{PROBLEM_FIXABLE | PROBLEM_MUST_FIX | PROBLEM_DROP_DATA | PROBLEM_NEED_REBUILD, "Corrupted index node"}, // TNC_CORRUPTED
{PROBLEM_FIXABLE | PROBLEM_MUST_FIX | PROBLEM_DROP_DATA, "Corrupted data searched from TNC"}, // TNC_DATA_CORRUPTED
+ {PROBLEM_FIXABLE | PROBLEM_MUST_FIX | PROBLEM_DROP_DATA, "Corrupted orphan LEB"}, // ORPHAN_CORRUPTED
};
static const char *get_question(const struct fsck_problem *problem,
return "Drop bud?";
case TNC_DATA_CORRUPTED:
return "Drop it?";
+ case ORPHAN_CORRUPTED:
+ return "Drop orphans on the LEB?";
}
return "Fix it?";
const struct fsck_problem *problem, int problem_type,
const void *priv)
{
- if (problem_type == BUD_CORRUPTED) {
+ switch (problem_type) {
+ case BUD_CORRUPTED:
+ {
const struct ubifs_bud *bud = (const struct ubifs_bud *)priv;
log_out(c, "problem: %s %d:%d %s", problem->desc, bud->lnum,
bud->start, dbg_jhead(bud->jhead));
- } else
+ break;
+ }
+ case ORPHAN_CORRUPTED:
+ {
+ const int *lnum = (const int *)priv;
+
+ log_out(c, "problem: %s %d", problem->desc, *lnum);
+ break;
+ }
+ default:
log_out(c, "problem: %s", problem->desc);
+ break;
+ }
}
static void fatal_error(const struct ubifs_info *c,
ubifs_dump_node(c, snod->node,
c->leb_size - snod->offs);
err = -EINVAL;
+ set_failure_reason_callback(c, FR_DATA_CORRUPTED);
goto out_free;
}
ubifs_dump_node(c, snod->node,
c->leb_size - snod->offs);
err = -EINVAL;
+ set_failure_reason_callback(c, FR_DATA_CORRUPTED);
goto out_free;
}
dbg_rcvry("out of date LEB %d", sleb->lnum);
ino_key_init(c, &key, inum);
err = ubifs_tnc_lookup(c, &key, ino);
- if (err && err != -ENOENT)
+ if (err && err != -ENOENT) {
+ unsigned int reason;
+
+ reason = get_failure_reason_callback(c);
+ if (reason & FR_DATA_CORRUPTED) {
+ test_and_clear_failure_reason_callback(c, FR_DATA_CORRUPTED);
+ if (handle_failure_callback(c, FR_H_TNC_DATA_CORRUPTED, NULL)) {
+ /* Leave the inode to be deleted by subsequent steps */
+ continue;
+ }
+ }
goto out_free;
+ }
/*
* Check whether an inode can really get deleted.
(unsigned long)inum);
err = ubifs_tnc_remove_ino(c, inum);
- if (err)
+ if (err) {
+ if (c->program_type == FSCK_PROGRAM_TYPE)
+ goto out_free;
goto out_ro;
+ }
}
}
c->sbuf, -1);
}
if (IS_ERR(sleb)) {
+ if (test_and_clear_failure_reason_callback(c, FR_DATA_CORRUPTED) &&
+ handle_failure_callback(c, FR_H_ORPHAN_CORRUPTED, &lnum)) {
+ /* Skip the orphan LEB. */
+ continue;
+ }
err = PTR_ERR(sleb);
break;
}
}
err = do_kill_orphans(c, sleb, &last_cmt_no, &outofdate,
&last_flagged);
- if (err || outofdate) {
+ if (err) {
+ unsigned int reason = get_failure_reason_callback(c);
+
+ if (reason & FR_DATA_CORRUPTED) {
+ test_and_clear_failure_reason_callback(c, FR_DATA_CORRUPTED);
+ if (handle_failure_callback(c, FR_H_ORPHAN_CORRUPTED, &lnum)) {
+ err = 0;
+ /* Skip the orphan LEB. */
+ ubifs_scan_destroy(sleb);
+ continue;
+ }
+ }
+ ubifs_scan_destroy(sleb);
+ break;
+ }
+ if (outofdate) {
ubifs_scan_destroy(sleb);
break;
}
enum {
FR_H_BUD_CORRUPTED = 0, /* Bud LEB is corrupted */
FR_H_TNC_DATA_CORRUPTED, /* Data searched from TNC is corrupted */
+ FR_H_ORPHAN_CORRUPTED, /* Orphan LEB is corrupted */
};
/* Callback functions for failure(which can be handled by fsck) happens. */
static inline void set_failure_reason_callback(const struct ubifs_info *c,