diff options
| -rw-r--r-- | tests/bugs/cli/bug-983317-volume-get.t (renamed from tests/bugs/cli/bug-983317.t) | 11 | ||||
| -rw-r--r-- | tests/volume.rc | 7 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 38 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 32 | 
4 files changed, 69 insertions, 19 deletions
diff --git a/tests/bugs/cli/bug-983317.t b/tests/bugs/cli/bug-983317-volume-get.t index 11590ac280f..8f09d588565 100644 --- a/tests/bugs/cli/bug-983317.t +++ b/tests/bugs/cli/bug-983317-volume-get.t @@ -13,13 +13,22 @@ TEST $CLI volume create $V0 $H0:$B0/$V0  TEST $CLI volume set $V0 open-behind on  TEST $CLI volume start $V0 +TEST $CLI volume set all server-quorum-ratio 80 + +TEST $CLI volume set $V0 user.metadata 'dummy' +  # Execute volume get without having an explicit option, this should fail  TEST ! $CLI volume get $V0  # Execute volume get with an explicit option  TEST $CLI volume get $V0 open-behind +EXPECT 'on' volume_get_field $V0 'open-behind'  # Execute volume get with 'all"  TEST $CLI volume get $V0 all -cleanup; +# Check if volume get can display correct global options values as well +EXPECT '80' volume_get_field $V0 'server-quorum-ratio' + +# Check user.* options can also be retrived using volume get +EXPECT 'dummy' volume_get_field $V0 'user.metadata' diff --git a/tests/volume.rc b/tests/volume.rc index 9bd9eca1ec5..9c6c6be2e8a 100644 --- a/tests/volume.rc +++ b/tests/volume.rc @@ -6,6 +6,13 @@ function volinfo_field()      $CLI volume info $vol | grep "^$field: " | sed 's/.*: //';  } +function volume_get_field() +{ +    local vol=$1 +    local field=$2 +    $CLI volume get $vol $field | tail -1 | awk '{print $2}' +} +  function brick_count()  { diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index 86d1d5f23fb..fd01f0205ab 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -4777,17 +4777,43 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict)                                          goto out;                                  }                          } else { -                                ret = glusterd_get_default_val_for_volopt +                                sprintf (dict_key, "key%d", count); +                                ret = dict_set_str(dict, dict_key, key); +                                if (ret) { +                                        gf_msg (this->name, GF_LOG_ERROR, 0, +                                                GD_MSG_DICT_SET_FAILED, "Failed" +                                                " to set %s in dictionary", +                                                key); +                                        goto out; +                                } +                                sprintf (dict_key, "value%d", count); +                                ret = dict_get_str (priv->opts, key, &value); +                                if (!ret) { +                                        ret = dict_set_str(dict, dict_key, +                                                           value); +                                        if (ret) { +                                                gf_msg (this->name, +                                                        GF_LOG_ERROR, 0, +                                                        GD_MSG_DICT_SET_FAILED, +                                                        "Failed to set %s in " +                                                        " dictionary", key); +                                                goto out; +                                        } +                                } else { +                                        ret = glusterd_get_default_val_for_volopt                                                                 (dict,                                                                  _gf_false,                                                                  key, orig_key,                                                                  volinfo->dict,                                                                  &rsp.op_errstr); -                                if (ret && !rsp.op_errstr) { -                                        snprintf (err_str, sizeof(err_str), -                                                  "Failed to fetch the value of" -                                                  " %s, check log file for more" -                                                  " details", key); +                                        if (ret && !rsp.op_errstr) { +                                                snprintf (err_str, +                                                          sizeof(err_str), +                                                          "Failed to fetch the " +                                                          "value of %s, check " +                                                          "log file for more" +                                                          " details", key); +                                        }                                  }                          }                  } diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 7e9781f190d..73cdf16badf 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -10635,10 +10635,14 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts,          char                    *def_val = NULL;          char                     dict_key[50] = {0,};          gf_boolean_t             key_found = _gf_false; +        glusterd_conf_t         *priv = NULL;          this = THIS;          GF_ASSERT (this); +        priv = this->private; +        GF_VALIDATE_OR_GOTO (this->name, priv, out); +          GF_VALIDATE_OR_GOTO (this->name, vol_dict, out);          /* Check whether key is passed for a single option */ @@ -10653,19 +10657,23 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts,                  if (!all_opts && strcmp (vme->key, input_key))                          continue;                  key_found = _gf_true; -                /* First look for the key in the vol_dict, if its not -                 * present then look for translator default value */ -                ret = dict_get_str (vol_dict, vme->key, &def_val); +                /* First look for the key in the priv->opts for global option +                 * and then into vol_dict, if its not present then look for +                 * translator default value */ +                ret = dict_get_str (priv->opts, vme->key, &def_val);                  if (!def_val) { -                        if (vme->value) { -                                def_val = vme->value; -                        } else { -                                ret = glusterd_get_value_for_vme_entry -                                         (vme, &def_val); -                                if (!all_opts && ret) -                                        goto out; -                                else if (ret == -2) -                                        continue; +                        ret = dict_get_str (vol_dict, vme->key, &def_val); +                        if (!def_val) { +                                if (vme->value) { +                                        def_val = vme->value; +                                } else { +                                        ret = glusterd_get_value_for_vme_entry +                                                 (vme, &def_val); +                                        if (!all_opts && ret) +                                                goto out; +                                        else if (ret == -2) +                                                continue; +                                }                          }                  }                  count++;  | 
