From: Ilya Dryomov Date: Sat, 9 Apr 2022 09:06:32 +0000 (+0200) Subject: rbd: factor out get_percentage() helper X-Git-Tag: v16.2.8~19^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4667b68feb7ded7cd31dcd0783f08dca44a2d52c;p=ceph.git rbd: factor out get_percentage() helper Signed-off-by: Ilya Dryomov (cherry picked from commit 9324ab94711dbe9a1265643adcc79ae0a3cba812) --- diff --git a/src/tools/rbd/Utils.cc b/src/tools/rbd/Utils.cc index 27789df1d6e..f3bd99dce18 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) { cerr << "\r" << operation << ": " << pc << "% complete..."; @@ -68,6 +68,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(