diff --git a/qdevices/Makefile.am b/qdevices/Makefile.am index 545c9a45..f6dbb667 100644 --- a/qdevices/Makefile.am +++ b/qdevices/Makefile.am @@ -1,145 +1,147 @@ # Copyright (c) 2012-2016 Red Hat, Inc. # # Authors: Fabio M. Di Nitto (fdinitto@redhat.com) # Jan Friesse (jfriesse@redhat.com) # # This software licensed under BSD license, the text of which follows: # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # - Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # - Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # - Neither the name of the MontaVista Software, Inc. nor the names of its # contributors may be used to endorse or promote products derived from this # software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF # THE POSSIBILITY OF SUCH DAMAGE. MAINTAINERCLEANFILES = Makefile.in if BUILD_QDEVICES SUBDIRS = sbin_PROGRAMS = corosync-qnetd corosync-qdevice corosync-qnetd-tool \ corosync-qdevice-tool sbin_SCRIPTS = corosync-qnetd-certutil corosync-qdevice-net-certutil EXTRA_DIST = corosync-qdevice-net-certutil.sh corosync-qnetd-certutil.sh corosync_qnetd_SOURCES = corosync-qnetd.c \ dynar.c dynar.h msg.c msg.h msgio.c msgio.h \ nss-sock.c nss-sock.h qnetd-client.c qnetd-client.h \ qnetd-client-list.c qnetd-client-list.h qnetd-log.c qnetd-log.h \ pr-poll-array.c pr-poll-array.h timer-list.c timer-list.h tlv.c tlv.h \ send-buffer-list.c send-buffer-list.h node-list.c node-list.h \ qnetd-algo-test.c qnetd-algo-test.h qnetd-algorithm.c qnetd-algorithm.h \ qnetd-algo-utils.c qnetd-algo-utils.h \ qnetd-algo-ffsplit.c qnetd-algo-ffsplit.h \ + qnetd-cluster.c qnetd-cluster.h \ qnetd-cluster-list.c qnetd-cluster-list.h \ qnetd-client-send.c qnetd-client-send.h \ qnetd-algo-2nodelms.c qnetd-algo-2nodelms.h qnetd-algo-lms.c qnetd-algo-lms.h \ utils.c utils.h qnetd-instance.c qnetd-instance.h \ qnetd-client-net.c qnetd-client-net.h \ qnetd-client-msg-received.c qnetd-client-msg-received.h \ qnetd-log-debug.c qnetd-log-debug.h \ qnetd-client-algo-timer.c qnetd-client-algo-timer.h \ qnetd-dpd-timer.c qnetd-dpd-timer.h \ qnetd-ipc.c qnetd-ipc.h unix-socket-ipc.c unix-socket-ipc.h \ dynar-simple-lex.c dynar-simple-lex.h dynar-str.c dynar-str.h \ unix-socket-client.c unix-socket-client.h \ unix-socket-client-list.c unix-socket-client-list.h \ unix-socket.c unix-socket.h qnetd-ipc-cmd.c qnetd-ipc-cmd.h \ qnetd-poll-array-user-data.h qnet-config.h dynar-getopt-lex.c \ dynar-getopt-lex.h qnetd-advanced-settings.c corosync_qdevice_SOURCES = corosync-qdevice.c \ qdevice-cmap.c qdevice-cmap.h \ qdevice-instance.c qdevice-instance.h node-list.c node-list.h \ utils.c utils.h qdevice-log.c qdevice-log.h \ qdevice-log-debug.c qdevice-log-debug.h \ qdevice-votequorum.c qdevice-votequorum.h \ qdevice-model.c qdevice-model.h qdevice-model-net.c qdevice-model-net.h \ qdevice-net-instance.c qdevice-net-instance.h dynar.c dynar.h \ send-buffer-list.c send-buffer-list.h timer-list.c timer-list.h \ msg.c msg.h msgio.c msgio.h nss-sock.c nss-sock.h tlv.c tlv.h \ unix-socket.c unix-socket.h unix-socket-client.c unix-socket-client.h \ unix-socket-client-list.c unix-socket-client-list.h \ unix-socket-ipc.c unix-socket-ipc.h qdevice-ipc.c qdevice-ipc.h \ pr-poll-array.c pr-poll-array.h dynar-simple-lex.c dynar-simple-lex.h \ dynar-str.c dynar-str.h qdevice-ipc-cmd.c qdevice-ipc-cmd.h \ qdevice-net-ipc-cmd.c qdevice-net-ipc-cmd.h \ qdevice-net-poll.c qdevice-net-poll.h \ qdevice-net-send.c qdevice-net-send.h \ qdevice-net-votequorum.c qdevice-net-votequorum.h \ qdevice-net-socket.c qdevice-net-socket.h \ qdevice-net-nss.c qdevice-net-nss.h \ qdevice-net-msg-received.c qdevice-net-msg-received.h \ qdevice-net-cast-vote-timer.c qdevice-net-cast-vote-timer.h \ qdevice-net-echo-request-timer.c qdevice-net-echo-request-timer.h \ qdevice-net-algorithm.c qdevice-net-algorithm.h \ qdevice-net-algo-test.c qdevice-net-algo-test.h \ qdevice-net-algo-ffsplit.c qdevice-net-algo-ffsplit.h \ qdevice-net-algo-2nodelms.c qdevice-net-algo-2nodelms.h \ qdevice-net-algo-lms.c qdevice-net-algo-lms.h \ qdevice-net-poll-array-user-data.h \ qdevice-config.h qnet-config.h qdevice-net-disconnect-reason.h \ qdevice-model-type.h qdevice-advanced-settings.c \ qdevice-advanced-settings.h dynar-getopt-lex.c dynar-getopt-lex.h corosync_qnetd_tool_SOURCES = corosync-qnetd-tool.c unix-socket.c unix-socket.h dynar.c dynar.h \ dynar-str.c dynar-str.h corosync_qdevice_tool_SOURCES = corosync-qdevice-tool.c unix-socket.c unix-socket.h dynar.c dynar.h \ dynar-str.c dynar-str.h corosync_qnetd_CFLAGS = $(nss_CFLAGS) corosync_qnetd_LDADD = $(nss_LIBS) corosync_qdevice_CFLAGS = $(nss_CFLAGS) corosync_qdevice_LDADD = $(nss_LIBS) $(LIBQB_LIBS) $(top_builddir)/lib/libcmap.la \ $(top_builddir)/lib/libvotequorum.la corosync-qnetd-certutil: corosync-qnetd-certutil.sh sed -e 's#@''DATADIR@#${datadir}#g' \ -e 's#@''BASHPATH@#${BASHPATH}#g' \ -e 's#@''COROSYSCONFDIR@#${COROSYSCONFDIR}#g' \ $< > $@ corosync-qdevice-net-certutil: corosync-qdevice-net-certutil.sh sed -e 's#@''DATADIR@#${datadir}#g' \ -e 's#@''BASHPATH@#${BASHPATH}#g' \ -e 's#@''COROSYSCONFDIR@#${COROSYSCONFDIR}#g' \ $< > $@ TESTS = qnetd-cluster-list.test dynar.test dynar-simple-lex.test \ dynar-getopt-lex.test check_PROGRAMS = qnetd-cluster-list.test dynar.test dynar-simple-lex.test \ dynar-getopt-lex.test qnetd_cluster_list_test_SOURCES = qnetd-cluster-list.c test-qnetd-cluster-list.c \ - qnetd-client-list.c qnetd-client.c dynar.c node-list.c \ - send-buffer-list.c + qnetd-cluster.c qnetd-cluster.h \ + qnetd-client-list.c qnetd-client.c dynar.c node-list.c \ + send-buffer-list.c qnetd_cluster_list_test_CFLAGS = $(nss_CFLAGS) qnetd_cluster_list_test_LDADD = $(nss_LIBS) dynar_test_SOURCES = test-dynar.c dynar.c dynar-str.c dynar_simple_lex_test_SOURCES = test-dynar-simple-lex.c dynar.c dynar-str.c dynar-simple-lex.c dynar_getopt_lex_test_SOURCES = test-dynar-getopt-lex.c dynar.c dynar-str.c dynar-getopt-lex.c endif diff --git a/qdevices/qnetd-cluster-list.c b/qdevices/qnetd-cluster-list.c index ea7e57e9..15a5e635 100644 --- a/qdevices/qnetd-cluster-list.c +++ b/qdevices/qnetd-cluster-list.c @@ -1,146 +1,139 @@ /* * Copyright (c) 2015-2016 Red Hat, Inc. * * All rights reserved. * * Author: Jan Friesse (jfriesse@redhat.com) * * This software licensed under BSD license, the text of which follows: * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the Red Hat, Inc. nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "qnetd-cluster-list.h" void qnetd_cluster_list_init(struct qnetd_cluster_list *list) { TAILQ_INIT(list); } struct qnetd_cluster * qnetd_cluster_list_find_by_name(struct qnetd_cluster_list *list, const char *cluster_name, size_t cluster_name_len) { struct qnetd_cluster *cluster; TAILQ_FOREACH(cluster, list, entries) { if (cluster->cluster_name_len == cluster_name_len && memcmp(cluster->cluster_name, cluster_name, cluster_name_len) == 0) { return (cluster); } } return (NULL); } struct qnetd_cluster * qnetd_cluster_list_add_client(struct qnetd_cluster_list *list, struct qnetd_client *client) { struct qnetd_cluster *cluster; cluster = qnetd_cluster_list_find_by_name(list, client->cluster_name, client->cluster_name_len); if (cluster == NULL) { cluster = (struct qnetd_cluster *)malloc(sizeof(*cluster)); if (cluster == NULL) { return (NULL); } - memset(cluster, 0, sizeof(*cluster)); - - cluster->cluster_name = malloc(client->cluster_name_len + 1); - if (cluster->cluster_name == NULL) { + if (qnetd_cluster_init(cluster, client->cluster_name, + client->cluster_name_len) != 0) { free(cluster); return (NULL); } - memset(cluster->cluster_name, 0, client->cluster_name_len + 1); - memcpy(cluster->cluster_name, client->cluster_name, client->cluster_name_len); - - cluster->cluster_name_len = client->cluster_name_len; - TAILQ_INIT(&cluster->client_list); TAILQ_INSERT_TAIL(list, cluster, entries); } TAILQ_INSERT_TAIL(&cluster->client_list, client, cluster_entries); return (cluster); } void qnetd_cluster_list_del_client(struct qnetd_cluster_list *list, struct qnetd_cluster *cluster, struct qnetd_client *client) { TAILQ_REMOVE(&cluster->client_list, client, cluster_entries); if (TAILQ_EMPTY(&cluster->client_list)) { TAILQ_REMOVE(list, cluster, entries); - free(cluster->cluster_name); + qnetd_cluster_destroy(cluster); free(cluster); } } void qnetd_cluster_list_free(struct qnetd_cluster_list *list) { struct qnetd_cluster *cluster; struct qnetd_cluster *cluster_next; cluster = TAILQ_FIRST(list); while (cluster != NULL) { cluster_next = TAILQ_NEXT(cluster, entries); - free(cluster->cluster_name); + qnetd_cluster_destroy(cluster); free(cluster); cluster = cluster_next; } TAILQ_INIT(list); } size_t -qnetd_cluster_list_no_clusters(struct qnetd_cluster_list *list) +qnetd_cluster_list_size(struct qnetd_cluster_list *list) { size_t res; struct qnetd_cluster *cluster; res = 0; TAILQ_FOREACH(cluster, list, entries) { res++; } return (res); } diff --git a/qdevices/qnetd-cluster-list.h b/qdevices/qnetd-cluster-list.h index cfbcdf76..a008a0e7 100644 --- a/qdevices/qnetd-cluster-list.h +++ b/qdevices/qnetd-cluster-list.h @@ -1,79 +1,72 @@ /* * Copyright (c) 2015-2016 Red Hat, Inc. * * All rights reserved. * * Author: Jan Friesse (jfriesse@redhat.com) * * This software licensed under BSD license, the text of which follows: * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the Red Hat, Inc. nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _QNETD_CLUSTER_LIST_H_ #define _QNETD_CLUSTER_LIST_H_ #include #include #include -#include "tlv.h" #include "qnetd-client-list.h" +#include "qnetd-cluster.h" #ifdef __cplusplus extern "C" { #endif -struct qnetd_cluster { - char *cluster_name; - size_t cluster_name_len; - struct qnetd_client_list client_list; - TAILQ_ENTRY(qnetd_cluster) entries; -}; - TAILQ_HEAD(qnetd_cluster_list, qnetd_cluster); extern void qnetd_cluster_list_init(struct qnetd_cluster_list *list); extern struct qnetd_cluster *qnetd_cluster_list_find_by_name( struct qnetd_cluster_list *list, const char *cluster_name, size_t cluster_name_len); extern struct qnetd_cluster *qnetd_cluster_list_add_client( struct qnetd_cluster_list *list, struct qnetd_client *client); extern void qnetd_cluster_list_del_client( struct qnetd_cluster_list *list, struct qnetd_cluster *cluster, struct qnetd_client *client); extern void qnetd_cluster_list_free(struct qnetd_cluster_list *list); -extern size_t qnetd_cluster_list_no_clusters( +extern size_t qnetd_cluster_list_size( struct qnetd_cluster_list *list); #ifdef __cplusplus } #endif #endif /* _QNETD_CLUSTER_LIST_H_ */ diff --git a/qdevices/qnetd-cluster-list.h b/qdevices/qnetd-cluster.c similarity index 60% copy from qdevices/qnetd-cluster-list.h copy to qdevices/qnetd-cluster.c index cfbcdf76..5ac78ed9 100644 --- a/qdevices/qnetd-cluster-list.h +++ b/qdevices/qnetd-cluster.c @@ -1,79 +1,81 @@ /* * Copyright (c) 2015-2016 Red Hat, Inc. * * All rights reserved. * * Author: Jan Friesse (jfriesse@redhat.com) * * This software licensed under BSD license, the text of which follows: * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the Red Hat, Inc. nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _QNETD_CLUSTER_LIST_H_ -#define _QNETD_CLUSTER_LIST_H_ - -#include - -#include #include +#include +#include + +#include "qnetd-cluster.h" -#include "tlv.h" -#include "qnetd-client-list.h" +int +qnetd_cluster_init(struct qnetd_cluster *cluster, const char *cluster_name, size_t cluster_name_len) +{ -#ifdef __cplusplus -extern "C" { -#endif + memset(cluster, 0, sizeof(*cluster)); -struct qnetd_cluster { - char *cluster_name; - size_t cluster_name_len; - struct qnetd_client_list client_list; - TAILQ_ENTRY(qnetd_cluster) entries; -}; + cluster->cluster_name = malloc(cluster_name_len + 1); + if (cluster->cluster_name == NULL) { + return (-1); + } + memset(cluster->cluster_name, 0, cluster_name_len + 1); + memcpy(cluster->cluster_name, cluster_name, cluster_name_len); -TAILQ_HEAD(qnetd_cluster_list, qnetd_cluster); + cluster->cluster_name_len = cluster_name_len; + TAILQ_INIT(&cluster->client_list); -extern void qnetd_cluster_list_init(struct qnetd_cluster_list *list); + return (0); +} -extern struct qnetd_cluster *qnetd_cluster_list_find_by_name( - struct qnetd_cluster_list *list, const char *cluster_name, size_t cluster_name_len); +void +qnetd_cluster_destroy(struct qnetd_cluster *cluster) +{ -extern struct qnetd_cluster *qnetd_cluster_list_add_client( - struct qnetd_cluster_list *list, struct qnetd_client *client); + free(cluster->cluster_name); + cluster->cluster_name = NULL; +} -extern void qnetd_cluster_list_del_client( - struct qnetd_cluster_list *list, struct qnetd_cluster *cluster, struct qnetd_client *client); +size_t +qnetd_cluster_size(struct qnetd_cluster *cluster) +{ + size_t res; + struct qnetd_client *client; -extern void qnetd_cluster_list_free(struct qnetd_cluster_list *list); + res = 0; -extern size_t qnetd_cluster_list_no_clusters( - struct qnetd_cluster_list *list); + TAILQ_FOREACH(client, &cluster->client_list, cluster_entries) { + res++; + } -#ifdef __cplusplus + return (res); } -#endif - -#endif /* _QNETD_CLUSTER_LIST_H_ */ diff --git a/qdevices/qnetd-cluster-list.h b/qdevices/qnetd-cluster.h similarity index 71% copy from qdevices/qnetd-cluster-list.h copy to qdevices/qnetd-cluster.h index cfbcdf76..dcc9502a 100644 --- a/qdevices/qnetd-cluster-list.h +++ b/qdevices/qnetd-cluster.h @@ -1,79 +1,69 @@ /* * Copyright (c) 2015-2016 Red Hat, Inc. * * All rights reserved. * * Author: Jan Friesse (jfriesse@redhat.com) * * This software licensed under BSD license, the text of which follows: * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the Red Hat, Inc. nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _QNETD_CLUSTER_LIST_H_ -#define _QNETD_CLUSTER_LIST_H_ +#ifndef _QNETD_CLUSTER_H_ +#define _QNETD_CLUSTER_H_ #include #include #include #include "tlv.h" #include "qnetd-client-list.h" #ifdef __cplusplus extern "C" { #endif struct qnetd_cluster { char *cluster_name; size_t cluster_name_len; + void *algorithm_data; struct qnetd_client_list client_list; TAILQ_ENTRY(qnetd_cluster) entries; }; -TAILQ_HEAD(qnetd_cluster_list, qnetd_cluster); +extern int qnetd_cluster_init(struct qnetd_cluster *cluster, + const char *cluster_name, size_t cluster_name_len); -extern void qnetd_cluster_list_init(struct qnetd_cluster_list *list); +extern void qnetd_cluster_destroy(struct qnetd_cluster *cluster); -extern struct qnetd_cluster *qnetd_cluster_list_find_by_name( - struct qnetd_cluster_list *list, const char *cluster_name, size_t cluster_name_len); - -extern struct qnetd_cluster *qnetd_cluster_list_add_client( - struct qnetd_cluster_list *list, struct qnetd_client *client); - -extern void qnetd_cluster_list_del_client( - struct qnetd_cluster_list *list, struct qnetd_cluster *cluster, struct qnetd_client *client); - -extern void qnetd_cluster_list_free(struct qnetd_cluster_list *list); - -extern size_t qnetd_cluster_list_no_clusters( - struct qnetd_cluster_list *list); +extern size_t qnetd_cluster_size(struct qnetd_cluster *cluster); #ifdef __cplusplus } #endif -#endif /* _QNETD_CLUSTER_LIST_H_ */ +#endif /* _QNETD_CLUSTER_H_ */ diff --git a/qdevices/qnetd-ipc-cmd.c b/qdevices/qnetd-ipc-cmd.c index 7054e1aa..630f9a25 100644 --- a/qdevices/qnetd-ipc-cmd.c +++ b/qdevices/qnetd-ipc-cmd.c @@ -1,288 +1,288 @@ /* * Copyright (c) 2015-2016 Red Hat, Inc. * * All rights reserved. * * Author: Jan Friesse (jfriesse@redhat.com) * * This software licensed under BSD license, the text of which follows: * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the Red Hat, Inc. nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #include "dynar-str.h" #include "qnetd-ipc-cmd.h" #include "qnetd-log.h" #include "utils.h" int qnetd_ipc_cmd_status(struct qnetd_instance *instance, struct dynar *outbuf, int verbose) { if (dynar_str_catf(outbuf, "QNetd address:\t\t\t%s:%"PRIu16"\n", (instance->host_addr != NULL ? instance->host_addr : "*"), instance->host_port) == -1) { return (-1); } if (dynar_str_catf(outbuf, "TLS:\t\t\t\t%s%s\n", tlv_tls_supported_to_str(instance->tls_supported), ((instance->tls_supported != TLV_TLS_UNSUPPORTED && instance->tls_client_cert_required) ? " (client certificate required)" : "")) == -1) { return (-1); } if (dynar_str_catf(outbuf, "Connected clients:\t\t%zu\n", qnetd_client_list_no_clients(&instance->clients)) == -1) { return (-1); } if (dynar_str_catf(outbuf, "Connected clusters:\t\t%zu\n", - qnetd_cluster_list_no_clusters(&instance->clusters)) == -1) { + qnetd_cluster_list_size(&instance->clusters)) == -1) { return (-1); } if (!verbose) { return (0); } if (instance->max_clients != 0) { if (dynar_str_catf(outbuf, "Maximum allowed clients:\t%zu\n", instance->max_clients) == -1) { return (-1); } } if (dynar_str_catf(outbuf, "Maximum send/receive size:\t%zu/%zu bytes\n", instance->advanced_settings->max_client_send_size, instance->advanced_settings->max_client_receive_size) == -1) { return (-1); } return (0); } static int qnetd_ipc_cmd_add_tie_breaker(const struct qnetd_client *client, struct dynar *outbuf) { if (dynar_str_catf(outbuf, " Tie-breaker:\t") == -1) { return (0); } switch (client->tie_breaker.mode) { case TLV_TIE_BREAKER_MODE_LOWEST: if (dynar_str_catf(outbuf, "Node with lowest node ID") == -1) { return (0); } break; case TLV_TIE_BREAKER_MODE_HIGHEST: if (dynar_str_catf(outbuf, "Node with highest node ID") == -1) { return (0); } break; case TLV_TIE_BREAKER_MODE_NODE_ID: if (dynar_str_catf(outbuf, "Node with node ID "UTILS_PRI_NODE_ID, client->tie_breaker.node_id) == -1) { return (0); } break; } return (dynar_str_catf(outbuf, "\n") != -1); } static int qnetd_ipc_cmd_list_add_node_list(struct dynar *outbuf, int verbose, const struct node_list *nlist) { struct node_list_entry *node_info; int i; i = 0; TAILQ_FOREACH(node_info, nlist, entries) { if (i != 0) { if (dynar_str_catf(outbuf, ", ") == -1) { return (-1); } } if (dynar_str_catf(outbuf, UTILS_PRI_NODE_ID, node_info->node_id) == -1) { return (-1); } if (node_info->data_center_id != 0) { if (dynar_str_catf(outbuf, " (" UTILS_PRI_DATACENTER_ID ")", node_info->data_center_id) == -1) { return (-1); } } i++; } return (0); } static int qnetd_ipc_cmd_list_add_client_info(const struct qnetd_client *client, struct dynar *outbuf, int verbose, size_t client_no) { if (dynar_str_catf(outbuf, " Node ID "UTILS_PRI_NODE_ID":\n", client->node_id) == -1) { return (-1); } if (dynar_str_catf(outbuf, " Client address:\t\t%s\n", client->addr_str) == -1) { return (-1); } if (verbose) { if (dynar_str_catf(outbuf, " HB interval:\t\t%"PRIu32"ms\n", client->heartbeat_interval) == -1) { return (-1); } } if (client->config_version_set) { if (dynar_str_catf(outbuf, " Configuration version:\t" UTILS_PRI_CONFIG_VERSION"\n", client->config_version) == -1) { return (-1); } } if (!node_list_is_empty(&client->configuration_node_list)) { if ((dynar_str_catf(outbuf, " Configured node list:\t") == -1) || (qnetd_ipc_cmd_list_add_node_list(outbuf, verbose, &client->configuration_node_list) == -1) || (dynar_str_catf(outbuf, "\n") == -1)) { return (-1); } } if (verbose) { if (dynar_str_catf(outbuf, " Ring ID:\t\t"UTILS_PRI_RING_ID"\n", client->last_ring_id.node_id, client->last_ring_id.seq) == -1) { return (-1); } } if (!node_list_is_empty(&client->last_membership_node_list)) { if ((dynar_str_catf(outbuf, " Membership node list:\t") == -1) || (qnetd_ipc_cmd_list_add_node_list(outbuf, verbose, &client->last_membership_node_list) == -1) || (dynar_str_catf(outbuf, "\n") == -1)) { return (-1); } } if (verbose) { if (dynar_str_catf(outbuf, " TLS active:\t\t%s", (client->tls_started ? "Yes" : "No")) == -1) { return (-1); } if (client->tls_started && client->tls_peer_certificate_verified) { if (dynar_str_catf(outbuf, " (client certificate verified)") == -1) { return (-1); } } if (dynar_str_catf(outbuf, "\n") == -1) { return (-1); } } if (client->last_sent_vote != TLV_VOTE_UNDEFINED) { if (dynar_str_catf(outbuf, " Vote:\t\t\t%s", tlv_vote_to_str(client->last_sent_vote)) == -1) { return (-1); } if (client->last_sent_ack_nack_vote != TLV_VOTE_UNDEFINED) { if (dynar_str_catf(outbuf, " (%s)", tlv_vote_to_str(client->last_sent_ack_nack_vote)) == -1) { return (-1); } } if (dynar_str_catf(outbuf, "\n") == -1) { return (-1); } } return (0); } int qnetd_ipc_cmd_list(struct qnetd_instance *instance, struct dynar *outbuf, int verbose, const char *cluster_name) { struct qnetd_cluster *cluster; struct qnetd_client *client; size_t cluster_no, client_no; cluster_no = 0; TAILQ_FOREACH(cluster, &instance->clusters, entries) { if (cluster_name != NULL && strcmp(cluster_name, "") != 0 && strcmp(cluster_name, cluster->cluster_name) != 0) { continue ; } if (dynar_str_catf(outbuf, "Cluster \"%s\":\n", cluster->cluster_name) == -1) { return (-1); } client_no = 0; TAILQ_FOREACH(client, &cluster->client_list, cluster_entries) { if (client_no == 0) { if (dynar_str_catf(outbuf, " Algorithm:\t\t%s\n", tlv_decision_algorithm_type_to_str( client->decision_algorithm)) == -1) { return (-1); } if (!qnetd_ipc_cmd_add_tie_breaker(client, outbuf)) { return (-1); } } if (qnetd_ipc_cmd_list_add_client_info(client, outbuf, verbose, client_no) == -1) { return (-1); } client_no++; } cluster_no++; } return (0); }