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

Add cpg_local_get api to cpg service

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1391 fd59a12c-fef9-0310-b244-a6a79926bd2f
Steven Dake 18 лет назад
Родитель
Сommit
39b3f0d5a6
9 измененных файлов с 163 добавлено и 5 удалено
  1. 21 0
      exec/cpg.c
  2. 4 0
      include/cpg.h
  3. 13 2
      include/ipc_cpg.h
  4. 42 0
      lib/cpg.c
  5. 1 0
      man/Makefile
  6. 64 0
      man/cpg_local_get.3
  7. 2 0
      man/index.html
  8. 4 1
      test/Makefile
  9. 12 2
      test/testcpg.c

+ 21 - 0
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_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_node_joinleave_send (struct group_info *gi, struct process_info *pi, int fn, int reason);
 
 
 static int cpg_exec_send_joinlist(void);
 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_size				= sizeof (struct res_lib_cpg_trackstart),
 		.response_id				= MESSAGE_RES_CPG_TRACKSTOP,
 		.response_id				= MESSAGE_RES_CPG_TRACKSTOP,
 		.flow_control				= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
 		.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;
 	res_lib_cpg_trackstop.header.error = SA_AIS_OK;
 	openais_conn_send_response(conn, &res_lib_cpg_trackstop.header, sizeof(res_lib_cpg_trackstop));
 	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));
+}

+ 4 - 0
include/cpg.h

@@ -199,6 +199,10 @@ cpg_error_t cpg_membership_get (
 	struct cpg_address *member_list,
 	struct cpg_address *member_list,
 	int *member_list_entries);
 	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_error_t cpg_flow_control_state_get (
 	cpg_handle_t handle,
 	cpg_handle_t handle,
 	cpg_flow_control_state_t *flow_control_enabled);
 	cpg_flow_control_state_t *flow_control_enabled);

+ 13 - 2
include/ipc_cpg.h

@@ -45,7 +45,8 @@ enum req_cpg_types {
 	MESSAGE_REQ_CPG_MCAST = 2,
 	MESSAGE_REQ_CPG_MCAST = 2,
 	MESSAGE_REQ_CPG_MEMBERSHIP = 3,
 	MESSAGE_REQ_CPG_MEMBERSHIP = 3,
 	MESSAGE_REQ_CPG_TRACKSTART = 4,
 	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 {
 enum res_cpg_types {
@@ -57,7 +58,8 @@ enum res_cpg_types {
 	MESSAGE_RES_CPG_DELIVER_CALLBACK = 5,
 	MESSAGE_RES_CPG_DELIVER_CALLBACK = 5,
 	MESSAGE_RES_CPG_TRACKSTART = 6,
 	MESSAGE_RES_CPG_TRACKSTART = 6,
 	MESSAGE_RES_CPG_TRACKSTOP = 7,
 	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 {
 enum lib_cpg_confchg_reason {
@@ -98,6 +100,15 @@ struct res_lib_cpg_trackstop {
 	mar_res_header_t header __attribute__((aligned(8)));
 	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 {
 struct req_lib_cpg_mcast {
 	mar_res_header_t header __attribute__((aligned(8)));
 	mar_res_header_t header __attribute__((aligned(8)));
 	mar_uint32_t guarantee __attribute__((aligned(8)));
 	mar_uint32_t guarantee __attribute__((aligned(8)));

+ 42 - 0
lib/cpg.c

@@ -644,6 +644,48 @@ error_exit:
 	return (error);
 	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_error_t cpg_flow_control_state_get (
 	cpg_handle_t handle,
 	cpg_handle_t handle,
 	cpg_flow_control_state_t *flow_control_state)
 	cpg_flow_control_state_t *flow_control_state)

+ 1 - 0
man/Makefile

@@ -57,6 +57,7 @@ html:
 	groff -mandoc -Thtml cpg_membership_get.3 > html/cpg_membership_get.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_get.3 > html/cpg_context_get.html
 	groff -mandoc -Thtml cpg_context_set.3 > html/cpg_context_set.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
 	cp index.html html
 
 

+ 64 - 0
man/cpg_local_get.3

@@ -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

+ 2 - 0
man/index.html

@@ -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.
 <A HREF="cpg_mcast_joined.html">cpg_mcast_joined(3)</A>: Description of the cpg_mcast_joined interface.
 <BR>
 <BR>
 <A HREF="cpg_membership_get.html">cpg_membership_get(3)</A>: Description of the cpg_membership_get interface.
 <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>
 </body>

+ 4 - 1
test/Makefile

@@ -56,7 +56,7 @@ all: testclm testamf1 \
 	testckpt ckptstress ckptbench \
 	testckpt ckptstress ckptbench \
 	ckptbenchth ckpt-rd ckpt-wr testevt testevs \
 	ckptbenchth ckpt-rd ckpt-wr testevt testevs \
 	evsbench subscription publish evtbench unlink testclm2 testlck \
 	evsbench subscription publish evtbench unlink testclm2 testlck \
-	testmsg testcpg cpgbench openais-cfgtool
+	testmsg testcpg testcpg2 cpgbench openais-cfgtool
 
 
 testtimer: testtimer.o $(LIBRARIES)
 testtimer: testtimer.o $(LIBRARIES)
 	$(CC) $(LDFLAGS) -o testtimer testtimer.o ../exec/timer.o
 	$(CC) $(LDFLAGS) -o testtimer testtimer.o ../exec/timer.o
@@ -145,6 +145,9 @@ testmsg: testmsg.o $(LIBRARIES)
 testcpg: testcpg.o $(LIBRARIES)
 testcpg: testcpg.o $(LIBRARIES)
 	$(CC) $(LDFLAGS) -o testcpg testcpg.o $(LIBS)
 	$(CC) $(LDFLAGS) -o testcpg testcpg.o $(LIBS)
 
 
+testcpg2: testcpg2.o $(LIBRARIES)
+	$(CC) $(LDFLAGS) -o testcpg2 testcpg2.o $(LIBS)
+
 cpgbench: cpgbench.o $(LIBRARIES)
 cpgbench: cpgbench.o $(LIBRARIES)
 	$(CC) $(LDFLAGS) -o cpgbench cpgbench.o $(LIBS)
 	$(CC) $(LDFLAGS) -o cpgbench cpgbench.o $(LIBS)
 
 

+ 12 - 2
test/testcpg.c

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2006 Red Hat Inc
+ * Copyright (c) 2006-2007 Red Hat Inc
  *
  *
  * All rights reserved.
  * All rights reserved.
  *
  *
@@ -89,7 +89,9 @@ void ConfchgCallback (
 	int i;
 	int i;
 	struct in_addr saddr;
 	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++) {
 	for (i=0; i<joined_list_entries; i++) {
 		if (show_ip) {
 		if (show_ip) {
 			saddr.s_addr = joined_list[i].nodeid;
 			saddr.s_addr = joined_list[i].nodeid;
@@ -156,6 +158,7 @@ int main (int argc, char *argv[]) {
 	int result;
 	int result;
 	const char *options = "i";
 	const char *options = "i";
 	int opt;
 	int opt;
+	unsigned int nodeid;
 
 
 	while ( (opt = getopt(argc, argv, options)) != -1 ) {
 	while ( (opt = getopt(argc, argv, options)) != -1 ) {
 		switch (opt) {
 		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);
 		printf ("Could not initialize Cluster Process Group API instance error %d\n", result);
 		exit (1);
 		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);
 	result = cpg_join(handle, &group_name);
 	if (result != SA_AIS_OK) {
 	if (result != SA_AIS_OK) {
 		printf ("Could not join process group, error %d\n", result);
 		printf ("Could not join process group, error %d\n", result);