summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorAmar Tumballi <amarts@redhat.com>2012-08-02 13:14:25 +0530
committerAnand Avati <avati@redhat.com>2012-08-03 02:01:52 -0700
commited4b76ba9c545f577287c0e70ae3cc853a0d5f3f (patch)
treedeffb91a0cee620ac7fcc8c7914dbca73668574e /libglusterfs/src
parent66205114267ec659b4ad8084c7e9497009529c61 (diff)
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 <amarts@redhat.com> BUG: 764890 Reviewed-on: http://review.gluster.com/3767 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/common-utils.c21
-rw-r--r--libglusterfs/src/common-utils.h3
-rw-r--r--libglusterfs/src/ctx.c6
-rw-r--r--libglusterfs/src/globals.c198
-rw-r--r--libglusterfs/src/globals.h13
-rw-r--r--libglusterfs/src/glusterfs.h22
-rw-r--r--libglusterfs/src/latency.c3
-rw-r--r--libglusterfs/src/logging.c202
-rw-r--r--libglusterfs/src/logging.h91
-rw-r--r--libglusterfs/src/mem-pool.c26
-rw-r--r--libglusterfs/src/mem-pool.h3
-rw-r--r--libglusterfs/src/stack.c5
-rw-r--r--libglusterfs/src/syncop.c2
-rw-r--r--libglusterfs/src/xlator.c6
-rw-r--r--libglusterfs/src/xlator.h1
15 files changed, 267 insertions, 335 deletions
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;
}
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 7fbaa87a8..3d18a29a1 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -109,9 +109,6 @@ 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, glusterfs_ctx_t *ctx);
-extern char *gf_fop_list[GF_FOP_MAXVALUE];
-extern char *gf_mgmt_list[GF_MGMT_MAXVALUE];
-
#define VECTORSIZE(count) (count * (sizeof (struct iovec)))
#define STRLEN_0(str) (strlen(str) + 1)
diff --git a/libglusterfs/src/ctx.c b/libglusterfs/src/ctx.c
index 22591317d..01489fbe0 100644
--- a/libglusterfs/src/ctx.c
+++ b/libglusterfs/src/ctx.c
@@ -16,8 +16,6 @@
#include <pthread.h>
#include "glusterfs.h"
-#include "mem-pool.h"
-
glusterfs_ctx_t *
glusterfs_ctx_new ()
@@ -27,7 +25,7 @@ glusterfs_ctx_new ()
/* no GF_CALLOC here, gf_acct_mem_set_enable is not
yet decided at this point */
- ctx = CALLOC (1, sizeof (*ctx));
+ ctx = calloc (1, sizeof (*ctx));
if (!ctx) {
ret = -1;
goto out;
@@ -38,7 +36,7 @@ glusterfs_ctx_new ()
ret = pthread_mutex_init (&ctx->lock, NULL);
if (ret) {
- FREE (ctx);
+ free (ctx);
ctx = NULL;
}
out:
diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c
index 49f118c6a..d84e49dcc 100644
--- a/libglusterfs/src/globals.c
+++ b/libglusterfs/src/globals.c
@@ -20,67 +20,54 @@
#include "xlator.h"
#include "mem-pool.h"
-
-/* gf_*_list[] */
-
-char *gf_fop_list[GF_FOP_MAXVALUE];
-char *gf_mgmt_list[GF_MGMT_MAXVALUE];
-
-
-void
-gf_op_list_init()
-{
- gf_fop_list[GF_FOP_NULL] = "NULL";
- gf_fop_list[GF_FOP_STAT] = "STAT";
- gf_fop_list[GF_FOP_READLINK] = "READLINK";
- gf_fop_list[GF_FOP_MKNOD] = "MKNOD";
- gf_fop_list[GF_FOP_MKDIR] = "MKDIR";
- gf_fop_list[GF_FOP_UNLINK] = "UNLINK";
- gf_fop_list[GF_FOP_RMDIR] = "RMDIR";
- gf_fop_list[GF_FOP_SYMLINK] = "SYMLINK";
- gf_fop_list[GF_FOP_RENAME] = "RENAME";
- gf_fop_list[GF_FOP_LINK] = "LINK";
- gf_fop_list[GF_FOP_TRUNCATE] = "TRUNCATE";
- gf_fop_list[GF_FOP_OPEN] = "OPEN";
- gf_fop_list[GF_FOP_READ] = "READ";
- gf_fop_list[GF_FOP_WRITE] = "WRITE";
- gf_fop_list[GF_FOP_STATFS] = "STATFS";
- gf_fop_list[GF_FOP_FLUSH] = "FLUSH";
- gf_fop_list[GF_FOP_FSYNC] = "FSYNC";
- gf_fop_list[GF_FOP_SETXATTR] = "SETXATTR";
- gf_fop_list[GF_FOP_GETXATTR] = "GETXATTR";
- gf_fop_list[GF_FOP_REMOVEXATTR] = "REMOVEXATTR";
- gf_fop_list[GF_FOP_OPENDIR] = "OPENDIR";
- gf_fop_list[GF_FOP_FSYNCDIR] = "FSYNCDIR";
- gf_fop_list[GF_FOP_ACCESS] = "ACCESS";
- gf_fop_list[GF_FOP_CREATE] = "CREATE";
- gf_fop_list[GF_FOP_FTRUNCATE] = "FTRUNCATE";
- gf_fop_list[GF_FOP_FSTAT] = "FSTAT";
- gf_fop_list[GF_FOP_LK] = "LK";
- gf_fop_list[GF_FOP_LOOKUP] = "LOOKUP";
- gf_fop_list[GF_FOP_READDIR] = "READDIR";
- gf_fop_list[GF_FOP_INODELK] = "INODELK";
- gf_fop_list[GF_FOP_FINODELK] = "FINODELK";
- gf_fop_list[GF_FOP_ENTRYLK] = "ENTRYLK";
- gf_fop_list[GF_FOP_FENTRYLK] = "FENTRYLK";
- gf_fop_list[GF_FOP_XATTROP] = "XATTROP";
- gf_fop_list[GF_FOP_FXATTROP] = "FXATTROP";
- gf_fop_list[GF_FOP_FSETXATTR] = "FSETXATTR";
- gf_fop_list[GF_FOP_FGETXATTR] = "FGETXATTR";
- gf_fop_list[GF_FOP_RCHECKSUM] = "RCHECKSUM";
- gf_fop_list[GF_FOP_SETATTR] = "SETATTR";
- gf_fop_list[GF_FOP_FSETATTR] = "FSETATTR";
- gf_fop_list[GF_FOP_READDIRP] = "READDIRP";
- gf_fop_list[GF_FOP_GETSPEC] = "GETSPEC";
- gf_fop_list[GF_FOP_FORGET] = "FORGET";
- gf_fop_list[GF_FOP_RELEASE] = "RELEASE";
- gf_fop_list[GF_FOP_RELEASEDIR] = "RELEASEDIR";
-
- gf_fop_list[GF_MGMT_NULL] = "NULL";
- return;
-}
-
-
+const char *gf_fop_list[GF_FOP_MAXVALUE] = {
+ [GF_FOP_NULL] = "NULL",
+ [GF_FOP_STAT] = "STAT",
+ [GF_FOP_READLINK] = "READLINK",
+ [GF_FOP_MKNOD] = "MKNOD",
+ [GF_FOP_MKDIR] = "MKDIR",
+ [GF_FOP_UNLINK] = "UNLINK",
+ [GF_FOP_RMDIR] = "RMDIR",
+ [GF_FOP_SYMLINK] = "SYMLINK",
+ [GF_FOP_RENAME] = "RENAME",
+ [GF_FOP_LINK] = "LINK",
+ [GF_FOP_TRUNCATE] = "TRUNCATE",
+ [GF_FOP_OPEN] = "OPEN",
+ [GF_FOP_READ] = "READ",
+ [GF_FOP_WRITE] = "WRITE",
+ [GF_FOP_STATFS] = "STATFS",
+ [GF_FOP_FLUSH] = "FLUSH",
+ [GF_FOP_FSYNC] = "FSYNC",
+ [GF_FOP_SETXATTR] = "SETXATTR",
+ [GF_FOP_GETXATTR] = "GETXATTR",
+ [GF_FOP_REMOVEXATTR] = "REMOVEXATTR",
+ [GF_FOP_OPENDIR] = "OPENDIR",
+ [GF_FOP_FSYNCDIR] = "FSYNCDIR",
+ [GF_FOP_ACCESS] = "ACCESS",
+ [GF_FOP_CREATE] = "CREATE",
+ [GF_FOP_FTRUNCATE] = "FTRUNCATE",
+ [GF_FOP_FSTAT] = "FSTAT",
+ [GF_FOP_LK] = "LK",
+ [GF_FOP_LOOKUP] = "LOOKUP",
+ [GF_FOP_READDIR] = "READDIR",
+ [GF_FOP_INODELK] = "INODELK",
+ [GF_FOP_FINODELK] = "FINODELK",
+ [GF_FOP_ENTRYLK] = "ENTRYLK",
+ [GF_FOP_FENTRYLK] = "FENTRYLK",
+ [GF_FOP_XATTROP] = "XATTROP",
+ [GF_FOP_FXATTROP] = "FXATTROP",
+ [GF_FOP_FSETXATTR] = "FSETXATTR",
+ [GF_FOP_FGETXATTR] = "FGETXATTR",
+ [GF_FOP_RCHECKSUM] = "RCHECKSUM",
+ [GF_FOP_SETATTR] = "SETATTR",
+ [GF_FOP_FSETATTR] = "FSETATTR",
+ [GF_FOP_READDIRP] = "READDIRP",
+ [GF_FOP_GETSPEC] = "GETSPEC",
+ [GF_FOP_FORGET] = "FORGET",
+ [GF_FOP_RELEASE] = "RELEASE",
+ [GF_FOP_RELEASEDIR] = "RELEASEDIR",
+ [GF_FOP_FREMOVEXATTR]= "FREMOVEXATTR",
+};
/* THIS */
xlator_t global_xlator;
@@ -173,45 +160,40 @@ glusterfs_this_set (xlator_t *this)
/* SYNCTASK */
-static pthread_key_t synctask_key;
-
-
int
-synctask_init ()
+synctask_init (glusterfs_ctx_t *ctx)
{
int ret = 0;
- ret = pthread_key_create (&synctask_key, NULL);
+ ret = pthread_key_create (&ctx->synctask_key, NULL);
return ret;
}
void *
-synctask_get ()
+synctask_get (glusterfs_ctx_t *ctx)
{
void *synctask = NULL;
- synctask = pthread_getspecific (synctask_key);
+ synctask = pthread_getspecific (ctx->synctask_key);
return synctask;
}
int
-synctask_set (void *synctask)
+synctask_set (glusterfs_ctx_t *ctx, void *synctask)
{
int ret = 0;
- pthread_setspecific (synctask_key, synctask);
+ pthread_setspecific (ctx->synctask_key, synctask);
return ret;
}
//UUID_BUFFER
-static pthread_key_t uuid_buf_key;
-static char global_uuid_buf[GF_UUID_BUF_SIZE];
void
glusterfs_uuid_buf_destroy (void *ptr)
{
@@ -219,35 +201,33 @@ glusterfs_uuid_buf_destroy (void *ptr)
}
int
-glusterfs_uuid_buf_init ()
+glusterfs_uuid_buf_init (glusterfs_ctx_t *ctx)
{
int ret = 0;
- ret = pthread_key_create (&uuid_buf_key,
+ ret = pthread_key_create (&ctx->uuid_buf_key,
glusterfs_uuid_buf_destroy);
return ret;
}
char *
-glusterfs_uuid_buf_get ()
+glusterfs_uuid_buf_get (glusterfs_ctx_t *ctx)
{
char *buf;
int ret = 0;
- buf = pthread_getspecific (uuid_buf_key);
+ buf = pthread_getspecific (ctx->uuid_buf_key);
if(!buf) {
buf = MALLOC (GF_UUID_BUF_SIZE);
- ret = pthread_setspecific (uuid_buf_key, (void *) buf);
- if(ret)
- buf = global_uuid_buf;
+ ret = pthread_setspecific (ctx->uuid_buf_key, (void *) buf);
+ if (ret)
+ buf = ctx->uuid_buf;
}
return buf;
}
/* LKOWNER_BUFFER */
-static pthread_key_t lkowner_buf_key;
-static char global_lkowner_buf[GF_LKOWNER_BUF_SIZE];
void
glusterfs_lkowner_buf_destroy (void *ptr)
{
@@ -255,39 +235,37 @@ glusterfs_lkowner_buf_destroy (void *ptr)
}
int
-glusterfs_lkowner_buf_init ()
+glusterfs_lkowner_buf_init (glusterfs_ctx_t *ctx)
{
int ret = 0;
- ret = pthread_key_create (&lkowner_buf_key,
+ ret = pthread_key_create (&ctx->lkowner_buf_key,
glusterfs_lkowner_buf_destroy);
return ret;
}
char *
-glusterfs_lkowner_buf_get ()
+glusterfs_lkowner_buf_get (glusterfs_ctx_t *ctx)
{
char *buf;
int ret = 0;
- buf = pthread_getspecific (lkowner_buf_key);
+ buf = pthread_getspecific (ctx->lkowner_buf_key);
if(!buf) {
buf = MALLOC (GF_LKOWNER_BUF_SIZE);
- ret = pthread_setspecific (lkowner_buf_key, (void *) buf);
- if(ret)
- buf = global_lkowner_buf;
+ ret = pthread_setspecific (ctx->lkowner_buf_key, (void *) buf);
+ if (ret)
+ buf = ctx->lkowner_buf;
}
return buf;
}
int
-glusterfs_globals_init ()
+glusterfs_globals_init (glusterfs_ctx_t *ctx)
{
int ret = 0;
- gf_op_list_init ();
-
- gf_log_globals_init ();
+ gf_log_globals_init (ctx);
ret = glusterfs_this_init ();
if (ret) {
@@ -296,23 +274,21 @@ glusterfs_globals_init ()
goto out;
}
- ret = glusterfs_uuid_buf_init ();
+ ret = glusterfs_uuid_buf_init (ctx);
if(ret) {
gf_log ("", GF_LOG_CRITICAL,
"ERROR: glusterfs uuid buffer init failed");
goto out;
}
- ret = glusterfs_lkowner_buf_init ();
+ ret = glusterfs_lkowner_buf_init (ctx);
if(ret) {
gf_log ("", GF_LOG_CRITICAL,
"ERROR: glusterfs lkowner buffer init failed");
goto out;
}
- gf_mem_acct_enable_set ();
-
- ret = synctask_init ();
+ ret = synctask_init (ctx);
if (ret) {
gf_log ("", GF_LOG_CRITICAL,
"ERROR: glusterfs synctask init failed");
@@ -321,31 +297,3 @@ glusterfs_globals_init ()
out:
return ret;
}
-
-
-char eventstring[GF_EVENT_MAXVAL+1][64] = {
- "Invalid event",
- "Parent Up",
- "Poll In",
- "Poll Out",
- "Poll Err",
- "Child Up",
- "Child Down",
- "Child Connecting",
- "Child Modified",
- "Transport Cleanup",
- "Transport Connected",
- "Volfile Modified",
- "New Volfile",
- "Translator Info",
- "Xlator Op",
- "Authentication Failed",
- "Invalid event",
-};
-
-/* Copy the string ptr contents if needed for yourself */
-char *
-glusterfs_strevent (glusterfs_event_t ev)
-{
- return eventstring[ev];
-}
diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h
index 7ccdb4a14..47a81afb8 100644
--- a/libglusterfs/src/globals.h
+++ b/libglusterfs/src/globals.h
@@ -18,21 +18,22 @@
/* THIS */
#define THIS (*__glusterfs_this_location())
-#define GF_UUID_BUF_SIZE 50
-
xlator_t **__glusterfs_this_location ();
xlator_t *glusterfs_this_get ();
int glusterfs_this_set (xlator_t *);
/* task */
void *synctask_get ();
-int synctask_set (void *);
+int synctask_set (glusterfs_ctx_t *, void *);
/* uuid_buf */
-char *glusterfs_uuid_buf_get();
-char *glusterfs_lkowner_buf_get();
+char *glusterfs_uuid_buf_get(glusterfs_ctx_t *);
+/* lkowner_buf */
+char *glusterfs_lkowner_buf_get(glusterfs_ctx_t *);
/* init */
-int glusterfs_globals_init (void);
+int glusterfs_globals_init (glusterfs_ctx_t *ctx);
+
+extern const char *gf_fop_list[];
#endif /* !_GLOBALS_H */
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
index ad3bae14b..70a50af6a 100644
--- a/libglusterfs/src/glusterfs.h
+++ b/libglusterfs/src/glusterfs.h
@@ -33,9 +33,9 @@
#include <sys/poll.h>
#include <pthread.h>
-
#include "list.h"
#include "logging.h"
+#include "lkowner.h"
#define GF_YES 1
#define GF_NO 0
@@ -134,6 +134,8 @@
* we have to add aux-gid in payload of actors */
#define GF_MAX_AUX_GROUPS 200
+#define GF_UUID_BUF_SIZE 50
+
/* NOTE: add members ONLY at the end (just before _MAXVALUE) */
typedef enum {
GF_FOP_NULL = 0,
@@ -379,14 +381,21 @@ struct _glusterfs_ctx {
glusterfsd_mgmt_event_notify_fn_t notify; /* Used for xlators to make
call to fsd-mgmt */
+ gf_log_handle_t log; /* all logging related variables */
+
+ pthread_key_t synctask_key;
+ pthread_key_t uuid_buf_key;
+ char uuid_buf[GF_UUID_BUF_SIZE];
+ pthread_key_t lkowner_buf_key;
+ char lkowner_buf[GF_LKOWNER_BUF_SIZE];
+
+ int mem_acct_enable;
+
};
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.
- */
typedef enum {
GF_EVENT_PARENT_UP = 1,
GF_EVENT_POLLIN,
@@ -408,9 +417,6 @@ typedef enum {
GF_EVENT_MAXVAL,
} glusterfs_event_t;
-/* gf_lkowner_t is defined in lkowner.h */
-#include "lkowner.h"
-
struct gf_flock {
short l_type;
short l_whence;
@@ -420,8 +426,6 @@ struct gf_flock {
gf_lkowner_t l_owner;
};
-extern char *glusterfs_strevent (glusterfs_event_t ev);
-
#define GF_MUST_CHECK __attribute__((warn_unused_result))
/*
* Some macros (e.g. ALLOC_OR_GOTO) set variables in function scope, but the
diff --git a/libglusterfs/src/latency.c b/libglusterfs/src/latency.c
index f7747b392..f143a8e46 100644
--- a/libglusterfs/src/latency.c
+++ b/libglusterfs/src/latency.c
@@ -148,7 +148,8 @@ gf_proc_dump_latency_info (xlator_t *xl)
gf_proc_dump_add_section (key_prefix);
for (i = 0; i < GF_FOP_MAXVALUE; i++) {
- gf_proc_dump_build_key (key, key_prefix, gf_fop_list[i]);
+ gf_proc_dump_build_key (key, key_prefix,
+ (char *)gf_fop_list[i]);
gf_proc_dump_write (key, "%.03f,%"PRId64",%.03f",
xl->latencies[i].mean,
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
index fc80f91d8..40981b526 100644
--- a/libglusterfs/src/logging.c
+++ b/libglusterfs/src/logging.c
@@ -25,6 +25,7 @@
#include "xlator.h"
#include "logging.h"
#include "defaults.h"
+#include "glusterfs.h"
#ifdef GF_LINUX_HOST_OS
#include <syslog.h>
@@ -34,50 +35,44 @@
#include <execinfo.h>
#endif
+/* Ideally this should get moved to logging.h */
+struct _msg_queue {
+ struct list_head msgs;
+};
-static pthread_mutex_t logfile_mutex;
-static char *filename = NULL;
-static uint8_t logrotate = 0;
-static FILE *logfile = NULL;
-static gf_loglevel_t loglevel = GF_LOG_INFO;
-static int gf_log_syslog = 1;
-static gf_loglevel_t sys_log_level = GF_LOG_CRITICAL;
-
-char gf_log_xl_log_set;
-gf_loglevel_t gf_log_loglevel = GF_LOG_INFO; /* extern'd */
-FILE *gf_log_logfile;
-
-static char *cmd_log_filename = NULL;
-static FILE *cmdlogfile = NULL;
+struct _log_msg {
+ const char *msg;
+ struct list_head queue;
+};
void
gf_log_logrotate (int signum)
{
- logrotate = 1;
+ THIS->ctx->log.logrotate = 1;
}
void
gf_log_enable_syslog (void)
{
- gf_log_syslog = 1;
+ THIS->ctx->log.gf_log_syslog = 1;
}
void
gf_log_disable_syslog (void)
{
- gf_log_syslog = 0;
+ THIS->ctx->log.gf_log_syslog = 0;
}
gf_loglevel_t
gf_log_get_loglevel (void)
{
- return loglevel;
+ return THIS->ctx->log.loglevel;
}
void
gf_log_set_loglevel (gf_loglevel_t level)
{
- gf_log_loglevel = loglevel = level;
+ THIS->ctx->log.loglevel = level;
}
@@ -96,21 +91,27 @@ gf_log_set_xl_loglevel (void *this, gf_loglevel_t level)
xlator_t *xl = this;
if (!xl)
return;
- gf_log_xl_log_set = 1;
+ xl->ctx->log.gf_log_xl_log_set = 1;
xl->loglevel = level;
}
void
gf_log_fini (void)
{
- pthread_mutex_destroy (&logfile_mutex);
+ pthread_mutex_destroy (&THIS->ctx->log.logfile_mutex);
}
void
-gf_log_globals_init (void)
+gf_log_globals_init (void *data)
{
- pthread_mutex_init (&logfile_mutex, NULL);
+ glusterfs_ctx_t *ctx = data;
+
+ pthread_mutex_init (&ctx->log.logfile_mutex, NULL);
+
+ ctx->log.loglevel = GF_LOG_INFO;
+ ctx->log.gf_log_syslog = 1;
+ ctx->log.sys_log_level = GF_LOG_CRITICAL;
#ifdef GF_LINUX_HOST_OS
/* For the 'syslog' output. one can grep 'GlusterFS' in syslog
@@ -120,23 +121,26 @@ gf_log_globals_init (void)
}
int
-gf_log_init (const char *file)
+gf_log_init (void *data, const char *file)
{
+ glusterfs_ctx_t *ctx = NULL;
int fd = -1;
+ ctx = data;
+
if (!file){
fprintf (stderr, "ERROR: no filename specified\n");
return -1;
}
if (strcmp (file, "-") == 0) {
- gf_log_logfile = stderr;
+ ctx->log.gf_log_logfile = stderr;
return 0;
}
- filename = gf_strdup (file);
- if (!filename) {
+ ctx->log.filename = gf_strdup (file);
+ if (!ctx->log.filename) {
fprintf (stderr, "ERROR: updating log-filename failed: %s\n",
strerror (errno));
return -1;
@@ -150,54 +154,22 @@ gf_log_init (const char *file)
}
close (fd);
- logfile = fopen (file, "a");
- if (!logfile){
+ ctx->log.logfile = fopen (file, "a");
+ if (!ctx->log.logfile){
fprintf (stderr, "ERROR: failed to open logfile \"%s\" (%s)\n",
file, strerror (errno));
return -1;
}
- gf_log_logfile = logfile;
+ ctx->log.gf_log_logfile = ctx->log.logfile;
return 0;
}
-
-
-struct _msg_queue {
- struct list_head msgs;
-};
-
-struct _log_msg {
- const char *msg;
- struct list_head queue;
-};
-
-
-void
-gf_log_lock (void)
-{
- pthread_mutex_lock (&logfile_mutex);
-}
-
-
-void
-gf_log_unlock (void)
-{
- pthread_mutex_unlock (&logfile_mutex);
-}
-
-
-void
-gf_log_cleanup (void)
-{
- pthread_mutex_destroy (&logfile_mutex);
-}
-
void
set_sys_log_level (gf_loglevel_t level)
{
- sys_log_level = level;
+ THIS->ctx->log.sys_log_level = level;
}
int
@@ -212,13 +184,15 @@ _gf_log_nomem (const char *domain, const char *file,
char msg[8092] = {0,};
char timestr[256] = {0,};
char callstr[4096] = {0,};
+ glusterfs_ctx_t *ctx = NULL;
this = THIS;
+ ctx = this->ctx;
- if (gf_log_xl_log_set) {
+ if (ctx->log.gf_log_xl_log_set) {
if (this->loglevel && (level > this->loglevel))
goto out;
- else if (level > gf_log_loglevel)
+ else if (level > ctx->log.loglevel)
goto out;
}
@@ -289,11 +263,10 @@ _gf_log_nomem (const char *domain, const char *file,
goto out;
}
- pthread_mutex_lock (&logfile_mutex);
+ pthread_mutex_lock (&ctx->log.logfile_mutex);
{
- if (logfile) {
- fprintf (logfile, "%s\n", msg);
- fflush (logfile);
+ if (ctx->log.logfile) {
+ fprintf (ctx->log.logfile, "%s\n", msg);
} else {
fprintf (stderr, "%s\n", msg);
}
@@ -301,12 +274,13 @@ _gf_log_nomem (const char *domain, const char *file,
#ifdef GF_LINUX_HOST_OS
/* We want only serious log in 'syslog', not our debug
and trace logs */
- if (gf_log_syslog && level && (level <= sys_log_level))
+ if (ctx->log.gf_log_syslog && level &&
+ (level <= ctx->log.sys_log_level))
syslog ((level-1), "%s\n", msg);
#endif
}
- pthread_mutex_unlock (&logfile_mutex);
+ pthread_mutex_unlock (&ctx->log.logfile_mutex);
out:
return ret;
}
@@ -326,13 +300,15 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,
size_t len = 0;
int ret = 0;
va_list ap;
+ glusterfs_ctx_t *ctx = NULL;
this = THIS;
+ ctx = this->ctx;
- if (gf_log_xl_log_set) {
+ if (ctx->log.gf_log_xl_log_set) {
if (this->loglevel && (level > this->loglevel))
goto out;
- else if (level > gf_log_loglevel)
+ else if (level > ctx->log.loglevel)
goto out;
}
@@ -416,11 +392,10 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,
strcpy (msg, str1);
strcpy (msg + len, str2);
- pthread_mutex_lock (&logfile_mutex);
+ pthread_mutex_lock (&ctx->log.logfile_mutex);
{
- if (logfile) {
- fprintf (logfile, "%s\n", msg);
- fflush (logfile);
+ if (ctx->log.logfile) {
+ fprintf (ctx->log.logfile, "%s\n", msg);
} else {
fprintf (stderr, "%s\n", msg);
}
@@ -428,12 +403,13 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,
#ifdef GF_LINUX_HOST_OS
/* We want only serious log in 'syslog', not our debug
and trace logs */
- if (gf_log_syslog && level && (level <= sys_log_level))
+ if (ctx->log.gf_log_syslog && level &&
+ (level <= ctx->log.sys_log_level))
syslog ((level-1), "%s\n", msg);
#endif
}
- pthread_mutex_unlock (&logfile_mutex);
+ pthread_mutex_unlock (&ctx->log.logfile_mutex);
out:
GF_FREE (msg);
@@ -461,13 +437,15 @@ _gf_log (const char *domain, const char *file, const char *function, int line,
int ret = 0;
int fd = -1;
xlator_t *this = NULL;
+ glusterfs_ctx_t *ctx = NULL;
this = THIS;
+ ctx = this->ctx;
- if (gf_log_xl_log_set) {
+ if (ctx->log.gf_log_xl_log_set) {
if (this->loglevel && (level > this->loglevel))
goto out;
- else if (level > gf_log_loglevel)
+ else if (level > ctx->log.loglevel)
goto out;
}
@@ -491,10 +469,11 @@ _gf_log (const char *domain, const char *file, const char *function, int line,
}
- if (logrotate) {
- logrotate = 0;
+ if (ctx->log.logrotate) {
+ ctx->log.logrotate = 0;
- fd = open (filename, O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR);
+ fd = open (ctx->log.filename,
+ O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR);
if (fd < 0) {
gf_log ("logrotate", GF_LOG_ERROR,
"%s", strerror (errno));
@@ -502,22 +481,22 @@ _gf_log (const char *domain, const char *file, const char *function, int line,
}
close (fd);
- new_logfile = fopen (filename, "a");
+ new_logfile = fopen (ctx->log.filename, "a");
if (!new_logfile) {
gf_log ("logrotate", GF_LOG_CRITICAL,
"failed to open logfile %s (%s)",
- filename, strerror (errno));
+ ctx->log.filename, strerror (errno));
goto log;
}
- pthread_mutex_lock (&logfile_mutex);
+ pthread_mutex_lock (&ctx->log.logfile_mutex);
{
- if (logfile)
- fclose (logfile);
+ if (ctx->log.logfile)
+ fclose (ctx->log.logfile);
- gf_log_logfile = logfile = new_logfile;
+ ctx->log.gf_log_logfile = ctx->log.logfile = new_logfile;
}
- pthread_mutex_unlock (&logfile_mutex);
+ pthread_mutex_unlock (&ctx->log.logfile_mutex);
}
@@ -557,12 +536,11 @@ log:
strcpy (msg, str1);
strcpy (msg + len, str2);
- pthread_mutex_lock (&logfile_mutex);
+ pthread_mutex_lock (&ctx->log.logfile_mutex);
{
- if (logfile) {
- fprintf (logfile, "%s\n", msg);
- fflush (logfile);
+ if (ctx->log.logfile) {
+ fprintf (ctx->log.logfile, "%s\n", msg);
} else {
fprintf (stderr, "%s\n", msg);
}
@@ -570,12 +548,13 @@ log:
#ifdef GF_LINUX_HOST_OS
/* We want only serious log in 'syslog', not our debug
and trace logs */
- if (gf_log_syslog && level && (level <= sys_log_level))
+ if (ctx->log.gf_log_syslog && level &&
+ (level <= ctx->log.sys_log_level))
syslog ((level-1), "%s\n", msg);
#endif
}
- pthread_mutex_unlock (&logfile_mutex);
+ pthread_mutex_unlock (&ctx->log.logfile_mutex);
err:
GF_FREE (msg);
@@ -639,8 +618,10 @@ gf_cmd_log_init (const char *filename)
{
int fd = -1;
xlator_t *this = NULL;
+ glusterfs_ctx_t *ctx = NULL;
this = THIS;
+ ctx = this->ctx;
if (!filename){
gf_log (this->name, GF_LOG_CRITICAL, "gf_cmd_log_init: no "
@@ -648,19 +629,20 @@ gf_cmd_log_init (const char *filename)
return -1;
}
- cmd_log_filename = gf_strdup (filename);
- if (!cmd_log_filename) {
+ ctx->log.cmd_log_filename = gf_strdup (filename);
+ if (!ctx->log.cmd_log_filename) {
gf_log (this->name, GF_LOG_CRITICAL,
"gf_cmd_log_init: strdup error\n");
return -1;
}
/* close and reopen cmdlogfile for log rotate*/
- if (cmdlogfile) {
- fclose (cmdlogfile);
- cmdlogfile = NULL;
+ if (ctx->log.cmdlogfile) {
+ fclose (ctx->log.cmdlogfile);
+ ctx->log.cmdlogfile = NULL;
}
- fd = open (cmd_log_filename, O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR);
+ fd = open (ctx->log.cmd_log_filename,
+ O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR);
if (fd < 0) {
gf_log (this->name, GF_LOG_CRITICAL,
"%s", strerror (errno));
@@ -668,11 +650,11 @@ gf_cmd_log_init (const char *filename)
}
close (fd);
- cmdlogfile = fopen (cmd_log_filename, "a");
- if (!cmdlogfile){
+ ctx->log.cmdlogfile = fopen (ctx->log.cmd_log_filename, "a");
+ if (!ctx->log.cmdlogfile){
gf_log (this->name, GF_LOG_CRITICAL,
"gf_cmd_log_init: failed to open logfile \"%s\" "
- "(%s)\n", cmd_log_filename, strerror (errno));
+ "(%s)\n", ctx->log.cmd_log_filename, strerror (errno));
return -1;
}
return 0;
@@ -689,8 +671,10 @@ gf_cmd_log (const char *domain, const char *fmt, ...)
char *msg = NULL;
size_t len = 0;
int ret = 0;
+ glusterfs_ctx_t *ctx = NULL;
- if (!cmdlogfile)
+ ctx = THIS->ctx;
+ if (!ctx->log.cmdlogfile)
return -1;
@@ -727,8 +711,8 @@ gf_cmd_log (const char *domain, const char *fmt, ...)
strcpy (msg, str1);
strcpy (msg + len, str2);
- fprintf (cmdlogfile, "%s\n", msg);
- fflush (cmdlogfile);
+ fprintf (ctx->log.cmdlogfile, "%s\n", msg);
+ fflush (ctx->log.cmdlogfile);
out:
GF_FREE (msg);
diff --git a/libglusterfs/src/logging.h b/libglusterfs/src/logging.h
index 0d290bd5a..53eb5b722 100644
--- a/libglusterfs/src/logging.h
+++ b/libglusterfs/src/logging.h
@@ -59,29 +59,60 @@ typedef enum {
GF_LOG_TRACE, /* full trace of operation */
} gf_loglevel_t;
-extern gf_loglevel_t gf_log_loglevel;
-extern char gf_log_xl_log_set;
+typedef struct gf_log_handle_ {
+ pthread_mutex_t logfile_mutex;
+ uint8_t logrotate;
+ gf_loglevel_t loglevel;
+ int gf_log_syslog;
+ gf_loglevel_t sys_log_level;
+ char gf_log_xl_log_set;
+ char *filename;
+ FILE *logfile;
+ FILE *gf_log_logfile;
+ char *cmd_log_filename;
+ FILE *cmdlogfile;
+
+} gf_log_handle_t;
+
+void gf_log_globals_init (void *ctx);
+int gf_log_init (void *data, const char *filename);
+
+void gf_log_logrotate (int signum);
+
+void gf_log_cleanup (void);
+
+int _gf_log (const char *domain, const char *file,
+ const char *function, int32_t line, gf_loglevel_t level,
+ const char *fmt, ...)
+ __attribute__ ((__format__ (__printf__, 6, 7)));
+int _gf_log_callingfn (const char *domain, const char *file,
+ const char *function, int32_t line, gf_loglevel_t level,
+ const char *fmt, ...)
+ __attribute__ ((__format__ (__printf__, 6, 7)));
+
+int _gf_log_nomem (const char *domain, const char *file,
+ const char *function, int line, gf_loglevel_t level,
+ size_t size);
+
+int _gf_log_eh (const char *function, const char *fmt, ...);
+
+
#define FMT_WARN(fmt...) do { if (0) printf (fmt); } while (0)
#define gf_log(dom, levl, fmt...) do { \
FMT_WARN (fmt); \
- \
- if ((levl > gf_log_loglevel) && !gf_log_xl_log_set) \
- break; \
_gf_log (dom, __FILE__, __FUNCTION__, __LINE__, \
levl, ##fmt); \
} while (0)
#define gf_log_eh(fmt...) do { \
- _gf_log_eh (__FUNTION__, ##fmt); \
+ FMT_WARN (fmt); \
+ _gf_log_eh (__FUNTION__, ##fmt); \
} while (0)
#define gf_log_callingfn(dom, levl, fmt...) do { \
FMT_WARN (fmt); \
- \
- if ((levl > gf_log_loglevel) && !gf_log_xl_log_set) \
- break; \
_gf_log_callingfn (dom, __FILE__, __FUNCTION__, __LINE__, \
levl, ##fmt); \
} while (0)
@@ -89,8 +120,6 @@ extern char gf_log_xl_log_set;
/* No malloc or calloc should be called in this function */
#define gf_log_nomem(dom, levl, size) do { \
- if ((levl > gf_log_loglevel) && !gf_log_xl_log_set) \
- break; \
_gf_log_nomem (dom, __FILE__, __FUNCTION__, __LINE__, \
levl, size); \
} while (0)
@@ -101,33 +130,6 @@ extern char gf_log_xl_log_set;
gf_log (args); \
}
-
-void gf_log_logrotate (int signum);
-
-void gf_log_globals_init (void);
-int gf_log_init (const char *filename);
-void gf_log_cleanup (void);
-
-int _gf_log (const char *domain, const char *file,
- const char *function, int32_t line, gf_loglevel_t level,
- const char *fmt, ...)
- __attribute__ ((__format__ (__printf__, 6, 7)));
-int _gf_log_callingfn (const char *domain, const char *file,
- const char *function, int32_t line, gf_loglevel_t level,
- const char *fmt, ...)
- __attribute__ ((__format__ (__printf__, 6, 7)));
-
-int _gf_log_nomem (const char *domain, const char *file,
- const char *function, int line, gf_loglevel_t level,
- size_t size);
-
-int _gf_log_eh (const char *function, const char *fmt, ...);
-
-int gf_log_from_client (const char *msg, char *identifier);
-
-void gf_log_lock (void);
-void gf_log_unlock (void);
-
void gf_log_disable_syslog (void);
void gf_log_enable_syslog (void);
gf_loglevel_t gf_log_get_loglevel (void);
@@ -135,6 +137,13 @@ void gf_log_set_loglevel (gf_loglevel_t level);
gf_loglevel_t gf_log_get_xl_loglevel (void *xl);
void gf_log_set_xl_loglevel (void *xl, gf_loglevel_t level);
+int gf_cmd_log (const char *domain, const char *fmt, ...)
+ __attribute__ ((__format__ (__printf__, 2, 3)));
+
+int gf_cmd_log_init (const char *filename);
+
+void set_sys_log_level (gf_loglevel_t level);
+
#define GF_DEBUG(xl, format, args...) \
gf_log ((xl)->name, GF_LOG_DEBUG, format, ##args)
#define GF_INFO(xl, format, args...) \
@@ -144,10 +153,4 @@ void gf_log_set_xl_loglevel (void *xl, gf_loglevel_t level);
#define GF_ERROR(xl, format, args...) \
gf_log ((xl)->name, GF_LOG_ERROR, format, ##args)
-int gf_cmd_log (const char *domain, const char *fmt, ...)
- __attribute__ ((__format__ (__printf__, 2, 3)));
-
-int gf_cmd_log_init (const char *filename);
-
-void set_sys_log_level (gf_loglevel_t level);
#endif /* __LOGGING_H__ */
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index 50f8fef5a..755e73944 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -30,22 +30,16 @@
#define GLUSTERFS_ENV_MEM_ACCT_STR "GLUSTERFS_DISABLE_MEM_ACCT"
-static int gf_mem_acct_enable = 0;
-
-int
-gf_mem_acct_is_enabled ()
-{
- return gf_mem_acct_enable;
-}
-
-
void
-gf_mem_acct_enable_set ()
+gf_mem_acct_enable_set (void *data)
{
char *opt = NULL;
long val = -1;
+ glusterfs_ctx_t *ctx = NULL;
+
+ ctx = data;
- if (gf_mem_acct_enable) {
+ if (ctx->mem_acct_enable) {
return;
}
@@ -53,7 +47,7 @@ gf_mem_acct_enable_set ()
if (opt) {
val = strtol (opt, NULL, 0);
if (val)
- gf_mem_acct_enable = 1;
+ ctx->mem_acct_enable = 1;
}
return;
@@ -115,7 +109,7 @@ __gf_calloc (size_t nmemb, size_t size, uint32_t type)
char *ptr = NULL;
xlator_t *xl = NULL;
- if (!gf_mem_acct_enable)
+ if (!THIS->ctx->mem_acct_enable)
return CALLOC (nmemb, size);
xl = THIS;
@@ -141,7 +135,7 @@ __gf_malloc (size_t size, uint32_t type)
char *ptr = NULL;
xlator_t *xl = NULL;
- if (!gf_mem_acct_enable)
+ if (!THIS->ctx->mem_acct_enable)
return MALLOC (size);
xl = THIS;
@@ -166,7 +160,7 @@ __gf_realloc (void *ptr, size_t size)
xlator_t *xl = NULL;
uint32_t type = 0;
- if (!gf_mem_acct_enable)
+ if (!THIS->ctx->mem_acct_enable)
return REALLOC (ptr, size);
tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE;
@@ -239,7 +233,7 @@ __gf_free (void *free_ptr)
uint32_t type = 0;
xlator_t *xl = NULL;
- if (!gf_mem_acct_enable) {
+ if (!THIS->ctx->mem_acct_enable) {
FREE (free_ptr);
return;
}
diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h
index b3a25b25e..4361c936d 100644
--- a/libglusterfs/src/mem-pool.h
+++ b/libglusterfs/src/mem-pool.h
@@ -157,7 +157,6 @@ void *mem_get0 (struct mem_pool *pool);
void mem_pool_destroy (struct mem_pool *pool);
-int gf_mem_acct_is_enabled ();
-void gf_mem_acct_enable_set ();
+void gf_mem_acct_enable_set (void *ctx);
#endif /* _MEM_POOL_H */
diff --git a/libglusterfs/src/stack.c b/libglusterfs/src/stack.c
index 1579e0974..5349eaa0b 100644
--- a/libglusterfs/src/stack.c
+++ b/libglusterfs/src/stack.c
@@ -103,7 +103,8 @@ gf_proc_dump_call_stack (call_stack_t *call_stack, const char *key_buf,...)
gf_proc_dump_write("lk-owner", "%s", lkowner_utoa (&call_stack->lk_owner));
if (call_stack->type == GF_OP_TYPE_FOP)
- gf_proc_dump_write("op", "%s", gf_fop_list[call_stack->op]);
+ gf_proc_dump_write("op", "%s",
+ (char *)gf_fop_list[call_stack->op]);
else
gf_proc_dump_write("op", "stack");
@@ -277,7 +278,7 @@ gf_proc_dump_call_stack_to_dict (call_stack_t *call_stack,
snprintf (key, sizeof (key), "%s.op", prefix);
if (call_stack->type == GF_OP_TYPE_FOP)
ret = dict_set_str (dict, key,
- gf_fop_list[call_stack->op]);
+ (char *)gf_fop_list[call_stack->op]);
else
ret = dict_set_str (dict, key, "other");
diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c
index 7b34c631d..95d6087f4 100644
--- a/libglusterfs/src/syncop.c
+++ b/libglusterfs/src/syncop.c
@@ -284,7 +284,7 @@ synctask_switchto (struct synctask *task)
env = task->env;
- synctask_set (task);
+ synctask_set (THIS->ctx, task);
THIS = task->xl;
task->woken = 0;
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index 7094f1ef5..6db27e9a4 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -460,12 +460,12 @@ xlator_mem_acct_init (xlator_t *xl, int num_types)
int i = 0;
int ret = 0;
- if (!gf_mem_acct_is_enabled ())
- return 0;
-
if (!xl)
return -1;
+ if (!xl->ctx->mem_acct_enable)
+ return 0;
+
xl->mem_acct.num_types = num_types;
xl->mem_acct.rec = CALLOC(num_types, sizeof(struct mem_acct_rec));
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
index 5162d20e5..eaaa44724 100644
--- a/libglusterfs/src/xlator.h
+++ b/libglusterfs/src/xlator.h
@@ -880,4 +880,5 @@ enum gf_hdsk_event_notify_op {
GF_EN_DEFRAG_STATUS,
GF_EN_MAX,
};
+
#endif /* _XLATOR_H */