From: Sage Weil Date: Thu, 29 Dec 2011 19:58:28 +0000 (-0800) Subject: keyring: print more useful errors to log/err X-Git-Tag: v0.40~101 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3b2ca7cf9bce654c0e478dbeeba5875537e3ced2;p=ceph.git keyring: print more useful errors to log/err Signed-off-by: Sage Weil --- diff --git a/src/auth/KeyRing.cc b/src/auth/KeyRing.cc index b4542c629647..45b07e73e518 100644 --- a/src/auth/KeyRing.cc +++ b/src/auth/KeyRing.cc @@ -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() diff --git a/src/auth/KeyRing.h b/src/auth/KeyRing.h index 1333009f14db..cfac054b28f8 100644 --- a/src/auth/KeyRing.h +++ b/src/auth/KeyRing.h @@ -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(); diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index 6e89ffce1a2a..1ea49dcdcb34 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -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);