X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Ftools%2Frbd_mirror%2Fimage_sync%2FObjectCopyRequest.h;fp=src%2Fceph%2Fsrc%2Ftools%2Frbd_mirror%2Fimage_sync%2FObjectCopyRequest.h;h=8430e7030c43933fb299222d7ac5d0fdea085ccd;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.h b/src/ceph/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.h new file mode 100644 index 0000000..8430e70 --- /dev/null +++ b/src/ceph/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.h @@ -0,0 +1,153 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef RBD_MIRROR_IMAGE_SYNC_OBJECT_COPY_REQUEST_H +#define RBD_MIRROR_IMAGE_SYNC_OBJECT_COPY_REQUEST_H + +#include "include/int_types.h" +#include "include/rados/librados.hpp" +#include "common/snap_types.h" +#include "librbd/ImageCtx.h" +#include +#include +#include +#include + +class Context; +class RWLock; + +namespace rbd { +namespace mirror { +namespace image_sync { + +template +class ObjectCopyRequest { +public: + typedef std::vector SnapIds; + typedef std::map SnapMap; + + static ObjectCopyRequest* create(ImageCtxT *local_image_ctx, + ImageCtxT *remote_image_ctx, + const SnapMap *snap_map, + uint64_t object_number, Context *on_finish) { + return new ObjectCopyRequest(local_image_ctx, remote_image_ctx, snap_map, + object_number, on_finish); + } + + ObjectCopyRequest(ImageCtxT *local_image_ctx, ImageCtxT *remote_image_ctx, + const SnapMap *snap_map, uint64_t object_number, + Context *on_finish); + + void send(); + + // testing support + inline librados::IoCtx &get_local_io_ctx() { + return m_local_io_ctx; + } + inline librados::IoCtx &get_remote_io_ctx() { + return m_remote_io_ctx; + } + +private: + /** + * @verbatim + * + * + * | + * v + * LIST_SNAPS < * * * + * | * (-ENOENT and snap set stale) + * | * * * * * * + * | * + * v * + * READ_OBJECT <--------\ + * | | (repeat for each snapshot) + * v | + * WRITE_OBJECT --------/ + * | + * | /-----------\ + * | | | (repeat for each snapshot) + * v v | + * UPDATE_OBJECT_MAP ---/ (skip if object + * | map disabled) + * | + * v + * + * + * @endverbatim + */ + + enum SyncOpType { + SYNC_OP_TYPE_WRITE, + SYNC_OP_TYPE_TRUNC, + SYNC_OP_TYPE_REMOVE + }; + + typedef std::map ExtentMap; + + struct SyncOp { + SyncOp(SyncOpType type, uint64_t offset, uint64_t length) + : type(type), offset(offset), length(length) { + } + + SyncOpType type; + uint64_t offset; + uint64_t length; + + ExtentMap extent_map; + bufferlist out_bl; + }; + + typedef std::list SyncOps; + typedef std::pair WriteReadSnapIds; + typedef std::map SnapSyncOps; + typedef std::map SnapObjectStates; + typedef std::map SnapObjectSizes; + + ImageCtxT *m_local_image_ctx; + ImageCtxT *m_remote_image_ctx; + const SnapMap *m_snap_map; + uint64_t m_object_number; + Context *m_on_finish; + + decltype(m_local_image_ctx->data_ctx) m_local_io_ctx; + decltype(m_remote_image_ctx->data_ctx) m_remote_io_ctx; + std::string m_local_oid; + std::string m_remote_oid; + + librados::snap_set_t m_snap_set; + int m_snap_ret; + + bool m_retry_missing_read = false; + librados::snap_set_t m_retry_snap_set; + + SnapSyncOps m_snap_sync_ops; + SnapObjectStates m_snap_object_states; + SnapObjectSizes m_snap_object_sizes; + + void send_list_snaps(); + void handle_list_snaps(int r); + + void send_read_object(); + void handle_read_object(int r); + + void send_write_object(); + void handle_write_object(int r); + + void send_update_object_map(); + void handle_update_object_map(int r); + + Context *start_local_op(RWLock &owner_lock); + + void compute_diffs(); + void finish(int r); + +}; + +} // namespace image_sync +} // namespace mirror +} // namespace rbd + +extern template class rbd::mirror::image_sync::ObjectCopyRequest; + +#endif // RBD_MIRROR_IMAGE_SYNC_OBJECT_COPY_REQUEST_H