[PATCH] resource check time override

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've got a patch which allows one to override the hard-coded resource
check timings actions in cluster.conf.  It lets you do what you could
previously only do by hand-editing the resource-agents on a per-resource
basis:

<rm>
  <resources>
    <script name="rarrr" file="./rg_test">
      <action name="status" interval="120"/>
    </script>
  </resources>

  <service name="test12" autostart="0">
    <action name="status" interval="120"/>
    <script ref="rarrr"/>
  </service>
</rm>

The default "depth" for replacing is '*', or 'all depths'.  This means
that the most-intensive checking is done always.  If you want to
override just one depth of resource checking, you can do that, but you
have to specify the depth, i.e.:

    <action name="status" interval="120" depth="10"/>

Note that originally, I was going to make it work only in the global
<resources> block.  The current implementation does allow you to specify
it inline - but it might prove confusing to allow people to do it this
way (because it looks like a resource).  Additionally, the use of the
name "action" as a resource-type is not allowed.

Patches against head (will apply to RHEL5/50 branches) and RHEL4

Comments?

-- Lon
### Eclipse Workspace Patch 1.0
#P cluster-RHEL4
Index: rgmanager/src/daemons/resrules.c
===================================================================
RCS file: /cvs/cluster/cluster/rgmanager/src/daemons/resrules.c,v
retrieving revision 1.9.2.4
diff -u -r1.9.2.4 resrules.c
--- rgmanager/src/daemons/resrules.c	20 Oct 2006 20:57:19 -0000	1.9.2.4
+++ rgmanager/src/daemons/resrules.c	14 Nov 2006 23:53:28 -0000
@@ -248,17 +248,36 @@
 }
 
 
+/**
+ * Store a resource action
+ * @param actsp		Action array; may be modified and returned!
+ * @param name		Name of the action
+ * @param depth		Resource depth (status/monitor; -1 means *ALL LEVELS*
+ * 			... this means that only the highest-level check depth
+ * 			will ever be performed!)
+ * @param timeout	Timeout (not used)
+ * @param interval	Time interval for status/monitor
+ * @return		0 on success, -1 on failure
+ * 
+ */
 int
 store_action(resource_act_t **actsp, char *name, int depth,
 	     int timeout, int interval)
 {
-	int x = 0;
+	int x = 0, replace = 0;
 	resource_act_t *acts = *actsp;
 
 	if (!name)
 		return -1;
+	
+	if (depth < 0 && timeout < 0 && interval < 0)
+		return -1;
 
 	if (!acts) {
+		/* Can't create with anything < 0 */
+		if (depth < 0 || timeout < 0 || interval < 0)
+			return -1;
+		
 		acts = malloc(sizeof(resource_act_t) * 2);
 		if (!acts)
 			return -1;
@@ -274,17 +293,38 @@
 
 	for (x = 0; acts[x].ra_name; x++) {
 		if (!strcmp(acts[x].ra_name, name) &&
-		    depth == acts[x].ra_depth) {
-			printf("Skipping duplicate action/depth %s/%d\n",
-			       name, depth);
-			return -1;
+		    (depth == acts[x].ra_depth || depth == -1)) {
+			printf("Replacing action '%s' depth %d: ",
+			       name, acts[x].ra_depth);
+			if (timeout >= 0) {
+				printf("timeout: %d->%d ",
+				       (int)acts[x].ra_timeout,
+				       (int)timeout);
+				acts[x].ra_timeout = timeout;
+			}
+			if (interval >= 0) {
+				printf("interval: %d->%d",
+				       (int)acts[x].ra_interval,
+				       (int)interval);
+				acts[x].ra_interval = interval;
+			}
+			printf("\n");
+			replace = 1;
 		}
 	}
+	
+	if (replace)
+		/* If we replaced something, we're done */
+		return 1;
+	
+	/* Can't create with anything < 0 */
+	if (depth < 0 || timeout < 0 || interval < 0)
+		return -1;
 
 	acts = realloc(acts, sizeof(resource_act_t) * (x+2));
 	if (!acts)
 		return -1;
-
+	
 	acts[x].ra_name = name;
 	acts[x].ra_depth = depth;
 	acts[x].ra_timeout = timeout;
@@ -297,6 +337,7 @@
 }
 
 
+
 void
 _get_actions(xmlDocPtr doc, xmlXPathContextPtr ctx, char *base,
 		 resource_rule_t *rr)
@@ -324,8 +365,8 @@
 		ret = xpath_get_one(doc, ctx, xpath);
 		if (ret) {
 			timeout = expand_time(ret);
-			if (interval < 0)
-				interval = 0;
+			if (timeout < 0)
+				timeout = 0;
 			free(ret);
 		}
 
@@ -352,9 +393,8 @@
 		}
 
 		if (store_action(&rr->rr_actions, act, depth, timeout,
-				 interval) < 0)
+				 interval) != 0)
 			free(act);
-		
 	} while (1);
 
 
@@ -946,6 +986,14 @@
 		type = xpath_get_one(doc, ctx, base);
 		if (!type)
 			break;
+		
+		if (!strcasecmp(type, "action")) {
+			fprintf(stderr,
+				"Error: Resource type '%s' is reserved",
+				type);
+			free(type);
+			break;
+		}
 
 		rr = malloc(sizeof(*rr));
 		if (!rr)
Index: rgmanager/src/daemons/reslist.c
===================================================================
RCS file: /cvs/cluster/cluster/rgmanager/src/daemons/reslist.c,v
retrieving revision 1.6.2.6
diff -u -r1.6.2.6 reslist.c
--- rgmanager/src/daemons/reslist.c	17 Oct 2005 20:23:52 -0000	1.6.2.6
+++ rgmanager/src/daemons/reslist.c	14 Nov 2006 23:53:27 -0000
@@ -523,6 +523,83 @@
 }
 
 
+/* Copied from resrules.c -- _get_actions */
+void
+_get_actions_ccs(int ccsfd, char *base, resource_t *res)
+{
+	char xpath[256];
+	int idx = 0;
+	char *act, *ret;
+	int interval, timeout, depth;
+
+	do {
+		/* setting these to -1 prevents overwriting with 0 */
+		interval = -1;
+		depth = -1;
+		act = NULL;
+		timeout = -1;
+
+		snprintf(xpath, sizeof(xpath),
+			 "%s/action[%d]/@name", base, ++idx);
+
+#ifndef NO_CCS
+		if (ccs_get(ccsfd, xpath, &act) != 0)
+#else
+		if (conf_get(xpath, &act) != 0)
+#endif
+			break;
+
+		snprintf(xpath, sizeof(xpath),
+			 "%s/action[%d]/@timeout", base, idx);
+#ifndef NO_CCS
+		if (ccs_get(ccsfd, xpath, &ret) == 0 && ret) {
+#else
+		if (conf_get(xpath, &ret) == 0 && ret) {
+#endif
+			timeout = expand_time(ret);
+			if (timeout < 0)
+				timeout = 0;
+			free(ret);
+		}
+
+		snprintf(xpath, sizeof(xpath),
+			 "%s/action[%d]/@interval", base, idx);
+#ifndef NO_CCS
+		if (ccs_get(ccsfd, xpath, &ret) == 0 && ret) {
+#else
+		if (conf_get(xpath, &ret) == 0 && ret) {
+#endif
+			interval = expand_time(ret);
+			if (interval < 0)
+				interval = 0;
+			free(ret);
+		}
+
+		if (!strcmp(act, "status") || !strcmp(act, "monitor")) {
+			snprintf(xpath, sizeof(xpath),
+				 "%s/action[%d]/@depth", base, idx);
+#ifndef NO_CCS
+			if (ccs_get(ccsfd, xpath, &ret) == 0 && ret) {
+#else
+			if (conf_get(xpath, &ret) == 0 && ret) {
+#endif
+				depth = atoi(ret);
+				if (depth < 0)
+					depth = 0;
+				
+				/* */
+				if (ret[0] == '*')
+					depth = -1;
+				free(ret);
+			}
+		}
+
+		if (store_action(&res->r_actions, act, depth, timeout,
+				 interval) != 0)
+			free(act);
+	} while (1);
+}
+
 
 /**
    Try to load all the attributes in our rule set.  If none are found,
@@ -628,12 +705,12 @@
 	}
 
 	if (!found) {
-		//printf("No attributes found for %s\n", base);
 		destroy_resource(res);
 		return NULL;
 	}
 
 	res->r_actions = act_dup(rule->rr_actions);
+	_get_actions_ccs(ccsfd, base, res);
 
 	return res;
 }
@@ -660,7 +737,7 @@
 		for (resID = 1; ; resID++) {
 			snprintf(tok, sizeof(tok), RESOURCE_BASE "/%s[%d]",
 				 currule->rr_type, resID);
-
+			
 			newres = load_resource(ccsfd, currule, tok);
 			if (!newres)
 				break;
### Eclipse Workspace Patch 1.0
#P cluster
Index: rgmanager/src/daemons/reslist.c
===================================================================
RCS file: /cvs/cluster/cluster/rgmanager/src/daemons/reslist.c,v
retrieving revision 1.14
diff -u -r1.14 reslist.c
--- rgmanager/src/daemons/reslist.c	11 Jul 2006 23:52:41 -0000	1.14
+++ rgmanager/src/daemons/reslist.c	14 Nov 2006 23:49:12 -0000
@@ -542,6 +542,83 @@
 }
 
 
+/* Copied from resrules.c -- _get_actions */
+void
+_get_actions_ccs(int ccsfd, char *base, resource_t *res)
+{
+	char xpath[256];
+	int idx = 0;
+	char *act, *ret;
+	int interval, timeout, depth;
+
+	do {
+		/* setting these to -1 prevents overwriting with 0 */
+		interval = -1;
+		depth = -1;
+		act = NULL;
+		timeout = -1;
+
+		snprintf(xpath, sizeof(xpath),
+			 "%s/action[%d]/@name", base, ++idx);
+
+#ifndef NO_CCS
+		if (ccs_get(ccsfd, xpath, &act) != 0)
+#else
+		if (conf_get(xpath, &act) != 0)
+#endif
+			break;
+
+		snprintf(xpath, sizeof(xpath),
+			 "%s/action[%d]/@timeout", base, idx);
+#ifndef NO_CCS
+		if (ccs_get(ccsfd, xpath, &ret) == 0 && ret) {
+#else
+		if (conf_get(xpath, &ret) == 0 && ret) {
+#endif
+			timeout = expand_time(ret);
+			if (timeout < 0)
+				timeout = 0;
+			free(ret);
+		}
+
+		snprintf(xpath, sizeof(xpath),
+			 "%s/action[%d]/@interval", base, idx);
+#ifndef NO_CCS
+		if (ccs_get(ccsfd, xpath, &ret) == 0 && ret) {
+#else
+		if (conf_get(xpath, &ret) == 0 && ret) {
+#endif
+			interval = expand_time(ret);
+			if (interval < 0)
+				interval = 0;
+			free(ret);
+		}
+
+		if (!strcmp(act, "status") || !strcmp(act, "monitor")) {
+			snprintf(xpath, sizeof(xpath),
+				 "%s/action[%d]/@depth", base, idx);
+#ifndef NO_CCS
+			if (ccs_get(ccsfd, xpath, &ret) == 0 && ret) {
+#else
+			if (conf_get(xpath, &ret) == 0 && ret) {
+#endif
+				depth = atoi(ret);
+				if (depth < 0)
+					depth = 0;
+				
+				/* */
+				if (ret[0] == '*')
+					depth = -1;
+				free(ret);
+			}
+		}
+
+		if (store_action(&res->r_actions, act, depth, timeout,
+				 interval) != 0)
+			free(act);
+	} while (1);
+}
+
 
 /**
    Try to load all the attributes in our rule set.  If none are found,
@@ -647,12 +724,12 @@
 	}
 
 	if (!found) {
-		//printf("No attributes found for %s\n", base);
 		destroy_resource(res);
 		return NULL;
 	}
 
 	res->r_actions = act_dup(rule->rr_actions);
+	_get_actions_ccs(ccsfd, base, res);
 
 	return res;
 }
@@ -679,7 +756,7 @@
 		for (resID = 1; ; resID++) {
 			snprintf(tok, sizeof(tok), RESOURCE_BASE "/%s[%d]",
 				 currule->rr_type, resID);
-
+			
 			newres = load_resource(ccsfd, currule, tok);
 			if (!newres)
 				break;
Index: rgmanager/src/daemons/resrules.c
===================================================================
RCS file: /cvs/cluster/cluster/rgmanager/src/daemons/resrules.c,v
retrieving revision 1.16
diff -u -r1.16 resrules.c
--- rgmanager/src/daemons/resrules.c	20 Oct 2006 20:59:49 -0000	1.16
+++ rgmanager/src/daemons/resrules.c	14 Nov 2006 23:49:12 -0000
@@ -218,17 +218,36 @@
 }
 
 
+/**
+ * Store a resource action
+ * @param actsp		Action array; may be modified and returned!
+ * @param name		Name of the action
+ * @param depth		Resource depth (status/monitor; -1 means *ALL LEVELS*
+ * 			... this means that only the highest-level check depth
+ * 			will ever be performed!)
+ * @param timeout	Timeout (not used)
+ * @param interval	Time interval for status/monitor
+ * @return		0 on success, -1 on failure
+ * 
+ */
 int
 store_action(resource_act_t **actsp, char *name, int depth,
 	     int timeout, int interval)
 {
-	int x = 0;
+	int x = 0, replace = 0;
 	resource_act_t *acts = *actsp;
 
 	if (!name)
 		return -1;
+	
+	if (depth < 0 && timeout < 0 && interval < 0)
+		return -1;
 
 	if (!acts) {
+		/* Can't create with anything < 0 */
+		if (depth < 0 || timeout < 0 || interval < 0)
+			return -1;
+		
 		acts = malloc(sizeof(resource_act_t) * 2);
 		if (!acts)
 			return -1;
@@ -244,17 +263,38 @@
 
 	for (x = 0; acts[x].ra_name; x++) {
 		if (!strcmp(acts[x].ra_name, name) &&
-		    depth == acts[x].ra_depth) {
-			printf("Skipping duplicate action/depth %s/%d\n",
-			       name, depth);
-			return -1;
+		    (depth == acts[x].ra_depth || depth == -1)) {
+			printf("Replacing action '%s' depth %d: ",
+			       name, acts[x].ra_depth);
+			if (timeout >= 0) {
+				printf("timeout: %d->%d ",
+				       (int)acts[x].ra_timeout,
+				       (int)timeout);
+				acts[x].ra_timeout = timeout;
+			}
+			if (interval >= 0) {
+				printf("interval: %d->%d",
+				       (int)acts[x].ra_interval,
+				       (int)interval);
+				acts[x].ra_interval = interval;
+			}
+			printf("\n");
+			replace = 1;
 		}
 	}
+	
+	if (replace)
+		/* If we replaced something, we're done */
+		return 1;
+	
+	/* Can't create with anything < 0 */
+	if (depth < 0 || timeout < 0 || interval < 0)
+		return -1;
 
 	acts = realloc(acts, sizeof(resource_act_t) * (x+2));
 	if (!acts)
 		return -1;
-
+	
 	acts[x].ra_name = name;
 	acts[x].ra_depth = depth;
 	acts[x].ra_timeout = timeout;
@@ -267,6 +307,7 @@
 }
 
 
+
 void
 _get_actions(xmlDocPtr doc, xmlXPathContextPtr ctx, char *base,
 		 resource_rule_t *rr)
@@ -294,8 +335,8 @@
 		ret = xpath_get_one(doc, ctx, xpath);
 		if (ret) {
 			timeout = expand_time(ret);
-			if (interval < 0)
-				interval = 0;
+			if (timeout < 0)
+				timeout = 0;
 			free(ret);
 		}
 
@@ -322,9 +363,8 @@
 		}
 
 		if (store_action(&rr->rr_actions, act, depth, timeout,
-				 interval) < 0)
+				 interval) != 0)
 			free(act);
-		
 	} while (1);
 }
 
@@ -866,6 +906,14 @@
 		type = xpath_get_one(doc, ctx, base);
 		if (!type)
 			break;
+		
+		if (!strcasecmp(type, "action")) {
+			fprintf(stderr,
+				"Error: Resource type '%s' is reserved",
+				type);
+			free(type);
+			break;
+		}
 
 		rr = malloc(sizeof(*rr));
 		if (!rr)

Attachment: signature.asc
Description: This is a digitally signed message part

--
Linux-cluster mailing list
Linux-cluster@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/linux-cluster

[Index of Archives]     [Corosync Cluster Engine]     [GFS]     [Linux Virtualization]     [Centos Virtualization]     [Centos]     [Linux RAID]     [Fedora Users]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite Camping]

  Powered by Linux