From: Chao Yu <chao@kernel.org>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Chao Yu <chao@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH v2 1/7] f2fs: fix to persist i_size extended inside last block for fsync
Date: Fri, 27 Nov 2026 10:56:08 +0000 [thread overview]
Message-ID: <20261127105608.537148-8-chao@kernel.org> (raw)
From: Chao Yu <chao@kernel.org>
generic/737 fails on 16k block size f2fs, after writing a 1M file w/
O_SYNC buffered or direct IO and shutdown, the file size is 0xff000
rather than 0x100000, i.e. the last fsynced 4k data is lost.
It can be reproduced as below w/ 16k block size:
xfs_io -fs -c "pwrite -S 0x5a 0 32k" /mnt/f2fs/file
xfs_io -x -c "shutdown" /mnt/f2fs
umount /mnt/f2fs; mount /dev/vdd /mnt/f2fs
stat -c %s /mnt/f2fs/file
28672
xfs_io writes 4k per pwrite() and fsyncs it, the 16k-sized 4k unaligned
direct IO falls back to buffered IO as well:
- pwrite [16k, 20k): allocates the block, last_disk_size = 32k (end of
the page) after writeback, i_size (20k) is unaligned, so fsync writes
the inode and its dnode w/ fsync mark
- pwrite [20k, 24k), [24k, 28k): in-place update of the block, i_size is
unaligned, fsync writes the inode w/ i_size = 28k
- pwrite [28k, 32k): in-place update of the block, f2fs_i_size_write()
sets FI_AUTO_RECOVER as the inode was clean; i_size (32k) is aligned
and equals last_disk_size, so f2fs_skip_inode_update() returns true,
and nothing is written for fsync since the in-place update doesn't
dirty the dnode
After shutdown, roll-forward recovery restores i_size = 28k from the
last fsynced inode, and do_recover_data() only extends i_size to the end
of a recovered block when i_size doesn't exceed the block's start
(28k > 16k), so i_size stays at 28k, losing the fsynced 4k data.
FI_AUTO_RECOVER means that the dirtied inode can be recovered from data
blocks via roll-forward recovery, it's not true when i_size is extended
inside the old last block, let's clear FI_AUTO_RECOVER in that case, so
that fsync will write the inode. It happens w/ 4k block size as well,
e.g. w/ 1k O_SYNC appends.
Cc: stable@vger.kernel.org
Fixes: 26de9b117130 ("f2fs: avoid unnecessary updating inode during fsync")
Signed-off-by: Chao Yu <chao@kernel.org>
---
v2:
- rebase to the latest dev-test branch.
fs/f2fs/f2fs.h | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 882ff2617531..d35149191625 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -3728,8 +3728,9 @@ static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
{
bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
+ loff_t old_size = i_size_read(inode);
- if (i_size_read(inode) == i_size)
+ if (old_size == i_size)
return;
i_size_write(inode, i_size);
@@ -3738,7 +3739,18 @@ static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
return;
f2fs_mark_inode_dirty_sync(inode, true);
- if (clean || recover)
+
+ /*
+ * Roll-forward recovery only extends i_size to the end of a recovered
+ * block if i_size doesn't exceed that block's start, so it can't
+ * recover an extension inside the old last block, e.g. an O_SYNC 4k
+ * append filling up a 16k block, which is an in-place update of an
+ * already allocated block. Let fsync write the inode for it.
+ */
+ if (i_size > old_size &&
+ old_size > round_down(i_size - 1, i_blocksize(inode)))
+ clear_inode_flag(inode, FI_AUTO_RECOVER);
+ else if (clean || recover)
set_inode_flag(inode, FI_AUTO_RECOVER);
}
base-commit: 9ad6c58bfbe5882b1aa0cbe2393dbfca89d2c199
--
2.49.0
WARNING: multiple messages have this Message-ID (diff)
From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: jaegeuk@kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH v2 1/7] f2fs: fix to persist i_size extended inside last block for fsync
Date: Fri, 27 Nov 2026 10:56:08 +0000 [thread overview]
Message-ID: <20261127105608.537148-8-chao@kernel.org> (raw)
From: Chao Yu <chao@kernel.org>
generic/737 fails on 16k block size f2fs, after writing a 1M file w/
O_SYNC buffered or direct IO and shutdown, the file size is 0xff000
rather than 0x100000, i.e. the last fsynced 4k data is lost.
It can be reproduced as below w/ 16k block size:
xfs_io -fs -c "pwrite -S 0x5a 0 32k" /mnt/f2fs/file
xfs_io -x -c "shutdown" /mnt/f2fs
umount /mnt/f2fs; mount /dev/vdd /mnt/f2fs
stat -c %s /mnt/f2fs/file
28672
xfs_io writes 4k per pwrite() and fsyncs it, the 16k-sized 4k unaligned
direct IO falls back to buffered IO as well:
- pwrite [16k, 20k): allocates the block, last_disk_size = 32k (end of
the page) after writeback, i_size (20k) is unaligned, so fsync writes
the inode and its dnode w/ fsync mark
- pwrite [20k, 24k), [24k, 28k): in-place update of the block, i_size is
unaligned, fsync writes the inode w/ i_size = 28k
- pwrite [28k, 32k): in-place update of the block, f2fs_i_size_write()
sets FI_AUTO_RECOVER as the inode was clean; i_size (32k) is aligned
and equals last_disk_size, so f2fs_skip_inode_update() returns true,
and nothing is written for fsync since the in-place update doesn't
dirty the dnode
After shutdown, roll-forward recovery restores i_size = 28k from the
last fsynced inode, and do_recover_data() only extends i_size to the end
of a recovered block when i_size doesn't exceed the block's start
(28k > 16k), so i_size stays at 28k, losing the fsynced 4k data.
FI_AUTO_RECOVER means that the dirtied inode can be recovered from data
blocks via roll-forward recovery, it's not true when i_size is extended
inside the old last block, let's clear FI_AUTO_RECOVER in that case, so
that fsync will write the inode. It happens w/ 4k block size as well,
e.g. w/ 1k O_SYNC appends.
Cc: stable@vger.kernel.org
Fixes: 26de9b117130 ("f2fs: avoid unnecessary updating inode during fsync")
Signed-off-by: Chao Yu <chao@kernel.org>
---
v2:
- rebase to the latest dev-test branch.
fs/f2fs/f2fs.h | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 882ff2617531..d35149191625 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -3728,8 +3728,9 @@ static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
{
bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
+ loff_t old_size = i_size_read(inode);
- if (i_size_read(inode) == i_size)
+ if (old_size == i_size)
return;
i_size_write(inode, i_size);
@@ -3738,7 +3739,18 @@ static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
return;
f2fs_mark_inode_dirty_sync(inode, true);
- if (clean || recover)
+
+ /*
+ * Roll-forward recovery only extends i_size to the end of a recovered
+ * block if i_size doesn't exceed that block's start, so it can't
+ * recover an extension inside the old last block, e.g. an O_SYNC 4k
+ * append filling up a 16k block, which is an in-place update of an
+ * already allocated block. Let fsync write the inode for it.
+ */
+ if (i_size > old_size &&
+ old_size > round_down(i_size - 1, i_blocksize(inode)))
+ clear_inode_flag(inode, FI_AUTO_RECOVER);
+ else if (clean || recover)
set_inode_flag(inode, FI_AUTO_RECOVER);
}
base-commit: 9ad6c58bfbe5882b1aa0cbe2393dbfca89d2c199
--
2.49.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next reply other threads:[~2026-11-27 10:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 10:56 Chao Yu [this message]
2026-11-27 10:56 ` [f2fs-dev] [PATCH v2 1/7] f2fs: fix to persist i_size extended inside last block for fsync Chao Yu via Linux-f2fs-devel
2026-11-27 10:56 ` [PATCH v2 2/7] f2fs: fix to return -EIO from f2fs_sync_fs() if cp_error is set Chao Yu
2026-11-27 10:56 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-27 10:56 ` [PATCH v2 3/7] f2fs: fix to return -EIO from f2fs_write_checkpoint() once " Chao Yu
2026-11-27 10:56 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-27 10:56 ` [PATCH v2 4/7] f2fs: fix to truncate stale meta cache entry on in-place update Chao Yu
2026-11-27 10:56 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-12-01 2:54 ` Jaegeuk Kim
2026-12-01 2:54 ` Jaegeuk Kim via Linux-f2fs-devel
2026-11-27 10:56 ` [PATCH v2 5/7] f2fs: fix to truncate meta cache entry in F2FS_IOC_SEC_TRIM_FILE Chao Yu
2026-11-27 10:56 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-27 10:56 ` [PATCH v2 6/7] f2fs: fix to serialize truncation of COW blocks w/ GC Chao Yu
2026-11-27 10:56 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-11-27 10:56 ` [PATCH v2 7/7] f2fs: cache: fix to initialize f2fs_writeback info at mount time Chao Yu
2026-11-27 10:56 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127105608.537148-8-chao@kernel.org \
--to=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.