From 3d006ddd311b9f566c3088b2d4d658f597a18093 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Mon, 2 Sep 2019 21:22:42 +0200 Subject: [PATCH] include: Fix new-style encoding routines on big-endian The new-style encoding routines (denc.h) are broken on big-endian systems. While there is a lot of infrastucture in place to recognize data types that need to be byte-swapped during encoding and decoding on big-endian systems, nothing is actually ever swapped. Fixed by using ceph_le16/32/64 instead of __le16/32/64 (which are no-ops outside of kernel code). Fixes (partially): https://tracker.ceph.com/issues/41605 Signed-off-by: Ulrich Weigand (cherry picked from commit 754b82ee15e6d1b52bc83011c2d7680bdb1d3830) Signed-off-by: Ulrich Weigand --- src/include/denc.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/include/denc.h b/src/include/denc.h index cc2b906bf02e7..a6a0fcaa9ade6 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -321,19 +321,19 @@ template struct ExtType { template struct ExtType || std::is_same_v>> { - using type = __le16; + using type = ceph_le16; }; template struct ExtType || std::is_same_v>> { - using type = __le32; + using type = ceph_le32; }; template struct ExtType || std::is_same_v>> { - using type = __le64; + using type = ceph_le64; }; template<> @@ -548,11 +548,11 @@ denc_lba(uint64_t v, It& p) { word |= (v << pos) & 0x7fffffff; v >>= 31 - pos; if (!v) { - *(__le32*)p.get_pos_add(sizeof(uint32_t)) = word; + *(ceph_le32*)p.get_pos_add(sizeof(uint32_t)) = word; return; } word |= 0x80000000; - *(__le32*)p.get_pos_add(sizeof(uint32_t)) = word; + *(ceph_le32*)p.get_pos_add(sizeof(uint32_t)) = word; uint8_t byte = v & 0x7f; v >>= 7; while (v) { @@ -567,7 +567,7 @@ denc_lba(uint64_t v, It& p) { template inline std::enable_if_t> denc_lba(uint64_t& v, It& p) { - uint32_t word = *(__le32*)p.get_pos_add(sizeof(uint32_t)); + uint32_t word = *(ceph_le32*)p.get_pos_add(sizeof(uint32_t)); int shift; switch (word & 7) { case 0: @@ -1638,7 +1638,7 @@ inline std::enable_if_t decode_nohead( __u8 *struct_compat, \ char **len_pos, \ uint32_t *start_oob_off) { \ - *(__le32*)*len_pos = p.get_pos() - *len_pos - sizeof(uint32_t) + \ + *(ceph_le32*)*len_pos = p.get_pos() - *len_pos - sizeof(uint32_t) + \ p.get_out_of_band_offset() - *start_oob_off; \ } \ /* decode */ \ -- 2.39.5