]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
keyring: print more useful errors to log/err
authorSage Weil <sage@newdream.net>
Thu, 29 Dec 2011 19:58:28 +0000 (11:58 -0800)
committerSage Weil <sage@newdream.net>
Thu, 29 Dec 2011 19:58:28 +0000 (11:58 -0800)
Signed-off-by: Sage Weil <sage@newdream.net>
src/auth/KeyRing.cc
src/auth/KeyRing.h
src/mon/MonClient.cc

index b4542c629647c2b9579d2f05e345ddb6ae05e3bf..45b07e73e518484ddcbb393be153300f59b2d5f1 100644 (file)
@@ -23,6 +23,7 @@
 #include "common/ConfUtils.h"
 #include "common/config.h"
 #include "common/debug.h"
+#include "common/errno.h"
 #include "include/str_list.h"
 
 #define DOUT_SUBSYS auth
@@ -32,7 +33,7 @@
 using std::auto_ptr;
 using namespace std;
 
-KeyRing *KeyRing::from_ceph_context(CephContext *cct)
+int KeyRing::from_ceph_context(CephContext *cct, KeyRing **pkeyring)
 {
   const md_config_t *conf = cct->_conf;
   bool found_key = false;
@@ -42,7 +43,8 @@ KeyRing *KeyRing::from_ceph_context(CephContext *cct)
 
   if (!supported.is_supported_auth(CEPH_AUTH_CEPHX)) {
     ldout(cct, 2) << "KeyRing::from_ceph_context: CephX auth is not supported." << dendl;
-    return keyring.release();
+    *pkeyring = keyring.release();
+    return 0;
   }
 
   int ret = 0;
@@ -51,9 +53,8 @@ KeyRing *KeyRing::from_ceph_context(CephContext *cct)
     ret = keyring->load(cct, filename);
     if (ret) {
       lderr(cct) << "KeyRing::from_ceph_context: failed to load " << filename
-                << ": error " << ret << dendl;
-    }
-    else {
+                << ": " << cpp_strerror(ret) << dendl;
+    } else {
       found_key = true;
     }
   }
@@ -72,7 +73,7 @@ KeyRing *KeyRing::from_ceph_context(CephContext *cct)
       int res = fread(buf, 1, sizeof(buf) - 1, fp);
       if (res < 0) {
        res = ferror(fp);
-       lderr(cct) << "KeyRing::from_ceph_conf: failed to read '" << conf->keyfile
+       lderr(cct) << "KeyRing::from_ceph_context: failed to read '" << conf->keyfile
                   << "'" << dendl;
       }
       else {
@@ -83,12 +84,21 @@ KeyRing *KeyRing::from_ceph_context(CephContext *cct)
        found_key = true;
       }
       fclose(fp);
+    } else {
+      ret = errno;
+      lderr(cct) << "KeyRing::conf_ceph_context: failed to open " << conf->keyfile
+                << ": " << cpp_strerror(ret) << dendl;
     }
   }
 
-  if (!found_key)
-    return NULL;
-  return keyring.release();
+  if (!found_key) {
+    if (conf->keyring.length())
+      lderr(cct) << "failed to open keyring from " << conf->keyring << dendl;
+    return -ENOENT;
+  }
+
+  *pkeyring = keyring.release();
+  return 0;
 }
 
 KeyRing *KeyRing::create_empty()
index 1333009f14db29063b369bf75ad2d6cbb909876c..cfac054b28f8680355a2418b82cc5d42eef4178e 100644 (file)
@@ -30,7 +30,7 @@ class KeyRing {
 public:
   /* Create a KeyRing from a Ceph context.
    * We will use the configuration stored inside the context. */
-  static KeyRing *from_ceph_context(CephContext *cct);
+  static int from_ceph_context(CephContext *cct, KeyRing **pkeyring);
   /* Create an empty KeyRing */
   static KeyRing *create_empty();
 
index 6e89ffce1a2a4e1b18d562405ea1eba0700347f3..1ea49dcdcb34a23b673cb27026bb950e004a50c7 100644 (file)
@@ -356,10 +356,10 @@ int MonClient::init()
 
   messenger->add_dispatcher_head(this);
 
-  keyring = KeyRing::from_ceph_context(cct);
-  if (!keyring) {
-    lderr(cct) << "MonClient::init(): Failed to create keyring" << dendl;
-    return -EDOM;
+  int r = KeyRing::from_ceph_context(cct, &keyring);
+  if (r < 0) {
+    lderr(cct) << "failed to open keyring: " << cpp_strerror(r) << dendl;
+    return r;
   }
   rotating_secrets = new RotatingKeyRing(cct, cct->get_module_type(), keyring);