WSL2-Linux-Kernel/fs/nilfs2
Ryusuke Konishi 3e349d7191 nilfs2: fix state management in error path of log writing function
commit 6576dd6695f2afca3f4954029ac4a64f82ba60ab upstream.

After commit a694291a62 ("nilfs2: separate wait function from
nilfs_segctor_write") was applied, the log writing function
nilfs_segctor_do_construct() was able to issue I/O requests continuously
even if user data blocks were split into multiple logs across segments,
but two potential flaws were introduced in its error handling.

First, if nilfs_segctor_begin_construction() fails while creating the
second or subsequent logs, the log writing function returns without
calling nilfs_segctor_abort_construction(), so the writeback flag set on
pages/folios will remain uncleared.  This causes page cache operations to
hang waiting for the writeback flag.  For example,
truncate_inode_pages_final(), which is called via nilfs_evict_inode() when
an inode is evicted from memory, will hang.

Second, the NILFS_I_COLLECTED flag set on normal inodes remain uncleared.
As a result, if the next log write involves checkpoint creation, that's
fine, but if a partial log write is performed that does not, inodes with
NILFS_I_COLLECTED set are erroneously removed from the "sc_dirty_files"
list, and their data and b-tree blocks may not be written to the device,
corrupting the block mapping.

Fix these issues by uniformly calling nilfs_segctor_abort_construction()
on failure of each step in the loop in nilfs_segctor_do_construct(),
having it clean up logs and segment usages according to progress, and
correcting the conditions for calling nilfs_redirty_inodes() to ensure
that the NILFS_I_COLLECTED flag is cleared.

Link: https://lkml.kernel.org/r/20240814101119.4070-1-konishi.ryusuke@gmail.com
Fixes: a694291a62 ("nilfs2: separate wait function from nilfs_segctor_write")
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-09-12 11:07:44 +02:00
..
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
alloc.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 13:07:36 +02:00
alloc.h nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 13:07:36 +02:00
bmap.c nilfs2: fix infinite loop in nilfs_mdt_get_block() 2023-05-11 23:00:39 +09:00
bmap.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
btnode.c nilfs2: handle inconsistent state in nilfs_btnode_create_block() 2024-08-19 05:45:22 +02:00
btnode.h nilfs2: fix lockdep warnings in page operations for btree nodes 2022-05-25 09:57:26 +02:00
btree.c nilfs2: handle inconsistent state in nilfs_btnode_create_block() 2024-08-19 05:45:22 +02:00
btree.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
cpfile.c nilfs2: fix typos in comments 2021-05-06 19:24:13 -07:00
cpfile.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
dat.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 13:07:36 +02:00
dat.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
dir.c nilfs2: fix kernel bug on rename operation of broken directory 2024-07-18 13:07:43 +02:00
direct.c nilfs2: fix failure to detect DAT corruption in btree and direct mappings 2024-04-10 16:18:42 +02:00
direct.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
export.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
file.c nilfs2: fix hang in nilfs_lookup_dirty_data_buffers() 2024-02-23 08:55:08 +01:00
gcinode.c nilfs2: fix potential use after free in nilfs_gccache_submit_read_data() 2023-10-06 13:18:21 +02:00
ifile.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 13:07:36 +02:00
ifile.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
inode.c nilfs2: prevent kernel bug at submit_bh_wbc() 2024-04-10 16:18:43 +02:00
ioctl.c nilfs2: fix out-of-range warning 2024-06-16 13:39:16 +02:00
mdt.c nilfs2: fix lockdep warnings during disk space reclamation 2022-05-25 09:57:26 +02:00
mdt.h nilfs2: fix lockdep warnings during disk space reclamation 2022-05-25 09:57:26 +02:00
namei.c Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2021-05-02 09:14:01 -07:00
nilfs.h nilfs2: add missing check for inode numbers on directory entries 2024-07-18 13:07:32 +02:00
page.c nilfs2: prevent general protection fault in nilfs_clear_dirty_page() 2023-06-28 10:29:45 +02:00
page.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
recovery.c nilfs2: fix missing cleanup on rollforward recovery error 2024-09-12 11:07:44 +02:00
segbuf.c nilfs2: fix buffer corruption due to concurrent device reads 2023-06-28 10:29:42 +02:00
segbuf.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
segment.c nilfs2: fix state management in error path of log writing function 2024-09-12 11:07:44 +02:00
segment.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
sufile.c nilfs2: prevent WARNING in nilfs_sufile_set_segment_usage() 2023-12-13 18:36:43 +01:00
sufile.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
super.c nilfs2: fix buffer corruption due to concurrent device reads 2023-06-28 10:29:42 +02:00
sysfs.c nilfs2: fix memory leak in nilfs_sysfs_delete_snapshot_group 2021-09-08 11:50:27 -07:00
sysfs.h nilfs2: convert to SPDX license tags 2018-09-04 16:45:02 -07:00
the_nilfs.c nilfs2: fix inode number range checks 2024-07-18 13:07:32 +02:00
the_nilfs.h nilfs2: fix inode number range checks 2024-07-18 13:07:32 +02:00