Skip to content

Commit 1ba9a32

Browse files
committed
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 <[email protected]>
1 parent f172fb9 commit 1ba9a32

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/librbd/migration/NativeFormat.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,12 @@ void NativeFormat<I>::open(Context* on_finish) {
6565
auto& pool_name_val = m_json_object[POOL_NAME_KEY];
6666
if (pool_name_val.type() == json_spirit::str_type) {
6767
librados::Rados rados(m_image_ctx->md_ctx);
68-
librados::IoCtx io_ctx;
69-
int r = rados.ioctx_create(pool_name_val.get_str().c_str(), io_ctx);
70-
if (r < 0 ) {
71-
lderr(cct) << "invalid pool name" << dendl;
72-
on_finish->complete(r);
68+
m_pool_id = rados.pool_lookup(pool_name_val.get_str().c_str());
69+
if (m_pool_id < 0) {
70+
lderr(cct) << "failed to lookup pool" << dendl;
71+
on_finish->complete(static_cast<int>(m_pool_id));
7372
return;
7473
}
75-
76-
m_pool_id = io_ctx.get_id();
7774
} else if (pool_name_val.type() != json_spirit::null_type) {
7875
lderr(cct) << "invalid pool name" << dendl;
7976
on_finish->complete(-EINVAL);

0 commit comments

Comments
 (0)