Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main-src > by-pkgid > e536fc0c6270ec1d92a0fd41bb1f8360 > files > 9

rgmanager-2.0.52-28.el5_8.2.src.rpm

From e27e6148dd6a033a3e0a57e04c06b6242efb3321 Mon Sep 17 00:00:00 2001
From: Lon Hohberger <lhh@redhat.com>
Date: Fri, 31 Jul 2009 15:42:58 -0400
Subject: [PATCH] rgmanager: Fix incarnation handling

* Don't allow simultaneous starts/stops of the *same*
resource.
* Make incarnation numbers consistent between start/stop

Resolves: rhbz506094

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;
 		}
 	}
-- 
1.6.2.5