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 --- libglusterfs/src/common-utils.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'libglusterfs/src/common-utils.c') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 74f38d01e..cf5991e10 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -239,24 +239,26 @@ err: void gf_log_volume_file (FILE *specfp) { - extern FILE *gf_log_logfile; int lcount = 0; char data[GF_UNIT_KB]; + glusterfs_ctx_t *ctx; + + ctx = THIS->ctx; fseek (specfp, 0L, SEEK_SET); - fprintf (gf_log_logfile, "Given volfile:\n"); - fprintf (gf_log_logfile, + fprintf (ctx->log.gf_log_logfile, "Given volfile:\n"); + fprintf (ctx->log.gf_log_logfile, "+---------------------------------------" "---------------------------------------+\n"); while (fgets (data, GF_UNIT_KB, specfp) != NULL){ lcount++; - fprintf (gf_log_logfile, "%3d: %s", lcount, data); + fprintf (ctx->log.gf_log_logfile, "%3d: %s", lcount, data); } - fprintf (gf_log_logfile, + fprintf (ctx->log.gf_log_logfile, "\n+---------------------------------------" "---------------------------------------+\n"); - fflush (gf_log_logfile); + fflush (ctx->log.gf_log_logfile); fseek (specfp, 0L, SEEK_SET); } @@ -396,13 +398,12 @@ out: void gf_print_trace (int32_t signum, glusterfs_ctx_t *ctx) { - extern FILE *gf_log_logfile; char msg[1024] = {0,}; char timestr[64] = {0,}; int ret = 0; int fd = 0; - fd = fileno (gf_log_logfile); + fd = fileno (ctx->log.gf_log_logfile); /* Pending frames, (if any), list them in order */ ret = write (fd, "pending frames:\n", 16); @@ -1818,7 +1819,7 @@ out: char * uuid_utoa (uuid_t uuid) { - char *uuid_buffer = glusterfs_uuid_buf_get(); + char *uuid_buffer = glusterfs_uuid_buf_get(THIS->ctx); uuid_unparse (uuid, uuid_buffer); return uuid_buffer; } @@ -1837,7 +1838,7 @@ uuid_utoa_r (uuid_t uuid, char *dst) char * lkowner_utoa (gf_lkowner_t *lkowner) { - char *lkowner_buffer = glusterfs_lkowner_buf_get(); + char *lkowner_buffer = glusterfs_lkowner_buf_get(THIS->ctx); lkowner_unparse (lkowner, lkowner_buffer, GF_LKOWNER_BUF_SIZE); return lkowner_buffer; } -- cgit