From 04df167b59f072f2aa913bea0b282115027f5505 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 29 Apr 2020 12:27:46 -0400 Subject: [PATCH] common: TokenBucketThrottle should use perfect forwarding for item This will allow more than just a pointer to an item to be passed to the callback. Signed-off-by: Jason Dillaman --- src/common/Throttle.h | 19 +++++++++++-------- src/librbd/io/ImageRequestWQ.cc | 10 +++++----- src/librbd/io/ImageRequestWQ.h | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/common/Throttle.h b/src/common/Throttle.h index e38886de06d33..d4bb77025af09 100644 --- a/src/common/Throttle.h +++ b/src/common/Throttle.h @@ -414,16 +414,17 @@ public: return m_name; } - template - void add_blocker(uint64_t c, T *handler, I *item, uint64_t flag) { - Context *ctx = new LambdaContext([handler, item, flag](int r) { - (handler->*MF)(r, item, flag); + template + void add_blocker(uint64_t c, T&& t, MF&& mf, I&& item, uint64_t flag) { + auto ctx = new LambdaContext( + [t, mf, item=std::forward(item), flag](int) mutable { + (t->*mf)(std::forward(item), flag); }); m_blockers.emplace_back(c, ctx); } - template - bool get(uint64_t c, T *handler, I *item, uint64_t flag) { + template + bool get(uint64_t c, T&& t, MF&& mf, I&& item, uint64_t flag) { bool wait = false; uint64_t got = 0; std::lock_guard lock(m_lock); @@ -441,8 +442,10 @@ public: } } - if (wait) - add_blocker(c - got, handler, item, flag); + if (wait) { + add_blocker(c - got, std::forward(t), std::forward(mf), + std::forward(item), flag); + } return wait; } diff --git a/src/librbd/io/ImageRequestWQ.cc b/src/librbd/io/ImageRequestWQ.cc index 2d21418428196..c8677d0a8c7a1 100644 --- a/src/librbd/io/ImageRequestWQ.cc +++ b/src/librbd/io/ImageRequestWQ.cc @@ -789,9 +789,10 @@ void ImageRequestWQ::apply_qos_limit(const uint64_t flag, } template -void ImageRequestWQ::handle_throttle_ready(int r, ImageDispatchSpec *item, uint64_t flag) { +void ImageRequestWQ::handle_throttle_ready( + ImageDispatchSpec *item, uint64_t flag) { CephContext *cct = m_image_ctx.cct; - ldout(cct, 15) << "r=" << r << ", " << "req=" << item << dendl; + ldout(cct, 15) << "req=" << item << dendl; ceph_assert(m_io_throttled.load() > 0); item->set_throttled(flag); @@ -821,9 +822,8 @@ bool ImageRequestWQ::needs_throttle(ImageDispatchSpec *item) { throttle = t.second; if (item->tokens_requested(flag, &tokens) && - throttle->get, ImageDispatchSpec, - &ImageRequestWQ::handle_throttle_ready>( - tokens, this, item, flag)) { + throttle->get(tokens, this, &ImageRequestWQ::handle_throttle_ready, + item, flag)) { blocked = true; } else { item->set_throttled(flag); diff --git a/src/librbd/io/ImageRequestWQ.h b/src/librbd/io/ImageRequestWQ.h index ecbf33f3d20a8..40acfa5239071 100644 --- a/src/librbd/io/ImageRequestWQ.h +++ b/src/librbd/io/ImageRequestWQ.h @@ -158,7 +158,7 @@ private: void handle_refreshed(int r, ImageDispatchSpec *req); void handle_blocked_writes(int r); - void handle_throttle_ready(int r, ImageDispatchSpec *item, uint64_t flag); + void handle_throttle_ready(ImageDispatchSpec *item, uint64_t flag); }; } // namespace io -- 2.39.5