From 7e6a2afe235f3ed7a390b398ea07a5d4433ee460 Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Wed, 17 Jul 2024 20:05:08 +0200 Subject: [PATCH] librbd/migration/NativeFormat: do pool lookup instead of creating io_ctx A Rados instance is sufficient to map the pool name to the pool ID, no need to involve an IoCtx instance as well. While at it, report distinctive errors for a non-existing pool and an invalid JSON value for pool_name key cases. Signed-off-by: Ilya Dryomov (cherry picked from commit 1ba9a32598f50073b574b4649736d76b678a1c58) --- src/librbd/migration/NativeFormat.cc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/librbd/migration/NativeFormat.cc b/src/librbd/migration/NativeFormat.cc index a7682619c1908..600c16c137194 100644 --- a/src/librbd/migration/NativeFormat.cc +++ b/src/librbd/migration/NativeFormat.cc @@ -65,15 +65,12 @@ void NativeFormat::open(Context* on_finish) { auto& pool_name_val = m_json_object[POOL_NAME_KEY]; if (pool_name_val.type() == json_spirit::str_type) { librados::Rados rados(m_image_ctx->md_ctx); - librados::IoCtx io_ctx; - int r = rados.ioctx_create(pool_name_val.get_str().c_str(), io_ctx); - if (r < 0 ) { - lderr(cct) << "invalid pool name" << dendl; - on_finish->complete(r); + m_pool_id = rados.pool_lookup(pool_name_val.get_str().c_str()); + if (m_pool_id < 0) { + lderr(cct) << "failed to lookup pool" << dendl; + on_finish->complete(static_cast(m_pool_id)); return; } - - m_pool_id = io_ctx.get_id(); } else if (pool_name_val.type() != json_spirit::null_type) { lderr(cct) << "invalid pool name" << dendl; on_finish->complete(-EINVAL); -- 2.39.5