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()) {
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()
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;
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";
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 {
// 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;
}