Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: Better handling for missing/inaccessible ceph.conf files #14757

Merged
merged 9 commits into from Apr 25, 2017
2 changes: 1 addition & 1 deletion src/ceph.in
Expand Up @@ -704,7 +704,7 @@ def main():
conffile=conffile)
retargs = run_in_thread(cluster_handle.conf_parse_argv, childargs)
except rados.Error as e:
print('Error initializing cluster client: {0}'.format(e), file=sys.stderr)
print('Error initializing cluster client: {0!r}'.format(e), file=sys.stderr)
return 1

childargs = retargs
Expand Down
11 changes: 7 additions & 4 deletions src/common/ConfUtils.cc
Expand Up @@ -101,6 +101,9 @@ parse_file(const std::string &fname, std::deque<std::string> *errors,
char *buf = NULL;
FILE *fp = fopen(fname.c_str(), "r");
if (!fp) {
ostringstream oss;
oss << "parse_file: cannot open " << fname << ": " << cpp_strerror(errno);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to use __func__ here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could. would save a little data space.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

errors->push_back(oss.str());
ret = -errno;
return ret;
}
Expand All @@ -109,14 +112,14 @@ parse_file(const std::string &fname, std::deque<std::string> *errors,
if (fstat(fileno(fp), &st_buf)) {
ret = -errno;
ostringstream oss;
oss << "read_conf: failed to fstat '" << fname << "': " << cpp_strerror(ret);
oss << "parse_file: failed to fstat '" << fname << "': " << cpp_strerror(ret);
errors->push_back(oss.str());
goto done;
}

if (st_buf.st_size > MAX_CONFIG_FILE_SZ) {
ostringstream oss;
oss << "read_conf: config file '" << fname << "' is " << st_buf.st_size
oss << "parse_file: config file '" << fname << "' is " << st_buf.st_size
<< " bytes, but the maximum is " << MAX_CONFIG_FILE_SZ;
errors->push_back(oss.str());
ret = -EINVAL;
Expand All @@ -134,14 +137,14 @@ parse_file(const std::string &fname, std::deque<std::string> *errors,
if (ferror(fp)) {
ret = -errno;
ostringstream oss;
oss << "read_conf: fread error while reading '" << fname << "': "
oss << "parse_file: fread error while reading '" << fname << "': "
<< cpp_strerror(ret);
errors->push_back(oss.str());
goto done;
}
else {
ostringstream oss;
oss << "read_conf: unexpected EOF while reading '" << fname << "': "
oss << "parse_file: unexpected EOF while reading '" << fname << "': "
<< "possible concurrent modification?";
errors->push_back(oss.str());
ret = -EIO;
Expand Down
3 changes: 2 additions & 1 deletion src/common/config.cc
Expand Up @@ -302,8 +302,9 @@ int md_config_t::parse_config_files_impl(const std::list<std::string> &conf_file
else if (ret != -ENOENT)
return ret;
}
// it must have been all ENOENTs, that's the only way we got here
if (c == conf_files.end())
return -EINVAL;
return -ENOENT;

if (cluster.size() == 0) {
/*
Expand Down
6 changes: 5 additions & 1 deletion src/librados/librados.cc
Expand Up @@ -2820,8 +2820,12 @@ extern "C" int rados_conf_read_file(rados_t cluster, const char *path_list)
tracepoint(librados, rados_conf_read_file_enter, cluster, path_list);
librados::RadosClient *client = (librados::RadosClient *)cluster;
md_config_t *conf = client->cct->_conf;
int ret = conf->parse_config_files(path_list, NULL, 0);
ostringstream warnings;
int ret = conf->parse_config_files(path_list, &warnings, 0);
if (ret) {
if (warnings.str().length())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use "warnings.tellp() > 0" to avoid the string copy here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose. I did a quick scan and missed that. Is it idiomatic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

lderr(client->cct) << warnings.str() << dendl;
client->cct->_conf->complain_about_parse_errors(client->cct);
tracepoint(librados, rados_conf_read_file_exit, ret);
return ret;
}
Expand Down
8 changes: 5 additions & 3 deletions src/pybind/rados/rados.pyx
Expand Up @@ -301,7 +301,7 @@ class Error(Exception):
""" `Error` class, derived from `Exception` """


class InvalidArgument(Error):
class InvalidArgumentError(Error):
pass


Expand Down Expand Up @@ -388,7 +388,8 @@ IF UNAME_SYSNAME == "FreeBSD":
errno.ENOATTR : NoData,
errno.EINTR : InterruptedOrTimeoutError,
errno.ETIMEDOUT : TimedOut,
errno.EACCES : PermissionDeniedError
errno.EACCES : PermissionDeniedError,
errno.EINVAL : InvalidArgumentError,
}
ELSE:
cdef errno_to_exception = {
Expand All @@ -401,7 +402,8 @@ ELSE:
errno.ENODATA : NoData,
errno.EINTR : InterruptedOrTimeoutError,
errno.ETIMEDOUT : TimedOut,
errno.EACCES : PermissionDeniedError
errno.EACCES : PermissionDeniedError,
errno.EINVAL : InvalidArgumentError,
}


Expand Down