]> git.proxmox.com Git - mirror_corosync.git/commitdiff
Add cpg_local_get api to cpg service
authorSteven Dake <sdake@redhat.com>
Mon, 25 Jun 2007 03:04:35 +0000 (03:04 +0000)
committerSteven Dake <sdake@redhat.com>
Mon, 25 Jun 2007 03:04:35 +0000 (03:04 +0000)
git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1391 fd59a12c-fef9-0310-b244-a6a79926bd2f

exec/cpg.c
include/cpg.h
include/ipc_cpg.h
lib/cpg.c
man/Makefile
man/cpg_local_get.3 [new file with mode: 0644]
man/index.html
test/Makefile
test/testcpg.c

index f7f0fbf730d10d2eaf9dd09cf19ec9acf6d5e5f6..8733ab11dfcb4b6e1df1e8518804f30e928db416 100644 (file)
@@ -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));
+}
index 9176c748ad236e86c872fdd9296820efadb307fa..c2c40b6af3ca76d1020f58efafcccf3affc5ef36 100644 (file)
@@ -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);
index cc3609db8ccefd08eadcc2786a1a4e06bec2d388..16b87a0c1ac9931c319b7571bd08ddefb3b52ab2 100644 (file)
@@ -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)));
index 66c462e04f443d8430e28207872640e49a665715..fecc86470f034c777b2bfd730cf7743f81127318 100644 (file)
--- 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)
index 845f003993790e4b2a1041584cc4ae4a1846a9c3..22c1e1a154ba4cf53f5ff8d922a7e0e9dfc3e595 100644 (file)
@@ -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 (file)
index 0000000..2be3d65
--- /dev/null
@@ -0,0 +1,64 @@
+.\"/*
+.\" * Copyright (c) 2007 Red Hat, Inc.
+.\" *
+.\" * All rights reserved.
+.\" *
+.\" * Author: Steven Dake <sdake@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.
+.\" */
+.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 <openais/cpg.h>
+.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
index 8f8b9158e334840c68c914f804a799080e9cd09c..a7a930b9dcefcd1de3a09ea93b73beb683bf0de7 100644 (file)
@@ -51,5 +51,7 @@ Welcome to the openais project's manual pages.
 <A HREF="cpg_mcast_joined.html">cpg_mcast_joined(3)</A>: Description of the cpg_mcast_joined interface.
 <BR>
 <A HREF="cpg_membership_get.html">cpg_membership_get(3)</A>: Description of the cpg_membership_get interface.
+<BR>
+<A HREF="cpg_local_get.html">cpg_local_get(3)</A>: Description of the cpg_local_get interface.
 
 </body>
index 91af90e091a7224778789825af39bf156c4cfcb3..b26b2129ffe2ee43612855437a7c70230189e08b 100644 (file)
@@ -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)
 
index 5d2746ad097b105bc59628d5aebe288d6fa57218..46ad04974068efbde9c1f5490fcada5e6c307cf4 100644 (file)
@@ -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<joined_list_entries; i++) {
                if (show_ip) {
                        saddr.s_addr = joined_list[i].nodeid;
@@ -156,6 +158,7 @@ int main (int argc, char *argv[]) {
        int result;
        const char *options = "i";
        int opt;
+       unsigned int nodeid;
 
        while ( (opt = getopt(argc, argv, options)) != -1 ) {
                switch (opt) {
@@ -179,6 +182,13 @@ int main (int argc, char *argv[]) {
                printf ("Could not initialize Cluster Process Group API instance error %d\n", result);
                exit (1);
        }
+       result = cpg_local_get (handle, &nodeid);
+       if (result != SA_AIS_OK) {
+               printf ("Could not get local node id\n");
+               exit (1);
+       }
+
+       printf ("Local node id is %x\n", nodeid);
        result = cpg_join(handle, &group_name);
        if (result != SA_AIS_OK) {
                printf ("Could not join process group, error %d\n", result);