From: Ilya Dryomov Date: Wed, 17 Jul 2024 18:05:08 +0000 (+0200) Subject: librbd/migration/NativeFormat: do pool lookup instead of creating io_ctx X-Git-Tag: v20.0.0~1358^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1ba9a32598f50073b574b4649736d76b678a1c58;p=ceph.git 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 --- diff --git a/src/librbd/migration/NativeFormat.cc b/src/librbd/migration/NativeFormat.cc index 51248b95e26e..a1810af4a1a4 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);