]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: removed hardcoded default rbd pool name 15518/head
authorJason Dillaman <dillaman@redhat.com>
Tue, 6 Jun 2017 17:24:54 +0000 (13:24 -0400)
committerJason Dillaman <dillaman@redhat.com>
Wed, 7 Jun 2017 20:26:25 +0000 (16:26 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/tools/rbd/ArgumentTypes.h
src/tools/rbd/Utils.cc
src/tools/rbd/Utils.h
src/tools/rbd/action/Kernel.cc
src/tools/rbd/rbd.cc

index f8a2cd1d8edb9472232bfdfd58755a51e4638b29..1f7da09764342ee351fb55146ae3547dbe883b13 100644 (file)
@@ -29,8 +29,6 @@ enum SpecFormat {
   SPEC_FORMAT_IMAGE_OR_SNAPSHOT
 };
 
-static const std::string DEFAULT_POOL_NAME("rbd");
-
 static const std::string SOURCE_PREFIX("source-");
 static const std::string DEST_PREFIX("dest-");
 
index a802a77cb8b6c00161b80adf6fe67552c2f0effb..db248e34a1b723072c71abefb9426bb413d102cf 100644 (file)
@@ -167,7 +167,6 @@ int extract_image_id_spec(const std::string &spec, std::string *pool_name,
   }
 
   return 0;
 }
 
 std::string get_positional_argument(const po::variables_map &vm, size_t index) {
@@ -184,8 +183,11 @@ std::string get_positional_argument(const po::variables_map &vm, size_t index) {
   return "";
 }
 
-std::string get_pool_name(const po::variables_map &vm,
-                          size_t *arg_index) {
+std::string get_default_pool_name() {
+  return g_ceph_context->_conf->rbd_default_pool;
+}
+
+std::string get_pool_name(const po::variables_map &vm, size_t *arg_index) {
   std::string pool_name;
   if (vm.count(at::POOL_NAME)) {
     pool_name = vm[at::POOL_NAME].as<std::string>();
@@ -197,7 +199,7 @@ std::string get_pool_name(const po::variables_map &vm,
   }
 
   if (pool_name.empty()) {
-    pool_name = at::DEFAULT_POOL_NAME;
+    pool_name = get_default_pool_name();
   }
   return pool_name;
 }
@@ -237,7 +239,7 @@ int get_special_pool_group_names(const po::variables_map &vm,
   }
 
   if (group_pool_name->empty()) {
-    *group_pool_name = at::DEFAULT_POOL_NAME;
+    *group_pool_name = get_default_pool_name();
   }
 
   if (group_name->empty()) {
@@ -286,7 +288,7 @@ int get_special_pool_image_names(const po::variables_map &vm,
   }
 
   if (image_pool_name->empty()) {
-    *image_pool_name = at::DEFAULT_POOL_NAME;
+    *image_pool_name = get_default_pool_name();
   }
 
   if (image_name->empty()) {
@@ -320,8 +322,8 @@ int get_pool_image_id(const po::variables_map &vm,
     }
   }
 
-  if (pool_name->empty()) {
-    *pool_name = at::DEFAULT_POOL_NAME;
+  if (pool_name != nullptr && pool_name->empty()) {
+    *pool_name = get_default_pool_name();
   }
 
   if (image_id != nullptr && image_id->empty()) {
@@ -361,8 +363,8 @@ int get_pool_group_names(const po::variables_map &vm,
     }
   }
 
-  if (pool_name->empty()) {
-    *pool_name = at::DEFAULT_POOL_NAME;
+  if (pool_name != nullptr && pool_name->empty()) {
+    *pool_name = get_default_pool_name();
   }
 
   if (group_name != nullptr && group_name->empty()) {
@@ -426,7 +428,7 @@ int get_pool_image_snapshot_names(const po::variables_map &vm,
   }
 
   if (pool_name != nullptr && pool_name->empty()) {
-    *pool_name = at::DEFAULT_POOL_NAME;
+    *pool_name = get_default_pool_name();
   }
 
   if (image_name != nullptr && image_required && image_name->empty()) {
@@ -437,11 +439,11 @@ int get_pool_image_snapshot_names(const po::variables_map &vm,
     return -EINVAL;
   }
 
-  //Validate pool name while creating/renaming/copying/cloning/importing/etc image
+  //Validate pool name while creating/renaming/copying/cloning/importing/etc
   if (spec_validation == SPEC_VALIDATION_FULL) {
-    boost::regex pattern("^[^@/]*?$");
+    boost::regex pattern("^[^@/]+?$");
     if (!boost::regex_match (*pool_name, pattern)) {
-      std::cerr << "rbd: invalid spec '" << *pool_name << "'" << std::endl;
+      std::cerr << "rbd: invalid pool name '" << *pool_name << "'" << std::endl;
       return -EINVAL;
     }
   }
@@ -476,7 +478,7 @@ int get_pool_snapshot_names(const po::variables_map &vm,
   }
 
   if (pool_name != nullptr && pool_name->empty()) {
-    *pool_name = at::DEFAULT_POOL_NAME;
+    *pool_name = get_default_pool_name();
   }
 
   if (snap_name != nullptr) {
@@ -549,7 +551,7 @@ int get_pool_journal_names(const po::variables_map &vm,
   }
 
   if (pool_name != nullptr && pool_name->empty()) {
-    *pool_name = at::DEFAULT_POOL_NAME;
+    *pool_name = get_default_pool_name();
   }
 
   if (pool_name != nullptr && journal_name != nullptr &&
@@ -621,7 +623,7 @@ int validate_snapshot_name(at::ArgumentModifier mod,
     // disallow "/" and "@" in snap name
     boost::regex pattern("^[^@/]*?$");
     if (!boost::regex_match (snap_name, pattern)) {
-      std::cerr << "rbd: invalid spec '" << snap_name << "'" << std::endl;
+      std::cerr << "rbd: invalid snap name '" << snap_name << "'" << std::endl;
       return -EINVAL;
     }
   }
@@ -867,8 +869,15 @@ int init_io_ctx(librados::Rados &rados, const std::string &pool_name,
                 librados::IoCtx *io_ctx) {
   int r = rados.ioctx_create(pool_name.c_str(), *io_ctx);
   if (r < 0) {
-    std::cerr << "rbd: error opening pool " << pool_name << ": "
-              << cpp_strerror(r) << std::endl;
+    if (r == -ENOENT && pool_name == get_default_pool_name()) {
+      std::cerr << "rbd: error opening default pool "
+                << "'" << pool_name << "'" << std::endl
+                << "Ensure that the default pool has been created or specify "
+                << "an alternate pool name." << std::endl;
+    } else {
+      std::cerr << "rbd: error opening pool '" << pool_name << "': "
+                << cpp_strerror(r) << std::endl;
+    }
     return r;
   }
   return 0;
index 943153e25726625a301719d88b1e0fdb9dfa419c..d60a7b3e2cb67e2589cc14d611b72b30cdd58efb 100644 (file)
@@ -102,6 +102,7 @@ int extract_image_id_spec(const std::string &spec, std::string *pool_name,
 std::string get_positional_argument(
     const boost::program_options::variables_map &vm, size_t index);
 
+std::string get_default_pool_name();
 std::string get_pool_name(const boost::program_options::variables_map &vm,
                           size_t *arg_index);
 
index 336dd597d86b01c90f3bd9239b3ec0b6cb76b7ad..1f1951fc8842539b269ca3d2b00d80d4bff87623 100644 (file)
@@ -259,8 +259,10 @@ static void print_error_description(const char *poolname, const char *imgname,
       } else {
         std::cout << "You can disable features unsupported by the kernel "
                   << "with \"rbd feature disable ";
-        if (poolname != at::DEFAULT_POOL_NAME)
+
+        if (poolname != utils::get_default_pool_name()) {
           std::cout << poolname << "/";
+        }
         std::cout << imgname;
       }
     } else {
index c81faf83696f59cf077d884839cc574bc3ac5657..6f24eec8fdebb488a821362b9b60954d82e02379 100644 (file)
@@ -14,7 +14,7 @@ int main(int argc, const char **argv)
   env_to_vec(args);
 
   auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
-                            CODE_ENVIRONMENT_UTILITY, 0);
+                         CODE_ENVIRONMENT_UTILITY, 0);
 
   rbd::Shell shell;
   return shell.execute(args);