]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: print-tree: print range information for extent csum items
authorFilipe Manana <fdmanana@suse.com>
Mon, 15 Sep 2025 10:09:10 +0000 (11:09 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 23 Sep 2025 06:49:22 +0000 (08:49 +0200)
Currently we don't print anything for extent csum items other than the
generic line with the key, item offset and item size. While one can still
determine the range the extent csum covers by doing a few simple
computations, it makes it more time consuming to analyse a leaf dump.
So add a line that prints information about the range covered by the
checksum using the same format as btrfs-progs. This is useful when
debugging log tree issues since we log extent csum items for new extents.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/print-tree.c

index a66aced1d29c6f2365c4a21031487a05dce6b181..c2898fa6d4ba4441079933bd830f33e9e343c176 100644 (file)
@@ -325,6 +325,18 @@ static void print_dir_log_index_item(const struct extent_buffer *eb, int i)
        pr_info("\t\tdir log end %llu\n", btrfs_dir_log_end(eb, dlog));
 }
 
+static void print_extent_csum(const struct extent_buffer *eb, int i)
+{
+       const struct btrfs_fs_info *fs_info = eb->fs_info;
+       const u32 size = btrfs_item_size(eb, i);
+       const u32 csum_bytes = (size / fs_info->csum_size) * fs_info->sectorsize;
+       struct btrfs_key key;
+
+       btrfs_item_key_to_cpu(eb, &key, i);
+       pr_info("\t\trange start %llu end %llu length %u\n",
+               key.offset, key.offset + csum_bytes, csum_bytes);
+}
+
 void btrfs_print_leaf(const struct extent_buffer *l)
 {
        struct btrfs_fs_info *fs_info;
@@ -373,6 +385,9 @@ void btrfs_print_leaf(const struct extent_buffer *l)
                case BTRFS_DIR_LOG_INDEX_KEY:
                        print_dir_log_index_item(l, i);
                        break;
+               case BTRFS_EXTENT_CSUM_KEY:
+                       print_extent_csum(l, i);
+                       break;
                case BTRFS_ROOT_ITEM_KEY:
                        ri = btrfs_item_ptr(l, i, struct btrfs_root_item);
                        pr_info("\t\troot data bytenr %llu refs %u\n",