diff mbox series

[v2] btrfs-progs: Fix checksum output for "checksum verify failed"

Message ID 20210303191843.6878-1-davispuh@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2] btrfs-progs: Fix checksum output for "checksum verify failed" | expand

Commit Message

Dāvis Mosāns March 3, 2021, 7:18 p.m. UTC
Currently only single checksum byte is outputted.
This fixes it so that full checksum is outputted.

Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
---
 kernel-shared/disk-io.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

Comments

David Sterba March 5, 2021, 4:30 p.m. UTC | #1
On Wed, Mar 03, 2021 at 09:18:44PM +0200, Dāvis Mosāns wrote:
> Currently only single checksum byte is outputted.
> This fixes it so that full checksum is outputted.
> 
> Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
> ---
>  kernel-shared/disk-io.c | 32 +++++++++++++++++++++++++++-----
>  1 file changed, 27 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
> index 6f584986..10b2421e 100644
> --- a/kernel-shared/disk-io.c
> +++ b/kernel-shared/disk-io.c
> @@ -160,10 +160,30 @@ int btrfs_csum_data(u16 csum_type, const u8 *data, u8 *out, size_t len)
>  	return -1;
>  }
>  
> +int btrfs_format_csum(u16 csum_type, u16 csum_size, const char *data, char *output)
> +{
> +	int i;
> +	int position = 0;
> +	int direction = 1;
> +	if (csum_type == BTRFS_CSUM_TYPE_CRC32 ||
> +		csum_type == BTRFS_CSUM_TYPE_XXHASH) {
> +		position = csum_size - 1;
> +		direction = -1;
> +	}

Per the discussion, I've dropped the direction variable and added the
"0x" prefix. The csum_size does not need to be passed, though it's
available in the caller's context. The type should be enough and then
the function can find the size independently.

Updated patch added to devel, thanks.
diff mbox series

Patch

diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index 6f584986..10b2421e 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -160,10 +160,30 @@  int btrfs_csum_data(u16 csum_type, const u8 *data, u8 *out, size_t len)
 	return -1;
 }
 
+int btrfs_format_csum(u16 csum_type, u16 csum_size, const char *data, char *output)
+{
+	int i;
+	int position = 0;
+	int direction = 1;
+	if (csum_type == BTRFS_CSUM_TYPE_CRC32 ||
+		csum_type == BTRFS_CSUM_TYPE_XXHASH) {
+		position = csum_size - 1;
+		direction = -1;
+	}
+
+	for (i = 0; i < csum_size; i++) {
+		sprintf(output + i*2, "%02X", data[position + i*direction] & 0xFF);
+	}
+
+	return csum_size;
+}
+
 static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
 				  int verify, int silent, u16 csum_type)
 {
 	u8 result[BTRFS_CSUM_SIZE];
+	char found[BTRFS_CSUM_SIZE * 2 + 1]; // 2 hex chars for each byte + null
+	char wanted[BTRFS_CSUM_SIZE * 2 + 1];
 	u32 len;
 
 	len = buf->len - BTRFS_CSUM_SIZE;
@@ -172,12 +192,14 @@  static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
 
 	if (verify) {
 		if (memcmp_extent_buffer(buf, result, 0, csum_size)) {
-			/* FIXME: format */
-			if (!silent)
-				printk("checksum verify failed on %llu found %08X wanted %08X\n",
+			if (!silent) {
+				btrfs_format_csum(csum_type, csum_size, (char *)result, found);
+				btrfs_format_csum(csum_type, csum_size, buf->data, wanted);
+				printk("checksum verify failed on %llu wanted %s found %s\n",
 				       (unsigned long long)buf->start,
-				       result[0],
-				       buf->data[0]);
+				       wanted,
+				       found);
+			}
 			return 1;
 		}
 	} else {