From: Vikhyat Umrao Date: Mon, 16 Sep 2019 19:59:56 +0000 (-0700) Subject: tools/rados: call pool_lookup() after rados is connected X-Git-Tag: v12.2.13~97^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3bfea34393a8ecc694146a78fd0fad1e443a5065;p=ceph.git 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) Conflicts: src/tools/rados/rados.cc - no return 1. --- diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index f39987f07be8..106ab568aceb 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -1939,14 +1939,6 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, } } - i = opts.find("pgid"); - boost::optional pgid(i != opts.end(), std::move(pg_t())); - if (pgid && (!pgid->parse(i->second.c_str()) || (pool_name && rados.pool_lookup(pool_name) != pgid->pool()))) { - cerr << "invalid pgid" << std::endl; - ret = -1; - goto out; - } - // open rados ret = rados.init_with_context(g_ceph_context); if (ret < 0) { @@ -1975,6 +1967,14 @@ 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; + ret = -1; + goto out; + } + // open io context. if (pool_name || pgid) { ret = pool_name ? rados.ioctx_create(pool_name, io_ctx) : rados.ioctx_create2(pgid->pool(), io_ctx);