]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: verify the specified namespace before set
authorsongweibin <song.weibin@zte.com.cn>
Tue, 28 Aug 2018 08:41:10 +0000 (16:41 +0800)
committersongweibin <song.weibin@zte.com.cn>
Thu, 30 Aug 2018 10:31:59 +0000 (18:31 +0800)
Signed-off-by: songweibin <song.weibin@zte.com.cn>
src/tools/rbd/Utils.cc

index e436a876ab6aff406593fb3a1b812c5ca5f70b91..722f4ba626159001b39f5e00e29b9e860295bc5e 100644 (file)
@@ -665,6 +665,21 @@ int init_io_ctx(librados::Rados &rados, const std::string &pool_name,
     return r;
   }
 
+  if (!namespace_name.empty()) {
+    librbd::RBD rbd;
+    bool exists = false;
+    r = rbd.namespace_exists(*io_ctx, namespace_name.c_str(), &exists);
+    if (r < 0) {
+      std::cerr << "rbd: error asserting namespace: "
+                << cpp_strerror(r) << std::endl;
+      return r;
+    }
+    if (!exists) {
+      std::cerr << "rbd: namespace '" << namespace_name << "' does not exist."
+                << std::endl;
+      return -ENOENT;
+    }
+  }
   io_ctx->set_namespace(namespace_name);
   return 0;
 }