Commit 83eba701 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Theodore Ts'o

ext4: Convert ext4_convert_inline_data_to_extent() to use a folio

Saves a number of calls to compound_head().
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Link: https://lore.kernel.org/r/20230324180129.1220691-11-willy@infradead.orgSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 3edde93e
...@@ -534,8 +534,7 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, ...@@ -534,8 +534,7 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
int ret, needed_blocks, no_expand; int ret, needed_blocks, no_expand;
handle_t *handle = NULL; handle_t *handle = NULL;
int retries = 0, sem_held = 0; int retries = 0, sem_held = 0;
struct page *page = NULL; struct folio *folio = NULL;
unsigned int flags;
unsigned from, to; unsigned from, to;
struct ext4_iloc iloc; struct ext4_iloc iloc;
...@@ -564,10 +563,9 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, ...@@ -564,10 +563,9 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
/* We cannot recurse into the filesystem as the transaction is already /* We cannot recurse into the filesystem as the transaction is already
* started */ * started */
flags = memalloc_nofs_save(); folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN | FGP_NOFS,
page = grab_cache_page_write_begin(mapping, 0); mapping_gfp_mask(mapping));
memalloc_nofs_restore(flags); if (!folio) {
if (!page) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
...@@ -582,8 +580,8 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, ...@@ -582,8 +580,8 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
from = 0; from = 0;
to = ext4_get_inline_size(inode); to = ext4_get_inline_size(inode);
if (!PageUptodate(page)) { if (!folio_test_uptodate(folio)) {
ret = ext4_read_inline_page(inode, page); ret = ext4_read_inline_page(inode, &folio->page);
if (ret < 0) if (ret < 0)
goto out; goto out;
} }
...@@ -593,21 +591,21 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, ...@@ -593,21 +591,21 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
goto out; goto out;
if (ext4_should_dioread_nolock(inode)) { if (ext4_should_dioread_nolock(inode)) {
ret = __block_write_begin(page, from, to, ret = __block_write_begin(&folio->page, from, to,
ext4_get_block_unwritten); ext4_get_block_unwritten);
} else } else
ret = __block_write_begin(page, from, to, ext4_get_block); ret = __block_write_begin(&folio->page, from, to, ext4_get_block);
if (!ret && ext4_should_journal_data(inode)) { if (!ret && ext4_should_journal_data(inode)) {
ret = ext4_walk_page_buffers(handle, inode, page_buffers(page), ret = ext4_walk_page_buffers(handle, inode,
from, to, NULL, folio_buffers(folio), from, to,
do_journal_get_write_access); NULL, do_journal_get_write_access);
} }
if (ret) { if (ret) {
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
page = NULL; folio = NULL;
ext4_orphan_add(handle, inode); ext4_orphan_add(handle, inode);
ext4_write_unlock_xattr(inode, &no_expand); ext4_write_unlock_xattr(inode, &no_expand);
sem_held = 0; sem_held = 0;
...@@ -627,12 +625,12 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, ...@@ -627,12 +625,12 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
goto retry; goto retry;
if (page) if (folio)
block_commit_write(page, from, to); block_commit_write(&folio->page, from, to);
out: out:
if (page) { if (folio) {
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
} }
if (sem_held) if (sem_held)
ext4_write_unlock_xattr(inode, &no_expand); ext4_write_unlock_xattr(inode, &no_expand);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment