diff options
| author | Amar Tumballi <amarts@redhat.com> | 2018-01-09 16:03:15 +0530 | 
|---|---|---|
| committer | Amar Tumballi <amarts@redhat.com> | 2018-01-17 03:53:37 +0000 | 
| commit | e3a191a0d3ea0706f4827ebdb6e5161623f2c5f1 (patch) | |
| tree | ca9da3761de87c5ea989b82c2fcfa911cc74d605 /libglusterfs/src | |
| parent | 6f877d04d6b1b9e0e10904c1a9da9e671bccb290 (diff) | |
dict: add another type to handle backward compatibility
This new type helps to avoid excessive logs. It should be
set only in case of
 * volume graph building (graph.y)
 * dict unserialize
   (happens once a dictionary is received on wire in old protocol)
All other dict set and get should have proper check and warning
logs if there is a mismatch.
updates #220
Change-Id: I1cccb304a877aa80c07aaac95f10f5005e35b9c5
Signed-off-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'libglusterfs/src')
| -rw-r--r-- | libglusterfs/src/dict.c | 37 | ||||
| -rw-r--r-- | libglusterfs/src/dict.h | 1 | ||||
| -rw-r--r-- | libglusterfs/src/graph.y | 2 | ||||
| -rw-r--r-- | libglusterfs/src/libglusterfs.sym | 1 | 
4 files changed, 35 insertions, 6 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 9dd1de4f81a..8a6fbb21d4b 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -43,8 +43,9 @@ struct dict_cmp {                                            LG_MSG_INVALID_ARG, "data is NULL"); \                          return ret_val;                                 \                  }                                                       \ -                                                                        \ -                if (data->data_type != type) {                          \ +                /* Not of the asked type, or old version */             \ +                if ((data->data_type != type) &&                        \ +                    (data->data_type != GF_DATA_TYPE_STR_OLD)) {        \                          gf_msg_callingfn ("dict", GF_LOG_INFO, EINVAL,  \                                            LG_MSG_INVALID_ARG,           \                                            "key %s, %s type asked, has %s type", \ @@ -996,6 +997,7 @@ bin_to_data (void *value, int32_t len)  static char *data_type_name[GF_DATA_TYPE_MAX] = {          [GF_DATA_TYPE_UNKNOWN] = "unknown", +        [GF_DATA_TYPE_STR_OLD] = "string-old-version",          [GF_DATA_TYPE_INT] = "integer",          [GF_DATA_TYPE_UINT] = "unsigned integer",          [GF_DATA_TYPE_DOUBLE] = "float", @@ -2273,6 +2275,28 @@ err:          return ret;  } +/* This function is called only by the volgen for now. +   Check how else you can handle it */ +int +dict_set_option (dict_t *this, char *key, char *str) +{ +        data_t *data = NULL; +        int     ret  = 0; + +        data = data_from_dynstr (str); +        if (!data) { +                ret = -EINVAL; +                goto err; +        } + +        data->data_type = GF_DATA_TYPE_STR_OLD; +        ret = dict_set (this, key, data); +        if (ret < 0) +                data_destroy (data); +err: +        return ret; +} +  int  dict_add_dynstr_with_alloc (dict_t *this, char *key, char *str)  { @@ -2910,7 +2934,7 @@ dict_unserialize (char *orig_buf, int32_t size, dict_t **fill)                  }                  value->len  = vallen;                  value->data = memdup (buf, vallen); -                value->data_type = GF_DATA_TYPE_STR; +                value->data_type = GF_DATA_TYPE_STR_OLD;                  value->is_static = 0;                  buf += vallen; @@ -3088,6 +3112,9 @@ dict_dump_to_str (dict_t *dict, char *dump, int dumpsize, char *format)          int          dumplen                   = 0;          data_pair_t *trav                      = NULL; +        if (!dict) +                return 0; +          for (trav = dict->members_list; trav; trav = trav->next) {                  ret = snprintf (&dump[dumplen], dumpsize - dumplen,                                  format, trav->key, trav->value->data); @@ -3126,8 +3153,8 @@ dict_dump_to_log (dict_t *dict)                          "Failed to log dictionary");                  goto out;          } -        gf_msg_callingfn ("dict", GF_LOG_INFO, 0, LG_MSG_DICT_ERROR, -                          "dict=%p (%s)", dict, dump); +        gf_msg ("dict", GF_LOG_INFO, 0, LG_MSG_DICT_ERROR, +                "dict=%p (%s)", dict, dump);  out:          GF_FREE (dump); diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index dfd4baf25ab..ab8a8a56352 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -238,6 +238,7 @@ GF_MUST_CHECK int dict_get_bin (dict_t *this, char *key, void **ptr);  GF_MUST_CHECK int dict_set_bin (dict_t *this, char *key, void *ptr, size_t size);  GF_MUST_CHECK int dict_set_static_bin (dict_t *this, char *key, void *ptr, size_t size); +GF_MUST_CHECK int dict_set_option (dict_t *this, char *key, char *str);  GF_MUST_CHECK int dict_set_str (dict_t *this, char *key, char *str);  GF_MUST_CHECK int dict_set_dynstr (dict_t *this, char *key, char *str);  GF_MUST_CHECK int dict_set_dynstr_with_alloc (dict_t *this, char *key, const char *str); diff --git a/libglusterfs/src/graph.y b/libglusterfs/src/graph.y index 7df3479d701..ddd2c9672fb 100644 --- a/libglusterfs/src/graph.y +++ b/libglusterfs/src/graph.y @@ -239,7 +239,7 @@ volume_option (char *key, char *value)          }          set_value = gf_strdup (value); -	ret = dict_set_dynstr (curr->options, key, set_value); +	ret = dict_set_option (curr->options, key, set_value);          if (ret == 1) {                  gf_msg ("parser", GF_LOG_ERROR, 0, diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym index 1efb2b18207..dfa962c7072 100644 --- a/libglusterfs/src/libglusterfs.sym +++ b/libglusterfs/src/libglusterfs.sym @@ -355,6 +355,7 @@ dict_copy_with_ref  dict_del  dict_dump_to_statedump  dict_dump_to_str +dict_dump_to_log  dict_foreach  dict_foreach_fnmatch  dict_foreach_match  | 
