From: Sage Weil Date: Tue, 26 Jan 2016 14:18:37 +0000 (-0500) Subject: global: add data_dir_option for all daemons X-Git-Tag: v10.0.4~29^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3944d560e490e9c7e03cedc4b8cad97a1f1f09d6;p=ceph.git global: add data_dir_option for all daemons This let's us use a generic $data_dir substitution that will map to rgw_data, osd_data, etc. Signed-off-by: Sage Weil --- diff --git a/src/ceph_mds.cc b/src/ceph_mds.cc index 0da51bffa8e5..08eee5e03135 100644 --- a/src/ceph_mds.cc +++ b/src/ceph_mds.cc @@ -93,7 +93,8 @@ int main(int argc, const char **argv) argv_to_vec(argc, argv, args); env_to_vec(args); - global_init(NULL, args, CEPH_ENTITY_TYPE_MDS, CODE_ENVIRONMENT_DAEMON, 0); + global_init(NULL, args, CEPH_ENTITY_TYPE_MDS, CODE_ENVIRONMENT_DAEMON, + 0, "mds_data"); ceph_heap_profiler_init(); // mds specific args diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index f15474c5e557..79d9e372751b 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -258,7 +258,7 @@ int main(int argc, const char **argv) } global_init(&def_args, args, - CEPH_ENTITY_TYPE_MON, CODE_ENVIRONMENT_DAEMON, flags); + CEPH_ENTITY_TYPE_MON, CODE_ENVIRONMENT_DAEMON, flags, "mon_data"); ceph_heap_profiler_init(); uuid_d fsid; diff --git a/src/ceph_osd.cc b/src/ceph_osd.cc index 6c5b7f1835f1..c648e2747c4e 100644 --- a/src/ceph_osd.cc +++ b/src/ceph_osd.cc @@ -118,7 +118,8 @@ int main(int argc, const char **argv) // option, therefore we will pass it as a default argument to global_init(). def_args.push_back("--leveldb-log="); - global_init(&def_args, args, CEPH_ENTITY_TYPE_OSD, CODE_ENVIRONMENT_DAEMON, 0); + global_init(&def_args, args, CEPH_ENTITY_TYPE_OSD, CODE_ENVIRONMENT_DAEMON, + 0, "osd_data"); ceph_heap_profiler_init(); // osd specific args diff --git a/src/common/common_init.cc b/src/common/common_init.cc index 3303a7a1f104..b1f716557564 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -34,7 +34,8 @@ #define STRINGIFY(x) _STR(x) CephContext *common_preinit(const CephInitParameters &iparams, - enum code_environment_t code_env, int flags) + enum code_environment_t code_env, int flags, + const char *data_dir_option) { // set code environment ANNOTATE_BENIGN_RACE_SIZED(&g_code_env, sizeof(g_code_env), "g_code_env"); @@ -49,6 +50,9 @@ CephContext *common_preinit(const CephInitParameters &iparams, // Set up our entity name. conf->name = iparams.name; + if (data_dir_option) + conf->data_dir_option = data_dir_option; + // Set some defaults based on code type switch (code_env) { case CODE_ENVIRONMENT_DAEMON: diff --git a/src/common/common_init.h b/src/common/common_init.h index f48b349bf001..6d11ef3177f1 100644 --- a/src/common/common_init.h +++ b/src/common/common_init.h @@ -57,7 +57,8 @@ enum common_init_flags_t { * Your library may also supply functions to read a configuration file. */ CephContext *common_preinit(const CephInitParameters &iparams, - enum code_environment_t code_env, int flags); + enum code_environment_t code_env, int flags, + const char *data_dir_option = 0); /* Print out some parse errors. */ void complain_about_parse_errors(CephContext *cct, diff --git a/src/common/config.cc b/src/common/config.cc index 37758d4d2047..27858a258a37 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -987,8 +987,10 @@ int md_config_t::set_val_raw(const char *val, const config_option *opt) return -ENOSYS; } -static const char *CONF_METAVARIABLES[] = - { "cluster", "type", "name", "host", "num", "id", "pid", "cctid" }; +static const char *CONF_METAVARIABLES[] = { + "data_dir", // put this first: it may contain some of the others + "cluster", "type", "name", "host", "num", "id", "pid", "cctid" +}; static const int NUM_CONF_METAVARIABLES = (sizeof(CONF_METAVARIABLES) / sizeof(CONF_METAVARIABLES[0])); @@ -1102,7 +1104,20 @@ bool md_config_t::expand_meta(std::string &origval, out += stringify(getpid()); else if (var == "cctid") out += stringify((unsigned long long)this); - else + else if (var == "data_dir") { + if (data_dir_option.length()) { + char *vv = NULL; + _get_val(data_dir_option.c_str(), &vv, -1); + string tmp = vv; + free(vv); + expand_meta(tmp, NULL, stack, oss); + out += tmp; + } else { + // this isn't really right, but it'll result in a mangled + // non-existent path that will fail any search list + out += "$data_dir"; + } + } else assert(0); // unreachable expanded = true; } diff --git a/src/common/config.h b/src/common/config.h index 262dc7153bae..79c443786cf8 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -205,6 +205,7 @@ public: ceph::log::SubsystemMap subsys; EntityName name; + string data_dir_option; ///< data_dir config option, if any /// cluster name string cluster; diff --git a/src/global/global_init.cc b/src/global/global_init.cc index f65d6acc03f3..27bdbc7954d2 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -62,7 +62,8 @@ static const char* c_str_or_null(const std::string &str) void global_pre_init(std::vector < const char * > *alt_def_args, std::vector < const char* >& args, uint32_t module_type, code_environment_t code_env, - int flags) + int flags, + const char *data_dir_option) { // You can only call global_init once. assert(!g_ceph_context); @@ -70,7 +71,7 @@ void global_pre_init(std::vector < const char * > *alt_def_args, std::string cluster = "ceph"; CephInitParameters iparams = ceph_argparse_early_args(args, module_type, flags, &cluster, &conf_file_list); - CephContext *cct = common_preinit(iparams, code_env, flags); + CephContext *cct = common_preinit(iparams, code_env, flags, data_dir_option); cct->_conf->cluster = cluster; global_init_set_globals(cct); md_config_t *conf = cct->_conf; @@ -115,9 +116,12 @@ void global_pre_init(std::vector < const char * > *alt_def_args, void global_init(std::vector < const char * > *alt_def_args, std::vector < const char* >& args, - uint32_t module_type, code_environment_t code_env, int flags) + uint32_t module_type, code_environment_t code_env, + int flags, + const char *data_dir_option) { - global_pre_init(alt_def_args, args, module_type, code_env, flags); + global_pre_init(alt_def_args, args, module_type, code_env, flags, + data_dir_option); // signal stuff int siglist[] = { SIGPIPE, 0 }; diff --git a/src/global/global_init.h b/src/global/global_init.h index 5e934a77acd1..0e27d43d55f1 100644 --- a/src/global/global_init.h +++ b/src/global/global_init.h @@ -32,14 +32,18 @@ class CephContext; */ void global_init(std::vector < const char * > *alt_def_args, std::vector < const char* >& args, - uint32_t module_type, code_environment_t code_env, int flags); + uint32_t module_type, + code_environment_t code_env, + int flags, + const char *data_dir_option = 0); // just the first half; enough to get config parsed but doesn't start up the // cct or log. void global_pre_init(std::vector < const char * > *alt_def_args, std::vector < const char* >& args, uint32_t module_type, code_environment_t code_env, - int flags); + int flags, + const char *data_dir_option = 0); /* * perform all of the steps that global_init_daemonize performs just prior diff --git a/src/rgw/librgw.cc b/src/rgw/librgw.cc index 556f57f3ba04..f9b39aeba59e 100644 --- a/src/rgw/librgw.cc +++ b/src/rgw/librgw.cc @@ -33,7 +33,8 @@ int librgw_create(librgw_t *rgw, const char * const id) if (id) { iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id); } - CephContext *cct = common_preinit(iparams, CODE_ENVIRONMENT_LIBRARY, 0); + CephContext *cct = common_preinit(iparams, CODE_ENVIRONMENT_LIBRARY, 0, + "rgw_data"); cct->_conf->set_val("log_to_stderr", "false"); // quiet by default cct->_conf->set_val("err_to_stderr", "true"); // quiet by default cct->_conf->parse_env(); // environment variables override diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index fa6b3cc70cbd..09b2e9960fa0 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -1079,7 +1079,7 @@ int main(int argc, const char **argv) argv_to_vec(argc, argv, args); env_to_vec(args); global_init(&def_args, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_DAEMON, - CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS); + CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS, "rgw_data"); for (std::vector::iterator i = args.begin(); i != args.end(); ++i) { if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) { diff --git a/src/rgw/rgw_object_expirer.cc b/src/rgw/rgw_object_expirer.cc index ae7424d35a5b..a53e1a770dc3 100644 --- a/src/rgw/rgw_object_expirer.cc +++ b/src/rgw/rgw_object_expirer.cc @@ -61,7 +61,7 @@ int main(const int argc, const char **argv) env_to_vec(args); global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_DAEMON, - CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS); + CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS, "rgw_data"); for (std::vector::iterator i = args.begin(); i != args.end(); ) { if (ceph_argparse_double_dash(args, i)) {