]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
tools/rbd: build without "using namespace std"
authorKefu Chai <kchai@redhat.com>
Wed, 11 Aug 2021 03:40:46 +0000 (11:40 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 13 Aug 2021 01:33:14 +0000 (09:33 +0800)
* 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>
src/tools/rbd/Shell.cc
src/tools/rbd/Utils.cc
src/tools/rbd/action/Bench.cc
src/tools/rbd/action/Create.cc
src/tools/rbd/action/Export.cc
src/tools/rbd/action/Import.cc
src/tools/rbd/action/List.cc
src/tools/rbd/action/MergeDiff.cc
src/tools/rbd/action/Snap.cc

index b3d33e9c81f6f151c82d4e979c209b4304dd038f..5df7b1380fc7f7bf05c57d4da9ffd92e026db243 100644 (file)
@@ -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;
         }
       }
index 27789df1d6eb01f48f62b3cac927ab1cceb88298..75d9e6c04432d8abd62ea0a7dc05982af16f8c06 100644 (file)
@@ -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;
   }
 }
 
index cca1ba5879598d016b5b67ab142fdc6897228965..6d0e2cff8f33d006c2810b3fc2e16961b9636119 100644 (file)
@@ -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 << "   "
index 9b38bee2eb3485cdacbff745bd6f1cbde2c9cf87..047a8cb77f6345133b15a658ee99bb31fc488b6e 100644 (file)
@@ -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;
 
index 5551c8ee881df96f08d37ed346c6625c6d99fb3c..21ece1fecfafff0a9e1a6760b7ab5532176ba41a 100644 (file)
@@ -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();
index 0cdf3b713f8e05dca73964304f526cb34c808869..3358c5bc6855c0d42ad98f7c7bf1d0c6ca84e62b 100644 (file)
@@ -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()) {
index b63f97aeb23bc1468a55cfc7aed2321b912a491d..c8bc3eeb83a2d7940b7c4f0b4c92cbec371acb80 100644 (file)
@@ -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;
index d33d1c11abbfd8483628b1dc67d6668a19e8c89e..c387be9a4c64ae0aa5cd6c97f8c9bf9299dc5b41 100644 (file)
@@ -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;
   }
 
index e8a9cb1b8d1c0e7aebdec5e2122f8934c7f8b96a..cb87735f90521695599f3b8a7e24b3c7ef950f67 100644 (file)
@@ -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, &timestamp);
-    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;