From: Ilya Dryomov Date: Sat, 9 Apr 2022 09:06:32 +0000 (+0200) Subject: rbd: factor out get_percentage() helper X-Git-Tag: v18.0.0~1081^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9324ab94711dbe9a1265643adcc79ae0a3cba812;p=ceph-ci.git rbd: factor out get_percentage() helper Signed-off-by: Ilya Dryomov --- diff --git a/src/tools/rbd/Utils.cc b/src/tools/rbd/Utils.cc index 75d9e6c0443..161cb91de17 100644 --- a/src/tools/rbd/Utils.cc +++ b/src/tools/rbd/Utils.cc @@ -44,7 +44,7 @@ static std::string mgr_command_args_to_str( int ProgressContext::update_progress(uint64_t offset, uint64_t total) { if (progress) { - int pc = total ? (offset * 100ull / total) : 0; + int pc = get_percentage(offset, total); if (pc > last_pc) { std::cerr << "\r" << operation << ": " << pc << "% complete..." << std::flush; @@ -67,6 +67,10 @@ void ProgressContext::fail() { } } +int get_percentage(uint64_t part, uint64_t whole) { + return whole ? (100 * part / whole) : 0; +} + void aio_context_callback(librbd::completion_t completion, void *arg) { librbd::RBD::AioCompletion *aio_completion = diff --git a/src/tools/rbd/Utils.h b/src/tools/rbd/Utils.h index a3f9baac7d3..66f8e18881b 100644 --- a/src/tools/rbd/Utils.h +++ b/src/tools/rbd/Utils.h @@ -82,6 +82,8 @@ struct ProgressContext : public librbd::ProgressContext { void fail(); }; +int get_percentage(uint64_t part, uint64_t whole); + template librbd::RBD::AioCompletion *create_aio_completion(T *t) { return new librbd::RBD::AioCompletion(