summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorAmar Tumballi <amarts@redhat.com>2012-09-06 00:13:04 +0530
committerAnand Avati <avati@redhat.com>2012-09-06 00:34:15 -0700
commitd6c99b6134f1eb90b3a8020c3538101df266e9b5 (patch)
treea5ec27bcf3136ddfda5ce5f21917bea50ad3be58 /cli
parent54b71368ef290bc579f113e683a82b09893fb50a (diff)
libglusterfs/dict: make 'dict_t' a opaque object
* ie, don't dereference dict_t pointer, instead use APIs everywhere * other than dict_t only 'data_t' should be the valid export from dict.h * added 'dict_foreach_fnmatch()' API * changed dict_lookup() to use data_t, instead of data_pair_t Change-Id: I400bb0dd55519a7c5d2a107e67c8e7a7207228dc Signed-off-by: Amar Tumballi <amarts@redhat.com> BUG: 850917 Reviewed-on: http://review.gluster.org/3829 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-rpc-ops.c40
-rw-r--r--cli/src/cli-xml-output.c52
2 files changed, 41 insertions, 51 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 9d699a0fdac..9d8aa26eeae 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -478,7 +478,6 @@ gf_cli_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
{
int ret = -1;
int opt_count = 0;
- int k = 0;
int32_t i = 0;
int32_t j = 1;
int32_t status = 0;
@@ -494,7 +493,6 @@ gf_cli_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
char *brick = NULL;
char *volname = NULL;
dict_t *dict = NULL;
- data_pair_t *pairs = NULL;
data_t *value = NULL;
cli_local_t *local = NULL;
char key[1024] = {0};
@@ -709,12 +707,6 @@ xml_output:
j++;
}
- pairs = dict->members_list;
- if (!pairs) {
- ret = -1;
- goto out;
- }
-
snprintf (key, 256, "volume%d.opt_count",i);
ret = dict_get_int32 (dict, key, &opt_count);
if (ret)
@@ -724,26 +716,26 @@ xml_output:
goto out;
cli_out ("Options Reconfigured:");
- k = 0;
- while (k < opt_count) {
-
- snprintf (key, 256, "volume%d.option.",i);
- while (pairs) {
- ptr = strstr (pairs->key, "option.");
- if (ptr) {
- value = pairs->value;
- if (!value) {
- ret = -1;
- goto out;
- }
- cli_out_options (key, pairs->key,
- value->data);
+ snprintf (key, 256, "volume%d.option.",i);
+ int _output_volinfo_opts (dict_t *d, char *k,
+ data_t *v, void *tmp)
+ {
+ ptr = strstr (k, "option.");
+ if (ptr) {
+ value = v;
+ if (!value) {
+ ret = -1;
+ goto internal_out;
}
- pairs = pairs->next;
+ cli_out_options (key, k, v->data);
}
- k++;
+ internal_out:
+ return ret;
}
+ ret = dict_foreach (dict, _output_volinfo_opts, NULL);
+ if (ret)
+ goto out;
i++;
}
diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c
index eebcafb9716..7ca57164e89 100644
--- a/cli/src/cli-xml-output.c
+++ b/cli/src/cli-xml-output.c
@@ -136,7 +136,7 @@ out:
return ret;
}
-void
+int
cli_xml_output_data_pair (dict_t *this, char *key, data_t *value,
void *data)
{
@@ -148,7 +148,7 @@ cli_xml_output_data_pair (dict_t *this, char *key, data_t *value,
ret = xmlTextWriterWriteFormatElement (*writer, (xmlChar *)key,
"%s", value->data);
- return;
+ return ret;
}
int
@@ -2077,17 +2077,9 @@ cli_xml_output_vol_info_options (xmlTextWriterPtr writer, dict_t *dict,
{
int ret = -1;
int opt_count = 0;
- data_pair_t *pairs = 0;
data_t *value = 0;
char *ptr = NULL;
char key[1024] = {0,};
- int i = 0;
-
- pairs = dict->members_list;
- if (!pairs) {
- ret = -1;
- goto out;
- }
snprintf (key, sizeof (key), "%s.opt_count", prefix);
ret = dict_get_int32 (dict, key, &opt_count);
@@ -2100,25 +2092,31 @@ cli_xml_output_vol_info_options (xmlTextWriterPtr writer, dict_t *dict,
/* <options> */
ret = xmlTextWriterStartElement (writer, (xmlChar *)"options");
XML_RET_CHECK_AND_GOTO (ret, out);
- while (i < opt_count) {
- snprintf (key, sizeof (key), "%s.option.", prefix);
- while (pairs) {
- ptr = strstr (pairs->key, "option.");
- if (ptr) {
- value = pairs->value;
- if (!value) {
- ret = -1;
- goto out;
- }
- ret = cli_xml_output_vol_info_option
- (writer, key, pairs->key, value->data);
- if (ret)
- goto out;
- }
- pairs = pairs->next;
+ snprintf (key, sizeof (key), "%s.option.", prefix);
+
+ int _output_vol_info_option (dict_t *d, char *k, data_t *v,
+ void *data)
+ {
+ int ret = 0;
+ ptr = strstr (k, "option.");
+ if (!ptr)
+ goto internal_out;
+
+ value = v;
+ if (!value) {
+ ret = -1;
+ goto internal_out;
}
- i++;
+ ret = cli_xml_output_vol_info_option (writer, key, k,
+ v->data);
+
+ internal_out:
+ return ret;
}
+ ret = dict_foreach (dict, _output_vol_info_option, NULL);
+ if (ret)
+ goto out;
+
/* </options> */
ret = xmlTextWriterEndElement (writer);
XML_RET_CHECK_AND_GOTO (ret, out);