From 231cee5980a3ad093aa9991c3f1c9aff6bfb9ab0 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 16 May 2020 10:16:13 -0500 Subject: [PATCH] common/CDC: make calc_chunks const Signed-off-by: Sage Weil --- src/common/CDC.h | 4 +++- src/common/FastCDC.cc | 4 ++-- src/common/FastCDC.h | 2 +- src/common/FixedCDC.cc | 2 +- src/common/FixedCDC.h | 2 +- src/common/rabin.cc | 6 +++--- src/common/rabin.h | 8 ++++---- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/common/CDC.h b/src/common/CDC.h index e58377dffe8..8c564034f2c 100644 --- a/src/common/CDC.h +++ b/src/common/CDC.h @@ -12,10 +12,12 @@ class CDC { public: virtual ~CDC() = default; + /// calculate chunk boundaries as vector of (offset, length) pairs virtual void calc_chunks( const bufferlist& inputdata, - std::vector> *chunks) = 0; + std::vector> *chunks) const = 0; + /// set target chunk size as a power of 2, and number of bits for hard min/max virtual void set_target_bits(int bits, int windowbits = 2) = 0; static std::unique_ptr create( diff --git a/src/common/FastCDC.cc b/src/common/FastCDC.cc index cacd084fc5c..b83a83749f8 100644 --- a/src/common/FastCDC.cc +++ b/src/common/FastCDC.cc @@ -64,7 +64,7 @@ static inline bool _scan( size_t& pos, size_t max, // how much to read uint64_t& fp, // fingerprint - uint64_t mask, uint64_t *table) + uint64_t mask, const uint64_t *table) { while (pos < max) { if (*pp == *pe) { @@ -88,7 +88,7 @@ static inline bool _scan( void FastCDC::calc_chunks( const bufferlist& bl, - std::vector> *chunks) + std::vector> *chunks) const { if (bl.length() == 0) { return; diff --git a/src/common/FastCDC.h b/src/common/FastCDC.h index 75b0fba954c..ce2ce95df6c 100644 --- a/src/common/FastCDC.h +++ b/src/common/FastCDC.h @@ -42,5 +42,5 @@ public: void calc_chunks( const bufferlist& bl, - std::vector> *chunks) override; + std::vector> *chunks) const override; }; diff --git a/src/common/FixedCDC.cc b/src/common/FixedCDC.cc index d2d55d5cfb6..6e87f070e81 100644 --- a/src/common/FixedCDC.cc +++ b/src/common/FixedCDC.cc @@ -7,7 +7,7 @@ void FixedCDC::calc_chunks( const bufferlist& bl, - std::vector> *chunks) + std::vector> *chunks) const { size_t len = bl.length(); if (!len) { diff --git a/src/common/FixedCDC.h b/src/common/FixedCDC.h index d3939753e73..a19a1859bfb 100644 --- a/src/common/FixedCDC.h +++ b/src/common/FixedCDC.h @@ -19,5 +19,5 @@ public: } void calc_chunks( const bufferlist& bl, - std::vector> *chunks) override; + std::vector> *chunks) const override; }; diff --git a/src/common/rabin.cc b/src/common/rabin.cc index 4352f798219..9a6bab4100c 100644 --- a/src/common/rabin.cc +++ b/src/common/rabin.cc @@ -7,7 +7,7 @@ #include "rabin.h" -uint64_t RabinChunk::gen_rabin_hash(char* chunk_data, uint64_t off, uint64_t len) { +uint64_t RabinChunk::gen_rabin_hash(char* chunk_data, uint64_t off, uint64_t len) const { uint64_t roll_sum = 0; uint64_t data_len = len; if (data_len == 0) { @@ -20,7 +20,7 @@ uint64_t RabinChunk::gen_rabin_hash(char* chunk_data, uint64_t off, uint64_t len return roll_sum; } -bool RabinChunk::end_of_chunk(const uint64_t fp , int numbits) { +bool RabinChunk::end_of_chunk(const uint64_t fp , int numbits) const { return ((fp & rabin_mask[numbits]) == 0) ; } @@ -38,7 +38,7 @@ bool RabinChunk::end_of_chunk(const uint64_t fp , int numbits) { int RabinChunk::do_rabin_chunks(ceph::buffer::list& inputdata, std::vector>& chunks, - uint64_t min_val, uint64_t max_val) + uint64_t min_val, uint64_t max_val) const { char *ptr = inputdata.c_str(); uint64_t data_size = inputdata.length(); diff --git a/src/common/rabin.h b/src/common/rabin.h index acc5766e4ad..939aa4ff846 100644 --- a/src/common/rabin.h +++ b/src/common/rabin.h @@ -51,15 +51,15 @@ public: void calc_chunks( const ceph::buffer::list& inputdata, - std::vector> *chunks) override { + std::vector> *chunks) const override { bufferlist b = inputdata; do_rabin_chunks(b, *chunks); } int do_rabin_chunks(ceph::buffer::list& inputdata, std::vector>& chunks, - uint64_t min=0, uint64_t max=0); - uint64_t gen_rabin_hash(char* chunk_data, uint64_t off, uint64_t len = 0); + uint64_t min=0, uint64_t max=0) const; + uint64_t gen_rabin_hash(char* chunk_data, uint64_t off, uint64_t len = 0) const; void set_window_size(uint32_t size) { window_size = size; } void set_rabin_prime(uint32_t r_prime) { rabin_prime = r_prime; } void set_mod_prime(uint64_t m_prime) { mod_prime = m_prime; } @@ -94,7 +94,7 @@ public: } private: - bool end_of_chunk(const uint64_t fp , int numbits); + bool end_of_chunk(const uint64_t fp , int numbits) const; uint32_t window_size; uint32_t rabin_prime; -- 2.39.5