]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd: factor out get_percentage() helper
authorIlya Dryomov <idryomov@gmail.com>
Sat, 9 Apr 2022 09:06:32 +0000 (11:06 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 11 Apr 2022 06:26:47 +0000 (08:26 +0200)
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
src/tools/rbd/Utils.cc
src/tools/rbd/Utils.h

index 75d9e6c04432d8abd62ea0a7dc05982af16f8c06..161cb91de1701f8a1093d5ec9e7affda2f3a03e0 100644 (file)
@@ -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 =
index a3f9baac7d338423e31e11c975f0bfc5ad6448c7..66f8e18881b2fc65ee0be3490a13ce87b66fe8e0 100644 (file)
@@ -82,6 +82,8 @@ struct ProgressContext : public librbd::ProgressContext {
   void fail();
 };
 
+int get_percentage(uint64_t part, uint64_t whole);
+
 template <typename T, void(T::*MF)(int)>
 librbd::RBD::AioCompletion *create_aio_completion(T *t) {
   return new librbd::RBD::AioCompletion(