Commit e4d80ebe authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: convert lock_delalloc_pages() to take a folio

Also rename lock_delalloc_pages => lock_delalloc_folios in the process,
now that it exclusively works on folios.
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 c987f1e6
...@@ -230,10 +230,9 @@ static noinline void __unlock_for_delalloc(const struct inode *inode, ...@@ -230,10 +230,9 @@ static noinline void __unlock_for_delalloc(const struct inode *inode,
PAGE_UNLOCK); PAGE_UNLOCK);
} }
static noinline int lock_delalloc_pages(struct inode *inode, static noinline int lock_delalloc_folios(struct inode *inode,
const struct page *locked_page, const struct folio *locked_folio,
u64 start, u64 start, u64 end)
u64 end)
{ {
struct btrfs_fs_info *fs_info = inode_to_fs_info(inode); struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
struct address_space *mapping = inode->i_mapping; struct address_space *mapping = inode->i_mapping;
...@@ -243,7 +242,7 @@ static noinline int lock_delalloc_pages(struct inode *inode, ...@@ -243,7 +242,7 @@ static noinline int lock_delalloc_pages(struct inode *inode,
u64 processed_end = start; u64 processed_end = start;
struct folio_batch fbatch; struct folio_batch fbatch;
if (index == locked_page->index && index == end_index) if (index == locked_folio->index && index == end_index)
return 0; return 0;
folio_batch_init(&fbatch); folio_batch_init(&fbatch);
...@@ -257,23 +256,22 @@ static noinline int lock_delalloc_pages(struct inode *inode, ...@@ -257,23 +256,22 @@ static noinline int lock_delalloc_pages(struct inode *inode,
for (i = 0; i < found_folios; i++) { for (i = 0; i < found_folios; i++) {
struct folio *folio = fbatch.folios[i]; struct folio *folio = fbatch.folios[i];
struct page *page = folio_page(folio, 0);
u32 len = end + 1 - start; u32 len = end + 1 - start;
if (page == locked_page) if (folio == locked_folio)
continue; continue;
if (btrfs_folio_start_writer_lock(fs_info, folio, start, if (btrfs_folio_start_writer_lock(fs_info, folio, start,
len)) len))
goto out; goto out;
if (!PageDirty(page) || page->mapping != mapping) { if (!folio_test_dirty(folio) || folio->mapping != mapping) {
btrfs_folio_end_writer_lock(fs_info, folio, start, btrfs_folio_end_writer_lock(fs_info, folio, start,
len); len);
goto out; goto out;
} }
processed_end = page_offset(page) + PAGE_SIZE - 1; processed_end = folio_pos(folio) + folio_size(folio) - 1;
} }
folio_batch_release(&fbatch); folio_batch_release(&fbatch);
cond_resched(); cond_resched();
...@@ -283,7 +281,8 @@ static noinline int lock_delalloc_pages(struct inode *inode, ...@@ -283,7 +281,8 @@ static noinline int lock_delalloc_pages(struct inode *inode,
out: out:
folio_batch_release(&fbatch); folio_batch_release(&fbatch);
if (processed_end > start) if (processed_end > start)
__unlock_for_delalloc(inode, locked_page, start, processed_end); __unlock_for_delalloc(inode, &locked_folio->page, start,
processed_end);
return -EAGAIN; return -EAGAIN;
} }
...@@ -356,8 +355,8 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode, ...@@ -356,8 +355,8 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode,
delalloc_end = delalloc_start + max_bytes - 1; delalloc_end = delalloc_start + max_bytes - 1;
/* step two, lock all the folioss after the folios that has start */ /* step two, lock all the folioss after the folios that has start */
ret = lock_delalloc_pages(inode, &locked_folio->page, ret = lock_delalloc_folios(inode, locked_folio, delalloc_start,
delalloc_start, delalloc_end); delalloc_end);
ASSERT(!ret || ret == -EAGAIN); ASSERT(!ret || ret == -EAGAIN);
if (ret == -EAGAIN) { if (ret == -EAGAIN) {
/* some of the folios are gone, lets avoid looping by /* some of the folios are gone, lets avoid looping by
......
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