From: Steven Dake Date: Mon, 25 Jun 2007 03:04:35 +0000 (+0000) Subject: Add cpg_local_get api to cpg service X-Git-Tag: v1.3.0~1198 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=39b3f0d5a6b5d63be9228486e46fd9581c0cf900;p=mirror_corosync.git Add cpg_local_get api to cpg service git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1391 fd59a12c-fef9-0310-b244-a6a79926bd2f --- diff --git a/exec/cpg.c b/exec/cpg.c index f7f0fbf7..8733ab11 100644 --- a/exec/cpg.c +++ b/exec/cpg.c @@ -174,6 +174,8 @@ static void message_handler_req_lib_cpg_trackstart (void *conn, void *message); static void message_handler_req_lib_cpg_trackstop (void *conn, void *message); +static void message_handler_req_lib_cpg_local_get (void *conn, void *message); + static int cpg_node_joinleave_send (struct group_info *gi, struct process_info *pi, int fn, int reason); static int cpg_exec_send_joinlist(void); @@ -222,6 +224,12 @@ static struct openais_lib_handler cpg_lib_service[] = .response_size = sizeof (struct res_lib_cpg_trackstart), .response_id = MESSAGE_RES_CPG_TRACKSTOP, .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED + }, + { /* 6 */ + .lib_handler_fn = message_handler_req_lib_cpg_local_get, + .response_size = sizeof (struct res_lib_cpg_local_get), + .response_id = MESSAGE_RES_CPG_LOCAL_GET, + .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED } }; @@ -1194,3 +1202,16 @@ tstop_ret: res_lib_cpg_trackstop.header.error = SA_AIS_OK; openais_conn_send_response(conn, &res_lib_cpg_trackstop.header, sizeof(res_lib_cpg_trackstop)); } + +static void message_handler_req_lib_cpg_local_get (void *conn, void *message) +{ + struct res_lib_cpg_local_get res_lib_cpg_local_get; + + res_lib_cpg_local_get.header.size = sizeof(res_lib_cpg_local_get); + res_lib_cpg_local_get.header.id = MESSAGE_RES_CPG_LOCAL_GET; + res_lib_cpg_local_get.header.error = SA_AIS_OK; + res_lib_cpg_local_get.local_nodeid = totempg_my_nodeid_get (); + + openais_conn_send_response(conn, &res_lib_cpg_local_get, + sizeof(res_lib_cpg_local_get)); +} diff --git a/include/cpg.h b/include/cpg.h index 9176c748..c2c40b6a 100644 --- a/include/cpg.h +++ b/include/cpg.h @@ -199,6 +199,10 @@ cpg_error_t cpg_membership_get ( struct cpg_address *member_list, int *member_list_entries); +cpg_error_t cpg_local_get ( + cpg_handle_t handle, + unsigned int *local_nodeid); + cpg_error_t cpg_flow_control_state_get ( cpg_handle_t handle, cpg_flow_control_state_t *flow_control_enabled); diff --git a/include/ipc_cpg.h b/include/ipc_cpg.h index cc3609db..16b87a0c 100644 --- a/include/ipc_cpg.h +++ b/include/ipc_cpg.h @@ -45,7 +45,8 @@ enum req_cpg_types { MESSAGE_REQ_CPG_MCAST = 2, MESSAGE_REQ_CPG_MEMBERSHIP = 3, MESSAGE_REQ_CPG_TRACKSTART = 4, - MESSAGE_REQ_CPG_TRACKSTOP = 5 + MESSAGE_REQ_CPG_TRACKSTOP = 5, + MESSAGE_REQ_CPG_LOCAL_GET = 6 }; enum res_cpg_types { @@ -57,7 +58,8 @@ enum res_cpg_types { MESSAGE_RES_CPG_DELIVER_CALLBACK = 5, MESSAGE_RES_CPG_TRACKSTART = 6, MESSAGE_RES_CPG_TRACKSTOP = 7, - MESSAGE_RES_CPG_FLOW_CONTROL_STATE_SET = 8 + MESSAGE_RES_CPG_FLOW_CONTROL_STATE_SET = 8, + MESSAGE_RES_CPG_LOCAL_GET = 9 }; enum lib_cpg_confchg_reason { @@ -98,6 +100,15 @@ struct res_lib_cpg_trackstop { mar_res_header_t header __attribute__((aligned(8))); }; +struct req_lib_cpg_local_get { + mar_req_header_t header __attribute__((aligned(8))); +}; + +struct res_lib_cpg_local_get { + mar_res_header_t header __attribute__((aligned(8))); + mar_uint32_t local_nodeid __attribute__((aligned(8))); +}; + struct req_lib_cpg_mcast { mar_res_header_t header __attribute__((aligned(8))); mar_uint32_t guarantee __attribute__((aligned(8))); diff --git a/lib/cpg.c b/lib/cpg.c index 66c462e0..fecc8647 100644 --- a/lib/cpg.c +++ b/lib/cpg.c @@ -644,6 +644,48 @@ error_exit: return (error); } +cpg_error_t cpg_local_get ( + cpg_handle_t handle, + unsigned int *local_nodeid) +{ + cpg_error_t error; + struct cpg_inst *cpg_inst; + struct iovec iov; + struct req_lib_cpg_local_get req_lib_cpg_local_get; + struct res_lib_cpg_local_get res_lib_cpg_local_get; + + error = saHandleInstanceGet (&cpg_handle_t_db, handle, (void *)&cpg_inst); + if (error != SA_AIS_OK) { + return (error); + } + + req_lib_cpg_local_get.header.size = sizeof (mar_req_header_t); + req_lib_cpg_local_get.header.id = MESSAGE_REQ_CPG_LOCAL_GET; + + iov.iov_base = &req_lib_cpg_local_get; + iov.iov_len = sizeof (struct req_lib_cpg_local_get); + + pthread_mutex_lock (&cpg_inst->response_mutex); + + error = saSendMsgReceiveReply (cpg_inst->response_fd, &iov, 1, + &res_lib_cpg_local_get, sizeof (res_lib_cpg_local_get)); + + pthread_mutex_unlock (&cpg_inst->response_mutex); + + if (error != SA_AIS_OK) { + goto error_exit; + } + + error = res_lib_cpg_local_get.header.error; + + *local_nodeid = res_lib_cpg_local_get.local_nodeid; + +error_exit: + saHandleInstancePut (&cpg_handle_t_db, handle); + + return (error); +} + cpg_error_t cpg_flow_control_state_get ( cpg_handle_t handle, cpg_flow_control_state_t *flow_control_state) diff --git a/man/Makefile b/man/Makefile index 845f0039..22c1e1a1 100644 --- a/man/Makefile +++ b/man/Makefile @@ -57,6 +57,7 @@ html: groff -mandoc -Thtml cpg_membership_get.3 > html/cpg_membership_get.html groff -mandoc -Thtml cpg_context_get.3 > html/cpg_context_get.html groff -mandoc -Thtml cpg_context_set.3 > html/cpg_context_set.html + groff -mandoc -Thtml cpg_local_get.3 > html/cpg_local_get.html cp index.html html diff --git a/man/cpg_local_get.3 b/man/cpg_local_get.3 new file mode 100644 index 00000000..2be3d658 --- /dev/null +++ b/man/cpg_local_get.3 @@ -0,0 +1,64 @@ +.\"/* +.\" * Copyright (c) 2007 Red Hat, Inc. +.\" * +.\" * All rights reserved. +.\" * +.\" * Author: Steven Dake +.\" * +.\" * 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 CPG_LOCAL_GET 3 2007-06-12 "openais Man Page" "Openais Programmer's Manual" +.SH NAME +cpg_local_get \- Returns the local processor id +.SH SYNOPSIS +.B #include +.sp +.BI "int cpg_local_get(cpg_handle_t " handle ", unsigned int *" local_nodeid "); +.SH DESCRIPTION +The +.B cpg_local_get +function is used to determine the local processor's identifier. +.BR +The argument +.I handle +is used to reference the cpg instantiation. +The argument +.I local_nodeid +will return the 32 bit node id. +.PP +.SH ERRORS +The errors are undocumented. +.SH "SEE ALSO" +.BR cpg_overview (8), +.BR cpg_initialize (3), +.BR cpg_finalize (3), +.BR cpg_fd_get (3), +.BR cpg_dispatch (3), +.BR cpg_leave (3), +.BR cpg_mcast_joined (3), +.BR cpg_membership_get (3) +.PP diff --git a/man/index.html b/man/index.html index 8f8b9158..a7a930b9 100644 --- a/man/index.html +++ b/man/index.html @@ -51,5 +51,7 @@ Welcome to the openais project's manual pages. cpg_mcast_joined(3): Description of the cpg_mcast_joined interface.
cpg_membership_get(3): Description of the cpg_membership_get interface. +
+cpg_local_get(3): Description of the cpg_local_get interface. diff --git a/test/Makefile b/test/Makefile index 91af90e0..b26b2129 100644 --- a/test/Makefile +++ b/test/Makefile @@ -56,7 +56,7 @@ all: testclm testamf1 \ testckpt ckptstress ckptbench \ ckptbenchth ckpt-rd ckpt-wr testevt testevs \ evsbench subscription publish evtbench unlink testclm2 testlck \ - testmsg testcpg cpgbench openais-cfgtool + testmsg testcpg testcpg2 cpgbench openais-cfgtool testtimer: testtimer.o $(LIBRARIES) $(CC) $(LDFLAGS) -o testtimer testtimer.o ../exec/timer.o @@ -145,6 +145,9 @@ testmsg: testmsg.o $(LIBRARIES) testcpg: testcpg.o $(LIBRARIES) $(CC) $(LDFLAGS) -o testcpg testcpg.o $(LIBS) +testcpg2: testcpg2.o $(LIBRARIES) + $(CC) $(LDFLAGS) -o testcpg2 testcpg2.o $(LIBS) + cpgbench: cpgbench.o $(LIBRARIES) $(CC) $(LDFLAGS) -o cpgbench cpgbench.o $(LIBS) diff --git a/test/testcpg.c b/test/testcpg.c index 5d2746ad..46ad0497 100644 --- a/test/testcpg.c +++ b/test/testcpg.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006 Red Hat Inc + * Copyright (c) 2006-2007 Red Hat Inc * * All rights reserved. * @@ -89,7 +89,9 @@ void ConfchgCallback ( int i; struct in_addr saddr; - printf("\nConfchgCallback: group '"); print_cpgname(groupName); printf("'\n"); + printf("\nConfchgCallback: group '"); + print_cpgname(groupName); + printf("'\n"); for (i=0; i