summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@zresearch.com>2009-05-15 03:55:50 -0700
committerAnand V. Avati <avati@amp.gluster.com>2009-05-16 16:40:26 +0530
commit254f770af6ae6ff207fc567b6576a31469c84f67 (patch)
tree148d1d0a88e606c01533b584379e33e971caebe6 /libglusterfs
parent9669c70c901474dc21ef08e49478b5f5dead8f64 (diff)
dict.c: make dict_serialized_length and dict_serialize to hold locks.
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/dict.c130
1 files changed, 10 insertions, 120 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index b4c75d79f89..eb9dfab2266 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -2228,75 +2228,18 @@ int
dict_serialized_length (dict_t *this)
{
int ret = -EINVAL;
- int count = 0;
- int len = 0;
- int i = 0;
- data_pair_t * pair = NULL;
if (!this) {
gf_log ("dict", GF_LOG_ERROR, "this is null!");
goto out;
}
- len = DICT_HDR_LEN;
- count = this->count;
-
- if (count < 0) {
- gf_log ("dict", GF_LOG_ERROR, "count (%d) < 0!", count);
- goto out;
- }
-
- pair = this->members_list;
-
- while (count) {
- if (!pair) {
- gf_log ("dict", GF_LOG_ERROR,
- "less than count data pairs found!");
- goto out;
- }
-
- len += DICT_DATA_HDR_KEY_LEN + DICT_DATA_HDR_VAL_LEN;
-
- if (!pair->key) {
- gf_log ("dict", GF_LOG_ERROR, "pair->key is null!");
- goto out;
- }
-
- len += strlen (pair->key) + 1 /* for '\0' */;
-
- if (!pair->value) {
- gf_log ("dict", GF_LOG_ERROR,
- "pair->value is null!");
- goto out;
- }
-
- if (pair->value->vec) {
- for (i = 0; i < pair->value->len; i++) {
- if (pair->value->vec[i].iov_len < 0) {
- gf_log ("dict", GF_LOG_ERROR,
- "iov_len (%"GF_PRI_SIZET") < 0!",
- pair->value->vec[i].iov_len);
- goto out;
- }
-
- len += pair->value->vec[i].iov_len;
- }
- } else {
- if (pair->value->len < 0) {
- gf_log ("dict", GF_LOG_ERROR,
- "value->len (%d) < 0",
- pair->value->len);
- goto out;
- }
-
- len += pair->value->len;
- }
+ LOCK (&this->lock);
+ {
+ ret = _dict_serialized_length (this);
+ }
+ UNLOCK (&this->lock);
- pair = pair->next;
- count--;
- }
-
- ret = len;
out:
return ret;
}
@@ -2316,10 +2259,6 @@ int
dict_serialize (dict_t *this, char *buf)
{
int ret = -1;
- data_pair_t * pair = NULL;
- int32_t count = 0;
- int32_t keylen = 0;
- int32_t vallen = 0;
if (!this) {
gf_log ("dict", GF_LOG_ERROR,
@@ -2331,61 +2270,12 @@ dict_serialize (dict_t *this, char *buf)
"buf is null!");
goto out;
}
-
- count = this->count;
- if (count < 0) {
- gf_log ("dict", GF_LOG_ERROR, "count (%d) < 0!", count);
- goto out;
- }
-
- *(int32_t *) buf = hton32 (count);
- buf += DICT_HDR_LEN;
- pair = this->members_list;
- while (count) {
- if (!pair) {
- gf_log ("dict", GF_LOG_ERROR,
- "less than count data pairs found!");
- goto out;
- }
-
- if (!pair->key) {
- gf_log ("dict", GF_LOG_ERROR,
- "pair->key is null!");
- goto out;
- }
-
- keylen = strlen (pair->key);
- *(int32_t *) buf = hton32 (keylen);
- buf += DICT_DATA_HDR_KEY_LEN;
-
- if (!pair->value) {
- gf_log ("dict", GF_LOG_ERROR,
- "pair->value is null!");
- goto out;
- }
-
- vallen = pair->value->len;
- *(int32_t *) buf = hton32 (vallen);
- buf += DICT_DATA_HDR_VAL_LEN;
-
- memcpy (buf, pair->key, keylen);
- buf += keylen;
- *buf++ = '\0';
-
- if (!pair->value->data) {
- gf_log ("dict", GF_LOG_ERROR,
- "pair->value->data is null!");
- goto out;
- }
- memcpy (buf, pair->value->data, vallen);
- buf += vallen;
-
- pair = pair->next;
- count--;
- }
-
- ret = 0;
+ LOCK (&this->lock);
+ {
+ ret = _dict_serialize (this, buf);
+ }
+ UNLOCK (&this->lock);
out:
return ret;
}