mirror of
https://github.com/ceph/ceph
synced 2025-02-19 17:08:05 +00:00
Fix handling of CEPH_CONF
Formerly, CEPH_CONF was not respected by libraries. But now it is. It overrides the default when reading the config file. Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
This commit is contained in:
parent
31d49735f7
commit
ca6d239083
@ -221,24 +221,12 @@ bool parse_ip_port_vec(const char *s, vector<entity_addr_t>& vec)
|
||||
}
|
||||
|
||||
// The defaults for CephInitParameters
|
||||
CephInitParameters::CephInitParameters(uint32_t module_type_, const char *conf_file_)
|
||||
: module_type(module_type_),
|
||||
conf_file(conf_file_)
|
||||
CephInitParameters::CephInitParameters(uint32_t module_type_)
|
||||
: module_type(module_type_)
|
||||
{
|
||||
const char *c = getenv("CEPH_CONF");
|
||||
if (c)
|
||||
conf_file = c;
|
||||
name.set(module_type, "admin");
|
||||
}
|
||||
|
||||
std::list<std::string> CephInitParameters::
|
||||
get_conf_files() const
|
||||
{
|
||||
std::list<std::string> ret;
|
||||
get_str_list(conf_file, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void dashes_to_underscores(const char *input, char *output)
|
||||
{
|
||||
char c = 0;
|
||||
@ -330,11 +318,10 @@ bool ceph_argparse_witharg(std::vector<const char*> &args,
|
||||
}
|
||||
|
||||
CephInitParameters ceph_argparse_early_args
|
||||
(std::vector<const char*>& args, uint32_t module_type, int flags)
|
||||
(std::vector<const char*>& args, uint32_t module_type, int flags,
|
||||
std::string *conf_file_list)
|
||||
{
|
||||
const char *conf = (flags & CINIT_FLAG_NO_DEFAULT_CONFIG_FILE) ?
|
||||
"" : CEPH_CONF_FILE_DEFAULT;
|
||||
CephInitParameters iparams(module_type, conf);
|
||||
CephInitParameters iparams(module_type);
|
||||
std::string val;
|
||||
for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
|
||||
if (strcmp(*i, "--") == 0)
|
||||
@ -344,7 +331,7 @@ CephInitParameters ceph_argparse_early_args
|
||||
_exit(0);
|
||||
}
|
||||
else if (ceph_argparse_witharg(args, i, &val, "--conf", "-c", (char*)NULL)) {
|
||||
iparams.conf_file = val;
|
||||
*conf_file_list = val;
|
||||
}
|
||||
else if ((module_type != CEPH_ENTITY_TYPE_CLIENT) &&
|
||||
(ceph_argparse_witharg(args, i, &val, "-i", (char*)NULL))) {
|
||||
|
@ -74,11 +74,10 @@ extern bool ceph_argparse_cmd_equals(const char *cmd, const char *opt,
|
||||
class CephInitParameters
|
||||
{
|
||||
public:
|
||||
CephInitParameters(uint32_t module_type_, const char *conf_file_);
|
||||
CephInitParameters(uint32_t module_type_);
|
||||
std::list<std::string> get_conf_files() const;
|
||||
|
||||
uint32_t module_type;
|
||||
std::string conf_file;
|
||||
EntityName name;
|
||||
};
|
||||
|
||||
@ -98,7 +97,8 @@ bool ceph_argparse_flag(std::vector<const char*> &args,
|
||||
bool ceph_argparse_witharg(std::vector<const char*> &args,
|
||||
std::vector<const char*>::iterator &i, std::string *ret, ...);
|
||||
extern CephInitParameters ceph_argparse_early_args
|
||||
(std::vector<const char*>& args, uint32_t module_type, int flags);
|
||||
(std::vector<const char*>& args, uint32_t module_type, int flags,
|
||||
std::string *conf_file_list);
|
||||
extern void generic_server_usage();
|
||||
extern void generic_client_usage();
|
||||
|
||||
|
@ -490,7 +490,20 @@ remove_observer(md_config_obs_t* observer_)
|
||||
}
|
||||
|
||||
int md_config_t::
|
||||
parse_config_files(const std::list<std::string> &conf_files,
|
||||
parse_config_files(const char *conf_files,
|
||||
std::deque<std::string> *parse_errors)
|
||||
{
|
||||
if (!conf_files) {
|
||||
const char *c = getenv("CEPH_CONF");
|
||||
conf_files = c ? c : CEPH_CONF_FILE_DEFAULT;
|
||||
}
|
||||
std::list<std::string> cfl;
|
||||
get_str_list(conf_files, cfl);
|
||||
return parse_config_files_impl(cfl, parse_errors);
|
||||
}
|
||||
|
||||
int md_config_t::
|
||||
parse_config_files_impl(const std::list<std::string> &conf_files,
|
||||
std::deque<std::string> *parse_errors)
|
||||
{
|
||||
// open new conf
|
||||
|
@ -71,7 +71,7 @@ public:
|
||||
void remove_observer(md_config_obs_t* observer_);
|
||||
|
||||
// Parse a config file
|
||||
int parse_config_files(const std::list<std::string> &conf_files,
|
||||
int parse_config_files(const char *conf_files,
|
||||
std::deque<std::string> *parse_errors);
|
||||
|
||||
// Absorb config settings from the environment
|
||||
@ -114,6 +114,9 @@ public:
|
||||
bool expand_meta(std::string &val) const;
|
||||
|
||||
private:
|
||||
int parse_config_files_impl(const std::list<std::string> &conf_files,
|
||||
std::deque<std::string> *parse_errors);
|
||||
|
||||
// Private function for setting a default for a config option
|
||||
void set_val_from_default(const config_option *opt);
|
||||
|
||||
|
@ -48,20 +48,27 @@ static void output_ceph_version()
|
||||
generic_dout(0) << buf << dendl;
|
||||
}
|
||||
|
||||
static const char* c_str_or_null(const std::string &str)
|
||||
{
|
||||
if (str.empty())
|
||||
return NULL;
|
||||
return str.c_str();
|
||||
}
|
||||
|
||||
void global_init(std::vector < const char* >& args,
|
||||
uint32_t module_type, code_environment_t code_env, int flags)
|
||||
{
|
||||
// You can only call global_init once.
|
||||
assert(!g_ceph_context);
|
||||
|
||||
CephInitParameters iparams =
|
||||
ceph_argparse_early_args(args, module_type, flags);
|
||||
std::string conf_file_list;
|
||||
CephInitParameters iparams = ceph_argparse_early_args(args, module_type, flags,
|
||||
&conf_file_list);
|
||||
CephContext *cct = common_preinit(iparams, code_env, flags);
|
||||
global_init_set_globals(cct);
|
||||
md_config_t *conf = cct->_conf;
|
||||
|
||||
std::deque<std::string> parse_errors;
|
||||
int ret = conf->parse_config_files(iparams.get_conf_files(), &parse_errors);
|
||||
int ret = conf->parse_config_files(c_str_or_null(conf_file_list), &parse_errors);
|
||||
if (ret == -EDOM) {
|
||||
dout_emergency("global_init: error parsing config file.\n");
|
||||
_exit(1);
|
||||
|
@ -49,7 +49,7 @@ void ceph_shutdown(struct ceph_mount_info *cmount);
|
||||
*
|
||||
* Functions for manipulating the Ceph configuration at runtime.
|
||||
*/
|
||||
int ceph_conf_read_file(struct ceph_mount_info *cmount, const char *path);
|
||||
int ceph_conf_read_file(struct ceph_mount_info *cmount, const char *path_list);
|
||||
|
||||
void ceph_conf_parse_argv(struct ceph_mount_info *cmount, int argc, const char **argv);
|
||||
|
||||
|
@ -129,19 +129,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
int conf_read_file(const char *path)
|
||||
int conf_read_file(const char *path_list)
|
||||
{
|
||||
if (!path)
|
||||
path = CEPH_CONF_FILE_DEFAULT;
|
||||
|
||||
std::list<std::string> conf_files;
|
||||
get_str_list(path, conf_files);
|
||||
std::deque<std::string> parse_errors;
|
||||
int ret = cct->_conf->parse_config_files(conf_files, &parse_errors);
|
||||
int ret = cct->_conf->parse_config_files(path_list, &parse_errors);
|
||||
if (ret)
|
||||
return ret;
|
||||
cct->_conf->parse_env(); // environment variables override
|
||||
|
||||
cct->_conf->apply_changes();
|
||||
complain_about_parse_errors(cct, &parse_errors);
|
||||
return 0;
|
||||
@ -222,8 +215,7 @@ extern "C" int ceph_create_with_context(struct ceph_mount_info **cmount, CephCon
|
||||
|
||||
extern "C" int ceph_create(struct ceph_mount_info **cmount, const char * const id)
|
||||
{
|
||||
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT, CEPH_CONF_FILE_DEFAULT);
|
||||
iparams.conf_file = "";
|
||||
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
|
||||
if (id) {
|
||||
iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
|
||||
}
|
||||
|
@ -3159,8 +3159,7 @@ librados::ObjectOperation::~ObjectOperation()
|
||||
///////////////////////////// C API //////////////////////////////
|
||||
extern "C" int rados_create(rados_t *pcluster, const char * const id)
|
||||
{
|
||||
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT, CEPH_CONF_FILE_DEFAULT);
|
||||
iparams.conf_file = "";
|
||||
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
|
||||
if (id) {
|
||||
iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
|
||||
}
|
||||
@ -3210,17 +3209,12 @@ extern "C" void rados_version(int *major, int *minor, int *extra)
|
||||
|
||||
|
||||
// -- config --
|
||||
extern "C" int rados_conf_read_file(rados_t cluster, const char *path)
|
||||
extern "C" int rados_conf_read_file(rados_t cluster, const char *path_list)
|
||||
{
|
||||
if (!path)
|
||||
path = CEPH_CONF_FILE_DEFAULT;
|
||||
|
||||
librados::RadosClient *client = (librados::RadosClient *)cluster;
|
||||
md_config_t *conf = client->cct->_conf;
|
||||
std::list<std::string> conf_files;
|
||||
get_str_list(path, conf_files);
|
||||
std::deque<std::string> parse_errors;
|
||||
int ret = conf->parse_config_files(conf_files, &parse_errors);
|
||||
int ret = conf->parse_config_files(path_list, &parse_errors);
|
||||
if (ret)
|
||||
return ret;
|
||||
conf->parse_env(); // environment variables override
|
||||
|
@ -27,8 +27,7 @@
|
||||
|
||||
int librgw_create(librgw_t *rgw, const char * const id)
|
||||
{
|
||||
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT, CEPH_CONF_FILE_DEFAULT);
|
||||
iparams.conf_file = "";
|
||||
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
|
||||
if (id) {
|
||||
iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
|
||||
}
|
||||
|
@ -463,20 +463,18 @@ TEST(Overrides, ConfUtils) {
|
||||
std::deque<std::string> err;
|
||||
std::string override_conf_1_f(next_tempfile(override_config_1));
|
||||
|
||||
std::list<std::string> conf_files;
|
||||
conf_files.push_back(override_conf_1_f);
|
||||
conf.name.set(CEPH_ENTITY_TYPE_MON, "0");
|
||||
conf.parse_config_files(conf_files, &err);
|
||||
conf.parse_config_files(override_conf_1_f.c_str(), &err);
|
||||
ASSERT_EQ(err.size(), 0U);
|
||||
ASSERT_EQ(conf.log_file, "global_log");
|
||||
|
||||
conf.name.set(CEPH_ENTITY_TYPE_MDS, "a");
|
||||
conf.parse_config_files(conf_files, &err);
|
||||
conf.parse_config_files(override_conf_1_f.c_str(), &err);
|
||||
ASSERT_EQ(err.size(), 0U);
|
||||
ASSERT_EQ(conf.log_file, "mds_log");
|
||||
|
||||
conf.name.set(CEPH_ENTITY_TYPE_OSD, "0");
|
||||
conf.parse_config_files(conf_files, &err);
|
||||
conf.parse_config_files(override_conf_1_f.c_str(), &err);
|
||||
ASSERT_EQ(err.size(), 0U);
|
||||
ASSERT_EQ(conf.log_file, "osd0_log");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user