]> www.infradead.org Git - mtd-utils.git/commitdiff
fsck.ubifs: Consolidate log
authorZhihao Cheng <chengzhihao1@huawei.com>
Mon, 11 Nov 2024 09:07:58 +0000 (17:07 +0800)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Mon, 11 Nov 2024 09:32:46 +0000 (10:32 +0100)
This is the 4/18 step of fsck. Consolidate log to ensure enough space
in log area. There could be following possible errors:
 1. corrupted scanning data in log area: danger mode with rebuild_fs and
    normal mode with 'yes' answer will turn to rebuild filesystem, other
    modes will exit.

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubifs-utils/fsck.ubifs/fsck.ubifs.c
ubifs-utils/fsck.ubifs/load_fs.c
ubifs-utils/libubifs/log.c

index 31c2aa6a08409b9810b57d1ee14cffc90f288dc5..83c8a2c53bb77472a047d39fec40020ab83a9143 100644 (file)
@@ -433,6 +433,7 @@ int main(int argc, char *argv[])
         * Step 1: Read master & init lpt
         * Step 2: Replay journal
         * Step 3: Handle orphan nodes
+        * Step 4: Consolidate log
         */
        err = ubifs_load_filesystem(c);
        if (err) {
index f376383cc2f0c709cf3b779c2eb01ae8889808ed..42b1afaae99cfd4b2de9689e44c851f88cf2f121 100644 (file)
@@ -199,6 +199,32 @@ int ubifs_load_filesystem(struct ubifs_info *c)
                goto out_orphans;
        }
 
+       if (!c->ro_mount) {
+               int lnum;
+
+               /* Check for enough log space */
+               lnum = c->lhead_lnum + 1;
+               if (lnum >= UBIFS_LOG_LNUM + c->log_lebs)
+                       lnum = UBIFS_LOG_LNUM;
+               if (lnum == c->ltail_lnum) {
+                       log_out(c, "Consolidate log");
+                       err = ubifs_consolidate_log(c);
+                       if (err) {
+                               unsigned int reason = get_failure_reason_callback(c);
+
+                               clear_failure_reason_callback(c);
+                               if (reason & FR_DATA_CORRUPTED) {
+                                       if (fix_problem(c, LOG_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;
index 0d45926100e88ff222a88b312d5c775b2cbaa592..c3dfd98e7e1b20feaf9a111ebede2d54d4e45659 100644 (file)
@@ -711,6 +711,7 @@ int ubifs_consolidate_log(struct ubifs_info *c)
        destroy_done_tree(&done_tree);
        vfree(buf);
        if (write_lnum == c->lhead_lnum) {
+               set_failure_reason_callback(c, FR_DATA_CORRUPTED);
                ubifs_err(c, "log is too full");
                return -EINVAL;
        }