diff options
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/common-utils.c | 31 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 2 | ||||
-rw-r--r-- | libglusterfs/src/options.c | 22 |
3 files changed, 49 insertions, 6 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index b2e91608b7a..2d4415f506d 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -1896,3 +1896,34 @@ gf_path_strip_trailing_slashes (char *path) return; } + +uint64_t +get_mem_size () +{ + uint64_t memsize = -1; + +#ifdef __linux__ + FILE *fp = NULL; + char line[1028] = {0,}; + + fp = fopen ("/proc/meminfo", "r"); + if (!fp) { + gf_log ("common-utils", GF_LOG_DEBUG, + "Could not open /proc/meminfo"); + return memsize; + } + + while (fgets (line, sizeof (line), fp) != 0) { + if (strncmp (line, "MemTotal:", 9) == 0) { + sscanf (line, "%*s %"SCNu64" kB", &memsize); + memsize *= 1024; //convert to bytes + gf_log ("common-utils", GF_LOG_INFO, + "Total Mem: %"PRIu64, memsize); + break; + } + } +#endif + // TODO: Methods for other platforms + + return memsize; +} diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 82e499b392a..2a5e00c5e11 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -50,6 +50,7 @@ void trap (void); #include "uuid.h" + #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define roof(a,b) ((((a)+(b)-1)/((b)?(b):1))*(b)) @@ -399,4 +400,5 @@ int validate_brick_name (char *brick); char *get_host_name (char *word, char **host); char *get_path_name (char *word, char **path); void gf_path_strip_trailing_slashes (char *path); +uint64_t get_mem_size (); #endif /* _COMMON_UTILS_H */ diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c index b64b24e0489..1e6413cc0a9 100644 --- a/libglusterfs/src/options.c +++ b/libglusterfs/src/options.c @@ -131,12 +131,22 @@ xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value, } if ((size < opt->min) || (size > opt->max)) { - snprintf (errstr, 256, - "'%"PRId64"' in 'option %s %s' is out of range " - "[%"PRId64" - %"PRId64"]", - size, key, value, opt->min, opt->max); - gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); - goto out; + if (strncmp (key, "cache-size", 10) == 0) { + snprintf (errstr, 256, "Cache size %"PRId64" is out of " + "range [%"PRId64" - %"PRId64"]", + size, opt->min, opt->max); + //*op_errstr = gf_strdup (errstr); + gf_log (xl->name, GF_LOG_WARNING, "%s", errstr); + ret = 0; + goto out; + } else { + snprintf (errstr, 256, + "'%"PRId64"' in 'option %s %s' " + "is out of range [%"PRId64" - %"PRId64"]", + size, key, value, opt->min, opt->max); + gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + goto out; + } } ret = 0; |