From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24550 invoked by alias); 11 Feb 2009 21:44:39 -0000 Received: (qmail 24543 invoked by alias); 11 Feb 2009 21:44:39 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS X-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS X-Spam-Check-By: sourceware.org X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bastion.fedora.phx.redhat.com Subject: fence: master - fence_tool: replace cman with votequorum To: cluster-cvs-relay@redhat.com X-Project: Cluster Project X-Git-Module: fence.git X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 27ef61602c6de5d04ddecc008af7be57c2763609 X-Git-Newrev: 7cc4bcfa3a5803cf247ccc8ebe3b4b2bc01ffdaa From: David Teigland Message-Id: <20090211214417.0C76812019A@lists.fedorahosted.org> Date: Wed, 11 Feb 2009 21:44:00 -0000 X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 Mailing-List: contact cluster-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cluster-cvs-owner@sourceware.org X-SW-Source: 2009-q1/txt/msg00438.txt.bz2 Gitweb: http://git.fedorahosted.org/git/fence.git?p=fence.git;a=commitdiff;h=7cc4bcfa3a5803cf247ccc8ebe3b4b2bc01ffdaa Commit: 7cc4bcfa3a5803cf247ccc8ebe3b4b2bc01ffdaa Parent: 27ef61602c6de5d04ddecc008af7be57c2763609 Author: David Teigland AuthorDate: Wed Feb 11 15:42:06 2009 -0600 Committer: David Teigland CommitterDate: Wed Feb 11 15:42:06 2009 -0600 fence_tool: replace cman with votequorum libcman calls have been replaced with libvotequorum Signed-off-by: David Teigland --- fence/fence_tool/Makefile | 8 ++- fence/fence_tool/fence_tool.c | 115 ++++++++++++++++++++++++----------------- 2 files changed, 72 insertions(+), 51 deletions(-) diff --git a/fence/fence_tool/Makefile b/fence/fence_tool/Makefile index 51413fc..0410e58 100644 --- a/fence/fence_tool/Makefile +++ b/fence/fence_tool/Makefile @@ -13,11 +13,13 @@ include $(OBJDIR)/make/uninstall.mk OBJS=fence_tool.o CFLAGS += -D_FILE_OFFSET_BITS=64 -CFLAGS += -I${ccsincdir} -I${cmanincdir} +CFLAGS += -I${corosyncincdir} +CFLAGS += -I${ccsincdir} CFLAGS += -I$(S)/../libfenced -I$(S)/../include -CFLAGS += -I${incdir} +CFLAGS += -I${incdir} -LDFLAGS += -L${ccslibdir} -L${cmanlibdir} -lccs -lcman +LDFLAGS += -L${corosynclibdir} -lvotequorum +LDFLAGS += -L${ccslibdir} -lccs LDFLAGS += -L../libfenced -lfenced LDFLAGS += -L${libdir} diff --git a/fence/fence_tool/fence_tool.c b/fence/fence_tool/fence_tool.c index f5a857e..436db02 100644 --- a/fence/fence_tool/fence_tool.c +++ b/fence/fence_tool/fence_tool.c @@ -18,8 +18,9 @@ #include "ccs.h" #include "copyright.cf" -#include "libcman.h" #include "libfenced.h" +#include +#include #define OP_JOIN 1 #define OP_LEAVE 2 @@ -32,8 +33,8 @@ int all_nodeids[MAX_NODES]; int all_nodeids_count; -cman_node_t cman_nodes[MAX_NODES]; -int cman_nodes_count; +static votequorum_node_t quorum_nodes[MAX_NODES]; +static int quorum_node_count; struct fenced_node nodes[MAX_NODES]; char *prog_name; int operation; @@ -223,25 +224,50 @@ static void read_ccs_nodeids(int cd) } } -static int all_nodeids_are_members(cman_handle_t ch) +static void quorum_callback(votequorum_handle_t h, uint64_t context, + uint32_t quorate, uint32_t node_list_entries, + votequorum_node_t node_list[]) { - int i, j, rv, found; + int i; - memset(&cman_nodes, 0, sizeof(cman_nodes)); - cman_nodes_count = 0; + for (i = 0; i < node_list_entries; i++) { + if (node_list[i].state == NODESTATE_MEMBER) { + memcpy(&quorum_nodes[quorum_node_count], + &node_list[i], sizeof(votequorum_node_t)); + quorum_node_count++; + } + } +} - rv = cman_get_nodes(ch, MAX_NODES, &cman_nodes_count, cman_nodes); - if (rv < 0) { - printf("cman_get_nodes error %d %d\n", rv, errno); - return 0; +static int all_nodeids_are_members(votequorum_handle_t qh) +{ + cs_error_t err; + int i, j, found; + + memset(&quorum_nodes, 0, sizeof(quorum_nodes)); + quorum_node_count = 0; + + err = votequorum_trackstart(qh, 0, CS_TRACK_CURRENT); + if (err != CS_OK) { + printf("votequorum_trackstart error %d %d\n", err, errno); + return -1; + } + + err = votequorum_dispatch(qh, CS_DISPATCH_ONE); + if (err != CS_OK) { + printf("votequorum_dispatch error %d %d\n", err, errno); + votequorum_trackstop(qh); + return -1; } + votequorum_trackstop(qh); + for (i = 0; i < all_nodeids_count; i++) { found = 0; - for (j = 0; j < cman_nodes_count; j++) { - if (cman_nodes[j].cn_nodeid == all_nodeids[i] && - cman_nodes[j].cn_member) { + for (j = 0; j < quorum_node_count; j++) { + if (quorum_nodes[j].nodeid == all_nodeids[i] && + quorum_nodes[j].state == NODESTATE_MEMBER) { found = 1; break; } @@ -253,68 +279,59 @@ static int all_nodeids_are_members(cman_handle_t ch) return 1; } -static void wait_cman(void) +static votequorum_callbacks_t quorum_callbacks = +{ + .votequorum_notify_fn = quorum_callback, +}; + +static void wait_quorum(void) { - cman_handle_t ch; - int try_init = 0, try_active = 0, try_quorate = 0; + votequorum_handle_t qh; + struct votequorum_info qinfo; + cs_error_t err; + int try_init = 0, try_quorate = 0; int try_ccs = 0, try_members = 0; int rv, cd; while (1) { - ch = cman_init(NULL); - if (ch) + err = votequorum_initialize(&qh, &quorum_callbacks); + if (err == CS_OK) break; if (inquorate_fail) goto fail; if (try_init++ >= wait_timeout) { - printf("%s: timed out waiting for cman init\n", + printf("%s: timed out waiting for quorum init\n", prog_name); goto fail; } if (!(try_init % 10)) - printf("%s: waiting for cman to start\n", prog_name); + printf("%s: waiting for quorum init\n", prog_name); sleep(1); } while (1) { - rv = cman_is_active(ch); - if (rv) - break; - - if (inquorate_fail) - goto fail; - - if (try_active++ >= wait_timeout) { - printf("%s: timed out waiting for cman active\n", - prog_name); + err = votequorum_getinfo(qh, 0, &qinfo); + if (err != CS_OK) goto fail; - } - - if (!(try_active % 10)) - printf("%s: waiting for cman active\n", prog_name); - sleep(1); - } - while (1) { - rv = cman_is_quorate(ch); - if (rv) + if (qinfo.quorum) break; if (inquorate_fail) goto fail; if (try_quorate++ >= wait_timeout) { - printf("%s: timed out waiting for cman quorum\n", + printf("%s: timed out waiting for quorum\n", prog_name); goto fail; } if (!(try_quorate % 10)) - printf("%s: waiting for cman quorum\n", prog_name); + printf("%s: waiting for quorum\n", prog_name); sleep(1); } @@ -341,8 +358,10 @@ static void wait_cman(void) read_ccs_nodeids(cd); while (1) { - rv = all_nodeids_are_members(ch); - if (rv) + rv = all_nodeids_are_members(qh); + if (rv < 0) + goto fail; + if (rv > 0) break; if (try_members++ >= wait_members) @@ -356,12 +375,12 @@ static void wait_cman(void) out: ccs_disconnect(cd); - cman_finish(ch); + votequorum_finalize(qh); return; fail: - if (ch) - cman_finish(ch); + if (qh) + votequorum_finalize(qh); exit(EXIT_FAILURE); } @@ -369,7 +388,7 @@ static void do_join(int argc, char *argv[]) { int rv; - wait_cman(); + wait_quorum(); rv = fenced_join(); if (rv < 0)