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 33d81879917..de5a745449e 100644 --- a/libglusterfs/src/options.c +++ b/libglusterfs/src/options.c @@ -12,6 +12,7 @@  #include "xlator.h"  #include "defaults.h" +#include "libglusterfs-messages.h"  #define GF_OPTION_LIST_EMPTY(_opt) (_opt->value[0] == NULL) @@ -27,7 +28,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;          } @@ -37,7 +39,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;          } @@ -62,7 +65,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;          } @@ -71,15 +75,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;          } @@ -90,7 +94,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) { @@ -99,7 +104,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)) { @@ -107,7 +113,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;          } @@ -132,15 +139,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;          } @@ -150,13 +157,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;                  }          } @@ -184,7 +193,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;          } @@ -222,7 +232,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;          } @@ -321,7 +332,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);          } @@ -342,7 +354,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;          } @@ -350,7 +363,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;          } @@ -396,7 +410,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; @@ -410,16 +425,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;  		} @@ -428,7 +442,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; @@ -440,7 +455,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: @@ -464,15 +479,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;          } @@ -483,7 +497,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;          } @@ -508,15 +523,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;          } @@ -527,7 +542,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) { @@ -536,7 +552,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)) { @@ -544,7 +561,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;          } @@ -568,7 +586,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);          } @@ -608,7 +627,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);          } @@ -647,7 +667,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);          } @@ -673,7 +694,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;  } @@ -717,9 +738,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;                  } @@ -727,9 +748,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;                  } @@ -739,7 +760,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;  } @@ -831,7 +852,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;          } @@ -918,17 +939,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);          } @@ -970,7 +991,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;          } @@ -1000,7 +1021,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;                  } @@ -1008,7 +1031,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; @@ -1024,11 +1047,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: @@ -1071,7 +1095,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; @@ -1088,7 +1112,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;  | 
