|
|
@@ -80,6 +80,12 @@ struct cs_ipcs_mapper {
|
|
|
char name[256];
|
|
|
};
|
|
|
|
|
|
+struct outq_item {
|
|
|
+ void *msg;
|
|
|
+ size_t mlen;
|
|
|
+ struct list_head list;
|
|
|
+};
|
|
|
+
|
|
|
static struct cs_ipcs_mapper ipcs_mapper[SERVICE_HANDLER_MAXIMUM_COUNT];
|
|
|
|
|
|
static int32_t cs_ipcs_job_add(enum qb_loop_priority p, void *data, qb_loop_job_dispatch_fn fn);
|
|
|
@@ -278,6 +284,12 @@ static char * pid_to_name (pid_t pid, char *out_name, size_t name_len)
|
|
|
|
|
|
struct cs_ipcs_conn_context {
|
|
|
qb_handle_t stats_handle;
|
|
|
+ struct list_head outq_head;
|
|
|
+ int32_t queuing;
|
|
|
+ uint32_t queued;
|
|
|
+ uint64_t invalid_request;
|
|
|
+ uint64_t overload;
|
|
|
+ uint32_t sent;
|
|
|
char data[1];
|
|
|
};
|
|
|
|
|
|
@@ -300,6 +312,12 @@ static void cs_ipcs_connection_created(qb_ipcs_connection_t *c)
|
|
|
|
|
|
size += ais_service[service]->private_data_size;
|
|
|
context = calloc(1, size);
|
|
|
+
|
|
|
+ list_init(&context->outq_head);
|
|
|
+ context->queuing = QB_FALSE;
|
|
|
+ context->queued = 0;
|
|
|
+ context->sent = 0;
|
|
|
+
|
|
|
qb_ipcs_context_set(c, context);
|
|
|
|
|
|
ais_service[service]->lib_init_fn(c);
|
|
|
@@ -378,6 +396,21 @@ static void cs_ipcs_connection_created(qb_ipcs_connection_t *c)
|
|
|
"flow_control_count",
|
|
|
&zero_64, sizeof (zero_64),
|
|
|
OBJDB_VALUETYPE_UINT64);
|
|
|
+
|
|
|
+ api->object_key_create_typed (object_handle,
|
|
|
+ "queue_size",
|
|
|
+ &zero_32, sizeof (zero_32),
|
|
|
+ OBJDB_VALUETYPE_UINT32);
|
|
|
+
|
|
|
+ api->object_key_create_typed (object_handle,
|
|
|
+ "invalid_request",
|
|
|
+ &zero_64, sizeof (zero_64),
|
|
|
+ OBJDB_VALUETYPE_UINT64);
|
|
|
+
|
|
|
+ api->object_key_create_typed (object_handle,
|
|
|
+ "overload",
|
|
|
+ &zero_64, sizeof (zero_64),
|
|
|
+ OBJDB_VALUETYPE_UINT64);
|
|
|
}
|
|
|
|
|
|
void cs_ipc_refcnt_inc(void *conn)
|
|
|
@@ -399,12 +432,25 @@ void *cs_ipcs_private_data_get(void *conn)
|
|
|
|
|
|
static void cs_ipcs_connection_destroyed (qb_ipcs_connection_t *c)
|
|
|
{
|
|
|
- struct cs_ipcs_conn_context *cnx;
|
|
|
+ struct cs_ipcs_conn_context *context;
|
|
|
+ struct list_head *list, *list_next;
|
|
|
+ struct outq_item *outq_item;
|
|
|
+
|
|
|
log_printf(LOG_INFO, "%s() ", __func__);
|
|
|
- cnx = qb_ipcs_context_get(c);
|
|
|
|
|
|
- if (cnx) {
|
|
|
- free(cnx);
|
|
|
+ context = qb_ipcs_context_get(c);
|
|
|
+ if (context) {
|
|
|
+ for (list = context->outq_head.next;
|
|
|
+ list != &context->outq_head; list = list_next) {
|
|
|
+
|
|
|
+ list_next = list->next;
|
|
|
+ outq_item = list_entry (list, struct outq_item, list);
|
|
|
+
|
|
|
+ list_del (list);
|
|
|
+ free (outq_item->msg);
|
|
|
+ free (outq_item);
|
|
|
+ }
|
|
|
+ free(context);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -454,24 +500,113 @@ int cs_ipcs_response_send(void *conn, const void *msg, size_t mlen)
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-int cs_ipcs_dispatch_send(void *conn, const void *msg, size_t mlen)
|
|
|
+static void outq_flush (void *data)
|
|
|
{
|
|
|
- int32_t rc = qb_ipcs_event_send(conn, msg, mlen);
|
|
|
- if (rc >= 0) {
|
|
|
- return 0;
|
|
|
+ qb_ipcs_connection_t *conn = data;
|
|
|
+ struct list_head *list, *list_next;
|
|
|
+ struct outq_item *outq_item;
|
|
|
+ int32_t rc;
|
|
|
+ struct cs_ipcs_conn_context *context = qb_ipcs_context_get(conn);
|
|
|
+
|
|
|
+ for (list = context->outq_head.next;
|
|
|
+ list != &context->outq_head; list = list_next) {
|
|
|
+
|
|
|
+ list_next = list->next;
|
|
|
+ outq_item = list_entry (list, struct outq_item, list);
|
|
|
+
|
|
|
+ rc = qb_ipcs_event_send(conn, outq_item->msg, outq_item->mlen);
|
|
|
+ if (rc != outq_item->mlen) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ context->sent++;
|
|
|
+ context->queued--;
|
|
|
+
|
|
|
+ list_del (list);
|
|
|
+ free (outq_item->msg);
|
|
|
+ free (outq_item);
|
|
|
}
|
|
|
- return rc;
|
|
|
+ if (list_empty (&context->outq_head)) {
|
|
|
+ context->queuing = QB_FALSE;
|
|
|
+ log_printf(LOGSYS_LEVEL_INFO, "Q empty, queued:%d sent:%d.",
|
|
|
+ context->queued, context->sent);
|
|
|
+ context->queued = 0;
|
|
|
+ context->sent = 0;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ qb_loop_job_add(cs_poll_handle_get(), QB_LOOP_HIGH, conn, outq_flush);
|
|
|
+ if (rc < 0 && rc != -EAGAIN) {
|
|
|
+ log_printf(LOGSYS_LEVEL_ERROR, "event_send retuned %d!", rc);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static void msg_send_or_queue(qb_ipcs_connection_t *conn, const struct iovec *iov, uint32_t iov_len)
|
|
|
+{
|
|
|
+ int32_t rc = 0;
|
|
|
+ int32_t i;
|
|
|
+ int32_t bytes_msg = 0;
|
|
|
+ struct outq_item *outq_item;
|
|
|
+ char *write_buf = 0;
|
|
|
+ struct cs_ipcs_conn_context *context = qb_ipcs_context_get(conn);
|
|
|
+
|
|
|
+ for (i = 0; i < iov_len; i++) {
|
|
|
+ bytes_msg += iov[i].iov_len;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!context->queuing) {
|
|
|
+ assert(list_empty (&context->outq_head));
|
|
|
+ rc = qb_ipcs_event_sendv(conn, iov, iov_len);
|
|
|
+ if (rc == bytes_msg) {
|
|
|
+ context->sent++;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (rc == -EAGAIN) {
|
|
|
+ context->queued = 0;
|
|
|
+ context->sent = 0;
|
|
|
+ context->queuing = QB_TRUE;
|
|
|
+ qb_loop_job_add(cs_poll_handle_get(), QB_LOOP_HIGH, conn, outq_flush);
|
|
|
+ } else {
|
|
|
+ log_printf(LOGSYS_LEVEL_ERROR, "event_send retuned %d, expected %d!", rc, bytes_msg);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ outq_item = malloc (sizeof (struct outq_item));
|
|
|
+ if (outq_item == NULL) {
|
|
|
+ qb_ipcs_disconnect(conn);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ outq_item->msg = malloc (bytes_msg);
|
|
|
+ if (outq_item->msg == NULL) {
|
|
|
+ free (outq_item);
|
|
|
+ qb_ipcs_disconnect(conn);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ write_buf = outq_item->msg;
|
|
|
+ for (i = 0; i < iov_len; i++) {
|
|
|
+ memcpy (write_buf, iov[i].iov_base, iov[i].iov_len);
|
|
|
+ write_buf += iov[i].iov_len;
|
|
|
+ }
|
|
|
+ outq_item->mlen = bytes_msg;
|
|
|
+ list_init (&outq_item->list);
|
|
|
+ list_add_tail (&outq_item->list, &context->outq_head);
|
|
|
+ context->queued++;
|
|
|
+}
|
|
|
+
|
|
|
+int cs_ipcs_dispatch_send(void *conn, const void *msg, size_t mlen)
|
|
|
+{
|
|
|
+ struct iovec iov;
|
|
|
+ iov.iov_base = (void *)msg;
|
|
|
+ iov.iov_len = mlen;
|
|
|
+ msg_send_or_queue (conn, &iov, 1);
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
int cs_ipcs_dispatch_iov_send (void *conn,
|
|
|
const struct iovec *iov,
|
|
|
unsigned int iov_len)
|
|
|
{
|
|
|
- int32_t rc = qb_ipcs_event_sendv(conn, iov, iov_len);
|
|
|
- if (rc >= 0) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- return rc;
|
|
|
+ msg_send_or_queue(conn, iov, iov_len);
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
static int32_t cs_ipcs_msg_process(qb_ipcs_connection_t *c,
|
|
|
@@ -480,34 +615,48 @@ static int32_t cs_ipcs_msg_process(qb_ipcs_connection_t *c,
|
|
|
struct qb_ipc_response_header response;
|
|
|
struct qb_ipc_request_header *request_pt = (struct qb_ipc_request_header *)data;
|
|
|
int32_t service = qb_ipcs_service_id_get(c);
|
|
|
- int32_t send_ok;
|
|
|
+ int32_t send_ok = 0;
|
|
|
+ int32_t is_async_call = QB_FALSE;
|
|
|
ssize_t res = -1;
|
|
|
int sending_allowed_private_data;
|
|
|
+ struct cs_ipcs_conn_context *cnx;
|
|
|
|
|
|
send_ok = corosync_sending_allowed (service,
|
|
|
request_pt->id,
|
|
|
request_pt,
|
|
|
&sending_allowed_private_data);
|
|
|
|
|
|
+ is_async_call = (service == CPG_SERVICE && request_pt->id == 2);
|
|
|
+
|
|
|
/*
|
|
|
* This happens when the message contains some kind of invalid
|
|
|
* parameter, such as an invalid size
|
|
|
*/
|
|
|
- if (send_ok == -1) {
|
|
|
+ if (send_ok == -EINVAL) {
|
|
|
response.size = sizeof (response);
|
|
|
response.id = 0;
|
|
|
response.error = CS_ERR_INVALID_PARAM;
|
|
|
- log_printf(LOG_INFO, "%s() invalid message! size:%d error:%d",
|
|
|
- __func__, response.size, response.error);
|
|
|
- qb_ipcs_response_send (c,
|
|
|
+
|
|
|
+ cnx = qb_ipcs_context_get(c);
|
|
|
+ if (cnx) {
|
|
|
+ cnx->invalid_request++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (is_async_call) {
|
|
|
+ log_printf(LOGSYS_LEVEL_INFO, "*** %s() invalid message! size:%d error:%d",
|
|
|
+ __func__, response.size, response.error);
|
|
|
+ } else {
|
|
|
+ qb_ipcs_response_send (c,
|
|
|
&response,
|
|
|
sizeof (response));
|
|
|
+ }
|
|
|
res = -EINVAL;
|
|
|
- } else {
|
|
|
- if (send_ok) {
|
|
|
- ais_service[service]->lib_engine[request_pt->id].lib_handler_fn(c, request_pt);
|
|
|
- res = 0;
|
|
|
- } else {
|
|
|
+ } else if (send_ok < 0) {
|
|
|
+ cnx = qb_ipcs_context_get(c);
|
|
|
+ if (cnx) {
|
|
|
+ cnx->overload++;
|
|
|
+ }
|
|
|
+ if (!is_async_call) {
|
|
|
/*
|
|
|
* Overload, tell library to retry
|
|
|
*/
|
|
|
@@ -515,10 +664,20 @@ static int32_t cs_ipcs_msg_process(qb_ipcs_connection_t *c,
|
|
|
response.id = 0;
|
|
|
response.error = CS_ERR_TRY_AGAIN;
|
|
|
qb_ipcs_response_send (c,
|
|
|
- &response,
|
|
|
- sizeof (response));
|
|
|
- res = -ENOBUFS;
|
|
|
+ &response,
|
|
|
+ sizeof (response));
|
|
|
+ } else {
|
|
|
+ log_printf(LOGSYS_LEVEL_WARNING,
|
|
|
+ "*** %s() (%d:%d - %d) %s!",
|
|
|
+ __func__, service, request_pt->id,
|
|
|
+ is_async_call, strerror(-send_ok));
|
|
|
}
|
|
|
+ res = -ENOBUFS;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (send_ok) {
|
|
|
+ ais_service[service]->lib_engine[request_pt->id].lib_handler_fn(c, request_pt);
|
|
|
+ res = 0;
|
|
|
}
|
|
|
corosync_sending_allowed_release (&sending_allowed_private_data);
|
|
|
return res;
|
|
|
@@ -677,13 +836,21 @@ void cs_ipcs_stats_update(void)
|
|
|
api->object_key_replace(cnx->stats_handle,
|
|
|
"recv_retries", strlen("recv_retries"),
|
|
|
&stats.recv_retries, sizeof(uint64_t));
|
|
|
+ api->object_key_replace(cnx->stats_handle,
|
|
|
+ "flow_control", strlen("flow_control"),
|
|
|
+ &stats.flow_control_state, sizeof(uint32_t));
|
|
|
api->object_key_replace(cnx->stats_handle,
|
|
|
"flow_control_count", strlen("flow_control_count"),
|
|
|
&stats.flow_control_count, sizeof(uint64_t));
|
|
|
api->object_key_replace(cnx->stats_handle,
|
|
|
- "flow_control_state", strlen("flow_control_state"),
|
|
|
- &stats.flow_control_state, sizeof(uint32_t));
|
|
|
-
|
|
|
+ "queue_size", strlen("queue_size"),
|
|
|
+ &cnx->queued, sizeof(uint32_t));
|
|
|
+ api->object_key_replace(cnx->stats_handle,
|
|
|
+ "invalid_request", strlen("invalid_request"),
|
|
|
+ &cnx->invalid_request, sizeof(uint64_t));
|
|
|
+ api->object_key_replace(cnx->stats_handle,
|
|
|
+ "overload", strlen("overload"),
|
|
|
+ &cnx->overload, sizeof(uint64_t));
|
|
|
qb_ipcs_connection_unref(c);
|
|
|
}
|
|
|
}
|