summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorAnand Avati <avati@redhat.com>2012-07-16 15:50:30 -0700
committerAnand Avati <avati@redhat.com>2012-07-17 23:04:39 -0700
commita4e11fd67e3608c828e5bb8abf7a310b4f0a3017 (patch)
tree184938d2faa7521cc4608e0d9fddc0ebc50ef461 /libglusterfs/src
parent06c1d6b2b87e542479e069132ee3cf9efa11384e (diff)
glusterfs_ctx_t: un-globalize the filesystem context
So far there has been a global glusterfs_ctx_t object which represents the running instance of the filesystem (client or server). It contains the various graphs, connection to the management daemon over which new graphs are obtained, calls stacks issued on this filesystem, and a bunch of such things. With the introduction of libgfapi, it is no more true that there will be only one filesystem context in a process. Applications can be written to use libgfapi and obtain serveral instances of different filesystems/volumes in the same process. This involves messy untangling of assumptions inside libglusterfs that there would only be one global glusterfs_ctx_t and offload that assumption to glusterfsd/ and cli/ (where it is true). Change-Id: Ifd7d1259428c26076140a5764a2dc7361694139c BUG: 839950 Signed-off-by: Anand Avati <avati@redhat.com> Reviewed-on: http://review.gluster.com/3678 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/Makefile.am2
-rw-r--r--libglusterfs/src/common-utils.c4
-rw-r--r--libglusterfs/src/common-utils.h2
-rw-r--r--libglusterfs/src/ctx.c47
-rw-r--r--libglusterfs/src/globals.c45
-rw-r--r--libglusterfs/src/globals.h7
-rw-r--r--libglusterfs/src/glusterfs.h3
-rw-r--r--libglusterfs/src/latency.c6
-rw-r--r--libglusterfs/src/latency.h3
-rw-r--r--libglusterfs/src/mem-pool.c15
-rw-r--r--libglusterfs/src/statedump.c9
-rw-r--r--libglusterfs/src/statedump.h2
-rw-r--r--libglusterfs/src/xlator.c4
13 files changed, 65 insertions, 84 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
index bcfe467af..85e061145 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 cd7045277..e5056b1e8 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 f21ade40b..7fbaa87a8 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 000000000..22591317d
--- /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 703c5271d..49f118c6a 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 e797db184..7ccdb4a14 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 7e2c81356..d14666fb6 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 58e8b9158..f7747b392 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 16c5994b0..81acbf484 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 3e8100c64..2df47756f 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 694146874..1abd603ad 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 dc56bda0c..03648ddd9 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 2bac24f04..7094f1ef5 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)