From: Ilya Dryomov Date: Wed, 27 Dec 2023 15:18:50 +0000 (+0100) Subject: include/intarith: introduce round_down_to() X-Git-Tag: v19.1.0~474^2~11 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=94bf3a5d74cfd61e0bd881ca2863fe2205f27767;p=ceph.git include/intarith: introduce round_down_to() Same as with round_up_to(), d isn't required to be a power of two. Signed-off-by: Ilya Dryomov --- diff --git a/src/include/intarith.h b/src/include/intarith.h index 68b0345a457e2..92f827d88e580 100644 --- a/src/include/intarith.h +++ b/src/include/intarith.h @@ -25,6 +25,10 @@ constexpr inline std::make_unsigned_t> div_round_up(T n return (n + d - 1) / d; } +template +constexpr inline std::make_unsigned_t> round_down_to(T n, U d) { + return n - n % d; +} template constexpr inline std::make_unsigned_t> round_up_to(T n, U d) { diff --git a/src/librbd/api/DiffIterate.cc b/src/librbd/api/DiffIterate.cc index 7679bf77759dc..4bbc8ebdc98ae 100644 --- a/src/librbd/api/DiffIterate.cc +++ b/src/librbd/api/DiffIterate.cc @@ -293,7 +293,7 @@ int DiffIterate::execute() { uint64_t left = m_length; while (left > 0) { - uint64_t period_off = off - (off % period); + uint64_t period_off = round_down_to(off, period); uint64_t read_len = std::min(period_off + period - off, left); if (fast_diff_enabled) {