]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/intarith: introduce round_down_to()
authorIlya Dryomov <idryomov@gmail.com>
Wed, 27 Dec 2023 15:18:50 +0000 (16:18 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Sat, 20 Jan 2024 18:00:24 +0000 (19:00 +0100)
Same as with round_up_to(), d isn't required to be a power of two.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit 94bf3a5d74cfd61e0bd881ca2863fe2205f27767)

src/include/intarith.h
src/librbd/api/DiffIterate.cc

index d3eaff15635f773bdb35314cbea09c35fb2773fb..f43981a6530f406a65eca0443878856d4045af8d 100644 (file)
@@ -22,6 +22,10 @@ constexpr inline std::make_unsigned_t<std::common_type_t<T, U>> div_round_up(T n
   return (n + d - 1) / d;
 }
 
+template<typename T, typename U>
+constexpr inline std::make_unsigned_t<std::common_type_t<T, U>> round_down_to(T n, U d) {
+  return n - n % d;
+}
 
 template<typename T, typename U>
 constexpr inline std::make_unsigned_t<std::common_type_t<T, U>> round_up_to(T n, U d) {
index 6c86f56b3eea3fbe28e3e378358276e7cf06adc3..d2003101f28b2a35f0c83d7ee96941783a11c8f8 100644 (file)
@@ -291,7 +291,7 @@ int DiffIterate<I>::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) {