diff --git a/CMakeLists.txt b/CMakeLists.txt
index ebf5cd92cd..281703fb01 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -137,12 +137,6 @@ CHECK_INCLUDE_FILES("valgrind/helgrind.h" HAVE_VALGRIND_HELGRIND_H)
 
 include(CheckTypeSize)
 set(CMAKE_EXTRA_INCLUDE_FILES "linux/types.h")
-CHECK_TYPE_SIZE(__be16 __BE16) 
-CHECK_TYPE_SIZE(__be32 __BE32) 
-CHECK_TYPE_SIZE(__be64 __BE64) 
-CHECK_TYPE_SIZE(__le16 __LE16) 
-CHECK_TYPE_SIZE(__le32 __LE32) 
-CHECK_TYPE_SIZE(__le64 __LE64) 
 CHECK_TYPE_SIZE(__u8 __U8) 
 CHECK_TYPE_SIZE(__u16 __U16) 
 CHECK_TYPE_SIZE(__u32 __U32) 
diff --git a/src/auth/cephx/CephxProtocol.cc b/src/auth/cephx/CephxProtocol.cc
index 5b7a2bcb86..d975cbea09 100644
--- a/src/auth/cephx/CephxProtocol.cc
+++ b/src/auth/cephx/CephxProtocol.cc
@@ -37,9 +37,9 @@ void cephx_calc_client_server_challenge(CephContext *cct, CryptoKey& secret, uin
     return;
 
   uint64_t k = 0;
-  const uint64_t *p = (const uint64_t *)enc.c_str();
+  const ceph_le64 *p = (const ceph_le64 *)enc.c_str();
   for (int pos = 0; pos + sizeof(k) <= enc.length(); pos+=sizeof(k), p++)
-    k ^= mswab(*p);
+    k ^= *p;
   *key = k;
 }
 
diff --git a/src/auth/cephx/CephxSessionHandler.cc b/src/auth/cephx/CephxSessionHandler.cc
index 6ef45eaa76..966f87197d 100644
--- a/src/auth/cephx/CephxSessionHandler.cc
+++ b/src/auth/cephx/CephxSessionHandler.cc
@@ -49,16 +49,16 @@ int CephxSessionHandler::_calc_signature(Message *m, uint64_t *psig)
     // - skip the leading 4 byte wrapper from encode_encrypt
     struct {
       __u8 v;
-      __le64 magic;
-      __le32 len;
-      __le32 header_crc;
-      __le32 front_crc;
-      __le32 middle_crc;
-      __le32 data_crc;
+      ceph_le64 magic;
+      ceph_le32 len;
+      ceph_le32 header_crc;
+      ceph_le32 front_crc;
+      ceph_le32 middle_crc;
+      ceph_le32 data_crc;
     } __attribute__ ((packed)) sigblock = {
-      1, mswab(AUTH_ENC_MAGIC), mswab<uint32_t>(4*4),
-      mswab<uint32_t>(header.crc), mswab<uint32_t>(footer.front_crc),
-      mswab<uint32_t>(footer.middle_crc), mswab<uint32_t>(footer.data_crc)
+      1, init_le64(AUTH_ENC_MAGIC), init_le32(4*4),
+      init_le32(header.crc), init_le32(footer.front_crc),
+      init_le32(footer.middle_crc), init_le32(footer.data_crc)
     };
 
     char exp_buf[CryptoKey::get_max_outbuf_size(sizeof(sigblock))];
@@ -78,27 +78,27 @@ int CephxSessionHandler::_calc_signature(Message *m, uint64_t *psig)
       return -1;
     }
 
-    *psig = *reinterpret_cast<__le64*>(exp_buf);
+    *psig = *reinterpret_cast<ceph_le64*>(exp_buf);
   } else {
     // newer mimic+ signatures
     struct {
-      __le32 header_crc;
-      __le32 front_crc;
-      __le32 front_len;
-      __le32 middle_crc;
-      __le32 middle_len;
-      __le32 data_crc;
-      __le32 data_len;
-      __le32 seq_lower_word;
+      ceph_le32 header_crc;
+      ceph_le32 front_crc;
+      ceph_le32 front_len;
+      ceph_le32 middle_crc;
+      ceph_le32 middle_len;
+      ceph_le32 data_crc;
+      ceph_le32 data_len;
+      ceph_le32 seq_lower_word;
     } __attribute__ ((packed)) sigblock = {
-      mswab<uint32_t>(header.crc),
-      mswab<uint32_t>(footer.front_crc),
-      mswab<uint32_t>(header.front_len),
-      mswab<uint32_t>(footer.middle_crc),
-      mswab<uint32_t>(header.middle_len),
-      mswab<uint32_t>(footer.data_crc),
-      mswab<uint32_t>(header.data_len),
-      mswab<uint32_t>(header.seq)
+      init_le32(header.crc),
+      init_le32(footer.front_crc),
+      init_le32(header.front_len),
+      init_le32(footer.middle_crc),
+      init_le32(header.middle_len),
+      init_le32(footer.data_crc),
+      init_le32(header.data_len),
+      init_le32(header.seq)
     };
 
     char exp_buf[CryptoKey::get_max_outbuf_size(sizeof(sigblock))];
@@ -119,7 +119,7 @@ int CephxSessionHandler::_calc_signature(Message *m, uint64_t *psig)
     }
 
     struct enc {
-      __le64 a, b, c, d;
+      ceph_le64 a, b, c, d;
     } *penc = reinterpret_cast<enc*>(exp_buf);
     *psig = penc->a ^ penc->b ^ penc->c ^ penc->d;
   }
diff --git a/src/cls/rgw/cls_rgw_types.cc b/src/cls/rgw/cls_rgw_types.cc
index 892ef5617e..a94c1134b9 100644
--- a/src/cls/rgw/cls_rgw_types.cc
+++ b/src/cls/rgw/cls_rgw_types.cc
@@ -481,7 +481,7 @@ void rgw_bi_log_entry::generate_test_instances(list<rgw_bi_log_entry*>& ls)
   ls.push_back(new rgw_bi_log_entry);
   ls.back()->id = "midf";
   ls.back()->object = "obj";
-  ls.back()->timestamp = ceph::real_clock::from_ceph_timespec({{2}, {3}});
+  ls.back()->timestamp = ceph::real_clock::from_ceph_timespec({init_le32(2), init_le32(3)});
   ls.back()->index_ver = 4323;
   ls.back()->tag = "tagasdfds";
   ls.back()->op = CLS_RGW_OP_DEL;
@@ -663,7 +663,7 @@ void cls_rgw_reshard_entry::generate_test_instances(list<cls_rgw_reshard_entry*>
 {
   ls.push_back(new cls_rgw_reshard_entry);
   ls.push_back(new cls_rgw_reshard_entry);
-  ls.back()->time = ceph::real_clock::from_ceph_timespec({{2}, {3}});
+  ls.back()->time = ceph::real_clock::from_ceph_timespec({init_le32(2), init_le32(3)});
   ls.back()->tenant = "tenant";
   ls.back()->bucket_name = "bucket1""";
   ls.back()->bucket_id = "bucket_id";
diff --git a/src/cls/rgw/cls_rgw_types.h b/src/cls/rgw/cls_rgw_types.h
index d069e8f516..6098f1be65 100644
--- a/src/cls/rgw/cls_rgw_types.h
+++ b/src/cls/rgw/cls_rgw_types.h
@@ -1093,7 +1093,7 @@ struct cls_rgw_gc_obj_info
     ls.push_back(new cls_rgw_gc_obj_info);
     ls.push_back(new cls_rgw_gc_obj_info);
     ls.back()->tag = "footag";
-    ceph_timespec ts{21, 32};
+    ceph_timespec ts{init_le32(21), init_le32(32)};
     ls.back()->time = ceph::real_clock::from_ceph_timespec(ts);
   }
 };
diff --git a/src/common/Checksummer.h b/src/common/Checksummer.h
index 2137c1d660..ceb551bcbf 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;
diff --git a/src/crimson/net/ProtocolV2.cc b/src/crimson/net/ProtocolV2.cc
index b51e32e134..2e80778cf2 100644
--- a/src/crimson/net/ProtocolV2.cc
+++ b/src/crimson/net/ProtocolV2.cc
@@ -446,7 +446,7 @@ seastar::future<entity_type_t, entity_addr_t> ProtocolV2::banner_exchange()
                  CEPH_BANNER_V2_PREFIX);
   return write_flush(std::move(bl)).then([this] {
       // 2. read peer banner
-      unsigned banner_len = strlen(CEPH_BANNER_V2_PREFIX) + sizeof(__le16);
+      unsigned banner_len = strlen(CEPH_BANNER_V2_PREFIX) + sizeof(ceph_le16);
       return read_exactly(banner_len); // or read exactly?
     }).then([this] (auto bl) {
       // 3. process peer banner and read banner_payload
diff --git a/src/include/byteorder.h b/src/include/byteorder.h
index 8674860166..03e30f84fc 100644
--- a/src/include/byteorder.h
+++ b/src/include/byteorder.h
@@ -66,38 +66,36 @@ inline T mswab(T val) {
 
 template<typename T>
 struct ceph_le {
+private:
   T v;
+public:
   ceph_le<T>& operator=(T nv) {
     v = mswab(nv);
     return *this;
   }
   operator T() const { return mswab(v); }
+  friend inline bool operator==(ceph_le a, ceph_le b) {
+    return a.v == b.v;
+  }
 } __attribute__ ((packed));
 
-template<typename T>
-inline bool operator==(ceph_le<T> a, ceph_le<T> b) {
-  return a.v == b.v;
-}
-
 using ceph_le64 = ceph_le<__u64>;
 using ceph_le32 = ceph_le<__u32>;
 using ceph_le16 = ceph_le<__u16>;
 
-inline __u64 init_le64(__u64 x) {
-  return mswab<__u64>(x);
+inline ceph_le64 init_le64(__u64 x) {
+  ceph_le64 v;
+  v = x;
+  return v;
 }
-inline __u32 init_le32(__u32 x) {
-  return mswab<__u32>(x);
+inline ceph_le32 init_le32(__u32 x) {
+  ceph_le32 v;
+  v = x;
+  return v;
 }
-inline __u16 init_le16(__u16 x) {
-  return mswab<__u16>(x);
+inline ceph_le16 init_le16(__u16 x) {
+  ceph_le16 v;
+  v = x;
+  return v;
 }
 
-  /*
-#define cpu_to_le64(x) (x)
-#define cpu_to_le32(x) (x)
-#define cpu_to_le16(x) (x)
-  */
-#define le64_to_cpu(x) ((uint64_t)x)
-#define le32_to_cpu(x) ((__u32)x)
-#define le16_to_cpu(x) ((__u16)x)
diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h
index e8258caa9c..28d03f0789 100644
--- a/src/include/ceph_fs.h
+++ b/src/include/ceph_fs.h
@@ -15,6 +15,27 @@
 #include "msgr.h"
 #include "rados.h"
 
+/*
+ * The data structures defined here are shared between Linux kernel and
+ * user space.  Also, those data structures are maintained always in
+ * little-endian byte order, even on big-endian systems.  This is handled
+ * differently in kernel vs. user space.  For use as kernel headers, the
+ * little-endian fields need to use the __le16/__le32/__le64 types.  These
+ * are markers that indicate endian conversion routines must be used
+ * whenever such fields are accessed, which can be verified by checker
+ * tools like "sparse".  For use as user-space headers, the little-endian
+ * fields instead use types ceph_le16/ceph_le32/ceph_le64, which are C++
+ * classes that implement automatic endian conversion on every access.
+ * To still allow for header sharing, this file uses the __le types, but
+ * redefines those to the ceph_ types when compiled in user space.
+ */
+#ifndef __KERNEL__
+#include "byteorder.h"
+#define __le16 ceph_le16
+#define __le32 ceph_le32
+#define __le64 ceph_le64
+#endif
+
 /*
  * subprotocol versions.  when specific messages types or high-level
  * protocols change, bump the affected components.  we keep rev
@@ -616,14 +637,18 @@ static inline void
 copy_from_legacy_head(struct ceph_mds_request_head *head,
 			struct ceph_mds_request_head_legacy *legacy)
 {
-	memcpy(&(head->oldest_client_tid), legacy, sizeof(*legacy));
+	struct ceph_mds_request_head_legacy *embedded_legacy =
+		(struct ceph_mds_request_head_legacy *)&head->oldest_client_tid;
+	*embedded_legacy = *legacy;
 }
 
 static inline void
 copy_to_legacy_head(struct ceph_mds_request_head_legacy *legacy,
 			struct ceph_mds_request_head *head)
 {
-	memcpy(legacy, &(head->oldest_client_tid), sizeof(*legacy));
+	struct ceph_mds_request_head_legacy *embedded_legacy =
+		(struct ceph_mds_request_head_legacy *)&head->oldest_client_tid;
+	*legacy = *embedded_legacy;
 }
 
 /* client reply */
@@ -853,10 +878,10 @@ struct ceph_mds_caps_body_legacy {
 			struct ceph_timespec mtime, atime, ctime;
 			struct ceph_file_layout layout;
 			__le32 time_warp_seq;
-		};
+		} __attribute__ ((packed));
 		/* export message */
 		struct ceph_mds_cap_peer peer;
-	};
+	} __attribute__ ((packed));
 } __attribute__ ((packed));
 
 /* cap release msg head */
@@ -951,4 +976,10 @@ struct ceph_mds_snap_realm {
 } __attribute__ ((packed));
 /* followed by my snap list, then prior parent snap list */
 
+#ifndef __KERNEL__
+#undef __le16
+#undef __le32
+#undef __le64
+#endif
+
 #endif
diff --git a/src/include/config-h.in.cmake b/src/include/config-h.in.cmake
index 0cb02efd3c..773ac2c567 100644
--- a/src/include/config-h.in.cmake
+++ b/src/include/config-h.in.cmake
@@ -39,24 +39,6 @@
 /* Define to 1 if you have the <execinfo.h> header file. */
 #cmakedefine HAVE_EXECINFO_H 1
 
-/* Define to 1 if the system has the type `__be16'. */
-#cmakedefine HAVE___BE16 1
-
-/* Define to 1 if the system has the type `__be32'. */
-#cmakedefine HAVE___BE32 1
-
-/* Define to 1 if the system has the type `__be64'. */
-#cmakedefine HAVE___BE64 1
-
-/* Define to 1 if the system has the type `__le16'. */
-#cmakedefine HAVE___LE16 1
-
-/* Define to 1 if the system has the type `__le32'. */
-#cmakedefine HAVE___LE32 1
-
-/* Define to 1 if the system has the type `__le64'. */
-#cmakedefine HAVE___LE64 1
-
 /* Define to 1 if the system has the type `__s16'. */
 #cmakedefine HAVE___S16 1
 
diff --git a/src/include/denc.h b/src/include/denc.h
index 41b333d39d..1ebf1a1ef8 100644
--- a/src/include/denc.h
+++ b/src/include/denc.h
@@ -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:
@@ -1684,7 +1684,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 */								\
diff --git a/src/include/int_types.h b/src/include/int_types.h
index 56b2723f3a..3435cbcbe2 100644
--- a/src/include/int_types.h
+++ b/src/include/int_types.h
@@ -41,15 +41,6 @@ typedef int64_t __s64;
 #endif
 #endif /* LINUX_TYPES_H */
 
-#define __bitwise__
-
-typedef __u16 __bitwise__ __le16;
-typedef __u16 __bitwise__ __be16;
-typedef __u32 __bitwise__ __le32;
-typedef __u32 __bitwise__ __be32;
-typedef __u64 __bitwise__ __le64;
-typedef __u64 __bitwise__ __be64;
-
 #ifndef BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
 #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
 #endif
diff --git a/src/include/msgr.h b/src/include/msgr.h
index 4029443d0a..bda8108082 100644
--- a/src/include/msgr.h
+++ b/src/include/msgr.h
@@ -7,6 +7,14 @@
 
 #include "include/int_types.h"
 
+/* See comment in ceph_fs.h.  */
+#ifndef __KERNEL__
+#include "byteorder.h"
+#define __le16 ceph_le16
+#define __le32 ceph_le32
+#define __le64 ceph_le64
+#endif
+
 /*
  * Data types for message passing layer used by Ceph.
  */
@@ -236,5 +244,10 @@ struct ceph_msg_footer {
 #define CEPH_MSG_FOOTER_NOCRC     (1<<1)   /* no data crc */
 #define CEPH_MSG_FOOTER_SIGNED	  (1<<2)   /* msg was signed */
 
+#ifndef __KERNEL__
+#undef __le16
+#undef __le32
+#undef __le64
+#endif
 
 #endif
diff --git a/src/include/rados.h b/src/include/rados.h
index f9aa1d526c..70ac314a7c 100644
--- a/src/include/rados.h
+++ b/src/include/rados.h
@@ -10,6 +10,14 @@
 #include <stdbool.h>
 #include "msgr.h"
 
+/* See comment in ceph_fs.h.  */
+#ifndef __KERNEL__
+#include "byteorder.h"
+#define __le16 ceph_le16
+#define __le32 ceph_le32
+#define __le64 ceph_le64
+#endif
+
 /*
  * fs id
  */
@@ -632,7 +640,7 @@ struct ceph_osd_op {
 			__le32 chunk_size;
 			__u8 type;              /* CEPH_OSD_CHECKSUM_OP_TYPE_* */
 		} __attribute__ ((packed)) checksum;
-	};
+	} __attribute__ ((packed));
 	__le32 payload_len;
 } __attribute__ ((packed));
 
@@ -662,5 +670,10 @@ struct ceph_osd_reply_head {
 	struct ceph_osd_op ops[0];  /* ops[], object */
 } __attribute__ ((packed));
 
+#ifndef __KERNEL__
+#undef __le16
+#undef __le32
+#undef __le64
+#endif
 
 #endif
diff --git a/src/include/rbd_types.h b/src/include/rbd_types.h
index 0277fd923c..97e51f2ecc 100644
--- a/src/include/rbd_types.h
+++ b/src/include/rbd_types.h
@@ -118,12 +118,12 @@
 #define RBD_MIRROR_PEER_CONFIG_KEY_PREFIX "rbd/mirror/peer/"
 
 struct rbd_info {
-	__le64 max_id;
+	ceph_le64 max_id;
 } __attribute__ ((packed));
 
 struct rbd_obj_snap_ondisk {
-	__le64 id;
-	__le64 image_size;
+	ceph_le64 id;
+	ceph_le64 image_size;
 } __attribute__((packed));
 
 struct rbd_obj_header_ondisk {
@@ -137,11 +137,11 @@ struct rbd_obj_header_ondisk {
 		__u8 comp_type;
 		__u8 unused;
 	} __attribute__((packed)) options;
-	__le64 image_size;
-	__le64 snap_seq;
-	__le32 snap_count;
-	__le32 reserved;
-	__le64 snap_names_len;
+	ceph_le64 image_size;
+	ceph_le64 snap_seq;
+	ceph_le32 snap_count;
+	ceph_le32 reserved;
+	ceph_le64 snap_names_len;
 	struct rbd_obj_snap_ondisk snaps[0];
 } __attribute__((packed));
 
diff --git a/src/include/types.h b/src/include/types.h
index be83e8f89d..79826105b0 100644
--- a/src/include/types.h
+++ b/src/include/types.h
@@ -24,19 +24,9 @@
 #include <fcntl.h>
 #include <string.h>
 
-// <macro hackery>
-// temporarily remap __le* to ceph_le* for benefit of shared kernel/userland headers
-#define __le16 ceph_le16
-#define __le32 ceph_le32
-#define __le64 ceph_le64
 #include "ceph_fs.h"
 #include "ceph_frag.h"
 #include "rbd_types.h"
-#undef __le16
-#undef __le32
-#undef __le64
-// </macro hackery>
-
 
 #ifdef __cplusplus
 #ifndef _BACKWARD_BACKWARD_WARNING_H
diff --git a/src/librbd/operation/ResizeRequest.cc b/src/librbd/operation/ResizeRequest.cc
index 7450bd4bd9..f4efe26782 100644
--- a/src/librbd/operation/ResizeRequest.cc
+++ b/src/librbd/operation/ResizeRequest.cc
@@ -401,9 +401,9 @@ void ResizeRequest<I>::send_update_header() {
   librados::ObjectWriteOperation op;
   if (image_ctx.old_format) {
     // rewrite only the size field of the header
-    // NOTE: format 1 image headers are not stored in fixed endian format
+    ceph_le64 new_size = init_le64(m_new_size);
     bufferlist bl;
-    bl.append(reinterpret_cast<const char*>(&m_new_size), sizeof(m_new_size));
+    bl.append(reinterpret_cast<const char*>(&new_size), sizeof(new_size));
     op.write(offsetof(rbd_obj_header_ondisk, image_size), bl);
   } else {
     cls_client::set_size(&op, m_new_size);
diff --git a/src/mds/locks.c b/src/mds/locks.c
index e057400de2..25646fddd0 100644
--- a/src/mds/locks.c
+++ b/src/mds/locks.c
@@ -3,9 +3,18 @@
 #include <string.h>
 #include <fcntl.h>
 
-#include "include/ceph_fs.h"
 #include "locks.h"
 
+/* Duplicated from ceph_fs.h, which we cannot include into a C file.  */
+#define CEPH_CAP_GSHARED     1  /* client can reads */
+#define CEPH_CAP_GEXCL       2  /* client can read and update */
+#define CEPH_CAP_GCACHE      4  /* (file) client can cache reads */
+#define CEPH_CAP_GRD         8  /* (file) client can read */
+#define CEPH_CAP_GWR        16  /* (file) client can write */
+#define CEPH_CAP_GBUFFER    32  /* (file) client can buffer writes */
+#define CEPH_CAP_GWREXTEND  64  /* (file) client can extend EOF */
+#define CEPH_CAP_GLAZYIO   128  /* (file) client can perform lazy io */
+
 static const struct sm_state_t simplelock[LOCK_MAX] = {
                       // stable     loner  rep state  r     rp   rd   wr   fwr  l    x    caps,other
     [LOCK_SYNC]      = { 0,         false, LOCK_SYNC, ANY,  0,   ANY, 0,   0,   ANY, 0,   CEPH_CAP_GSHARED,0,0,CEPH_CAP_GSHARED },
diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h
index 49627231fa..f375be07af 100644
--- a/src/mds/mdstypes.h
+++ b/src/mds/mdstypes.h
@@ -1422,13 +1422,13 @@ WRITE_CLASS_ENCODER(snaprealm_reconnect_t)
 
 // compat for pre-FLOCK feature
 struct old_ceph_mds_cap_reconnect {
-	__le64 cap_id;
-	__le32 wanted;
-	__le32 issued;
-  __le64 old_size;
+	ceph_le64 cap_id;
+	ceph_le32 wanted;
+	ceph_le32 issued;
+  ceph_le64 old_size;
   struct ceph_timespec old_mtime, old_atime;
-	__le64 snaprealm;
-	__le64 pathbase;        /* base ino for our path to this ino */
+	ceph_le64 snaprealm;
+	ceph_le64 pathbase;        /* base ino for our path to this ino */
 } __attribute__ ((packed));
 WRITE_RAW_ENCODER(old_ceph_mds_cap_reconnect)
 
diff --git a/src/messages/MClientRequest.h b/src/messages/MClientRequest.h
index 20118cdd32..944cd8810c 100644
--- a/src/messages/MClientRequest.h
+++ b/src/messages/MClientRequest.h
@@ -193,7 +193,7 @@ public:
 
 	localmask &= ~CEPH_SETATTR_BTIME;
 
-	head.args.setattr.btime = { 0 };
+	head.args.setattr.btime = { init_le32(0), init_le32(0) };
 	head.args.setattr.mask = localmask;
       }
     }
diff --git a/src/messages/MMonSubscribe.h b/src/messages/MMonSubscribe.h
index 2872c0b46e..2ae6140a85 100644
--- a/src/messages/MMonSubscribe.h
+++ b/src/messages/MMonSubscribe.h
@@ -22,8 +22,8 @@
  * compatibility with old crap
  */
 struct ceph_mon_subscribe_item_old {
-	__le64 unused;
-	__le64 have;
+	ceph_le64 unused;
+	ceph_le64 have;
 	__u8 onetime;
 } __attribute__ ((packed));
 WRITE_RAW_ENCODER(ceph_mon_subscribe_item_old)
diff --git a/src/messages/MOSDOp.h b/src/messages/MOSDOp.h
index ad3a75a67e..43bd400546 100644
--- a/src/messages/MOSDOp.h
+++ b/src/messages/MOSDOp.h
@@ -257,22 +257,22 @@ public:
       // here is the old structure we are encoding to: //
 #if 0
 struct ceph_osd_request_head {
-	__le32 client_inc;                 /* client incarnation */
+	ceph_le32 client_inc;              /* client incarnation */
 	struct ceph_object_layout layout;  /* pgid */
-	__le32 osdmap_epoch;               /* client's osdmap epoch */
+	ceph_le32 osdmap_epoch;            /* client's osdmap epoch */
 
-	__le32 flags;
+	ceph_le32 flags;
 
 	struct ceph_timespec mtime;        /* for mutations only */
 	struct ceph_eversion reassert_version; /* if we are replaying op */
 
-	__le32 object_len;     /* length of object name */
+	ceph_le32 object_len;     /* length of object name */
 
-	__le64 snapid;         /* snapid to read */
-	__le64 snap_seq;       /* writer's snap context */
-	__le32 num_snaps;
+	ceph_le64 snapid;         /* snapid to read */
+	ceph_le64 snap_seq;       /* writer's snap context */
+	ceph_le32 num_snaps;
 
-	__le16 num_ops;
+	ceph_le16 num_ops;
 	struct ceph_osd_op ops[];  /* followed by ops[], obj, ticket, snaps */
 } __attribute__ ((packed));
 #endif
diff --git a/src/msg/async/ProtocolV1.cc b/src/msg/async/ProtocolV1.cc
index 2c7121a9c8..86b84d860c 100644
--- a/src/msg/async/ProtocolV1.cc
+++ b/src/msg/async/ProtocolV1.cc
@@ -801,8 +801,8 @@ CtPtr ProtocolV1::handle_message_middle(char *buffer, int r) {
 CtPtr ProtocolV1::read_message_data_prepare() {
   ldout(cct, 20) << __func__ << dendl;
 
-  unsigned data_len = le32_to_cpu(current_header.data_len);
-  unsigned data_off = le32_to_cpu(current_header.data_off);
+  unsigned data_len = current_header.data_len;
+  unsigned data_off = current_header.data_off;
 
   if (data_len) {
     // get a buffer
diff --git a/src/msg/async/ProtocolV2.cc b/src/msg/async/ProtocolV2.cc
index 7e98f55d66..edda424e35 100644
--- a/src/msg/async/ProtocolV2.cc
+++ b/src/msg/async/ProtocolV2.cc
@@ -498,8 +498,8 @@ ssize_t ProtocolV2::write_message(Message *m, bool more) {
   ceph_msg_header2 header2{header.seq,        header.tid,
                            header.type,       header.priority,
                            header.version,
-                           0,                 header.data_off,
-                           ack_seq,
+                           init_le32(0),      header.data_off,
+                           init_le64(ack_seq),
                            footer.flags,      header.compat_version,
                            header.reserved};
 
@@ -799,7 +799,7 @@ CtPtr ProtocolV2::_banner_exchange(CtRef callback) {
 }
 
 CtPtr ProtocolV2::_wait_for_peer_banner() {
-  unsigned banner_len = strlen(CEPH_BANNER_V2_PREFIX) + sizeof(__le16);
+  unsigned banner_len = strlen(CEPH_BANNER_V2_PREFIX) + sizeof(ceph_le16);
   return READ(banner_len, _handle_peer_banner);
 }
 
@@ -827,7 +827,7 @@ CtPtr ProtocolV2::_handle_peer_banner(rx_buffer_t &&buffer, int r) {
   uint16_t payload_len;
   bufferlist bl;
   buffer->set_offset(banner_prefix_len);
-  buffer->set_length(sizeof(__le16));
+  buffer->set_length(sizeof(ceph_le16));
   bl.push_back(std::move(buffer));
   auto ti = bl.cbegin();
   try {
@@ -1393,15 +1393,16 @@ CtPtr ProtocolV2::handle_message() {
                          current_header.type,
                          current_header.priority,
                          current_header.version,
-                         msg_frame.front_len(),
-                         msg_frame.middle_len(),
-                         msg_frame.data_len(),
+                         init_le32(msg_frame.front_len()),
+                         init_le32(msg_frame.middle_len()),
+                         init_le32(msg_frame.data_len()),
                          current_header.data_off,
                          peer_name,
                          current_header.compat_version,
                          current_header.reserved,
-                         0};
-  ceph_msg_footer footer{0, 0, 0, 0, current_header.flags};
+                         init_le32(0)};
+  ceph_msg_footer footer{init_le32(0), init_le32(0),
+	                 init_le32(0), init_le64(0), current_header.flags};
 
   Message *message = decode_message(cct, 0, header, footer,
       msg_frame.front(),
diff --git a/src/msg/async/frames_v2.h b/src/msg/async/frames_v2.h
index 2abce8ae0d..3f8708f237 100644
--- a/src/msg/async/frames_v2.h
+++ b/src/msg/async/frames_v2.h
@@ -58,12 +58,12 @@ enum class Tag : __u8 {
 struct segment_t {
   // TODO: this will be dropped with support for `allocation policies`.
   // We need them because of the rx_buffers zero-copy optimization.
-  static constexpr __le16 PAGE_SIZE_ALIGNMENT{4096};
+  static constexpr __u16 PAGE_SIZE_ALIGNMENT = 4096;
 
-  static constexpr __le16 DEFAULT_ALIGNMENT = sizeof(void *);
+  static constexpr __u16 DEFAULT_ALIGNMENT = sizeof(void *);
 
-  __le32 length;
-  __le16 alignment;
+  ceph_le32 length;
+  ceph_le16 alignment;
 } __attribute__((packed));
 
 struct SegmentIndex {
@@ -98,11 +98,11 @@ struct preamble_block_t {
   // third to #segments - MAX_NUM_SEGMENTS and so on.
   __u8 num_segments;
 
-  std::array<segment_t, MAX_NUM_SEGMENTS> segments;
+  segment_t segments[MAX_NUM_SEGMENTS];
   __u8 _reserved[2];
 
   // CRC32 for this single preamble block.
-  __le32 crc;
+  ceph_le32 crc;
 } __attribute__((packed));
 static_assert(sizeof(preamble_block_t) % CRYPTO_BLOCK_SIZE == 0);
 static_assert(std::is_standard_layout<preamble_block_t>::value);
@@ -128,7 +128,7 @@ static_assert(std::is_standard_layout<preamble_block_t>::value);
 // frame abortion facility.
 struct epilogue_plain_block_t {
   __u8 late_flags;
-  std::array<__le32, MAX_NUM_SEGMENTS> crc_values;
+  ceph_le32 crc_values[MAX_NUM_SEGMENTS];
 } __attribute__((packed));
 static_assert(std::is_standard_layout<epilogue_plain_block_t>::value);
 
@@ -177,8 +177,7 @@ private:
   };
   ceph::bufferlist::contiguous_filler preamble_filler;
 
-  __u8 calc_num_segments(
-    const std::array<segment_t, MAX_NUM_SEGMENTS>& segments)
+  __u8 calc_num_segments(const segment_t segments[])
   {
     for (__u8 num = SegmentsNumV; num > 0; num--) {
       if (segments[num-1].length) {
@@ -203,9 +202,9 @@ private:
     // implementation detail: the first bufferlist of Frame::segments carries
     // space for preamble. This glueing isn't a part of the onwire format but
     // just our private detail.
-    main_preamble.segments.front().length =
-        segments.front().length() - FRAME_PREAMBLE_SIZE;
-    main_preamble.segments.front().alignment = alignments.front();
+    main_preamble.segments[0].length =
+        segments[0].length() - FRAME_PREAMBLE_SIZE;
+    main_preamble.segments[0].alignment = alignments[0];
 
     // there is no business in issuing frame without at least one segment
     // filled.
diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h
index 6ce1b3a0b2..3016d2c53f 100644
--- a/src/msg/msg_types.h
+++ b/src/msg/msg_types.h
@@ -77,7 +77,7 @@ public:
   bool is_mgr() const { return type() == TYPE_MGR; }
 
   operator ceph_entity_name() const {
-    ceph_entity_name n = { _type, {init_le64(_num)} };
+    ceph_entity_name n = { _type, init_le64(_num) };
     return n;
   }
 
@@ -154,8 +154,8 @@ namespace std {
 
 // define a wire format for sockaddr that matches Linux's.
 struct ceph_sockaddr_storage {
-  __le16 ss_family;
-  __u8 __ss_padding[128 - sizeof(__le16)];
+  ceph_le16 ss_family;
+  __u8 __ss_padding[128 - sizeof(ceph_le16)];
 
   void encode(ceph::buffer::list& bl) const {
     struct ceph_sockaddr_storage ss = *this;
diff --git a/src/os/Transaction.h b/src/os/Transaction.h
index 20d554819c..7ecd173309 100644
--- a/src/os/Transaction.h
+++ b/src/os/Transaction.h
@@ -159,42 +159,42 @@ public:
   };
 
   struct Op {
-    __le32 op;
-    __le32 cid;
-    __le32 oid;
-    __le64 off;
-    __le64 len;
-    __le32 dest_cid;
-    __le32 dest_oid;                  //OP_CLONE, OP_CLONERANGE
-    __le64 dest_off;                  //OP_CLONERANGE
+    ceph_le32 op;
+    ceph_le32 cid;
+    ceph_le32 oid;
+    ceph_le64 off;
+    ceph_le64 len;
+    ceph_le32 dest_cid;
+    ceph_le32 dest_oid;               //OP_CLONE, OP_CLONERANGE
+    ceph_le64 dest_off;               //OP_CLONERANGE
     union {
 	struct {
-	  __le32 hint_type;             //OP_COLL_HINT
-	};
+	  ceph_le32 hint_type;          //OP_COLL_HINT
+	} __attribute__ ((packed));
 	struct {
-	  __le32 alloc_hint_flags;      //OP_SETALLOCHINT
-	};
-    };
-    __le64 expected_object_size;      //OP_SETALLOCHINT
-    __le64 expected_write_size;       //OP_SETALLOCHINT
-    __le32 split_bits;                //OP_SPLIT_COLLECTION2,OP_COLL_SET_BITS,
+	  ceph_le32 alloc_hint_flags;   //OP_SETALLOCHINT
+	} __attribute__ ((packed));
+    } __attribute__ ((packed));
+    ceph_le64 expected_object_size;   //OP_SETALLOCHINT
+    ceph_le64 expected_write_size;    //OP_SETALLOCHINT
+    ceph_le32 split_bits;             //OP_SPLIT_COLLECTION2,OP_COLL_SET_BITS,
                                       //OP_MKCOLL
-    __le32 split_rem;                 //OP_SPLIT_COLLECTION2
+    ceph_le32 split_rem;              //OP_SPLIT_COLLECTION2
   } __attribute__ ((packed)) ;
 
   struct TransactionData {
-    __le64 ops;
-    __le32 largest_data_len;
-    __le32 largest_data_off;
-    __le32 largest_data_off_in_data_bl;
-    __le32 fadvise_flags;
+    ceph_le64 ops;
+    ceph_le32 largest_data_len;
+    ceph_le32 largest_data_off;
+    ceph_le32 largest_data_off_in_data_bl;
+    ceph_le32 fadvise_flags;
 
     TransactionData() noexcept :
-      ops(0),
-      largest_data_len(0),
-      largest_data_off(0),
-      largest_data_off_in_data_bl(0),
-	fadvise_flags(0) { }
+      ops(init_le64(0)),
+      largest_data_len(init_le32(0)),
+      largest_data_off(init_le32(0)),
+      largest_data_off_in_data_bl(init_le32(0)),
+      fadvise_flags(init_le32(0)) { }
 
     // override default move operations to reset default values
     TransactionData(TransactionData&& other) noexcept :
@@ -237,11 +237,11 @@ public:
 private:
   TransactionData data;
 
-  std::map<coll_t, __le32> coll_index;
-  std::map<ghobject_t, __le32> object_index;
+  std::map<coll_t, uint32_t> coll_index;
+  std::map<ghobject_t, uint32_t> object_index;
 
-  __le32 coll_id {0};
-  __le32 object_id {0};
+  uint32_t coll_id = 0;
+  uint32_t object_id = 0;
 
   ceph::buffer::list data_bl;
   ceph::buffer::list op_bl;
@@ -297,7 +297,7 @@ public:
   Transaction& operator=(const Transaction& other) = default;
 
   // expose object_index for FileStore::Op's benefit
-  const std::map<ghobject_t, __le32>& get_object_index() const {
+  const std::map<ghobject_t, uint32_t>& get_object_index() const {
     return object_index;
   }
 
@@ -394,8 +394,8 @@ public:
   }
 
   void _update_op(Op* op,
-    std::vector<__le32> &cm,
-    std::vector<__le32> &om) {
+    std::vector<uint32_t> &cm,
+    std::vector<uint32_t> &om) {
 
     switch (op->op) {
     case OP_NOP:
@@ -494,8 +494,8 @@ public:
   }
   void _update_op_bl(
     ceph::buffer::list& bl,
-    std::vector<__le32> &cm,
-    std::vector<__le32> &om) {
+    std::vector<uint32_t> &cm,
+    std::vector<uint32_t> &om) {
     for (auto& bp : bl.buffers()) {
       ceph_assert(bp.length() % sizeof(Op) == 0);
 
@@ -510,28 +510,28 @@ public:
   /// Append the operations of the parameter to this Transaction. Those operations are removed from the parameter Transaction
   void append(Transaction& other) {
 
-    data.ops += other.data.ops;
+    data.ops = data.ops + other.data.ops;
     if (other.data.largest_data_len > data.largest_data_len) {
 	data.largest_data_len = other.data.largest_data_len;
 	data.largest_data_off = other.data.largest_data_off;
 	data.largest_data_off_in_data_bl = data_bl.length() + other.data.largest_data_off_in_data_bl;
     }
-    data.fadvise_flags |= other.data.fadvise_flags;
+    data.fadvise_flags = data.fadvise_flags | other.data.fadvise_flags;
     on_applied.splice(on_applied.end(), other.on_applied);
     on_commit.splice(on_commit.end(), other.on_commit);
     on_applied_sync.splice(on_applied_sync.end(), other.on_applied_sync);
 
     //append coll_index & object_index
-    std::vector<__le32> cm(other.coll_index.size());
-    std::map<coll_t, __le32>::iterator coll_index_p;
+    std::vector<uint32_t> cm(other.coll_index.size());
+    std::map<coll_t, uint32_t>::iterator coll_index_p;
     for (coll_index_p = other.coll_index.begin();
          coll_index_p != other.coll_index.end();
          ++coll_index_p) {
       cm[coll_index_p->second] = _get_coll_id(coll_index_p->first);
     }
 
-    std::vector<__le32> om(other.object_index.size());
-    std::map<ghobject_t, __le32>::iterator object_index_p;
+    std::vector<uint32_t> om(other.object_index.size());
+    std::map<ghobject_t, uint32_t>::iterator object_index_p;
     for (object_index_p = other.object_index.begin();
          object_index_p != other.object_index.end();
          ++object_index_p) {
@@ -570,7 +570,7 @@ public:
     size_t final_size = sizeof(__u32) * 2 + sizeof(data);
 
     // coll_index second and object_index second
-    final_size += (coll_index.size() + object_index.size()) * sizeof(__le32);
+    final_size += (coll_index.size() + object_index.size()) * sizeof(__u32);
 
     // coll_index first
     for (auto p = coll_index.begin(); p != coll_index.end(); ++p) {
@@ -665,14 +665,14 @@ public:
       ops = t->data.ops;
       op_buffer_p = t->op_bl.c_str();
 
-      std::map<coll_t, __le32>::iterator coll_index_p;
+      std::map<coll_t, uint32_t>::iterator coll_index_p;
       for (coll_index_p = t->coll_index.begin();
            coll_index_p != t->coll_index.end();
            ++coll_index_p) {
         colls[coll_index_p->second] = coll_index_p->first;
       }
 
-      std::map<ghobject_t, __le32>::iterator object_index_p;
+      std::map<ghobject_t, uint32_t>::iterator object_index_p;
       for (object_index_p = t->object_index.begin();
            object_index_p != t->object_index.end();
            ++object_index_p) {
@@ -729,11 +729,11 @@ public:
       decode_str_set_to_bl(data_bl_p, pbl);
     }
 
-    const ghobject_t &get_oid(__le32 oid_id) {
+    const ghobject_t &get_oid(uint32_t oid_id) {
       ceph_assert(oid_id < objects.size());
       return objects[oid_id];
     }
-    const coll_t &get_cid(__le32 cid_id) {
+    const coll_t &get_cid(uint32_t cid_id) {
       ceph_assert(cid_id < colls.size());
       return colls[cid_id];
     }
@@ -767,21 +767,21 @@ private:
     memset(p, 0, sizeof(Op));
     return reinterpret_cast<Op*>(p);
   }
-  __le32 _get_coll_id(const coll_t& coll) {
-    std::map<coll_t, __le32>::iterator c = coll_index.find(coll);
+  uint32_t _get_coll_id(const coll_t& coll) {
+    std::map<coll_t, uint32_t>::iterator c = coll_index.find(coll);
     if (c != coll_index.end())
       return c->second;
 
-    __le32 index_id = coll_id++;
+    uint32_t index_id = coll_id++;
     coll_index[coll] = index_id;
     return index_id;
   }
-  __le32 _get_object_id(const ghobject_t& oid) {
-    std::map<ghobject_t, __le32>::iterator o = object_index.find(oid);
+  uint32_t _get_object_id(const ghobject_t& oid) {
+    std::map<ghobject_t, uint32_t>::iterator o = object_index.find(oid);
     if (o != object_index.end())
       return o->second;
 
-    __le32 index_id = object_id++;
+    uint32_t index_id = object_id++;
     object_index[oid] = index_id;
     return index_id;
   }
@@ -791,7 +791,7 @@ public:
   void nop() {
     Op* _op = _get_next_op();
     _op->op = OP_NOP;
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /**
    * create
@@ -804,7 +804,7 @@ public:
     _op->op = OP_CREATE;
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /**
    * touch
@@ -817,7 +817,7 @@ public:
     _op->op = OP_TOUCH;
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /**
    * Write data to an offset within an object. If the object is too
@@ -850,7 +850,7 @@ public:
 	data.largest_data_off = off;
 	data.largest_data_off_in_data_bl = orig_len + sizeof(__u32);  // we are about to
     }
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /**
    * zero out the indicated byte range within an object. Some
@@ -869,7 +869,7 @@ public:
     _op->oid = _get_object_id(oid);
     _op->off = off;
     _op->len = len;
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /// Discard all data in the object beyond the specified size.
   void truncate(const coll_t& cid, const ghobject_t& oid, uint64_t off) {
@@ -878,7 +878,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
     _op->off = off;
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /// Remove an object. All four parts of the object are removed.
   void remove(const coll_t& cid, const ghobject_t& oid) {
@@ -886,7 +886,7 @@ public:
     _op->op = OP_REMOVE;
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /// Set an xattr of an object
   void setattr(const coll_t& cid, const ghobject_t& oid, const char* name, ceph::buffer::list& val) {
@@ -902,7 +902,7 @@ public:
     _op->oid = _get_object_id(oid);
     encode(s, data_bl);
     encode(val, data_bl);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /// Set multiple xattrs of an object
   void setattrs(const coll_t& cid, const ghobject_t& oid, const std::map<std::string,ceph::buffer::ptr>& attrset) {
@@ -912,7 +912,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
     encode(attrset, data_bl);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /// Set multiple xattrs of an object
   void setattrs(const coll_t& cid, const ghobject_t& oid, const std::map<std::string,ceph::buffer::list>& attrset) {
@@ -922,7 +922,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
     encode(attrset, data_bl);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /// remove an xattr from an object
   void rmattr(const coll_t& cid, const ghobject_t& oid, const char *name) {
@@ -937,7 +937,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
     encode(s, data_bl);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /// remove all xattrs from an object
   void rmattrs(const coll_t& cid, const ghobject_t& oid) {
@@ -945,7 +945,7 @@ public:
     _op->op = OP_RMATTRS;
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /**
    * Clone an object into another object.
@@ -965,7 +965,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
     _op->dest_oid = _get_object_id(noid);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /**
    * Clone a byte range from one object to another.
@@ -990,7 +990,7 @@ public:
     _op->off = srcoff;
     _op->len = srclen;
     _op->dest_off = dstoff;
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   /// Create the collection
@@ -999,7 +999,7 @@ public:
     _op->op = OP_MKCOLL;
     _op->cid = _get_coll_id(cid);
     _op->split_bits = bits;
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   /**
@@ -1017,7 +1017,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->hint_type = type;
     encode(hint, data_bl);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   /// remove the collection, the collection must be empty
@@ -1025,7 +1025,7 @@ public:
     Op* _op = _get_next_op();
     _op->op = OP_RMCOLL;
     _op->cid = _get_coll_id(cid);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   void collection_move(const coll_t& cid, const coll_t &oldcid, const ghobject_t& oid)
     __attribute__ ((deprecated)) {
@@ -1036,13 +1036,13 @@ public:
 	_op->cid = _get_coll_id(oldcid);
 	_op->oid = _get_object_id(oid);
 	_op->dest_cid = _get_coll_id(cid);
-	data.ops++;
+	data.ops = data.ops + 1;
 
 	_op = _get_next_op();
 	_op->op = OP_COLL_REMOVE;
 	_op->cid = _get_coll_id(oldcid);
 	_op->oid = _get_object_id(oid);
-	data.ops++;
+	data.ops = data.ops + 1;
     }
   void collection_move_rename(const coll_t& oldcid, const ghobject_t& oldoid,
 				const coll_t &cid, const ghobject_t& oid) {
@@ -1052,7 +1052,7 @@ public:
     _op->oid = _get_object_id(oldoid);
     _op->dest_cid = _get_coll_id(cid);
     _op->dest_oid = _get_object_id(oid);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   void try_rename(const coll_t &cid, const ghobject_t& oldoid,
                   const ghobject_t& oid) {
@@ -1061,7 +1061,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oldoid);
     _op->dest_oid = _get_object_id(oid);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   /// Remove omap from oid
@@ -1073,7 +1073,7 @@ public:
     _op->op = OP_OMAP_CLEAR;
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
   /// Set keys on oid omap.  Replaces duplicate keys.
   void omap_setkeys(
@@ -1087,7 +1087,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
     encode(attrset, data_bl);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   /// Set keys on an oid omap (ceph::buffer::list variant).
@@ -1101,7 +1101,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
     data_bl.append(attrset_bl);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   /// Remove keys from oid omap
@@ -1116,7 +1116,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
     encode(keys, data_bl);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   /// Remove keys from oid omap
@@ -1130,7 +1130,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
     data_bl.append(keys_bl);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   /// Remove key range from oid omap
@@ -1147,7 +1147,7 @@ public:
 	_op->oid = _get_object_id(oid);
 	encode(first, data_bl);
 	encode(last, data_bl);
-	data.ops++;
+	data.ops = data.ops + 1;
     }
 
   /// Set omap header
@@ -1162,7 +1162,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->oid = _get_object_id(oid);
     encode(bl, data_bl);
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   /// Split collection based on given prefixes, objects matching the specified bits/rem are
@@ -1178,7 +1178,7 @@ public:
     _op->dest_cid = _get_coll_id(destination);
     _op->split_bits = bits;
     _op->split_rem = rem;
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   /// Merge collection into another.
@@ -1191,7 +1191,7 @@ public:
     _op->cid = _get_coll_id(cid);
     _op->dest_cid = _get_coll_id(destination);
     _op->split_bits = bits;
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   void collection_set_bits(
@@ -1201,7 +1201,7 @@ public:
     _op->op = OP_COLL_SET_BITS;
     _op->cid = _get_coll_id(cid);
     _op->split_bits = bits;
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   /// Set allocation hint for an object
@@ -1220,7 +1220,7 @@ public:
     _op->expected_object_size = expected_object_size;
     _op->expected_write_size = expected_write_size;
     _op->alloc_hint_flags = flags;
-    data.ops++;
+    data.ops = data.ops + 1;
   }
 
   void encode(ceph::buffer::list& bl) const {
diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc
index bf1407ba7b..5359848ed9 100644
--- a/src/os/bluestore/BlueStore.cc
+++ b/src/os/bluestore/BlueStore.cc
@@ -641,9 +641,9 @@ struct Int64ArrayMergeOperator : public KeyValueDB::MergeOperator {
     ceph_assert(llen == rlen);
     ceph_assert((rlen % 8) == 0);
     new_value->resize(rlen);
-    const __le64* lv = (const __le64*)ldata;
-    const __le64* rv = (const __le64*)rdata;
-    __le64* nv = &(__le64&)new_value->at(0);
+    const ceph_le64* lv = (const ceph_le64*)ldata;
+    const ceph_le64* rv = (const ceph_le64*)rdata;
+    ceph_le64* nv = &(ceph_le64&)new_value->at(0);
     for (size_t i = 0; i < rlen >> 3; ++i) {
       nv[i] = lv[i] + rv[i];
     }
diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h
index 87fbd981d9..f58a079c4a 100644
--- a/src/os/bluestore/bluestore_types.h
+++ b/src/os/bluestore/bluestore_types.h
@@ -756,11 +756,11 @@ public:
     case 1:
       return reinterpret_cast<const uint8_t*>(p)[i];
     case 2:
-      return reinterpret_cast<const __le16*>(p)[i];
+      return reinterpret_cast<const ceph_le16*>(p)[i];
     case 4:
-      return reinterpret_cast<const __le32*>(p)[i];
+      return reinterpret_cast<const ceph_le32*>(p)[i];
     case 8:
-      return reinterpret_cast<const __le64*>(p)[i];
+      return reinterpret_cast<const ceph_le64*>(p)[i];
     default:
       ceph_abort_msg("unrecognized csum word size");
     }
diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h
index e298c6824c..5888f5dd4b 100644
--- a/src/osd/OSDMap.h
+++ b/src/osd/OSDMap.h
@@ -111,7 +111,7 @@ std::ostream& operator<<(std::ostream& out, const osd_xinfo_t& xi);
 struct PGTempMap {
 #if 1
   ceph::buffer::list data;
-  typedef btree::btree_map<pg_t,int32_t*> map_t;
+  typedef btree::btree_map<pg_t,ceph_le32*> map_t;
   map_t map;
 
   void encode(ceph::buffer::list& bl) const {
@@ -120,7 +120,7 @@ struct PGTempMap {
     encode(n, bl);
     for (auto &p : map) {
       encode(p.first, bl);
-      bl.append((char*)p.second, (*p.second + 1) * sizeof(int32_t));
+      bl.append((char*)p.second, (*p.second + 1) * sizeof(ceph_le32));
     }
   }
   void decode(ceph::buffer::list::const_iterator& p) {
@@ -152,7 +152,7 @@ struct PGTempMap {
     //map.reserve(n);
     char *start = data.c_str();
     for (auto i : offsets) {
-      map.insert(map.end(), std::make_pair(i.first, (int32_t*)(start + i.second)));
+      map.insert(map.end(), std::make_pair(i.first, (ceph_le32*)(start + i.second)));
     }
   }
   void rebuild() {
@@ -176,8 +176,8 @@ struct PGTempMap {
 	current.first = it->first;
 	ceph_assert(it->second);
 	current.second.resize(*it->second);
-	int32_t *p = it->second + 1;
-	for (int n = 0; n < *it->second; ++n, ++p) {
+	ceph_le32 *p = it->second + 1;
+	for (uint32_t n = 0; n < *it->second; ++n, ++p) {
 	  current.second[n] = *p;
 	}
       }
@@ -239,18 +239,18 @@ struct PGTempMap {
   }
   void set(pg_t pgid, const mempool::osdmap::vector<int32_t>& v) {
     using ceph::encode;
-    size_t need = sizeof(int32_t) * (1 + v.size());
+    size_t need = sizeof(ceph_le32) * (1 + v.size());
     if (need < data.get_append_buffer_unused_tail_length()) {
       ceph::buffer::ptr z(data.get_append_buffer_unused_tail_length());
       z.zero();
       data.append(z.c_str(), z.length());
     }
     encode(v, data);
-    map[pgid] = (int32_t*)(data.back().end_c_str()) - (1 + v.size());
+    map[pgid] = (ceph_le32*)(data.back().end_c_str()) - (1 + v.size());
   }
   mempool::osdmap::vector<int32_t> get(pg_t pgid) {
     mempool::osdmap::vector<int32_t> v;
-    int32_t *p = map[pgid];
+    ceph_le32 *p = map[pgid];
     size_t n = *p++;
     v.resize(n);
     for (size_t i = 0; i < n; ++i, ++p) {
diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc
index 840d9ec112..9801ab4dbf 100644
--- a/src/osd/PrimaryLogPG.cc
+++ b/src/osd/PrimaryLogPG.cc
@@ -4899,10 +4899,10 @@ struct FillInVerifyExtent : public Context {
   uint64_t size;
   OSDService *osd;
   hobject_t soid;
-  __le32 flags;
+  uint32_t flags;
   FillInVerifyExtent(ceph_le64 *r, int32_t *rv, bufferlist *blp,
 		     std::optional<uint32_t> mc, uint64_t size,
-		     OSDService *osd, hobject_t soid, __le32 flags) :
+		     OSDService *osd, hobject_t soid, uint32_t flags) :
     r(r), rval(rv), outdatap(blp), maybe_crc(mc),
     size(size), osd(osd), soid(soid), flags(flags) {}
   void finish(int len) override {
@@ -5018,7 +5018,7 @@ struct C_ChecksumRead : public Context {
   C_ChecksumRead(PrimaryLogPG *primary_log_pg, OSDOp &osd_op,
 		 Checksummer::CSumType csum_type, bufferlist &&init_value_bl,
 		 std::optional<uint32_t> maybe_crc, uint64_t size,
-		 OSDService *osd, hobject_t soid, __le32 flags)
+		 OSDService *osd, hobject_t soid, uint32_t flags)
     : primary_log_pg(primary_log_pg), osd_op(osd_op),
       csum_type(csum_type), init_value_bl(std::move(init_value_bl)),
       fill_extent_ctx(new FillInVerifyExtent(&read_length, &osd_op.rval,
@@ -5230,7 +5230,7 @@ struct C_ExtentCmpRead : public Context {
 
   C_ExtentCmpRead(PrimaryLogPG *primary_log_pg, OSDOp &osd_op,
 		  std::optional<uint32_t> maybe_crc, uint64_t size,
-		  OSDService *osd, hobject_t soid, __le32 flags)
+		  OSDService *osd, hobject_t soid, uint32_t flags)
     : primary_log_pg(primary_log_pg), osd_op(osd_op),
       fill_extent_ctx(new FillInVerifyExtent(&read_length, &osd_op.rval,
 					     &read_bl, maybe_crc, size,
@@ -5600,7 +5600,7 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
       }
     }
 
-    // TODO: check endianness (__le32 vs uint32_t, etc.)
+    // TODO: check endianness (ceph_le32 vs uint32_t, etc.)
     // The fields in ceph_osd_op are little-endian (according to the definition in rados.h),
     // but the code in this function seems to treat them as native-endian.  What should the
     // tracepoints do?
@@ -6464,9 +6464,8 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
       ++ctx->num_write;
       {
 	tracepoint(osd, do_osd_op_pre_create, soid.oid.name.c_str(), soid.snap.val);
-        int flags = le32_to_cpu(op.flags);
 	if (obs.exists && !oi.is_whiteout() &&
-	    (flags & CEPH_OSD_OP_FLAG_EXCL)) {
+	    (op.flags & CEPH_OSD_OP_FLAG_EXCL)) {
           result = -EEXIST; /* this is an exclusive create */
 	} else {
 	  if (osd_op.indata.length()) {
diff --git a/src/osd/mClockOpClassSupport.cc b/src/osd/mClockOpClassSupport.cc
index 22416e064f..49cad6ced5 100644
--- a/src/osd/mClockOpClassSupport.cc
+++ b/src/osd/mClockOpClassSupport.cc
@@ -85,13 +85,9 @@ namespace ceph {
       if (osd_op_type_t::client_op != type) {
 	return type;
       } else {
-	// get_header returns ceph_msg_header type, ceph_msg_header
-	// stores type as unsigned little endian, so be sure to
-	// convert to CPU byte ordering
 	std::optional<OpRequestRef> op_ref_maybe = op.maybe_get_op();
 	ceph_assert(op_ref_maybe);
-	__le16 mtype_le = (*op_ref_maybe)->get_req()->get_header().type;
-	__u16 mtype = le16_to_cpu(mtype_le);
+	__u16 mtype = (*op_ref_maybe)->get_req()->get_header().type;
 	if (rep_op_msg_bitset.test(mtype)) {
 	  return osd_op_type_t::osd_rep_op;
 	} else {
diff --git a/src/test/common/test_time.cc b/src/test/common/test_time.cc
index a643337d4a..347916114b 100644
--- a/src/test/common/test_time.cc
+++ b/src/test/common/test_time.cc
@@ -51,7 +51,7 @@ static constexpr uint32_t bns = 123456789;
 static constexpr uint32_t bus = 123456;
 static constexpr time_t btt = bs;
 static constexpr struct timespec bts = { bs, bns };
-static constexpr struct ceph_timespec bcts = { bs, bns };
+static struct ceph_timespec bcts = { init_le32(bs), init_le32(bns) };
 static constexpr struct timeval btv = { bs, bus };
 static constexpr double bd = bs + ((double)bns / 1000000000.);
 
diff --git a/src/test/librados/aio.cc b/src/test/librados/aio.cc
index 503f992c06..a8ca47b8b8 100644
--- a/src/test/librados/aio.cc
+++ b/src/test/librados/aio.cc
@@ -226,8 +226,8 @@ TEST(LibRadosAio, RoundTrip3) {
   rados_read_op_read(op2, 0, sizeof(buf2), buf2, NULL, NULL);
   rados_read_op_set_flags(op2, LIBRADOS_OP_FLAG_FADVISE_NOCACHE |
 			       LIBRADOS_OP_FLAG_FADVISE_RANDOM);
-  __le32 init_value = -1;
-  __le32 checksum[2];
+  ceph_le32 init_value = init_le32(-1);
+  ceph_le32 checksum[2];
   rados_read_op_checksum(op2, LIBRADOS_CHECKSUM_TYPE_CRC32C,
 			 reinterpret_cast<char *>(&init_value),
 			 sizeof(init_value), 0, 0, 0,
diff --git a/src/tools/immutable_object_cache/Types.h b/src/tools/immutable_object_cache/Types.h
index 30324d5e89..7967d16564 100644
--- a/src/tools/immutable_object_cache/Types.h
+++ b/src/tools/immutable_object_cache/Types.h
@@ -15,7 +15,7 @@ namespace {
 struct HeaderHelper {
   uint8_t v;
   uint8_t c_v;
-  uint32_t len;
+  ceph_le32 len;
 }__attribute__((packed));
 
 inline uint8_t get_header_size() {
diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc
index 79c390a5f4..8533855eb5 100644
--- a/src/tools/rados/rados.cc
+++ b/src/tools/rados/rados.cc
@@ -497,8 +497,8 @@ static int do_get(IoCtx& io_ctx, const char *objname, const char *outfile, unsig
 static int do_copy(IoCtx& io_ctx, const char *objname,
 		   IoCtx& target_ctx, const char *target_obj)
 {
-  __le32 src_fadvise_flags = LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL | LIBRADOS_OP_FLAG_FADVISE_NOCACHE;
-  __le32 dest_fadvise_flags = LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL | LIBRADOS_OP_FLAG_FADVISE_DONTNEED;
+  uint32_t src_fadvise_flags = LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL | LIBRADOS_OP_FLAG_FADVISE_NOCACHE;
+  uint32_t dest_fadvise_flags = LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL | LIBRADOS_OP_FLAG_FADVISE_DONTNEED;
   ObjectWriteOperation op;
   op.copy_from(objname, io_ctx, 0, src_fadvise_flags);
   op.set_op_flags2(dest_fadvise_flags);
diff --git a/src/tools/rbd_recover_tool/metadata_h b/src/tools/rbd_recover_tool/metadata_h
index 4aa491b5bd..b736ceea77 100644
--- a/src/tools/rbd_recover_tool/metadata_h
+++ b/src/tools/rbd_recover_tool/metadata_h
@@ -80,19 +80,19 @@ function get_image_format_by_hobject()
 # 1		__u8 comp_type;
 # 1		__u8 unused;
 # 	} __attribute__((packed)) options;
-# 8	__le64 image_size;//hexdump -C s=80 n=8
-# 8	__le64 snap_seq;  //hexdump -C s=88 n=8
-# 4	__le32 snap_count;//hexdump -C s=96 n=4
-# 4	__le32 reserved;
-# 8	__le64 snap_names_len;//hexdump -C s=104 n=8
+# 8	ceph_le64 image_size;//hexdump -C s=80 n=8
+# 8	ceph_le64 snap_seq;  //hexdump -C s=88 n=8
+# 4	ceph_le32 snap_count;//hexdump -C s=96 n=4
+# 4	ceph_le32 reserved;
+# 8	ceph_le64 snap_names_len;//hexdump -C s=104 n=8
 # 	struct rbd_obj_snap_ondisk snaps[0];
 # } __attribute__((packed));
 #
 # sizeof(rbd_obj_header_ondisk): 112
 #
 # struct rbd_obj_snap_ondisk {
-# 8	__le64 id;    //hexdump -C s=112+i*16 n=8   , i=[0, snap_count)
-# 8	__le64 image_size;//hexdump -C s=112+i*16+8 n=8, i=[0, snap_count)
+# 8	ceph_le64 id;    //hexdump -C s=112+i*16 n=8   , i=[0, snap_count)
+# 8	ceph_le64 image_size;//hexdump -C s=112+i*16+8 n=8, i=[0, snap_count)
 # } __attribute__((packed));
 # sizeof(rbd_obj_snap_ondisk): 16
 #
