From: Jason Dillaman Date: Wed, 27 Jul 2016 14:56:48 +0000 (-0400) Subject: librbd: utilize factory methods to create AioObjectRequest objects X-Git-Tag: v10.2.3~48^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=062162f88f1bdaaaa96713429007757b72ec92f9;p=ceph.git librbd: utilize factory methods to create AioObjectRequest objects Signed-off-by: Jason Dillaman (cherry picked from commit 2e5076eb19172919deeb0f4d11f2b2b6cc03fab3) --- diff --git a/src/librbd/AioImageRequest.cc b/src/librbd/AioImageRequest.cc index 40327aaa805d8..dd1e26aa49fe2 100644 --- a/src/librbd/AioImageRequest.cc +++ b/src/librbd/AioImageRequest.cc @@ -269,14 +269,10 @@ void AioImageRead::send_request() { << dendl; C_AioRead *req_comp = new C_AioRead(aio_comp); - AioObjectRead *req = new AioObjectRead(get_image_ctx(&image_ctx), - extent.oid.name, - extent.objectno, - extent.offset, - extent.length, - extent.buffer_extents, - snap_id, true, req_comp, - m_op_flags); + AioObjectRead *req = AioObjectRead::create( + &image_ctx, extent.oid.name, extent.objectno, extent.offset, + extent.length, extent.buffer_extents, snap_id, true, req_comp, + m_op_flags); req_comp->set_req(req); if (image_ctx.object_cacher) { @@ -379,7 +375,8 @@ void AbstractAioImageWrite::send_object_requests( ldout(cct, 20) << " oid " << p->oid << " " << p->offset << "~" << p->length << " from " << p->buffer_extents << dendl; C_AioRequest *req_comp = new C_AioRequest(aio_comp); - AioObjectRequest<> *request = create_object_request(*p, snapc, req_comp); + AioObjectRequestHandle *request = create_object_request(*p, snapc, + req_comp); // if journaling, stash the request for later; otherwise send if (request != NULL) { @@ -450,7 +447,7 @@ void AioImageWrite::send_object_requests( } template -AioObjectRequest<> *AioImageWrite::create_object_request( +AioObjectRequestHandle *AioImageWrite::create_object_request( const ObjectExtent &object_extent, const ::SnapContext &snapc, Context *on_finish) { I &image_ctx = this->m_image_ctx; @@ -458,12 +455,9 @@ AioObjectRequest<> *AioImageWrite::create_object_request( bufferlist bl; assemble_extent(object_extent, &bl); - AioObjectWrite *req = new AioObjectWrite(get_image_ctx(&image_ctx), - object_extent.oid.name, - object_extent.objectno, - object_extent.offset, bl, - snapc, on_finish); - req->set_op_flags(m_op_flags); + AioObjectRequest *req = AioObjectRequest::create_write( + &image_ctx, object_extent.oid.name, object_extent.objectno, + object_extent.offset, bl, snapc, on_finish, m_op_flags); return req; } @@ -536,27 +530,25 @@ void AioImageDiscard::send_cache_requests(const ObjectExtents &object_extents } template -AioObjectRequest<> *AioImageDiscard::create_object_request( +AioObjectRequestHandle *AioImageDiscard::create_object_request( const ObjectExtent &object_extent, const ::SnapContext &snapc, Context *on_finish) { I &image_ctx = this->m_image_ctx; - AioObjectRequest<> *req; + AioObjectRequest *req; if (object_extent.length == image_ctx.layout.object_size) { - req = new AioObjectRemove(get_image_ctx(&image_ctx), - object_extent.oid.name, - object_extent.objectno, snapc, on_finish); + req = AioObjectRequest::create_remove( + &image_ctx, object_extent.oid.name, object_extent.objectno, snapc, + on_finish); } else if (object_extent.offset + object_extent.length == image_ctx.layout.object_size) { - req = new AioObjectTruncate(get_image_ctx(&image_ctx), - object_extent.oid.name, - object_extent.objectno, object_extent.offset, - snapc, on_finish); + req = AioObjectRequest::create_truncate( + &image_ctx, object_extent.oid.name, object_extent.objectno, + object_extent.offset, snapc, on_finish); } else { - req = new AioObjectZero(get_image_ctx(&image_ctx), - object_extent.oid.name, - object_extent.objectno, object_extent.offset, - object_extent.length, snapc, on_finish); + req = AioObjectRequest::create_zero( + &image_ctx, object_extent.oid.name, object_extent.objectno, + object_extent.offset, object_extent.length, snapc, on_finish); } return req; } diff --git a/src/librbd/AioImageRequest.h b/src/librbd/AioImageRequest.h index f5ae33d6ae45b..3d6b3851b35b0 100644 --- a/src/librbd/AioImageRequest.h +++ b/src/librbd/AioImageRequest.h @@ -16,7 +16,7 @@ namespace librbd { class AioCompletion; -template class AioObjectRequest; +class AioObjectRequestHandle; class ImageCtx; template @@ -49,7 +49,7 @@ public: void fail(int r); protected: - typedef std::list *> AioObjectRequests; + typedef std::list AioObjectRequests; ImageCtxT &m_image_ctx; AioCompletion *m_aio_comp; @@ -135,7 +135,7 @@ protected: virtual void send_object_requests(const ObjectExtents &object_extents, const ::SnapContext &snapc, AioObjectRequests *aio_object_requests); - virtual AioObjectRequest *create_object_request( + virtual AioObjectRequestHandle *create_object_request( const ObjectExtent &object_extent, const ::SnapContext &snapc, Context *on_finish) = 0; @@ -175,7 +175,7 @@ protected: virtual void send_object_requests(const ObjectExtents &object_extents, const ::SnapContext &snapc, AioObjectRequests *aio_object_requests); - virtual AioObjectRequest *create_object_request( + virtual AioObjectRequestHandle *create_object_request( const ObjectExtent &object_extent, const ::SnapContext &snapc, Context *on_finish); @@ -211,7 +211,7 @@ protected: virtual void send_cache_requests(const ObjectExtents &object_extents, uint64_t journal_tid); - virtual AioObjectRequest *create_object_request( + virtual AioObjectRequestHandle *create_object_request( const ObjectExtent &object_extent, const ::SnapContext &snapc, Context *on_finish); diff --git a/src/librbd/AioObjectRequest.cc b/src/librbd/AioObjectRequest.cc index 9ece245c05cf8..cf7617640b2c2 100644 --- a/src/librbd/AioObjectRequest.cc +++ b/src/librbd/AioObjectRequest.cc @@ -27,6 +27,48 @@ namespace librbd { +template +AioObjectRequest* +AioObjectRequest::create_remove(I *ictx, const std::string &oid, + uint64_t object_no, + const ::SnapContext &snapc, + Context *completion) { + return new AioObjectRemove(util::get_image_ctx(ictx), oid, object_no, snapc, + completion); +} + +template +AioObjectRequest* +AioObjectRequest::create_truncate(I *ictx, const std::string &oid, + uint64_t object_no, uint64_t object_off, + const ::SnapContext &snapc, + Context *completion) { + return new AioObjectTruncate(util::get_image_ctx(ictx), oid, object_no, + object_off, snapc, completion); +} + +template +AioObjectRequest* +AioObjectRequest::create_write(I *ictx, const std::string &oid, + uint64_t object_no, uint64_t object_off, + const ceph::bufferlist &data, + const ::SnapContext &snapc, + Context *completion, int op_flags) { + return new AioObjectWrite(util::get_image_ctx(ictx), oid, object_no, + object_off, data, snapc, completion, op_flags); +} + +template +AioObjectRequest* +AioObjectRequest::create_zero(I *ictx, const std::string &oid, + uint64_t object_no, uint64_t object_off, + uint64_t object_len, + const ::SnapContext &snapc, + Context *completion) { + return new AioObjectZero(util::get_image_ctx(ictx), oid, object_no, + object_off, object_len, snapc, completion); +} + template AioObjectRequest::AioObjectRequest(ImageCtx *ictx, const std::string &oid, uint64_t objectno, uint64_t off, @@ -97,14 +139,14 @@ static inline bool is_copy_on_read(ImageCtx *ictx, librados::snap_t snap_id) { /** read **/ template -AioObjectRead::AioObjectRead(ImageCtx *ictx, const std::string &oid, +AioObjectRead::AioObjectRead(I *ictx, const std::string &oid, uint64_t objectno, uint64_t offset, uint64_t len, vector >& be, librados::snap_t snap_id, bool sparse, Context *completion, int op_flags) - : AioObjectRequest(ictx, oid, objectno, offset, len, snap_id, completion, - false), + : AioObjectRequest(util::get_image_ctx(ictx), oid, objectno, offset, len, + snap_id, completion, false), m_buffer_extents(be), m_tried_parent(false), m_sparse(sparse), m_op_flags(op_flags), m_parent_completion(NULL), m_state(LIBRBD_AIO_READ_FLAT) { diff --git a/src/librbd/AioObjectRequest.h b/src/librbd/AioObjectRequest.h index c32d33579631a..068ce1a846dc8 100644 --- a/src/librbd/AioObjectRequest.h +++ b/src/librbd/AioObjectRequest.h @@ -18,17 +18,54 @@ class Context; namespace librbd { struct AioCompletion; +class AioObjectRemove; +class AioObjectTruncate; +class AioObjectWrite; +class AioObjectZero; struct ImageCtx; class CopyupRequest; +struct AioObjectRequestHandle { + virtual ~AioObjectRequestHandle() { + } + + virtual void complete(int r) = 0; + virtual void send() = 0; +}; + /** * This class represents an I/O operation to a single RBD data object. * Its subclasses encapsulate logic for dealing with special cases * for I/O due to layering. */ template -class AioObjectRequest { +class AioObjectRequest : public AioObjectRequestHandle { public: + typedef std::vector > Extents; + + static AioObjectRequest* create_remove(ImageCtxT *ictx, + const std::string &oid, + uint64_t object_no, + const ::SnapContext &snapc, + Context *completion); + static AioObjectRequest* create_truncate(ImageCtxT *ictx, + const std::string &oid, + uint64_t object_no, + uint64_t object_off, + const ::SnapContext &snapc, + Context *completion); + static AioObjectRequest* create_write(ImageCtxT *ictx, const std::string &oid, + uint64_t object_no, + uint64_t object_off, + const ceph::bufferlist &data, + const ::SnapContext &snapc, + Context *completion, int op_flags); + static AioObjectRequest* create_zero(ImageCtxT *ictx, const std::string &oid, + uint64_t object_no, uint64_t object_off, + uint64_t object_len, + const ::SnapContext &snapc, + Context *completion); + AioObjectRequest(ImageCtx *ictx, const std::string &oid, uint64_t objectno, uint64_t off, uint64_t len, librados::snap_t snap_id, @@ -54,7 +91,7 @@ protected: uint64_t m_object_no, m_object_off, m_object_len; librados::snap_t m_snap_id; Context *m_completion; - std::vector > m_parent_extents; + Extents m_parent_extents; bool m_hide_enoent; }; @@ -64,7 +101,16 @@ public: typedef std::vector > Extents; typedef std::map ExtentMap; - AioObjectRead(ImageCtx *ictx, const std::string &oid, + static AioObjectRead* create(ImageCtxT *ictx, const std::string &oid, + uint64_t objectno, uint64_t offset, + uint64_t len, Extents &buffer_extents, + librados::snap_t snap_id, bool sparse, + Context *completion, int op_flags) { + return new AioObjectRead(ictx, oid, objectno, offset, len, buffer_extents, + snap_id, sparse, completion, op_flags); + } + + AioObjectRead(ImageCtxT *ictx, const std::string &oid, uint64_t objectno, uint64_t offset, uint64_t len, Extents& buffer_extents, librados::snap_t snap_id, bool sparse, Context *completion, int op_flags); @@ -212,15 +258,13 @@ class AioObjectWrite : public AbstractAioObjectWrite { public: AioObjectWrite(ImageCtx *ictx, const std::string &oid, uint64_t object_no, uint64_t object_off, const ceph::bufferlist &data, - const ::SnapContext &snapc, Context *completion) + const ::SnapContext &snapc, Context *completion, + int op_flags) : AbstractAioObjectWrite(ictx, oid, object_no, object_off, data.length(), snapc, completion, false), - m_write_data(data), m_op_flags(0) { + m_write_data(data), m_op_flags(op_flags) { } - void set_op_flags(int op_flags) { - m_op_flags = op_flags; - } protected: virtual void add_write_ops(librados::ObjectWriteOperation *wr); diff --git a/src/librbd/Journal.h b/src/librbd/Journal.h index 2acb1c62deb57..ec3b328d88d40 100644 --- a/src/librbd/Journal.h +++ b/src/librbd/Journal.h @@ -31,7 +31,7 @@ namespace librados { namespace librbd { -template class AioObjectRequest; +struct AioObjectRequestHandle; class ImageCtx; namespace journal { template class Replay; } @@ -87,7 +87,7 @@ public: static const std::string LOCAL_MIRROR_UUID; static const std::string ORPHAN_MIRROR_UUID; - typedef std::list *> AioObjectRequests; + typedef std::list AioObjectRequests; Journal(ImageCtxT &image_ctx); ~Journal(); diff --git a/src/librbd/LibrbdWriteback.cc b/src/librbd/LibrbdWriteback.cc index e3ba517849c23..977b0b3163d75 100644 --- a/src/librbd/LibrbdWriteback.cc +++ b/src/librbd/LibrbdWriteback.cc @@ -162,7 +162,7 @@ namespace librbd { request_sent = true; AioObjectWrite *req = new AioObjectWrite(image_ctx, oid, object_no, off, - bl, snapc, this); + bl, snapc, this, 0); req->send(); } }; @@ -274,7 +274,7 @@ namespace librbd { journal_tid)); } else { AioObjectWrite *req = new AioObjectWrite(m_ictx, oid.name, object_no, - off, bl, snapc, req_comp); + off, bl, snapc, req_comp, 0); req->send(); } return ++m_tid; diff --git a/src/librbd/operation/FlattenRequest.cc b/src/librbd/operation/FlattenRequest.cc index 85433aeaa3643..8cfddbeac74dc 100644 --- a/src/librbd/operation/FlattenRequest.cc +++ b/src/librbd/operation/FlattenRequest.cc @@ -42,7 +42,7 @@ public: bufferlist bl; string oid = image_ctx.get_object_name(m_object_no); AioObjectWrite *req = new AioObjectWrite(&image_ctx, oid, m_object_no, 0, - bl, m_snapc, this); + bl, m_snapc, this, 0); if (!req->has_parent()) { // stop early if the parent went away - it just means // another flatten finished first or the image was resized diff --git a/src/test/librbd/mock/MockJournal.h b/src/test/librbd/mock/MockJournal.h index a66347edb9583..48447c3b8b476 100644 --- a/src/test/librbd/mock/MockJournal.h +++ b/src/test/librbd/mock/MockJournal.h @@ -11,11 +11,11 @@ namespace librbd { -template struct AioObjectRequest; +struct AioObjectRequestHandle; struct ImageCtx; struct MockJournal { - typedef std::list *> AioObjectRequests; + typedef std::list AioObjectRequests; static MockJournal *s_instance; static MockJournal *get_instance() {