Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs: a couple cleanups in replay_one_extent()
@ 2025-09-18 12:42 fdmanana
  2025-09-18 12:42 ` [PATCH 1/2] btrfs: fix comment about nbytes increase at replay_one_extent() fdmanana
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: fdmanana @ 2025-09-18 12:42 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

Trivial changes, details in the changelogs.

Filipe Manana (2):
  btrfs: fix comment about nbytes increase at replay_one_extent()
  btrfs: simplify inline extent end calculation at replay_one_extent()

 fs/btrfs/tree-log.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

-- 
2.47.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] btrfs: fix comment about nbytes increase at replay_one_extent()
  2025-09-18 12:42 [PATCH 0/2] btrfs: a couple cleanups in replay_one_extent() fdmanana
@ 2025-09-18 12:42 ` fdmanana
  2025-09-18 12:42 ` [PATCH 2/2] btrfs: simplify inline extent end calculation " fdmanana
  2025-09-18 21:10 ` [PATCH 0/2] btrfs: a couple cleanups in replay_one_extent() Qu Wenruo
  2 siblings, 0 replies; 4+ messages in thread
From: fdmanana @ 2025-09-18 12:42 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

The comment is wrong about the part where it says a prealloc extent does
not contribute to an inode's nbytes - it does. Only holes don't contribute
and that's what we are checking for, as prealloc extents always have a
disk_bytenr different from 0. So fix the comment and re-organize the code
to not set nbytes twice and set it to the extent item's number of bytes
only if it doesn't represent a hole - in case it's a hole we have already
initialized nbytes to 0 when we declared it.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/tree-log.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 144b12725365..96492080fed8 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -740,15 +740,10 @@ static noinline int replay_one_extent(struct walk_control *wc)
 
 	if (found_type == BTRFS_FILE_EXTENT_REG ||
 	    found_type == BTRFS_FILE_EXTENT_PREALLOC) {
-		nbytes = btrfs_file_extent_num_bytes(wc->log_leaf, item);
-		extent_end = start + nbytes;
-
-		/*
-		 * We don't add to the inodes nbytes if we are prealloc or a
-		 * hole.
-		 */
-		if (btrfs_file_extent_disk_bytenr(wc->log_leaf, item) == 0)
-			nbytes = 0;
+		extent_end = start + btrfs_file_extent_num_bytes(wc->log_leaf, item);
+		/* Holes don't take up space. */
+		if (btrfs_file_extent_disk_bytenr(wc->log_leaf, item) != 0)
+			nbytes = btrfs_file_extent_num_bytes(wc->log_leaf, item);
 	} else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
 		size = btrfs_file_extent_ram_bytes(wc->log_leaf, item);
 		nbytes = btrfs_file_extent_ram_bytes(wc->log_leaf, item);
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] btrfs: simplify inline extent end calculation at replay_one_extent()
  2025-09-18 12:42 [PATCH 0/2] btrfs: a couple cleanups in replay_one_extent() fdmanana
  2025-09-18 12:42 ` [PATCH 1/2] btrfs: fix comment about nbytes increase at replay_one_extent() fdmanana
@ 2025-09-18 12:42 ` fdmanana
  2025-09-18 21:10 ` [PATCH 0/2] btrfs: a couple cleanups in replay_one_extent() Qu Wenruo
  2 siblings, 0 replies; 4+ messages in thread
From: fdmanana @ 2025-09-18 12:42 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

There is no need to store the extent's ram_bytes in two variables,
further more one of them, named 'size', is used only for the extent's end
offset calculation. So remove the 'size' variable and use 'nbytes' only.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/tree-log.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 96492080fed8..ac7805d40ab2 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -732,7 +732,6 @@ static noinline int replay_one_extent(struct walk_control *wc)
 	struct btrfs_key ins;
 	struct btrfs_file_extent_item *item;
 	struct btrfs_inode *inode = NULL;
-	unsigned long size;
 	int ret = 0;
 
 	item = btrfs_item_ptr(wc->log_leaf, wc->log_slot, struct btrfs_file_extent_item);
@@ -745,10 +744,8 @@ static noinline int replay_one_extent(struct walk_control *wc)
 		if (btrfs_file_extent_disk_bytenr(wc->log_leaf, item) != 0)
 			nbytes = btrfs_file_extent_num_bytes(wc->log_leaf, item);
 	} else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
-		size = btrfs_file_extent_ram_bytes(wc->log_leaf, item);
 		nbytes = btrfs_file_extent_ram_bytes(wc->log_leaf, item);
-		extent_end = ALIGN(start + size,
-				   fs_info->sectorsize);
+		extent_end = ALIGN(start + nbytes, fs_info->sectorsize);
 	} else {
 		btrfs_abort_log_replay(wc, -EUCLEAN,
 		       "unexpected extent type=%d root=%llu inode=%llu offset=%llu",
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] btrfs: a couple cleanups in replay_one_extent()
  2025-09-18 12:42 [PATCH 0/2] btrfs: a couple cleanups in replay_one_extent() fdmanana
  2025-09-18 12:42 ` [PATCH 1/2] btrfs: fix comment about nbytes increase at replay_one_extent() fdmanana
  2025-09-18 12:42 ` [PATCH 2/2] btrfs: simplify inline extent end calculation " fdmanana
@ 2025-09-18 21:10 ` Qu Wenruo
  2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2025-09-18 21:10 UTC (permalink / raw)
  To: fdmanana, linux-btrfs



在 2025/9/18 22:12, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
> 
> Trivial changes, details in the changelogs.

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> 
> Filipe Manana (2):
>    btrfs: fix comment about nbytes increase at replay_one_extent()
>    btrfs: simplify inline extent end calculation at replay_one_extent()
> 
>   fs/btrfs/tree-log.c | 18 +++++-------------
>   1 file changed, 5 insertions(+), 13 deletions(-)
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-18 21:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-18 12:42 [PATCH 0/2] btrfs: a couple cleanups in replay_one_extent() fdmanana
2025-09-18 12:42 ` [PATCH 1/2] btrfs: fix comment about nbytes increase at replay_one_extent() fdmanana
2025-09-18 12:42 ` [PATCH 2/2] btrfs: simplify inline extent end calculation " fdmanana
2025-09-18 21:10 ` [PATCH 0/2] btrfs: a couple cleanups in replay_one_extent() Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox