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

[Cluster-devel] cluster/rgmanager/src daemons/resrules.c daemo ...



CVSROOT:	/cvs/cluster
Module name:	cluster
Branch: 	RHEL5
Changes by:	lhh sourceware org	2007-01-26 20:41:41

Modified files:
	rgmanager/src/daemons: resrules.c reslist.c Makefile 
	rgmanager/src/utils: clustat.c 

Log message:
	Fix #223230; allow <action> spec. in cluster.conf.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/daemons/resrules.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.16&r2=1.16.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/daemons/reslist.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.14&r2=1.14.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/daemons/Makefile.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.14&r2=1.14.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/utils/clustat.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.25.2.2&r2=1.25.2.3

--- cluster/rgmanager/src/daemons/resrules.c	2006/10/20 20:59:49	1.16
+++ cluster/rgmanager/src/daemons/resrules.c	2007/01/26 20:41:40	1.16.2.1
@@ -31,7 +31,9 @@
 #include <pthread.h>
 #include <dirent.h>
 #include <libgen.h>
+#ifndef NO_CCS
 #include <clulog.h>
+#endif
 
 
 /**
@@ -49,8 +51,13 @@
 
 	list_do(rulelist, curr) {
 		if (!strcmp(newrule->rr_type, curr->rr_type)) {
+#ifdef NO_CCS
 			fprintf(stderr, "Error storing %s: Duplicate\n",
 				newrule->rr_type);
+#else
+			clulog(LOG_ERR, "Error storing %s: Duplicate\n",
+				newrule->rr_type);
+#endif
 			return -1;
 		}
 
@@ -218,17 +225,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 +270,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 +314,7 @@
 }
 
 
+
 void
 _get_actions(xmlDocPtr doc, xmlXPathContextPtr ctx, char *base,
 		 resource_rule_t *rr)
@@ -294,8 +342,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 +370,8 @@
 		}
 
 		if (store_action(&rr->rr_actions, act, depth, timeout,
-				 interval) < 0)
+				 interval) != 0)
 			free(act);
-		
 	} while (1);
 }
 
@@ -866,6 +913,20 @@
 		type = xpath_get_one(doc, ctx, base);
 		if (!type)
 			break;
+		
+		if (!strcasecmp(type, "action")) {
+#ifdef NO_CCS
+			fprintf(stderr,
+				"Error: Resource type '%s' is reserved",
+				type);
+#else
+			clulog(LOG_ERR,
+				"Error: Resource type '%s' is reserved",
+				type);
+#endif
+			free(type);
+			break;
+		}
 
 		rr = malloc(sizeof(*rr));
 		if (!rr)
--- cluster/rgmanager/src/daemons/reslist.c	2006/07/11 23:52:41	1.14
+++ cluster/rgmanager/src/daemons/reslist.c	2007/01/26 20:41:40	1.14.2.1
@@ -28,6 +28,9 @@
 #include <list.h>
 #include <reslist.h>
 #include <pthread.h>
+#ifndef NO_CCS
+#include <clulog.h>
+#endif
 
 
 char *attr_value(resource_node_t *node, char *attrname);
@@ -360,12 +363,29 @@
 					/*
 					   Unique/primary is not unique
 					 */
-					printf("Unique/primary not unique "
-					       "type %s, %s=%s\n",
+#ifdef NO_CCS
+					printf("Error: "
+                                               "%s attribute collision. "
+                                               "type=%s attr=%s value=%s\n",
+					       (newres->r_attrs[x].ra_flags&
+                                                RA_PRIMARY)?"Primary":
+                                               "Unique",
+					       newres->r_rule->rr_type,
+					       newres->r_attrs[x].ra_name,
+					       newres->r_attrs[x].ra_value
+					       );
+#else 
+					clulog(LOG_ERR,
+                                               "%s attribute collision. "
+                                               "type=%s attr=%s value=%s\n",
+					       (newres->r_attrs[x].ra_flags&
+                                                RA_PRIMARY)?"Primary":
+                                               "Unique",
 					       newres->r_rule->rr_type,
 					       newres->r_attrs[x].ra_name,
 					       newres->r_attrs[x].ra_value
 					       );
+#endif
 					return -1;
 				}
 				break;
@@ -542,6 +562,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 +744,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,14 +776,21 @@
 		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;
 
 		       if (store_resource(reslist, newres) != 0) {
+#ifdef NO_CCS
 	       		       printf("Error storing %s resource\n",
 				      newres->r_rule->rr_type);
+#else
+	       		       clulog(LOG_ERR,
+				      "Error storing %s resource\n",
+				      newres->r_rule->rr_type);
+#endif
+
 			       destroy_resource(newres);
 		       }
 
--- cluster/rgmanager/src/daemons/Makefile	2006/07/12 14:38:01	1.14
+++ cluster/rgmanager/src/daemons/Makefile	2007/01/26 20:41:40	1.14.2.1
@@ -59,7 +59,7 @@
 # packages should run 'make check' as part of the build process.
 #
 rg_test: rg_locks-noccs.o test-noccs.o reslist-noccs.o \
-		resrules.o restree-noccs.o fo_domain-noccs.o
+		resrules-noccs.o restree-noccs.o fo_domain-noccs.o
 	$(CC) -o $@ $^ $(INCLUDE) $(CFLAGS) -llalloc $(LDFLAGS) -lccs -lcman
 
 clurmtabd: clurmtabd.o clurmtabd_lib.o
--- cluster/rgmanager/src/utils/clustat.c	2007/01/17 16:20:29	1.25.2.2
+++ cluster/rgmanager/src/utils/clustat.c	2007/01/26 20:41:41	1.25.2.3
@@ -20,6 +20,7 @@
 #define FLAG_LOCAL 0x2
 #define FLAG_RGMGR 0x4
 #define FLAG_NOCFG 0x8	/* Shouldn't happen */
+#define FLAG_QDISK 0x10
 
 #define RG_VERBOSE 0x1
 
@@ -342,8 +343,8 @@
 cluster_member_list_t *
 add_missing(cluster_member_list_t *all, cluster_member_list_t *these)
 {
-	int x, y;
-	cman_node_t *m, *new;
+	int x, y, addflag;
+	cman_node_t *m, *nn;
 
 	if (!these)
 		return all;
@@ -356,12 +357,8 @@
 				    these->cml_members[x].cn_name))
                         	m = &all->cml_members[y];
 		}
-
+        	
 		if (!m) {
-			printf("%s not found\n", these->cml_members[x].cn_name);
-			/* WTF? It's not in our config */
-			printf("realloc %d\n", (int)((all->cml_count+1) *
-			       sizeof(cman_node_t)));
 			all->cml_members = realloc(all->cml_members,
 						   (all->cml_count+1) *
 						   sizeof(cman_node_t));
@@ -370,15 +367,21 @@
 				exit(1);
 			}
 			
-			new = &all->cml_members[all->cml_count];
+			nn = &all->cml_members[all->cml_count];
 
-			memcpy(new, &these->cml_members[x],
+			memcpy(nn, &these->cml_members[x],
 			       sizeof(cman_node_t));
+			
+			if (nn->cn_nodeid == 0) { /* quorum disk? */
+				addflag = FLAG_QDISK;
+			} else {
+				addflag = FLAG_NOCFG;
+			}
 
-			if (new->cn_member) {
-				new->cn_member = FLAG_UP | FLAG_NOCFG;
+			if (nn->cn_member) {
+				nn->cn_member = FLAG_UP | addflag;
 			} else {
-				new->cn_member = FLAG_NOCFG;
+				nn->cn_member = addflag;
 			}
 			++all->cml_count;
 
@@ -612,9 +615,12 @@
 	
 	if (node->cn_member & FLAG_NOCFG)
 		printf(", Estranged");
-
+	
 	if (node->cn_member & FLAG_RGMGR)
 		printf(", rgmanager");
+	
+	if (node->cn_member & FLAG_QDISK)
+		printf(", Quorum Disk");
 
 	printf("\n");
 		
@@ -626,12 +632,13 @@
 xml_member_state(cman_node_t *node)
 {
 	printf("    <node name=\"%s\" state=\"%d\" local=\"%d\" "
-	       "estranged=\"%d\" rgmanager=\"%d\" nodeid=\"0x%08x\"/>\n",
+	       "estranged=\"%d\" rgmanager=\"%d\" qdisk=\"%d\" nodeid=\"0x%08x\"/>\n",
 	       node->cn_name,
 	       !!(node->cn_member & FLAG_UP),
 	       !!(node->cn_member & FLAG_LOCAL),
 	       !!(node->cn_member & FLAG_NOCFG),
 	       !!(node->cn_member & FLAG_RGMGR),
+	       !!(node->cn_member & FLAG_QDISK),
 	       (uint32_t)((node->cn_nodeid      )&0xffffffff));
 }
 


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