Patch "ubifs: Re-statistic cleaned znode count if commit failed" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    ubifs: Re-statistic cleaned znode count if commit failed

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     ubifs-re-statistic-cleaned-znode-count-if-commit-fai.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 83ba62f3f125db2d9de71712db393b86564219a7
Author: Zhihao Cheng <chengzhihao1@xxxxxxxxxx>
Date:   Fri Nov 18 17:02:35 2022 +0800

    ubifs: Re-statistic cleaned znode count if commit failed
    
    [ Upstream commit 944e096aa24071d3fe22822f6249d3ae309e39ea ]
    
    Dirty znodes will be written on flash in committing process with
    following states:
    
                  process A                 |  znode state
    ------------------------------------------------------
    do_commit                               | DIRTY_ZNODE
      ubifs_tnc_start_commit                | DIRTY_ZNODE
       get_znodes_to_commit                 | DIRTY_ZNODE | COW_ZNODE
        layout_commit                       | DIRTY_ZNODE | COW_ZNODE
         fill_gap                           | 0
      write master                          | 0 or OBSOLETE_ZNODE
    
                  process B                 |  znode state
    ------------------------------------------------------
    do_commit                               | DIRTY_ZNODE[1]
      ubifs_tnc_start_commit                | DIRTY_ZNODE
       get_znodes_to_commit                 | DIRTY_ZNODE | COW_ZNODE
      ubifs_tnc_end_commit                  | DIRTY_ZNODE | COW_ZNODE
       write_index                          | 0
      write master                          | 0 or OBSOLETE_ZNODE[2] or
                                            | DIRTY_ZNODE[3]
    
    [1] znode is dirtied without concurrent committing process
    [2] znode is copied up (re-dirtied by other process) before cleaned
        up in committing process
    [3] znode is re-dirtied after cleaned up in committing process
    
    Currently, the clean znode count is updated in free_obsolete_znodes(),
    which is called only in normal path. If do_commit failed, clean znode
    count won't be updated, which triggers a failure ubifs assertion[4] in
    ubifs_tnc_close():
     ubifs_assert_failed [ubifs]: UBIFS assert failed: freed == n
    
    [4] Commit 380347e9ca7682 ("UBIFS: Add an assertion for clean_zn_cnt").
    
    Fix it by re-statisticing cleaned znode count in tnc_destroy_cnext().
    
    Fetch a reproducer in [Link].
    
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=216704
    Fixes: 1e51764a3c2a ("UBIFS: add new flash file system")
    Signed-off-by: Zhihao Cheng <chengzhihao1@xxxxxxxxxx>
    Signed-off-by: Richard Weinberger <richard@xxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c
index 33742ee3945b3..b162561ca9c31 100644
--- a/fs/ubifs/tnc.c
+++ b/fs/ubifs/tnc.c
@@ -3054,6 +3054,21 @@ static void tnc_destroy_cnext(struct ubifs_info *c)
 		cnext = cnext->cnext;
 		if (ubifs_zn_obsolete(znode))
 			kfree(znode);
+		else if (!ubifs_zn_cow(znode)) {
+			/*
+			 * Don't forget to update clean znode count after
+			 * committing failed, because ubifs will check this
+			 * count while closing tnc. Non-obsolete znode could
+			 * be re-dirtied during committing process, so dirty
+			 * flag is untrustable. The flag 'COW_ZNODE' is set
+			 * for each dirty znode before committing, and it is
+			 * cleared as long as the znode become clean, so we
+			 * can statistic clean znode count according to this
+			 * flag.
+			 */
+			atomic_long_inc(&c->clean_zn_cnt);
+			atomic_long_inc(&ubifs_clean_zn_cnt);
+		}
 	} while (cnext && cnext != c->cnext);
 }
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux