[PATCH] Add a samplewindow API
by Steven Dake
This API works by allowing the API user to keep a list of samples internally.
Every time a new sample is taken, the difference between the current sample
and the first sample in the window is returned. When the sample array is
filled, old entries drop off the sample list.
The use case where this is helpful is recovery escalation. Every time a failure
occurs we take a sample. If the resulting window is less then the escalation
window, an escalation should occur and the sample window should be reset.
Signed-off-by: Steven Dake <sdake(a)redhat.com>
---
include/qb/qbutil.h | 25 +++++++++++++
lib/util.c | 64 ++++++++++++++++++++++++++++++++
tests/Makefile.am | 8 +++-
tests/check_util.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 195 insertions(+), 2 deletions(-)
create mode 100644 tests/check_util.c
diff --git a/include/qb/qbutil.h b/include/qb/qbutil.h
index 2b450e9..d737ec2 100644
--- a/include/qb/qbutil.h
+++ b/include/qb/qbutil.h
@@ -171,6 +171,31 @@ uint64_t qb_util_stopwatch_us_elapsed_get(qb_util_stopwatch_t *sw);
*/
float qb_util_stopwatch_sec_elapsed_get(qb_util_stopwatch_t *sw);
+typedef struct qb_util_samplewindow qb_util_samplewindow_t;
+
+/**
+ * Create a timer sample window
+ */
+qb_util_samplewindow_t * qb_util_samplewindow_create(uint32_t size);
+
+/**
+ * Free a timer sample window
+ */
+void qb_util_samplewindow_free(qb_util_samplewindow_t *sw);
+
+/**
+ * Get the elapsed time in micro seconds across the sample window.
+ *
+ * A return value of 0 indicates there have not been enough samples
+ * to determine the elapsed time.
+ */
+uint64_t qb_util_samplewindow_sample(qb_util_samplewindow_t *sw);
+
+/*
+ * Reset the sample window
+ */
+void qb_util_samplewindow_reset(qb_util_samplewindow_t *sw);
+
/* *INDENT-OFF* */
#ifdef __cplusplus
}
diff --git a/lib/util.c b/lib/util.c
index 51c94bb..d9f11c6 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -272,3 +272,67 @@ qb_util_stopwatch_sec_elapsed_get(qb_util_stopwatch_t * sw)
return ((float)e6 / (float)QB_TIME_US_IN_SEC);
}
+struct qb_util_samplewindow {
+ uint32_t size;
+ uint32_t entries;
+ uint64_t *entry_list;
+};
+
+/**
+ * Create a timer sample window
+ */
+qb_util_samplewindow_t * qb_util_samplewindow_create(uint32_t size)
+{
+ struct qb_util_samplewindow *sw;
+
+ sw = (struct qb_util_samplewindow *)calloc(1, sizeof(struct qb_util_stopwatch));
+ sw->size = size;
+ sw->entry_list = (uint64_t *)calloc(1, sizeof (uint64_t) * size);
+ if (sw->entry_list == NULL) {
+ free (sw);
+ sw = NULL;
+ }
+ return sw;
+}
+
+/**
+ * Free a timer sample window
+ */
+void qb_util_samplewindow_free(qb_util_samplewindow_t *sw)
+{
+ free(sw->entry_list);
+ free(sw);
+}
+
+/**
+ * Get the elapsed time in micro seconds across the sample window.
+ *
+ * A return value of 0 indicates there have not been enough samples
+ * to determine the elapsed time.
+ */
+uint64_t qb_util_samplewindow_sample(qb_util_samplewindow_t *sw)
+{
+ uint32_t new_entry_pos;
+ uint64_t time_start;
+ uint64_t time_end;
+
+ new_entry_pos = sw->entries % (sw->size);
+
+ sw->entry_list[new_entry_pos] = qb_util_nano_current_get();
+ sw->entries++;
+ if (sw->entries < sw->size) {
+ return 0ULL;
+ }
+
+ time_start = sw->entry_list[(new_entry_pos) % sw->size];
+ time_end = sw->entry_list[(new_entry_pos + 1) % sw->size];
+ return (time_start - time_end) / QB_TIME_NS_IN_USEC;
+}
+
+/*
+ * Reset the sample window
+ */
+void qb_util_samplewindow_reset(qb_util_samplewindow_t *sw)
+{
+ sw->entries = 0;
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d8f64e2..dd73363 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -73,11 +73,11 @@ bench_log_LDADD = $(LIB_RT) $(top_builddir)/lib/libqb.la
if HAVE_CHECK
EXTRA_DIST += resources.test
-TESTS = array.test map.test rb.test log.test loop.test ipc.test resources.test
+TESTS = array.test map.test rb.test log.test loop.test ipc.test resources.test util.test
resources.log: rb.log log.log ipc.log
-check_PROGRAMS = array.test map.test rb.test log.test loop.test ipc.test
+check_PROGRAMS = array.test map.test rb.test log.test loop.test ipc.test util.test
check_SCRIPTS = resources.test
array_test_SOURCES = check_array.c $(top_builddir)/include/qb/qbarray.h
@@ -104,6 +104,10 @@ log_test_SOURCES = check_log.c $(top_builddir)/include/qb/qblog.h
log_test_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include
log_test_LDADD = $(top_builddir)/lib/libqb.la $(LIB_RT) @CHECK_LIBS@
+util_test_SOURCES = check_util.c $(top_builddir)/include/qb/qbutil.h
+util_test_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include
+util_test_LDADD = $(top_builddir)/lib/libqb.la $(LIB_RT) @CHECK_LIBS@
+
endif
clean-generic:
diff --git a/tests/check_util.c b/tests/check_util.c
new file mode 100644
index 0000000..0313325
--- /dev/null
+++ b/tests/check_util.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * All rights reserved.
+ *
+ * Author: Steven Dake <sdake(a)redhat.com>
+ *
+ * This file is part of libqb.
+ *
+ * libqb is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * libqb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libqb. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "os_base.h"
+#include <check.h>
+
+#include <qb/qbdefs.h>
+#include <qb/qbutil.h>
+#include <qb/qblog.h>
+
+START_TEST(test_check_samplewindow)
+{
+ qb_util_samplewindow_t *sw;
+ uint64_t res;
+
+ sw = qb_util_samplewindow_create(5);
+ res = qb_util_samplewindow_sample(sw);
+ ck_assert_int_eq(res, 0ULL);
+
+ usleep(10000);
+ res = qb_util_samplewindow_sample(sw);
+ ck_assert_int_eq(res, 0ULL);
+
+ usleep(20000);
+ res = qb_util_samplewindow_sample(sw);
+ ck_assert_int_eq(res, 0ULL);
+
+ usleep(30000);
+ res = qb_util_samplewindow_sample(sw);
+ ck_assert_int_eq(res, 0ULL);
+
+ usleep(40000);
+ res = qb_util_samplewindow_sample(sw);
+ /*
+ * window should be 100000 (40000 + 30000 + 20000 + 10000) usec
+ */
+ ck_assert(res > 95000);
+ ck_assert(res < 105000);
+
+ usleep(50000);
+ res = qb_util_samplewindow_sample(sw);
+ /*
+ * window should be 140000 (50000 + 40000 + 30000 + 20000) usec
+ */
+ ck_assert(res > 135000);
+ ck_assert(res < 145000);
+
+}
+END_TEST
+
+static Suite *util_suite(void)
+{
+ TCase *tc;
+ Suite *s = suite_create("qb_util");
+
+ tc = tcase_create("properop");
+ tcase_add_test(tc, test_check_samplewindow);
+ suite_add_tcase(s, tc);
+
+ return s;
+}
+
+int32_t main(void)
+{
+ int32_t number_failed;
+
+ Suite *s = util_suite();
+ SRunner *sr = srunner_create(s);
+
+ qb_log_init("check", LOG_USER, LOG_EMERG);
+ qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
+ qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
+ QB_LOG_FILTER_FILE, "*", LOG_INFO);
+ qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
+
+ srunner_run_all(sr, CK_VERBOSE);
+ number_failed = srunner_ntests_failed(sr);
+ srunner_free(sr);
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
--
1.7.7.4
12 years, 3 months
make rpm error of libqb
by nozawat
Hi
Pacemaker depended on libqb.
Therefore I was going to make RPM of libqb.
I got libqb from the following.
->https://github.com/asalkeld/libqb.git
->git show commit:d823a480dc49639fd13ea8ab6e5f586842c64e24
However, the following errors occurred and were not able to make rpm.
-------
PASS: array.test
PASS: map.test
PASS: rb.test
PASS: log.test
PASS: loop.test
PASS: ipc.test
FAIL: resources.test
===================================================
1 of 7 tests failed
See tests/test-suite.log
Please report to quarterback-devel(a)fedorahosted.org
===================================================
make[5]: *** [test-suite.log] Error 1
make[5]: Leaving directory
`/share/ha/buildbot/build/RHEL6.0-x86_64/libqb/libqb-0.7.0.31-d823/tests'
make[4]: *** [check-TESTS] Error 2
make[4]: Leaving directory
`/share/ha/buildbot/build/RHEL6.0-x86_64/libqb/libqb-0.7.0.31-d823/tests'
make[3]: *** [check-am] Error 2
make[3]: Leaving directory
`/share/ha/buildbot/build/RHEL6.0-x86_64/libqb/libqb-0.7.0.31-d823/tests'
make[2]: *** [check-recursive] Error 1
make[2]: Leaving directory
`/share/ha/buildbot/build/RHEL6.0-x86_64/libqb/libqb-0.7.0.31-d823'
make[1]: *** [check] Error 2
make[1]: Leaving directory
`/share/ha/buildbot/build/RHEL6.0-x86_64/libqb/libqb-0.7.0.31-d823'
error: Bad exit status from /var/tmp/rpm-tmp.F0jYH5 (%check)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.F0jYH5 (%check)
make: *** [rpm] Error 1
-------
make is completed.
My environment is RHEL6.0.
Thanks in advance for any advice :)
Regards,
Tomo
12 years, 3 months
[PATCH] Fixed bug: incorrect array length definition
by Yunkai Zhang
When MAX_BINS is larger than MAX_BIN_ELEMENTS, this bug will cause
boudary overflow in qb_array_create function.
Signed-off-by: Yunkai Zhang <qiushu.zyk(a)taobao.com>
---
lib/array.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/array.c b/lib/array.c
index 038cac2..96a7f43 100644
--- a/lib/array.c
+++ b/lib/array.c
@@ -29,7 +29,7 @@
#define ELEM_NUM_GET(_idx_) (_idx_ & 0xff)
struct qb_array {
- void *bin[MAX_BIN_ELEMENTS];
+ void *bin[MAX_BINS];
size_t max_elements;
size_t element_size;
size_t num_bins;
--
1.7.7.4
12 years, 4 months
How does ld linker work?
by Yunkai Zhang
Hi Angus:
I'm confused by these code in qblog.h:
240 /* will be assigned by ld linker magic */
241 #ifdef QB_HAVE_ATTRIBUTE_SECTION
242 extern struct qb_log_callsite __start___verbose[];
243 extern struct qb_log_callsite __stop___verbose[];
I can't understand how ld linker work:
What is the naming rule when we use callsite? __start___<section_name>?
Can you give me some references about ld linker's magic?
Thanks a lot.
--
Yunkai Zhang
Work at Taobao
12 years, 4 months
[PATCH] Fix some sparc test failures.
by Angus Salkeld
From: "Fabio M. Di Nitto" <fdinitto(a)redhat.com>
I (Angus) have changed some of Fabio's changes.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
examples/ipcclient.c | 49 ++++++++++++++++++++++++++-----------------------
examples/ipcserver.c | 2 +-
examples/tcpclient.c | 2 +-
lib/ipc_us.c | 12 ++++++------
lib/log_format.c | 29 +++++++++++++++--------------
tests/bmc.c | 15 ++++++++++-----
tests/bmcpt.c | 15 ++++++++++-----
tests/check_ipc.c | 26 +++++++++++++++++---------
tests/check_rb.c | 24 ++++++++++++------------
9 files changed, 98 insertions(+), 76 deletions(-)
diff --git a/examples/ipcclient.c b/examples/ipcclient.c
index c43998f..a8180c2 100644
--- a/examples/ipcclient.c
+++ b/examples/ipcclient.c
@@ -27,12 +27,23 @@
#define MAX_MSG_SIZE (8192)
+struct my_req {
+ struct qb_ipc_request_header hdr;
+ char message[256];
+};
+
+struct my_res {
+ struct qb_ipc_response_header hdr;
+ char message[256];
+};
+
int
main(int argc, char *argv[])
{
qb_ipcc_connection_t *conn;
- int32_t res;
- char *buffer[MAX_MSG_SIZE];
+ int32_t rc;
+ struct my_req req;
+ struct my_res res;
conn = qb_ipcc_connect("ipcserver", MAX_MSG_SIZE);
if (conn == NULL) {
@@ -41,39 +52,31 @@ main(int argc, char *argv[])
}
while(1) {
- struct qb_ipc_request_header *req_header = (struct qb_ipc_request_header *)buffer;
- struct qb_ipc_response_header *res_header = (struct qb_ipc_response_header *)buffer;
- char *data = (char*)buffer + sizeof(struct qb_ipc_request_header);
-
printf("SEND (q or Q to quit) : ");
- if (gets(data) == NULL) {
+ if (gets(req.message) == NULL) {
continue;
}
- if (strcmp(data , "q") != 0 &&
- strcmp(data , "Q") != 0) {
- req_header->id = QB_IPC_MSG_USER_START + 3;
- req_header->size = sizeof(struct qb_ipc_request_header) + strlen(data) + 1;
- res = qb_ipcc_send(conn, req_header, req_header->size);
- if (res < 0) {
+ if (strcmp(req.message, "q") != 0 &&
+ strcmp(req.message, "Q") != 0) {
+ req.hdr.id = QB_IPC_MSG_USER_START + 3;
+ req.hdr.size = sizeof(struct my_req);
+ rc = qb_ipcc_send(conn, &req, req.hdr.size);
+ if (rc < 0) {
perror("qb_ipcc_send");
}
} else {
break;
}
- if (res > 0) {
- res = qb_ipcc_recv(conn,
- buffer,
- MAX_MSG_SIZE, -1);
- if (res < 0) {
+ if (rc > 0) {
+ rc = qb_ipcc_recv(conn,
+ &res,
+ sizeof(res), -1);
+ if (rc < 0) {
perror("qb_ipcc_recv");
}
- res_header = (struct qb_ipc_response_header*)buffer;
- data = (char*)buffer + sizeof(struct qb_ipc_response_header);
- data[res - sizeof(struct qb_ipc_response_header)] = '\0';
-
- printf("Response[%d]: %s \n", res_header->id, data);
+ printf("Response[%d]: %s \n", res.hdr.id, res.message);
}
}
diff --git a/examples/ipcserver.c b/examples/ipcserver.c
index f4c47d4..4a51121 100644
--- a/examples/ipcserver.c
+++ b/examples/ipcserver.c
@@ -111,7 +111,7 @@ s1_msg_process_fn(qb_ipcs_connection_t *c,
snprintf(resp, 100, "ACK %zd bytes", size);
iov[0].iov_len = sizeof(response);
iov[0].iov_base = &response;
- iov[1].iov_len = strlen(resp);
+ iov[1].iov_len = strlen(resp) + 1;
iov[1].iov_base = resp;
res = qb_ipcs_response_sendv(c, iov, 2);
diff --git a/examples/tcpclient.c b/examples/tcpclient.c
index 8283321..15c60f0 100644
--- a/examples/tcpclient.c
+++ b/examples/tcpclient.c
@@ -39,7 +39,7 @@ main(int argc, char *argv[])
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000);
- server_addr.sin_addr = *((struct in_addr *)host->h_addr);
+ memcpy(&server_addr.sin_addr, host->h_addr, sizeof(host->h_addr));
bzero(&(server_addr.sin_zero),8);
if (connect(sock, (struct sockaddr *)&server_addr,
diff --git a/lib/ipc_us.c b/lib/ipc_us.c
index 3f11dfe..1387b0b 100644
--- a/lib/ipc_us.c
+++ b/lib/ipc_us.c
@@ -720,15 +720,15 @@ qb_ipcs_uc_recv_and_auth(int32_t sock, void *msg, size_t len,
* Usually Linux systems
*/
{
- struct ucred *cred;
+ struct ucred cred;
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg_recv);
assert(cmsg != NULL);
- cred = (struct ucred *)CMSG_DATA(cmsg);
- if (cred) {
+ if (CMSG_DATA(cmsg)) {
+ memcpy(&cred, CMSG_DATA(cmsg), sizeof(struct ucred));
res = 0;
- ugp->pid = cred->pid;
- ugp->uid = cred->uid;
- ugp->gid = cred->gid;
+ ugp->pid = cred.pid;
+ ugp->uid = cred.uid;
+ ugp->gid = cred.gid;
} else {
res = -EBADMSG;
}
diff --git a/lib/log_format.c b/lib/log_format.c
index 55d8a6f..a626cae 100644
--- a/lib/log_format.c
+++ b/lib/log_format.c
@@ -482,11 +482,12 @@ reprocess:
goto reprocess;
case '*': {
- int *arg_int = (int *)&buf[data_pos];
+ int arg_int;
+ memcpy(&arg_int, &buf[data_pos], sizeof(int));
data_pos += sizeof(int);
fmt_pos += snprintf(&fmt[fmt_pos],
MINI_FORMAT_STR_LEN - fmt_pos,
- "%d", *arg_int);
+ "%d", arg_int);
format++;
goto reprocess;
}
@@ -506,38 +507,38 @@ reprocess:
case 'x':
case 'X':
if (type_long) {
- long int *arg_int;
+ long int arg_int;
fmt[fmt_pos++] = *format;
fmt[fmt_pos++] = '\0';
- arg_int = (long int *)&buf[data_pos];
+ memcpy(&arg_int, &buf[data_pos], sizeof(long int));
location += snprintf(&string[location],
str_len - location,
- fmt, *arg_int);
+ fmt, arg_int);
data_pos += sizeof(long int);
format++;
break;
} else if (type_longlong) {
- long long int *arg_int;
+ long long int arg_int;
fmt[fmt_pos++] = *format;
fmt[fmt_pos++] = '\0';
- arg_int = (long long int *)&buf[data_pos];
+ memcpy(&arg_int, &buf[data_pos], sizeof(long long int));
location += snprintf(&string[location],
str_len - location,
- fmt, *arg_int);
+ fmt, arg_int);
data_pos += sizeof(long long int);
format++;
break;
} else {
- int *arg_int;
+ int arg_int;
fmt[fmt_pos++] = *format;
fmt[fmt_pos++] = '\0';
- arg_int = (int *)&buf[data_pos];
+ memcpy(&arg_int, &buf[data_pos], sizeof(int));
location += snprintf(&string[location],
str_len - location,
- fmt, *arg_int);
+ fmt, arg_int);
data_pos += sizeof(int);
format++;
break;
@@ -551,14 +552,14 @@ reprocess:
case 'a':
case 'A':
{
- double *arg_double;
+ double arg_double;
fmt[fmt_pos++] = *format;
fmt[fmt_pos++] = '\0';
- arg_double = (double *)&buf[data_pos];
+ memcpy(&arg_double, &buf[data_pos], sizeof(double));
location += snprintf(&string[location],
str_len - location,
- fmt, *arg_double);
+ fmt, arg_double);
data_pos += sizeof(double);
format++;
break;
diff --git a/tests/bmc.c b/tests/bmc.c
index 3e805ed..6a4eeb4 100644
--- a/tests/bmc.c
+++ b/tests/bmc.c
@@ -49,18 +49,23 @@ static void bm_finish(const char *operation, int32_t size)
printf("MB/sec, %9.3f\n", mbs_per_sec);
}
-static char buffer[1024 * 1024];
+struct my_req {
+ struct qb_ipc_request_header hdr;
+ char message[1024 * 1024];
+};
+
+static struct my_req request;
+
static int32_t bmc_send_nozc(uint32_t size)
{
- struct qb_ipc_request_header *req_header = (struct qb_ipc_request_header *)buffer;
struct qb_ipc_response_header res_header;
int32_t res;
- req_header->id = QB_IPC_MSG_USER_START + 3;
- req_header->size = sizeof(struct qb_ipc_request_header) + size;
+ request.hdr.id = QB_IPC_MSG_USER_START + 3;
+ request.hdr.size = sizeof(struct qb_ipc_request_header) + size;
repeat_send:
- res = qb_ipcc_send(conn, req_header, req_header->size);
+ res = qb_ipcc_send(conn, &request, request.hdr.size);
if (res < 0) {
if (res == -EAGAIN) {
goto repeat_send;
diff --git a/tests/bmcpt.c b/tests/bmcpt.c
index e9faca1..5f5d1f6 100644
--- a/tests/bmcpt.c
+++ b/tests/bmcpt.c
@@ -88,18 +88,23 @@ static void bmc_disconnect(struct bm_ctx *ctx)
qb_ipcc_disconnect(ctx->conn);
}
-static char buffer[1024 * 1024];
+struct my_req {
+ struct qb_ipc_request_header hdr;
+ char message[1024 * 1024];
+};
+
+static struct my_req request;
+
static int32_t bmc_send_nozc(struct bm_ctx *ctx, uint32_t size)
{
- struct qb_ipc_request_header *req_header = (struct qb_ipc_request_header *)buffer;
struct qb_ipc_response_header res_header;
int32_t res;
- req_header->id = QB_IPC_MSG_USER_START + 3;
- req_header->size = sizeof(struct qb_ipc_request_header) + size;
+ request.hdr.id = QB_IPC_MSG_USER_START + 3;
+ request.hdr.size = sizeof(struct qb_ipc_request_header) + size;
repeat_send:
- res = qb_ipcc_send(ctx->conn, req_header, req_header->size);
+ res = qb_ipcc_send(ctx->conn, &request, request.hdr.size);
if (res < 0) {
if (res == -EAGAIN) {
goto repeat_send;
diff --git a/tests/check_ipc.c b/tests/check_ipc.c
index 7c93383..b31b4a3 100644
--- a/tests/check_ipc.c
+++ b/tests/check_ipc.c
@@ -210,21 +210,24 @@ static int32_t stop_process(pid_t pid)
return 0;
}
-#define IPC_BUF_SIZE (1024 * 1024)
-static char buffer[IPC_BUF_SIZE];
+struct my_req {
+ struct qb_ipc_request_header hdr;
+ char message[1024 * 1024];
+};
+
+static struct my_req request;
static int32_t send_and_check(uint32_t size, int32_t ms_timeout)
{
- struct qb_ipc_request_header *req_header = (struct qb_ipc_request_header *)buffer;
struct qb_ipc_response_header res_header;
int32_t res;
int32_t try_times = 0;
- req_header->id = IPC_MSG_REQ_TX_RX;
- req_header->size = sizeof(struct qb_ipc_request_header) + size;
+ request.hdr.id = IPC_MSG_REQ_TX_RX;
+ request.hdr.size = sizeof(struct qb_ipc_request_header) + size;
repeat_send:
- res = qb_ipcc_send(conn, req_header, req_header->size);
+ res = qb_ipcc_send(conn, &request, request.hdr.size);
try_times++;
if (res < 0) {
if (res == -EAGAIN && try_times < 10) {
@@ -378,6 +381,12 @@ START_TEST(test_ipc_txrx_smq)
}
END_TEST
+struct my_res {
+ struct qb_ipc_response_header hdr;
+ char message[1024 * 1024];
+};
+
+static struct my_res response;
static void test_ipc_dispatch(void)
{
int32_t res;
@@ -385,7 +394,6 @@ static void test_ipc_dispatch(void)
int32_t c = 0;
pid_t pid;
struct qb_ipc_request_header req_header;
- struct qb_ipc_response_header *res_header = (struct qb_ipc_response_header*)buffer;
pid = run_function_in_new_process(run_ipc_server);
fail_if(pid == -1);
@@ -420,7 +428,7 @@ static void test_ipc_dispatch(void)
}
}
repeat_event_recv:
- res = qb_ipcc_event_recv(conn, res_header, IPC_BUF_SIZE, 0);
+ res = qb_ipcc_event_recv(conn, &response, sizeof(struct my_res), 0);
if (res < 0) {
if (res == -EAGAIN || res == -ETIMEDOUT) {
goto repeat_event_recv;
@@ -431,7 +439,7 @@ static void test_ipc_dispatch(void)
}
}
ck_assert_int_eq(res, sizeof(struct qb_ipc_response_header));
- ck_assert_int_eq(res_header->id, IPC_MSG_RES_DISPATCH);
+ ck_assert_int_eq(response.hdr.id, IPC_MSG_RES_DISPATCH);
qb_ipcc_disconnect(conn);
stop_process(pid);
diff --git a/tests/check_rb.c b/tests/check_rb.c
index d67263e..002521e 100644
--- a/tests/check_rb.c
+++ b/tests/check_rb.c
@@ -35,7 +35,7 @@
START_TEST(test_ring_buffer1)
{
char my_buf[512];
- struct qb_ipc_request_header *hdr;
+ struct qb_ipc_request_header hdr;
char *str;
qb_ringbuffer_t *rb;
int32_t i;
@@ -47,39 +47,39 @@ START_TEST(test_ring_buffer1)
fail_if(rb == NULL);
for (b = 0; b < 3; b++) {
- hdr = (struct qb_ipc_request_header *) my_buf;
+ memcpy(&hdr, my_buf, sizeof(struct qb_ipc_request_header));
str = my_buf + sizeof(struct qb_ipc_request_header);
for (i = 0; i < 900; i++) {
- hdr->id = __LINE__ + i;
- hdr->size =
+ hdr.id = __LINE__ + i;
+ hdr.size =
sprintf(str, "ID: %d (%s + i(%d)) -- %s-%s!",
- hdr->id, "actually the line number", i,
+ hdr.id, "actually the line number", i,
__func__, __FILE__) + 1;
- hdr->size += sizeof(struct qb_ipc_request_header);
+ hdr.size += sizeof(struct qb_ipc_request_header);
avail = qb_rb_space_free(rb);
- actual = qb_rb_chunk_write(rb, hdr, hdr->size);
- if (avail < (hdr->size + (2 * sizeof(uint32_t)))) {
+ actual = qb_rb_chunk_write(rb, &hdr, hdr.size);
+ if (avail < (hdr.size + (2 * sizeof(uint32_t)))) {
ck_assert_int_eq(actual, -EAGAIN);
} else {
- ck_assert_int_eq(actual, hdr->size);
+ ck_assert_int_eq(actual, hdr.size);
}
}
memset(my_buf, 0, sizeof(my_buf));
- hdr = (struct qb_ipc_request_header *) my_buf;
+ memcpy(&hdr, my_buf, sizeof(struct qb_ipc_request_header));
str = my_buf + sizeof(struct qb_ipc_request_header);
for (i = 0; i < 15; i++) {
- actual = qb_rb_chunk_read(rb, hdr, 512, 0);
+ actual = qb_rb_chunk_read(rb, &hdr, 512, 0);
if (actual < 0) {
ck_assert_int_eq(0, qb_rb_chunks_used(rb));
break;
}
str[actual - sizeof(struct qb_ipc_request_header)] = '\0';
- ck_assert_int_eq(actual, hdr->size);
+ ck_assert_int_eq(actual, hdr.size);
}
}
qb_rb_close(rb);
--
1.7.7.4
12 years, 4 months
[PATCH] re-fix qb_strerror_r() in case caller frees buf.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/unix.c | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/lib/unix.c b/lib/unix.c
index f683e7b..0e4e8be 100644
--- a/lib/unix.c
+++ b/lib/unix.c
@@ -38,14 +38,10 @@ qb_strerror_r(int errnum, char *buf, size_t buflen)
#ifdef QB_LINUX
return strerror_r(errnum, buf, buflen);
#else
- char *out_buf;
-
- if (strerror_r(errnum, buf, buflen) == 0) {
- out_buf = buf;
- } else {
- out_buf = (char*)"";
+ if (strerror_r(errnum, buf, buflen) != 0) {
+ buf[0] = '\0';
}
- return out_buf;
+ return buf;
#endif /* QB_LINUX */
}
--
1.7.7.4
12 years, 4 months
[PATCH] LOG: pass args directly into qb_log_from_external_source()
by Angus Salkeld
From: Andrew Beekhof <andrew(a)beekhof.net>
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qblog.h | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/include/qb/qblog.h b/include/qb/qblog.h
index b996c87..1f5f00c 100644
--- a/include/qb/qblog.h
+++ b/include/qb/qblog.h
@@ -312,10 +312,8 @@ void qb_log_from_external_source_va(const char *function,
} while(0)
#else
#define qb_logt(priority, tags, fmt, args...) do { \
- char _log_buf_[QB_LOG_MAX_LEN]; \
- snprintf(_log_buf_, QB_LOG_MAX_LEN, fmt, ##args); \
qb_log_from_external_source(__func__, __FILE__, fmt, priority, \
- __LINE__, tags, _log_buf_); \
+ __LINE__, tags, ##args); \
} while(0)
#endif /* QB_HAVE_ATTRIBUTE_SECTION */
--
1.7.7.4
12 years, 4 months
[PATCH 1/6] fix strerror on non-linux
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/util.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/util.c b/lib/util.c
index 4239cf8..151b04a 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -462,10 +462,10 @@ qb_strerror_r(int errnum, char *buf, size_t buflen)
#else
char *out_buf;
- if (strerror_r(err_num, buffer, sizeof_buffer) == 0) {
- out_ptr = buffer;
+ if (strerror_r(errnum, buf, buflen) == 0) {
+ out_buf = buf;
} else {
- out_ptr = "";
+ out_buf = (char*)"";
}
return out_buf;
#endif /* QB_LINUX */
--
1.7.7.4
12 years, 4 months
[PATCH 1/7] trie: split trie_lookup into trie_lookup and trie_insert
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/trie.c | 123 +++++++++++++++++++++++++++++++++---------------------------
1 files changed, 68 insertions(+), 55 deletions(-)
diff --git a/lib/trie.c b/lib/trie.c
index 38dc2d1..dc56e2b 100644
--- a/lib/trie.c
+++ b/lib/trie.c
@@ -53,6 +53,7 @@ struct trie {
static void trie_notify(struct trie_node *n, uint32_t event, const char *key,
void *old_value, void *value);
+static struct trie_node *trie_new_node(struct trie *t, struct trie_node *parent);
/*
* characters are stored in reverse to make accessing the
@@ -119,6 +120,67 @@ keep_going:
return n;
}
+static struct trie_node *
+trie_insert(struct trie *t, const char *key)
+{
+ struct trie_node *cur_node = t->header;
+ struct trie_node *new_node;
+ int old_max_idx;
+ int i;
+ char *cur = (char *)key;
+ int idx = TRIE_CHAR2INDEX(key[0]);
+
+ do {
+ if (idx >= cur_node->num_children) {
+ old_max_idx = cur_node->num_children;
+ cur_node->num_children = QB_MAX(idx + 1, 30);;
+ cur_node->children = realloc(cur_node->children,
+ (cur_node->num_children *
+ sizeof(struct trie_node*)));
+ /*
+ printf("%s(%d) %d %d\n", __func__, idx,
+ old_max_idx, cur_node->num_children);
+ */
+ for (i = old_max_idx; i < cur_node->num_children; i++) {
+ cur_node->children[i] = NULL;
+ }
+ }
+ if (cur_node->children[idx] == NULL) {
+ new_node = trie_new_node(t, cur_node);
+ if (new_node == NULL) {
+ return NULL;
+ }
+ new_node->idx = idx;
+ cur_node->children[idx] = new_node;
+ }
+ cur_node = cur_node->children[idx];
+ cur++;
+ idx = TRIE_CHAR2INDEX(*cur);
+ } while (*cur != '\0');
+
+ return cur_node;
+}
+
+static struct trie_node *
+trie_lookup(struct trie *t, const char *key)
+{
+ struct trie_node *cur_node = t->header;
+ char *cur = (char *)key;
+ int idx = TRIE_CHAR2INDEX(key[0]);
+
+ do {
+ if (idx >= cur_node->num_children ||
+ cur_node->children[idx] == NULL) {
+ return NULL;
+ }
+ cur_node = cur_node->children[idx];
+ cur++;
+ idx = TRIE_CHAR2INDEX(*cur);
+ } while (*cur != '\0');
+
+ return cur_node;
+}
+
static void
trie_node_destroy(struct trie *t, struct trie_node *n)
{
@@ -181,63 +243,14 @@ trie_new_node(struct trie *t, struct trie_node *parent)
return new_node;
}
-static struct trie_node *
-trie_lookup(struct trie *t, const char *key, int32_t create_path)
{
- struct trie_node *cur_node = t->header;
- struct trie_node *new_node;
- int old_max_idx;
- int i;
- char *cur = (char *)key;
- int idx = TRIE_CHAR2INDEX(key[0]);
-
- do {
- if (idx >= cur_node->num_children) {
- if (!create_path) {
- return NULL;
- }
- if (cur_node->num_children == 0) {
- old_max_idx = 0;
- } else {
- old_max_idx = cur_node->num_children;
- }
- cur_node->num_children = idx + 1;
- cur_node->children = realloc(cur_node->children,
- (cur_node->num_children *
- sizeof(struct trie_node
- *)));
- /*
- printf("%s(%d) %d %d\n", __func__, idx,
- old_max_idx, cur_node->num_children);
- */
- for (i = old_max_idx; i < cur_node->num_children; i++) {
- cur_node->children[i] = NULL;
- }
- }
- if (cur_node->children[idx] == NULL) {
- if (!create_path) {
- return NULL;
- }
- new_node = trie_new_node(t, cur_node);
- if (new_node == NULL) {
- return NULL;
- }
- new_node->idx = idx;
- cur_node->children[idx] = new_node;
- }
- cur_node = cur_node->children[idx];
- cur++;
- idx = TRIE_CHAR2INDEX(*cur);
- } while (*cur != '\0');
-
- return cur_node;
}
static void
trie_put(struct qb_map *map, const char *key, const void *value)
{
struct trie *t = (struct trie *)map;
- struct trie_node *n = trie_lookup(t, key, QB_TRUE);
+ struct trie_node *n = trie_insert(t, key);
if (n) {
const char *old_value = n->value;
const char *old_key = n->key;
@@ -262,7 +275,7 @@ static int32_t
trie_rm(struct qb_map *map, const char *key)
{
struct trie *t = (struct trie *)map;
- struct trie_node *n = trie_lookup(t, key, QB_FALSE);
+ struct trie_node *n = trie_lookup(t, key);
if (n) {
trie_node_deref(t, n);
t->length--;
@@ -276,7 +289,7 @@ static void *
trie_get(struct qb_map *map, const char *key)
{
struct trie *t = (struct trie *)map;
- struct trie_node *n = trie_lookup(t, key, QB_FALSE);
+ struct trie_node *n = trie_lookup(t, key);
if (n) {
return n->value;
}
@@ -325,7 +338,7 @@ trie_notify_add(qb_map_t * m, const char *key,
int add_to_tail = QB_FALSE;
if (key) {
- n = trie_lookup(t, key, QB_TRUE);
+ n = trie_insert(t, key);
} else {
n = t->header;
}
@@ -386,7 +399,7 @@ trie_notify_del(qb_map_t * m, const char *key,
int32_t found = QB_FALSE;
if (key) {
- n = trie_lookup(t, key, QB_TRUE);
+ n = trie_lookup(t, key);
} else {
n = t->header;
}
@@ -445,7 +458,7 @@ trie_iter_next(qb_map_iter_t * i, void **value)
}
if (p->parent == NULL && si->prefix) {
- si->root = trie_lookup(t, si->prefix, QB_FALSE);
+ si->root = trie_lookup(t, si->prefix);
if (si->root == NULL) {
si->n = NULL;
} else if (si->root->value == NULL) {
--
1.7.7.4
12 years, 4 months
[PATCH] clean .version .tarball-version
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
Makefile.am | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 09aa451..3420bea 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,6 +51,7 @@ dist-clean-local:
maintainer-clean-local:
$(AM_V_GEN)rm -rf m4
+ $(AM_V_GEN)rm -f .version .tarball-version
clean-generic:
$(AM_V_GEN)rm -rf $(SPEC) $(TARFILE)
--
1.7.7.4
12 years, 4 months