]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/rbd: s/Mutex/ceph::mutex/
authorKefu Chai <kchai@redhat.com>
Wed, 17 Jul 2019 08:30:56 +0000 (16:30 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Aug 2019 03:27:20 +0000 (11:27 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/tools/rbd/action/Bench.cc
src/tools/rbd/action/Create.cc

index d5791bdc6ff0bd9cdc3559bfd3da3ef663ab0c32..2c2fa5836fe88818610c932ab7846f356cb638fa 100644 (file)
@@ -6,8 +6,8 @@
 #include "tools/rbd/Utils.h"
 #include "common/errno.h"
 #include "common/strtol.h"
-#include "common/Cond.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
+#include "include/types.h"
 #include "global/signal_handler.h"
 #include <iostream>
 #include <boost/accumulators/accumulators.hpp>
@@ -79,7 +79,7 @@ void validate(boost::any& v, const std::vector<std::string>& values,
   }
 }
 
-io_type_t get_io_type(string io_type_string) {
+io_type_t get_io_type(std::string io_type_string) {
   if (io_type_string == "read")
     return IO_TYPE_READ;
   else if (io_type_string == "write")
@@ -124,8 +124,8 @@ public:
 
 struct rbd_bencher {
   librbd::Image *image;
-  Mutex lock;
-  Cond cond;
+  ceph::mutex lock = ceph::make_mutex("rbd_bencher::lock");
+  ceph::condition_variable cond;
   int in_flight;
   io_type_t io_type;
   uint64_t io_size;
@@ -133,7 +133,6 @@ struct rbd_bencher {
 
   explicit rbd_bencher(librbd::Image *i, io_type_t io_type, uint64_t io_size)
     : image(i),
-      lock("rbd_bencher::lock"),
       in_flight(0),
       io_type(io_type),
       io_size(io_size)
@@ -148,7 +147,7 @@ struct rbd_bencher {
   void start_io(int max, uint64_t off, uint64_t len, int op_flags, bool read_flag)
   {
     {
-      Mutex::Locker l(lock);
+      std::lock_guard l{lock};
       in_flight++;
     }
 
@@ -166,11 +165,9 @@ struct rbd_bencher {
   }
 
   int wait_for(int max, bool interrupt_on_terminating) {
-    Mutex::Locker l(lock);
+    std::unique_lock l{lock};
     while (in_flight > max && !(terminating && interrupt_on_terminating)) {
-      utime_t dur;
-      dur.set_from_double(.2);
-      cond.WaitInterval(lock, dur);
+      cond.wait_for(l, 200ms);
     }
 
     return terminating ? -EINTR : 0;
@@ -186,16 +183,16 @@ void rbd_bencher_completion(void *vc, void *pc)
   //cout << "complete " << c << std::endl;
   int ret = c->get_return_value();
   if (b->io_type == IO_TYPE_WRITE && ret != 0) {
-    cout << "write error: " << cpp_strerror(ret) << std::endl;
+    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;
     exit(ret < 0 ? -ret : ret);
   }
-  b->lock.Lock();
+  b->lock.lock();
   b->in_flight--;
-  b->cond.Signal();
-  b->lock.Unlock();
+  b->cond.notify_all();
+  b->lock.unlock();
   c->release();
   delete bc;
 }
index 5a168d9bc268b4f879415c737a91ecb5afb0eef8..30a0ba03f0a08917f59fda347514d14de9ac66d5 100644 (file)
@@ -4,11 +4,12 @@
 #include "tools/rbd/ArgumentTypes.h"
 #include "tools/rbd/Shell.h"
 #include "tools/rbd/Utils.h"
+#include "common/ceph_mutex.h"
+#include "common/config_proxy.h"
 #include "common/errno.h"
+#include "global/global_context.h"
 #include <iostream>
 #include <boost/program_options.hpp>
-#include "common/Cond.h"
-#include "common/Mutex.h"
 
 namespace rbd {
 namespace action {
@@ -37,8 +38,8 @@ void thick_provision_writer_completion(rbd_completion_t, void *);
 
 struct thick_provision_writer {
   librbd::Image *image;
-  Mutex lock;
-  Cond cond;
+  ceph::mutex lock = ceph::make_mutex("thick_provision_writer::lock");
+  ceph::condition_variable cond;
   bufferlist bl;
   uint64_t chunk_size;
   const int block_size;
@@ -51,7 +52,6 @@ struct thick_provision_writer {
   // Constructor
   explicit thick_provision_writer(librbd::Image *i, librbd::ImageOptions &o)
     : image(i),
-      lock("thick_provision_writer::lock"),
       block_size(512) // 512 Bytes
   {
     // If error cases occur, the code is aborted, because
@@ -81,7 +81,7 @@ struct thick_provision_writer {
   int start_io(uint64_t write_offset)
   {
     {
-      Mutex::Locker l(lock);
+      std::lock_guard l{lock};
       io_status.in_flight++;
       if (io_status.in_flight > concurr) {
         io_status.in_flight--;
@@ -94,20 +94,18 @@ struct thick_provision_writer {
     int r;
     r = image->aio_writesame(write_offset, chunk_size, bl, c, LIBRADOS_OP_FLAG_FADVISE_SEQUENTIAL);
     if (r < 0) {
-      Mutex::Locker l(lock);
+      std::lock_guard l{lock};
       io_status.io_error = r;
     }
     return r;
   }
 
   int wait_for(uint64_t max) {
-    Mutex::Locker l(lock);
+    std::unique_lock l{lock};
     int r = io_status.io_error;
 
     while (io_status.in_flight > max) {
-      utime_t dur;
-      dur.set_from_double(.2);
-      cond.WaitInterval(lock, dur);
+      cond.wait_for(l, 200ms);
     }
     return r;
   }
@@ -118,13 +116,13 @@ void thick_provision_writer_completion(rbd_completion_t rc, void *pc) {
   thick_provision_writer *tc = static_cast<thick_provision_writer *>(pc);
 
   int r = ac->get_return_value();
-  tc->lock.Lock();
+  tc->lock.lock();
   if (r < 0 &&  tc->io_status.io_error >= 0) {
     tc->io_status.io_error = r;
   }
   tc->io_status.in_flight--;
-  tc->cond.Signal();
-  tc->lock.Unlock();
+  tc->cond.notify_all();
+  tc->lock.unlock();
   ac->release();
 }