[sheepdog] [PATCH] init trace for work queue before journal init

Jinzhi Chen nxtjinzhi at gmail.com
Fri Oct 31 06:33:09 CET 2014


when journal thread init before the initialization of trace,
it enter into loop (using uninitailized `tid_max`)with
--debug-enable configured. we need to initialize trace before
 journal thread init.
this patch extrace `wq_trace_init` from `init_work_queue` and
call it in the main() function just before the initialization
of journal file.

Signed-off-by: Jinzhi Chen <nxtjinzhi at gmail.com>
---
 include/work.h |    1 +
 lib/work.c     |   49 +++++++++++++++++++++++--------------------------
 sheep/sheep.c  |    7 +++++++
 3 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/include/work.h b/include/work.h
index b2fa0cf..c2008ba 100644
--- a/include/work.h
+++ b/include/work.h
@@ -63,6 +63,7 @@ struct work_queue *create_work_queue(const char *name,
enum wq_thread_control);
 struct work_queue *create_ordered_work_queue(const char *name);
 void queue_work(struct work_queue *q, struct work *work);
 bool work_queue_empty(struct work_queue *q);
+int wq_trace_init(void);

 #ifdef HAVE_TRACE
 void suspend_worker_threads(void);
diff --git a/lib/work.c b/lib/work.c
index 7e2cd79..ebce3b0 100644
--- a/lib/work.c
+++ b/lib/work.c
@@ -134,27 +134,6 @@ static void suspend(int num)
  eventfd_xwrite(ack_efd, 1); /* ack of resume */
 }

-static int wq_trace_init(void)
-{
- tid_max = TID_MAX_DEFAULT;
- tid_map = alloc_bitmap(NULL, 0, tid_max);
-
- resume_efd = eventfd(0, EFD_SEMAPHORE);
- ack_efd = eventfd(0, EFD_SEMAPHORE);
-
- if (resume_efd < 0 || ack_efd < 0) {
- sd_err("failed to create event fds: %m");
- return -1;
- }
-
- /* trace uses this signal to suspend the worker threads */
- if (install_sighandler(SIGUSR2, suspend, false) < 0) {
- sd_debug("%m");
- return -1;
- }
- return 0;
-}
-
 static void trace_set_tid_map(int tid)
 {
  sd_mutex_lock(&tid_map_lock);
@@ -180,12 +159,34 @@ static void trace_clear_tid_map(int tid)

 #else

-static inline int wq_trace_init(void) { return 0; }
 static inline void trace_set_tid_map(int tid) {}
 static inline void trace_clear_tid_map(int tid) {}

 #endif /* HAVE_TRACE */

+int wq_trace_init(void)
+{
+#ifdef HAVE_TRACE
+ tid_max = TID_MAX_DEFAULT;
+ tid_map = alloc_bitmap(NULL, 0, tid_max);
+
+ resume_efd = eventfd(0, EFD_SEMAPHORE);
+ ack_efd = eventfd(0, EFD_SEMAPHORE);
+
+ if (resume_efd < 0 || ack_efd < 0) {
+ sd_err("failed to create event fds: %m");
+ return -1;
+ }
+
+ /* trace uses this signal to suspend the worker threads */
+ if (install_sighandler(SIGUSR2, suspend, false) < 0) {
+ sd_debug("%m");
+ return -1;
+ }
+#endif
+ return 0;
+}
+
 static uint64_t get_msec_time(void)
 {
  struct timeval tv;
@@ -364,10 +365,6 @@ int init_work_queue(size_t (*get_nr_nodes)(void))
  return -1;
  }

- ret = wq_trace_init();
- if (ret < 0)
- return ret;
-
  ret = register_event(efd, worker_thread_request_done, NULL);
  if (ret) {
  sd_err("failed to register event fd %m");
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 2e91d0f..07c217b 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -885,6 +885,13 @@ int main(int argc, char **argv)
  goto cleanup_log;
  }

+ /* We should init trace before journal init */
+ ret = wq_trace_init();
+ if (ret) {
+ sd_err("failed to init trace");
+ goto cleanup_log;
+ }
+
  /* We should init journal file before backend init */
  if (uatomic_is_true(&sys->use_journal)) {
  if (!strlen(jpath))
-- 
1.7.9.5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wpkg.org/pipermail/sheepdog/attachments/20141031/0ad53327/attachment-0003.html>


More information about the sheepdog mailing list