From: John Spray Date: Mon, 19 May 2014 10:31:24 +0000 (+0100) Subject: osdc/JournalStream: DRY envelope size calc X-Git-Tag: v0.82~48^2~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=778b78519fd8e06e7a2fc91e318dc3c4345140a9;p=ceph.git osdc/JournalStream: DRY envelope size calc Replace repetitive sizeof() calculation for the envelope overhead per log event with #defines. Signed-off-by: John Spray --- diff --git a/src/osdc/Journaler.cc b/src/osdc/Journaler.cc index f28f6e413fe6..825fbca99779 100644 --- a/src/osdc/Journaler.cc +++ b/src/osdc/Journaler.cc @@ -1099,7 +1099,6 @@ bool JournalStream::readable(bufferlist &read_buf, uint64_t *need) assert(need != NULL); uint32_t entry_size = 0; - uint64_t start_ptr = 0; uint64_t entry_sentinel = 0; bufferlist::iterator p = read_buf.begin(); @@ -1124,9 +1123,9 @@ bool JournalStream::readable(bufferlist &read_buf, uint64_t *need) // Do we have enough data to decode an entry prefix, payload and suffix? if (format >= JOURNAL_FORMAT_RESILIENT) { - *need = sizeof(entry_size) + sizeof(entry_sentinel) + entry_size + sizeof(start_ptr); + *need = JOURNAL_ENVELOPE_RESILIENT + entry_size; } else { - *need = sizeof(entry_size) + entry_size; + *need = JOURNAL_ENVELOPE_LEGACY + entry_size; } if (read_buf.length() >= *need) { return true; // No more bytes needed @@ -1174,10 +1173,10 @@ size_t JournalStream::read(bufferlist &from, bufferlist *entry, uint64_t *start_ size_t raw_length; if (format >= JOURNAL_FORMAT_RESILIENT) { - raw_length = sizeof(entry_size) + sizeof(entry_sentinel) + entry_size + sizeof(*start_ptr); + raw_length = JOURNAL_ENVELOPE_RESILIENT + entry_size; assert(entry_sentinel == sentinel); } else { - raw_length = sizeof(entry_size) + entry_size; + raw_length = JOURNAL_ENVELOPE_LEGACY + entry_size; } assert(from.length() >= raw_length); assert(entry_size != 0); @@ -1213,9 +1212,9 @@ size_t JournalStream::write(bufferlist &entry, bufferlist *to, uint64_t const &s } if (format >= JOURNAL_FORMAT_RESILIENT) { - return sizeof(sentinel) + sizeof(entry_size) + entry_size + sizeof(start_ptr); + return JOURNAL_ENVELOPE_RESILIENT + entry_size; } else { - return sizeof(entry_size) + entry_size; + return JOURNAL_ENVELOPE_LEGACY + entry_size; } } diff --git a/src/osdc/Journaler.h b/src/osdc/Journaler.h index 876c41a8ca90..07d6ee5d6657 100644 --- a/src/osdc/Journaler.h +++ b/src/osdc/Journaler.h @@ -61,8 +61,14 @@ class Context; class PerfCounters; typedef __u8 stream_format_t; + +// Legacy envelope is leading uint32_t size #define JOURNAL_FORMAT_LEGACY 0 +#define JOURNAL_ENVELOPE_LEGACY (sizeof(uint32_t)) + +// Resilient envelope is leading uint64_t sentinel, uint32_t size, trailing uint64_t start_ptr #define JOURNAL_FORMAT_RESILIENT 1 +#define JOURNAL_ENVELOPE_RESILIENT (sizeof(uint32_t) + sizeof(uint64_t) + sizeof(uint64_t)) /**