All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] f2fs: keep pinned fallocate failures section-aligned
@ 2026-07-23 13:36 ` Wenjie Qi
  0 siblings, 0 replies; 6+ messages in thread
From: Wenjie Qi @ 2026-07-23 13:36 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, qiwenjie, qwjhust, stable

Pinned fallocate allocates one section at a time. If f2fs_map_blocks()
fails after allocating part of the current section, the error path still
adds the partial length to expanded and clears FADVISE_TRUNC_BIT. A failed
fallocate can then leave a pinned file with a non-section-aligned size.

Count only complete sections on failure and keep FADVISE_TRUNC_BIT set
until the failed section preallocation has been removed.

Fixes: f5a53edcf01e ("f2fs: support aligned pinned file")
Cc: stable@kernel.org
Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
---
 fs/f2fs/file.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index c54897a25981..83af73f3831e 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1966,11 +1966,12 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
 
 		map.m_seg_type = CURSEG_COLD_DATA_PINNED;
 		err = f2fs_map_blocks(inode, &map, F2FS_GET_BLOCK_PRE_DIO);
-		file_dont_truncate(inode);
+		if (!err)
+			file_dont_truncate(inode);
 
 		f2fs_up_write(&sbi->pin_sem);
 
-		expanded += map.m_len;
+		expanded += err ? rounddown(map.m_len, sec_blks) : map.m_len;
 		sec_len -= map.m_len;
 		map.m_lblk += map.m_len;
 		if (!err && sec_len)
@@ -1986,7 +1987,7 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
 		pgoff_t last_off;
 
 		if (!expanded)
-			return err;
+			goto out;
 
 		last_off = pg_start + expanded - 1;
 
@@ -2004,6 +2005,16 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
 			f2fs_i_size_write(inode, new_size);
 	}
 
+out:
+	if (err && f2fs_is_pinned_file(inode) && file_should_truncate(inode)) {
+		f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
+		filemap_invalidate_lock(inode->i_mapping);
+		if (!f2fs_truncate(inode))
+			file_dont_truncate(inode);
+		filemap_invalidate_unlock(inode->i_mapping);
+		f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
+	}
+
 	return err;
 }
 
-- 
2.43.0


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

end of thread, other threads:[~2026-08-03  8:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 13:36 [PATCH] f2fs: keep pinned fallocate failures section-aligned Wenjie Qi
2026-07-23 13:36 ` [f2fs-dev] " Wenjie Qi
2026-08-03  7:24 ` Chao Yu via Linux-f2fs-devel
2026-08-03  7:24   ` Chao Yu
2026-08-03  8:35   ` [f2fs-dev] " Wenjie Qi
2026-08-03  8:35     ` Wenjie Qi

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.