]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include: Fix new-style encoding routines on big-endian
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Mon, 2 Sep 2019 19:22:42 +0000 (21:22 +0200)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Thu, 5 Sep 2019 08:50:04 +0000 (10:50 +0200)
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 <ulrich.weigand@de.ibm.com>
src/include/denc.h

index 91089260366e634e54a570178045a173a0a737e5..2a3a640147627142c5cbf9c1696e19cbab16da0d 100644 (file)
@@ -360,19 +360,19 @@ template<typename T, typename=void> struct ExtType {
 template<typename T>
 struct ExtType<T, std::enable_if_t<std::is_same_v<T, int16_t> ||
                                   std::is_same_v<T, uint16_t>>> {
-  using type = __le16;
+  using type = ceph_le16;
 };
 
 template<typename T>
 struct ExtType<T, std::enable_if_t<std::is_same_v<T, int32_t> ||
                                   std::is_same_v<T, uint32_t>>> {
-  using type = __le32;
+  using type = ceph_le32;
 };
 
 template<typename T>
 struct ExtType<T, std::enable_if_t<std::is_same_v<T, int64_t> ||
                                   std::is_same_v<T, uint64_t>>> {
-  using type = __le64;
+  using type = ceph_le64;
 };
 
 template<>
@@ -588,11 +588,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) {
@@ -607,7 +607,7 @@ denc_lba(uint64_t v, It& p) {
 template<class It>
 inline std::enable_if_t<is_const_iterator_v<It>>
 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:
@@ -1693,7 +1693,7 @@ inline std::enable_if_t<traits::supported && !traits::featured> 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 */                                                         \