From 9997eabe6d3a06fa1fc054f2dbf6e8fe6fb3d22c Mon Sep 17 00:00:00 2001 From: Vikhyat Umrao Date: Mon, 16 Sep 2019 12:59:56 -0700 Subject: [PATCH] tools/rados: call pool_lookup() after rados is connected This commit fixes a segmentation fault when using --pgid option in rados ls command in combination with --pool/-p option. The reason for the crash was that we can not use the rados object before connecting it with the cluster using rados.init_with_context(). Fixes: https://tracker.ceph.com/issues/41875 Signed-off-by: Vikhyat Umrao (cherry picked from commit 56b6dd9bd7a50371062128122e6a899f2c79c5f5) --- src/tools/rados/rados.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index 37c6d3352e0d6..f752e3c8975fa 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -2106,13 +2106,6 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, with_reference = true; } - i = opts.find("pgid"); - boost::optional pgid(i != opts.end(), pg_t()); - if (pgid && (!pgid->parse(i->second.c_str()) || (pool_name && rados.pool_lookup(pool_name) != pgid->pool()))) { - cerr << "invalid pgid" << std::endl; - return 1; - } - // open rados ret = rados.init_with_context(g_ceph_context); if (ret < 0) { @@ -2141,6 +2134,13 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, } } + i = opts.find("pgid"); + boost::optional pgid(i != opts.end(), pg_t()); + if (pgid && (!pgid->parse(i->second.c_str()) || (pool_name && rados.pool_lookup(pool_name) != pgid->pool()))) { + cerr << "invalid pgid" << std::endl; + return 1; + } + // open io context. if (pool_name || pgid) { ret = pool_name ? rados.ioctx_create(pool_name, io_ctx) : rados.ioctx_create2(pgid->pool(), io_ctx); -- 2.39.5