]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rados: check for pool prior to using io_ctx
authorDavid Disseldorp <ddiss@suse.de>
Mon, 24 Oct 2016 16:51:42 +0000 (18:51 +0200)
committerDavid Disseldorp <ddiss@suse.de>
Tue, 25 Oct 2016 11:19:55 +0000 (13:19 +0200)
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 <ddiss@suse.de>
src/tools/rados/rados.cc

index 4ae230fe65aaa5b7fc1edf6b08b2474ce6c99ae4..5857f74662ca152de732cd0c6d265cb557173fe1 100644 (file)
@@ -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) {