]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: convert find_lock_delalloc_range() to use a folio
authorJosef Bacik <josef@toxicpanda.com>
Wed, 24 Jul 2024 20:08:13 +0000 (16:08 -0400)
committerDavid Sterba <dsterba@suse.com>
Tue, 10 Sep 2024 14:51:14 +0000 (16:51 +0200)
Instead of passing in a page for locked_page, pass in the folio instead.
We only use the folio itself to validate some range assumptions, and
then pass it into other functions.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c
fs/btrfs/extent_io.h
fs/btrfs/tests/extent-io-tests.c

index 1c784f7e6858d0ab2dc045dd6e4db70ddcf0870f..b9921b8235e248f871961396ea369dfa763fa94e 100644 (file)
@@ -304,8 +304,8 @@ out:
  */
 EXPORT_FOR_TESTS
 noinline_for_stack bool find_lock_delalloc_range(struct inode *inode,
-                                   struct page *locked_page, u64 *start,
-                                   u64 *end)
+                                                struct folio *locked_folio,
+                                                u64 *start, u64 *end)
 {
        struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
        struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
@@ -323,9 +323,9 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode,
        /* Caller should pass a valid @end to indicate the search range end */
        ASSERT(orig_end > orig_start);
 
-       /* The range should at least cover part of the page */
-       ASSERT(!(orig_start >= page_offset(locked_page) + PAGE_SIZE ||
-                orig_end <= page_offset(locked_page)));
+       /* The range should at least cover part of the folio */
+       ASSERT(!(orig_start >= folio_pos(locked_folio) + folio_size(locked_folio) ||
+                orig_end <= folio_pos(locked_folio)));
 again:
        /* step one, find a bunch of delalloc bytes starting at start */
        delalloc_start = *start;
@@ -342,25 +342,25 @@ again:
        }
 
        /*
-        * start comes from the offset of locked_page.  We have to lock
-        * pages in order, so we can't process delalloc bytes before
-        * locked_page
+        * start comes from the offset of locked_folio.  We have to lock
+        * folios in order, so we can't process delalloc bytes before
+        * locked_folio
         */
        if (delalloc_start < *start)
                delalloc_start = *start;
 
        /*
-        * make sure to limit the number of pages we try to lock down
+        * make sure to limit the number of folios we try to lock down
         */
        if (delalloc_end + 1 - delalloc_start > max_bytes)
                delalloc_end = delalloc_start + max_bytes - 1;
 
-       /* step two, lock all the pages after the page that has start */
-       ret = lock_delalloc_pages(inode, locked_page,
+       /* step two, lock all the folioss after the folios that has start */
+       ret = lock_delalloc_pages(inode, &locked_folio->page,
                                  delalloc_start, delalloc_end);
        ASSERT(!ret || ret == -EAGAIN);
        if (ret == -EAGAIN) {
-               /* some of the pages are gone, lets avoid looping by
+               /* some of the folios are gone, lets avoid looping by
                 * shortening the size of the delalloc range we're searching
                 */
                free_extent_state(cached_state);
@@ -384,7 +384,7 @@ again:
 
        unlock_extent(tree, delalloc_start, delalloc_end, &cached_state);
        if (!ret) {
-               __unlock_for_delalloc(inode, locked_page,
+               __unlock_for_delalloc(inode, &locked_folio->page,
                              delalloc_start, delalloc_end);
                cond_resched();
                goto again;
@@ -1209,7 +1209,7 @@ static noinline_for_stack int writepage_delalloc(struct btrfs_inode *inode,
        /* Lock all (subpage) delalloc ranges inside the folio first. */
        while (delalloc_start < page_end) {
                delalloc_end = page_end;
-               if (!find_lock_delalloc_range(&inode->vfs_inode, &folio->page,
+               if (!find_lock_delalloc_range(&inode->vfs_inode, folio,
                                              &delalloc_start, &delalloc_end)) {
                        delalloc_start = delalloc_end + 1;
                        continue;
index dceebd76c7d17d2821a9cc41fb9b4f5a285a4add..1dd295e1b5a5d78efa0878c5a50bd9ac479eebb9 100644 (file)
@@ -368,7 +368,7 @@ int btrfs_alloc_folio_array(unsigned int nr_folios, struct folio **folio_array);
 
 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
 bool find_lock_delalloc_range(struct inode *inode,
-                            struct page *locked_page, u64 *start,
+                             struct folio *locked_folio, u64 *start,
                             u64 *end);
 #endif
 struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
index 865d4af4b30356898acbe587ac0844956f836a57..0a2dbfaaf49e292baf8d92df33ae8d876a94556e 100644 (file)
@@ -180,7 +180,7 @@ static int test_find_delalloc(u32 sectorsize, u32 nodesize)
        set_extent_bit(tmp, 0, sectorsize - 1, EXTENT_DELALLOC, NULL);
        start = 0;
        end = start + PAGE_SIZE - 1;
-       found = find_lock_delalloc_range(inode, locked_page, &start,
+       found = find_lock_delalloc_range(inode, page_folio(locked_page), &start,
                                         &end);
        if (!found) {
                test_err("should have found at least one delalloc");
@@ -211,7 +211,7 @@ static int test_find_delalloc(u32 sectorsize, u32 nodesize)
        set_extent_bit(tmp, sectorsize, max_bytes - 1, EXTENT_DELALLOC, NULL);
        start = test_start;
        end = start + PAGE_SIZE - 1;
-       found = find_lock_delalloc_range(inode, locked_page, &start,
+       found = find_lock_delalloc_range(inode, page_folio(locked_page), &start,
                                         &end);
        if (!found) {
                test_err("couldn't find delalloc in our range");
@@ -245,7 +245,7 @@ static int test_find_delalloc(u32 sectorsize, u32 nodesize)
        }
        start = test_start;
        end = start + PAGE_SIZE - 1;
-       found = find_lock_delalloc_range(inode, locked_page, &start,
+       found = find_lock_delalloc_range(inode, page_folio(locked_page), &start,
                                         &end);
        if (found) {
                test_err("found range when we shouldn't have");
@@ -266,7 +266,7 @@ static int test_find_delalloc(u32 sectorsize, u32 nodesize)
        set_extent_bit(tmp, max_bytes, total_dirty - 1, EXTENT_DELALLOC, NULL);
        start = test_start;
        end = start + PAGE_SIZE - 1;
-       found = find_lock_delalloc_range(inode, locked_page, &start,
+       found = find_lock_delalloc_range(inode, page_folio(locked_page), &start,
                                         &end);
        if (!found) {
                test_err("didn't find our range");
@@ -307,7 +307,7 @@ static int test_find_delalloc(u32 sectorsize, u32 nodesize)
         * this changes at any point in the future we will need to fix this
         * tests expected behavior.
         */
-       found = find_lock_delalloc_range(inode, locked_page, &start,
+       found = find_lock_delalloc_range(inode, page_folio(locked_page), &start,
                                         &end);
        if (!found) {
                test_err("didn't find our range");