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

[Cluster-devel] cluster/rgmanager/src/utils clustat.c



CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	lhh sourceware org	2006-12-13 18:36:09

Modified files:
	rgmanager/src/utils: clustat.c 

Log message:
	Fix #211468 - clustat always returns 0, but should give a nonzero code for non-running services.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/utils/clustat.c.diff?cvsroot=cluster&r1=1.26&r2=1.27

--- cluster/rgmanager/src/utils/clustat.c	2006/12/13 17:12:02	1.26
+++ cluster/rgmanager/src/utils/clustat.c	2006/12/13 18:36:09	1.27
@@ -485,14 +485,17 @@
 }
 
 
-void
+int
 txt_rg_states(rg_state_list_t *rgl, cluster_member_list_t *members, 
 	      char *svcname, int flags)
 {
-	int x;
+	int x, ret = 0;
 
 	if (!rgl || !members)
-		return;
+		return -1;
+
+	if (svcname)
+		ret = -1;
 
 	if (!(flags & RG_VERBOSE)) {
 		printf("  %-20.20s %-30.30s %-14.14s\n",
@@ -509,18 +512,32 @@
 		    strcmp(rgl->rgl_states[x].rs_name, svcname))
 			continue;
 		txt_rg_state(&rgl->rgl_states[x], members, flags);
+		if (svcname) {
+			switch (rgl->rgl_states[x].rs_state) {
+			case RG_STATE_STARTING:
+			case RG_STATE_STARTED:
+			case RG_STATE_STOPPING:
+				ret = 0;
+				break;
+			default:
+				ret = rgl->rgl_states[x].rs_state;
+			}
+		}
 	}
+	
+	return ret;
 }
 
 
-void
+int
 xml_rg_states(rg_state_list_t *rgl, cluster_member_list_t *members,
 	      char *svcname)
 {
 	int x;
+	int ret = 0;
 
 	if (!rgl || !members)
-		return;
+		return -1;
 
 	printf("  <groups>\n");
 
@@ -528,14 +545,23 @@
 		if (svcname &&
 		    strcmp(rgl->rgl_states[x].rs_name, svcname))
 			continue;
-		xml_rg_state(&rgl->rgl_states[x], members, 0);
+		if (svcname) {
+			switch (rgl->rgl_states[x].rs_state) {
+			case RG_STATE_STARTING:
+			case RG_STATE_STARTED:
+			case RG_STATE_STOPPING:
+				break;
+			default:
+				ret = rgl->rgl_states[x].rs_state;
+			}
+		}
 	}
 
 	printf("  </groups>\n");
+	return ret;
 }
 
 
-
 void
 txt_quorum_state(int qs)
 {
@@ -609,10 +635,15 @@
 }
 
 
-void
+int
 txt_member_states(cluster_member_list_t *membership, char *name)
 {
-	int x;
+	int x, ret = 0;
+
+  	if (!membership) {
+  		printf("Membership information not available\n");
+ 		return -1;
+  	}
 
 	printf("  %-34.34s %-4.4s %s\n", "Member Name", "ID", "Status");
 	printf("  %-34.34s %-4.4s %s\n", "------ ----", "----", "------");
@@ -621,35 +652,45 @@
 		if (name && strcmp(membership->cml_members[x].cn_name, name))
 			continue;
 		txt_member_state(&membership->cml_members[x]);
+ 		ret = !(membership->cml_members[x].cn_member & FLAG_UP);
 	}
 
 	printf("\n");
+	return ret;
 }
 
 
-void
+int
 xml_member_states(cluster_member_list_t *membership, char *name)
 {
-	int x;
+	int x, ret = 0;
 
-	if (!membership)
-		return;
+	if (!membership) {
+		printf("  <nodes/>\n");
+		return -1;
+	}
 
 	printf("  <nodes>\n");
 	for (x = 0; x < membership->cml_count; x++) {
 		if (name && strcmp(membership->cml_members[x].cn_name, name))
 			continue;
 		xml_member_state(&membership->cml_members[x]);
+		if (name)
+			ret = !(membership->cml_members[x].cn_member & FLAG_UP);
 	}
 	printf("  </nodes>\n");
+	
+	return ret;
 }
 
 
-void
+int 
 txt_cluster_status(int qs, cluster_member_list_t *membership,
 		   rg_state_list_t *rgs, char *name, char *svcname, 
 		   int flags)
 {
+	int ret;
+	
 	if (!svcname && !name) {
 		txt_quorum_state(qs);
 		if (!membership) {
@@ -659,18 +700,22 @@
 		}
 	}
 
-	if (!svcname || (name && svcname))
-		txt_member_states(membership, name);
-	if (!name || (name && svcname))
-		txt_rg_states(rgs, membership, svcname, flags);
+  	if (!svcname || (name && svcname))
+ 		ret = txt_member_states(membership, name);
+ 	if (name && !svcname)
+ 		return ret;
+ 	if (!name || (name && svcname))
+ 		ret = txt_rg_states(rgs, membership, svcname, flags);
+ 	return ret;
 }
 
 
-void
+int
 xml_cluster_status(int qs, cluster_member_list_t *membership,
 		   rg_state_list_t *rgs, char *name, char *svcname,
 		   int flags)
 {
+ 	int ret1 = 0, ret2 = -1;
 	int x;
 
 	printf("<?xml version=\"1.0\"?>\n");
@@ -690,36 +735,24 @@
 		}
 	}
 
-	if (!svcname && !name)
-		xml_quorum_state(qs);
-	if (!svcname || (name && svcname)) 
-		xml_member_states(membership, name);
-	if (rgs &&
-	    (!name || (name && svcname)))
-		xml_rg_states(rgs, membership, svcname);
-	printf("</clustat>\n");
+  	if (!svcname && !name)
+  		xml_quorum_state(qs);
+  	if (!svcname || (name && svcname)) 
+ 		ret1 = xml_member_states(membership, name);
+ 	
+  	if (rgs &&
+  	    (!name || (name && svcname)))
+ 		ret2 = xml_rg_states(rgs, membership, svcname);
+  	printf("</clustat>\n");
+ 	
+ 	if (name && ret1)
+ 		return ret1;
+ 	if (svcname && ret2)
+ 		return ret2;
+ 	return 0;
 }
 
 
-void
-dump_node(cman_node_t *node)
-{
-	printf("Node %s state %02x\n", node->cn_name, node->cn_member);
-}
-
-
-void 
-dump_nodes(cluster_member_list_t *nodes)
-{
-	int x;
-
-	for (x=0; x<nodes->cml_count; x++) {
-		dump_node(&nodes->cml_members[x]);
-	}
-}
-
-
-
 cluster_member_list_t *
 build_member_list(cman_handle_t ch, int *lid)
 {
@@ -924,11 +957,13 @@
 		}
 
 		if (xml)
-			xml_cluster_status(qs, membership, rgs, member_name,
-					   rg_name,flags);
+			ret = xml_cluster_status(qs, membership, rgs,
+						 member_name, rg_name,
+						 flags);
 		else
-			txt_cluster_status(qs, membership, rgs, member_name,
-					   rg_name,flags);
+			ret = txt_cluster_status(qs, membership, rgs,
+						 member_name, rg_name,
+						 flags);
 
 		if (membership)
 			free_member_list(membership);


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