[Openais] [PATCH corosync/trunk] add a log_printf function to coroipcs so we can pass log level

angus salkeld angus.salkeld at alliedtelesis.co.nz
Wed Oct 14 15:22:06 PDT 2009


Hi

Add apiv2->log_printf(<log level>, ...);

Else you can't add anything but error logs int coroipcs.c.

(Attached & inline)

Note: I am not nuts about the #include <syslog.h>
but if I include <logsys.h> the #define for log_printf() in
that header messes with the log_printf in coroipcs.c

Regards
Angus

Index: include/corosync/coroipcs.h
===================================================================
--- include/corosync/coroipcs.h	(revision 2524)
+++ include/corosync/coroipcs.h	(working copy)
@@ -75,20 +75,22 @@
 	coroipcs_handler_fn_lvalue (*handler_fn_get)(unsigned int service, unsigned int id);
 };
 
-struct coroipcs_init_stats_state {
+struct coroipcs_init_state_v2 {
 	hdb_handle_t (*stats_create_connection) (const char* name,
 		pid_t pid, int fd);
 	void (*stats_destroy_connection) (hdb_handle_t handle);
 	void (*stats_update_value) (hdb_handle_t handle,
 		const char *name, const void *value, size_t value_len);
 	void (*stats_increment_value) (hdb_handle_t handle, const char* name);
+	void (*log_printf) (unsigned int level, const char *format, ...)
+		__attribute__((format(printf, 2, 3)));
 };
 
 extern void coroipcs_ipc_init (
 	struct coroipcs_init_state *init_state);
 
-extern void coroipcs_ipc_stats_init (
-        struct coroipcs_init_stats_state *init_stats_state);
+extern void coroipcs_ipc_init_v2 (
+        struct coroipcs_init_state_v2 *init_stats_state_v2);
 
 extern void *coroipcs_private_data_get (void *conn);
 
Index: exec/coroipcs.c
===================================================================
--- exec/coroipcs.c	(revision 2524)
+++ exec/coroipcs.c	(working copy)
@@ -75,6 +75,7 @@
 #include <corosync/hdb.h>
 #include <corosync/coroipcs.h>
 #include <corosync/coroipc_ipc.h>
+#include <syslog.h>
 
 #if _POSIX_THREAD_PROCESS_SHARED > 0
 #include <semaphore.h>
@@ -92,7 +93,7 @@
 #define MSG_SEND_UNLOCKED	1
 
 static struct coroipcs_init_state *api;
-static struct coroipcs_init_stats_state *stats_api;
+static struct coroipcs_init_state_v2 *apiv2;
 
 DECLARE_LIST_INIT (conn_info_list_head);
 
@@ -200,11 +201,17 @@
 {
 }
 
-static struct coroipcs_init_stats_state dummy_init_stats_state = {
+
+static void dummy_log_printf (unsigned int level, const char *format, ...) __attribute__((format(printf, 2, 3)));
+static void dummy_log_printf (unsigned int level, const char *format, ...) {
+}
+
+static struct coroipcs_init_state_v2 dummy_init_state_v2 = {
 	.stats_create_connection	= dummy_stats_create_connection,
 	.stats_destroy_connection	= dummy_stats_destroy_connection,
 	.stats_update_value			= dummy_stats_update_value,
-	.stats_increment_value		= dummy_stats_increment_value
+	.stats_increment_value		= dummy_stats_increment_value,
+	.log_printf					= dummy_log_printf
 };
 
 static void sem_post_exit_thread (struct conn_info *conn_info)
@@ -218,7 +225,7 @@
 retry_semop:
 	res = sem_post (&conn_info->control_buffer->sem0);
 	if (res == -1 && errno == EINTR) {
-		stats_api->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
+		apiv2->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
 		goto retry_semop;
 	}
 #else
@@ -229,7 +236,7 @@
 retry_semop:
 	res = semop (conn_info->semid, &sop, 1);
 	if ((res == -1) && (errno == EINTR || errno == EAGAIN)) {
-		stats_api->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
+		apiv2->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
 		goto retry_semop;
 	}
 #endif
@@ -477,7 +484,7 @@
 	 * Retry library exit function if busy
 	 */
 	if (conn_info->state == CONN_STATE_THREAD_DESTROYED) {
-		stats_api->stats_destroy_connection (conn_info->stats_handle);
+		apiv2->stats_destroy_connection (conn_info->stats_handle);
 		res = api->exit_fn_get (conn_info->service) (conn_info);
 		if (res == -1) {
 			api->serialize_unlock ();
@@ -629,7 +636,7 @@
 			pthread_exit (0);
 		}
 		if ((res == -1) && (errno == EINTR)) {
-			stats_api->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
+			apiv2->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
 			goto retry_semwait;
 		}
 #else
@@ -644,7 +651,7 @@
 			pthread_exit (0);
 		}
 		if ((res == -1) && (errno == EINTR || errno == EAGAIN)) {
-			stats_api->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
+			apiv2->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
 			goto retry_semop;
 		} else
 		if ((res == -1) && (errno == EINVAL || errno == EIDRM)) {
@@ -682,14 +689,14 @@
 		} else 
 		if (send_ok) {
 			api->serialize_lock();
-			stats_api->stats_increment_value (conn_info->stats_handle, "requests");
+			apiv2->stats_increment_value (conn_info->stats_handle, "requests");
 			api->handler_fn_get (conn_info->service, header->id) (conn_info, header);
 			api->serialize_unlock();
 		} else {
 			/*
 			 * Overload, tell library to retry
 			 */
-			stats_api->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
+			apiv2->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
 			coroipc_response_header.size = sizeof (coroipc_response_header_t);
 			coroipc_response_header.id = 0;
 			coroipc_response_header.error = CS_ERR_TRY_AGAIN;
@@ -717,11 +724,11 @@
 retry_send:
 	res = send (conn_info->fd, &res_setup, sizeof (mar_res_setup_t), MSG_WAITALL);
 	if (res == -1 && errno == EINTR) {
-		stats_api->stats_increment_value (conn_info->stats_handle, "send_retry_count");
+		apiv2->stats_increment_value (conn_info->stats_handle, "send_retry_count");
 		goto retry_send;
 	} else
 	if (res == -1 && errno == EAGAIN) {
-		stats_api->stats_increment_value (conn_info->stats_handle, "send_retry_count");
+		apiv2->stats_increment_value (conn_info->stats_handle, "send_retry_count");
 		goto retry_send;
 	}
 	return (0);
@@ -766,7 +773,7 @@
 retry_recv:
 	res = recvmsg (conn_info->fd, &msg_recv, MSG_NOSIGNAL);
 	if (res == -1 && errno == EINTR) {
-		stats_api->stats_increment_value (conn_info->stats_handle, "recv_retry_count");
+		apiv2->stats_increment_value (conn_info->stats_handle, "recv_retry_count");
 		goto retry_recv;
 	} else
 	if (res == -1 && errno != EAGAIN) {
@@ -926,7 +933,7 @@
 
 	api = init_state;
 
-	stats_api = &dummy_init_stats_state;
+	apiv2 = &dummy_init_state_v2;
 
 	/*
 	 * Create socket for IPC clients, name socket, listen for connections
@@ -989,10 +996,10 @@
 	api->poll_accept_add (server_fd);
 }
 
-extern void coroipcs_ipc_stats_init (
-	struct coroipcs_init_stats_state *init_stats_state)
+extern void coroipcs_ipc_init_v2 (
+	struct coroipcs_init_state_v2 *init_state_v2)
 {
-	stats_api = init_stats_state;
+	apiv2 = init_state_v2;
 }
 
 void coroipcs_ipc_exit (void)
@@ -1063,14 +1070,14 @@
 retry_semop:
 	res = semop (conn_info->semid, &sop, 1);
 	if ((res == -1) && (errno == EINTR || errno == EAGAIN)) {
-		stats_api->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
+		apiv2->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
 		goto retry_semop;
 	} else
 	if ((res == -1) && (errno == EINVAL || errno == EIDRM)) {
 		return (0);
 	}
 #endif
-	stats_api->stats_increment_value (conn_info->stats_handle, "responses");
+	apiv2->stats_increment_value (conn_info->stats_handle, "responses");
 	return (0);
 }
 
@@ -1103,14 +1110,14 @@
 retry_semop:
 	res = semop (conn_info->semid, &sop, 1);
 	if ((res == -1) && (errno == EINTR || errno == EAGAIN)) {
-		stats_api->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
+		apiv2->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
 		goto retry_semop;
 	} else
 	if ((res == -1) && (errno == EINVAL || errno == EIDRM)) {
 		return (0);
 	}
 #endif
-	stats_api->stats_increment_value (conn_info->stats_handle, "responses");
+	apiv2->stats_increment_value (conn_info->stats_handle, "responses");
 	return (0);
 }
 
@@ -1182,14 +1189,14 @@
 retry_semop:
 	res = semop (conn_info->semid, &sop, 1);
 	if ((res == -1) && (errno == EINTR || errno == EAGAIN)) {
-		stats_api->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
+		apiv2->stats_increment_value (conn_info->stats_handle, "sem_retry_count");
 		goto retry_semop;
 	} else
 	if ((res == -1) && (errno == EINVAL || errno == EIDRM)) {
 		return;
 	}
 #endif
-	stats_api->stats_increment_value (conn_info->stats_handle, "dispatched");
+	apiv2->stats_increment_value (conn_info->stats_handle, "dispatched");
 }
 
 static void outq_flush (struct conn_info *conn_info) {
@@ -1242,11 +1249,11 @@
 		sizeof (mar_req_priv_change),
 		MSG_NOSIGNAL);
 	if (res == -1 && errno == EINTR) {
-	stats_api->stats_increment_value (conn_info->stats_handle, "recv_retry_count");
+	apiv2->stats_increment_value (conn_info->stats_handle, "recv_retry_count");
 		goto retry_recv;
 	}
 	if (res == -1 && errno == EAGAIN) {
-		stats_api->stats_increment_value (conn_info->stats_handle, "recv_retry_count");
+		apiv2->stats_increment_value (conn_info->stats_handle, "recv_retry_count");
 		goto retry_recv;
 	}
 	if (res == -1 && errno != EAGAIN) {
@@ -1475,8 +1482,8 @@
 	} else
 		snprintf (conn_name, sizeof(conn_name), "%d", conn->fd);
 
-	conn->stats_handle = stats_api->stats_create_connection (conn_name, conn->client_pid, conn->fd);
-	stats_api->stats_update_value (conn->stats_handle, "service_id",
+	conn->stats_handle = apiv2->stats_create_connection (conn_name, conn->client_pid, conn->fd);
+	apiv2->stats_update_value (conn->stats_handle, "service_id",
 								   &conn->service, sizeof(conn->service));
 }
 
Index: exec/main.c
===================================================================
--- exec/main.c	(revision 2524)
+++ exec/main.c	(working copy)
@@ -889,6 +889,22 @@
 	va_end (ap);
 }
 
+static void ipc_log_printf_level (unsigned int level, const char *format, ...) __attribute__((format(printf, 2, 3)));
+static void ipc_log_printf_level (unsigned int level, const char *format, ...) {
+	va_list ap;
+
+	va_start (ap, format);
+
+	_logsys_log_vprintf (
+		LOGSYS_ENCODE_RECID(level,
+				    ipc_subsys_id,
+				    LOGSYS_RECID_LOG),
+		__FUNCTION__, __FILE__, __LINE__,
+		format, ap);
+
+	va_end (ap);
+}
+
 static void ipc_fatal_error(const char *error_msg) {
        _logsys_log_printf (
 		LOGSYS_ENCODE_RECID(LOGSYS_LEVEL_ERROR,
@@ -1058,11 +1074,12 @@
 	.handler_fn_get			= corosync_handler_fn_get
 };
 
-static struct coroipcs_init_stats_state ipc_init_stats_state = {
+static struct coroipcs_init_state_v2 ipc_init_state_v2 = {
 	.stats_create_connection		= corosync_stats_create_connection,
 	.stats_destroy_connection		= corosync_stats_destroy_connection,
 	.stats_update_value				= corosync_stats_update_value,
-	.stats_increment_value			= corosync_stats_increment_value
+	.stats_increment_value			= corosync_stats_increment_value,
+	.log_printf						= ipc_log_printf_level,
 };
 
 static void corosync_setscheduler (void)
@@ -1473,7 +1490,7 @@
 	}
 
 	coroipcs_ipc_init (&ipc_init_state);
-	coroipcs_ipc_stats_init (&ipc_init_stats_state);
+	coroipcs_ipc_init_v2 (&ipc_init_state_v2);
 
 	/*
 	 * Start main processing loop


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: lp.patch
Url: http://lists.linux-foundation.org/pipermail/openais/attachments/20091015/62d4fb82/attachment-0001.txt 


More information about the Openais mailing list