From 8e0f5e7105c0d03b50a9342f4285a985b9cdb090 Mon Sep 17 00:00:00 2001 From: Vikas Gorur Date: Mon, 5 Oct 2009 04:01:36 +0000 Subject: cluster/afr: Initialize local->first_up_child in AFR_LOCAL_INIT. Signed-off-by: Anand V. Avati BUG: 285 ("first up child" can change during a transaction) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=285 --- xlators/cluster/afr/src/afr.h | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'xlators/cluster/afr/src/afr.h') diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h index 37dc13959..a708f7d0a 100644 --- a/xlators/cluster/afr/src/afr.h +++ b/xlators/cluster/afr/src/afr.h @@ -514,9 +514,6 @@ afr_up_children_count (int child_count, unsigned char *child_up); int afr_locked_nodes_count (unsigned char *locked_nodes, int child_count); -int -afr_first_up_child (afr_private_t *priv); - ino64_t afr_itransform (ino64_t ino, int child_count, int child_index); @@ -592,11 +589,40 @@ AFR_LOCAL_INIT (afr_local_t *local, afr_private_t *priv) } +/** + * first_up_child - return the index of the first child that is up + */ + +static inline int +afr_first_up_child (afr_private_t *priv) +{ + xlator_t ** children = NULL; + int ret = -1; + int i = 0; + + LOCK (&priv->lock); + { + children = priv->children; + for (i = 0; i < priv->child_count; i++) { + if (priv->child_up[i]) { + ret = i; + break; + } + } + } + UNLOCK (&priv->lock); + + return ret; +} + + static inline int afr_transaction_local_init (afr_local_t *local, afr_private_t *priv) { int i; + local->first_up_child = afr_first_up_child (priv); + local->child_errno = CALLOC (sizeof (*local->child_errno), priv->child_count); if (!local->child_errno) { -- cgit