|
72 | 72 | #include "raid-stripe-tree.h"
|
73 | 73 | #include "fiemap.h"
|
74 | 74 |
|
| 75 | +#define COW_FILE_RANGE_KEEP_LOCKED (1UL << 0) |
| 76 | +#define COW_FILE_RANGE_NO_INLINE (1UL << 1) |
| 77 | + |
75 | 78 | struct btrfs_iget_args {
|
76 | 79 | u64 ino;
|
77 | 80 | struct btrfs_root *root;
|
@@ -1243,26 +1246,26 @@ u64 btrfs_get_extent_allocation_hint(struct btrfs_inode *inode, u64 start,
|
1243 | 1246 | * locked_folio is the folio that writepage had locked already. We use
|
1244 | 1247 | * it to make sure we don't do extra locks or unlocks.
|
1245 | 1248 | *
|
1246 |
| - * When this function fails, it unlocks all pages except @locked_folio. |
| 1249 | + * When this function fails, it unlocks all folios except @locked_folio. |
1247 | 1250 | *
|
1248 | 1251 | * 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). |
1252 | 1255 | *
|
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 |
1254 | 1257 | * status depends on the passed in flags:
|
1255 | 1258 | *
|
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. |
1258 | 1261 | *
|
1259 | 1262 | * When a failure happens in the second or later iteration of the
|
1260 | 1263 | * while-loop, the ordered extents created in previous iterations are cleaned up.
|
1261 | 1264 | */
|
1262 | 1265 | static noinline int cow_file_range(struct btrfs_inode *inode,
|
1263 | 1266 | struct folio *locked_folio, u64 start,
|
1264 | 1267 | u64 end, u64 *done_offset,
|
1265 |
| - bool keep_locked, bool no_inline) |
| 1268 | + unsigned long flags) |
1266 | 1269 | {
|
1267 | 1270 | struct btrfs_root *root = inode->root;
|
1268 | 1271 | struct btrfs_fs_info *fs_info = root->fs_info;
|
@@ -1290,7 +1293,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
|
1290 | 1293 |
|
1291 | 1294 | inode_should_defrag(inode, start, end, num_bytes, SZ_64K);
|
1292 | 1295 |
|
1293 |
| - if (!no_inline) { |
| 1296 | + if (!(flags & COW_FILE_RANGE_NO_INLINE)) { |
1294 | 1297 | /* lets try to make an inline extent */
|
1295 | 1298 | ret = cow_file_range_inline(inode, locked_folio, start, end, 0,
|
1296 | 1299 | BTRFS_COMPRESS_NONE, NULL, false);
|
@@ -1318,7 +1321,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
|
1318 | 1321 | * Do set the Ordered (Private2) bit so we know this page was properly
|
1319 | 1322 | * setup for writepage.
|
1320 | 1323 | */
|
1321 |
| - page_ops = (keep_locked ? 0 : PAGE_UNLOCK); |
| 1324 | + page_ops = ((flags & COW_FILE_RANGE_KEEP_LOCKED) ? 0 : PAGE_UNLOCK); |
1322 | 1325 | page_ops |= PAGE_SET_ORDERED;
|
1323 | 1326 |
|
1324 | 1327 | /*
|
@@ -1685,7 +1688,7 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode,
|
1685 | 1688 |
|
1686 | 1689 | while (start <= end) {
|
1687 | 1690 | ret = cow_file_range(inode, locked_folio, start, end,
|
1688 |
| - &done_offset, true, false); |
| 1691 | + &done_offset, COW_FILE_RANGE_KEEP_LOCKED); |
1689 | 1692 | if (ret)
|
1690 | 1693 | return ret;
|
1691 | 1694 | extent_write_locked_range(&inode->vfs_inode, locked_folio,
|
@@ -1767,8 +1770,8 @@ static int fallback_to_cow(struct btrfs_inode *inode,
|
1767 | 1770 | * is written out and unlocked directly and a normal NOCOW extent
|
1768 | 1771 | * doesn't work.
|
1769 | 1772 | */
|
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); |
1772 | 1775 | ASSERT(ret != 1);
|
1773 | 1776 | return ret;
|
1774 | 1777 | }
|
@@ -2347,8 +2350,7 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct folio *locked_fol
|
2347 | 2350 | ret = run_delalloc_cow(inode, locked_folio, start, end, wbc,
|
2348 | 2351 | true);
|
2349 | 2352 | 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); |
2352 | 2354 | return ret;
|
2353 | 2355 | }
|
2354 | 2356 |
|
|
0 commit comments