diff mbox series

[f2fs-dev,08/13] f2fs: convert inline tail when inode expand

Message ID a76b4bcb04c636b7e40443a9c372679db67fdb6d.1725334811.git.bo.wu@vivo.com (mailing list archive)
State Superseded
Headers show
Series f2fs: introduce inline tail | expand

Commit Message

Wu Bo Sept. 3, 2024, 8:54 a.m. UTC
Convert an inline tail file to a normal file when the inode expansion
exceeds the maximum size allowed for the inline tail.

Signed-off-by: Wu Bo <bo.wu@vivo.com>
---
 fs/f2fs/f2fs.h   |  1 +
 fs/f2fs/file.c   |  6 ++++++
 fs/f2fs/inline.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
diff mbox series

Patch

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 2e0530b55e74..f889d97209c7 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4211,6 +4211,7 @@  void f2fs_truncate_inline_inode(struct inode *inode,
 						struct page *ipage, u64 from);
 int f2fs_read_inline_data(struct inode *inode, struct folio *folio);
 int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page);
+int f2fs_convert_inline_tail(struct inode *inode);
 int f2fs_convert_inline_inode(struct inode *inode);
 int f2fs_clear_inline_tail(struct inode *inode, bool force);
 int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index dda4cf6d7325..2551403a5b83 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1783,6 +1783,12 @@  static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
 	if (err)
 		return err;
 
+	if (len + offset > MAX_INLINE_TAIL(inode)) {
+		err = f2fs_convert_inline_tail(inode);
+		if (err)
+			return err;
+	}
+
 	f2fs_balance_fs(sbi, true);
 
 	pg_start = ((unsigned long long)offset) >> PAGE_SHIFT;
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index a542956d618a..c2f84f3dde67 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -235,6 +235,49 @@  int f2fs_clear_inline_tail(struct inode *inode, bool force)
 	return 0;
 }
 
+int f2fs_convert_inline_tail(struct inode *inode)
+{
+	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+	struct dnode_of_data dn;
+	struct page *ipage, *page;
+	loff_t i_size = i_size_read(inode);
+	pgoff_t end_index = i_size >> PAGE_SHIFT;
+	int err = 0;
+
+	if (!f2fs_has_inline_tail(inode))
+		return 0;
+
+	page = f2fs_grab_cache_page(inode->i_mapping, end_index, false);
+	if (!page)
+		return -ENOMEM;
+
+	f2fs_lock_op(sbi);
+
+	ipage = f2fs_get_node_page(sbi, inode->i_ino);
+	if (IS_ERR(ipage)) {
+		err = PTR_ERR(ipage);
+		goto out;
+	}
+
+	set_new_dnode(&dn, inode, ipage, ipage, 0);
+
+	if (f2fs_has_inline_tail(inode))
+		err = f2fs_convert_inline_page(&dn, page);
+
+	f2fs_put_dnode(&dn);
+out:
+	f2fs_unlock_op(sbi);
+
+	f2fs_put_page(page, 1);
+
+	if (!err) {
+		err = f2fs_clear_inline_tail(inode, true);
+		f2fs_balance_fs(sbi, dn.node_changed);
+	}
+
+	return err;
+}
+
 int f2fs_convert_inline_inode(struct inode *inode)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);