From e7ca6d0276a4550aea09c88ed62308456bf3c81a Mon Sep 17 00:00:00 2001 From: myoungwon oh Date: Sat, 17 Sep 2022 16:11:49 +0900 Subject: [PATCH] ceph_dedup_tool: fix threshold comparison If threadhold count is 2, existing code always returns true even though reference count is 1 actually because it additionally adds one via ++. Signed-off-by: Myoungwon Oh --- src/tools/ceph_dedup_tool.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tools/ceph_dedup_tool.cc b/src/tools/ceph_dedup_tool.cc index e95aad68aaca..f3c942a97604 100644 --- a/src/tools/ceph_dedup_tool.cc +++ b/src/tools/ceph_dedup_tool.cc @@ -561,13 +561,13 @@ public: bool add(chunk_t& chunk) { std::unique_lock lock(fingerprint_lock); auto found_iter = fp_map.find(chunk.fingerprint); + ssize_t cur_reference = 1; if (found_iter == fp_map.end()) { - auto ret = fp_map.insert({chunk.fingerprint, 1}); - found_iter = ret.first; + fp_map.insert({chunk.fingerprint, 1}); + } else { + cur_reference = ++found_iter->second; } - auto &target = found_iter->second; - target++; - return target >= dedup_threshold && dedup_threshold != -1; + return cur_reference >= dedup_threshold && dedup_threshold != -1; } void init(size_t dedup_threshold_) { -- 2.47.3