From b8685d855263ec8c8df3ac7d10b401409c556973 Mon Sep 17 00:00:00 2001 From: myoungwon oh Date: Wed, 12 Sep 2018 21:25:24 +0900 Subject: [PATCH] osd, src/common: return sha1 value if zero-length buffer. Signed-off-by: Myoungwon Oh --- src/common/buffer.cc | 16 ++++------------ src/include/buffer.h | 3 +-- src/osd/PrimaryLogPG.cc | 7 ++----- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index b88e74a9caf..b0ba27ded8a 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -2473,23 +2473,15 @@ void buffer::list::invalidate_crc() #include "common/ceph_crypto.h" using ceph::crypto::SHA1; -boost::optional buffer::list::sha1() +sha1_digest_t buffer::list::sha1() { - ptr nb; unsigned char fingerprint[CEPH_CRYPTO_SHA1_DIGESTSIZE]; - if (_len == 0) { - return boost::none; - } - nb = buffer::create(_len); SHA1 sha1_gen; - for (std::list::iterator it = _buffers.begin(); - it != _buffers.end(); - ++it) { - sha1_gen.Update((const unsigned char *)it->c_str(), it->length()); + for (auto& p : _buffers) { + sha1_gen.Update((const unsigned char *)p.c_str(), p.length()); } sha1_gen.Final(fingerprint); - sha1_digest_t fp_t(fingerprint); - return fp_t; + return sha1_digest_t(fingerprint); } /** diff --git a/src/include/buffer.h b/src/include/buffer.h index f32285a158b..54e320ead09 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -61,7 +61,6 @@ #endif #include "inline_memory.h" -#include #if __GNUC__ >= 4 #define CEPH_BUFFER_API __attribute__ ((visibility ("default"))) @@ -957,7 +956,7 @@ namespace buffer CEPH_BUFFER_API { } uint32_t crc32c(uint32_t crc) const; void invalidate_crc(); - boost::optional sha1(); + sha1_digest_t sha1(); // These functions return a bufferlist with a pointer to a single // static buffer. They /must/ not outlive the memory they diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index 0577e0bf632..d11cb9ed836 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -2614,12 +2614,9 @@ int PrimaryLogPG::do_manifest_flush(OpRequestRef op, ObjectContextRef obc, Flush switch (fp_algo_t) { case pg_pool_t::TYPE_FINGERPRINT_SHA1: { - boost::optional fp_t = chunk_data.sha1(); - object_t fp_oid; + sha1_digest_t sha1r = chunk_data.sha1(); + object_t fp_oid = sha1r.to_str(); bufferlist in; - if (fp_t != boost::none) { - fp_oid = fp_t.get().to_str(); - } if (fp_oid != tgt_soid.oid) { // decrement old chunk's reference count ObjectOperation dec_op; -- 2.39.5