From 98a2e5c59daa87d21affcc6513c469cd180fbb9d Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 4 Mar 2015 13:18:23 +0800 Subject: [PATCH] rados: translate errno to str in CLI * and print detailed error message when monmap or keyring fails to load from specified file. Fixes: #10877 Signed-off-by: Kefu Chai --- src/auth/KeyRing.cc | 8 +++++--- src/common/config.cc | 14 ++++++++------ src/common/config.h | 4 ++-- src/mon/Monitor.cc | 7 +++++-- src/tools/ceph_conf.cc | 3 ++- src/tools/rados/rados.cc | 4 ++-- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/auth/KeyRing.cc b/src/auth/KeyRing.cc index 7aeb9e833a0..63f2ccdb9c2 100644 --- a/src/auth/KeyRing.cc +++ b/src/auth/KeyRing.cc @@ -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()) { diff --git a/src/common/config.cc b/src/common/config.cc index fda0c2226d9..1efc1555608 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -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 ls; get_str_list(filename_list, ls); + int ret = -ENOENT; list::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() diff --git a/src/common/config.h b/src/common/config.h index d4a84becca8..41c999d73d0 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -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; diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index c1686b02c80..4b897ea0b41 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -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"; diff --git a/src/tools/ceph_conf.cc b/src/tools/ceph_conf.cc index 30e40ab9a91..0d0b85c8969 100644 --- a/src/tools/ceph_conf.cc +++ b/src/tools/ceph_conf.cc @@ -121,7 +121,8 @@ static int lookup(const std::deque §ions, 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 { diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index 4b96ac5ae4a..d1fde7ad61a 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -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; } -- 2.47.3