linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH 1/1] f2fs: fix to check space of current segment journal
@ 2022-09-14  4:04 Wu Bo via Linux-f2fs-devel
  2022-09-14  8:08 ` Philippe De Muyter
  2022-09-20  0:50 ` Jaegeuk Kim
  0 siblings, 2 replies; 6+ messages in thread
From: Wu Bo via Linux-f2fs-devel @ 2022-09-14  4:04 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: Philippe De Muyter, linux-kernel, Wu Bo, linux-f2fs-devel

As Philippe De Muyter reported:
https://lore.kernel.org/linux-f2fs-devel/20220913224908.GA25100@172.21.0.10/T/#u

The warning log showed that when finding a new space for nat the journal
space turned out to be full. This because the journal_rwsem is not
locked before the journal space checking. The journal space may become
full just after we check it.

Reported-by: Philippe De Muyter <phdm@macq.eu>
Signed-off-by: Wu Bo <bo.wu@vivo.com>
---
 fs/f2fs/node.c    |  6 +++---
 fs/f2fs/segment.c | 10 +++++-----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index e06a0c478b39..971d8b9ccdf1 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -2995,13 +2995,13 @@ static int __flush_nat_entry_set(struct f2fs_sb_info *sbi,
 	 * #1, flush nat entries to journal in current hot data summary block.
 	 * #2, flush nat entries to nat page.
 	 */
+	down_write(&curseg->journal_rwsem);
 	if ((cpc->reason & CP_UMOUNT) ||
 		!__has_cursum_space(journal, set->entry_cnt, NAT_JOURNAL))
 		to_journal = false;
 
-	if (to_journal) {
-		down_write(&curseg->journal_rwsem);
-	} else {
+	if (!to_journal) {
+		up_write(&curseg->journal_rwsem);
 		page = get_next_nat_page(sbi, start_nid);
 		if (IS_ERR(page))
 			return PTR_ERR(page);
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 0de21f82d7bc..d545032d2f6f 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3914,13 +3914,13 @@ int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type,
 			if (le32_to_cpu(nid_in_journal(journal, i)) == val)
 				return i;
 		}
-		if (alloc && __has_cursum_space(journal, 1, NAT_JOURNAL))
+		if (alloc)
 			return update_nats_in_cursum(journal, 1);
 	} else if (type == SIT_JOURNAL) {
 		for (i = 0; i < sits_in_cursum(journal); i++)
 			if (le32_to_cpu(segno_in_journal(journal, i)) == val)
 				return i;
-		if (alloc && __has_cursum_space(journal, 1, SIT_JOURNAL))
+		if (alloc)
 			return update_sits_in_cursum(journal, 1);
 	}
 	return -1;
@@ -4085,13 +4085,13 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 						(unsigned long)MAIN_SEGS(sbi));
 		unsigned int segno = start_segno;
 
+		down_write(&curseg->journal_rwsem);
 		if (to_journal &&
 			!__has_cursum_space(journal, ses->entry_cnt, SIT_JOURNAL))
 			to_journal = false;
 
-		if (to_journal) {
-			down_write(&curseg->journal_rwsem);
-		} else {
+		if (!to_journal) {
+			up_write(&curseg->journal_rwsem);
 			page = get_next_sit_page(sbi, start_segno);
 			raw_sit = page_address(page);
 		}
-- 
2.36.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-09-20  0:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14  4:04 [f2fs-dev] [PATCH 1/1] f2fs: fix to check space of current segment journal Wu Bo via Linux-f2fs-devel
2022-09-14  8:08 ` Philippe De Muyter
2022-09-15  7:10   ` Wu Bo via Linux-f2fs-devel
2022-09-16 14:59     ` Philippe De Muyter
2022-09-20  0:52       ` Jaegeuk Kim
2022-09-20  0:50 ` Jaegeuk Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).