From 41557b5d3144686fc5c455c2395dfdda124caa73 Mon Sep 17 00:00:00 2001 From: N Balachandran Date: Thu, 16 Feb 2023 10:27:02 +0530 Subject: [PATCH] rbd-mirror: fix syncing_percent calculation logic in get_replay_status() When a snapshot sync is resumed and the get_replay_status function is called before handle_copy_image_progress, the syncing_percent value may be greater than 100 as the m_local_object_count is still set to zero. This commit sets the syncing_percent to 0 in such cases. Fixes: https://tracker.ceph.com/issues/58706 Signed-off-by: N Balachandran (cherry picked from commit c7ae0f6eb6a8fb08859454d1b2e81d2dc7b0226f) --- .../rbd_mirror/image_replayer/snapshot/Replayer.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc index 4a44a57bc2235..b2a126b2fb8d4 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc +++ b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc @@ -277,9 +277,17 @@ bool Replayer::get_replay_status(std::string* description, matching_remote_snap_it != m_state_builder->remote_image_ctx->snap_info.end()) { root_obj["syncing_snapshot_timestamp"] = remote_snap_info->timestamp.sec(); - root_obj["syncing_percent"] = static_cast( - 100 * m_local_mirror_snap_ns.last_copied_object_number / - static_cast(std::max(1U, m_local_object_count))); + + if (m_local_object_count > 0) { + root_obj["syncing_percent"] = + 100 * m_local_mirror_snap_ns.last_copied_object_number / + m_local_object_count; + } else { + // Set syncing_percent to 0 if m_local_object_count has + // not yet been set (last_copied_object_number may be > 0 + // if the sync is being resumed). + root_obj["syncing_percent"] = 0; + } } m_bytes_per_second(0); -- 2.39.5