From: Ilya Dryomov Date: Wed, 27 Dec 2023 15:18:50 +0000 (+0100) Subject: include/intarith: introduce round_down_to() X-Git-Tag: v16.2.15~27^2~11 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=f69deca57fef8ebdd9afbe8803bc63d8522ab982;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 (cherry picked from commit 94bf3a5d74cfd61e0bd881ca2863fe2205f27767) Conflicts: src/librbd/api/DiffIterate.cc [ commit 6eb14774fec0 ("librbd: build without "using namespace std"") not in pacific ] --- diff --git a/src/include/intarith.h b/src/include/intarith.h index e912cbe7b3c44..a4ac36d4934e8 100644 --- a/src/include/intarith.h +++ b/src/include/intarith.h @@ -22,6 +22,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 6ded254f0992c..edc1811256e7f 100644 --- a/src/librbd/api/DiffIterate.cc +++ b/src/librbd/api/DiffIterate.cc @@ -291,7 +291,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 = min(period_off + period - off, left); if (fast_diff_enabled) {