Skip to contentSkip to conversation

btrfs-progs: print the csum length in debug-tree

PATCH Superseded [email protected] 3 participants 4 messages Aug 25, 2017 – Sep 1, 2017 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: print the csum length in debug-tree

From: Josef Bacik <[email protected]>

While looking at a log of a corrupted fs I needed to verify we were missing csums for a given range. Make this easier by printing out how many bytes a csum extent item represents when using btrfs_debug_tree.

---
 print-tree.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
print-tree.c +8 -2
index 5927ed3..a124c96 100644
@@ -1103,9 +1103,15 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
 		case BTRFS_CSUM_ITEM_KEY:
 			printf("\t\tcsum item\n");
 			break;
-		case BTRFS_EXTENT_CSUM_KEY:
-			printf("\t\textent csum item\n");
+		case BTRFS_EXTENT_CSUM_KEY: {
+			u16 csum_size =
+				btrfs_super_csum_size(root->fs_info->super_copy);
+			u32 size = (item_size / csum_size) *
+				root->fs_info->sectorsize;
+			printf("\t\textent csum item bytes %lu\n",
+			       (unsigned long)size);
 			break;
+			}
 		case BTRFS_EXTENT_DATA_KEY:
 			print_file_extent_item(eb, item, i, ptr);
 			break;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 18 lines · On 25.08.2017 16:13, [email protected] wrote:

From: Josef Bacik <[email protected]>

While looking at a log of a corrupted fs I needed to verify we were missing csums for a given range. Make this easier by printing out how many bytes a csum extent item represents when using btrfs_debug_tree.

---
 print-tree.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
print-tree.c +0 -0
index 5927ed3..a124c96 100644
@@ -1103,9 +1103,15 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
 		case BTRFS_CSUM_ITEM_KEY:
 			printf("\t\tcsum item\n");

print-tree.c void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb) · line 1112

Quoted 10 lines
print-tree.c +7 -2
 			break;
-		case BTRFS_EXTENT_CSUM_KEY:
-			printf("\t\textent csum item\n");
+		case BTRFS_EXTENT_CSUM_KEY: {
+			u16 csum_size =
+				btrfs_super_csum_size(root->fs_info->super_copy);
+			u32 size = (item_size / csum_size) *
+				root->fs_info->sectorsize;
+			printf("\t\textent csum item bytes %lu\n",
+			       (unsigned long)size);

Currently for a csum item we get:

item 0 key (EXTENT_CSUM EXTENT_CSUM 1103101952) itemoff 16279 itemsize 4
extent csum item

Why don't you go one step further and print the covered range -
it would be key.offset + size (the number you've calculated) And so you can print something like:

item 0 key (EXTENT_CSUM EXTENT_CSUM 1103101952) itemoff 16279 itemsize 4

		extent csum item 1103101952-1103106048

"extent csum item range %llu-%lly\n", key.offset, key.offset + size

Quoted 6 lines
print-tree.c +1 -0
 			break;
+			}
 		case BTRFS_EXTENT_DATA_KEY:
 			print_file_extent_item(eb, item, i, ptr);
 			break;
#2 lore raw
Quoted 38 lines · Nikolay Borisov
Quoted 18 lines · On 25.08.2017 16:13, [email protected] wrote:

From: Josef Bacik <[email protected]>

While looking at a log of a corrupted fs I needed to verify we were missing csums for a given range. Make this easier by printing out how many bytes a csum extent item represents when using btrfs_debug_tree.

---
 print-tree.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
print-tree.c +0 -0
index 5927ed3..a124c96 100644
@@ -1103,9 +1103,15 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
 		case BTRFS_CSUM_ITEM_KEY:
 			printf("\t\tcsum item\n");

print-tree.c void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb) · line 1112

Quoted 10 lines
print-tree.c +7 -2
 			break;
-		case BTRFS_EXTENT_CSUM_KEY:
-			printf("\t\textent csum item\n");
+		case BTRFS_EXTENT_CSUM_KEY: {
+			u16 csum_size =
+				btrfs_super_csum_size(root->fs_info->super_copy);
+			u32 size = (item_size / csum_size) *
+				root->fs_info->sectorsize;
+			printf("\t\textent csum item bytes %lu\n",
+			       (unsigned long)size);

Currently for a csum item we get:

item 0 key (EXTENT_CSUM EXTENT_CSUM 1103101952) itemoff 16279 itemsize 4
extent csum item

Quoted 9 lines

Why don't you go one step further and print the covered range -
it would be key.offset + size (the number you've calculated) And so you can print something like:

item 0 key (EXTENT_CSUM EXTENT_CSUM 1103101952) itemoff 16279 itemsize 4

		extent csum item 1103101952-1103106048

"extent csum item range %llu-%lly\n", key.offset, key.offset + size

Because real engineers do that math in their head.

Josef

#3 lore raw
In reply to Nikolay Borisov
Quoted 38 lines · Nikolay Borisov
Quoted 18 lines · On 25.08.2017 16:13, [email protected] wrote:

From: Josef Bacik <[email protected]>

While looking at a log of a corrupted fs I needed to verify we were missing csums for a given range. Make this easier by printing out how many bytes a csum extent item represents when using btrfs_debug_tree.

---
 print-tree.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
print-tree.c +0 -0
index 5927ed3..a124c96 100644
@@ -1103,9 +1103,15 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
 		case BTRFS_CSUM_ITEM_KEY:
 			printf("\t\tcsum item\n");

print-tree.c void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb) · line 1112

Quoted 10 lines
print-tree.c +7 -2
 			break;
-		case BTRFS_EXTENT_CSUM_KEY:
-			printf("\t\textent csum item\n");
+		case BTRFS_EXTENT_CSUM_KEY: {
+			u16 csum_size =
+				btrfs_super_csum_size(root->fs_info->super_copy);
+			u32 size = (item_size / csum_size) *
+				root->fs_info->sectorsize;
+			printf("\t\textent csum item bytes %lu\n",
+			       (unsigned long)size);

Currently for a csum item we get:

item 0 key (EXTENT_CSUM EXTENT_CSUM 1103101952) itemoff 16279 itemsize 4
extent csum item

Quoted 8 lines

Why don't you go one step further and print the covered range -
it would be key.offset + size (the number you've calculated) And so you can print something like:

item 0 key (EXTENT_CSUM EXTENT_CSUM 1103101952) itemoff 16279 itemsize 4

		extent csum item 1103101952-1103106048

"extent csum item range %llu-%lly\n", key.offset, key.offset + size

I think the calculation is really simple to do, if one needs it.

The 'bytes' seem to refer to the range so I'll change that to length.