[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
Thu Oct 15 12:44:03 PDT 2009
Ok, here is a better patch.
-Angus
Index: include/corosync/coroipcs.h
===================================================================
--- include/corosync/coroipcs.h (revision 2529)
+++ include/corosync/coroipcs.h (working copy)
@@ -75,20 +75,28 @@
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 rec_ident,
+ const char *function_name,
+ const char *file_name,
+ int file_line,
+ const char *format,
+ ...) __attribute__((format(printf, 5, 6)));
+ int log_subsys_id;
};
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_state_v2);
extern void *coroipcs_private_data_get (void *conn);
Index: exec/coroipcs.c
===================================================================
--- exec/coroipcs.c (revision 2529)
+++ exec/coroipcs.c (working copy)
@@ -76,6 +76,9 @@
#include <corosync/coroipcs.h>
#include <corosync/coroipc_ipc.h>
+#define LOGSYS_UTILS_ONLY 1
+#include <corosync/engine/logsys.h>
+
#if _POSIX_THREAD_PROCESS_SHARED > 0
#include <semaphore.h>
#else
@@ -92,7 +95,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 = NULL;
DECLARE_LIST_INIT (conn_info_list_head);
@@ -173,6 +176,16 @@
static void msg_send (void *conn, const struct iovec *iov, unsigned int iov_len,
int locked);
+#define log_printf(level, format, args...) \
+do { \
+ apiv2->log_printf ( \
+ LOGSYS_ENCODE_RECID(level, \
+ apiv2->log_subsys_id, \
+ LOGSYS_RECID_LOG), \
+ __FUNCTION__, __FILE__, __LINE__, \
+ (const char *)format, ##args); \
+} while (0)
+
static hdb_handle_t dummy_stats_create_connection (
const char *name,
pid_t pid,
@@ -200,11 +213,28 @@
{
}
-static struct coroipcs_init_stats_state dummy_init_stats_state = {
+static void dummy_log_printf (
+ unsigned int rec_ident,
+ const char *function_name,
+ const char *file_name,
+ int file_line,
+ const char *format,
+ ...) __attribute__((format(printf, 5, 6)));
+static void dummy_log_printf (
+ unsigned int rec_ident,
+ const char *function_name,
+ const char *file_name,
+ int file_line,
+ 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 +248,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 +259,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 +507,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 +659,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 +674,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 +712,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 +747,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 +796,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) {
@@ -846,11 +876,11 @@
#else /* no credentials */
authenticated = 1;
- api->log_printf ("Platform does not support IPC authentication. Using no authentication\n");
+ log_printf (LOGSYS_LEVEL_ERROR, "Platform does not support IPC authentication. Using no authentication\n");
#endif /* no credentials */
if (authenticated == 0) {
- api->log_printf ("Invalid IPC credentials.\n");
+ log_printf (LOGSYS_LEVEL_ERROR, "Invalid IPC credentials.\n");
ipc_disconnect (conn_info);
return (-1);
}
@@ -926,8 +956,10 @@
api = init_state;
- stats_api = &dummy_init_stats_state;
+ if (apiv2 == NULL)
+ apiv2 = &dummy_init_state_v2;
+ log_printf (LOGSYS_LEVEL_ERROR, "hello how are you?\n");
/*
* Create socket for IPC clients, name socket, listen for connections
*/
@@ -937,13 +969,13 @@
server_fd = socket (PF_LOCAL, SOCK_STREAM, 0);
#endif
if (server_fd == -1) {
- api->log_printf ("Cannot create client connections socket.\n");
+ log_printf (LOGSYS_LEVEL_CRIT, "Cannot create client connections socket.\n");
api->fatal_error ("Can't create library listen socket");
};
res = fcntl (server_fd, F_SETFL, O_NONBLOCK);
if (res == -1) {
- api->log_printf ("Could not set non-blocking operation on server socket: %s\n", strerror (errno));
+ log_printf (LOGSYS_LEVEL_CRIT, "Could not set non-blocking operation on server socket: %s\n", strerror (errno));
api->fatal_error ("Could not set non-blocking operation on server socket");
}
@@ -960,7 +992,7 @@
struct stat stat_out;
res = stat (SOCKETDIR, &stat_out);
if (res == -1 || (res == 0 && !S_ISDIR(stat_out.st_mode))) {
- api->log_printf ("Required directory not present %s\n", SOCKETDIR);
+ log_printf (LOGSYS_LEVEL_CRIT, "Required directory not present %s\n", SOCKETDIR);
api->fatal_error ("Please create required directory.");
}
sprintf (un_addr.sun_path, "%s/%s", SOCKETDIR, api->socket_name);
@@ -970,7 +1002,7 @@
res = bind (server_fd, (struct sockaddr *)&un_addr, COROSYNC_SUN_LEN(&un_addr));
if (res) {
- api->log_printf ("Could not bind AF_UNIX (%s): %s.\n", un_addr.sun_path, strerror (errno));
+ log_printf (LOGSYS_LEVEL_CRIT, "Could not bind AF_UNIX (%s): %s.\n", un_addr.sun_path, strerror (errno));
api->fatal_error ("Could not bind to AF_UNIX socket\n");
}
@@ -989,10 +1021,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 +1095,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 +1135,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 +1214,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 +1274,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) {
@@ -1387,13 +1419,16 @@
}
if (new_fd == -1) {
- api->log_printf ("Could not accept Library connection: %s\n", strerror (errno));
+ log_printf (LOGSYS_LEVEL_ERROR,
+ "Could not accept Library connection: %s\n", strerror (errno));
return (0); /* This is an error, but -1 would indicate disconnect from poll loop */
}
res = fcntl (new_fd, F_SETFL, O_NONBLOCK);
if (res == -1) {
- api->log_printf ("Could not set non-blocking operation on library connection: %s\n", strerror (errno));
+ log_printf (LOGSYS_LEVEL_ERROR,
+ "Could not set non-blocking operation on library connection: %s\n",
+ strerror (errno));
close (new_fd);
return (0); /* This is an error, but -1 would indicate disconnect from poll loop */
}
@@ -1475,8 +1510,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 2529)
+++ exec/main.c (working copy)
@@ -1058,11 +1058,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 = _logsys_log_printf,
};
static void corosync_setscheduler (void)
@@ -1465,15 +1466,15 @@
serialize_lock,
serialize_unlock);
- ipc_subsys_id = _logsys_subsys_create ("IPC");
- if (ipc_subsys_id < 0) {
+ ipc_init_state_v2.log_subsys_id = _logsys_subsys_create ("IPC");
+ if (ipc_init_state_v2.log_subsys_id < 0) {
log_printf (LOGSYS_LEVEL_ERROR,
"Could not initialize IPC logging subsystem\n");
corosync_exit_error (AIS_DONE_INIT_SERVICES);
}
+ coroipcs_ipc_init_v2 (&ipc_init_state_v2);
coroipcs_ipc_init (&ipc_init_state);
- coroipcs_ipc_stats_init (&ipc_init_stats_state);
/*
* Start main processing loop
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: log.patch
Url: http://lists.linux-foundation.org/pipermail/openais/attachments/20091016/5427762e/attachment-0001.txt
More information about the Openais
mailing list