Commit 4cf7e056 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: convert cow_file_range() to take a folio

Convert this to take a folio and pass it into all of the various cleanup
functions.  Update the callers to pass in a folio instead.
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 9f5db280
...@@ -1307,21 +1307,21 @@ u64 btrfs_get_extent_allocation_hint(struct btrfs_inode *inode, u64 start, ...@@ -1307,21 +1307,21 @@ u64 btrfs_get_extent_allocation_hint(struct btrfs_inode *inode, u64 start,
* allocate extents on disk for the range, and create ordered data structs * allocate extents on disk for the range, and create ordered data structs
* in ram to track those extents. * in ram to track those extents.
* *
* locked_page is the page that writepage had locked already. We use * locked_folio is the folio that writepage had locked already. We use
* it to make sure we don't do extra locks or unlocks. * it to make sure we don't do extra locks or unlocks.
* *
* When this function fails, it unlocks all pages except @locked_page. * When this function fails, it unlocks all pages except @locked_folio.
* *
* When this function successfully creates an inline extent, it returns 1 and * When this function successfully creates an inline extent, it returns 1 and
* unlocks all pages including locked_page and starts I/O on them. * unlocks all pages including locked_folio and starts I/O on them.
* (In reality inline extents are limited to a single page, so locked_page is * (In reality inline extents are limited to a single page, so locked_folio is
* the only page handled anyway). * the only page handled anyway).
* *
* When this function succeed and creates a normal extent, the page locking * When this function succeed and creates a normal extent, the page locking
* status depends on the passed in flags: * status depends on the passed in flags:
* *
* - If @keep_locked is set, all pages are kept locked. * - If @keep_locked is set, all pages are kept locked.
* - Else all pages except for @locked_page are unlocked. * - Else all pages except for @locked_folio are unlocked.
* *
* When a failure happens in the second or later iteration of the * When a failure happens in the second or later iteration of the
* while-loop, the ordered extents created in previous iterations are kept * while-loop, the ordered extents created in previous iterations are kept
...@@ -1330,8 +1330,8 @@ u64 btrfs_get_extent_allocation_hint(struct btrfs_inode *inode, u64 start, ...@@ -1330,8 +1330,8 @@ u64 btrfs_get_extent_allocation_hint(struct btrfs_inode *inode, u64 start,
* example. * example.
*/ */
static noinline int cow_file_range(struct btrfs_inode *inode, static noinline int cow_file_range(struct btrfs_inode *inode,
struct page *locked_page, u64 start, u64 end, struct folio *locked_folio, u64 start,
u64 *done_offset, u64 end, u64 *done_offset,
bool keep_locked, bool no_inline) bool keep_locked, bool no_inline)
{ {
struct btrfs_root *root = inode->root; struct btrfs_root *root = inode->root;
...@@ -1364,9 +1364,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1364,9 +1364,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
if (!no_inline) { if (!no_inline) {
/* lets try to make an inline extent */ /* lets try to make an inline extent */
ret = cow_file_range_inline(inode, page_folio(locked_page), ret = cow_file_range_inline(inode, locked_folio, start, end, 0,
start, end, 0, BTRFS_COMPRESS_NONE, BTRFS_COMPRESS_NONE, NULL, false);
NULL, false);
if (ret <= 0) { if (ret <= 0) {
/* /*
* We succeeded, return 1 so the caller knows we're done * We succeeded, return 1 so the caller knows we're done
...@@ -1502,7 +1501,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1502,7 +1501,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
page_ops |= PAGE_SET_ORDERED; page_ops |= PAGE_SET_ORDERED;
extent_clear_unlock_delalloc(inode, start, start + ram_size - 1, extent_clear_unlock_delalloc(inode, start, start + ram_size - 1,
page_folio(locked_page), &cached, locked_folio, &cached,
EXTENT_LOCKED | EXTENT_DELALLOC, EXTENT_LOCKED | EXTENT_DELALLOC,
page_ops); page_ops);
if (num_bytes < cur_alloc_size) if (num_bytes < cur_alloc_size)
...@@ -1555,14 +1554,13 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1555,14 +1554,13 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
* function. * function.
* *
* However, in case of @keep_locked, we still need to unlock the pages * However, in case of @keep_locked, we still need to unlock the pages
* (except @locked_page) to ensure all the pages are unlocked. * (except @locked_folio) to ensure all the pages are unlocked.
*/ */
if (keep_locked && orig_start < start) { if (keep_locked && orig_start < start) {
if (!locked_page) if (!locked_folio)
mapping_set_error(inode->vfs_inode.i_mapping, ret); mapping_set_error(inode->vfs_inode.i_mapping, ret);
extent_clear_unlock_delalloc(inode, orig_start, start - 1, extent_clear_unlock_delalloc(inode, orig_start, start - 1,
page_folio(locked_page), NULL, 0, locked_folio, NULL, 0, page_ops);
page_ops);
} }
/* /*
...@@ -1585,8 +1583,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1585,8 +1583,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
if (extent_reserved) { if (extent_reserved) {
extent_clear_unlock_delalloc(inode, start, extent_clear_unlock_delalloc(inode, start,
start + cur_alloc_size - 1, start + cur_alloc_size - 1,
page_folio(locked_page), &cached, locked_folio, &cached, clear_bits,
clear_bits,
page_ops); page_ops);
btrfs_qgroup_free_data(inode, NULL, start, cur_alloc_size, NULL); btrfs_qgroup_free_data(inode, NULL, start, cur_alloc_size, NULL);
start += cur_alloc_size; start += cur_alloc_size;
...@@ -1600,9 +1597,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1600,9 +1597,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
*/ */
if (start < end) { if (start < end) {
clear_bits |= EXTENT_CLEAR_DATA_RESV; clear_bits |= EXTENT_CLEAR_DATA_RESV;
extent_clear_unlock_delalloc(inode, start, end, extent_clear_unlock_delalloc(inode, start, end, locked_folio,
page_folio(locked_page), &cached, &cached, clear_bits, page_ops);
clear_bits, page_ops);
btrfs_qgroup_free_data(inode, NULL, start, cur_alloc_size, NULL); btrfs_qgroup_free_data(inode, NULL, start, cur_alloc_size, NULL);
} }
return ret; return ret;
...@@ -1755,7 +1751,7 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode, ...@@ -1755,7 +1751,7 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode,
int ret; int ret;
while (start <= end) { while (start <= end) {
ret = cow_file_range(inode, &locked_folio->page, start, end, ret = cow_file_range(inode, locked_folio, start, end,
&done_offset, true, false); &done_offset, true, false);
if (ret) if (ret)
return ret; return ret;
...@@ -1837,7 +1833,8 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, ...@@ -1837,7 +1833,8 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page,
* is written out and unlocked directly and a normal NOCOW extent * is written out and unlocked directly and a normal NOCOW extent
* doesn't work. * doesn't work.
*/ */
ret = cow_file_range(inode, locked_page, start, end, NULL, false, true); ret = cow_file_range(inode, page_folio(locked_page), start, end, NULL,
false, true);
ASSERT(ret != 1); ASSERT(ret != 1);
return ret; return ret;
} }
...@@ -2314,8 +2311,8 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page ...@@ -2314,8 +2311,8 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page
ret = run_delalloc_cow(inode, page_folio(locked_page), start, ret = run_delalloc_cow(inode, page_folio(locked_page), start,
end, wbc, true); end, wbc, true);
else else
ret = cow_file_range(inode, locked_page, start, end, NULL, ret = cow_file_range(inode, page_folio(locked_page), start, end,
false, false); NULL, false, false);
out: out:
if (ret < 0) if (ret < 0)
......
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