From c830a9b241c3c5b68887d68bb6d6e53823045271 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 30 Oct 2012 13:16:57 -0700 Subject: [PATCH] mon: separate pre- and post-fork init Do most init pre-fork, then do the last little bit (start up messenger, bootstrap) post-fork. Signed-off-by: Sage Weil --- src/ceph_mon.cc | 8 +++++++- src/mon/Monitor.cc | 21 +++++++++++++++------ src/mon/Monitor.h | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index 9d5db254f5bca..f369f4150e5a0 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -404,10 +404,13 @@ int main(int argc, const char **argv) // start monitor mon = new Monitor(g_ceph_context, g_conf->name.get_id(), &store, messenger, &monmap); + err = mon->preinit(); + if (err < 0) + return 1; + global_init_daemonize(g_ceph_context, 0); common_init_finish(g_ceph_context); global_init_chdir(g_ceph_context); - messenger->start(); // set up signal handlers, now that we've daemonized/forked. init_async_signal_handler(); @@ -415,7 +418,10 @@ int main(int argc, const char **argv) register_async_signal_handler_oneshot(SIGINT, handle_mon_signal); register_async_signal_handler_oneshot(SIGTERM, handle_mon_signal); + messenger->start(); + mon->init(); + messenger->wait(); unregister_async_signal_handler(SIGHUP, sighup_handler); diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 6c5134f4c9250..0ce53515bd02a 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -409,11 +409,11 @@ void Monitor::write_features() store->put_bl_ss(bl, COMPAT_SET_LOC, 0); } -int Monitor::init() +int Monitor::preinit() { lock.Lock(); - dout(1) << "init fsid " << monmap->fsid << dendl; + dout(1) << "preinit fsid " << monmap->fsid << dendl; assert(!logger); { @@ -540,15 +540,24 @@ int Monitor::init() assert(r == 0); lock.Lock(); - // i'm ready! - messenger->add_dispatcher_tail(this); - + lock.Unlock(); + return 0; +} + +int Monitor::init() +{ + dout(2) << "init" << dendl; + lock.Lock(); + // start ticker timer.init(); new_tick(); + // i'm ready! + messenger->add_dispatcher_tail(this); + bootstrap(); - + lock.Unlock(); return 0; } diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 43b46a449158c..8ff376ce880eb 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -440,6 +440,7 @@ public: static int check_features(MonitorStore *store); + int preinit(); int init(); void shutdown(); void tick(); -- 2.39.5