Skip to content

Commit

Permalink
rbd_mirror: use asynchronous create_v2()
Browse files Browse the repository at this point in the history
Fixes: http://tracker.ceph.com/issues/15321
Signed-off-by: Venky Shankar <vshankar@redhat.com>
  • Loading branch information
vshankar committed Jun 8, 2016
1 parent fc362df commit 61b903c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
50 changes: 21 additions & 29 deletions src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc
Expand Up @@ -59,35 +59,27 @@ template <typename I>
void CreateImageRequest<I>::create_image() {
dout(20) << dendl;

// TODO: librbd should provide an AIO image creation method -- this is
// blocking so we execute in our worker thread
Context *ctx = new FunctionContext([this](int r) {
// TODO: rbd-mirror should offer a feature mask capability
RWLock::RLocker snap_locker(m_remote_image_ctx->snap_lock);
int order = m_remote_image_ctx->order;

CephContext *cct = reinterpret_cast<CephContext*>(m_local_io_ctx.cct());
uint64_t journal_order = cct->_conf->rbd_journal_order;
uint64_t journal_splay_width = cct->_conf->rbd_journal_splay_width;
std::string journal_pool = cct->_conf->rbd_journal_pool;

// NOTE: bid is 64bit but overflow will result due to
// RBD_MAX_BLOCK_NAME_SIZE being too small
librados::Rados rados(m_local_io_ctx);
uint64_t bid = rados.get_instance_id();

r = utils::create_image(m_local_io_ctx, m_remote_image_ctx,
m_local_image_name.c_str(), bid,
m_remote_image_ctx->size, order,
m_remote_image_ctx->features,
m_remote_image_ctx->stripe_unit,
m_remote_image_ctx->stripe_count,
journal_order, journal_splay_width,
journal_pool, m_global_image_id,
m_remote_mirror_uuid);
handle_create_image(r);
});
m_work_queue->queue(ctx, 0);
using klass = CreateImageRequest<I>;
Context *ctx = create_context_callback<klass, &klass::handle_create_image>(this);

RWLock::RLocker snap_locker(m_remote_image_ctx->snap_lock);
int order = m_remote_image_ctx->order;

CephContext *cct = reinterpret_cast<CephContext*>(m_local_io_ctx.cct());
uint64_t journal_order = cct->_conf->rbd_journal_order;
uint64_t journal_splay_width = cct->_conf->rbd_journal_splay_width;
std::string journal_pool = cct->_conf->rbd_journal_pool;

// NOTE: bid is 64bit but overflow will result due to
// RBD_MAX_BLOCK_NAME_SIZE being too small
librados::Rados rados(m_local_io_ctx);
uint64_t bid = rados.get_instance_id();

utils::create_image(m_local_io_ctx, m_remote_image_ctx, m_local_image_name.c_str(),
bid, m_remote_image_ctx->size, order, m_remote_image_ctx->features,
m_remote_image_ctx->stripe_unit, m_remote_image_ctx->stripe_count,
journal_order, journal_splay_width, journal_pool, m_global_image_id,
m_remote_mirror_uuid, ctx);
}

template <typename I>
Expand Down
15 changes: 15 additions & 0 deletions src/tools/rbd_mirror/image_replayer/Utils.h
Expand Up @@ -17,6 +17,7 @@ namespace utils {

// TODO: free-functions used for mocking until create/clone
// converted to async state machines

template <typename I>
int create_image(librados::IoCtx& io_ctx, I *_image_ctx, const char *imgname,
uint64_t bid, uint64_t size, int order, uint64_t features,
Expand All @@ -31,6 +32,20 @@ int create_image(librados::IoCtx& io_ctx, I *_image_ctx, const char *imgname,
non_primary_global_image_id, primary_mirror_uuid);
}

template <typename I>
void create_image(librados::IoCtx& io_ctx, I *_image_ctx, const char *imgname,
uint64_t bid, uint64_t size, int order, uint64_t features,
uint64_t stripe_unit, uint64_t stripe_count,
uint8_t journal_order, uint8_t journal_splay_width,
const std::string &journal_pool,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid, Context *ctx) {
librbd::create_v2(io_ctx, imgname, bid, size, order, features,
stripe_unit, stripe_count, journal_order,
journal_splay_width, journal_pool,
non_primary_global_image_id, primary_mirror_uuid, ctx);
}

template <typename I>
int clone_image(I *p_imctx, librados::IoCtx& c_ioctx, const char *c_name,
librbd::ImageOptions& c_opts,
Expand Down

0 comments on commit 61b903c

Please sign in to comment.