Browse Source

qnetd: Replace err by qnetd_log on some places

err should be used only before qnetd log is fully initialized.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Jan Friesse 10 years ago
parent
commit
4231ad97a3
4 changed files with 39 additions and 35 deletions
  1. 3 1
      qdevices/corosync-qnetd.c
  2. 0 4
      qdevices/qnetd-algo-utils.c
  3. 34 28
      qdevices/qnetd-algorithm.c
  4. 2 2
      qdevices/qnetd-algorithm.h

+ 3 - 1
qdevices/corosync-qnetd.c

@@ -386,7 +386,9 @@ main(int argc, char *argv[])
 	signal_handlers_register();
 	signal_handlers_register();
 
 
 	qnetd_log(LOG_DEBUG, "Registering algorithms");
 	qnetd_log(LOG_DEBUG, "Registering algorithms");
-	qnetd_algorithm_register_all();
+	if (qnetd_algorithm_register_all() != 0) {
+		exit(1);
+	}
 
 
 	qnetd_log(LOG_DEBUG, "QNetd ready to provide service");
 	qnetd_log(LOG_DEBUG, "QNetd ready to provide service");
 	/*
 	/*

+ 0 - 4
qdevices/qnetd-algo-utils.c

@@ -31,17 +31,13 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
  */
-
 #include <sys/types.h>
 #include <sys/types.h>
 #include <string.h>
 #include <string.h>
 
 
-#include <err.h>
-
 #include "qnetd-log.h"
 #include "qnetd-log.h"
 #include "qnetd-cluster-list.h"
 #include "qnetd-cluster-list.h"
 #include "qnetd-algo-utils.h"
 #include "qnetd-algo-utils.h"
 
 
-
 /*
 /*
  * Returns -1 if any node that is supposedly in the same cluster partition
  * Returns -1 if any node that is supposedly in the same cluster partition
  * as us has a different ring_id.
  * as us has a different ring_id.

+ 34 - 28
qdevices/qnetd-algorithm.c

@@ -34,14 +34,13 @@
 
 
 #include <sys/types.h>
 #include <sys/types.h>
 
 
-#include <err.h>
-
 #include "qnet-config.h"
 #include "qnet-config.h"
 #include "qnetd-algorithm.h"
 #include "qnetd-algorithm.h"
 #include "qnetd-algo-test.h"
 #include "qnetd-algo-test.h"
 #include "qnetd-algo-ffsplit.h"
 #include "qnetd-algo-ffsplit.h"
 #include "qnetd-algo-2nodelms.h"
 #include "qnetd-algo-2nodelms.h"
 #include "qnetd-algo-lms.h"
 #include "qnetd-algo-lms.h"
+#include "qnetd-log.h"
 
 
 static struct qnetd_algorithm *qnetd_algorithm_array[QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE];
 static struct qnetd_algorithm *qnetd_algorithm_array[QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE];
 
 
@@ -50,8 +49,8 @@ qnetd_algorithm_client_init(struct qnetd_client *client)
 {
 {
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
+		qnetd_log(LOG_CRIT, "qnetd_algorithm_client_init unhandled decision algorithm");
 
 
-		errx(1, "qnetd_algorithm_client_init unhandled decision algorithm");
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 	}
 	}
 
 
@@ -65,8 +64,7 @@ qnetd_algorithm_config_node_list_received(struct qnetd_client *client,
 {
 {
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
-
-		errx(1, "qnetd_algorithm_config_node_list_received unhandled "
+		qnetd_log(LOG_CRIT, "qnetd_algorithm_config_node_list_received unhandled "
 		     "decision algorithm");
 		     "decision algorithm");
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 	}
 	}
@@ -84,8 +82,7 @@ qnetd_algorithm_membership_node_list_received(struct qnetd_client *client,
 
 
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
-
-		errx(1, "qnetd_algorithm_membership_node_list_received unhandled "
+		qnetd_log(LOG_CRIT, "qnetd_algorithm_membership_node_list_received unhandled "
 		    "decision algorithm");
 		    "decision algorithm");
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 	}
 	}
@@ -103,8 +100,7 @@ qnetd_algorithm_quorum_node_list_received(struct qnetd_client *client,
 
 
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
-
-		errx(1, "qnetd_algorithm_quorum_node_list_received unhandled "
+		qnetd_log(LOG_CRIT, "algorithm_quorum_node_list_received unhandled "
 		    "decision algorithm");
 		    "decision algorithm");
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 	}
 	}
@@ -119,8 +115,8 @@ qnetd_algorithm_client_disconnect(struct qnetd_client *client, int server_going_
 
 
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
-
-		errx(1, "qnetd_algorithm_client_disconnect unhandled decision algorithm");
+		qnetd_log(LOG_CRIT, "qnetd_algorithm_client_disconnect unhandled decision "
+		    "algorithm");
 		return;
 		return;
 	}
 	}
 
 
@@ -134,8 +130,8 @@ qnetd_algorithm_ask_for_vote_received(struct qnetd_client *client, uint32_t msg_
 
 
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
-
-		errx(1, "qnetd_algorithm_ask_for_vote_received unhandled decision algorithm");
+		qnetd_log(LOG_CRIT, "qnetd_algorithm_ask_for_vote_received unhandled "
+		    "decision algorithm");
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 	}
 	}
 
 
@@ -149,7 +145,7 @@ qnetd_algorithm_vote_info_reply_received(struct qnetd_client *client, uint32_t m
 
 
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
-		errx(1, "qnetd_algorithm_vote_info_reply_received unhandled decision algorithm");
+		qnetd_log(LOG_CRIT, "qnetd_algorithm_vote_info_reply_received unhandled decision algorithm");
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 	}
 	}
 
 
@@ -165,7 +161,7 @@ qnetd_algorithm_timer_callback(struct qnetd_client *client, int *reschedule_time
 
 
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	if (client->decision_algorithm >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE ||
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
 	    qnetd_algorithm_array[client->decision_algorithm] == NULL) {
-		errx(1, "qnetd_algorithm_timer_callback unhandled decision algorithm");
+		qnetd_log(LOG_CRIT, "qnetd_algorithm_timer_callback unhandled decision algorithm");
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 		return (TLV_REPLY_ERROR_CODE_INTERNAL_ERROR);
 	}
 	}
 
 
@@ -173,38 +169,48 @@ qnetd_algorithm_timer_callback(struct qnetd_client *client, int *reschedule_time
 		client, reschedule_timer, send_vote, result_vote));
 		client, reschedule_timer, send_vote, result_vote));
 }
 }
 
 
-enum tlv_reply_error_code
+int
 qnetd_algorithm_register(enum tlv_decision_algorithm_type algorithm_number,
 qnetd_algorithm_register(enum tlv_decision_algorithm_type algorithm_number,
     struct qnetd_algorithm *algorithm)
     struct qnetd_algorithm *algorithm)
 {
 {
 
 
 	if (algorithm_number >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE) {
 	if (algorithm_number >= QNETD_STATIC_SUPPORTED_DECISION_ALGORITHMS_SIZE) {
-		return (TLV_REPLY_ERROR_CODE_UNSUPPORTED_DECISION_ALGORITHM);
+		qnetd_log(LOG_CRIT, "Failed to register unsupported decision algorithm %u",
+		    algorithm_number);
+		return (-1);
 	}
 	}
 
 
 	if (qnetd_algorithm_array[algorithm_number] != NULL) {
 	if (qnetd_algorithm_array[algorithm_number] != NULL) {
-		return (TLV_REPLY_ERROR_CODE_DECISION_ALGORITHM_ALREADY_REGISTERED);
+		qnetd_log(LOG_CRIT, "Failed to register decision algorithm %u, "
+		"it's already registered.", algorithm_number);
+		return (-1);
 	}
 	}
 
 
 	qnetd_algorithm_array[algorithm_number] = algorithm;
 	qnetd_algorithm_array[algorithm_number] = algorithm;
 
 
-	return (TLV_REPLY_ERROR_CODE_NO_ERROR);
+	return (0);
 }
 }
 
 
-void
+int
 qnetd_algorithm_register_all(void)
 qnetd_algorithm_register_all(void)
 {
 {
 
 
-	if (qnetd_algo_test_register() != TLV_REPLY_ERROR_CODE_NO_ERROR) {
-		errx(1, "Failed to register decision algorithm 'test' ");
+	if (qnetd_algo_test_register() != 0) {
+		qnetd_log(LOG_CRIT, "Failed to register decision algorithm 'test'");
+		return (-1);
 	}
 	}
-	if (qnetd_algo_ffsplit_register() != TLV_REPLY_ERROR_CODE_NO_ERROR) {
-		errx(1, "Failed to register decision algorithm 'ffsplit' ");
+	if (qnetd_algo_ffsplit_register() != 0) {
+		qnetd_log(LOG_CRIT, "Failed to register decision algorithm 'ffsplit'");
+		return (-1);
 	}
 	}
-	if (qnetd_algo_2nodelms_register() != TLV_REPLY_ERROR_CODE_NO_ERROR) {
-		errx(1, "Failed to register decision algorithm '2nodelms' ");
+	if (qnetd_algo_2nodelms_register() != 0) {
+		qnetd_log(LOG_CRIT, "Failed to register decision algorithm '2nodelms'");
+		return (-1);
 	}
 	}
-	if (qnetd_algo_lms_register() != TLV_REPLY_ERROR_CODE_NO_ERROR) {
-		errx(1, "Failed to register decision algorithm 'lms' ");
+	if (qnetd_algo_lms_register() != 0) {
+		qnetd_log(LOG_CRIT, "Failed to register decision algorithm 'lms'");
+		return (-1);
 	}
 	}
+
+	return (0);
 }
 }

+ 2 - 2
qdevices/qnetd-algorithm.h

@@ -101,10 +101,10 @@ struct qnetd_algorithm {
 	    int *reschedule_timer, int *send_vote, enum tlv_vote *result_vote);
 	    int *reschedule_timer, int *send_vote, enum tlv_vote *result_vote);
 };
 };
 
 
-extern enum tlv_reply_error_code	qnetd_algorithm_register(
+extern int				qnetd_algorithm_register(
 	enum tlv_decision_algorithm_type algorithm_number, struct qnetd_algorithm *algorithm);
 	enum tlv_decision_algorithm_type algorithm_number, struct qnetd_algorithm *algorithm);
 
 
-extern void qnetd_algorithm_register_all(void);
+extern int qnetd_algorithm_register_all(void);
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }