Skip to content

Commit

Permalink
Merge pull request #6549 from kylinstorage/global_flags
Browse files Browse the repository at this point in the history
fix: use right init_flags to finish CephContext

Reviewed-by: Josh Durgin <jdurgin@redhat.com>
  • Loading branch information
jdurgin committed Nov 15, 2015
2 parents d5bf38e + 0669cba commit 6ad1013
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/ceph_mds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ int main(int argc, const char **argv)
exit(1);

if (shadow != MDSMap::STATE_ONESHOT_REPLAY)
global_init_daemonize(g_ceph_context, 0);
global_init_daemonize(g_ceph_context);
common_init_finish(g_ceph_context);

// get monmap
Expand Down
6 changes: 3 additions & 3 deletions src/ceph_mon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ int main(int argc, const char **argv)
// resolve public_network -> public_addr
pick_addresses(g_ceph_context, CEPH_PICK_ADDRESS_PUBLIC);

common_init_finish(g_ceph_context, flags);
common_init_finish(g_ceph_context);

bufferlist monmapbl, osdmapbl;
std::string error;
Expand Down Expand Up @@ -496,7 +496,7 @@ int main(int argc, const char **argv)
// screwing us over
Preforker prefork;
if (!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS)) {
if (global_init_prefork(g_ceph_context, 0) >= 0) {
if (global_init_prefork(g_ceph_context) >= 0) {
string err_msg;
err = prefork.prefork(err_msg);
if (err < 0) {
Expand Down Expand Up @@ -749,7 +749,7 @@ int main(int argc, const char **argv)
}

if (g_conf->daemonize) {
global_init_postfork_finish(g_ceph_context, 0);
global_init_postfork_finish(g_ceph_context);
prefork.daemonize();
}

Expand Down
2 changes: 1 addition & 1 deletion src/ceph_osd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ int main(int argc, const char **argv)
exit(1);

// Set up crypto, daemonize, etc.
global_init_daemonize(g_ceph_context, 0);
global_init_daemonize(g_ceph_context);
common_init_finish(g_ceph_context);

TracepointProvider::initialize<osd_tracepoint_traits>(g_ceph_context);
Expand Down
8 changes: 7 additions & 1 deletion src/common/ceph_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/common/ceph_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -86,6 +86,8 @@ class CephContext {
/* 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();

Expand Down Expand Up @@ -173,6 +175,8 @@ class CephContext {

uint32_t _module_type;

int _init_flags;

bool _crypto_inited;

/* libcommon service thread.
Expand Down
6 changes: 3 additions & 3 deletions src/common/common_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion src/common/common_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions src/global/global_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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 "
Expand Down
6 changes: 3 additions & 3 deletions src/global/global_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);


/*
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ int main(int argc, const char **argv)
check_curl();

if (g_conf->daemonize) {
global_init_daemonize(g_ceph_context, 0);
global_init_daemonize(g_ceph_context);
}
Mutex mutex("main");
SafeTimer init_timer(g_ceph_context, mutex);
Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_object_expirer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int main(const int argc, const char **argv)
}

if (g_conf->daemonize) {
global_init_daemonize(g_ceph_context, 0);
global_init_daemonize(g_ceph_context);
}

common_init_finish(g_ceph_context);
Expand Down

0 comments on commit 6ad1013

Please sign in to comment.