From: Jason Dillaman Date: Thu, 17 Dec 2015 18:21:42 +0000 (-0500) Subject: librbd: AioImageRequest base class is now templated X-Git-Tag: v10.0.3~24^2~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=37df59701210eded02640b3ca7dd52730b6abb73;p=ceph.git librbd: AioImageRequest base class is now templated Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/AioImageRequest.cc b/src/librbd/AioImageRequest.cc index ed93b34eb750..cba7dde12197 100644 --- a/src/librbd/AioImageRequest.cc +++ b/src/librbd/AioImageRequest.cc @@ -77,39 +77,46 @@ struct C_FlushJournalCommit : public Context { } // anonymous namespace -void AioImageRequest::aio_read( - ImageCtx *ictx, AioCompletion *c, +template +void AioImageRequest::aio_read( + I *ictx, AioCompletion *c, const std::vector > &extents, char *buf, bufferlist *pbl, int op_flags) { AioImageRead req(*ictx, c, extents, buf, pbl, op_flags); req.send(); } -void AioImageRequest::aio_read(ImageCtx *ictx, AioCompletion *c, uint64_t off, - size_t len, char *buf, bufferlist *pbl, - int op_flags) { +template +void AioImageRequest::aio_read(I *ictx, AioCompletion *c, + uint64_t off, size_t len, char *buf, + bufferlist *pbl, int op_flags) { AioImageRead req(*ictx, c, off, len, buf, pbl, op_flags); req.send(); } -void AioImageRequest::aio_write(ImageCtx *ictx, AioCompletion *c, uint64_t off, - size_t len, const char *buf, int op_flags) { +template +void AioImageRequest::aio_write(I *ictx, AioCompletion *c, + uint64_t off, size_t len, const char *buf, + int op_flags) { AioImageWrite req(*ictx, c, off, len, buf, op_flags); req.send(); } -void AioImageRequest::aio_discard(ImageCtx *ictx, AioCompletion *c, - uint64_t off, uint64_t len) { +template +void AioImageRequest::aio_discard(I *ictx, AioCompletion *c, + uint64_t off, uint64_t len) { AioImageDiscard req(*ictx, c, off, len); req.send(); } -void AioImageRequest::aio_flush(ImageCtx *ictx, AioCompletion *c) { +template +void AioImageRequest::aio_flush(I *ictx, AioCompletion *c) { AioImageFlush req(*ictx, c); req.send(); } -void AioImageRequest::send() { +template +void AioImageRequest::send() { assert(m_image_ctx.owner_lock.is_locked()); CephContext *cct = m_image_ctx.cct; @@ -120,7 +127,8 @@ void AioImageRequest::send() { send_request(); } -void AioImageRequest::fail(int r) { +template +void AioImageRequest::fail(int r) { m_aio_comp->get(); m_aio_comp->fail(m_image_ctx.cct, r); } @@ -466,3 +474,5 @@ void AioImageFlush::send_request() { } } // namespace librbd + +template class librbd::AioImageRequest; diff --git a/src/librbd/AioImageRequest.h b/src/librbd/AioImageRequest.h index 6ee6d64322ba..e8a3fd5b106e 100644 --- a/src/librbd/AioImageRequest.h +++ b/src/librbd/AioImageRequest.h @@ -18,22 +18,23 @@ namespace librbd { class AioObjectRequest; class ImageCtx; +template class AioImageRequest { public: typedef std::vector > Extents; virtual ~AioImageRequest() {} - static void aio_read(ImageCtx *ictx, AioCompletion *c, + static void aio_read(ImageCtxT *ictx, AioCompletion *c, const std::vector > &extents, char *buf, bufferlist *pbl, int op_flags); - static void aio_read(ImageCtx *ictx, AioCompletion *c, uint64_t off, + static void aio_read(ImageCtxT *ictx, AioCompletion *c, uint64_t off, size_t len, char *buf, bufferlist *pbl, int op_flags); - static void aio_write(ImageCtx *ictx, AioCompletion *c, uint64_t off, + static void aio_write(ImageCtxT *ictx, AioCompletion *c, uint64_t off, size_t len, const char *buf, int op_flags); - static void aio_discard(ImageCtx *ictx, AioCompletion *c, uint64_t off, + static void aio_discard(ImageCtxT *ictx, AioCompletion *c, uint64_t off, uint64_t len); - static void aio_flush(ImageCtx *ictx, AioCompletion *c); + static void aio_flush(ImageCtxT *ictx, AioCompletion *c); virtual bool is_write_op() const { return false; @@ -45,17 +46,17 @@ public: protected: typedef std::list AioObjectRequests; - ImageCtx &m_image_ctx; + ImageCtxT &m_image_ctx; AioCompletion *m_aio_comp; - AioImageRequest(ImageCtx &image_ctx, AioCompletion *aio_comp) + AioImageRequest(ImageCtxT &image_ctx, AioCompletion *aio_comp) : m_image_ctx(image_ctx), m_aio_comp(aio_comp) {} virtual void send_request() = 0; virtual const char *get_request_type() const = 0; }; -class AioImageRead : public AioImageRequest { +class AioImageRead : public AioImageRequest<> { public: AioImageRead(ImageCtx &image_ctx, AioCompletion *aio_comp, uint64_t off, size_t len, char *buf, bufferlist *pbl, int op_flags) @@ -83,7 +84,7 @@ private: int m_op_flags; }; -class AbstractAioImageWrite : public AioImageRequest { +class AbstractAioImageWrite : public AioImageRequest<> { public: virtual bool is_write_op() const { return true; @@ -194,7 +195,7 @@ protected: virtual void update_stats(size_t length); }; -class AioImageFlush : public AioImageRequest { +class AioImageFlush : public AioImageRequest<> { public: AioImageFlush(ImageCtx &image_ctx, AioCompletion *aio_comp) : AioImageRequest(image_ctx, aio_comp) { @@ -213,4 +214,6 @@ protected: } // namespace librbd +extern template class librbd::AioImageRequest; + #endif // CEPH_LIBRBD_AIO_IMAGE_REQUEST_H diff --git a/src/librbd/AioImageRequestWQ.cc b/src/librbd/AioImageRequestWQ.cc index f6607e227139..2de18d35c50d 100644 --- a/src/librbd/AioImageRequestWQ.cc +++ b/src/librbd/AioImageRequestWQ.cc @@ -19,7 +19,7 @@ namespace librbd { AioImageRequestWQ::AioImageRequestWQ(ImageCtx *image_ctx, const string &name, time_t ti, ThreadPool *tp) - : ThreadPool::PointerWQ(name, ti, 0, tp), + : ThreadPool::PointerWQ >(name, ti, 0, tp), m_image_ctx(*image_ctx), m_lock(util::unique_lock_name("AioImageRequestWQ::m_lock", this)), m_write_blockers(0), m_in_progress_writes(0), m_queued_writes(0), @@ -115,7 +115,7 @@ void AioImageRequestWQ::aio_read(AioCompletion *c, uint64_t off, uint64_t len, if (m_image_ctx.non_blocking_aio || writes_blocked() || !writes_empty()) { queue(new AioImageRead(m_image_ctx, c, off, len, buf, pbl, op_flags)); } else { - AioImageRequest::aio_read(&m_image_ctx, c, off, len, buf, pbl, op_flags); + AioImageRequest<>::aio_read(&m_image_ctx, c, off, len, buf, pbl, op_flags); finish_in_flight_op(); } } @@ -142,7 +142,7 @@ void AioImageRequestWQ::aio_write(AioCompletion *c, uint64_t off, uint64_t len, writes_blocked()) { queue(new AioImageWrite(m_image_ctx, c, off, len, buf, op_flags)); } else { - AioImageRequest::aio_write(&m_image_ctx, c, off, len, buf, op_flags); + AioImageRequest<>::aio_write(&m_image_ctx, c, off, len, buf, op_flags); finish_in_flight_op(); } } @@ -168,7 +168,7 @@ void AioImageRequestWQ::aio_discard(AioCompletion *c, uint64_t off, writes_blocked()) { queue(new AioImageDiscard(m_image_ctx, c, off, len)); } else { - AioImageRequest::aio_discard(&m_image_ctx, c, off, len); + AioImageRequest<>::aio_discard(&m_image_ctx, c, off, len); finish_in_flight_op(); } } @@ -192,7 +192,7 @@ void AioImageRequestWQ::aio_flush(AioCompletion *c, bool native_async) { writes_blocked() || !writes_empty()) { queue(new AioImageFlush(m_image_ctx, c)); } else { - AioImageRequest::aio_flush(&m_image_ctx, c); + AioImageRequest<>::aio_flush(&m_image_ctx, c); finish_in_flight_op(); } } @@ -265,7 +265,7 @@ void AioImageRequestWQ::unblock_writes() { } void *AioImageRequestWQ::_void_dequeue() { - AioImageRequest *peek_item = front(); + AioImageRequest<> *peek_item = front(); if (peek_item == NULL || m_refresh_in_progress) { return NULL; } @@ -278,8 +278,8 @@ void *AioImageRequestWQ::_void_dequeue() { m_in_progress_writes.inc(); } - AioImageRequest *item = reinterpret_cast( - ThreadPool::PointerWQ::_void_dequeue()); + AioImageRequest<> *item = reinterpret_cast *>( + ThreadPool::PointerWQ >::_void_dequeue()); assert(peek_item == item); if (m_image_ctx.state->is_refresh_required()) { @@ -295,7 +295,7 @@ void *AioImageRequestWQ::_void_dequeue() { return item; } -void AioImageRequestWQ::process(AioImageRequest *req) { +void AioImageRequestWQ::process(AioImageRequest<> *req) { CephContext *cct = m_image_ctx.cct; ldout(cct, 20) << __func__ << ": ictx=" << &m_image_ctx << ", " << "req=" << req << dendl; @@ -376,7 +376,7 @@ bool AioImageRequestWQ::is_lock_required() const { return (!m_image_ctx.exclusive_lock->is_lock_owner()); } -void AioImageRequestWQ::queue(AioImageRequest *req) { +void AioImageRequestWQ::queue(AioImageRequest<> *req) { CephContext *cct = m_image_ctx.cct; ldout(cct, 20) << __func__ << ": ictx=" << &m_image_ctx << ", " << "req=" << req << dendl; @@ -387,14 +387,14 @@ void AioImageRequestWQ::queue(AioImageRequest *req) { m_queued_writes.inc(); } - ThreadPool::PointerWQ::queue(req); + ThreadPool::PointerWQ >::queue(req); if (write_op && is_lock_required()) { m_image_ctx.exclusive_lock->request_lock(nullptr); } } -void AioImageRequestWQ::handle_refreshed(int r, AioImageRequest *req) { +void AioImageRequestWQ::handle_refreshed(int r, AioImageRequest<> *req) { CephContext *cct = m_image_ctx.cct; ldout(cct, 15) << "resuming IO after image refresh: r=" << r << ", " << "req=" << req << dendl; diff --git a/src/librbd/AioImageRequestWQ.h b/src/librbd/AioImageRequestWQ.h index c84548955a33..1573e72658cd 100644 --- a/src/librbd/AioImageRequestWQ.h +++ b/src/librbd/AioImageRequestWQ.h @@ -14,10 +14,10 @@ namespace librbd { class AioCompletion; -class AioImageRequest; +template class AioImageRequest; class ImageCtx; -class AioImageRequestWQ : protected ThreadPool::PointerWQ { +class AioImageRequestWQ : protected ThreadPool::PointerWQ > { public: AioImageRequestWQ(ImageCtx *image_ctx, const string &name, time_t ti, ThreadPool *tp); @@ -30,11 +30,12 @@ public: bufferlist *pbl, int op_flags, bool native_async=true); void aio_write(AioCompletion *c, uint64_t off, uint64_t len, const char *buf, int op_flags, bool native_async=true); - void aio_discard(AioCompletion *c, uint64_t off, uint64_t len, bool native_async=true); + void aio_discard(AioCompletion *c, uint64_t off, uint64_t len, + bool native_async=true); void aio_flush(AioCompletion *c, bool native_async=true); - using ThreadPool::PointerWQ::drain; - using ThreadPool::PointerWQ::empty; + using typename ThreadPool::PointerWQ >::drain; + using typename ThreadPool::PointerWQ >::empty; inline bool writes_empty() const { RWLock::RLocker locker(m_lock); @@ -54,17 +55,17 @@ public: protected: virtual void *_void_dequeue(); - virtual void process(AioImageRequest *req); + virtual void process(AioImageRequest *req); private: typedef std::list Contexts; struct C_RefreshFinish : public Context { AioImageRequestWQ *aio_work_queue; - AioImageRequest *aio_image_request; + AioImageRequest *aio_image_request; C_RefreshFinish(AioImageRequestWQ *aio_work_queue, - AioImageRequest *aio_image_request) + AioImageRequest *aio_image_request) : aio_work_queue(aio_work_queue), aio_image_request(aio_image_request) { } virtual void finish(int r) override { @@ -101,9 +102,9 @@ private: bool is_journal_required() const; bool is_lock_required() const; - void queue(AioImageRequest *req); + void queue(AioImageRequest *req); - void handle_refreshed(int r, AioImageRequest *req); + void handle_refreshed(int r, AioImageRequest *req); void handle_blocked_writes(int r); }; diff --git a/src/librbd/AioObjectRequest.cc b/src/librbd/AioObjectRequest.cc index 34a1c116999d..96669eadbe47 100644 --- a/src/librbd/AioObjectRequest.cc +++ b/src/librbd/AioObjectRequest.cc @@ -281,8 +281,8 @@ namespace librbd { << " extents " << parent_extents << dendl; RWLock::RLocker owner_locker(m_ictx->parent->owner_lock); - AioImageRequest::aio_read(m_ictx->parent, m_parent_completion, - parent_extents, NULL, &m_read_data, 0); + AioImageRequest<>::aio_read(m_ictx->parent, m_parent_completion, + parent_extents, NULL, &m_read_data, 0); } /** write **/ diff --git a/src/librbd/CopyupRequest.cc b/src/librbd/CopyupRequest.cc index d7713ad166a0..29d8a4ac40fb 100644 --- a/src/librbd/CopyupRequest.cc +++ b/src/librbd/CopyupRequest.cc @@ -191,8 +191,8 @@ private: << ", extents " << m_image_extents << dendl; RWLock::RLocker owner_locker(m_ictx->parent->owner_lock); - AioImageRequest::aio_read(m_ictx->parent, comp, m_image_extents, NULL, - &m_copyup_data, 0); + AioImageRequest<>::aio_read(m_ictx->parent, comp, m_image_extents, NULL, + &m_copyup_data, 0); } void CopyupRequest::complete(int r) diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index a926e03731cf..eb77456a7e8c 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -1894,8 +1894,8 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { bufferlist *bl = new bufferlist(); Context *ctx = new C_CopyRead(&throttle, dest, offset, bl); AioCompletion *comp = AioCompletion::create(ctx); - AioImageRequest::aio_read(src, comp, offset, len, NULL, bl, - fadvise_flags); + AioImageRequest<>::aio_read(src, comp, offset, len, NULL, bl, + fadvise_flags); prog_ctx.update_progress(offset, src_size); } @@ -2119,7 +2119,7 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { C_SaferCond ctx; AioCompletion *c = AioCompletion::create(&ctx); - AioImageRequest::aio_read(ictx, c, off, read_len, NULL, &bl, 0); + AioImageRequest<>::aio_read(ictx, c, off, read_len, NULL, &bl, 0); int ret = ctx.wait(); if (ret < 0) { diff --git a/src/librbd/journal/Replay.cc b/src/librbd/journal/Replay.cc index 23172179e180..b0bb1ce573cf 100644 --- a/src/librbd/journal/Replay.cc +++ b/src/librbd/journal/Replay.cc @@ -67,8 +67,8 @@ void Replay::handle_event(const journal::AioDiscardEvent &event, ldout(cct, 20) << this << " " << __func__ << ": AIO discard event" << dendl; AioCompletion *aio_comp = create_aio_completion(on_safe); - AioImageRequest::aio_discard(&m_image_ctx, aio_comp, event.offset, - event.length); + AioImageRequest::aio_discard(&m_image_ctx, aio_comp, event.offset, + event.length); } template @@ -79,8 +79,8 @@ void Replay::handle_event(const journal::AioWriteEvent &event, bufferlist data = event.data; AioCompletion *aio_comp = create_aio_completion(on_safe); - AioImageRequest::aio_write(&m_image_ctx, aio_comp, event.offset, event.length, - data.c_str(), 0); + AioImageRequest::aio_write(&m_image_ctx, aio_comp, event.offset, + event.length, data.c_str(), 0); } template @@ -90,7 +90,7 @@ void Replay::handle_event(const journal::AioFlushEvent &event, ldout(cct, 20) << this << " " << __func__ << ": AIO flush event" << dendl; AioCompletion *aio_comp = create_aio_completion(on_safe); - AioImageRequest::aio_flush(&m_image_ctx, aio_comp); + AioImageRequest::aio_flush(&m_image_ctx, aio_comp); } template