diff options
Diffstat (limited to 'libglusterfs/src/options.c')
| -rw-r--r-- | libglusterfs/src/options.c | 156 | 
1 files changed, 90 insertions, 66 deletions
diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c index 75dce0ea3b6..4786a2789ca 100644 --- a/libglusterfs/src/options.c +++ b/libglusterfs/src/options.c @@ -17,6 +17,7 @@  #include "xlator.h"  #include "defaults.h" +#include "libglusterfs-messages.h"  #define GF_OPTION_LIST_EMPTY(_opt) (_opt->value[0] == NULL) @@ -32,7 +33,8 @@ xlator_option_validate_path (xlator_t *xl, const char *key, const char *value,                  snprintf (errstr, 256,                            "invalid path given '%s'",                            value); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  goto out;          } @@ -42,7 +44,8 @@ xlator_option_validate_path (xlator_t *xl, const char *key, const char *value,                            "option %s %s: '%s' is not an "                            "absolute path name",                            key, value, value); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  goto out;          } @@ -67,7 +70,8 @@ xlator_option_validate_int (xlator_t *xl, const char *key, const char *value,                  snprintf (errstr, 256,                            "invalid number format \"%s\" in option \"%s\"",                            value, key); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  goto out;          } @@ -76,15 +80,15 @@ xlator_option_validate_int (xlator_t *xl, const char *key, const char *value,                  snprintf (errstr, 256,                            "invalid number format \"%s\" in option \"%s\"",                            value, key); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  goto out;          }          if ((opt->min == 0) && (opt->max == 0) &&              (opt->validate == GF_OPT_VALIDATE_BOTH)) { -                gf_log (xl->name, GF_LOG_TRACE, -                        "no range check required for 'option %s %s'", -                        key, value); +                gf_msg_trace (xl->name, 0, "no range check required for " +                              "'option %s %s'", key, value);                  ret = 0;                  goto out;          } @@ -95,7 +99,8 @@ xlator_option_validate_int (xlator_t *xl, const char *key, const char *value,                                    "'%lld' in 'option %s %s' is smaller than "                                    "minimum value '%.0f'", inputll, key,                                    value, opt->min); -                        gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                        gf_msg (xl->name, GF_LOG_ERROR, 0, +                                LG_MSG_INVALID_ENTRY, "%s", errstr);                          goto out;                  }          } else if (opt->validate == GF_OPT_VALIDATE_MAX) { @@ -104,7 +109,8 @@ xlator_option_validate_int (xlator_t *xl, const char *key, const char *value,                                    "'%lld' in 'option %s %s' is greater than "                                    "maximum value '%.0f'", inputll, key,                                    value, opt->max); -                        gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                        gf_msg (xl->name, GF_LOG_ERROR, 0, +                                LG_MSG_INVALID_ENTRY, "%s", errstr);                          goto out;                  }          } else if ((inputll < opt->min) || (inputll > opt->max)) { @@ -112,7 +118,8 @@ xlator_option_validate_int (xlator_t *xl, const char *key, const char *value,                            "'%lld' in 'option %s %s' is out of range "                            "[%.0f - %.0f]",                            inputll, key, value, opt->min, opt->max); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", +                        errstr);                  goto out;          } @@ -137,15 +144,15 @@ xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value,                  snprintf (errstr, 256,                            "invalid number format \"%s\" in option \"%s\"",                            value, key); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  ret = -1;                  goto out;          }          if ((opt->min == 0) && (opt->max == 0)) { -                gf_log (xl->name, GF_LOG_TRACE, -                        "no range check required for 'option %s %s'", -                        key, value); +                gf_msg_trace (xl->name, 0, "no range check required for " +                              "'option %s %s'", key, value);                  goto out;          } @@ -155,13 +162,15 @@ xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value,                         snprintf (errstr, 256, "Cache size %" GF_PRI_SIZET " is out of "                                   "range [%.0f - %.0f]",                                   size, opt->min, opt->max); -                       gf_log (xl->name, GF_LOG_WARNING, "%s", errstr); +                       gf_msg (xl->name, GF_LOG_WARNING, 0, +                               LG_MSG_OUT_OF_RANGE, "%s", errstr);                  } else {                          snprintf (errstr, 256,                                    "'%" GF_PRI_SIZET "' in 'option %s %s' "                                    "is out of range [%.0f - %.0f]",                                    size, key, value, opt->min, opt->max); -                        gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                        gf_msg (xl->name, GF_LOG_ERROR, 0, +                                LG_MSG_OUT_OF_RANGE, "%s", errstr);                          ret = -1;                  }          } @@ -189,7 +198,8 @@ xlator_option_validate_bool (xlator_t *xl, const char *key, const char *value,                  snprintf (errstr, 256,                            "option %s %s: '%s' is not a valid boolean value",                            key, value, value); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  goto out;          } @@ -227,7 +237,8 @@ xlator_option_validate_xlator (xlator_t *xl, const char *key, const char *value,                  snprintf (errstr, 256,                            "option %s %s: '%s' is not a valid volume name",                            key, value, value); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  goto out;          } @@ -326,7 +337,8 @@ xlator_option_validate_str (xlator_t *xl, const char *key, const char *value,  out:          if (ret) {                  set_error_str (errstr, sizeof (errstr), opt, key, value); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  if (op_errstr)                          *op_errstr = gf_strdup (errstr);          } @@ -347,7 +359,8 @@ xlator_option_validate_percent (xlator_t *xl, const char *key, const char *value                  snprintf (errstr, 256,                            "invalid percent format \"%s\" in \"option %s\"",                            value, key); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  goto out;          } @@ -355,7 +368,8 @@ xlator_option_validate_percent (xlator_t *xl, const char *key, const char *value                  snprintf (errstr, 256,                            "'%lf' in 'option %s %s' is out of range [0 - 100]",                            percent, key, value); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", +                        errstr);                  goto out;          } @@ -401,7 +415,8 @@ xlator_option_validate_percent_or_sizet (xlator_t *xl, const char *key,                                            "'%lf' in 'option %s %s' is out"                                            " of range [0 - 100]", size, key,                                            value); -                                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                                gf_msg (xl->name, GF_LOG_ERROR, 0, +                                        LG_MSG_OUT_OF_RANGE, "%s", errstr);                                  goto out;                          }  			ret = 0; @@ -415,16 +430,15 @@ xlator_option_validate_percent_or_sizet (xlator_t *xl, const char *key,                                    " %s' should not be fractional value. Use "                                    "valid unsigned integer value.", size, key,                                    value); -                        gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                        gf_msg (xl->name, GF_LOG_ERROR, 0, +                                LG_MSG_INVALID_ENTRY, "%s", errstr);                          goto out;                  }  		/* Check the range */  		if ((opt->min == 0) && (opt->max == 0)) { -			gf_log (xl->name, GF_LOG_TRACE, -				"no range check required for " -				"'option %s %s'", -				key, value); +			gf_msg_trace (xl->name, 0, "no range check required " +                                      "for 'option %s %s'", key, value);  			ret = 0;  			goto out;  		} @@ -433,7 +447,8 @@ xlator_option_validate_percent_or_sizet (xlator_t *xl, const char *key,  				  "'%lf' in 'option %s %s'"  				  " is out of range [%.0f - %.0f]",  				  size, key, value, opt->min, opt->max); -			gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +			gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, +                                "%s", errstr);  			goto out;  		}  		ret = 0; @@ -445,7 +460,7 @@ xlator_option_validate_percent_or_sizet (xlator_t *xl, const char *key,  	snprintf (errstr, 256,  		  "invalid number format \"%s\" in \"option %s\"",  		  value, key); -	gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +	gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr);  out: @@ -469,15 +484,14 @@ xlator_option_validate_time (xlator_t *xl, const char *key, const char *value,                            "invalid time format \"%s\" in "                            "\"option %s\"",                            value, key); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  goto out;          }          if ((opt->min == 0) && (opt->max == 0)) { -                gf_log (xl->name, GF_LOG_TRACE, -                        "no range check required for " -                        "'option %s %s'", -                        key, value); +                gf_msg_trace (xl->name, 0, "no range check required for " +                              "'option %s %s'", key, value);                  ret = 0;                  goto out;          } @@ -488,7 +502,8 @@ xlator_option_validate_time (xlator_t *xl, const char *key, const char *value,                            "out of range [%.0f - %.0f]",                            input_time, key, value,                            opt->min, opt->max); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", +                        errstr);                  goto out;          } @@ -513,15 +528,15 @@ xlator_option_validate_double (xlator_t *xl, const char *key, const char *value,                  snprintf (errstr, 256,                            "invalid number format \"%s\" in option \"%s\"",                            value, key); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  goto out;          }          if ((opt->min == 0) && (opt->max == 0) &&              (opt->validate == GF_OPT_VALIDATE_BOTH)) { -                gf_log (xl->name, GF_LOG_TRACE, -                        "no range check required for 'option %s %s'", -                        key, value); +                gf_msg_trace (xl->name, 0, "no range check required for " +                              "'option %s %s'", key, value);                  ret = 0;                  goto out;          } @@ -532,7 +547,8 @@ xlator_option_validate_double (xlator_t *xl, const char *key, const char *value,                                    "'%f' in 'option %s %s' is smaller than "                                    "minimum value '%f'", input, key,                                    value, opt->min); -                        gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                        gf_msg (xl->name, GF_LOG_ERROR, 0, +                                LG_MSG_INVALID_ENTRY, "%s", errstr);                          goto out;                  }          } else if (opt->validate == GF_OPT_VALIDATE_MAX) { @@ -541,7 +557,8 @@ xlator_option_validate_double (xlator_t *xl, const char *key, const char *value,                                    "'%f' in 'option %s %s' is greater than "                                    "maximum value '%f'", input, key,                                    value, opt->max); -                        gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                        gf_msg (xl->name, GF_LOG_ERROR, 0, +                                LG_MSG_INVALID_ENTRY, "%s", errstr);                          goto out;                  }          } else if ((input < opt->min) || (input > opt->max)) { @@ -549,7 +566,8 @@ xlator_option_validate_double (xlator_t *xl, const char *key, const char *value,                            "'%f' in 'option %s %s' is out of range "                            "[%f - %f]",                            input, key, value, opt->min, opt->max); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", +                        errstr);                  goto out;          } @@ -573,7 +591,8 @@ xlator_option_validate_addr (xlator_t *xl, const char *key, const char *value,                            "option %s %s: '%s'  is not a valid internet-address,"                            " it does not conform to standards.",                            key, value, value); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  if (op_errstr)                          *op_errstr = gf_strdup (errstr);          } @@ -613,7 +632,8 @@ out:          if (ret) {                  snprintf (errstr, sizeof (errstr), "option %s %s: '%s' is not "                  "a valid internet-address-list", key, value, value); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  if (op_errstr)                          *op_errstr = gf_strdup (errstr);          } @@ -652,7 +672,8 @@ out:          if (ret) {                  snprintf (errstr, sizeof (errstr), "option %s %s: '%s' is not "                  "a valid mount-auth-address", key, value, value); -                gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", +                        errstr);                  if (op_errstr)                          *op_errstr = gf_strdup (errstr);          } @@ -678,7 +699,7 @@ gf_validate_size (const char *sizestr, volume_option_t *opt)          }   out: -        gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret); +        gf_msg_debug (THIS->name, 0, "Returning %d", ret);          return ret;  } @@ -722,9 +743,9 @@ validate_list_elements (const char *string, volume_option_t *opt,                  if (!key ||                      (key_validator && key_validator(key))) {                          ret = -1; -                        gf_log (THIS->name, GF_LOG_WARNING, -                                "invalid list '%s', key '%s' not valid.", -                                string, key); +                        gf_msg (THIS->name, GF_LOG_WARNING, 0, +                                LG_MSG_INVALID_ENTRY, "invalid list '%s', key " +                                "'%s' not valid.", string, key);                          goto out;                  } @@ -732,9 +753,9 @@ validate_list_elements (const char *string, volume_option_t *opt,                  if (!value ||                      (value_validator && value_validator(value, opt))) {                          ret = -1; -                        gf_log (THIS->name, GF_LOG_WARNING, -                                "invalid list '%s', value '%s' not valid.", -                                string, key); +                        gf_msg (THIS->name, GF_LOG_WARNING, 0, +                                LG_MSG_INVALID_ENTRY, "invalid list '%s', " +                                "value '%s' not valid.", string, key);                          goto out;                  } @@ -744,7 +765,7 @@ validate_list_elements (const char *string, volume_option_t *opt,   out:          GF_FREE (dup_string); -        gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret); +        gf_msg_debug (THIS->name, 0, "Returning %d", ret);          return ret;  } @@ -836,7 +857,7 @@ xlator_option_validate (xlator_t *xl, char *key, char *value,          };          if (opt->type > GF_OPTION_TYPE_MAX) { -                gf_log (xl->name, GF_LOG_ERROR, +                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY,                          "unknown option type '%d'", opt->type);                  goto out;          } @@ -923,17 +944,17 @@ xl_opt_validate (dict_t *dict, char *key, data_t *value, void *data)          ret = xlator_option_validate (xl, key, value->data, opt, &errstr);          if (ret) -                gf_log (xl->name, GF_LOG_WARNING, "validate of %s returned %d", -                        key, ret); +                gf_msg (xl->name, GF_LOG_WARNING, 0, LG_MSG_VALIDATE_RETURNS, +                        "validate of %s returned %d", key, ret);          if (errstr)                  /* possible small leak of previously set stub->errstr */                  stub->errstr = errstr;          if (fnmatch (opt->key[0], key, FNM_NOESCAPE) != 0) { -                gf_log (xl->name, GF_LOG_WARNING, "option '%s' is deprecated, " -                        "preferred is '%s', continuing with correction", -                        key, opt->key[0]); +                gf_msg (xl->name, GF_LOG_WARNING, 0, LG_MSG_INVALID_ENTRY, +                        "option '%s' is deprecated, preferred is '%s', " +                        "continuing with correction", key, opt->key[0]);                  dict_set (dict, opt->key[0], value);                  dict_del (dict, key);          } @@ -975,7 +996,7 @@ xlator_options_validate (xlator_t *xl, dict_t *options, char **op_errstr)          if (!xl) { -                gf_log (THIS->name, GF_LOG_DEBUG, "'this' not a valid ptr"); +                gf_msg_debug (THIS->name, 0, "'this' not a valid ptr");                  ret = -1;                  goto out;          } @@ -1005,7 +1026,9 @@ xlator_validate_rec (xlator_t *xlator, char **op_errstr)          while (trav) {                  if (xlator_validate_rec (trav->xlator, op_errstr)) { -                        gf_log ("xlator", GF_LOG_WARNING, "validate_rec failed"); +                        gf_msg ("xlator", GF_LOG_WARNING, 0, +                                LG_MSG_VALIDATE_REC_FAILED, "validate_rec " +                                "failed");                          goto out;                  } @@ -1013,7 +1036,7 @@ xlator_validate_rec (xlator_t *xlator, char **op_errstr)          }          if (xlator_dynload (xlator)) -                gf_log (xlator->name, GF_LOG_DEBUG, "Did not load the symbols"); +                gf_msg_debug (xlator->name, 0, "Did not load the symbols");          old_THIS = THIS;          THIS = xlator; @@ -1029,11 +1052,12 @@ xlator_validate_rec (xlator_t *xlator, char **op_errstr)          THIS = old_THIS;          if (ret) { -                gf_log (xlator->name, GF_LOG_INFO, "%s", *op_errstr); +                gf_msg (xlator->name, GF_LOG_INFO, 0, LG_MSG_INVALID_ENTRY, +                        "%s", *op_errstr);                  goto out;          } -        gf_log (xlator->name, GF_LOG_DEBUG, "Validated options"); +        gf_msg_debug (xlator->name, 0, "Validated options");          ret = 0;  out: @@ -1076,7 +1100,7 @@ xlator_reconfigure_rec (xlator_t *old_xl, xlator_t *new_xl)                  if (ret)                          goto out; -                gf_log (trav1->xlator->name, GF_LOG_DEBUG, "reconfigured"); +                gf_msg_debug (trav1->xlator->name, 0, "reconfigured");                  trav1 = trav1->next;                  trav2 = trav2->next; @@ -1093,7 +1117,7 @@ xlator_reconfigure_rec (xlator_t *old_xl, xlator_t *new_xl)                  if (ret)                          goto out;          } else { -                gf_log (old_xl->name, GF_LOG_DEBUG, "No reconfigure() found"); +                gf_msg_debug (old_xl->name, 0, "No reconfigure() found");          }          ret = 0;  | 
