From 63609fd1aef9811d9d3c9bd27bb9d2c88f1c2fe8 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Mon, 2 Sep 2019 21:23:13 +0200 Subject: [PATCH] checksum: Fix incorrect use of __le16/32/64 Use ceph_le16/32/64 instead of __le16/32/64 (which are no-op outside of kernel code). Note that I've changed the Alg::calc routines to return the init_value_t type instead of value_t, to avoid having to introduce explicit byte-swapping calls to init_le16/32/64 in many places. (This way, the byte-swapping happens implicitly at the very end, wher the init_value_t value is assigned via a value_t pointer.) Fixes (partially): https://tracker.ceph.com/issues/41605 Signed-off-by: Ulrich Weigand --- src/common/Checksummer.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/common/Checksummer.h b/src/common/Checksummer.h index 2137c1d6609..ceb551bcbf4 100644 --- a/src/common/Checksummer.h +++ b/src/common/Checksummer.h @@ -5,6 +5,7 @@ #define CEPH_OS_BLUESTORE_CHECKSUMMER #include "xxHash/xxhash.h" +#include "include/byteorder.h" class Checksummer { public: @@ -69,7 +70,7 @@ public: struct crc32c { typedef uint32_t init_value_t; - typedef __le32 value_t; + typedef ceph_le32 value_t; // we have no execution context/state. typedef int state_t; @@ -78,7 +79,7 @@ public: static void fini(state_t *state) { } - static value_t calc( + static init_value_t calc( state_t state, init_value_t init_value, size_t len, @@ -90,7 +91,7 @@ public: struct crc32c_16 { typedef uint32_t init_value_t; - typedef __le16 value_t; + typedef ceph_le16 value_t; // we have no execution context/state. typedef int state_t; @@ -99,7 +100,7 @@ public: static void fini(state_t *state) { } - static value_t calc( + static init_value_t calc( state_t state, init_value_t init_value, size_t len, @@ -120,7 +121,7 @@ public: static void fini(state_t *state) { } - static value_t calc( + static init_value_t calc( state_t state, init_value_t init_value, size_t len, @@ -132,7 +133,7 @@ public: struct xxhash32 { typedef uint32_t init_value_t; - typedef __le32 value_t; + typedef ceph_le32 value_t; typedef XXH32_state_t *state_t; static void init(state_t *s) { @@ -142,7 +143,7 @@ public: XXH32_freeState(*s); } - static value_t calc( + static init_value_t calc( state_t state, init_value_t init_value, size_t len, @@ -161,7 +162,7 @@ public: struct xxhash64 { typedef uint64_t init_value_t; - typedef __le64 value_t; + typedef ceph_le64 value_t; typedef XXH64_state_t *state_t; static void init(state_t *s) { @@ -171,7 +172,7 @@ public: XXH64_freeState(*s); } - static value_t calc( + static init_value_t calc( state_t state, init_value_t init_value, size_t len, @@ -250,7 +251,7 @@ public: pv += offset / csum_block_size; size_t pos = offset; while (length > 0) { - typename Alg::value_t v = Alg::calc(state, -1, csum_block_size, p); + typename Alg::init_value_t v = Alg::calc(state, -1, csum_block_size, p); if (*pv != v) { if (bad_csum) { *bad_csum = v; -- 2.39.5