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)
Conflicts:
src/librbd/api/DiffIterate.cc [ commit
6eb14774fec0 ("librbd:
build without "using namespace std"") not in pacific ]
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) {
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) {