Преглед изворни кода

vqsim: Fix vqsim for corosync 3.0

A couple of small internal changes in corosync 3.0 broke vqsim.
1) The way the custom config file is specified (no long an env variable)
2) votequorum now needs to know ouZ_node_pos

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
Reviewed-by: Jan Friesse <jfriesse@redhat.com>
Christine Caulfield пре 6 година
родитељ
комит
e65d7b5d98
2 измењених фајлова са 38 додато и 7 уклоњено
  1. 1 7
      vqsim/vqmain.c
  2. 37 0
      vqsim/vqsim_vq_engine.c

+ 1 - 7
vqsim/vqmain.c

@@ -667,14 +667,12 @@ int main(int argc, char **argv)
 {
 	qb_loop_signal_handle sigchld_qb_handle;
 	int ch;
-	char *config_file_name = NULL;
 	char *output_file_name = NULL;
-	char envstring[PATH_MAX];
 
 	while ((ch = getopt (argc, argv, "f:o:nh")) != EOF) {
 		switch (ch) {
 		case 'f':
-			config_file_name = optarg;
+			strncpy(corosync_config_file, optarg, sizeof(corosync_config_file));
 			break;
 		case 'o':
 			output_file_name = optarg;
@@ -688,10 +686,6 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (config_file_name) {
-		sprintf(envstring, "COROSYNC_MAIN_CONFIG_FILE=%s", config_file_name);
-		putenv(envstring);
-	}
 	if (output_file_name) {
 		output_file = fopen(output_file_name, "w");
 		if (!output_file) {

+ 37 - 0
vqsim/vqsim_vq_engine.c

@@ -178,6 +178,42 @@ char *get_run_dir()
 	return getcwd(cwd_buffer, PATH_MAX);
 }
 
+/* This is different to the one in totemconfig.c in that we already
+ * know the 'local' node ID, so we can just search for that.
+ * It needs to be here rather than at main config read time as it's
+ * (obviously) going to be different for each instance.
+ */
+static void set_local_node_pos(struct corosync_api_v1 *api)
+{
+	icmap_iter_t iter;
+	uint32_t node_pos;
+	char name_str[ICMAP_KEYNAME_MAXLEN];
+	uint32_t nodeid;
+	const char *iter_key;
+	int res;
+
+	iter = icmap_iter_init("nodelist.node.");
+	while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
+		res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, name_str);
+		if (res != 2) {
+			continue;
+		}
+		if (strcmp(name_str, "nodeid")) {
+			continue;
+		}
+
+		res = icmap_get_uint32(iter_key, &nodeid);
+		if (res == CS_OK) {
+			if (nodeid == our_nodeid) {
+				res = icmap_set_uint32("nodelist.local_node_pos", node_pos);
+				if (res != CS_OK) {
+					fprintf(stderr, "Failed to find node %d in corosync.conf. Quorum calculations may not be correct:\n", our_nodeid);
+				}
+			}
+		}
+	}
+}
+
 static int load_quorum_instance(struct corosync_api_v1 *api)
 {
 	const char *error_string;
@@ -417,6 +453,7 @@ int fork_new_instance(int nodeid, int *vq_sock, pid_t *childpid)
 		qdevice_timeout = VOTEQUORUM_QDEVICE_DEFAULT_TIMEOUT;
 	}
 
+	set_local_node_pos(&corosync_api);
 	load_quorum_instance(&corosync_api);
 
 	qb_loop_poll_add(poll_loop,