From a7ac68d4fd81d9046d225e2f61e2d57ab26c3d23 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 17 Jul 2019 16:30:56 +0800 Subject: [PATCH] tools/rbd: s/Mutex/ceph::mutex/ Signed-off-by: Kefu Chai --- src/tools/rbd/action/Bench.cc | 27 ++++++++++++--------------- src/tools/rbd/action/Create.cc | 26 ++++++++++++-------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/tools/rbd/action/Bench.cc b/src/tools/rbd/action/Bench.cc index d5791bdc6ff0b..2c2fa5836fe88 100644 --- a/src/tools/rbd/action/Bench.cc +++ b/src/tools/rbd/action/Bench.cc @@ -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 #include @@ -79,7 +79,7 @@ void validate(boost::any& v, const std::vector& 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; } diff --git a/src/tools/rbd/action/Create.cc b/src/tools/rbd/action/Create.cc index 5a168d9bc268b..30a0ba03f0a08 100644 --- a/src/tools/rbd/action/Create.cc +++ b/src/tools/rbd/action/Create.cc @@ -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 #include -#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(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(); } -- 2.39.5