]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: Endian fix for PGTempMap handling
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Mon, 2 Sep 2019 19:28:44 +0000 (21:28 +0200)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Wed, 2 Oct 2019 16:30:57 +0000 (18:30 +0200)
struct PGTempMap in osd/OSDMap.h tracks a number of int32_t pointers
pointing into a buffer list. But that list was generated via encode,
which means int members are bytes-swapped. Fixed by using ceph_le32
pointers instead.

Fixes (partially): https://tracker.ceph.com/issues/41605

Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
(cherry picked from commit c3ebaf9aac7295c2426c8cb26def2ffd148c3e7a)
Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
src/osd/OSDMap.h

index 1f7e74f4d838243fd37d4d27df37f6fb6723b7dd..61a80c4961e7b13bb5325a9ed0f42843fabf79ba 100644 (file)
@@ -106,7 +106,7 @@ ostream& operator<<(ostream& out, const osd_xinfo_t& xi);
 struct PGTempMap {
 #if 1
   bufferlist 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(bufferlist& bl) const {
@@ -115,7 +115,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(bufferlist::const_iterator& p) {
@@ -147,7 +147,7 @@ struct PGTempMap {
     //map.reserve(n);
     char *start = data.c_str();
     for (auto i : offsets) {
-      map.insert(map.end(), make_pair(i.first, (int32_t*)(start + i.second)));
+      map.insert(map.end(), make_pair(i.first, (ceph_le32*)(start + i.second)));
     }
   }
   void rebuild() {
@@ -171,8 +171,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;
        }
       }
@@ -234,18 +234,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()) {
       bufferptr 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) {