All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: populate extent_map::generation when reading from disk
@ 2022-02-05  8:55 Qu Wenruo
  2022-02-07 10:52 ` Filipe Manana
  0 siblings, 1 reply; 5+ messages in thread
From: Qu Wenruo @ 2022-02-05  8:55 UTC (permalink / raw)
  To: linux-btrfs

[WEIRD BEHAVIOR]

When btrfs_get_extent() tries to get some file extent from disk, it
never populates extent_map::generation , leaving the value to be 0.

On the other hand, for extent map generated by IO, it will get its
generation properly set at finish_ordered_io()

 finish_ordered_io()
 |- unpin_extent_cache(gen = trans->transid)
    |- em->generation = gen;

[REGRESSION?]
I have no idea when such behavior is introduced, but at least in v5.15
this incorrect behavior is already there.

[AFFECT]
Not really sure if there is any behavior really get affected.

Sure there are locations like extent map merging, but there is no value
smaller than 0 for u64, thus it won't really cause a difference.

For autodefrag, although it's checking em->generation to determine if we
need to defrag a range, but that @new_than value is always from IO, thus
all those extent maps with 0 generation will just be skipped, and that's
the expected behavior anyway.

For manual defrag, @newer_than is 0, and our check is to skip generation
smaller than @newer_than, thus it still makes no difference.

[FIX]
To make things less weird, let us populate extent_map::generation in
btrfs_extent_item_to_extent_map().

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/file-item.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 90c5c38836ab..9a3de652ada8 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -1211,6 +1211,7 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
 	extent_start = key.offset;
 	extent_end = btrfs_file_extent_end(path);
 	em->ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi);
+	em->generation = btrfs_file_extent_generation(leaf, fi);
 	if (type == BTRFS_FILE_EXTENT_REG ||
 	    type == BTRFS_FILE_EXTENT_PREALLOC) {
 		em->start = extent_start;
-- 
2.35.0


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

end of thread, other threads:[~2022-02-09  0:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-05  8:55 [PATCH] btrfs: populate extent_map::generation when reading from disk Qu Wenruo
2022-02-07 10:52 ` Filipe Manana
2022-02-07 11:39   ` Qu Wenruo
2022-02-08 16:34     ` Filipe Manana
2022-02-09  0:41       ` Qu Wenruo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.