]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rados: translate errno to str in CLI 3873/head
authorKefu Chai <kchai@redhat.com>
Wed, 4 Mar 2015 05:18:23 +0000 (13:18 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 4 Mar 2015 19:03:02 +0000 (03:03 +0800)
* and print detailed error message when monmap or keyring fails to
  load from specified file.

Fixes: #10877
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/auth/KeyRing.cc
src/common/config.cc
src/common/config.h
src/mon/Monitor.cc
src/tools/ceph_conf.cc
src/tools/rados/rados.cc

index 7aeb9e833a06f4bf8a558ba689f0305310ce2b9d..63f2ccdb9c2e2bcba5261a60a09322469409c2b0 100644 (file)
@@ -39,15 +39,17 @@ using namespace std;
 int KeyRing::from_ceph_context(CephContext *cct)
 {
   const md_config_t *conf = cct->_conf;
-
-  int ret = -ENOENT;
   string filename;
 
-  if (ceph_resolve_file_search(conf->keyring, filename)) {
+  int ret = ceph_resolve_file_search(conf->keyring, filename);
+  if (!ret) {
     ret = load(cct, filename);
     if (ret < 0)
       lderr(cct) << "failed to load " << filename
                 << ": " << cpp_strerror(ret) << dendl;
+  } else {
+    lderr(cct) << "unable to find a keyring on " << conf->keyring
+              << ": " << cpp_strerror(ret) << dendl;
   }
 
   if (!conf->key.empty()) {
index fda0c2226d928fe90ddfdf8a2dc931f1e4c20512..1efc15556084ea1c1125aef2c1485c69ebe79252 100644 (file)
@@ -98,24 +98,26 @@ struct config_option config_optionsp[] = {
 
 const int NUM_CONFIG_OPTIONS = sizeof(config_optionsp) / sizeof(config_option);
 
-bool ceph_resolve_file_search(const std::string& filename_list,
-                             std::string& result)
+int ceph_resolve_file_search(const std::string& filename_list,
+                            std::string& result)
 {
   list<string> ls;
   get_str_list(filename_list, ls);
 
+  int ret = -ENOENT;
   list<string>::iterator iter;
   for (iter = ls.begin(); iter != ls.end(); ++iter) {
     int fd = ::open(iter->c_str(), O_RDONLY);
-    if (fd < 0)
+    if (fd < 0) {
+      ret = -errno;
       continue;
-
+    }
     close(fd);
     result = *iter;
-    return true;
+    return 0;
   }
 
-  return false;
+  return ret;
 }
 
 md_config_t::md_config_t()
index d4a84becca8684e4da7725be4e6a090d2220a240..41c999d73d0339b650a8f8efb3266d41ad48cd37 100644 (file)
@@ -255,8 +255,8 @@ typedef enum {
        OPT_ADDR, OPT_U32, OPT_U64, OPT_UUID
 } opt_type_t;
 
-bool ceph_resolve_file_search(const std::string& filename_list,
-                             std::string& result);
+int ceph_resolve_file_search(const std::string& filename_list,
+                            std::string& result);
 
 struct config_option {
   const char *name;
index c1686b02c80c4cda6b1ca0101f273a14e81b9134..4b897ea0b411c3b555fcc753b2e0d5f3b6c73b37 100644 (file)
@@ -4497,8 +4497,11 @@ int Monitor::mkfs(bufferlist& osdmapbl)
   if (is_keyring_required()) {
     KeyRing keyring;
     string keyring_filename;
-    if (!ceph_resolve_file_search(g_conf->keyring, keyring_filename)) {
-      derr << "unable to find a keyring file on " << g_conf->keyring << dendl;
+
+    r = ceph_resolve_file_search(g_conf->keyring, keyring_filename);
+    if (r) {
+      derr << "unable to find a keyring file on " << g_conf->keyring
+          << ": " << cpp_strerror(r) << dendl;
       if (g_conf->key != "") {
        string keyring_plaintext = "[mon.]\n\tkey = " + g_conf->key +
          "\n\tcaps mon = \"allow *\"\n";
index 30e40ab9a91da23efb06bfe96a71fc9f6abb7a8e..0d0b85c8969c7994faaab68a172633face085958 100644 (file)
@@ -121,7 +121,8 @@ static int lookup(const std::deque<std::string> &sections,
   else if (ret == 0) {
     if (resolve_search) {
       string result;
-      if (ceph_resolve_file_search(val, result))
+      ret = ceph_resolve_file_search(val, result);
+      if (!ret)
        puts(result.c_str());
     }
     else {
index 4b96ac5ae4a1063d849f2b2bfb4ba5807cb9733a..d1fde7ad61a58c1afd4027f3dd63fdb363cb85d1 100644 (file)
@@ -1316,14 +1316,14 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
   // open rados
   ret = rados.init_with_context(g_ceph_context);
   if (ret) {
-     cerr << "couldn't initialize rados! error " << ret << std::endl;
+     cerr << "couldn't initialize rados: " << cpp_strerror(ret) << std::endl;
      ret = -1;
      goto out;
   }
 
   ret = rados.connect();
   if (ret) {
-     cerr << "couldn't connect to cluster! error " << ret << std::endl;
+     cerr << "couldn't connect to cluster: " << cpp_strerror(ret) << std::endl;
      ret = -1;
      goto out;
   }