diff options
author | Vikas Gorur <vikas@gluster.com> | 2009-10-05 04:01:36 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-10-05 05:16:43 -0700 |
commit | 8e0f5e7105c0d03b50a9342f4285a985b9cdb090 (patch) | |
tree | 69d5a2b3be95c15782ab31596cb79eaa52439ed9 /xlators/cluster/afr/src/afr.h | |
parent | b441730b5b54fcd9355bef42bd0f45a4147212e4 (diff) |
cluster/afr: Initialize local->first_up_child in AFR_LOCAL_INIT.
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 285 ("first up child" can change during a transaction)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=285
Diffstat (limited to 'xlators/cluster/afr/src/afr.h')
-rw-r--r-- | xlators/cluster/afr/src/afr.h | 32 |
1 files changed, 29 insertions, 3 deletions
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) { |