Commit df055afe authored by Goldwyn Rodrigues's avatar Goldwyn Rodrigues Committed by David Sterba

btrfs: page to folio conversion in btrfs_truncate_block()

Convert use of struct page to struct folio inside btrfs_truncate_block().
The only page based function is set_page_extent_mapped(). All other
functions have folio equivalents.

Had to use __filemap_get_folio() because filemap_grab_folio() does not
allow passing allocation mask as a parameter.
Signed-off-by: default avatarGoldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Reviewed-by: default avatarBoris Burkov <boris@bur.io>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent fae9cd25
...@@ -4695,7 +4695,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, ...@@ -4695,7 +4695,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len,
u32 blocksize = fs_info->sectorsize; u32 blocksize = fs_info->sectorsize;
pgoff_t index = from >> PAGE_SHIFT; pgoff_t index = from >> PAGE_SHIFT;
unsigned offset = from & (blocksize - 1); unsigned offset = from & (blocksize - 1);
struct page *page; struct folio *folio;
gfp_t mask = btrfs_alloc_write_mask(mapping); gfp_t mask = btrfs_alloc_write_mask(mapping);
size_t write_bytes = blocksize; size_t write_bytes = blocksize;
int ret = 0; int ret = 0;
...@@ -4727,8 +4727,9 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, ...@@ -4727,8 +4727,9 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len,
goto out; goto out;
} }
again: again:
page = find_or_create_page(mapping, index, mask); folio = __filemap_get_folio(mapping, index,
if (!page) { FGP_LOCK | FGP_ACCESSED | FGP_CREAT, mask);
if (IS_ERR(folio)) {
btrfs_delalloc_release_space(inode, data_reserved, block_start, btrfs_delalloc_release_space(inode, data_reserved, block_start,
blocksize, true); blocksize, true);
btrfs_delalloc_release_extents(inode, blocksize); btrfs_delalloc_release_extents(inode, blocksize);
...@@ -4736,15 +4737,15 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, ...@@ -4736,15 +4737,15 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len,
goto out; goto out;
} }
if (!PageUptodate(page)) { if (!folio_test_uptodate(folio)) {
ret = btrfs_read_folio(NULL, page_folio(page)); ret = btrfs_read_folio(NULL, folio);
lock_page(page); folio_lock(folio);
if (page->mapping != mapping) { if (folio->mapping != mapping) {
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
goto again; goto again;
} }
if (!PageUptodate(page)) { if (!folio_test_uptodate(folio)) {
ret = -EIO; ret = -EIO;
goto out_unlock; goto out_unlock;
} }
...@@ -4756,19 +4757,19 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, ...@@ -4756,19 +4757,19 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len,
* folio private, but left the page in the mapping. Set the page mapped * folio private, but left the page in the mapping. Set the page mapped
* here to make sure it's properly set for the subpage stuff. * here to make sure it's properly set for the subpage stuff.
*/ */
ret = set_page_extent_mapped(page); ret = set_folio_extent_mapped(folio);
if (ret < 0) if (ret < 0)
goto out_unlock; goto out_unlock;
wait_on_page_writeback(page); folio_wait_writeback(folio);
lock_extent(io_tree, block_start, block_end, &cached_state); lock_extent(io_tree, block_start, block_end, &cached_state);
ordered = btrfs_lookup_ordered_extent(inode, block_start); ordered = btrfs_lookup_ordered_extent(inode, block_start);
if (ordered) { if (ordered) {
unlock_extent(io_tree, block_start, block_end, &cached_state); unlock_extent(io_tree, block_start, block_end, &cached_state);
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
btrfs_start_ordered_extent(ordered); btrfs_start_ordered_extent(ordered);
btrfs_put_ordered_extent(ordered); btrfs_put_ordered_extent(ordered);
goto again; goto again;
...@@ -4789,15 +4790,16 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, ...@@ -4789,15 +4790,16 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len,
if (!len) if (!len)
len = blocksize - offset; len = blocksize - offset;
if (front) if (front)
memzero_page(page, (block_start - page_offset(page)), folio_zero_range(folio, block_start - folio_pos(folio),
offset); offset);
else else
memzero_page(page, (block_start - page_offset(page)) + offset, folio_zero_range(folio,
(block_start - folio_pos(folio)) + offset,
len); len);
} }
btrfs_folio_clear_checked(fs_info, page_folio(page), block_start, btrfs_folio_clear_checked(fs_info, folio, block_start,
block_end + 1 - block_start); block_end + 1 - block_start);
btrfs_folio_set_dirty(fs_info, page_folio(page), block_start, btrfs_folio_set_dirty(fs_info, folio, block_start,
block_end + 1 - block_start); block_end + 1 - block_start);
unlock_extent(io_tree, block_start, block_end, &cached_state); unlock_extent(io_tree, block_start, block_end, &cached_state);
...@@ -4814,8 +4816,8 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, ...@@ -4814,8 +4816,8 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len,
block_start, blocksize, true); block_start, blocksize, true);
} }
btrfs_delalloc_release_extents(inode, blocksize); btrfs_delalloc_release_extents(inode, blocksize);
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
out: out:
if (only_release_metadata) if (only_release_metadata)
btrfs_check_nocow_unlock(inode); btrfs_check_nocow_unlock(inode);
......
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