From 439fdbe3bf7fbcb4e7c833cb185dfccc4f4bfef9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 8 May 2017 11:54:54 -0400 Subject: [PATCH] include/denc: clean up ENCODE_DUMP a bit - PATH_MAX for string - ENCODE_DUMP -> ENCODE_DUMP_PATH - some comments! Signed-off-by: Sage Weil --- src/include/denc.h | 17 ++++++++++++++--- src/include/encoding.h | 12 +++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/include/denc.h b/src/include/denc.h index 7b15b3948564b..d04f959d043dc 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -56,8 +56,16 @@ struct denc_traits { //#include //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 # include # include @@ -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) { \ diff --git a/src/include/encoding.h b/src/include/encoding.h index 085eec7cf3c05..953420e899101 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -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); } \ -- 2.39.5