From 5591e0d30355df1e4437a57fe4a0534938cfd992 Mon Sep 17 00:00:00 2001
From: Anthony Iliopoulos <ailiop@suse.com>
Date: Jun 02 2025 09:10:41 +0000
Subject: nilfs2: do not propagate ENOENT error from

nilfs_btree_propagate() (git-fixes).

---

diff --git a/patches.suse/nilfs2-do-not-propagate-ENOENT-error-from-nilfs_btree_propagate.patch b/patches.suse/nilfs2-do-not-propagate-ENOENT-error-from-nilfs_btree_propagate.patch
new file mode 100644
index 0000000..540d9ad
--- /dev/null
+++ b/patches.suse/nilfs2-do-not-propagate-ENOENT-error-from-nilfs_btree_propagate.patch
@@ -0,0 +1,56 @@
+From 8e39fbb1edbb4ec9d7c1124f403877fc167fcecd Mon Sep 17 00:00:00 2001
+From: Ryusuke Konishi <konishi.ryusuke@gmail.com>
+Date: Tue, 29 Apr 2025 02:37:08 +0900
+Subject: [PATCH] nilfs2: do not propagate ENOENT error from
+ nilfs_btree_propagate()
+Git-commit: 8e39fbb1edbb4ec9d7c1124f403877fc167fcecd
+Patch-mainline: v6.16-rc1
+References: git-fixes
+
+In preparation for writing logs, in nilfs_btree_propagate(), which makes
+parent and ancestor node blocks dirty starting from a modified data block
+or b-tree node block, if the starting block does not belong to the b-tree,
+i.e.  is isolated, nilfs_btree_do_lookup() called within the function
+fails with -ENOENT.
+
+In this case, even though -ENOENT is an internal code, it is propagated to
+the log writer via nilfs_bmap_propagate() and may be erroneously returned
+to system calls such as fsync().
+
+Fix this issue by changing the error code to -EINVAL in this case, and
+having the bmap layer detect metadata corruption and convert the error
+code appropriately.
+
+Link: https://lkml.kernel.org/r/20250428173808.6452-3-konishi.ryusuke@gmail.com
+Fixes: 1f5abe7e7dbc ("nilfs2: replace BUG_ON and BUG calls triggerable from ioctl")
+Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
+Cc: Wentao Liang <vulab@iscas.ac.cn>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Acked-by: Anthony Iliopoulos <ailiop@suse.com>
+
+---
+ fs/nilfs2/btree.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
+index 0d8f7fb15c2e..dd0c8e560ef6 100644
+--- a/fs/nilfs2/btree.c
++++ b/fs/nilfs2/btree.c
+@@ -2102,11 +2102,13 @@ static int nilfs_btree_propagate(struct nilfs_bmap *btree,
+ 
+ 	ret = nilfs_btree_do_lookup(btree, path, key, NULL, level + 1, 0);
+ 	if (ret < 0) {
+-		if (unlikely(ret == -ENOENT))
++		if (unlikely(ret == -ENOENT)) {
+ 			nilfs_crit(btree->b_inode->i_sb,
+ 				   "writing node/leaf block does not appear in b-tree (ino=%lu) at key=%llu, level=%d",
+ 				   btree->b_inode->i_ino,
+ 				   (unsigned long long)key, level);
++			ret = -EINVAL;
++		}
+ 		goto out;
+ 	}
+ 
+-- 
+2.49.0
+
diff --git a/series.conf b/series.conf
index 9228cb1..8ea0057 100644
--- a/series.conf
+++ b/series.conf
@@ -31935,6 +31935,7 @@
 	patches.suse/s390-bpf-Store-backchain-even-for-leaf-progs.patch
 	patches.suse/Squashfs-check-return-result-of-sb_min_blocksize.patch
 	patches.suse/nilfs2-add-pointer-check-for-nilfs_direct_propagate.patch
+	patches.suse/nilfs2-do-not-propagate-ENOENT-error-from-nilfs_btree_propagate.patch
 
 	# jejb/scsi for-next
 	patches.suse/scsi-lpfc-Use-memcpy-for-BIOS-version.patch