summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/dht/src
diff options
context:
space:
mode:
authorVenky Shankar <venky@gluster.com>2011-08-16 12:17:29 +0530
committerVijay Bellur <vijay@gluster.com>2011-08-24 06:41:39 -0700
commitd499cb8064f61b70bc37a7d6cbf0f0c3b219c342 (patch)
tree5a93bc707dd7a18e103e0ce686615711323f9775 /xlators/cluster/dht/src
parent6f1062f3473407cebfd5d902db2d2c6965dcf034 (diff)
afr/stripe: collect pathinfo xattr from all childs
Change-Id: Iec8b609e66ef21f4fdd6ee2ff3060f0b71d47ca0 BUG: 3046 Reviewed-on: http://review.gluster.com/237 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Amar Tumballi <amar@gluster.com>
Diffstat (limited to 'xlators/cluster/dht/src')
-rw-r--r--xlators/cluster/dht/src/dht-common.c60
-rw-r--r--xlators/cluster/dht/src/dht-common.h1
2 files changed, 44 insertions, 17 deletions
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
index 3bd9df9c3..e03c463bc 100644
--- a/xlators/cluster/dht/src/dht-common.c
+++ b/xlators/cluster/dht/src/dht-common.c
@@ -1913,28 +1913,50 @@ int
dht_pathinfo_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int op_ret, int op_errno, dict_t *xattr)
{
- dht_local_t *local = NULL;
- int ret = 0;
- int flag = 0;
- int this_call_cnt = 0;
- char *value_got = NULL;
- char layout_buf[8192] = {0,};
- char xattr_buf[8192 + 1024] = {0,};
- dict_t *dict = NULL;
+ dht_local_t *local = NULL;
+ int ret = 0;
+ int flag = 0;
+ int this_call_cnt = 0;
+ char *value_got = NULL;
+ char layout_buf[8192] = {0,};
+ char *xattr_buf = NULL;
+ dict_t *dict = NULL;
+ int32_t alloc_len = 0;
+ int32_t plen = 0;
local = frame->local;
if (op_ret != -1) {
ret = dict_get_str (xattr, GF_XATTR_PATHINFO_KEY, &value_got);
if (!ret) {
- if (!local->pathinfo)
- local->pathinfo = GF_CALLOC (8192, sizeof (char),
- gf_common_mt_char);
- if (local->pathinfo)
+ alloc_len = strlen (value_got);
+
+ /**
+ * allocate the buffer:- we allocate 10 bytes extra in case we need to
+ * append ' Link: ' in the buffer for another STACK_WIND
+ */
+ if (!local->pathinfo) {
+ alloc_len += (strlen (DHT_PATHINFO_HEADER) + 10);
+ local->pathinfo = GF_CALLOC (alloc_len, sizeof (char), gf_common_mt_char);
+ }
+
+ if (local->pathinfo) {
+ plen = strlen (local->pathinfo);
+ if (plen) {
+ /* extra byte(s) for \0 to be safe */
+ alloc_len += (plen + 2);
+ local->pathinfo = GF_REALLOC (local->pathinfo,
+ alloc_len);
+ if (!local->pathinfo)
+ goto out;
+ }
+
strcat (local->pathinfo, value_got);
+ }
}
}
+ out:
this_call_cnt = dht_frame_return (frame);
if (is_last_call (this_call_cnt)) {
if (local->layout->cnt > 1) {
@@ -1945,19 +1967,23 @@ dht_pathinfo_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
dict = dict_new ();
+ /* we would need max-to-max this many bytes to create pathinfo string */
+ alloc_len += (2 * strlen (this->name)) + strlen (layout_buf) + 40;
+ xattr_buf = GF_CALLOC (alloc_len, sizeof (char), gf_common_mt_char);
+
if (flag && local->pathinfo)
- snprintf (xattr_buf, 9216, "((%s %s) (%s-layout %s))",
+ snprintf (xattr_buf, alloc_len, "((<"DHT_PATHINFO_HEADER"%s> %s) (%s-layout %s))",
this->name, local->pathinfo, this->name,
layout_buf);
else if (local->pathinfo)
- snprintf (xattr_buf, 9216, "(%s %s)",
+ snprintf (xattr_buf, alloc_len, "(<"DHT_PATHINFO_HEADER"%s> %s)",
this->name, local->pathinfo);
else if (flag)
- snprintf (xattr_buf, 9216, "(%s-layout %s)",
+ snprintf (xattr_buf, alloc_len, "(%s-layout %s)",
this->name, layout_buf);
- ret = dict_set_str (dict, GF_XATTR_PATHINFO_KEY,
- xattr_buf);
+ ret = dict_set_dynstr (dict, GF_XATTR_PATHINFO_KEY,
+ xattr_buf);
if (local->pathinfo)
GF_FREE (local->pathinfo);
diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h
index 7e93b02f8..437e0dff3 100644
--- a/xlators/cluster/dht/src/dht-common.h
+++ b/xlators/cluster/dht/src/dht-common.h
@@ -31,6 +31,7 @@
#define GF_XATTR_FIX_LAYOUT_KEY "trusted.distribute.fix.layout"
#define GF_DHT_LOOKUP_UNHASHED_ON 1
#define GF_DHT_LOOKUP_UNHASHED_AUTO 2
+#define DHT_PATHINFO_HEADER "DISTRIBUTE:"
#include <fnmatch.h>