btrfs: a couple cleanups in replay_one_extent()
cover btrfs: a couple cleanups in replay_one_extent()
From: Filipe Manana <[email protected]>
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(-)
Signature · 1 line
2.47.2
PATCH 1/2 btrfs: fix comment about nbytes increase at replay_one_extent()
From: Filipe Manana <[email protected]>
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.
--- fs/btrfs/tree-log.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
fs/btrfs/tree-log.c +4 -9
@@ -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);
Signature · 1 line
2.47.2
PATCH 2/2 btrfs: simplify inline extent end calculation at replay_one_extent()
In reply to [email protected]From: Filipe Manana <[email protected]>
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.
--- fs/btrfs/tree-log.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
fs/btrfs/tree-log.c +1 -4
@@ -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",
Signature · 1 line
2.47.2
Quoted 3 lines · 在 2025/9/18 22:12, [email protected] 写道:
From: Filipe Manana <[email protected]>
Trivial changes, details in the changelogs.
Thanks,
Qu
Quoted 8 lines
Filipe Manana (2):
btrfs: fix comment about nbytes increase atreplay_one_extent()
btrfs: simplify inline extent end calculation atreplay_one_extent()fs/btrfs/tree-log.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)