summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/dht/src/dht-common.c
diff options
context:
space:
mode:
authorVenky Shankar <venky@gluster.com>2011-07-01 00:18:53 +0000
committerAnand Avati <avati@gluster.com>2011-07-12 05:37:51 -0700
commit4c55f76d6a4d13ec1ed3cffd31ff4acc3d3122f0 (patch)
treebdc9a5522e30adee821e53f2bb5613e7296aa95d /xlators/cluster/dht/src/dht-common.c
parent1a82b4539b69390dfb1a158c420385c7ad5d999f (diff)
afr/stripe: collect pathinfo xattrs from all childs
Signed-off-by: Venky Shankar <venky@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 3046 (getxattr for afr should returns realpath from all childs) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=3046
Diffstat (limited to 'xlators/cluster/dht/src/dht-common.c')
-rw-r--r--xlators/cluster/dht/src/dht-common.c56
1 files changed, 40 insertions, 16 deletions
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
index 18bb65d30..c07de1380 100644
--- a/xlators/cluster/dht/src/dht-common.c
+++ b/xlators/cluster/dht/src/dht-common.c
@@ -1680,28 +1680,48 @@ 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) {
+ 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)
- local->pathinfo = GF_CALLOC (8192, sizeof (char),
- gf_common_mt_char);
- if (local->pathinfo)
+ local->pathinfo = GF_CALLOC (alloc_len + strlen (DHT_PATHINFO_HEADER) + 10,
+ sizeof (char), gf_common_mt_char);
+
+ if (local->pathinfo) {
+ plen = strlen (local->pathinfo);
+ if (plen) {
+ alloc_len += plen;
+ 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) {
@@ -1712,19 +1732,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);