Просмотр исходного кода

Qnetd: Split cluster-list

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Jan Friesse 9 лет назад
Родитель
Сommit
65d0f5eff3

+ 4 - 2
qdevices/Makefile.am

@@ -51,6 +51,7 @@ corosync_qnetd_SOURCES	= corosync-qnetd.c \
                           qnetd-algo-test.c qnetd-algo-test.h qnetd-algorithm.c qnetd-algorithm.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-utils.c qnetd-algo-utils.h \
                           qnetd-algo-ffsplit.c qnetd-algo-ffsplit.h \
                           qnetd-algo-ffsplit.c qnetd-algo-ffsplit.h \
+                          qnetd-cluster.c qnetd-cluster.h \
                           qnetd-cluster-list.c qnetd-cluster-list.h \
                           qnetd-cluster-list.c qnetd-cluster-list.h \
                           qnetd-client-send.c qnetd-client-send.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 \
                           qnetd-algo-2nodelms.c qnetd-algo-2nodelms.h qnetd-algo-lms.c qnetd-algo-lms.h \
@@ -133,8 +134,9 @@ check_PROGRAMS			= qnetd-cluster-list.test dynar.test dynar-simple-lex.test \
                                   dynar-getopt-lex.test
                                   dynar-getopt-lex.test
 
 
 qnetd_cluster_list_test_SOURCES	= qnetd-cluster-list.c test-qnetd-cluster-list.c \
 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_CFLAGS  = $(nss_CFLAGS)
 qnetd_cluster_list_test_LDADD	= $(nss_LIBS)
 qnetd_cluster_list_test_LDADD	= $(nss_LIBS)
 
 

+ 5 - 12
qdevices/qnetd-cluster-list.c

@@ -74,19 +74,12 @@ qnetd_cluster_list_add_client(struct qnetd_cluster_list *list, struct qnetd_clie
 			return (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);
 			free(cluster);
 
 
 			return (NULL);
 			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(list, cluster, entries);
 	}
 	}
@@ -106,7 +99,7 @@ qnetd_cluster_list_del_client(struct qnetd_cluster_list *list, struct qnetd_clus
 	if (TAILQ_EMPTY(&cluster->client_list)) {
 	if (TAILQ_EMPTY(&cluster->client_list)) {
 		TAILQ_REMOVE(list, cluster, entries);
 		TAILQ_REMOVE(list, cluster, entries);
 
 
-		free(cluster->cluster_name);
+		qnetd_cluster_destroy(cluster);
 		free(cluster);
 		free(cluster);
 	}
 	}
 }
 }
@@ -121,7 +114,7 @@ qnetd_cluster_list_free(struct qnetd_cluster_list *list)
 	while (cluster != NULL) {
 	while (cluster != NULL) {
 		cluster_next = TAILQ_NEXT(cluster, entries);
 		cluster_next = TAILQ_NEXT(cluster, entries);
 
 
-		free(cluster->cluster_name);
+		qnetd_cluster_destroy(cluster);
 		free(cluster);
 		free(cluster);
 
 
 		cluster = cluster_next;
 		cluster = cluster_next;
@@ -131,7 +124,7 @@ qnetd_cluster_list_free(struct qnetd_cluster_list *list)
 }
 }
 
 
 size_t
 size_t
-qnetd_cluster_list_no_clusters(struct qnetd_cluster_list *list)
+qnetd_cluster_list_size(struct qnetd_cluster_list *list)
 {
 {
 	size_t res;
 	size_t res;
 	struct qnetd_cluster *cluster;
 	struct qnetd_cluster *cluster;

+ 2 - 9
qdevices/qnetd-cluster-list.h

@@ -40,20 +40,13 @@
 #include <sys/queue.h>
 #include <sys/queue.h>
 #include <inttypes.h>
 #include <inttypes.h>
 
 
-#include "tlv.h"
 #include "qnetd-client-list.h"
 #include "qnetd-client-list.h"
+#include "qnetd-cluster.h"
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
 #endif
 #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);
 TAILQ_HEAD(qnetd_cluster_list, qnetd_cluster);
 
 
 extern void				 qnetd_cluster_list_init(struct qnetd_cluster_list *list);
 extern void				 qnetd_cluster_list_init(struct qnetd_cluster_list *list);
@@ -69,7 +62,7 @@ extern void				 qnetd_cluster_list_del_client(
 
 
 extern void				 qnetd_cluster_list_free(struct qnetd_cluster_list *list);
 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);
     struct qnetd_cluster_list *list);
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus

+ 81 - 0
qdevices/qnetd-cluster.c

@@ -0,0 +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.
+ */
+
+#include <inttypes.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "qnetd-cluster.h"
+
+int
+qnetd_cluster_init(struct qnetd_cluster *cluster, const char *cluster_name, size_t cluster_name_len)
+{
+
+	memset(cluster, 0, sizeof(*cluster));
+
+	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);
+
+	cluster->cluster_name_len = cluster_name_len;
+	TAILQ_INIT(&cluster->client_list);
+
+	return (0);
+}
+
+void
+qnetd_cluster_destroy(struct qnetd_cluster *cluster)
+{
+
+	free(cluster->cluster_name);
+	cluster->cluster_name = NULL;
+}
+
+size_t
+qnetd_cluster_size(struct qnetd_cluster *cluster)
+{
+	size_t res;
+	struct qnetd_client *client;
+
+	res = 0;
+
+	TAILQ_FOREACH(client, &cluster->client_list, cluster_entries) {
+		res++;
+	}
+
+	return (res);
+}

+ 69 - 0
qdevices/qnetd-cluster.h

@@ -0,0 +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_H_
+#define _QNETD_CLUSTER_H_
+
+#include <sys/types.h>
+
+#include <sys/queue.h>
+#include <inttypes.h>
+
+#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;
+};
+
+extern int		qnetd_cluster_init(struct qnetd_cluster *cluster,
+    const char *cluster_name, size_t cluster_name_len);
+
+extern void		qnetd_cluster_destroy(struct qnetd_cluster *cluster);
+
+extern size_t		qnetd_cluster_size(struct qnetd_cluster *cluster);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _QNETD_CLUSTER_H_ */

+ 1 - 1
qdevices/qnetd-ipc-cmd.c

@@ -59,7 +59,7 @@ qnetd_ipc_cmd_status(struct qnetd_instance *instance, struct dynar *outbuf, int
 	}
 	}
 
 
 	if (dynar_str_catf(outbuf, "Connected clusters:\t\t%zu\n",
 	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);
 		return (-1);
 	}
 	}