diff options
| -rw-r--r-- | libglusterfs/src/glusterfs/options.h | 44 | ||||
| -rw-r--r-- | libglusterfs/src/options.c | 31 | 
2 files changed, 26 insertions, 49 deletions
diff --git a/libglusterfs/src/glusterfs/options.h b/libglusterfs/src/glusterfs/options.h index 0e683d780df..747b13ba375 100644 --- a/libglusterfs/src/glusterfs/options.h +++ b/libglusterfs/src/glusterfs/options.h @@ -264,7 +264,7 @@ DECLARE_INIT_OPT(uint32_t, time);  #define DECLARE_RECONF_OPT(type_t, type)                                       \      int xlator_option_reconf_##type(xlator_t *this, dict_t *options,           \ -                                    char *key, type_t *val_p); +                                    char *key, int keylen, type_t *val_p);  DECLARE_RECONF_OPT(char *, str);  DECLARE_RECONF_OPT(uint64_t, uint64); @@ -283,56 +283,44 @@ DECLARE_RECONF_OPT(uint32_t, time);  #define DEFINE_RECONF_OPT(type_t, type, conv)                                  \      int xlator_option_reconf_##type(xlator_t *this, dict_t *options,           \ -                                    char *key, type_t *val_p)                  \ +                                    char *key, int keylen, type_t *val_p)      \      {                                                                          \          int ret = 0;                                                           \ -        volume_option_t *opt = NULL;                                           \ -        char *def_value = NULL;                                                \ -        char *set_value = NULL;                                                \          char *value = NULL;                                                    \          xlator_t *old_THIS = NULL;                                             \                                                                                 \ -        opt = xlator_volume_option_get(this, key);                             \ +        volume_option_t *opt = xlator_volume_option_get(this, key);            \          if (!opt) {                                                            \              gf_msg(this->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ENTRY,   \                     "unknown option: %s", key);                                 \ -            ret = -1;                                                          \ -            return ret;                                                        \ +            return -1;                                                         \          }                                                                      \ -        def_value = opt->default_value;                                        \ -        ret = dict_get_str(options, key, &set_value);                          \ -                                                                               \ -        if (def_value)                                                         \ -            value = def_value;                                                 \ -        if (set_value)                                                         \ -            value = set_value;                                                 \ -        if (!value) {                                                          \ -            gf_msg_trace(this->name, 0, "option %s not set", key);             \ -            *val_p = (type_t)0;                                                \ -            return 0;                                                          \ -        }                                                                      \ -        if (value == def_value) {                                              \ +        ret = dict_get_strn(options, key, keylen, &value);                     \ +        if (ret == 0 && value) {                                               \ +            gf_msg(this->name, GF_LOG_INFO, 0, 0,                              \ +                   "option %s using set value %s", key, value);                \ +        } else if (opt->default_value) {                                       \ +            value = opt->default_value;                                        \              gf_msg_trace(this->name, 0, "option %s using default value %s",    \                           key, value);                                          \          } else {                                                               \ -            gf_msg(this->name, GF_LOG_INFO, 0, 0,                              \ -                   "option %s using set value %s", key, value);                \ +            gf_msg_trace(this->name, 0, "option %s not set", key);             \ +            *val_p = (type_t)0;                                                \ +            return 0;                                                          \          }                                                                      \ +                                                                               \          old_THIS = THIS;                                                       \          THIS = this;                                                           \          ret = conv(value, val_p);                                              \          THIS = old_THIS;                                                       \          if (ret)                                                               \              return ret;                                                        \ -        ret = xlator_option_validate(this, key, value, opt, NULL);             \ -        return ret;                                                            \ +        return xlator_option_validate(this, key, value, opt, NULL);            \      }  #define GF_OPTION_RECONF(key, val, opt, type, err_label)                       \      do {                                                                       \ -        int val_ret = 0;                                                       \ -        val_ret = xlator_option_reconf_##type(THIS, opt, key, &(val));         \ -        if (val_ret)                                                           \ +        if (xlator_option_reconf_##type(THIS, opt, key, SLEN(key), &(val)))    \              goto err_label;                                                    \      } while (0) diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c index 2884d200caa..400a3901689 100644 --- a/libglusterfs/src/options.c +++ b/libglusterfs/src/options.c @@ -217,7 +217,7 @@ out:      return ret;  } -void +static void  set_error_str(char *errstr, size_t len, volume_option_t *opt, const char *key,                const char *value)  { @@ -239,18 +239,15 @@ set_error_str(char *errstr, size_t len, volume_option_t *opt, const char *key,      return;  } -int +static int  is_all_whitespaces(const char *value)  {      int i = 0; -    size_t len = 0;      if (value == NULL)          return -1; -    len = strlen(value); - -    for (i = 0; i < len; i++) { +    for (i = 0; value[i] != '\0'; i++) {          if (value[i] == ' ')              continue;          else @@ -266,9 +263,6 @@ xlator_option_validate_str(xlator_t *xl, const char *key, const char *value,  {      int ret = -1;      int i = 0; -    char errstr[4096] = { -        0, -    };      /* Check if the '*str' is valid */      if (GF_OPTION_LIST_EMPTY(opt)) { @@ -308,6 +302,7 @@ xlator_option_validate_str(xlator_t *xl, const char *key, const char *value,  out:      if (ret) { +        char errstr[4096];          set_error_str(errstr, sizeof(errstr), opt, key, value);          gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); @@ -580,9 +575,6 @@ xlator_option_validate_addr_list(xlator_t *xl, const char *key,      char *addr_list = NULL;      char *addr = NULL;      char *dir = NULL; -    char errstr[4096] = { -        0, -    };      dup_val = gf_strdup(value);      if (!dup_val) @@ -643,6 +635,7 @@ xlator_option_validate_addr_list(xlator_t *xl, const char *key,  out:      if (ret) { +        char errstr[4096];          snprintf(errstr, sizeof(errstr),                   "option %s %s: '%s' is not "                   "a valid internet-address-list", @@ -665,9 +658,6 @@ xlator_option_validate_mntauth(xlator_t *xl, const char *key, const char *value,      char *dup_val = NULL;      char *addr_tok = NULL;      char *save_ptr = NULL; -    char errstr[4096] = { -        0, -    };      dup_val = gf_strdup(value);      if (!dup_val) @@ -686,6 +676,7 @@ xlator_option_validate_mntauth(xlator_t *xl, const char *key, const char *value,  out:      if (ret) { +        char errstr[4096];          snprintf(errstr, sizeof(errstr),                   "option %s %s: '%s' is not "                   "a valid mount-auth-address", @@ -759,7 +750,7 @@ validate_list_elements(const char *string, volume_option_t *opt,              gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INVALID_ENTRY,                     "invalid list '%s', key "                     "'%s' not valid.", -                   string, key); +                   string, key ? key : "");              goto out;          } @@ -891,7 +882,6 @@ xlator_volume_option_get_list(volume_opt_list_t *vol_list, const char *key)  {      volume_option_t *opt = NULL;      volume_opt_list_t *opt_list = NULL; -    volume_option_t *found = NULL;      int index = 0;      int i = 0;      char *cmp_key = NULL; @@ -908,13 +898,12 @@ xlator_volume_option_get_list(volume_opt_list_t *vol_list, const char *key)              if (!cmp_key)                  break;              if (fnmatch(cmp_key, key, FNM_NOESCAPE) == 0) { -                found = &opt[index]; -                goto out; +                return &opt[index];              }          }      } -out: -    return found; + +    return NULL;  }  volume_option_t *  | 
