[PATCH RFC 14/17] ubifs: repair: Clean up log and orphan area
Zhihao Cheng
chengzhihao1 at huawei.com
Wed Dec 27 17:41:09 PST 2023
This is the 12/13 step of repairing. Clean up log and orphan area, all
nodes have been recovered, these two areas should be cleared, otherwise
old content in journal/orphan could be replayed in next mounting.
Signed-off-by: Zhihao Cheng <chengzhihao1 at huawei.com>
---
fs/ubifs/repair.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/fs/ubifs/repair.c b/fs/ubifs/repair.c
index 8d40cff26f7a..42124cda5d7d 100644
--- a/fs/ubifs/repair.c
+++ b/fs/ubifs/repair.c
@@ -2367,6 +2367,43 @@ int build_lpt(struct ubifs_info *c)
return ubifs_create_lpt(c, c->repair->lpts, c->main_lebs, hash_lpt);
}
+/**
+ * clean_log - clean up log area.
+ * @c: UBIFS file-system description object
+ *
+ * This function cleans up log area, since there is no need to do recovery
+ * in next mounting.
+ */
+static int clean_log(struct ubifs_info *c)
+{
+ int lnum, err;
+ struct ubifs_cs_node *cs;
+
+ for (lnum = UBIFS_LOG_LNUM; lnum <= c->log_last; lnum++) {
+ if (fatal_signal_pending(current))
+ return -EINTR;
+ cond_resched();
+
+ err = ubifs_leb_unmap(c, lnum);
+ if (err)
+ return err;
+ }
+
+ cs = kzalloc(ALIGN(UBIFS_CS_NODE_SZ, c->min_io_size), GFP_KERNEL);
+ if (!cs)
+ return -ENOMEM;
+
+ cs->ch.node_type = UBIFS_CS_NODE;
+ cs->cmt_no = cpu_to_le64(0);
+
+ err = ubifs_write_node(c, cs, UBIFS_CS_NODE_SZ, UBIFS_LOG_LNUM, 0);
+ kfree(cs);
+ if (err)
+ return err;
+
+ return 0;
+}
+
static int do_repair(struct ubifs_info *c)
{
int err = 0;
@@ -2416,6 +2453,16 @@ static int do_repair(struct ubifs_info *c)
/* Step 11. Build LPT. */
ubifs_msg(c, "Step 11: Build LPT");
err = build_lpt(c);
+ if (err)
+ goto out;
+
+ /* Step 12. Clean up log & orphan. */
+ ubifs_msg(c, "Step 12: Clean up log & orphan");
+ err = clean_log(c);
+ if (err)
+ goto out;
+
+ err = ubifs_clear_orphans(c);
out:
destroy_scanned_info(c, &si);
--
2.31.1
More information about the linux-mtd
mailing list