]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
messages/MOSDPing: initialize MOSDPing padding
authorSage Weil <sage@redhat.com>
Fri, 16 Jun 2017 02:18:08 +0000 (22:18 -0400)
committerVikhyat Umrao <vumrao@redhat.com>
Tue, 18 Jul 2017 20:36:41 +0000 (16:36 -0400)
This memory must be initialized or else valgrind will be very unhappy.

Avoid the cost of zeroing (or even allocating) the buffer for normal
padding values by (re)using a static zero buffer.

Fixes: http://tracker.ceph.com/issues/20323
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 9beaf5efd74daa8c15e50b42583264d1252a85f5)

src/messages/MOSDPing.h

index 61310b3534f175c41c6b260a7d05bcd511374e7e..cf211ed9795c0954931dac7681313b2900032591 100644 (file)
@@ -99,10 +99,22 @@ public:
     ::encode(op, payload);
     ::encode(peer_stat, payload);
     ::encode(stamp, payload);
-    bufferptr size_bp(MAX(min_message_size - payload.length(), 0));
-    bufferlist size_bl;;
-    size_bl.push_back(size_bp);
-    ::encode(size_bl, payload);
+
+    bufferlist pad;
+    size_t s = MAX(min_message_size - payload.length(), 0);
+    // this should be big enough for normal min_message padding sizes. since
+    // we are targetting jumbo ethernet frames around 9000 bytes, 16k should
+    // be more than sufficient!  the compiler will statically zero this so
+    // that at runtime we are only adding a bufferptr reference to it.
+    static char zeros[16384] = {};
+    while (s > sizeof(zeros)) {
+      pad.append(buffer::create_static(sizeof(zeros), zeros));
+      s -= sizeof(zeros);
+    }
+    if (s) {
+      pad.append(buffer::create_static(s, zeros));
+    }
+    ::encode(pad, payload);
   }
 
   const char *get_type_name() const { return "osd_ping"; }