Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=f50272d497c5596a7b191b66ef216878b0fafc07 Commit: f50272d497c5596a7b191b66ef216878b0fafc07 Parent: 48ea9c79b17f5fd98ab07fb2dc219ffee00bfc89 Author: Lon Hohberger <lhh@redhat.com> AuthorDate: Fri Jul 31 15:42:58 2009 -0400 Committer: Lon Hohberger <lhh@redhat.com> CommitterDate: Wed Aug 12 10:46:24 2009 -0400 rgmanager: Fix incarnation handling * Don't allow simultaneous starts/stops of the *same* resource. * Make incarnation numbers consistent between start/stop Red Hat Bugzilla #506094, part 3/3 Signed-off-by: Lon Hohberger <lhh@redhat.com> --- rgmanager/include/reslist.h | 1 + rgmanager/src/daemons/reslist.c | 1 + rgmanager/src/daemons/restree.c | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletions(-) diff --git a/rgmanager/include/reslist.h b/rgmanager/include/reslist.h index 7e30db5..b202c2f 100644 --- a/rgmanager/include/reslist.h +++ b/rgmanager/include/reslist.h @@ -110,6 +110,7 @@ typedef struct _resource_rule { typedef struct _resource { list_head(); + pthread_mutex_t r_mutex; resource_rule_t * r_rule; char * r_name; resource_attr_t * r_attrs; diff --git a/rgmanager/src/daemons/reslist.c b/rgmanager/src/daemons/reslist.c index cdc68a0..94e8c64 100644 --- a/rgmanager/src/daemons/reslist.c +++ b/rgmanager/src/daemons/reslist.c @@ -749,6 +749,7 @@ load_resource(int ccsfd, resource_rule_t *rule, char *base) } memset(res, 0, sizeof(*res)); + pthread_mutex_init(&res->r_mutex, NULL); res->r_rule = rule; for (x = 0; res->r_rule->rr_attrs && diff --git a/rgmanager/src/daemons/restree.c b/rgmanager/src/daemons/restree.c index 6de7c49..d93921b 100644 --- a/rgmanager/src/daemons/restree.c +++ b/rgmanager/src/daemons/restree.c @@ -1345,6 +1345,7 @@ _res_op_internal(resource_node_t __attribute__ ((unused)) **tree, /* Start starts before children */ if (me && (op == RS_START)) { + pthread_mutex_lock(&node->rn_resource->r_mutex); if (node->rn_flags & RF_RECONFIG && realop == RS_CONDSTART) { rv = res_exec(node, RS_RECONFIG, NULL, 0); @@ -1355,6 +1356,7 @@ _res_op_internal(resource_node_t __attribute__ ((unused)) **tree, node->rn_flags &= ~(RF_NEEDSTART | RF_RECONFIG); if (rv != 0) { node->rn_state = RES_FAILED; + pthread_mutex_unlock(&node->rn_resource->r_mutex); return SFL_FAILURE; } @@ -1365,6 +1367,8 @@ _res_op_internal(resource_node_t __attribute__ ((unused)) **tree, ++node->rn_resource->r_incarnations; node->rn_state = RES_STARTED; } + pthread_mutex_unlock(&node->rn_resource->r_mutex); + } else if (me && (op == RS_STATUS || op == RS_STATUS_INQUIRY)) { /* Special quick-check for status inquiry */ @@ -1422,16 +1426,30 @@ _res_op_internal(resource_node_t __attribute__ ((unused)) **tree, /* Stop should occur after children have stopped */ if (me && (op == RS_STOP)) { + + /* Decrease incarnations so the script knows how many *other* + incarnations there are. */ + pthread_mutex_lock(&node->rn_resource->r_mutex); + if (node->rn_state == RES_STARTED) { + assert(node->rn_resource->r_incarnations > 0); + --node->rn_resource->r_incarnations; + } + node->rn_flags &= ~RF_NEEDSTOP; rv |= res_exec(node, op, NULL, 0); if (rv != 0) { + if (node->rn_state == RES_STARTED) { + /* Fail to stop: fix incarnations */ + ++node->rn_resource->r_incarnations; + } node->rn_state = RES_FAILED; + pthread_mutex_unlock(&node->rn_resource->r_mutex); return SFL_FAILURE; } + pthread_mutex_unlock(&node->rn_resource->r_mutex); if (node->rn_state != RES_STOPPED) { - --node->rn_resource->r_incarnations; node->rn_state = RES_STOPPED; } }