[PATCH 17/25] votequorum: drop votequorum_qdevice_getinfo and collapse data into getinfo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Fabio M. Di Nitto" <fdinitto@xxxxxxxxxx>

it's really pointless to have basically a duplicated API call
to transfer one value and one name.

Signed-off-by: Fabio M. Di Nitto <fdinitto@xxxxxxxxxx>
---
:100644 100644 ab8ebae... b3c6b52... M	exec/votequorum.c
:100644 100644 e148149... 9bb15a9... M	include/corosync/ipc_votequorum.h
:100644 100644 ba8b30c... 0cbc456... M	include/corosync/votequorum.h
:100644 100644 2af705a... 7a37030... M	lib/libvotequorum.versions
:100644 100644 e36d114... d046663... M	lib/votequorum.c
:100644 100644 4c4e349... 1694f34... M	man/votequorum_getinfo.3.in
:100644 000000 9d6eeeb... 0000000... D	man/votequorum_qdevice_getinfo.3.in
:100644 100644 a66e25b... 2257a74... M	test/testvotequorum2.c
:100644 100644 1d2417b... 40c1d25... M	tools/corosync-quorumtool.c
 exec/votequorum.c                   |   57 +++-----------------------
 include/corosync/ipc_votequorum.h   |   19 +-------
 include/corosync/votequorum.h       |   17 +-------
 lib/libvotequorum.versions          |    1 -
 lib/votequorum.c                    |   51 +----------------------
 man/votequorum_getinfo.3.in         |    2 +
 man/votequorum_qdevice_getinfo.3.in |   75 -----------------------------------
 test/testvotequorum2.c              |   18 +++++---
 tools/corosync-quorumtool.c         |   46 ++++++++++++----------
 9 files changed, 52 insertions(+), 234 deletions(-)

diff --git a/exec/votequorum.c b/exec/votequorum.c
index ab8ebae..b3c6b52 100644
--- a/exec/votequorum.c
+++ b/exec/votequorum.c
@@ -319,9 +319,6 @@ static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
 static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
 							     const void *message);
 
-static void message_handler_req_lib_votequorum_qdevice_getinfo (void *conn,
-								const void *message);
-
 static struct corosync_lib_handler quorum_lib_service[] =
 {
 	{ /* 0 */
@@ -359,10 +356,6 @@ static struct corosync_lib_handler quorum_lib_service[] =
 	{ /* 8 */
 		.lib_handler_fn		= message_handler_req_lib_votequorum_qdevice_poll,
 		.flow_control		= COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
-	},
-	{ /* 9 */
-		.lib_handler_fn		= message_handler_req_lib_votequorum_qdevice_getinfo,
-		.flow_control		= COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
 	}
 };
 
@@ -2044,8 +2037,14 @@ static void message_handler_req_lib_votequorum_getinfo (void *conn, const void *
 		if (allow_downscale) {
 			res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_ALLOW_DOWNSCALE;
 		}
+
+		memset(res_lib_votequorum_getinfo.qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
+		res_lib_votequorum_getinfo.qdevice_votes = 0;
+
 		if (node->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
 			res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_REGISTERED;
+			res_lib_votequorum_getinfo.qdevice_votes = qdevice->votes;
+			strcpy(res_lib_votequorum_getinfo.qdevice_name, qdevice_name);
 		}
 		if (node->flags & NODE_FLAGS_QDEVICE_ALIVE) {
 			res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_ALIVE;
@@ -2392,47 +2391,3 @@ out:
 
 	LEAVE();
 }
-
-static void message_handler_req_lib_votequorum_qdevice_getinfo (void *conn,
-								const void *message)
-{
-	const struct req_lib_votequorum_qdevice_getinfo *req_lib_votequorum_qdevice_getinfo = message;
-	struct res_lib_votequorum_qdevice_getinfo res_lib_votequorum_qdevice_getinfo;
-	cs_error_t error = CS_OK;
-	struct cluster_node *node;
-	uint32_t nodeid = req_lib_votequorum_qdevice_getinfo->nodeid;
-
-	ENTER();
-
-	if (nodeid == NODEID_QDEVICE) {
-		nodeid = us->node_id;
-	}
-
-	node = find_node_by_nodeid(nodeid);
-	if ((node) &&
-	    (node->flags & NODE_FLAGS_QDEVICE_REGISTERED)) {
-		int alive_status = 0, vote_status = 0;
-
-		if (node->flags & NODE_FLAGS_QDEVICE_ALIVE) {
-			alive_status = 1;
-		}
-		if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
-			vote_status = 1;
-		}
-		log_printf(LOGSYS_LEVEL_DEBUG, "got qdevice_getinfo node %u alive_status %d vote_status %d",
-						nodeid, alive_status, vote_status);
-		res_lib_votequorum_qdevice_getinfo.votes = qdevice->votes;
-		res_lib_votequorum_qdevice_getinfo.alive = alive_status;
-		res_lib_votequorum_qdevice_getinfo.cast_vote = vote_status;
-		strcpy(res_lib_votequorum_qdevice_getinfo.name, qdevice_name);
-	} else {
-		error = CS_ERR_NOT_EXIST;
-	}
-
-	res_lib_votequorum_qdevice_getinfo.header.size = sizeof(res_lib_votequorum_qdevice_getinfo);
-	res_lib_votequorum_qdevice_getinfo.header.id = MESSAGE_RES_VOTEQUORUM_GETINFO;
-	res_lib_votequorum_qdevice_getinfo.header.error = error;
-	corosync_api->ipc_response_send(conn, &res_lib_votequorum_qdevice_getinfo, sizeof(res_lib_votequorum_qdevice_getinfo));
-
-	LEAVE();
-}
diff --git a/include/corosync/ipc_votequorum.h b/include/corosync/ipc_votequorum.h
index e148149..9bb15a9 100644
--- a/include/corosync/ipc_votequorum.h
+++ b/include/corosync/ipc_votequorum.h
@@ -47,14 +47,12 @@ enum req_votequorum_types {
 	MESSAGE_REQ_VOTEQUORUM_QDEVICE_REGISTER,
 	MESSAGE_REQ_VOTEQUORUM_QDEVICE_UNREGISTER,
 	MESSAGE_REQ_VOTEQUORUM_QDEVICE_UPDATE,
-	MESSAGE_REQ_VOTEQUORUM_QDEVICE_POLL,
-	MESSAGE_REQ_VOTEQUORUM_QDEVICE_GETINFO
+	MESSAGE_REQ_VOTEQUORUM_QDEVICE_POLL
 };
 
 enum res_votequorum_types {
 	MESSAGE_RES_VOTEQUORUM_STATUS = 0,
 	MESSAGE_RES_VOTEQUORUM_GETINFO,
-	MESSAGE_RES_VOTEQUORUM_QDEVICE_GETINFO,
 	MESSAGE_RES_VOTEQUORUM_TRACKSTART,
 	MESSAGE_RES_VOTEQUORUM_NOTIFICATION,
 	MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION
@@ -82,11 +80,6 @@ struct req_lib_votequorum_qdevice_poll {
 	int cast_vote;
 };
 
-struct req_lib_votequorum_qdevice_getinfo {
-	struct qb_ipc_request_header header __attribute__((aligned(8)));
-	int nodeid;
-};
-
 struct req_lib_votequorum_setvotes {
 	struct qb_ipc_request_header header __attribute__((aligned(8)));
 	unsigned int votes;
@@ -141,14 +134,8 @@ struct res_lib_votequorum_getinfo {
 	unsigned int total_votes;
 	unsigned int quorum;
 	unsigned int flags;
-};
-
-struct res_lib_votequorum_qdevice_getinfo {
-	struct qb_ipc_response_header header __attribute__((aligned(8)));
-	unsigned int votes;
-	unsigned int alive;
-	unsigned int cast_vote;
-	char name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
+	unsigned int qdevice_votes;
+	char qdevice_name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
 };
 
 struct votequorum_node {
diff --git a/include/corosync/votequorum.h b/include/corosync/votequorum.h
index ba8b30c..0cbc456 100644
--- a/include/corosync/votequorum.h
+++ b/include/corosync/votequorum.h
@@ -70,13 +70,8 @@ struct votequorum_info {
 	unsigned int total_votes;
 	unsigned int quorum;
 	unsigned int flags;
-};
-
-struct votequorum_qdevice_info {
-	unsigned int votes;
-	unsigned int alive;
-	unsigned int cast_vote;
-	char name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
+	unsigned int qdevice_votes;
+	char qdevice_name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
 };
 
 typedef struct {
@@ -210,14 +205,6 @@ cs_error_t votequorum_qdevice_poll (
 	const char *name,
 	unsigned int cast_vote);
 
-/**
- * Get quorum device information
- */
-cs_error_t votequorum_qdevice_getinfo (
-	votequorum_handle_t handle,
-	unsigned int nodeid,
-	struct votequorum_qdevice_info *info);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/libvotequorum.versions b/lib/libvotequorum.versions
index 2af705a..7a37030 100644
--- a/lib/libvotequorum.versions
+++ b/lib/libvotequorum.versions
@@ -10,7 +10,6 @@ COROSYNC_VOTEQUORUM_1.0 {
 		votequorum_qdevice_register;
 		votequorum_qdevice_unregister;
 		votequorum_qdevice_poll;
-		votequorum_qdevice_getinfo;
 		votequorum_trackstart;
 		votequorum_trackstop;
 		votequorum_context_get;
diff --git a/lib/votequorum.c b/lib/votequorum.c
index e36d114..d046663 100644
--- a/lib/votequorum.c
+++ b/lib/votequorum.c
@@ -188,6 +188,9 @@ cs_error_t votequorum_getinfo (
 	info->total_votes = res_lib_votequorum_getinfo.total_votes;
 	info->quorum = res_lib_votequorum_getinfo.quorum;
 	info->flags = res_lib_votequorum_getinfo.flags;
+	info->qdevice_votes = res_lib_votequorum_getinfo.qdevice_votes;
+	memset(info->qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
+	strcpy(info->qdevice_name, res_lib_votequorum_getinfo.qdevice_name);
 
 error_exit:
 	hdb_handle_put (&votequorum_handle_t_db, handle);
@@ -687,51 +690,3 @@ error_exit:
 
 	return (error);
 }
-
-cs_error_t votequorum_qdevice_getinfo (
-	votequorum_handle_t handle,
-	unsigned int nodeid,
-	struct votequorum_qdevice_info *qinfo)
-{
-	cs_error_t error;
-	struct votequorum_inst *votequorum_inst;
-	struct iovec iov;
-	struct req_lib_votequorum_qdevice_getinfo req_lib_votequorum_qdevice_getinfo;
-	struct res_lib_votequorum_qdevice_getinfo res_lib_votequorum_qdevice_getinfo;
-
-	error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
-	if (error != CS_OK) {
-		return (error);
-	}
-
-	req_lib_votequorum_qdevice_getinfo.header.size = sizeof (struct req_lib_votequorum_qdevice_getinfo);
-	req_lib_votequorum_qdevice_getinfo.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_GETINFO;
-	req_lib_votequorum_qdevice_getinfo.nodeid = nodeid;
-
-	iov.iov_base = (char *)&req_lib_votequorum_qdevice_getinfo;
-	iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_getinfo);
-
-        error = qb_to_cs_error(qb_ipcc_sendv_recv (
-		votequorum_inst->c,
-		&iov,
-		1,
-                &res_lib_votequorum_qdevice_getinfo,
-		sizeof (struct res_lib_votequorum_qdevice_getinfo), CS_IPC_TIMEOUT_MS));
-
-	if (error != CS_OK) {
-		goto error_exit;
-	}
-
-	error = res_lib_votequorum_qdevice_getinfo.header.error;
-
-	qinfo->votes = res_lib_votequorum_qdevice_getinfo.votes;
-	qinfo->alive = res_lib_votequorum_qdevice_getinfo.alive;
-	qinfo->cast_vote = res_lib_votequorum_qdevice_getinfo.cast_vote;
-	strcpy(qinfo->name, res_lib_votequorum_qdevice_getinfo.name);
-
-
-error_exit:
-	hdb_handle_put (&votequorum_handle_t_db, handle);
-
-	return (error);
-}
diff --git a/man/votequorum_getinfo.3.in b/man/votequorum_getinfo.3.in
index 4c4e349..1694f34 100644
--- a/man/votequorum_getinfo.3.in
+++ b/man/votequorum_getinfo.3.in
@@ -60,6 +60,8 @@ struct votequorum_info {
         unsigned int total_votes;
         unsigned int quorum;
         unsigned int flags;
+        unsigned int qdevice_votes;
+        char qdevice_name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
 };
 
 .fi
diff --git a/man/votequorum_qdevice_getinfo.3.in b/man/votequorum_qdevice_getinfo.3.in
deleted file mode 100644
index 9d6eeeb..0000000
--- a/man/votequorum_qdevice_getinfo.3.in
+++ /dev/null
@@ -1,75 +0,0 @@
-.\"/*
-.\" * Copyright (c) 2009,2012 Red Hat, Inc.
-.\" *
-.\" * All rights reserved.
-.\" *
-.\" * Author: Christine Caulfield <ccaulfie@xxxxxxxxxx>
-.\" *
-.\" * 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.
-.\" */
-.TH VOTEQUORUM_QDEVICE_GETINFO 3 @BUILDDATE@ "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
-.SH NAME
-votequorum_qdevice_getinfo \- Get details of the quorum device
-.SH SYNOPSIS
-.B #include <corosync/votequorum.h>
-.sp
-.BI "int votequorum_qdevice_getinfo(votequorum_handle_t " handle ", struct votequorum_qdevice_info " *info ");"
-.SH DESCRIPTION
-The
-.B votequorum_qdevice_getinfo
-Returns information about the quorum device in the following structure:
-
-.nf
-struct votequorum_qdevice_info {
-        unsigned int votes;
-        unsigned int alive;
-        unsigned int vote;
-        char name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
-};
-.fi
-.SH RETURN VALUE
-This call returns the CS_OK value if successful, otherwise an error is returned.
-.PP
-.SH ERRORS
-@COMMONIPCERRORS@
-.SH "SEE ALSO"
-.BR votequorum_overview (8),
-.BR votequorum_initialize (3),
-.BR votequorum_finalize (3),
-.BR votequorum_getinfo (3),
-.BR votequorum_trackstart (3),
-.BR votequorum_trackstop (3),
-.BR votequorum_fd_get (3),
-.BR votequorum_dispatch (3),
-.BR votequorum_context_set (3),
-.BR votequorum_context_get (3),
-.BR votequorum_setexpected (3),
-.BR votequorum_setvotes (3),
-.BR votequorum_qdevice_register (3),
-.BR votequorum_qdevice_unregister (3),
-.BR votequorum_qdevice_poll (3)
-.PP
diff --git a/test/testvotequorum2.c b/test/testvotequorum2.c
index a66e25b..2257a74 100644
--- a/test/testvotequorum2.c
+++ b/test/testvotequorum2.c
@@ -46,16 +46,20 @@ static votequorum_handle_t handle;
 
 static void print_info(int ok_to_fail)
 {
-	struct votequorum_qdevice_info qinfo;
+	struct votequorum_info info;
 	int err;
 
-	if ( (err=votequorum_qdevice_getinfo(handle, VOTEQUORUM_NODEID_QDEVICE, &qinfo)) != CS_OK)
-		fprintf(stderr, "votequorum_qdevice_getinfo error %d: %s\n", err, ok_to_fail?"OK":"FAILED");
+	if ( (err=votequorum_getinfo(handle, VOTEQUORUM_NODEID_QDEVICE, &info)) != CS_OK)
+		fprintf(stderr, "votequorum_getinfo error %d: %s\n", err, ok_to_fail?"OK":"FAILED");
 	else {
-		printf("qdevice votes  %d\n", qinfo.votes);
-		printf("alive          %d\n", qinfo.alive);
-		printf("cast vote      %d\n", qinfo.cast_vote);
-		printf("name           %s\n", qinfo.name);
+		printf("name           %s\n", info.qdevice_name);
+		printf("qdevice votes  %d\n", info.qdevice_votes);
+		if (info.flags & VOTEQUORUM_INFO_QDEVICE_ALIVE) {
+			printf("alive\n");
+		}
+		if (info.flags & VOTEQUORUM_INFO_QDEVICE_CAST_VOTE) {
+			printf("cast vote\n");
+		}
 		printf("\n");
 	}
 }
diff --git a/tools/corosync-quorumtool.c b/tools/corosync-quorumtool.c
index 1d2417b..40c1d25 100644
--- a/tools/corosync-quorumtool.c
+++ b/tools/corosync-quorumtool.c
@@ -219,18 +219,6 @@ static int set_expected(int expected_votes)
 	return err==CS_OK?0:err;
 }
 
-static int get_votes(uint32_t nodeid)
-{
-	int votes = -1;
-	struct votequorum_info info;
-
-	if (votequorum_getinfo(v_handle, nodeid, &info) == CS_OK) {
-		votes = info.node_votes;
-	}
-
-	return votes;
-}
-
 /*
  * This resolves the first address assigned to a node
  * and returns the name or IP address. Use cfgtool if you need more information.
@@ -310,6 +298,18 @@ static void print_uint32_padded(uint32_t value)
 	print_string_padded(buf);
 }
 
+static int get_votes(uint32_t nodeid)
+{
+	int votes = -1;
+	struct votequorum_info info;
+
+	if (votequorum_getinfo(v_handle, nodeid, &info) == CS_OK) {
+		votes = info.node_votes;
+	}
+
+	return votes;
+}
+
 static void display_nodes_data(uint32_t nodeid, nodeid_format_t nodeid_format, name_format_t name_format)
 {
 	int i;
@@ -342,9 +342,9 @@ static void display_nodes_data(uint32_t nodeid, nodeid_format_t nodeid_format, n
 
 	if ((display_qdevice) && (v_handle)) {
 		int err;
-		struct votequorum_qdevice_info qinfo;
+		struct votequorum_info info;
 
-		err = votequorum_qdevice_getinfo(v_handle, nodeid, &qinfo);
+		err = votequorum_getinfo(v_handle, nodeid, &info);
 		if (err != CS_OK) {
 			fprintf(stderr, "Unable to get quorum device info: %s\n", cs_strerror(err));
 		} else {
@@ -353,10 +353,10 @@ static void display_nodes_data(uint32_t nodeid, nodeid_format_t nodeid_format, n
 			} else {
 				printf("0x%08x ", VOTEQUORUM_NODEID_QDEVICE);
 			}
-			print_uint32_padded(qinfo.votes);
-			printf("%s (%s/%s)\n", qinfo.name,
-			       qinfo.alive?"Alive":"Not alive",
-			       qinfo.cast_vote?"Voting":"Not voting");
+			print_uint32_padded(info.qdevice_votes);
+			printf("%s (%s/%s)\n", info.qdevice_name,
+			       info.flags & VOTEQUORUM_INFO_QDEVICE_ALIVE?"Alive":"Not alive",
+			       info.flags & VOTEQUORUM_INFO_QDEVICE_CAST_VOTE?"Voting":"Not voting");
 		}
 	}
 }
@@ -563,15 +563,19 @@ err_exit:
 static int unregister_qdevice(void)
 {
 	int err;
-	struct votequorum_qdevice_info qinfo;
+	struct votequorum_info info;
 
-	err = votequorum_qdevice_getinfo(v_handle, our_nodeid, &qinfo);
+	err = votequorum_getinfo(v_handle, our_nodeid, &info);
 	if (err != CS_OK) {
 		fprintf(stderr, "Unable to get quorum device info: %s\n", cs_strerror(err));
 		return -1;
 	}
 
-	err = votequorum_qdevice_unregister(v_handle, qinfo.name);
+	if (!(info.flags & VOTEQUORUM_INFO_QDEVICE_REGISTERED)) {
+		return 0;
+	}
+
+	err = votequorum_qdevice_unregister(v_handle, info.qdevice_name);
 	if (err != CS_OK) {
 		fprintf(stderr, "Unable to unregister quorum device: %s\n", cs_strerror(err));
 		return -1;
-- 
1.7.7.6

_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss


[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux