From db37bd8e7383fe59e1e93169acf4bc7997cacbcb Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 17 Apr 2013 15:31:36 -0700 Subject: [PATCH] rbd: add --no-progress switch Disable progress output to stderr.t Signed-off-by: Sage Weil --- src/rbd.cc | 32 +++++++++++++++++++++----------- src/test/cli/rbd/help.t | 1 + 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/rbd.cc b/src/rbd.cc index 6449ef1f4cd1c..03735a20cb13e 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -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 take a shared (rather than exclusive) lock\n" " --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); diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 3fc81a2f31f0e..b88b42bdb3002 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -75,3 +75,4 @@ --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 -- 2.39.5