Skip to content

Commit 7a3c944

Browse files
adam900710kdave
authored andcommitted
btrfs: replace double boolean parameters of cow_file_range()
The function cow_file_range() has two boolean parameters, which is never a good thing for eyes. Replace it with a single @flags parameter, with two flags: - COW_FILE_RANGE_NO_INLINE - COW_FILE_RANGE_KEEP_LOCKED And since we're here, also update the comments of cow_file_range() to replace the old "page" usage with "folio". Reviewed-by: Boris Burkov <[email protected]> Signed-off-by: Qu Wenruo <[email protected]>
1 parent eb11326 commit 7a3c944

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

fs/btrfs/inode.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
#include "raid-stripe-tree.h"
7373
#include "fiemap.h"
7474

75+
#define COW_FILE_RANGE_KEEP_LOCKED (1UL << 0)
76+
#define COW_FILE_RANGE_NO_INLINE (1UL << 1)
77+
7578
struct btrfs_iget_args {
7679
u64 ino;
7780
struct btrfs_root *root;
@@ -1243,26 +1246,26 @@ u64 btrfs_get_extent_allocation_hint(struct btrfs_inode *inode, u64 start,
12431246
* locked_folio is the folio that writepage had locked already. We use
12441247
* it to make sure we don't do extra locks or unlocks.
12451248
*
1246-
* When this function fails, it unlocks all pages except @locked_folio.
1249+
* When this function fails, it unlocks all folios except @locked_folio.
12471250
*
12481251
* When this function successfully creates an inline extent, it returns 1 and
1249-
* unlocks all pages including locked_folio and starts I/O on them.
1250-
* (In reality inline extents are limited to a single page, so locked_folio is
1251-
* the only page handled anyway).
1252+
* unlocks all folios including locked_folio and starts I/O on them.
1253+
* (In reality inline extents are limited to a single block, so locked_folio is
1254+
* the only folio handled anyway).
12521255
*
1253-
* When this function succeed and creates a normal extent, the page locking
1256+
* When this function succeed and creates a normal extent, the folio locking
12541257
* status depends on the passed in flags:
12551258
*
1256-
* - If @keep_locked is set, all pages are kept locked.
1257-
* - Else all pages except for @locked_folio are unlocked.
1259+
* - If COW_FILE_RANGE_KEEP_LOCKED flag is set, all folios are kept locked.
1260+
* - Else all folios except for @locked_folio are unlocked.
12581261
*
12591262
* When a failure happens in the second or later iteration of the
12601263
* while-loop, the ordered extents created in previous iterations are cleaned up.
12611264
*/
12621265
static noinline int cow_file_range(struct btrfs_inode *inode,
12631266
struct folio *locked_folio, u64 start,
12641267
u64 end, u64 *done_offset,
1265-
bool keep_locked, bool no_inline)
1268+
unsigned long flags)
12661269
{
12671270
struct btrfs_root *root = inode->root;
12681271
struct btrfs_fs_info *fs_info = root->fs_info;
@@ -1290,7 +1293,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
12901293

12911294
inode_should_defrag(inode, start, end, num_bytes, SZ_64K);
12921295

1293-
if (!no_inline) {
1296+
if (!(flags & COW_FILE_RANGE_NO_INLINE)) {
12941297
/* lets try to make an inline extent */
12951298
ret = cow_file_range_inline(inode, locked_folio, start, end, 0,
12961299
BTRFS_COMPRESS_NONE, NULL, false);
@@ -1318,7 +1321,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
13181321
* Do set the Ordered (Private2) bit so we know this page was properly
13191322
* setup for writepage.
13201323
*/
1321-
page_ops = (keep_locked ? 0 : PAGE_UNLOCK);
1324+
page_ops = ((flags & COW_FILE_RANGE_KEEP_LOCKED) ? 0 : PAGE_UNLOCK);
13221325
page_ops |= PAGE_SET_ORDERED;
13231326

13241327
/*
@@ -1685,7 +1688,7 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode,
16851688

16861689
while (start <= end) {
16871690
ret = cow_file_range(inode, locked_folio, start, end,
1688-
&done_offset, true, false);
1691+
&done_offset, COW_FILE_RANGE_KEEP_LOCKED);
16891692
if (ret)
16901693
return ret;
16911694
extent_write_locked_range(&inode->vfs_inode, locked_folio,
@@ -1767,8 +1770,8 @@ static int fallback_to_cow(struct btrfs_inode *inode,
17671770
* is written out and unlocked directly and a normal NOCOW extent
17681771
* doesn't work.
17691772
*/
1770-
ret = cow_file_range(inode, locked_folio, start, end, NULL, false,
1771-
true);
1773+
ret = cow_file_range(inode, locked_folio, start, end, NULL,
1774+
COW_FILE_RANGE_NO_INLINE);
17721775
ASSERT(ret != 1);
17731776
return ret;
17741777
}
@@ -2347,8 +2350,7 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct folio *locked_fol
23472350
ret = run_delalloc_cow(inode, locked_folio, start, end, wbc,
23482351
true);
23492352
else
2350-
ret = cow_file_range(inode, locked_folio, start, end, NULL,
2351-
false, false);
2353+
ret = cow_file_range(inode, locked_folio, start, end, NULL, 0);
23522354
return ret;
23532355
}
23542356

0 commit comments

Comments
 (0)