diff options
author | Kefu Chai <kchai@redhat.com> | 2021-08-11 05:40:46 +0200 |
---|---|---|
committer | Kefu Chai <kchai@redhat.com> | 2021-08-13 03:33:14 +0200 |
commit | c537ffe22c2888e5e20394947922353e3134584d (patch) | |
tree | cb13983e218cb5e7f66c567ed4bc64eeed6f2580 /src/tools/rbd | |
parent | test/crimson: build without "using namespace std" (diff) | |
download | ceph-c537ffe22c2888e5e20394947922353e3134584d.tar.xz ceph-c537ffe22c2888e5e20394947922353e3134584d.zip |
tools/rbd: build without "using namespace std"
* add "std::" prefix in headers
* add "using" declarations in .cc files.
so we don't rely on "using namespace std" in one or more included
headers.
Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to '')
-rw-r--r-- | src/tools/rbd/Shell.cc | 2 | ||||
-rw-r--r-- | src/tools/rbd/Utils.cc | 11 | ||||
-rw-r--r-- | src/tools/rbd/action/Bench.cc | 15 | ||||
-rw-r--r-- | src/tools/rbd/action/Create.cc | 1 | ||||
-rw-r--r-- | src/tools/rbd/action/Export.cc | 5 | ||||
-rw-r--r-- | src/tools/rbd/action/Import.cc | 9 | ||||
-rw-r--r-- | src/tools/rbd/action/List.cc | 4 | ||||
-rw-r--r-- | src/tools/rbd/action/MergeDiff.cc | 4 | ||||
-rw-r--r-- | src/tools/rbd/action/Snap.cc | 12 |
9 files changed, 36 insertions, 27 deletions
diff --git a/src/tools/rbd/Shell.cc b/src/tools/rbd/Shell.cc index b3d33e9c81f..5df7b1380fc 100644 --- a/src/tools/rbd/Shell.cc +++ b/src/tools/rbd/Shell.cc @@ -221,7 +221,7 @@ int Shell::execute(int argc, const char **argv) { if (!result.empty()) { print_deprecated_warning(option, description); } - } catch (exception& e) { + } catch (std::exception& e) { continue; } } diff --git a/src/tools/rbd/Utils.cc b/src/tools/rbd/Utils.cc index 27789df1d6e..75d9e6c0443 100644 --- a/src/tools/rbd/Utils.cc +++ b/src/tools/rbd/Utils.cc @@ -46,9 +46,8 @@ int ProgressContext::update_progress(uint64_t offset, uint64_t total) { if (progress) { int pc = total ? (offset * 100ull / total) : 0; if (pc > last_pc) { - cerr << "\r" << operation << ": " - << pc << "% complete..."; - cerr.flush(); + std::cerr << "\r" << operation << ": " + << pc << "% complete..." << std::flush; last_pc = pc; } } @@ -57,14 +56,14 @@ int ProgressContext::update_progress(uint64_t offset, uint64_t total) { void ProgressContext::finish() { if (progress) { - cerr << "\r" << operation << ": 100% complete...done." << std::endl; + std::cerr << "\r" << operation << ": 100% complete...done." << std::endl; } } void ProgressContext::fail() { if (progress) { - cerr << "\r" << operation << ": " << last_pc << "% complete...failed." - << std::endl; + std::cerr << "\r" << operation << ": " << last_pc << "% complete...failed." + << std::endl; } } diff --git a/src/tools/rbd/action/Bench.cc b/src/tools/rbd/action/Bench.cc index cca1ba58795..6d0e2cff8f3 100644 --- a/src/tools/rbd/action/Bench.cc +++ b/src/tools/rbd/action/Bench.cc @@ -188,7 +188,7 @@ void rbd_bencher_completion(void *vc, void *pc) std::cout << "write error: " << cpp_strerror(ret) << std::endl; exit(ret < 0 ? -ret : ret); } else if (b->io_type == IO_TYPE_READ && (unsigned int)ret != b->io_size) { - cout << "read error: " << cpp_strerror(ret) << std::endl; + std::cout << "read error: " << cpp_strerror(ret) << std::endl; exit(ret < 0 ? -ret : ret); } b->lock.lock(); @@ -239,7 +239,8 @@ int do_bench(librbd::Image& image, io_type_t io_type, << " type " << (io_type == IO_TYPE_READ ? "read" : io_type == IO_TYPE_WRITE ? "write" : "readwrite") << (io_type == IO_TYPE_RW ? " read:write=" + - to_string(read_proportion) + ":" + to_string(100 - read_proportion) : "") + std::to_string(read_proportion) + ":" + + std::to_string(100 - read_proportion) : "") << " io_size " << io_size << " io_threads " << io_threads << " bytes " << io_bytes @@ -263,10 +264,10 @@ int do_bench(librbd::Image& image, io_type_t io_type, srand(time(NULL) % (unsigned long) -1); coarse_mono_time start = coarse_mono_clock::now(); - chrono::duration<double> last = chrono::duration<double>::zero(); + std::chrono::duration<double> last = std::chrono::duration<double>::zero(); unsigned ios = 0; - vector<uint64_t> thread_offset; + std::vector<uint64_t> thread_offset; uint64_t i; uint64_t seq_chunk_length = (size / io_size / io_threads) * io_size;; @@ -374,8 +375,8 @@ int do_bench(librbd::Image& image, io_type_t io_type, } coarse_mono_time now = coarse_mono_clock::now(); - chrono::duration<double> elapsed = now - start; - if (last == chrono::duration<double>::zero()) { + std::chrono::duration<double> elapsed = now - start; + if (last == std::chrono::duration<double>::zero()) { last = elapsed; } else if ((int)elapsed.count() != (int)last.count()) { time_acc((elapsed - last).count()); @@ -408,7 +409,7 @@ int do_bench(librbd::Image& image, io_type_t io_type, } coarse_mono_time now = coarse_mono_clock::now(); - chrono::duration<double> elapsed = now - start; + std::chrono::duration<double> elapsed = now - start; std::cout << "elapsed: " << (int)elapsed.count() << " " << "ops: " << ios << " " diff --git a/src/tools/rbd/action/Create.cc b/src/tools/rbd/action/Create.cc index 9b38bee2eb3..047a8cb77f6 100644 --- a/src/tools/rbd/action/Create.cc +++ b/src/tools/rbd/action/Create.cc @@ -100,6 +100,7 @@ struct thick_provision_writer { } int wait_for(uint64_t max) { + using namespace std::chrono_literals; std::unique_lock l{lock}; int r = io_status.io_error; diff --git a/src/tools/rbd/action/Export.cc b/src/tools/rbd/action/Export.cc index 5551c8ee881..21ece1fecfa 100644 --- a/src/tools/rbd/action/Export.cc +++ b/src/tools/rbd/action/Export.cc @@ -15,6 +15,9 @@ #include <boost/program_options.hpp> #include <boost/scope_exit.hpp> +using std::cerr; +using std::string; + namespace rbd { namespace action { namespace export_full { @@ -527,7 +530,7 @@ static int do_export_v1(librbd::Image& image, librbd::image_info_t &info, break; } - uint64_t length = min(period, info.size - offset); + uint64_t length = std::min(period, info.size - offset); C_Export *ctx = new C_Export(throttle, image, file_size + offset, offset, length, fd); ctx->send(); diff --git a/src/tools/rbd/action/Import.cc b/src/tools/rbd/action/Import.cc index 0cdf3b713f8..3358c5bc685 100644 --- a/src/tools/rbd/action/Import.cc +++ b/src/tools/rbd/action/Import.cc @@ -22,6 +22,9 @@ #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rbd +using std::cerr; +using std::string; + namespace rbd { namespace action { namespace import { @@ -324,7 +327,7 @@ static int skip_tag(int fd, uint64_t length) if (fd == STDIN_FILENO) { // read the appending data out to skip this tag. char buf[4096]; - uint64_t len = min<uint64_t>(length, sizeof(buf)); + uint64_t len = std::min<uint64_t>(length, sizeof(buf)); while (len > 0) { r = safe_read_exact(fd, buf, len); if (r < 0) { @@ -332,7 +335,7 @@ static int skip_tag(int fd, uint64_t length) return r; } length -= len; - len = min<uint64_t>(length, sizeof(buf)); + len = std::min<uint64_t>(length, sizeof(buf)); } } else { // lseek to skip this tag @@ -739,7 +742,7 @@ static int do_import_v1(int fd, librbd::Image &image, uint64_t size, g_conf().get_val<uint64_t>("rbd_concurrent_management_ops"), false)); } - reqlen = min<uint64_t>(reqlen, size); + reqlen = std::min<uint64_t>(reqlen, size); // loop body handles 0 return, as we may have a block to flush while ((readlen = ::read(fd, p + blklen, reqlen)) >= 0) { if (throttle->pending_error()) { diff --git a/src/tools/rbd/action/List.cc b/src/tools/rbd/action/List.cc index b63f97aeb23..c8bc3eeb83a 100644 --- a/src/tools/rbd/action/List.cc +++ b/src/tools/rbd/action/List.cc @@ -34,8 +34,8 @@ struct WorkerEntry { librbd::Image img; librbd::RBD::AioCompletion* completion; WorkerState state; - string name; - string id; + std::string name; + std::string id; WorkerEntry() { state = STATE_IDLE; diff --git a/src/tools/rbd/action/MergeDiff.cc b/src/tools/rbd/action/MergeDiff.cc index d33d1c11abb..c387be9a4c6 100644 --- a/src/tools/rbd/action/MergeDiff.cc +++ b/src/tools/rbd/action/MergeDiff.cc @@ -18,6 +18,8 @@ #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rbd +using std::string; + namespace rbd { namespace action { namespace merge_diff { @@ -438,7 +440,7 @@ int execute(const po::variables_map &vm, r = do_merge_diff(first_diff.c_str(), second_diff.c_str(), path.c_str(), vm[at::NO_PROGRESS].as<bool>()); if (r < 0) { - cerr << "rbd: merge-diff error" << std::endl; + std::cerr << "rbd: merge-diff error" << std::endl; return -r; } diff --git a/src/tools/rbd/action/Snap.cc b/src/tools/rbd/action/Snap.cc index e8a9cb1b8d1..cb87735f905 100644 --- a/src/tools/rbd/action/Snap.cc +++ b/src/tools/rbd/action/Snap.cc @@ -72,7 +72,7 @@ int do_list_snaps(librbd::Image& image, Formatter *f, bool all_snaps, librados:: struct timespec timestamp; bool snap_protected = false; image.snap_get_timestamp(s->id, ×tamp); - string tt_str = ""; + std::string tt_str = ""; if(timestamp.tv_sec != 0) { time_t tt = timestamp.tv_sec; tt_str = ctime(&tt); @@ -186,7 +186,7 @@ int do_list_snaps(librbd::Image& image, Formatter *f, bool all_snaps, librados:: t << s->id << s->name << stringify(byte_u_t(s->size)) << protected_str << tt_str; if (all_snaps) { - ostringstream oss; + std::ostringstream oss; oss << snap_namespace_name; if (get_group_res == 0) { @@ -291,7 +291,7 @@ int do_purge_snaps(librbd::Image& image, bool no_progress) } else if (0 == snaps.size()) { return 0; } else { - list<std::string> protect; + std::list<std::string> protect; snaps.erase(remove_if(snaps.begin(), snaps.end(), boost::bind(utils::is_not_user_snap_namespace, &image, _1)), @@ -415,7 +415,7 @@ int execute_list(const po::variables_map &vm, bool all_snaps = vm[ALL_NAME].as<bool>(); r = do_list_snaps(image, formatter.get(), all_snaps, rados); if (r < 0) { - cerr << "rbd: failed to list snapshots: " << cpp_strerror(r) + std::cerr << "rbd: failed to list snapshots: " << cpp_strerror(r) << std::endl; return r; } @@ -462,8 +462,8 @@ int execute_create(const po::variables_map &vm, r = do_add_snap(image, snap_name.c_str(), flags, vm[at::NO_PROGRESS].as<bool>()); if (r < 0) { - cerr << "rbd: failed to create snapshot: " << cpp_strerror(r) - << std::endl; + std::cerr << "rbd: failed to create snapshot: " << cpp_strerror(r) + << std::endl; return r; } return 0; |