summaryrefslogtreecommitdiffstats
path: root/libglusterfs
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 /libglusterfs
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 'libglusterfs')
-rw-r--r--libglusterfs/src/common-utils.h26
-rw-r--r--libglusterfs/src/dict.c83
-rw-r--r--libglusterfs/src/dict.h21
-rw-r--r--libglusterfs/src/graph-print.c18
-rw-r--r--libglusterfs/src/graph.c4
-rw-r--r--libglusterfs/src/options.c6
6 files changed, 111 insertions, 47 deletions
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 3d18a29a1..7e9145717 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -171,24 +171,26 @@ void gf_print_trace (int32_t signal, glusterfs_ctx_t *ctx);
} while (0)
-#define GF_IF_INTERNAL_XATTR_GOTO(pattern, dict, trav, op_errno, label) \
+#define GF_IF_INTERNAL_XATTR_GOTO(pattern, dict, op_errno, label) \
do { \
if (!dict) { \
gf_log (this->name, GF_LOG_ERROR, \
"setxattr dict is null"); \
goto label; \
} \
- trav = dict->members_list; \
- while (trav) { \
- if (!fnmatch (pattern, trav->key, 0)) { \
- op_errno = EPERM; \
- gf_log (this->name, GF_LOG_ERROR, \
- "attempt to set internal" \
- " xattr: %s: %s", trav->key, \
- strerror (op_errno)); \
- goto label; \
- } \
- trav = trav->next; \
+ int _handle_keyvalue_pair (dict_t *d, char *k, \
+ data_t *v, void *tmp) \
+ { \
+ return 0; \
+ } \
+ if (dict_foreach_fnmatch (dict, pattern, \
+ _handle_keyvalue_pair, NULL) > 0) { \
+ op_errno = EPERM; \
+ gf_log (this->name, GF_LOG_ERROR, \
+ "attempt to set internal" \
+ " xattr: %s: %s", pattern, \
+ strerror (op_errno)); \
+ goto label; \
} \
} while (0)
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index c290e0d62..1420246e8 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -14,6 +14,7 @@
#include <stdio.h>
#include <inttypes.h>
#include <limits.h>
+#include <fnmatch.h>
#ifndef _CONFIG_H
#define _CONFIG_H
@@ -208,7 +209,7 @@ _dict_lookup (dict_t *this, char *key)
}
int32_t
-dict_lookup (dict_t *this, char *key, data_pair_t **data)
+dict_lookup (dict_t *this, char *key, data_t **data)
{
if (!this || !key || !data) {
gf_log_callingfn ("dict", GF_LOG_WARNING,
@@ -216,16 +217,18 @@ dict_lookup (dict_t *this, char *key, data_pair_t **data)
return -1;
}
+ data_pair_t *tmp = NULL;
LOCK (&this->lock);
{
- *data = _dict_lookup (this, key);
+ tmp = _dict_lookup (this, key);
}
UNLOCK (&this->lock);
- if (*data)
- return 0;
- else
+
+ if (!tmp)
return -1;
+ *data = tmp->value;
+ return 0;
}
static int32_t
@@ -1051,47 +1054,93 @@ data_to_bin (data_t *data)
return data->data;
}
-void
+int
dict_foreach (dict_t *dict,
- void (*fn)(dict_t *this,
- char *key,
- data_t *value,
- void *data),
+ int (*fn)(dict_t *this,
+ char *key,
+ data_t *value,
+ void *data),
void *data)
{
if (!dict) {
gf_log_callingfn ("dict", GF_LOG_WARNING,
"dict is NULL");
- return;
+ return -1;
}
- data_pair_t *pairs = dict->members_list;
- data_pair_t *next = NULL;
+ int ret = -1;
+ data_pair_t *pairs = NULL;
+ data_pair_t *next = NULL;
+ pairs = dict->members_list;
while (pairs) {
next = pairs->next;
- fn (dict, pairs->key, pairs->value, data);
+ ret = fn (dict, pairs->key, pairs->value, data);
+ if (ret == -1)
+ return -1;
pairs = next;
}
+
+ return 0;
}
+/* return values:
+ -1 = failure,
+ 0 = no matches found,
+ +n = n number of matches
+*/
+int
+dict_foreach_fnmatch (dict_t *dict, char *pattern,
+ int (*fn)(dict_t *this,
+ char *key,
+ data_t *value,
+ void *data),
+ void *data)
+{
+ if (!dict) {
+ gf_log_callingfn ("dict", GF_LOG_WARNING,
+ "dict is NULL");
+ return 0;
+ }
-static void
+ int ret = -1;
+ int count = 0;
+ data_pair_t *pairs = NULL;
+ data_pair_t *next = NULL;
+
+ pairs = dict->members_list;
+ while (pairs) {
+ next = pairs->next;
+ if (!fnmatch (pattern, pairs->key, 0)) {
+ ret = fn (dict, pairs->key, pairs->value, data);
+ if (ret == -1)
+ return -1;
+ count++;
+ }
+ pairs = next;
+ }
+
+ return count;
+}
+
+
+static int
_copy (dict_t *unused,
char *key,
data_t *value,
void *newdict)
{
- dict_set ((dict_t *)newdict, key, (value));
+ return dict_set ((dict_t *)newdict, key, (value));
}
-static void
+static int
_remove (dict_t *dict,
char *key,
data_t *value,
void *unused)
{
dict_del ((dict_t *)dict, key);
+ return 0;
}
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h
index 17e9bcb45..050f7ca2f 100644
--- a/libglusterfs/src/dict.h
+++ b/libglusterfs/src/dict.h
@@ -122,7 +122,7 @@ dict_t *dict_ref (dict_t *dict);
data_t *data_ref (data_t *data);
void data_unref (data_t *data);
-int32_t dict_lookup (dict_t *this, char *key, data_pair_t **data);
+int32_t dict_lookup (dict_t *this, char *key, data_t **data);
/*
TODO: provide converts for differnt byte sizes, signedness, and void *
*/
@@ -165,12 +165,19 @@ data_t * data_copy (data_t *old);
dict_t *get_new_dict_full (int size_hint);
dict_t *get_new_dict ();
-void dict_foreach (dict_t *this,
- void (*fn)(dict_t *this,
- char *key,
- data_t *value,
- void *data),
- void *data);
+int dict_foreach (dict_t *this,
+ int (*fn)(dict_t *this,
+ char *key,
+ data_t *value,
+ void *data),
+ void *data);
+
+int dict_foreach_fnmatch (dict_t *dict, char *pattern,
+ int (*fn)(dict_t *this,
+ char *key,
+ data_t *value,
+ void *data),
+ void *data);
dict_t *dict_copy (dict_t *this, dict_t *new);
diff --git a/libglusterfs/src/graph-print.c b/libglusterfs/src/graph-print.c
index 667129864..862a93000 100644
--- a/libglusterfs/src/graph-print.c
+++ b/libglusterfs/src/graph-print.c
@@ -92,7 +92,6 @@ glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph)
} while (0)
xlator_t *trav = NULL;
- data_pair_t *pair = NULL;
xlator_list_t *xch = NULL;
int ret = 0;
ssize_t len = 0;
@@ -105,11 +104,18 @@ glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph)
GPPRINTF (gp, "volume %s\n type %s\n", trav->name,
trav->type);
- for (pair = trav->options->members_list; pair && pair->next;
- pair = pair->next);
- for (; pair; pair = pair->prev)
- GPPRINTF (gp, " option %s %s\n", pair->key,
- pair->value->data);
+ int _print_volume_options (dict_t *d, char *k, data_t *v,
+ void *tmp)
+ {
+ GPPRINTF (gp, " option %s %s\n", k, v->data);
+ return 0;
+ out:
+ /* means, it is a failure */
+ return -1;
+ }
+ ret = dict_foreach (trav->options, _print_volume_options, NULL);
+ if (ret)
+ goto out;
if (trav->children) {
GPPRINTF (gp, " subvolumes");
diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c
index a42ae7cd7..c18d02659 100644
--- a/libglusterfs/src/graph.c
+++ b/libglusterfs/src/graph.c
@@ -298,7 +298,7 @@ glusterfs_graph_init (glusterfs_graph_t *graph)
}
-static void
+static int
_log_if_unknown_option (dict_t *dict, char *key, data_t *value, void *data)
{
volume_option_t *found = NULL;
@@ -313,7 +313,7 @@ _log_if_unknown_option (dict_t *dict, char *key, data_t *value, void *data)
"option '%s' is not recognized", key);
}
- return;
+ return 0;
}
diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c
index fa238528e..6fa11283d 100644
--- a/libglusterfs/src/options.c
+++ b/libglusterfs/src/options.c
@@ -777,7 +777,7 @@ xlator_volume_option_get (xlator_t *xl, const char *key)
}
-static void
+static int
xl_opt_validate (dict_t *dict, char *key, data_t *value, void *data)
{
xlator_t *xl = NULL;
@@ -798,7 +798,7 @@ xl_opt_validate (dict_t *dict, char *key, data_t *value, void *data)
opt = xlator_volume_option_get_list (vol_opt, key);
if (!opt)
- return;
+ return 0;
ret = xlator_option_validate (xl, key, value->data, opt, &errstr);
if (ret)
@@ -816,7 +816,7 @@ xl_opt_validate (dict_t *dict, char *key, data_t *value, void *data)
dict_set (dict, opt->key[0], value);
dict_del (dict, key);
}
- return;
+ return 0;
}