btrfs-progs: fix xxhash on big endian machines
xxhash's state and results are always in little, but in progs after the
hash was calculated it was copied to the final buffer via memcpy,
meaning it'd be parsed as a big endian number on big endian machines.
This is incompatible with the kernel implementation of xxhash which
results in erroneous "checksum didn't match" errors on mount.
Fix it by using put_unaligned_le64 which always ensures the resulting
checksum will be copied in little endian format as the kernel expects
it.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=206835
Fixes: f070ece2e9
("btrfs-progs: add xxhash64 to mkfs")
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
1173a4ba26
commit
5b13164cf9
|
@ -19,11 +19,7 @@ int hash_xxhash(const u8 *buf, size_t length, u8 *out)
|
||||||
XXH64_hash_t hash;
|
XXH64_hash_t hash;
|
||||||
|
|
||||||
hash = XXH64(buf, length, 0);
|
hash = XXH64(buf, length, 0);
|
||||||
/*
|
put_unaligned_le64(hash, out);
|
||||||
* NOTE: we're not taking the canonical form here but the plain hash to
|
|
||||||
* be compatible with the kernel implementation!
|
|
||||||
*/
|
|
||||||
memcpy(out, &hash, 8);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue