]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add --no-progress switch 219/head
authorSage Weil <sage@inktank.com>
Wed, 17 Apr 2013 22:31:36 +0000 (15:31 -0700)
committerSage Weil <sage@inktank.com>
Wed, 17 Apr 2013 22:31:36 +0000 (15:31 -0700)
Disable progress output to stderr.t

Signed-off-by: Sage Weil <sage@inktank.com>
src/rbd.cc
src/test/cli/rbd/help.t

index 6449ef1f4cd1cb326ee739f94431fb7aae7474e7..03735a20cb13e57611a6b856b39ebc69426d4f08 100644 (file)
@@ -71,6 +71,7 @@ static string dir_oid = RBD_DIRECTORY;
 static string dir_info_oid = RBD_INFO;
 
 bool udevadm_settle = true;
+bool progress = true;
 
 #define dout_subsys ceph_subsys_rbd
 
@@ -152,7 +153,8 @@ void usage()
 "  --shared <tag>                     take a shared (rather than exclusive) lock\n"
 "  --format <output-format>           output format (default: plain, json, xml)\n"
 "  --pretty-format                    make json or xml output more readable\n"
-"  --no-settle                        do not wait for udevadm to settle on map/unmap\n";
+"  --no-settle                        do not wait for udevadm to settle on map/unmap\n"
+"  --no-progress                      do not show progress for long-running commands\n";
 }
 
 static string feature_str(uint64_t feature)
@@ -198,22 +200,28 @@ struct MyProgressContext : public librbd::ProgressContext {
   }
 
   int update_progress(uint64_t offset, uint64_t total) {
-    int pc = total ? (offset * 100ull / total) : 0;
-    if (pc != last_pc) {
-      cerr << "\r" << operation << ": "
-       //         << offset << " / " << total << " "
-          << pc << "% complete...";
-      cerr.flush();
-      last_pc = pc;
+    if (progress) {
+      int pc = total ? (offset * 100ull / total) : 0;
+      if (pc != last_pc) {
+       cerr << "\r" << operation << ": "
+         //       << offset << " / " << total << " "
+            << pc << "% complete...";
+       cerr.flush();
+       last_pc = pc;
+      }
     }
     return 0;
   }
   void finish() {
-    cerr << "\r" << operation << ": 100% complete...done." << std::endl;
+    if (progress) {
+      cerr << "\r" << operation << ": 100% complete...done." << std::endl;
+    }
   }
   void fail() {
-    cerr << "\r" << operation << ": " << last_pc << "% complete...failed."
-        << std::endl;
+    if (progress) {
+      cerr << "\r" << operation << ": " << last_pc << "% complete...failed."
+          << std::endl;
+    }
   }
 };
 
@@ -2188,6 +2196,8 @@ int main(int argc, const char **argv)
       lock_tag = strdup(val.c_str());
     } else if (ceph_argparse_flag(args, i, "--no-settle", (char *)NULL)) {
       udevadm_settle = false;
+    } else if (ceph_argparse_flag(args, i, "--no-progress", (char *)NULL)) {
+      progress = false;
     } else if (ceph_argparse_witharg(args, i, &val, "--format", (char *) NULL)) {
       std::string err;
       long long ret = strict_strtoll(val.c_str(), 10, &err);
index 3fc81a2f31f0edb7fffd5ae26fa78c0df1293b07..b88b42bdb3002c320019e3ae8e260acfa0c7f7d3 100644 (file)
@@ -75,3 +75,4 @@
     --format <output-format>           output format (default: plain, json, xml)
     --pretty-format                    make json or xml output more readable
     --no-settle                        do not wait for udevadm to settle on map/unmap
+    --no-progress                      do not show progress for long-running commands