diff mbox series

[f2fs-dev,v2,09/13] f2fs: fix data loss during inline tail writing

Message ID 067f905e4f3b71727cfada291b090896463ef796.1726024117.git.bo.wu@vivo.com (mailing list archive)
State New
Headers show
Series f2fs: introduce inline tail | expand

Commit Message

Wu Bo Sept. 11, 2024, 3:57 a.m. UTC
This is detected by xfstest generic/114. The inline data needs to be
read out before writing to avoid losing the already inline data.

Signed-off-by: Wu Bo <bo.wu@vivo.com>
---
 fs/f2fs/data.c | 3 ++-
 fs/f2fs/file.c | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 476325a26d4e..275c5739993e 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3477,7 +3477,8 @@  static int prepare_write_begin(struct f2fs_sb_info *sbi,
 			if (inode->i_nlink)
 				set_page_private_inline(ipage);
 			goto out;
-		}
+		} else if (f2fs_exist_data(inode))
+			f2fs_do_read_inline_data(page_folio(page), ipage);
 	}
 
 	if (!f2fs_lookup_read_extent_cache_block(inode, index,
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 2551403a5b83..64ea0bfc2e1e 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4729,7 +4729,7 @@  static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,
 
 	if (f2fs_has_inline_tail(inode) &&
 			(pos + count > MAX_INLINE_TAIL(inode))) {
-		ret = f2fs_clear_inline_tail(inode, true);
+		ret = f2fs_convert_inline_tail(inode);
 		if (ret)
 			return ret;
 	}
@@ -4842,6 +4842,7 @@  static ssize_t f2fs_dio_write_iter(struct kiocb *iocb, struct iov_iter *from,
 	if (iocb->ki_flags & IOCB_NOWAIT) {
 		/* f2fs_convert_inline_inode() and block allocation can block */
 		if (f2fs_has_inline_data(inode) ||
+		    f2fs_has_inline_tail(inode) ||
 		    !f2fs_overwrite_io(inode, pos, count)) {
 			ret = -EAGAIN;
 			goto out;
@@ -4861,6 +4862,10 @@  static ssize_t f2fs_dio_write_iter(struct kiocb *iocb, struct iov_iter *from,
 		if (ret)
 			goto out;
 
+		ret = f2fs_convert_inline_tail(inode);
+		if (ret)
+			goto out;
+
 		f2fs_down_read(&fi->i_gc_rwsem[WRITE]);
 		if (do_opu)
 			f2fs_down_read(&fi->i_gc_rwsem[READ]);