From: David Disseldorp Date: Mon, 24 Oct 2016 16:51:42 +0000 (+0200) Subject: rados: check for pool prior to using io_ctx X-Git-Tag: v11.1.0~352^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7cacbe5eb883c00fa4d75292e3429c753f4551e0;p=ceph.git rados: check for pool prior to using io_ctx The rados --snap[id], --object_locator and --namespace parameters all require a valid io_ctx to process the corresponding argument. The io_ctx is initialised with a valid --pool parameter, so check for this before handling any of the above dependent parameters. Fixes: http://tracker.ceph.com/issues/17684 Signed-off-by: David Disseldorp --- diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index 4ae230fe65aa..5857f74662ca 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -1879,6 +1879,11 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, // snapname? if (snapname) { + if (!pool_name) { + cerr << "pool name must be specified with --snap" << std::endl; + ret = -1; + goto out; + } ret = io_ctx.snap_lookup(snapname, &snapid); if (ret < 0) { cerr << "error looking up snap '" << snapname << "': " << cpp_strerror(ret) << std::endl; @@ -1886,10 +1891,20 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, } } if (oloc.size()) { + if (!pool_name) { + cerr << "pool name must be specified with --object_locator" << std::endl; + ret = -1; + goto out; + } io_ctx.locator_set_key(oloc); } // Use namespace from command line if specified if (opts.find("namespace") != opts.end()) { + if (!pool_name) { + cerr << "pool name must be specified with --namespace" << std::endl; + ret = -1; + goto out; + } io_ctx.set_namespace(nspace); // Use wildcard if --all specified and --default NOT specified } else if (opts.find("all") != opts.end() && opts.find("default") == opts.end()) { @@ -1897,6 +1912,11 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, wildcard = true; } if (snapid != CEPH_NOSNAP) { + if (!pool_name) { + cerr << "pool name must be specified with --snapid" << std::endl; + ret = -1; + goto out; + } string name; ret = io_ctx.snap_get_name(snapid, &name); if (ret < 0) {