summaryrefslogtreecommitdiffstats
path: root/glusterfsd/src/glusterfsd.c
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 /glusterfsd/src/glusterfsd.c
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 'glusterfsd/src/glusterfsd.c')
-rw-r--r--glusterfsd/src/glusterfsd.c58
1 files changed, 35 insertions, 23 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
index c9c7ad065..2b6ee5452 100644
--- a/glusterfsd/src/glusterfsd.c
+++ b/glusterfsd/src/glusterfsd.c
@@ -492,7 +492,7 @@ gf_remember_xlator_option (struct list_head *options, char *arg)
char *dot = NULL;
char *equals = NULL;
- ctx = glusterfs_ctx_get ();
+ ctx = glusterfsd_ctx;
cmd_args = &ctx->cmd_args;
option = GF_CALLOC (1, sizeof (xlator_cmdline_option_t),
@@ -560,7 +560,6 @@ out:
static error_t
parse_opts (int key, char *arg, struct argp_state *state)
{
- glusterfs_ctx_t *ctx = NULL;
cmd_args_t *cmd_args = NULL;
uint32_t n = 0;
double d = 0.0;
@@ -833,8 +832,7 @@ parse_opts (int key, char *arg, struct argp_state *state)
case ARGP_MEM_ACCOUNTING_KEY:
/* TODO: it should have got handled much earlier */
- ctx = glusterfs_ctx_get ();
- ctx->mem_accounting = 1;
+ gf_mem_acct_enable_set ();
break;
case ARGP_FOPEN_KEEP_CACHE_KEY:
@@ -859,7 +857,7 @@ cleanup_and_exit (int signum)
glusterfs_ctx_t *ctx = NULL;
xlator_t *trav = NULL;
- ctx = glusterfs_ctx_get ();
+ ctx = glusterfsd_ctx;
if (!ctx)
return;
@@ -918,7 +916,7 @@ reincarnate (int signum)
glusterfs_ctx_t *ctx = NULL;
cmd_args_t *cmd_args = NULL;
- ctx = glusterfs_ctx_get ();
+ ctx = glusterfsd_ctx;
cmd_args = &ctx->cmd_args;
if (cmd_args->volfile_server) {
@@ -1190,12 +1188,12 @@ logging_init (glusterfs_ctx_t *ctx)
}
void
-gf_check_and_set_mem_acct (int argc, char *argv[], glusterfs_ctx_t *ctx)
+gf_check_and_set_mem_acct (int argc, char *argv[])
{
int i = 0;
for (i = 0; i < argc; i++) {
if (strcmp (argv[i], "--mem-accounting") == 0) {
- ctx->mem_accounting = 1;
+ gf_mem_acct_enable_set ();
break;
}
}
@@ -1463,10 +1461,10 @@ glusterfs_sigwaiter (void *arg)
reincarnate (sig);
break;
case SIGUSR1:
- gf_proc_dump_info (sig);
+ gf_proc_dump_info (sig, glusterfsd_ctx);
break;
case SIGUSR2:
- gf_latency_toggle (sig);
+ gf_latency_toggle (sig, glusterfsd_ctx);
break;
default:
@@ -1478,6 +1476,13 @@ glusterfs_sigwaiter (void *arg)
}
+void
+glusterfsd_print_trace (int signum)
+{
+ gf_print_trace (signum, glusterfsd_ctx);
+}
+
+
int
glusterfs_signals_setup (glusterfs_ctx_t *ctx)
{
@@ -1487,12 +1492,12 @@ glusterfs_signals_setup (glusterfs_ctx_t *ctx)
sigemptyset (&set);
/* common setting for all threads */
- signal (SIGSEGV, gf_print_trace);
- signal (SIGABRT, gf_print_trace);
- signal (SIGILL, gf_print_trace);
- signal (SIGTRAP, gf_print_trace);
- signal (SIGFPE, gf_print_trace);
- signal (SIGBUS, gf_print_trace);
+ signal (SIGSEGV, glusterfsd_print_trace);
+ signal (SIGABRT, glusterfsd_print_trace);
+ signal (SIGILL, glusterfsd_print_trace);
+ signal (SIGTRAP, glusterfsd_print_trace);
+ signal (SIGFPE, glusterfsd_print_trace);
+ signal (SIGBUS, glusterfsd_print_trace);
signal (SIGINT, cleanup_and_exit);
signal (SIGPIPE, SIG_IGN);
@@ -1504,7 +1509,7 @@ glusterfs_signals_setup (glusterfs_ctx_t *ctx)
ret = pthread_sigmask (SIG_BLOCK, &set, NULL);
if (ret) {
- gf_log ("", GF_LOG_WARNING,
+ gf_log ("glusterfsd", GF_LOG_WARNING,
"failed to execute pthread_signmask %s",
strerror (errno));
return ret;
@@ -1518,7 +1523,7 @@ glusterfs_signals_setup (glusterfs_ctx_t *ctx)
fallback to signals getting handled by other threads.
setup the signal handlers
*/
- gf_log ("", GF_LOG_WARNING,
+ gf_log ("glusterfsd", GF_LOG_WARNING,
"failed to create pthread %s",
strerror (errno));
return ret;
@@ -1667,6 +1672,9 @@ out:
}
+/* This is the only legal global pointer */
+glusterfs_ctx_t *glusterfsd_ctx;
+
int
main (int argc, char *argv[])
{
@@ -1677,16 +1685,20 @@ main (int argc, char *argv[])
if (ret)
return ret;
- ctx = glusterfs_ctx_get ();
+#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,
"ERROR: glusterfs context not initialized");
return ENOMEM;
}
-#ifndef DEBUG
- /* Enable memory accounting on the fly based on argument */
- gf_check_and_set_mem_acct (argc, argv, ctx);
-#endif
+ glusterfsd_ctx = ctx;
+ THIS->ctx = ctx;
+
ret = glusterfs_ctx_defaults_init (ctx);
if (ret)
goto out;