Pārlūkot izejas kodu

qnetd: Move algorithms_register into qnetd-algorithms.c

and fix qnetd_algorithm_vote_info_reply_received

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
Christine Caulfield 10 gadi atpakaļ
vecāks
revīzija
3999cd1444
3 mainītis faili ar 18 papildinājumiem un 23 dzēšanām
  1. 0 12
      qdevices/corosync-qnetd.c
  2. 16 11
      qdevices/qnetd-algorithm.c
  3. 2 0
      qdevices/qnetd-algorithm.h

+ 0 - 12
qdevices/corosync-qnetd.c

@@ -61,8 +61,6 @@
 #include "dynar.h"
 #include "timer-list.h"
 #include "qnetd-algorithm.h"
-#include "qnetd-algo-test.h"
-#include "qnetd-algo-ffsplit.h"
 #include "qnetd-cluster-list.h"
 #include "qnetd-client-send.h"
 
@@ -1385,16 +1383,6 @@ qnetd_instance_destroy(struct qnetd_instance *instance)
 	return (0);
 }
 
-static void algorithms_register(void)
-{
-	if (qnetd_algo_test_register() != TLV_REPLY_ERROR_CODE_NO_ERROR) {
-		errx(1, "Failed to register decision algorithm 'test' ");
-	}
-	if (qnetd_algo_ffsplit_register() != TLV_REPLY_ERROR_CODE_NO_ERROR) {
-		errx(1, "Failed to register decision algorithm 'ffsplit' ");
-	}
-}
-
 static void
 signal_int_handler(int sig)
 {

+ 16 - 11
qdevices/qnetd-algorithm.c

@@ -124,20 +124,15 @@ qnetd_algorithm_ask_for_vote_received(struct qnetd_client *client, uint32_t msg_
 enum tlv_reply_error_code
 qnetd_algorithm_vote_info_reply_received(struct qnetd_client *client, uint32_t msg_seq_num)
 {
-
-	switch (client->decision_algorithm) {
-	case TLV_DECISION_ALGORITHM_TYPE_TEST:
-		return (qnetd_algo_test_vote_info_reply_received(client, msg_seq_num));
-		break;
-	case TLV_DECISION_ALGORITHM_TYPE_FFSPLIT:
-		return (qnetd_algo_ffsplit_vote_info_reply_received(client, msg_seq_num));
-		break;
-	default:
+	if (client->decision_algorithm >= MAX_QNETD_ALGORITHMS ||
+	    qnetd_algorithm[client->decision_algorithm] == NULL) {
 		errx(1, "qnetd_algorithm_vote_info_reply_received unhandled decision algorithm");
-		break;
+		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 	}
 
-	return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
+	return qnetd_algorithm[client->decision_algorithm]->vote_info_reply_received(
+		client, msg_seq_num);
+
 }
 
 
@@ -154,3 +149,13 @@ qnetd_algorithm_register(enum tlv_decision_algorithm_type algorithm_number, stru
 	qnetd_algorithm[algorithm_number] = algorithm;
 	return TLV_REPLY_ERROR_CODE_NO_ERROR;
 }
+
+void algorithms_register(void)
+{
+	if (qnetd_algo_test_register() != TLV_REPLY_ERROR_CODE_NO_ERROR) {
+		errx(1, "Failed to register decision algorithm 'test' ");
+	}
+	if (qnetd_algo_ffsplit_register() != TLV_REPLY_ERROR_CODE_NO_ERROR) {
+		errx(1, "Failed to register decision algorithm 'ffsplit' ");
+	}
+}

+ 2 - 0
qdevices/qnetd-algorithm.h

@@ -92,6 +92,8 @@ struct qnetd_algorithm {
 extern enum tlv_reply_error_code	qnetd_algorithm_register(
 	enum tlv_decision_algorithm_type algorithm_number, struct qnetd_algorithm *algorithm);
 
+extern void algorithms_register(void);
+
 #define MAX_QNETD_ALGORITHMS 10
 
 #ifdef __cplusplus