]> git.apps.os.sepia.ceph.com Git - ceph.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>
Wed, 13 Apr 2022 10:51:21 +0000 (12:51 +0200)
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit 9324ab94711dbe9a1265643adcc79ae0a3cba812)

src/tools/rbd/Utils.cc
src/tools/rbd/Utils.h

index 27789df1d6eb01f48f62b3cac927ab1cceb88298..f3bd99dce181a1b28db23a00e33b7ea4e7972298 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) {
       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 =
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(