diff options
Diffstat (limited to 'libglusterfs/src')
| -rw-r--r-- | libglusterfs/src/Makefile.am | 2 | ||||
| -rw-r--r-- | libglusterfs/src/common-utils.c | 4 | ||||
| -rw-r--r-- | libglusterfs/src/common-utils.h | 2 | ||||
| -rw-r--r-- | libglusterfs/src/ctx.c | 47 | ||||
| -rw-r--r-- | libglusterfs/src/globals.c | 45 | ||||
| -rw-r--r-- | libglusterfs/src/globals.h | 7 | ||||
| -rw-r--r-- | libglusterfs/src/glusterfs.h | 3 | ||||
| -rw-r--r-- | libglusterfs/src/latency.c | 6 | ||||
| -rw-r--r-- | libglusterfs/src/latency.h | 3 | ||||
| -rw-r--r-- | libglusterfs/src/mem-pool.c | 15 | ||||
| -rw-r--r-- | libglusterfs/src/statedump.c | 9 | ||||
| -rw-r--r-- | libglusterfs/src/statedump.h | 2 | ||||
| -rw-r--r-- | libglusterfs/src/xlator.c | 4 | 
13 files changed, 65 insertions, 84 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index bcfe467af62..85e06114532 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -23,7 +23,7 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \  	$(CONTRIBDIR)/uuid/uuid_time.c $(CONTRIBDIR)/uuid/compare.c \  	$(CONTRIBDIR)/uuid/isnull.c $(CONTRIBDIR)/uuid/unpack.c syncop.c \  	graph-print.c trie.c run.c options.c fd-lk.c circ-buff.c \ -	event-history.c gidcache.c +	event-history.c gidcache.c ctx.c  nodist_libglusterfs_la_SOURCES = y.tab.c graph.lex.c diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index cd7045277ba..e5056b1e85e 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -392,8 +392,9 @@ out:  /* Obtain a backtrace and print it to stdout. */  /* TODO: It looks like backtrace_symbols allocates memory,     it may be problem because mostly memory allocation/free causes 'sigsegv' */ +  void -gf_print_trace (int32_t signum) +gf_print_trace (int32_t signum, glusterfs_ctx_t *ctx)  {          extern FILE *gf_log_logfile;          char         msg[1024] = {0,}; @@ -409,7 +410,6 @@ gf_print_trace (int32_t signum)                  goto out;          { -                glusterfs_ctx_t *ctx = glusterfs_ctx_get ();                  struct list_head *trav = ((call_pool_t *)ctx->pool)->all_frames.next;                  while (trav != (&((call_pool_t *)ctx->pool)->all_frames)) {                          call_frame_t *tmp = (call_frame_t *)(&((call_stack_t *)trav)->frames); diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index f21ade40b8f..7fbaa87a87e 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -107,7 +107,7 @@ void gf_global_variable_init(void);  in_addr_t gf_resolve_ip (const char *hostname, void **dnscache);  void gf_log_volume_file (FILE *specfp); -void gf_print_trace (int32_t signal); +void gf_print_trace (int32_t signal, glusterfs_ctx_t *ctx);  extern char *gf_fop_list[GF_FOP_MAXVALUE];  extern char *gf_mgmt_list[GF_MGMT_MAXVALUE]; diff --git a/libglusterfs/src/ctx.c b/libglusterfs/src/ctx.c new file mode 100644 index 00000000000..22591317d86 --- /dev/null +++ b/libglusterfs/src/ctx.c @@ -0,0 +1,47 @@ +/* +  Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> +  This file is part of GlusterFS. + +  This file is licensed to you under your choice of the GNU Lesser +  General Public License, version 3 or any later version (LGPLv3 or +  later), or the GNU General Public License, version 2 (GPLv2), in all +  cases as published by the Free Software Foundation. +*/ + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif /* !_CONFIG_H */ + +#include <pthread.h> + +#include "glusterfs.h" +#include "mem-pool.h" + + +glusterfs_ctx_t * +glusterfs_ctx_new () +{ +        int               ret = 0; +	glusterfs_ctx_t  *ctx = NULL; + +	/* no GF_CALLOC here, gf_acct_mem_set_enable is not +	   yet decided at this point */ +        ctx = CALLOC (1, sizeof (*ctx)); +        if (!ctx) { +                ret = -1; +                goto out; +        } + +        INIT_LIST_HEAD (&ctx->graphs); +	INIT_LIST_HEAD (&ctx->mempool_list); + +	ret = pthread_mutex_init (&ctx->lock, NULL); +	if (ret) { +		FREE (ctx); +		ctx = NULL; +	} +out: +	return ctx; +} + diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c index 703c5271d7e..49f118c6a07 100644 --- a/libglusterfs/src/globals.c +++ b/libglusterfs/src/globals.c @@ -81,43 +81,6 @@ gf_op_list_init()  } -/* CTX */ -static glusterfs_ctx_t *glusterfs_ctx; - - -int -glusterfs_ctx_init () -{ -        int  ret = 0; - -        if (glusterfs_ctx) { -                gf_log_callingfn ("", GF_LOG_WARNING, "init called again"); -                goto out; -        } - -        glusterfs_ctx = CALLOC (1, sizeof (*glusterfs_ctx)); -        if (!glusterfs_ctx) { -                ret = -1; -                goto out; -        } - -        INIT_LIST_HEAD (&glusterfs_ctx->graphs); -        INIT_LIST_HEAD (&glusterfs_ctx->mempool_list); -        ret = pthread_mutex_init (&glusterfs_ctx->lock, NULL); - -out: -        return ret; -} - - -glusterfs_ctx_t * -glusterfs_ctx_get () -{ -        return glusterfs_ctx; - -} - -  /* THIS */  xlator_t global_xlator; @@ -143,7 +106,6 @@ glusterfs_this_init ()          global_xlator.name = "glusterfs";          global_xlator.type = "global"; -        global_xlator.ctx  = glusterfs_ctx;          INIT_LIST_HEAD (&global_xlator.volume_options); @@ -327,13 +289,6 @@ glusterfs_globals_init ()          gf_log_globals_init (); -        ret = glusterfs_ctx_init (); -        if (ret) { -                gf_log ("", GF_LOG_CRITICAL, -                        "ERROR: glusterfs context init failed"); -                goto out; -        } -          ret = glusterfs_this_init ();          if (ret) {                  gf_log ("", GF_LOG_CRITICAL, diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h index e797db184bd..7ccdb4a1498 100644 --- a/libglusterfs/src/globals.h +++ b/libglusterfs/src/globals.h @@ -13,13 +13,6 @@  #define GF_DEFAULT_BASE_PORT 24007 -#include "glusterfs.h" - -/* CTX */ -#define CTX (glusterfs_ctx_get()) - -glusterfs_ctx_t *glusterfs_ctx_get (); -  #include "xlator.h"  /* THIS */ diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 7e2c8135600..d14666fb63d 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -369,13 +369,12 @@ struct _glusterfs_ctx {          struct mem_pool    *dict_pair_pool;          struct mem_pool    *dict_data_pool; -        int                 mem_accounting; /* if value is other than 0, it -                                               will be set */          glusterfsd_mgmt_event_notify_fn_t notify; /* Used for xlators to make                                                       call to fsd-mgmt */  };  typedef struct _glusterfs_ctx glusterfs_ctx_t; +glusterfs_ctx_t *glusterfs_ctx_new (void);  /* If you edit this structure then, make a corresponding change in   * globals.c in the eventstring. diff --git a/libglusterfs/src/latency.c b/libglusterfs/src/latency.c index 58e8b915852..f7747b39230 100644 --- a/libglusterfs/src/latency.c +++ b/libglusterfs/src/latency.c @@ -159,12 +159,8 @@ gf_proc_dump_latency_info (xlator_t *xl)  void -gf_latency_toggle (int signum) +gf_latency_toggle (int signum, glusterfs_ctx_t *ctx)  { -        glusterfs_ctx_t *ctx = NULL; - -        ctx = glusterfs_ctx_get (); -          if (ctx) {                  ctx->measure_latency = !ctx->measure_latency;                  gf_log ("[core]", GF_LOG_INFO, diff --git a/libglusterfs/src/latency.h b/libglusterfs/src/latency.h index 16c5994b008..81acbf48478 100644 --- a/libglusterfs/src/latency.h +++ b/libglusterfs/src/latency.h @@ -11,6 +11,7 @@  #ifndef __LATENCY_H__  #define __LATENCY_H__ +#include "glusterfs.h"  typedef struct fop_latency {          uint64_t min;           /* min time for the call (microseconds) */ @@ -22,6 +23,6 @@ typedef struct fop_latency {  } fop_latency_t;  void -gf_latency_toggle (int signum); +gf_latency_toggle (int signum, glusterfs_ctx_t *ctx);  #endif /* __LATENCY_H__ */ diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index 3e8100c6438..2df47756f7d 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -38,23 +38,14 @@ gf_mem_acct_is_enabled ()          return gf_mem_acct_enable;  } +  void  gf_mem_acct_enable_set ()  { -#ifdef DEBUG -        gf_mem_acct_enable = 1; -        return; -#endif -        glusterfs_ctx_t *ctx = NULL;          char            *opt = NULL;          long             val = -1; -        gf_mem_acct_enable = 0; - -        ctx = glusterfs_ctx_get (); - -        if (ctx->mem_accounting) { -                gf_mem_acct_enable = 1; +        if (gf_mem_acct_enable) {                  return;          } @@ -365,7 +356,7 @@ mem_pool_new_fn (unsigned long sizeof_type,          mem_pool->pool_end = pool + (count * (padded_sizeof_type));          /* add this pool to the global list */ -        ctx = glusterfs_ctx_get (); +        ctx = THIS->ctx;          if (!ctx)                  goto out; diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index 6941468747e..1abd603adca 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -381,7 +381,7 @@ gf_proc_dump_xlator_info (xlator_t *top)          if (!top)                  return; -        ctx = glusterfs_ctx_get (); +        ctx = top->ctx;          trav = top;          while (trav) { @@ -436,7 +436,7 @@ gf_proc_dump_oldgraph_xlator_info (xlator_t *top)          if (!top)                  return; -        ctx = glusterfs_ctx_get (); +        ctx = top->ctx;          trav = top;          while (trav) { @@ -614,18 +614,17 @@ gf_proc_dump_options_init ()          return 0;  } +  void -gf_proc_dump_info (int signum) +gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx)  {          int                i    = 0;          int                ret  = -1; -        glusterfs_ctx_t   *ctx  = NULL;          glusterfs_graph_t *trav = NULL;          char               brick_name[PATH_MAX] = {0,};          gf_proc_dump_lock (); -        ctx = glusterfs_ctx_get ();          if (!ctx)                  goto out; diff --git a/libglusterfs/src/statedump.h b/libglusterfs/src/statedump.h index dc56bda0cbb..03648ddd9bd 100644 --- a/libglusterfs/src/statedump.h +++ b/libglusterfs/src/statedump.h @@ -61,7 +61,7 @@ void gf_proc_dump_fini(void);  void gf_proc_dump_cleanup(void); -void gf_proc_dump_info(int signum); +void gf_proc_dump_info(int signum, glusterfs_ctx_t *ctx);  int gf_proc_dump_add_section(char *key,...); diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index 2bac24f040f..7094f1ef5cf 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -460,7 +460,7 @@ xlator_mem_acct_init (xlator_t *xl, int num_types)          int             i = 0;          int             ret = 0; -        if (!gf_mem_acct_is_enabled()) +        if (!gf_mem_acct_is_enabled ())                  return 0;          if (!xl) @@ -721,7 +721,7 @@ is_gf_log_command (xlator_t *this, const char *name, char *value)                  goto out;          } -        ctx = glusterfs_ctx_get(); +        ctx = this->ctx;          if (!ctx)                  goto out;          if (!ctx->active)  | 
