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