]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/denc: clean up ENCODE_DUMP a bit 14962/head
authorSage Weil <sage@redhat.com>
Mon, 8 May 2017 15:54:54 +0000 (11:54 -0400)
committerSage Weil <sage@redhat.com>
Mon, 8 May 2017 15:54:54 +0000 (11:54 -0400)
- PATH_MAX for string
- ENCODE_DUMP -> ENCODE_DUMP_PATH
- some comments!

Signed-off-by: Sage Weil <sage@redhat.com>
src/include/denc.h
src/include/encoding.h

index 7b15b3948564bfe934c7bd0dd2d6fc706fd7888b..d04f959d043dc3aa26ee216901d7f21e90730bdc 100644 (file)
@@ -56,8 +56,16 @@ struct denc_traits {
 //#include <iostream>
 //using std::cout;
 
+// Define this to compile in a dump of all encoded objects to disk to
+// populate ceph-object-corpus.  Note that there is an almost
+// identical implementation in encoding.h, but you only need to define
+// ENCODE_DUMP_PATH here.
+//
+// See src/test/encoding/generate-corpus-objects.sh.
+//
+//#define ENCODE_DUMP_PATH /tmp/something
 
-#ifdef ENCODE_DUMP
+#ifdef ENCODE_DUMP_PATH
 # include <stdio.h>
 # include <sys/types.h>
 # include <sys/stat.h>
@@ -66,6 +74,9 @@ struct denc_traits {
 # define ENCODE_STRINGIFY(x) ENCODE_STR(x)
 # define DENC_DUMP_PRE(Type)                   \
   char *__denc_dump_pre = p.get_pos();
+  // this hackery with bits below is just to get a semi-reasonable
+  // distribution across time.  it is somewhat exponential but not
+  // quite.
 # define DENC_DUMP_POST(Type)                  \
   do {                                                                 \
     static int i = 0;                                                  \
@@ -75,9 +86,9 @@ struct denc_traits {
       t &= t - 1;                                                      \
     if (bits > 2)                                                      \
       break;                                                           \
-    char fn[200];                                                      \
+    char fn[PATH_MAX];                                                 \
     snprintf(fn, sizeof(fn),                                           \
-            ENCODE_STRINGIFY(ENCODE_DUMP) "/%s__%d.%x", #Type,         \
+            ENCODE_STRINGIFY(ENCODE_DUMP_PATH) "/%s__%d.%x", #Type,            \
             getpid(), i++);                                            \
     int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT, 0644);               \
     if (fd >= 0) {                                                     \
index 085eec7cf3c0500749c66cc036639e60c8c75cb4..953420e8991018528daf418f8c924f8d435bebdb 100644 (file)
@@ -111,13 +111,10 @@ WRITE_INTTYPE_ENCODER(int32_t, le32)
 WRITE_INTTYPE_ENCODER(uint16_t, le16)
 WRITE_INTTYPE_ENCODER(int16_t, le16)
 
-#ifdef ENCODE_DUMP
-
+// see denc.h for ENCODE_DUMP_PATH discussion and definition.
+#ifdef ENCODE_DUMP_PATH
 # define ENCODE_DUMP_PRE()                     \
   unsigned pre_off = bl.length()
-
-// NOTE: This is almost an exponential backoff, but because we count
-// bits we get a better sample of things we encode later on.
 # define ENCODE_DUMP_POST(cl)                                          \
   do {                                                                 \
     static int i = 0;                                                  \
@@ -127,8 +124,8 @@ WRITE_INTTYPE_ENCODER(int16_t, le16)
       t &= t - 1;                                                      \
     if (bits > 2)                                                      \
       break;                                                           \
-    char fn[200];                                                      \
-    snprintf(fn, sizeof(fn), ENCODE_STRINGIFY(ENCODE_DUMP) "/%s__%d.%x", #cl, getpid(), i++); \
+    char fn[PATH_MAX];                                                 \
+    snprintf(fn, sizeof(fn), ENCODE_STRINGIFY(ENCODE_DUMP_PATH) "/%s__%d.%x", #cl, getpid(), i++); \
     int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT, 0644);               \
     if (fd >= 0) {                                                     \
       bufferlist sub;                                                  \
@@ -142,6 +139,7 @@ WRITE_INTTYPE_ENCODER(int16_t, le16)
 # define ENCODE_DUMP_POST(cl)
 #endif
 
+
 #define WRITE_CLASS_ENCODER(cl)                                                \
   inline void encode(const cl &c, bufferlist &bl, uint64_t features=0) { \
     ENCODE_DUMP_PRE(); c.encode(bl); ENCODE_DUMP_POST(cl); }           \