From 628f69f1b210c3c66fddbc5d214a8ef37c9edf97 Mon Sep 17 00:00:00 2001 From: Yunchuan Wen Date: Thu, 12 Nov 2015 16:10:10 +0800 Subject: [PATCH] save init flags to CephContext The constructor of RadosClient will use CephContext, and RadosClient.connect func will *always* use 0 as init_flags to call common_init_finish. So, save the init_flags to CephContex, will let RadosClient.connect use right init_flags to finish the cct. Signed-off-by: Yunchuan Wen --- src/common/ceph_context.cc | 8 +++++++- src/common/ceph_context.h | 6 +++++- src/common/common_init.cc | 6 +++--- src/common/common_init.h | 2 +- src/global/global_init.cc | 12 ++++++------ src/global/global_init.h | 6 +++--- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 7383ed7fd663f..6e60cf7a21658 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -398,11 +398,12 @@ void CephContext::do_command(std::string command, cmdmap_t& cmdmap, } -CephContext::CephContext(uint32_t module_type_) +CephContext::CephContext(uint32_t module_type_, int init_flags_) : nref(1), _conf(new md_config_t()), _log(NULL), _module_type(module_type_), + _init_flags(init_flags_), _crypto_inited(false), _service_thread(NULL), _log_obs(NULL), @@ -586,6 +587,11 @@ uint32_t CephContext::get_module_type() const return _module_type; } +int CephContext::get_init_flags() const +{ + return _init_flags; +} + PerfCountersCollection *CephContext::get_perfcounters_collection() { return _perf_counters_collection; diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index 037f2d813a2e8..3820a2355ead4 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -55,7 +55,7 @@ using ceph::bufferlist; */ class CephContext { public: - CephContext(uint32_t module_type_); + CephContext(uint32_t module_type_, int init_flags_ = 0); // ref count! private: @@ -86,6 +86,8 @@ public: /* Get the module type (client, mon, osd, mds, etc.) */ uint32_t get_module_type() const; + int get_init_flags() const; + /* Get the PerfCountersCollection of this CephContext */ PerfCountersCollection *get_perfcounters_collection(); @@ -173,6 +175,8 @@ private: uint32_t _module_type; + int _init_flags; + bool _crypto_inited; /* libcommon service thread. diff --git a/src/common/common_init.cc b/src/common/common_init.cc index a580309463f81..23c2e7ce7a19b 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -39,7 +39,7 @@ CephContext *common_preinit(const CephInitParameters &iparams, g_code_env = code_env; // Create a configuration object - CephContext *cct = new CephContext(iparams.module_type); + CephContext *cct = new CephContext(iparams.module_type, flags); md_config_t *conf = cct->_conf; // add config observers here @@ -113,10 +113,10 @@ void complain_about_parse_errors(CephContext *cct, /* Please be sure that this can safely be called multiple times by the * same application. */ -void common_init_finish(CephContext *cct, int flags) +void common_init_finish(CephContext *cct) { cct->init_crypto(); - if (!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS)) + if (!(cct->get_init_flags() & CINIT_FLAG_NO_DAEMON_ACTIONS)) cct->start_service_thread(); } diff --git a/src/common/common_init.h b/src/common/common_init.h index d6aa9fa32c1b5..f48b349bf0011 100644 --- a/src/common/common_init.h +++ b/src/common/common_init.h @@ -75,6 +75,6 @@ void complain_about_parse_errors(CephContext *cct, * libraries. The most obvious reason for this is that the threads started by * the Ceph libraries would be destroyed by a fork(). */ -void common_init_finish(CephContext *cct, int flags = 0); +void common_init_finish(CephContext *cct); #endif diff --git a/src/global/global_init.cc b/src/global/global_init.cc index ed5d18633bedd..609c7ea1e079a 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -257,7 +257,7 @@ static void pidfile_remove_void(void) pidfile_remove(); } -int global_init_prefork(CephContext *cct, int flags) +int global_init_prefork(CephContext *cct) { if (g_code_env != CODE_ENVIRONMENT_DAEMON) return -1; @@ -279,9 +279,9 @@ int global_init_prefork(CephContext *cct, int flags) return 0; } -void global_init_daemonize(CephContext *cct, int flags) +void global_init_daemonize(CephContext *cct) { - if (global_init_prefork(cct, flags) < 0) + if (global_init_prefork(cct) < 0) return; int ret = daemon(1, 1); @@ -293,7 +293,7 @@ void global_init_daemonize(CephContext *cct, int flags) } global_init_postfork_start(cct); - global_init_postfork_finish(cct, flags); + global_init_postfork_finish(cct); } void global_init_postfork_start(CephContext *cct) @@ -332,13 +332,13 @@ void global_init_postfork_start(CephContext *cct) pidfile_write(g_conf); } -void global_init_postfork_finish(CephContext *cct, int flags) +void global_init_postfork_finish(CephContext *cct) { /* We only close stderr once the caller decides the daemonization * process is finished. This way we can allow error messages to be * propagated in a manner that the user is able to see. */ - if (!(flags & CINIT_FLAG_NO_CLOSE_STDERR)) { + if (!(cct->get_init_flags() & CINIT_FLAG_NO_CLOSE_STDERR)) { int ret = global_init_shutdown_stderr(cct); if (ret) { derr << "global_init_daemonize: global_init_shutdown_stderr failed with " diff --git a/src/global/global_init.h b/src/global/global_init.h index 54c8d3d20c60a..5e934a77acd11 100644 --- a/src/global/global_init.h +++ b/src/global/global_init.h @@ -46,7 +46,7 @@ void global_pre_init(std::vector < const char * > *alt_def_args, * to actually forking (via daemon(3)). return 0 if we are going to proceed * with the fork, or -1 otherwise. */ -int global_init_prefork(CephContext *cct, int flags); +int global_init_prefork(CephContext *cct); /* * perform all the steps that global_init_daemonize performs just after @@ -57,7 +57,7 @@ void global_init_postfork_start(CephContext *cct); /* * close stderr, thus completing the postfork. */ -void global_init_postfork_finish(CephContext *cct, int flags); +void global_init_postfork_finish(CephContext *cct); /* @@ -67,7 +67,7 @@ void global_init_postfork_finish(CephContext *cct, int flags); * Note that this is equivalent to calling _prefork(), daemon(), and * _postfork. */ -void global_init_daemonize(CephContext *cct, int flags); +void global_init_daemonize(CephContext *cct); /* * global_init_chdir changes the process directory. -- 2.39.5