From d499cb8064f61b70bc37a7d6cbf0f0c3b219c342 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Tue, 16 Aug 2011 12:17:29 +0530 Subject: 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 Reviewed-by: Amar Tumballi --- xlators/cluster/dht/src/dht-common.c | 60 ++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 17 deletions(-) (limited to 'xlators/cluster/dht/src/dht-common.c') 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); -- cgit