From 61ad15c73220726714fdcb02d0eeb76ea71219b9 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Sun, 6 Sep 2015 17:06:44 +0300 Subject: [PATCH] librbd: allow alternate pool for journal objects Signed-off-by: Mykola Golub --- src/common/config_opts.h | 1 + src/librbd/ImageCtx.cc | 4 +++- src/librbd/ImageCtx.h | 1 + src/librbd/Journal.cc | 21 +++++++++++++++++---- src/librbd/Journal.h | 3 ++- src/librbd/internal.cc | 6 ++++-- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 7502422d09a8..011732384969 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -1028,6 +1028,7 @@ OPTION(rbd_journal_commit_age, OPT_DOUBLE, 5) // commit time interval, seconds OPTION(rbd_journal_object_flush_interval, OPT_INT, 0) // maximum number of pending commits per journal object OPTION(rbd_journal_object_flush_bytes, OPT_INT, 0) // maximum number of pending bytes per journal object OPTION(rbd_journal_object_flush_age, OPT_DOUBLE, 0) // maximum age (in seconds) for pending commits +OPTION(rbd_journal_pool, OPT_STR, "") // pool for journal objects OPTION(nss_db_path, OPT_STR, "") // path to nss db diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index dab2c6e29b21..5faad48cf539 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -933,7 +933,8 @@ struct C_InvalidateCache : public Context { "rbd_journal_commit_age", false)( "rbd_journal_object_flush_interval", false)( "rbd_journal_object_flush_bytes", false)( - "rbd_journal_object_flush_age", false); + "rbd_journal_object_flush_age", false)( + "rbd_journal_pool", false); string start = METADATA_CONF_PREFIX; int r = 0, j = 0; @@ -1009,6 +1010,7 @@ struct C_InvalidateCache : public Context { ASSIGN_OPTION(journal_object_flush_interval); ASSIGN_OPTION(journal_object_flush_bytes); ASSIGN_OPTION(journal_object_flush_age); + ASSIGN_OPTION(journal_pool); } void ImageCtx::open_journal() { diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index ec7783c5e6c9..d49dadf33473 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -181,6 +181,7 @@ namespace librbd { int journal_object_flush_interval; uint64_t journal_object_flush_bytes; double journal_object_flush_age; + std::string journal_pool; LibrbdAdminSocketHook *asok_hook; diff --git a/src/librbd/Journal.cc b/src/librbd/Journal.cc index 2fb745ce9600..f38bb86af3f0 100644 --- a/src/librbd/Journal.cc +++ b/src/librbd/Journal.cc @@ -91,13 +91,28 @@ bool Journal::is_journal_supported(ImageCtx &image_ctx) { } int Journal::create(librados::IoCtx &io_ctx, const std::string &image_id, - double commit_age, uint8_t order, uint8_t splay_width) { + double commit_age, uint8_t order, uint8_t splay_width, + const std::string &object_pool) { CephContext *cct = reinterpret_cast(io_ctx.cct()); ldout(cct, 5) << __func__ << ": image=" << image_id << dendl; + int64_t pool_id = -1; + if (!object_pool.empty()) { + librados::Rados rados(io_ctx); + IoCtx data_io_ctx; + int r = rados.ioctx_create(object_pool.c_str(), data_io_ctx); + if (r != 0) { + lderr(cct) << "failed to create journal: " + << "error opening journal objects pool '" << object_pool + << "': " << cpp_strerror(r) << dendl; + return r; + } + pool_id = data_io_ctx.get_id(); + } + ::journal::Journaler journaler(io_ctx, image_id, "", commit_age); - int r = journaler.create(order, splay_width, io_ctx.get_id()); + int r = journaler.create(order, splay_width, pool_id); if (r < 0) { lderr(cct) << "failed to create journal: " << cpp_strerror(r) << dendl; return r; @@ -404,11 +419,9 @@ void Journal::create_journaler() { assert(m_state == STATE_UNINITIALIZED); assert(m_journaler == NULL); - // TODO allow alternate pool for journal objects and commit flush interval m_close_pending = false; m_journaler = new ::journal::Journaler(m_image_ctx.md_ctx, m_image_ctx.id, "", m_image_ctx.journal_commit_age); - m_journaler->init(new C_InitJournal(this)); transition_state(STATE_INITIALIZING); } diff --git a/src/librbd/Journal.h b/src/librbd/Journal.h index acbab5baeeec..d694cf418100 100644 --- a/src/librbd/Journal.h +++ b/src/librbd/Journal.h @@ -43,7 +43,8 @@ public: static bool is_journal_supported(ImageCtx &image_ctx); static int create(librados::IoCtx &io_ctx, const std::string &image_id, - double commit_age, uint8_t order, uint8_t splay_width); + double commit_age, uint8_t order, uint8_t splay_width, + const std::string &object_pool); static int remove(librados::IoCtx &io_ctx, const std::string &image_id); bool is_journal_ready() const; diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index d644c4469e97..985b16f24e80 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -1206,7 +1206,8 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type, r = Journal::create(io_ctx, id, cct->_conf->rbd_journal_commit_age, cct->_conf->rbd_journal_order, - cct->_conf->rbd_journal_splay_width); + cct->_conf->rbd_journal_splay_width, + cct->_conf->rbd_journal_pool); if (r < 0) { lderr(cct) << "error creating journal: " << cpp_strerror(r) << dendl; goto err_remove_object_map; @@ -1756,7 +1757,8 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type, features_mask |= RBD_FEATURE_EXCLUSIVE_LOCK; r = Journal::create(ictx->md_ctx, ictx->id, ictx->journal_commit_age, - ictx->journal_order, ictx->journal_splay_width); + ictx->journal_order, ictx->journal_splay_width, + ictx->journal_pool); if (r < 0) { lderr(cct) << "error creating image journal: " << cpp_strerror(r) << dendl; -- 2.47.3