From ed4b76ba9c545f577287c0e70ae3cc853a0d5f3f Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Thu, 2 Aug 2012 13:14:25 +0530 Subject: core: reduce the usage of global variables * move all the 'logging' related global variables into ctx * make gf_fop_list a 'const' global array, hence no init(), no edits. * make sure ctx is allocated without any dependancy on memory-accounting infrastructure, so it can be the first one to get allocated * globals_init() should happen with ctx as argument not yet fixed below in this patchset: * anything with 'THIS' related globals * anything related to compat_errno related globals as its one time init'd and not changed later on. * statedump related globals Change-Id: Iab8fc30d4bfdbded6741d66ff1ed670fdc7b7ad2 Signed-off-by: Amar Tumballi BUG: 764890 Reviewed-on: http://review.gluster.com/3767 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- glusterfsd/src/glusterfsd.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'glusterfsd') diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 5d5586625..262ef15b6 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -857,7 +857,7 @@ parse_opts (int key, char *arg, struct argp_state *state) case ARGP_MEM_ACCOUNTING_KEY: /* TODO: it should have got handled much earlier */ - gf_mem_acct_enable_set (); + //gf_mem_acct_enable_set (THIS->ctx); break; case ARGP_FOPEN_KEEP_CACHE_KEY: @@ -1201,7 +1201,7 @@ logging_init (glusterfs_ctx_t *ctx) } } - if (gf_log_init (cmd_args->log_file) == -1) { + if (gf_log_init (ctx, cmd_args->log_file) == -1) { fprintf (stderr, "ERROR: failed to open logfile %s\n", cmd_args->log_file); return -1; @@ -1213,12 +1213,12 @@ logging_init (glusterfs_ctx_t *ctx) } void -gf_check_and_set_mem_acct (int argc, char *argv[]) +gf_check_and_set_mem_acct (glusterfs_ctx_t *ctx, int argc, char *argv[]) { int i = 0; for (i = 0; i < argc; i++) { if (strcmp (argv[i], "--mem-accounting") == 0) { - gf_mem_acct_enable_set (); + gf_mem_acct_enable_set (ctx); break; } } @@ -1706,15 +1706,6 @@ main (int argc, char *argv[]) glusterfs_ctx_t *ctx = NULL; int ret = -1; - ret = glusterfs_globals_init (); - if (ret) - return ret; - -#ifndef DEBUG - /* Enable memory accounting on the fly based on argument */ - gf_check_and_set_mem_acct (argc, argv); -#endif - ctx = glusterfs_ctx_new (); if (!ctx) { gf_log ("glusterfs", GF_LOG_CRITICAL, @@ -1722,6 +1713,18 @@ main (int argc, char *argv[]) return ENOMEM; } glusterfsd_ctx = ctx; + + gf_mem_acct_enable_set (ctx); + +#ifndef DEBUG + /* Enable memory accounting on the fly based on argument */ + gf_check_and_set_mem_acct (ctx, argc, argv); +#endif + + ret = glusterfs_globals_init (ctx); + if (ret) + return ret; + THIS->ctx = ctx; ret = glusterfs_ctx_defaults_init (ctx); -- cgit