summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2011-03-16 09:37:55 +0000
committerVijay Bellur <vijay@dev.gluster.com>2011-03-17 11:57:04 -0700
commitce01662eefb575d1afe397486653920ec101f40f (patch)
tree671f2eaad1efaf80c4f0d8a45c8c6c94dd6131c4 /libglusterfs
parentb44b06a9d0adb50b426e0ee195a9867e01240ada (diff)
libglusterfs: logging/mem-pool section white-space cleanup
Signed-off-by: Amar Tumballi <amar@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 2346 (Log message enhancements in GlusterFS - phase 1) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2346
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/logging.c250
-rw-r--r--libglusterfs/src/logging.h35
-rw-r--r--libglusterfs/src/mem-pool.c256
-rw-r--r--libglusterfs/src/mem-pool.h28
4 files changed, 283 insertions, 286 deletions
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
index 78bd1d6..ed02484 100644
--- a/libglusterfs/src/logging.c
+++ b/libglusterfs/src/logging.c
@@ -61,7 +61,7 @@ static FILE *cmdlogfile = NULL;
void
gf_log_logrotate (int signum)
{
- logrotate = 1;
+ logrotate = 1;
}
void
@@ -79,7 +79,7 @@ gf_log_disable_syslog (void)
gf_loglevel_t
gf_log_get_loglevel (void)
{
- return loglevel;
+ return loglevel;
}
void
@@ -111,34 +111,34 @@ gf_log_set_xl_loglevel (void *this, gf_loglevel_t level)
void
gf_log_fini (void)
{
- pthread_mutex_destroy (&logfile_mutex);
+ pthread_mutex_destroy (&logfile_mutex);
}
int
gf_log_init (const char *file)
{
- if (!file){
- fprintf (stderr, "gf_log_init: no filename specified\n");
- return -1;
- }
+ if (!file){
+ fprintf (stderr, "gf_log_init: no filename specified\n");
+ return -1;
+ }
- pthread_mutex_init (&logfile_mutex, NULL);
+ pthread_mutex_init (&logfile_mutex, NULL);
filename = gf_strdup (file);
- if (!filename) {
- fprintf (stderr, "gf_log_init: strdup error\n");
- return -1;
- }
-
- logfile = fopen (file, "a");
- if (!logfile){
- fprintf (stderr,
- "gf_log_init: failed to open logfile \"%s\" (%s)\n",
- file,
- strerror (errno));
- return -1;
- }
+ if (!filename) {
+ fprintf (stderr, "gf_log_init: strdup error\n");
+ return -1;
+ }
+
+ logfile = fopen (file, "a");
+ if (!logfile){
+ fprintf (stderr,
+ "gf_log_init: failed to open logfile \"%s\" (%s)\n",
+ file,
+ strerror (errno));
+ return -1;
+ }
#ifdef GF_LINUX_HOST_OS
/* For the 'syslog' output. one can grep 'GlusterFS' in syslog
@@ -146,9 +146,9 @@ gf_log_init (const char *file)
openlog ("GlusterFS", LOG_PID, LOG_DAEMON);
#endif
- gf_log_logfile = logfile;
+ gf_log_logfile = logfile;
- return 0;
+ return 0;
}
@@ -175,43 +175,43 @@ struct _log_msg {
void
gf_log_lock (void)
{
- pthread_mutex_lock (&logfile_mutex);
+ pthread_mutex_lock (&logfile_mutex);
}
void
gf_log_unlock (void)
{
- pthread_mutex_unlock (&logfile_mutex);
+ pthread_mutex_unlock (&logfile_mutex);
}
void
gf_log_cleanup (void)
{
- pthread_mutex_destroy (&logfile_mutex);
+ pthread_mutex_destroy (&logfile_mutex);
}
int
_gf_log_callingfn (const char *domain, const char *file, const char *function,
int line, gf_loglevel_t level, const char *fmt, ...)
{
- const char *basename = NULL;
- struct tm *tm = NULL;
+ const char *basename = NULL;
+ struct tm *tm = NULL;
xlator_t *this = NULL;
char *str1 = NULL;
char *str2 = NULL;
char *msg = NULL;
- char timestr[256] = {0,};
- char callstr[4096] = {0,};
+ char timestr[256] = {0,};
+ char callstr[4096] = {0,};
struct timeval tv = {0,};
size_t len = 0;
int ret = 0;
gf_loglevel_t xlator_loglevel = 0;
- va_list ap;
+ va_list ap;
- if (!logfile)
- return -1;
+ if (!logfile)
+ return -1;
this = THIS;
@@ -222,33 +222,33 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,
if (level > xlator_loglevel)
goto out;
- static char *level_strings[] = {"", /* NONE */
+ static char *level_strings[] = {"", /* NONE */
"M", /* EMERGENCY */
"A", /* ALERT */
- "C", /* CRITICAL */
- "E", /* ERROR */
- "W", /* WARNING */
- "N", /* NOTICE */
+ "C", /* CRITICAL */
+ "E", /* ERROR */
+ "W", /* WARNING */
+ "N", /* NOTICE */
"I", /* INFO/NORMAL */
- "D", /* DEBUG */
+ "D", /* DEBUG */
"T", /* TRACE */
- ""};
+ ""};
- if (!domain || !file || !function || !fmt) {
- fprintf (stderr,
- "logging: %s:%s():%d: invalid argument\n",
- __FILE__, __PRETTY_FUNCTION__, __LINE__);
- return -1;
- }
+ if (!domain || !file || !function || !fmt) {
+ fprintf (stderr,
+ "logging: %s:%s():%d: invalid argument\n",
+ __FILE__, __PRETTY_FUNCTION__, __LINE__);
+ return -1;
+ }
#if HAVE_BACKTRACE
- /* Print 'calling function' */
- do {
- void *array[5];
+ /* Print 'calling function' */
+ do {
+ void *array[5];
char **callingfn = NULL;
- size_t size = 0;
+ size_t size = 0;
- size = backtrace (array, 5);
+ size = backtrace (array, 5);
if (size)
callingfn = backtrace_symbols (&array[2], size-2);
if (!callingfn)
@@ -264,28 +264,28 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,
snprintf (callstr, 4096, "(-->%s)", callingfn[0]);
free (callingfn);
- } while (0);
+ } while (0);
#endif /* HAVE_BACKTRACE */
ret = gettimeofday (&tv, NULL);
if (-1 == ret)
goto out;
- tm = localtime (&tv.tv_sec);
+ tm = localtime (&tv.tv_sec);
- pthread_mutex_lock (&logfile_mutex);
- {
- va_start (ap, fmt);
+ pthread_mutex_lock (&logfile_mutex);
+ {
+ va_start (ap, fmt);
- strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm);
+ strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm);
snprintf (timestr + strlen (timestr), 256 - strlen (timestr),
".%"GF_PRI_SUSECONDS, tv.tv_usec);
- basename = strrchr (file, '/');
- if (basename)
- basename++;
- else
- basename = file;
+ basename = strrchr (file, '/');
+ if (basename)
+ basename++;
+ else
+ basename = file;
ret = gf_asprintf (&str1, "[%s] %s [%s:%d:%s] %s %s: ",
timestr, level_strings[level],
@@ -300,7 +300,7 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,
goto unlock;
}
- va_end (ap);
+ va_end (ap);
len = strlen (str1);
msg = GF_MALLOC (len + strlen (str2) + 1, gf_common_mt_char);
@@ -308,8 +308,8 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,
strcpy (msg, str1);
strcpy (msg + len, str2);
- fprintf (logfile, "%s\n", msg);
- fflush (logfile);
+ fprintf (logfile, "%s\n", msg);
+ fflush (logfile);
#ifdef GF_LINUX_HOST_OS
/* We want only serious log in 'syslog', not our debug
@@ -317,10 +317,10 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,
if (gf_log_syslog && level && (level <= GF_LOG_ERROR))
syslog ((level-1), "%s\n", msg);
#endif
- }
+ }
unlock:
- pthread_mutex_unlock (&logfile_mutex);
+ pthread_mutex_unlock (&logfile_mutex);
if (msg) {
GF_FREE (msg);
@@ -338,13 +338,13 @@ out:
int
_gf_log (const char *domain, const char *file, const char *function, int line,
- gf_loglevel_t level, const char *fmt, ...)
+ gf_loglevel_t level, const char *fmt, ...)
{
- const char *basename = NULL;
- FILE *new_logfile = NULL;
- va_list ap;
- struct tm *tm = NULL;
- char timestr[256];
+ const char *basename = NULL;
+ FILE *new_logfile = NULL;
+ va_list ap;
+ struct tm *tm = NULL;
+ char timestr[256];
struct timeval tv = {0,};
char *str1 = NULL;
@@ -355,8 +355,8 @@ _gf_log (const char *domain, const char *file, const char *function, int line,
xlator_t *this = NULL;
gf_loglevel_t xlator_loglevel = 0;
- if (!logfile)
- return -1;
+ if (!logfile)
+ return -1;
this = THIS;
@@ -367,61 +367,61 @@ _gf_log (const char *domain, const char *file, const char *function, int line,
if (level > xlator_loglevel)
goto out;
- static char *level_strings[] = {"", /* NONE */
+ static char *level_strings[] = {"", /* NONE */
"M", /* EMERGENCY */
"A", /* ALERT */
- "C", /* CRITICAL */
- "E", /* ERROR */
- "W", /* WARNING */
- "N", /* NOTICE */
+ "C", /* CRITICAL */
+ "E", /* ERROR */
+ "W", /* WARNING */
+ "N", /* NOTICE */
"I", /* INFO/NORMAL */
- "D", /* DEBUG */
+ "D", /* DEBUG */
"T", /* TRACE */
- ""};
+ ""};
- if (!domain || !file || !function || !fmt) {
- fprintf (stderr,
- "logging: %s:%s():%d: invalid argument\n",
- __FILE__, __PRETTY_FUNCTION__, __LINE__);
- return -1;
- }
+ if (!domain || !file || !function || !fmt) {
+ fprintf (stderr,
+ "logging: %s:%s():%d: invalid argument\n",
+ __FILE__, __PRETTY_FUNCTION__, __LINE__);
+ return -1;
+ }
- if (logrotate) {
- logrotate = 0;
+ if (logrotate) {
+ logrotate = 0;
- new_logfile = fopen (filename, "a");
- if (!new_logfile) {
- gf_log ("logrotate", GF_LOG_CRITICAL,
- "failed to open logfile %s (%s)",
- filename, strerror (errno));
- goto log;
- }
+ new_logfile = fopen (filename, "a");
+ if (!new_logfile) {
+ gf_log ("logrotate", GF_LOG_CRITICAL,
+ "failed to open logfile %s (%s)",
+ filename, strerror (errno));
+ goto log;
+ }
- fclose (logfile);
- gf_log_logfile = logfile = new_logfile;
- }
+ fclose (logfile);
+ gf_log_logfile = logfile = new_logfile;
+ }
log:
ret = gettimeofday (&tv, NULL);
if (-1 == ret)
goto out;
- tm = localtime (&tv.tv_sec);
+ tm = localtime (&tv.tv_sec);
- pthread_mutex_lock (&logfile_mutex);
- {
- va_start (ap, fmt);
+ pthread_mutex_lock (&logfile_mutex);
+ {
+ va_start (ap, fmt);
- strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm);
+ strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm);
snprintf (timestr + strlen (timestr), 256 - strlen (timestr),
".%"GF_PRI_SUSECONDS, tv.tv_usec);
- basename = strrchr (file, '/');
- if (basename)
- basename++;
- else
- basename = file;
+ basename = strrchr (file, '/');
+ if (basename)
+ basename++;
+ else
+ basename = file;
ret = gf_asprintf (&str1, "[%s] %s [%s:%d:%s] %s: ",
timestr, level_strings[level],
@@ -436,7 +436,7 @@ log:
goto unlock;
}
- va_end (ap);
+ va_end (ap);
len = strlen (str1);
msg = GF_MALLOC (len + strlen (str2) + 1, gf_common_mt_char);
@@ -444,8 +444,8 @@ log:
strcpy (msg, str1);
strcpy (msg + len, str2);
- fprintf (logfile, "%s\n", msg);
- fflush (logfile);
+ fprintf (logfile, "%s\n", msg);
+ fflush (logfile);
#ifdef GF_LINUX_HOST_OS
/* We want only serious log in 'syslog', not our debug
@@ -453,10 +453,10 @@ log:
if (gf_log_syslog && level && (level <= GF_LOG_ERROR))
syslog ((level-1), "%s\n", msg);
#endif
- }
+ }
unlock:
- pthread_mutex_unlock (&logfile_mutex);
+ pthread_mutex_unlock (&logfile_mutex);
if (msg) {
if ((ret != -1) && __central_log_enabled &&
@@ -478,7 +478,7 @@ unlock:
FREE (str2);
out:
- return (0);
+ return (0);
}
@@ -517,7 +517,7 @@ __logfile_for_client (char *identifier)
if (!client_logs) {
client = GF_CALLOC (1, sizeof (*client),
- gf_common_mt_client_log);
+ gf_common_mt_client_log);
if (!client)
return NULL;
@@ -533,7 +533,7 @@ __logfile_for_client (char *identifier)
if (!client) {
client = GF_CALLOC (1, sizeof (*client),
- gf_common_mt_client_log);
+ gf_common_mt_client_log);
if (!client)
return NULL;
@@ -578,8 +578,8 @@ gf_cmd_log_init (const char *filename)
cmdlogfile = fopen (cmd_log_filename, "a");
if (!cmdlogfile){
gf_log ("glusterd", GF_LOG_CRITICAL,
- "gf_cmd_log_init: failed to open logfile \"%s\" "
- "(%s)\n", cmd_log_filename, strerror (errno));
+ "gf_cmd_log_init: failed to open logfile \"%s\" "
+ "(%s)\n", cmd_log_filename, strerror (errno));
return -1;
}
return 0;
@@ -604,7 +604,7 @@ gf_cmd_log (const char *domain, const char *fmt, ...)
if (!domain || !fmt) {
gf_log ("glusterd", GF_LOG_TRACE,
- "logging: invalid argument\n");
+ "logging: invalid argument\n");
return -1;
}
@@ -620,14 +620,14 @@ gf_cmd_log (const char *domain, const char *fmt, ...)
".%"GF_PRI_SUSECONDS, tv.tv_usec);
ret = gf_asprintf (&str1, "[%s] %s : ",
- timestr, domain);
+ timestr, domain);
if (ret == -1) {
- goto out;
+ goto out;
}
ret = vasprintf (&str2, fmt, ap);
if (ret == -1) {
- goto out;
+ goto out;
}
va_end (ap);
@@ -643,7 +643,7 @@ gf_cmd_log (const char *domain, const char *fmt, ...)
out:
if (msg) {
- GF_FREE (msg);
+ GF_FREE (msg);
}
if (str1)
diff --git a/libglusterfs/src/logging.h b/libglusterfs/src/logging.h
index 235410e..aa6e00e 100644
--- a/libglusterfs/src/logging.h
+++ b/libglusterfs/src/logging.h
@@ -17,7 +17,6 @@
<http://www.gnu.org/licenses/>.
*/
-
#ifndef __LOGGING_H__
#define __LOGGING_H__
@@ -57,16 +56,16 @@
#endif
typedef enum {
- GF_LOG_NONE,
+ GF_LOG_NONE,
GF_LOG_EMERG,
GF_LOG_ALERT,
- GF_LOG_CRITICAL, /* fatal errors */
- GF_LOG_ERROR, /* major failures (not necessarily fatal) */
- GF_LOG_WARNING, /* info about normal operation */
+ GF_LOG_CRITICAL, /* fatal errors */
+ GF_LOG_ERROR, /* major failures (not necessarily fatal) */
+ GF_LOG_WARNING, /* info about normal operation */
GF_LOG_NOTICE,
- GF_LOG_INFO, /* Normal information */
+ GF_LOG_INFO, /* Normal information */
#define GF_LOG_NORMAL GF_LOG_INFO
- GF_LOG_DEBUG, /* internal errors */
+ GF_LOG_DEBUG, /* internal errors */
GF_LOG_TRACE, /* full trace of operation */
} gf_loglevel_t;
@@ -77,7 +76,7 @@ extern char gf_log_xl_log_set;
#define FMT_WARN(fmt...) do { if (0) printf (fmt); } while (0)
-#define gf_log(dom, levl, fmt...) do { \
+#define gf_log(dom, levl, fmt...) do { \
FMT_WARN (fmt); \
\
if ((levl > gf_log_loglevel) && !gf_log_xl_log_set) \
@@ -97,7 +96,7 @@ extern char gf_log_xl_log_set;
/* Log once in GF_UNIVERSAL_ANSWER times */
#define GF_LOG_OCCASIONALLY(var, args...) if (!(var++%GF_UNIVERSAL_ANSWER)) { \
- gf_log (args); \
+ gf_log (args); \
}
@@ -109,7 +108,7 @@ 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, ...);
+ int32_t line, gf_loglevel_t level, const char *fmt, ...);
int
_gf_log_callingfn (const char *domain, const char *file, const char *function,
int32_t line, gf_loglevel_t level, const char *fmt, ...);
@@ -127,14 +126,14 @@ 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);
-#define GF_DEBUG(xl, format, args...) \
- gf_log ((xl)->name, GF_LOG_DEBUG, format, ##args)
-#define GF_INFO(xl, format, args...) \
- gf_log ((xl)->name, GF_LOG_INFO, format, ##args)
-#define GF_WARNING(xl, format, args...) \
- gf_log ((xl)->name, GF_LOG_WARNING, format, ##args)
-#define GF_ERROR(xl, format, args...) \
- gf_log ((xl)->name, GF_LOG_ERROR, format, ##args)
+#define GF_DEBUG(xl, format, args...) \
+ gf_log ((xl)->name, GF_LOG_DEBUG, format, ##args)
+#define GF_INFO(xl, format, args...) \
+ gf_log ((xl)->name, GF_LOG_INFO, format, ##args)
+#define GF_WARNING(xl, format, args...) \
+ gf_log ((xl)->name, GF_LOG_WARNING, format, ##args)
+#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, ...);
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index a8eb985..9acebad 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -99,11 +99,11 @@ gf_mem_set_acct_info (xlator_t *xl, char **alloc_ptr,
xl->mem_acct.rec[type].size += size;
xl->mem_acct.rec[type].num_allocs++;
xl->mem_acct.rec[type].max_size =
- max (xl->mem_acct.rec[type].max_size,
- xl->mem_acct.rec[type].size);
+ max (xl->mem_acct.rec[type].max_size,
+ xl->mem_acct.rec[type].size);
xl->mem_acct.rec[type].max_num_allocs =
- max (xl->mem_acct.rec[type].max_num_allocs,
- xl->mem_acct.rec[type].num_allocs);
+ max (xl->mem_acct.rec[type].max_num_allocs,
+ xl->mem_acct.rec[type].num_allocs);
}
UNLOCK(&xl->mem_acct.rec[type].lock);
@@ -208,44 +208,44 @@ int
gf_vasprintf (char **string_ptr, const char *format, va_list arg)
{
va_list arg_save;
- char *str = NULL;
- int size = 0;
- int rv = 0;
+ char *str = NULL;
+ int size = 0;
+ int rv = 0;
- if (!string_ptr || !format)
- return -1;
+ if (!string_ptr || !format)
+ return -1;
va_copy (arg_save, arg);
- size = vsnprintf (NULL, 0, format, arg);
- size++;
- str = GF_MALLOC (size, gf_common_mt_asprintf);
- if (str == NULL) {
- /*
- * Strictly speaking, GNU asprintf doesn't do this,
- * but the caller isn't checking the return value.
- */
- gf_log ("libglusterfs", GF_LOG_CRITICAL,
- "failed to allocate memory");
- return -1;
- }
- rv = vsnprintf (str, size, format, arg_save);
-
- *string_ptr = str;
- return (rv);
+ size = vsnprintf (NULL, 0, format, arg);
+ size++;
+ str = GF_MALLOC (size, gf_common_mt_asprintf);
+ if (str == NULL) {
+ /*
+ * Strictly speaking, GNU asprintf doesn't do this,
+ * but the caller isn't checking the return value.
+ */
+ gf_log ("libglusterfs", GF_LOG_CRITICAL,
+ "failed to allocate memory");
+ return -1;
+ }
+ rv = vsnprintf (str, size, format, arg_save);
+
+ *string_ptr = str;
+ return (rv);
}
int
gf_asprintf (char **string_ptr, const char *format, ...)
{
- va_list arg;
- int rv = 0;
+ va_list arg;
+ int rv = 0;
- va_start (arg, format);
- rv = gf_vasprintf (string_ptr, format, arg);
- va_end (arg);
+ va_start (arg, format);
+ rv = gf_vasprintf (string_ptr, format, arg);
+ va_end (arg);
- return rv;
+ return rv;
}
void
@@ -293,7 +293,7 @@ __gf_free (void *free_ptr)
type = *(uint32_t *)ptr;
if (GF_MEM_TRAILER_MAGIC != *(uint32_t *)
- ((char *)free_ptr + req_size)) {
+ ((char *)free_ptr + req_size)) {
// This points to a memory overrun
GF_ASSERT (0);
}
@@ -313,47 +313,47 @@ free:
struct mem_pool *
mem_pool_new_fn (unsigned long sizeof_type,
- unsigned long count)
+ unsigned long count)
{
- struct mem_pool *mem_pool = NULL;
- unsigned long padded_sizeof_type = 0;
- void *pool = NULL;
- int i = 0;
- struct list_head *list = NULL;
-
- if (!sizeof_type || !count) {
- gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
- return NULL;
- }
+ struct mem_pool *mem_pool = NULL;
+ unsigned long padded_sizeof_type = 0;
+ void *pool = NULL;
+ int i = 0;
+ struct list_head *list = NULL;
+
+ if (!sizeof_type || !count) {
+ gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
+ return NULL;
+ }
padded_sizeof_type = sizeof_type + GF_MEM_POOL_PAD_BOUNDARY;
- mem_pool = GF_CALLOC (sizeof (*mem_pool), 1, gf_common_mt_mem_pool);
- if (!mem_pool)
- return NULL;
+ mem_pool = GF_CALLOC (sizeof (*mem_pool), 1, gf_common_mt_mem_pool);
+ if (!mem_pool)
+ return NULL;
- LOCK_INIT (&mem_pool->lock);
- INIT_LIST_HEAD (&mem_pool->list);
+ LOCK_INIT (&mem_pool->lock);
+ INIT_LIST_HEAD (&mem_pool->list);
- mem_pool->padded_sizeof_type = padded_sizeof_type;
- mem_pool->cold_count = count;
+ mem_pool->padded_sizeof_type = padded_sizeof_type;
+ mem_pool->cold_count = count;
mem_pool->real_sizeof_type = sizeof_type;
pool = GF_CALLOC (count, padded_sizeof_type, gf_common_mt_long);
- if (!pool) {
+ if (!pool) {
GF_FREE (mem_pool);
- return NULL;
+ return NULL;
}
- for (i = 0; i < count; i++) {
- list = pool + (i * (padded_sizeof_type));
- INIT_LIST_HEAD (list);
- list_add_tail (list, &mem_pool->list);
- }
+ for (i = 0; i < count; i++) {
+ list = pool + (i * (padded_sizeof_type));
+ INIT_LIST_HEAD (list);
+ list_add_tail (list, &mem_pool->list);
+ }
- mem_pool->pool = pool;
- mem_pool->pool_end = pool + (count * (padded_sizeof_type));
+ mem_pool->pool = pool;
+ mem_pool->pool_end = pool + (count * (padded_sizeof_type));
- return mem_pool;
+ return mem_pool;
}
void*
@@ -377,30 +377,30 @@ mem_get0 (struct mem_pool *mem_pool)
void *
mem_get (struct mem_pool *mem_pool)
{
- struct list_head *list = NULL;
- void *ptr = NULL;
+ struct list_head *list = NULL;
+ void *ptr = NULL;
int *in_use = NULL;
- if (!mem_pool) {
- gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
- return NULL;
- }
+ if (!mem_pool) {
+ gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
+ return NULL;
+ }
- LOCK (&mem_pool->lock);
- {
- if (mem_pool->cold_count) {
- list = mem_pool->list.next;
- list_del (list);
+ LOCK (&mem_pool->lock);
+ {
+ if (mem_pool->cold_count) {
+ list = mem_pool->list.next;
+ list_del (list);
- mem_pool->hot_count++;
- mem_pool->cold_count--;
+ mem_pool->hot_count++;
+ mem_pool->cold_count--;
- ptr = list;
+ ptr = list;
in_use = (ptr + GF_MEM_POOL_LIST_BOUNDARY);
*in_use = 1;
goto fwd_addr_out;
- }
+ }
/* This is a problem area. If we've run out of
* chunks in our slab above, we need to allocate
@@ -422,83 +422,83 @@ mem_get (struct mem_pool *mem_pool)
* because it is too much work knowing that a better slab
* allocator is coming RSN.
*/
- ptr = MALLOC (mem_pool->real_sizeof_type);
+ ptr = MALLOC (mem_pool->real_sizeof_type);
/* Memory coming from the heap need not be transformed from a
* chunkhead to a usable pointer since it is not coming from
* the pool.
*/
goto unlocked_out;
- }
+ }
fwd_addr_out:
ptr = mem_pool_chunkhead2ptr (ptr);
unlocked_out:
UNLOCK (&mem_pool->lock);
- return ptr;
+ return ptr;
}
static int
__is_member (struct mem_pool *pool, void *ptr)
{
- if (!pool || !ptr) {
- gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
- return -1;
- }
+ if (!pool || !ptr) {
+ gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
+ return -1;
+ }
- if (ptr < pool->pool || ptr >= pool->pool_end)
- return 0;
+ if (ptr < pool->pool || ptr >= pool->pool_end)
+ return 0;
- if ((mem_pool_ptr2chunkhead (ptr) - pool->pool)
- % pool->padded_sizeof_type)
- return -1;
+ if ((mem_pool_ptr2chunkhead (ptr) - pool->pool)
+ % pool->padded_sizeof_type)
+ return -1;
- return 1;
+ return 1;
}
void
mem_put (struct mem_pool *pool, void *ptr)
{
- struct list_head *list = NULL;
- int *in_use = NULL;
- void *head = NULL;
-
- if (!pool || !ptr) {
- gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
- return;
- }
-
- LOCK (&pool->lock);
- {
-
- switch (__is_member (pool, ptr))
- {
- case 1:
- list = head = mem_pool_ptr2chunkhead (ptr);
- in_use = (head + GF_MEM_POOL_LIST_BOUNDARY);
- if (!is_mem_chunk_in_use(in_use)) {
- gf_log_callingfn ("mem-pool", GF_LOG_CRITICAL,
- "mem_put called on freed ptr %p of mem "
- "pool %p", ptr, pool);
- break;
- }
- pool->hot_count--;
- pool->cold_count++;
- *in_use = 0;
- list_add (list, &pool->list);
- break;
- case -1:
+ struct list_head *list = NULL;
+ int *in_use = NULL;
+ void *head = NULL;
+
+ if (!pool || !ptr) {
+ gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
+ return;
+ }
+
+ LOCK (&pool->lock);
+ {
+
+ switch (__is_member (pool, ptr))
+ {
+ case 1:
+ list = head = mem_pool_ptr2chunkhead (ptr);
+ in_use = (head + GF_MEM_POOL_LIST_BOUNDARY);
+ if (!is_mem_chunk_in_use(in_use)) {
+ gf_log_callingfn ("mem-pool", GF_LOG_CRITICAL,
+ "mem_put called on freed ptr %p of mem "
+ "pool %p", ptr, pool);
+ break;
+ }
+ pool->hot_count--;
+ pool->cold_count++;
+ *in_use = 0;
+ list_add (list, &pool->list);
+ break;
+ case -1:
/* For some reason, the address given is within
* the address range of the mem-pool but does not align
* with the expected start of a chunk that includes
* the list headers also. Sounds like a problem in
* layers of clouds up above us. ;)
*/
- abort ();
- break;
- case 0:
+ abort ();
+ break;
+ case 0:
/* The address is outside the range of the mem-pool. We
* assume here that this address was allocated at a
* point when the mem-pool was out of chunks in mem_get
@@ -507,14 +507,14 @@ mem_put (struct mem_pool *pool, void *ptr)
* not have enough info to distinguish between the two
* situations.
*/
- FREE (ptr);
- break;
- default:
- /* log error */
- break;
- }
- }
- UNLOCK (&pool->lock);
+ FREE (ptr);
+ break;
+ default:
+ /* log error */
+ break;
+ }
+ }
+ UNLOCK (&pool->lock);
}
diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h
index 6b09d62..0cda62f 100644
--- a/libglusterfs/src/mem-pool.h
+++ b/libglusterfs/src/mem-pool.h
@@ -32,11 +32,11 @@
#define MALLOC(size) malloc(size)
#define CALLOC(cnt,size) calloc(cnt,size)
-#define FREE(ptr) \
- if (ptr != NULL) { \
- free ((void *)ptr); \
- ptr = (void *)0xeeeeeeee; \
- }
+#define FREE(ptr) \
+ if (ptr != NULL) { \
+ free ((void *)ptr); \
+ ptr = (void *)0xeeeeeeee; \
+ }
struct mem_acct {
uint32_t num_types;
@@ -73,7 +73,7 @@ gf_asprintf (char **string_ptr, const char *format, ...);
#define GF_REALLOC(ptr, size) __gf_realloc (ptr, size)
-void
+void
__gf_free (void *ptr);
@@ -98,16 +98,14 @@ char * gf_strdup (const char *src)
return dup_str;
}
-
-
struct mem_pool {
- struct list_head list;
- int hot_count;
- int cold_count;
- gf_lock_t lock;
- unsigned long padded_sizeof_type;
- void *pool;
- void *pool_end;
+ struct list_head list;
+ int hot_count;
+ int cold_count;
+ gf_lock_t lock;
+ unsigned long padded_sizeof_type;
+ void *pool;
+ void *pool_end;
int real_sizeof_type;
};