From 4d06719f101f49019be25bd6137f72f2cb85bd5a Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 24 Jul 2017 06:01:36 -0400 Subject: [PATCH] common: use code_environment_t for daemon-ness in config ...and reinstate the set_daemon_default versions of config options in place of the special casing in common_init. Signed-off-by: John Spray --- src/common/ceph_context.cc | 18 ++++----------- src/common/ceph_context.h | 5 +++- src/common/common_init.cc | 47 +++++++++----------------------------- src/common/options.cc | 12 +++++++--- 4 files changed, 28 insertions(+), 54 deletions(-) diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 1d5c6facadeef..2cf0f7d8c5866 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -550,21 +550,11 @@ void CephContext::do_command(std::string command, cmdmap_t& cmdmap, << "result is " << out->length() << " bytes" << dendl; } - -static bool is_daemon(uint32_t module_type) -{ - if (module_type == CEPH_ENTITY_TYPE_OSD || - module_type == CEPH_ENTITY_TYPE_MDS || - module_type == CEPH_ENTITY_TYPE_MON) { - return true; - } else { - return false; - } -} - -CephContext::CephContext(uint32_t module_type_, int init_flags_) +CephContext::CephContext(uint32_t module_type_, + enum code_environment_t code_env, + int init_flags_) : nref(1), - _conf(new md_config_t(is_daemon(module_type_))), + _conf(new md_config_t(code_env == CODE_ENVIRONMENT_DAEMON)), _log(NULL), _module_type(module_type_), _init_flags(init_flags_), diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index 64aec93f768e4..e024dba70f2ac 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -20,6 +20,7 @@ #include #include "common/cmdparse.h" +#include "common/code_environment.h" #include "crush/CrushLocation.h" #include "include/Spinlock.h" @@ -50,7 +51,9 @@ namespace ceph { */ class CephContext { public: - CephContext(uint32_t module_type_, int init_flags_ = 0); + CephContext(uint32_t module_type_, + enum code_environment_t code_env=CODE_ENVIRONMENT_UTILITY, + int init_flags_ = 0); // ref count! private: diff --git a/src/common/common_init.cc b/src/common/common_init.cc index a62f67e2ee7fe..b74633cf94879 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -32,7 +32,7 @@ CephContext *common_preinit(const CephInitParameters &iparams, g_code_env = code_env; // Create a configuration object - CephContext *cct = new CephContext(iparams.module_type, flags); + CephContext *cct = new CephContext(iparams.module_type, code_env, flags); md_config_t *conf = cct->_conf; // add config observers here @@ -43,44 +43,19 @@ CephContext *common_preinit(const CephInitParameters &iparams, 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: - conf->set_val_or_die("daemonize", "true"); - conf->set_val_or_die("log_to_stderr", "false"); - conf->set_val_or_die("err_to_stderr", "true"); - - // different default keyring locations for osd and mds. this is - // for backward compatibility. moving forward, we want all keyrings - // in these locations. the mon already forces $mon_data/keyring. - if (conf->name.is_mds()) - conf->set_val("keyring", "$mds_data/keyring", false); - else if (conf->name.is_osd()) - conf->set_val("keyring", "$osd_data/keyring", false); - break; - - case CODE_ENVIRONMENT_UTILITY_NODOUT: - case CODE_ENVIRONMENT_LIBRARY: + // different default keyring locations for osd and mds. this is + // for backward compatibility. moving forward, we want all keyrings + // in these locations. the mon already forces $mon_data/keyring. + if (conf->name.is_mds()) { + conf->set_val("keyring", "$mds_data/keyring", false); + } else if (conf->name.is_osd()) { + conf->set_val("keyring", "$osd_data/keyring", false); + } + + if (code_env == CODE_ENVIRONMENT_LIBRARY) { conf->set_val_or_die("log_to_stderr", "false"); conf->set_val_or_die("err_to_stderr", "false"); conf->set_val_or_die("log_flush_on_exit", "false"); - break; - - default: - break; - } - - if (flags & CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS) { - // do nothing special! we used to do no default log, pid_file, - // admin_socket, but changed our minds. let's make ceph-fuse - // and radosgw use the same defaults as ceph-{osd,mon,mds,...} - } else if (code_env != CODE_ENVIRONMENT_DAEMON) { - // no default log, pid_file, admin_socket - conf->set_val_or_die("pid_file", ""); - conf->set_val_or_die("admin_socket", ""); - conf->set_val_or_die("log_file", ""); - // use less memory for logs - conf->set_val_or_die("log_max_recent", "500"); } return cct; diff --git a/src/common/options.cc b/src/common/options.cc index 4bbe7693998ed..7a333f01d1e86 100644 --- a/src/common/options.cc +++ b/src/common/options.cc @@ -205,7 +205,8 @@ std::vector