From ac344e1cf5fb80f0c237f74508f5087741e94ee9 Mon Sep 17 00:00:00 2001 From: Vikas Gorur Date: Mon, 5 Oct 2009 04:02:10 +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.c | 26 -------------------------- xlators/cluster/afr/src/afr.h | 32 +++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 29 deletions(-) (limited to 'xlators/cluster/afr') diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c index fe0ec3f1d..f413a297c 100644 --- a/xlators/cluster/afr/src/afr.c +++ b/xlators/cluster/afr/src/afr.c @@ -314,32 +314,6 @@ afr_frame_return (call_frame_t *frame) return call_count; } -/** - * first_up_child - return the index of the first child that is up - */ - -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; -} - /** * up_children_count - return the number of children that are up diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h index 87e210b23..ba5015cc9 100644 --- a/xlators/cluster/afr/src/afr.h +++ b/xlators/cluster/afr/src/afr.h @@ -490,9 +490,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); @@ -568,11 +565,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