Răsfoiți Sursa

Solaris port for openais

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1175 fd59a12c-fef9-0310-b244-a6a79926bd2f
Steven Dake 19 ani în urmă
părinte
comite
90ccff6bbc
46 a modificat fișierele cu 720 adăugiri și 196 ștergeri
  1. 20 4
      Makefile.inc
  2. 5 1
      exec/Makefile
  3. 6 0
      exec/amfcomp.c
  4. 2 1
      exec/cfg.c
  5. 19 5
      exec/clm.c
  6. 5 3
      exec/cpg.c
  7. 5 5
      exec/evs.c
  8. 11 11
      exec/evt.c
  9. 47 3
      exec/ipc.c
  10. 7 2
      exec/main.c
  11. 11 2
      exec/timer.c
  12. 11 4
      exec/totemconfig.c
  13. 32 6
      exec/totemip.c
  14. 43 14
      exec/totemnet.c
  15. 63 17
      exec/totempg.c
  16. 69 47
      exec/totemsrp.c
  17. 5 5
      exec/vsf_ykd.c
  18. 2 1
      include/evs.h
  19. 5 0
      include/mar_gen.h
  20. 6 0
      include/queue.h
  21. 5 0
      include/saAis.h
  22. 4 0
      lcr/Makefile
  23. 100 3
      lcr/lcr_ifact.c
  24. 12 4
      lcr/uic.c
  25. 7 4
      lcr/uis.c
  26. 2 2
      lib/ckpt.c
  27. 6 5
      lib/cpg.c
  28. 9 8
      lib/evs.c
  29. 8 8
      lib/evt.c
  30. 35 4
      lib/util.c
  31. 5 0
      test/Makefile
  32. 13 0
      test/ckptbench.c
  33. 15 1
      test/ckptbenchth.c
  34. 12 0
      test/evsbench.c
  35. 17 1
      test/evtbench.c
  36. 5 1
      test/publish.c
  37. 35 5
      test/subscription.c
  38. 15 15
      test/testamf1.c
  39. 5 0
      test/testamf2.c
  40. 5 0
      test/testamf3.c
  41. 4 0
      test/testamf4.c
  42. 1 0
      test/testamf6.c
  43. 17 2
      test/testckpt.c
  44. 2 0
      test/testclm.c
  45. 2 1
      test/testevs.c
  46. 5 1
      test/unlink.c

+ 20 - 4
Makefile.inc

@@ -11,8 +11,12 @@ endif
 ifneq "" "$(findstring BSD,$(UNAME))"
 	OPENAIS_COMPAT=BSD
 endif
+ifeq "$(UNAME)" "SunOS"
+	OPENAIS_COMPAT=SOLARIS
+	# CC must be set to gcc compiled to link with gnu-ld 
+endif
 ifndef OPENAIS_COMPAT
-$(error "OPENAIS_COMPAT cannot be detected, it must be manually defined")
+	$(error "OPENAIS_COMPAT cannot be detected, it must be manually defined")
 endif
 
 # BUILD_DYNAMIC can be defined to 1 to build for dynamic loading of service
@@ -25,7 +29,7 @@ endif
 # OPENAIS_BUILD can be defined as RELEASE or DEBUG
 #
 ifndef OPENAIS_BUILD
-	OPENAIS_BUILD=RELEASE
+	OPENAIS_BUILD=DEBUG
 endif
 
 # OPENAIS_PROFILE
@@ -36,10 +40,13 @@ CFLAGS =
 LDFLAGS =
 DYFLAGS =
 
+# Adding the TS_CLASS flag enables not being scheduled RR
+#CFLAGS += -DTS_CLASS
+
 # build CFLAGS, LDFLAGS
 #
 ifeq (${OPENAIS_BUILD}, RELEASE) 
-	CFLAGS += -O3 -Wall
+	CFLAGS += -O3 -Wall -DDEBUG
 # -Wstrict-aliasing=2 TODO sameday fix all of these
 ifndef OPENAIS_PROFILE
 	CFLAGS += -fomit-frame-pointer
@@ -47,8 +54,11 @@ endif
 	LDFLAGS += 
 endif
 ifeq (${OPENAIS_BUILD}, DEBUG) 
-	CFLAGS += -O0 -g -Wall -DDEBUG 
+	CFLAGS += -O0 -g -Wall -DDEBUG
 	LDFLAGS += -g
+	ifeq (${OPENAIS_COMPAT}, SOLARIS)
+		CFLAGS += -Werror
+	endif
 endif
 ifeq (${OPENAIS_BUILD}, COVERAGE)
 	CFLAGS += -O0 -g -ftest-coverage -fprofile-arcs
@@ -77,3 +87,9 @@ ifeq (${OPENAIS_COMPAT}, DARWIN)
 	override CFLAGS += -DOPENAIS_DARWIN
 	override LDFLAGS += -lpthread
 endif
+ifeq (${OPENAIS_COMPAT}, SOLARIS)
+	override CFLAGS += -DOPENAIS_SOLARIS -D_REENTRANT
+	override LDFLAGS += -lpthread
+	# See http://sources.redhat.com/ml/bug-gnu-utils/2000-07/msg00168.html
+	override LDFLAGS += -Wl,--export-dynamic
+endif

+ 5 - 1
exec/Makefile

@@ -1,5 +1,5 @@
 # Copyright (c) 2002-2006 MontaVista Software, Inc.
-
+# Copyright (c) 2006 Sun Microsystems, Inc.
 # 
 # All rights reserved.
 # 
@@ -44,6 +44,10 @@ ifeq (${OPENAIS_COMPAT}, LINUX)
 	override LDFLAGS += -ldl
 endif
 
+ifeq (${OPENAIS_COMPAT}, SOLARIS) 
+	override LDFLAGS += -lnsl -lsocket -lrt
+endif
+
 # Totem objects
 TOTEM_SRC = aispoll.c totemip.c totemnet.c totemrrp.c totemsrp.c totemmrp.c totempg.c crypto.c wthread.c
 TOTEM_OBJS = aispoll.o totemip.o totemnet.o totemrrp.o totemsrp.o totemmrp.o totempg.o crypto.o wthread.o

+ 6 - 0
exec/amfcomp.c

@@ -1438,6 +1438,10 @@ int amf_comp_response_1 (
 			assert (0);
 			break;
 	}
+
+	/* XXX we fall here in case NDEBUG is set */
+	*retval = -1;
+	return 0;
 }
 
 /**
@@ -1714,4 +1718,6 @@ SaAmfReadinessStateT amf_comp_get_saAmfCompReadinessState (
 	}
 
 	assert (0);
+	/* XXX we fall here in case NDEBUG is set */
+	return -1;
 }

+ 2 - 1
exec/cfg.c

@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2005-2006 MontaVista Software, Inc.
  * Copyright (c) 2006 Red Hat, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -333,7 +334,7 @@ static void message_handler_req_lib_cfg_ringreenable (
 		MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
 	message_source_set (&req_exec_cfg_ringreenable.source, conn);
 
-	iovec.iov_base = &req_exec_cfg_ringreenable;
+	iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
 	iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
 
 	assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1,

+ 19 - 5
exec/clm.c

@@ -38,9 +38,10 @@
 #include <sys/un.h>
 #if defined(OPENAIS_LINUX)
 #include <sys/sysinfo.h>
-#endif
-#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
+#elif defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
 #include <sys/sysctl.h>
+#elif defined(OPENAIS_SOLARIS)
+#include <utmpx.h>
 #endif
 #include <sys/ioctl.h>
 #include <netinet/in.h>
@@ -291,13 +292,16 @@ static int clm_exec_init_fn (struct objdb_iface_ver0 *objdb)
 	my_cluster_node.node_id = this_ip->nodeid;
 	my_cluster_node.member = 1;
 	{
+#ifndef NANOSEC
+#define	NANOSEC	1000000000
+#endif
 #if defined(OPENAIS_LINUX)
 		struct sysinfo s_info;
 		time_t current_time;
 		sysinfo (&s_info);
 		current_time = time (NULL);
 		 /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
-		my_cluster_node.boot_timestamp = ((SaTimeT)(current_time - s_info.uptime)) * 1000000000;
+		my_cluster_node.boot_timestamp = ((SaTimeT)(current_time - s_info.uptime)) * NANOSEC;
 #elif defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
 		int mib[2] = { CTL_KERN, KERN_BOOTTIME };
 		struct timeval boot_time;
@@ -306,8 +310,18 @@ static int clm_exec_init_fn (struct objdb_iface_ver0 *objdb)
 		if ( sysctl(mib, 2, &boot_time, &size, NULL, 0) == -1 )
 			boot_time.tv_sec = time (NULL);
 		 /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
-		my_cluster_node.boot_timestamp = ((SaTimeT)boot_time.tv_sec) * 1000000000;
-#else /* defined(CTL_KERN) && defined(KERN_BOOTTIME) */
+		my_cluster_node.boot_timestamp = ((SaTimeT)boot_time.tv_sec) * NANOSEC;
+#elif defined(OPENAIS_SOLARIS)
+		struct utmpx ut, *utp;
+		ut.ut_type = BOOT_TIME;
+		setutxent();
+		if ((utp = getutxid(&ut)) == NULL) {
+			my_cluster_node.boot_timestamp = ((SaTimeT)time(NULL)) * NANOSEC;
+		} else {
+			my_cluster_node.boot_timestamp = ((SaTimeT)utp->ut_xtime) * NANOSEC;
+		}
+		endutxent();
+#else
 	#warning "no bootime support"
 #endif
 	}

+ 5 - 3
exec/cpg.c

@@ -32,6 +32,8 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
+
+#include <alloca.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
@@ -497,7 +499,7 @@ static int cpg_node_joinleave_send (struct group_info *gi, struct process_info *
 	req_exec_cpg_procjoin.header.size = sizeof(req_exec_cpg_procjoin);
 	req_exec_cpg_procjoin.header.id = SERVICE_ID_MAKE(CPG_SERVICE, fn);
 
-	req_exec_cpg_iovec.iov_base = &req_exec_cpg_procjoin;
+	req_exec_cpg_iovec.iov_base = (char *)&req_exec_cpg_procjoin;
 	req_exec_cpg_iovec.iov_len = sizeof(req_exec_cpg_procjoin);
 
 	result = totempg_groups_mcast_joined (openais_group_handle, &req_exec_cpg_iovec, 1, TOTEMPG_AGREED);
@@ -985,9 +987,9 @@ static void message_handler_req_lib_cpg_mcast (void *conn, void *message)
 	memcpy(&req_exec_cpg_mcast.group_name, &gi->group_name,
 		sizeof(mar_cpg_name_t));
 
-	req_exec_cpg_iovec[0].iov_base = &req_exec_cpg_mcast;
+	req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast;
 	req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast);
-	req_exec_cpg_iovec[1].iov_base = &req_lib_cpg_mcast->message;
+	req_exec_cpg_iovec[1].iov_base = (char *)&req_lib_cpg_mcast->message;
 	req_exec_cpg_iovec[1].iov_len = msglen;
 
 	// TODO: guarantee type...

+ 5 - 5
exec/evs.c

@@ -377,11 +377,11 @@ static void message_handler_req_evs_mcast_joined (void *conn, void *msg)
 	req_exec_evs_mcast.msg_len = req_lib_evs_mcast_joined->msg_len;
 	req_exec_evs_mcast.group_entries = evs_pd->group_entries;
 
-	req_exec_evs_mcast_iovec[0].iov_base = &req_exec_evs_mcast;
+	req_exec_evs_mcast_iovec[0].iov_base = (char *)&req_exec_evs_mcast;
 	req_exec_evs_mcast_iovec[0].iov_len = sizeof (req_exec_evs_mcast);
-	req_exec_evs_mcast_iovec[1].iov_base = evs_pd->groups;
+	req_exec_evs_mcast_iovec[1].iov_base = (char *)evs_pd->groups;
 	req_exec_evs_mcast_iovec[1].iov_len = evs_pd->group_entries * sizeof (struct evs_group);
-	req_exec_evs_mcast_iovec[2].iov_base = &req_lib_evs_mcast_joined->msg;
+	req_exec_evs_mcast_iovec[2].iov_base = (char *)&req_lib_evs_mcast_joined->msg;
 	req_exec_evs_mcast_iovec[2].iov_len = req_lib_evs_mcast_joined->msg_len;
 // TODO this doesn't seem to work for some reason	
 	send_ok = totempg_groups_send_ok_joined (openais_group_handle, req_exec_evs_mcast_iovec, 3);
@@ -424,9 +424,9 @@ static void message_handler_req_evs_mcast_groups (void *conn, void *msg)
 		sizeof (struct req_lib_evs_mcast_groups) + 
 		(sizeof (struct evs_group) * req_lib_evs_mcast_groups->group_entries);
 
-	req_exec_evs_mcast_iovec[0].iov_base = &req_exec_evs_mcast;
+	req_exec_evs_mcast_iovec[0].iov_base = (char *)&req_exec_evs_mcast;
 	req_exec_evs_mcast_iovec[0].iov_len = sizeof (req_exec_evs_mcast);
-	req_exec_evs_mcast_iovec[1].iov_base = &req_lib_evs_mcast_groups->groups;
+	req_exec_evs_mcast_iovec[1].iov_base = (char *)&req_lib_evs_mcast_groups->groups;
 	req_exec_evs_mcast_iovec[1].iov_len = sizeof (struct evs_group) * req_lib_evs_mcast_groups->group_entries;
 	req_exec_evs_mcast_iovec[2].iov_base = msg_addr;
 	req_exec_evs_mcast_iovec[2].iov_len = req_lib_evs_mcast_groups->msg_len;

+ 11 - 11
exec/evt.c

@@ -1254,7 +1254,7 @@ static SaAisErrorT evt_open_channel(mar_name_t *cn, SaUint8T flgs)
 	cpkt.chc_op = EVT_OPEN_CHAN_OP;
 	cpkt.u.chc_chan.ocr_name = *cn;
 	cpkt.u.chc_chan.ocr_serial_no = ++open_serial_no;
-	chn_iovec.iov_base = &cpkt;
+	chn_iovec.iov_base = (char *)&cpkt;
 	chn_iovec.iov_len = cpkt.chc_head.size;
 	log_printf(CHAN_OPEN_DEBUG, "evt_open_channel: Send open mcast\n");
 	res = totempg_groups_mcast_joined(openais_group_handle,
@@ -1293,7 +1293,7 @@ static SaAisErrorT evt_close_channel(mar_name_t *cn, uint64_t unlink_id)
 	cpkt.chc_op = EVT_CLOSE_CHAN_OP;
 	cpkt.u.chcu.chcu_name = *cn;
 	cpkt.u.chcu.chcu_unlink_id = unlink_id;
-	chn_iovec.iov_base = &cpkt;
+	chn_iovec.iov_base = (char *)&cpkt;
 	chn_iovec.iov_len = cpkt.chc_head.size;
 	res = totempg_groups_mcast_joined(openais_group_handle,
 			&chn_iovec, 1, TOTEMPG_AGREED);
@@ -1638,7 +1638,7 @@ evt_delivered(struct event_data *evt, struct event_svr_channel_open *eco)
 	log_printf(LOG_LEVEL_DEBUG, "delivered ID %llx to eco %p\n",
 			(unsigned long long)evt->ed_event.led_event_id, eco);
 	if (evt->ed_delivered_count == evt->ed_delivered_next) {
-		struct event_svr_channel_open *ed_delivered_tmp;
+		struct event_svr_channel_open **ed_delivered_tmp;
 
 		ed_delivered_tmp = realloc (evt->ed_delivered,
 			DELIVER_SIZE * sizeof(struct event_svr_channel_open *));
@@ -2488,7 +2488,7 @@ static void lib_evt_unlink_channel(void *conn, void *message)
 	cpkt.chc_op = EVT_UNLINK_CHAN_OP;
 	cpkt.u.chcu.chcu_name = req->iuc_channel_name;
 	cpkt.u.chcu.chcu_unlink_id = ucp->ucp_unlink_id;
-	chn_iovec.iov_base = &cpkt;
+	chn_iovec.iov_base = (char *)&cpkt;
 	chn_iovec.iov_len = cpkt.chc_head.size;
 	if (totempg_groups_mcast_joined(openais_group_handle,
 								&chn_iovec, 1, TOTEMPG_AGREED) == 0) {
@@ -2766,7 +2766,7 @@ static void lib_evt_event_publish(void *conn, void *message)
 	 * The multicasted event will be picked up and delivered
 	 * locally by the local network event receiver.
 	 */
-	pub_iovec.iov_base = req;
+	pub_iovec.iov_base = (char *)req;
 	pub_iovec.iov_len = req->led_head.size;
 	result = totempg_groups_mcast_joined(openais_group_handle, &pub_iovec, 1, TOTEMPG_AGREED);
 	if (result != 0) {
@@ -2825,7 +2825,7 @@ static void lib_evt_event_clear_retentiontime(void *conn, void *message)
 	cpkt.chc_head.size = sizeof(cpkt);
 	cpkt.chc_op = EVT_CLEAR_RET_OP;
 	cpkt.u.chc_event_id = req->iec_event_id;
-	rtn_iovec.iov_base = &cpkt;
+	rtn_iovec.iov_base = (char *)&cpkt;
 	rtn_iovec.iov_len = cpkt.chc_head.size;
 	ret = totempg_groups_mcast_joined(openais_group_handle,
 			&rtn_iovec, 1, TOTEMPG_AGREED);
@@ -4143,7 +4143,7 @@ static int evt_sync_process(void)
 				cpkt.chc_op = EVT_SET_ID_OP;
 				cpkt.u.chc_set_id.chc_nodeid = *add_list;
 				cpkt.u.chc_set_id.chc_last_id = md->mn_last_msg_id;
-				chn_iovec.iov_base = &cpkt;
+				chn_iovec.iov_base = (char *)&cpkt;
 				chn_iovec.iov_len = cpkt.chc_head.size;
 				res = totempg_groups_mcast_joined(openais_group_handle,
 						&chn_iovec, 1, TOTEMPG_AGREED);
@@ -4210,7 +4210,7 @@ static int evt_sync_process(void)
 			cpkt.chc_op = EVT_OPEN_COUNT;
 			cpkt.u.chc_set_opens.chc_chan_name = eci->esc_channel_name;
 			cpkt.u.chc_set_opens.chc_open_count = eci->esc_local_opens;
-			chn_iovec.iov_base = &cpkt;
+			chn_iovec.iov_base = (char *)&cpkt;
 			chn_iovec.iov_len = cpkt.chc_head.size;
 			res = totempg_groups_mcast_joined(openais_group_handle,
 					&chn_iovec, 1, TOTEMPG_AGREED);
@@ -4227,7 +4227,7 @@ static int evt_sync_process(void)
 			SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD);
 		cpkt.chc_head.size = sizeof(cpkt);
 		cpkt.chc_op = EVT_OPEN_COUNT_DONE;
-		chn_iovec.iov_base = &cpkt;
+		chn_iovec.iov_base = (char *)&cpkt;
 		chn_iovec.iov_len = cpkt.chc_head.size;
 		res = totempg_groups_mcast_joined(openais_group_handle,
 				&chn_iovec, 1,TOTEMPG_AGREED);
@@ -4276,7 +4276,7 @@ static int evt_sync_process(void)
 			evt = list_entry(next_retained, struct event_data, ed_retained);
 			evt->ed_event.led_head.id =
 				SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_RECOVERY_EVENTDATA);
-			chn_iovec.iov_base = &evt->ed_event;
+			chn_iovec.iov_base = (char *)&evt->ed_event;
 			chn_iovec.iov_len = evt->ed_event.led_head.size;
 			res = totempg_groups_mcast_joined(openais_group_handle,
 					&chn_iovec, 1, TOTEMPG_AGREED);
@@ -4305,7 +4305,7 @@ static int evt_sync_process(void)
 				SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD);
 		cpkt.chc_head.size = sizeof(cpkt);
 		cpkt.chc_op = EVT_CONF_DONE;
-		chn_iovec.iov_base = &cpkt;
+		chn_iovec.iov_base = (char *)&cpkt;
 		chn_iovec.iov_len = cpkt.chc_head.size;
 		res = totempg_groups_mcast_joined(openais_group_handle,
 				&chn_iovec, 1, TOTEMPG_AGREED);

+ 47 - 3
exec/ipc.c

@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2002-2006 MontaVista Software, Inc.
  * Copyright (c) 2006 Red Hat, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -78,6 +79,10 @@
 
 #include "util.h"
 
+#ifdef OPENAIS_SOLARIS
+#define MSG_NOSIGNAL 0
+#endif
+
 #define SERVER_BACKLOG 5
 
 static unsigned int g_gid_valid = 0;
@@ -405,14 +410,17 @@ static void *prioritized_poll_thread (void *conn)
 	struct conn_info *conn_info = (struct conn_info *)conn;
 	struct pollfd ufd;
 	int fds;
-	struct sched_param sched_param;
 	int res;
 	pthread_mutex_t *rel_mutex;
 	unsigned int service;
 	struct conn_info *cinfo_partner;
 
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
+	struct sched_param sched_param;
+
 	sched_param.sched_priority = 1;
 	res = pthread_setschedparam (conn_info->thread, SCHED_RR, &sched_param);
+#endif
 
 	ufd.fd = conn_info->fd;
 	for (;;) {
@@ -504,7 +512,7 @@ retry_poll:
  */
 #define AIS_SUN_LEN(a) sizeof(*(a))
 
-char *socketname = "libais.socket";
+char socketname[20];
 #else
 #define AIS_SUN_LEN(a) SUN_LEN(a)
 
@@ -529,9 +537,14 @@ static int conn_info_outq_flush (struct conn_info *conn_info) {
 	msg_send.msg_name = 0;
 	msg_send.msg_namelen = 0;
 	msg_send.msg_iovlen = 1;
+#ifndef OPENAIS_SOLARIS
 	msg_send.msg_control = 0;
 	msg_send.msg_controllen = 0;
 	msg_send.msg_flags = 0;
+#else
+	msg_send.msg_accrights = NULL;
+	msg_send.msg_accrightslen = 0;
+#endif
 
 	while (!queue_is_empty (outq)) {
 		queue_item = queue_item_get (outq);
@@ -596,6 +609,8 @@ static void libais_deliver (struct conn_info *conn_info)
 	char cmsg_cred[CMSG_SPACE (sizeof (struct ucred))];
 	struct ucred *cred;
 	int on = 0;
+#elif defined(OPENAIS_SOLARIS)
+	int fd;
 #else
 	uid_t euid;
 	gid_t egid;
@@ -609,15 +624,25 @@ static void libais_deliver (struct conn_info *conn_info)
 	msg_recv.msg_iovlen = 1;
 	msg_recv.msg_name = 0;
 	msg_recv.msg_namelen = 0;
+#ifndef OPENAIS_SOLARIS
 	msg_recv.msg_flags = 0;
+#endif
 
 	if (conn_info->authenticated) {
+#ifndef OPENAIS_SOLARIS
 		msg_recv.msg_control = 0;
 		msg_recv.msg_controllen = 0;
+#else
+		msg_recv.msg_accrights = NULL;
+		msg_recv.msg_accrightslen = 0;
+#endif
 	} else {
 #ifdef OPENAIS_LINUX
 		msg_recv.msg_control = (void *)cmsg_cred;
 		msg_recv.msg_controllen = sizeof (cmsg_cred);
+#elif defined(OPENAIS_SOLARIS)
+		msg_recv.msg_accrights = (char *)&fd;
+		msg_recv.msg_accrightslen = sizeof (fd);
 #else
 		euid = -1; egid = -1;
 		if (getpeereid(conn_info->fd, &euid, &egid) != -1 &&
@@ -643,6 +668,10 @@ retry_recv:
 		return;
 	} else
 	if (res == 0) {
+#ifdef OPENAIS_SOLARIS
+		/* res == 0 means hang up on Solaris */
+		libais_disconnect_request (conn_info);
+#endif
 		return;
 	}
 
@@ -664,6 +693,9 @@ retry_recv:
 			log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated because gid is %d, expecting %d\n", cred->gid, g_gid_valid);
 		}
 	}
+#elif defined(OPENAIS_SOLARIS)
+	/* TODO Fix this. There is no authentication on Solaris yet. */
+	conn_info->authenticated = 1;
 #endif
 	/*
 	 * Dispatch all messages received in recvmsg that can be dispatched
@@ -702,7 +734,7 @@ retry_recv:
 			 * to queue a message, otherwise tell the library we are busy and to
 			 * try again later
 			 */
-			send_ok_joined_iovec.iov_base = header;
+			send_ok_joined_iovec.iov_base = (char *)header;
 			send_ok_joined_iovec.iov_len = header->size;
 			send_ok_joined = totempg_groups_send_ok_joined (openais_group_handle,
 				&send_ok_joined_iovec, 1);
@@ -840,9 +872,16 @@ void openais_ipc_init (
 	int libais_server_fd;
 	struct sockaddr_un un_addr;
 	int res;
+	char *socket_number;
 
 	log_init ("IPC");
 
+	socket_number = getenv ("INTERFACE_NUMBER");
+	if (socket_number) {
+		sprintf (socketname, "libais.socket%s", socket_number);
+	} else {
+		strcpy (socketname, "libais.socket");
+	}
 	ipc_serialize_lock_fn = serialize_lock_fn;
 
 	ipc_serialize_unlock_fn = serialize_unlock_fn;
@@ -953,9 +992,14 @@ int openais_conn_send_response (
 	msg_send.msg_name = 0;
 	msg_send.msg_namelen = 0;
 	msg_send.msg_iovlen = 1;
+#ifndef OPENAIS_SOLARIS
 	msg_send.msg_control = 0;
 	msg_send.msg_controllen = 0;
 	msg_send.msg_flags = 0;
+#else
+	msg_send.msg_accrights = NULL;
+	msg_send.msg_accrightslen = 0;
+#endif
 
 	if (queue_is_full (outq)) {
 		/*

+ 7 - 2
exec/main.c

@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2002-2006 MontaVista Software, Inc.
  * Copyright (c) 2006 Red Hat, Inc..
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -266,7 +267,7 @@ static void aisexec_tty_detach (void)
 
 static void aisexec_setscheduler (void)
 {
-#if defined(OPENAIS_BSD) || defined(OPENAIS_LINUX)
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 	struct sched_param sched_param;
 	int res;
 
@@ -294,7 +295,11 @@ static void aisexec_mlockall (void)
 
 	rlimit.rlim_cur = RLIM_INFINITY;
 	rlimit.rlim_max = RLIM_INFINITY;
+#ifndef OPENAIS_SOLARIS
 	setrlimit (RLIMIT_MEMLOCK, &rlimit);
+#else
+	setrlimit (RLIMIT_VMEM, &rlimit);
+#endif
 
 #if defined(OPENAIS_BSD)
 	/* under FreeBSD a process with locked page cannot call dlopen
@@ -490,7 +495,7 @@ int main (int argc, char **argv)
 	 */
 	aisexec_setscheduler ();
 
-	aisexec_mlockall ();
+//	aisexec_mlockall ();
 
 	totem_config.totem_logging_configuration = totem_logging_configuration;
 	totem_log_service = _log_init ("TOTEM");

+ 11 - 2
exec/timer.c

@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2002-2006 MontaVista Software, Inc.
  * Copyright (c) 2006 Red Hat, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -93,18 +94,23 @@ static void (*timer_serialize_unlock_fn) (void);
 
 static void *prioritized_timer_thread (void *data);
 
+extern void pthread_exit(void *) __attribute__((noreturn));
+
 /*
  * This thread runs at the highest priority to run system wide timers
  */
 static void *prioritized_timer_thread (void *data)
 {
 	int fds;
+	unsigned int timeout;
+
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 	struct sched_param sched_param;
 	int res;
-	unsigned int timeout;
 
 	sched_param.sched_priority = 2;
 	res = pthread_setschedparam (expiry_thread, SCHED_RR, &sched_param);
+#endif
 
 	pthread_mutex_unlock (&timer_mutex);
 	for (;;) {
@@ -126,10 +132,13 @@ retry_poll:
 	}
 
 	pthread_exit (0);
-	return (0);
 }
 
 static void sigusr1_handler (int num) {
+#ifdef OPENAIS_SOLARIS
+	/* Rearm the signal facility */
+        signal (num, sigusr1_handler);
+#endif
 }
 
 int openais_timer_init (

+ 11 - 4
exec/totemconfig.c

@@ -58,12 +58,12 @@
 #endif
 
 #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST	4
-#define TOKEN_TIMEOUT				1000
+#define TOKEN_TIMEOUT				10000
 #define TOKEN_RETRANSMIT_TIMEOUT		(int)(TOKEN_TIMEOUT / (TOKEN_RETRANSMITS_BEFORE_LOSS_CONST + 0.2))
 #define TOKEN_HOLD_TIMEOUT			(int)(TOKEN_RETRANSMIT_TIMEOUT * 0.8 - (1000/(int)HZ))
-#define JOIN_TIMEOUT				100
-#define CONSENSUS_TIMEOUT			200
-#define MERGE_TIMEOUT				200
+#define JOIN_TIMEOUT				300
+#define CONSENSUS_TIMEOUT			30000
+#define MERGE_TIMEOUT				2000
 #define DOWNCHECK_TIMEOUT			1000000
 #define FAIL_TO_RECV_CONST			50
 #define	SEQNO_UNCHANGED_CONST			30
@@ -125,6 +125,7 @@ extern int totem_config_read (
 	unsigned int object_interface_handle;
 	char *str;
 	unsigned int ringnumber = 0;
+	char *ring0;
 
 	memset (totem_config, 0, sizeof (struct totem_config));
 	totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
@@ -238,6 +239,11 @@ extern int totem_config_read (
 			totem_config->interfaces[ringnumber].ip_port = atoi (str);
 		}
 
+		ring0 = getenv ("INTERFACE_RING0");
+		if (ring0) {
+			res = totemip_parse (&totem_config->interfaces[ringnumber].bindnet, ring0,
+					     totem_config->interfaces[ringnumber].mcast_addr.family);
+		} else {
 		/*
 		 * Get the bind net address
 		 */
@@ -246,6 +252,7 @@ extern int totem_config_read (
 			res = totemip_parse (&totem_config->interfaces[ringnumber].bindnet, str,
 					     totem_config->interfaces[ringnumber].mcast_addr.family);
 		}
+		}
 		totem_config->interface_count++;
 	}
 

+ 32 - 6
exec/totemip.c

@@ -42,10 +42,12 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
-#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
+#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) || defined(OPENAIS_SOLARIS)
 #include <sys/sockio.h>
 #include <net/if.h>
+#ifndef OPENAIS_SOLARIS
 #include <net/if_var.h>
+#endif
 #include <netinet/in_var.h>
 #endif
 #include <string.h>
@@ -63,7 +65,7 @@
 #include <linux/rtnetlink.h>
 #endif
 
-#ifndef s6_addr16
+#if ! defined(OPENAIS_SOLARIS) && ! defined(s6_addr16)
 #define s6_addr16 __u6_addr.__u6_addr16
 #endif
 
@@ -116,7 +118,9 @@ void totemip_copy_endian_convert(struct totem_ip_address *addr1, struct totem_ip
 {
 	addr1->nodeid = swab32(addr2->nodeid);
 	addr1->family = swab16(addr2->family);
-	memcpy(addr1->addr, addr2->addr, TOTEMIP_ADDRLEN);
+	if (addr1 != addr2) {
+		memcpy(addr1->addr, addr2->addr, TOTEMIP_ADDRLEN);
+	}
 }
 
 /* For sorting etc. params are void * for qsort's benefit */
@@ -132,8 +136,17 @@ int totemip_compare(const void *a, const void *b)
 		return (addr1->family > addr2->family);
 
 	if (addr1->family == AF_INET) {
+#ifndef __sparc
 		struct in_addr *in1 = (struct in_addr *)addr1->addr;
 		struct in_addr *in2 = (struct in_addr *)addr2->addr;
+#else
+		/* Deal with misalignment */
+		struct in_addr i1, i2;
+		struct in_addr *in1 = &i1;
+		struct in_addr *in2 = &i2;
+		memcpy(in1, addr1->addr, sizeof (*in1));
+		memcpy(in2, addr2->addr, sizeof (*in2));
+#endif
 
 		/* A bit clunky but avoids sign problems */
 		if (in1->s_addr == in2->s_addr)
@@ -151,8 +164,13 @@ int totemip_compare(const void *a, const void *b)
 	/* Remember, addresses are in big-endian format.
 	   We compare 16bits at a time rather than 32 to avoid sign problems */
 	for (i = 0; i < 8; i++) {
+#ifndef OPENAIS_SOLARIS
 		int res = htons(sin6a->s6_addr16[i]) -
 			htons(sin6b->s6_addr16[i]);
+#else
+		int res = htons(((uint16_t *)sin6a->s6_addr)[i]) -
+			htons(((uint16_t *)sin6b->s6_addr)[i]);
+#endif
 		if (res) {
 			return res;
 		}
@@ -164,14 +182,16 @@ int totemip_compare(const void *a, const void *b)
 int totemip_localhost(int family, struct totem_ip_address *localhost)
 {
 	char *addr_text;
+	uint32_t nodeid;
 
 	memset (localhost, 0, sizeof (struct totem_ip_address));
 
 	if (family == AF_INET) {
 		addr_text = LOCALHOST_IPV4;
-		if (inet_pton(family, addr_text, (char *)&localhost->nodeid) <= 0) {
+		if (inet_pton(family, addr_text, (char *)&nodeid) <= 0) {
 			return -1;
 		}
+		localhost->nodeid = ntohl(nodeid);
 	} else {
 		addr_text = LOCALHOST_IPV6;
 	}
@@ -299,14 +319,19 @@ int totemip_sockaddr_to_totemip_convert(struct sockaddr_storage *saddr, struct t
 	return ret;
 }
 
-#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
+#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) || defined(OPENAIS_SOLARIS)
 int totemip_iface_check(struct totem_ip_address *bindnet,
 			struct totem_ip_address *boundto,
 			int *interface_up,
 			int *interface_num)
 {
+#ifndef OPENAIS_SOLARIS
 #define NEXT_IFR(a)	((struct ifreq *)((u_char *)&(a)->ifr_addr +\
 	((a)->ifr_addr.sa_len ? (a)->ifr_addr.sa_len : sizeof((a)->ifr_addr))))
+#else
+#define NEXT_IFR(a)	((struct ifreq *)((u_char *)&(a)->ifr_addr +\
+	sizeof((a)->ifr_addr)))
+#endif
 
 	struct sockaddr_in *intf_addr_mask;
 	struct sockaddr_storage bindnet_ss, intf_addr_ss;
@@ -507,8 +532,9 @@ int totemip_iface_check(struct totem_ip_address *bindnet,
 				parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), len);
 
 				memcpy(ipaddr.addr, RTA_DATA(tb[IFA_ADDRESS]), TOTEMIP_ADDRLEN);
-				if (totemip_equal(&ipaddr, bindnet))
+				if (totemip_equal(&ipaddr, bindnet)) {
 					found_if = 1;
+				}
 
 				/* If the address we have is an IPv4 network address, then
 				   substitute the actual IP address of this interface */

+ 43 - 14
exec/totemnet.c

@@ -68,6 +68,10 @@
 
 #include "crypto.h"
 
+#ifdef OPENAIS_SOLARIS
+#define MSG_NOSIGNAL 0
+#endif
+
 #define MCAST_SOCKET_BUFFER_SIZE (TRANSMITS_ALLOWED * FRAME_SIZE_MAX) 
 
 #define NETIF_STATE_REPORT_UP		1	
@@ -235,7 +239,8 @@ static int authenticate_and_decrypt (
 	struct iovec *iov)
 {
 	unsigned char keys[48];
-	struct security_header *header = iov[0].iov_base;
+	struct security_header *header =
+		(struct security_header *)iov[0].iov_base;
 	prng_state keygen_prng_state;
 	prng_state stream_prng_state;
 	unsigned char *hmac_key = &keys[32];
@@ -269,7 +274,7 @@ static int authenticate_and_decrypt (
 	hmac_init (&instance->totemnet_hmac_state, DIGEST_SHA1, hmac_key, 16);
 
 	hmac_process (&instance->totemnet_hmac_state, 
-		iov->iov_base + HMAC_HASH_SIZE,
+		(unsigned char *)iov->iov_base + HMAC_HASH_SIZE,
 		iov->iov_len - HMAC_HASH_SIZE);
 
 	len = hash_descriptor[DIGEST_SHA1]->hashsize;
@@ -285,12 +290,13 @@ static int authenticate_and_decrypt (
 	/*
 	 * Decrypt the contents of the message with the cipher key
 	 */
-	sober128_read (iov->iov_base + sizeof (struct security_header),
-		iov->iov_len - sizeof (struct security_header),
+	assert(iov->iov_len >= sizeof (struct security_header));
+	sober128_read (
+		(unsigned char *)iov->iov_base + sizeof (struct security_header),
+		(unsigned long)iov->iov_len - sizeof (struct security_header),
 		&stream_prng_state);
 
 	return (res);
-	return (0);
 }
 static void encrypt_and_sign_worker (
 	struct totemnet_instance *instance,
@@ -393,7 +399,7 @@ static inline void ucast_sendmsg (
 
 	if (instance->totem_config->secauth == 1) {
 
-		iovec_encrypt[0].iov_base = sheader;
+		iovec_encrypt[0].iov_base = (char *)sheader;
 		iovec_encrypt[0].iov_len = sizeof (struct security_header);
 		memcpy (&iovec_encrypt[1], &iovec_in[0],
 			sizeof (struct iovec) * iov_len_in);
@@ -409,7 +415,7 @@ static inline void ucast_sendmsg (
 			iov_len_in + 1,
 			&instance->totemnet_prng_state);
 
-		iovec_encrypt[0].iov_base = encrypt_data;
+		iovec_encrypt[0].iov_base = (char *)encrypt_data;
 		iovec_encrypt[0].iov_len = buf_len;
 		iovec_sendmsg = &iovec_encrypt[0];
 		iov_len = 1;
@@ -427,9 +433,14 @@ static inline void ucast_sendmsg (
 	msg_ucast.msg_namelen = addrlen;
 	msg_ucast.msg_iov = iovec_sendmsg;
 	msg_ucast.msg_iovlen = iov_len;
+#ifndef OPENAIS_SOLARIS
 	msg_ucast.msg_control = 0;
 	msg_ucast.msg_controllen = 0;
 	msg_ucast.msg_flags = 0;
+#else
+	msg_ucast.msg_accrights = NULL;
+	msg_ucast.msg_accrightslen = 0;
+#endif
 
 	/*
 	 * Transmit multicast message
@@ -457,7 +468,7 @@ static inline void mcast_sendmsg (
 
 	if (instance->totem_config->secauth == 1) {
 
-		iovec_encrypt[0].iov_base = sheader;
+		iovec_encrypt[0].iov_base = (char *)sheader;
 		iovec_encrypt[0].iov_len = sizeof (struct security_header);
 		memcpy (&iovec_encrypt[1], &iovec_in[0],
 			sizeof (struct iovec) * iov_len_in);
@@ -473,7 +484,7 @@ static inline void mcast_sendmsg (
 			iov_len_in + 1,
 			&instance->totemnet_prng_state);
 
-		iovec_encrypt[0].iov_base = encrypt_data;
+		iovec_encrypt[0].iov_base = (char *)encrypt_data;
 		iovec_encrypt[0].iov_len = buf_len;
 		iovec_sendmsg = &iovec_encrypt[0];
 		iov_len = 1;
@@ -491,9 +502,14 @@ static inline void mcast_sendmsg (
 	msg_mcast.msg_namelen = addrlen;
 	msg_mcast.msg_iov = iovec_sendmsg;
 	msg_mcast.msg_iovlen = iov_len;
+#ifndef OPENAIS_SOLARIS
 	msg_mcast.msg_control = 0;
 	msg_mcast.msg_controllen = 0;
 	msg_mcast.msg_flags = 0;
+#else
+	msg_mcast.msg_accrights = NULL;
+	msg_mcast.msg_accrightslen = 0;
+#endif
 
 	/*
 	 * Transmit multicast message
@@ -535,7 +551,7 @@ static void totemnet_mcast_worker_fn (void *thread_state, void *work_item_in)
 	if (instance->totem_config->secauth == 1) {
 		memmove (&work_item->iovec[1], &work_item->iovec[0],
 			work_item->iov_len * sizeof (struct iovec));
-		work_item->iovec[0].iov_base = sheader;
+		work_item->iovec[0].iov_base = (char *)sheader;
 		work_item->iovec[0].iov_len = sizeof (struct security_header);
 
 		/*
@@ -548,7 +564,7 @@ static void totemnet_mcast_worker_fn (void *thread_state, void *work_item_in)
 			&totemnet_mcast_thread_state->prng_state);
 
 			iovec_sendmsg = &iovec_encrypted;
-			iovec_sendmsg->iov_base = totemnet_mcast_thread_state->iobuf;
+			iovec_sendmsg->iov_base = (char *)totemnet_mcast_thread_state->iobuf;
 			iovec_sendmsg->iov_len = buf_len;
 			iovs = 1;
 	} else {
@@ -563,9 +579,14 @@ static void totemnet_mcast_worker_fn (void *thread_state, void *work_item_in)
 	msg_mcast.msg_namelen = addrlen;
 	msg_mcast.msg_iov = iovec_sendmsg;
 	msg_mcast.msg_iovlen = iovs;
+#ifndef OPENAIS_SOLARIS
 	msg_mcast.msg_control = 0;
 	msg_mcast.msg_controllen = 0;
 	msg_mcast.msg_flags = 0;
+#else
+	msg_mcast.msg_accrights = NULL;
+	msg_mcast.msg_accrightslen = 0;
+#endif
 
 	/*
 	 * Transmit multicast message
@@ -616,7 +637,7 @@ static int net_deliver_fn (
 	struct sockaddr_storage system_from;
 	int bytes_received;
 	int res = 0;
-	unsigned char *msg_offset;
+	char *msg_offset;
 	unsigned int size_delv;
 
 	if (instance->flushing == 1) {
@@ -632,11 +653,17 @@ static int net_deliver_fn (
 	msg_recv.msg_namelen = sizeof (struct sockaddr_storage);
 	msg_recv.msg_iov = iovec;
 	msg_recv.msg_iovlen = 1;
+#ifndef OPENAIS_SOLARIS
 	msg_recv.msg_control = 0;
 	msg_recv.msg_controllen = 0;
 	msg_recv.msg_flags = 0;
+#else
+	msg_recv.msg_accrights = NULL;
+	msg_recv.msg_accrightslen = 0;
+#endif
 
 	bytes_received = recvmsg (fd, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT);
+//log_printf (instance->totemnet_log_level_notice, "bytes received %d\n", bytes_received);
 	if (bytes_received == -1) {
 		return (0);
 	} else {
@@ -1046,6 +1073,7 @@ static int totemnet_build_sockets_ip (
 		break;
 	}
 	
+#ifndef OPENAIS_SOLARIS
 	/*
 	 * Turn on multicast loopback
 	 */
@@ -1053,17 +1081,18 @@ static int totemnet_build_sockets_ip (
 	flag = 1;
 	switch ( bindnet_address->family ) {
 		case AF_INET:
-		res = setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_LOOP,
+		res = setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_MULTICAST_LOOP,
 			&flag, sizeof (flag));
 		break;
 		case AF_INET6:
-		res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
+		res = setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
 			&flag, sizeof (flag));
 	}
 	if (res == -1) {
 		perror ("turn off loopback");
 		return (-1);
 	}
+#endif
 
 	/*
 	 * Set multicast packets TTL

+ 63 - 17
exec/totempg.c

@@ -82,6 +82,7 @@
  *	
  */
 
+#include <alloca.h>
 #include <netinet/in.h>
 #include <sys/uio.h>
 #include <stdio.h>
@@ -177,7 +178,7 @@ DECLARE_LIST_INIT(assembly_list_free);
  * fragment_contuation indicates whether the first packed message in 
  * the buffer is a continuation of a previously packed fragment.
  */
-static unsigned char *fragmentation_data;
+static char *fragmentation_data;
 
 static int fragment_size = 0;
 
@@ -336,14 +337,25 @@ static inline int group_matches (
 	char *group_name;
 	int i;
 	int j;
+#ifdef __sparc
+	struct iovec iovec_aligned = { NULL, 0 };
+#endif
 	
 	assert (iov_len == 1);
 
+#ifdef __sparc
+	if ((size_t)iovec->iov_base % 4 != 0) {
+		iovec_aligned.iov_base = alloca(iovec->iov_len);
+		memcpy(iovec_aligned.iov_base, iovec->iov_base, iovec->iov_len);
+		iovec_aligned.iov_len = iovec->iov_len;
+		iovec = &iovec_aligned;
+	}
+#endif
+
 	group_len = (unsigned short *)iovec->iov_base;
 	group_name = ((char *)iovec->iov_base) +
 		sizeof (unsigned short) * (group_len[0] + 1);
 
-
 	/*
 	 * Calculate amount to adjust the iovec by before delivering to app
 	 */
@@ -377,10 +389,23 @@ static inline void app_deliver_fn (
 	int i;
 	struct totempg_group_instance *instance;
 	struct iovec stripped_iovec;
+#ifdef __sparc
+	struct iovec aligned_iovec = { NULL, 0 };
+#endif
 	unsigned int adjust_iovec;
 	unsigned int res;
 
 	if (endian_conversion_required) {
+#ifdef __sparc
+		if ((size_t)iovec->iov_base % 4 != 0) {
+			/* Deal with misalignment */
+			aligned_iovec.iov_base = alloca(iovec->iov_len);
+			aligned_iovec.iov_len = iovec->iov_len;
+			memcpy(aligned_iovec.iov_base, iovec->iov_base,
+				iovec->iov_len);
+			iovec = &aligned_iovec;
+		}
+#endif
 		group_endian_convert (iovec);
 	}
 	for (i = 0; i <= totempg_max_handle; i++) {
@@ -389,9 +414,28 @@ static inline void app_deliver_fn (
 
 		if (res == 0) {
 			assert (iov_len == 1);
-			if (group_matches (iovec, iov_len, instance->groups, instance->groups_cnt, &adjust_iovec)) {
-				stripped_iovec.iov_len = iovec->iov_len - adjust_iovec;
-				stripped_iovec.iov_base = (char *)iovec->iov_base + adjust_iovec;
+			if (group_matches (iovec, iov_len, instance->groups,
+				instance->groups_cnt, &adjust_iovec)) {
+				stripped_iovec.iov_len =
+					iovec->iov_len - adjust_iovec;
+#ifndef __sparc
+				stripped_iovec.iov_base =
+					(char *)iovec->iov_base + adjust_iovec;
+#else
+				if (iovec->iov_base + adjust_iovec % 4 != 0) {
+					/* Deal with misalignment */
+					/*
+					 * XXX Using alloca() is dangerous,
+					 * since it may be called multiple
+					 * times within the for() loop
+					 */
+					stripped_iovec.iov_base = alloca(
+						stripped_iovec.iov_len);
+					memcpy(stripped_iovec.iov_base,
+						iovec->iov_base + adjust_iovec,
+						stripped_iovec.iov_len);
+				}
+#endif
 				instance->deliver_fn (
 					nodeid,
 					&stripped_iovec,
@@ -458,7 +502,9 @@ static void totempg_deliver_fn (
 		msg_count = mcast->msg_count;
 		datasize = sizeof (struct totempg_mcast) +
 			msg_count * sizeof (unsigned short);
-		
+
+		assert (iovec[0].iov_len >= datasize);
+
 		memcpy (header, iovec[0].iov_base, datasize);
 		assert(iovec);
 		data = iovec[0].iov_base;
@@ -475,7 +521,7 @@ static void totempg_deliver_fn (
 	} else {
 		/* 
 		 * The message originated from local processor  
-		 * becasue there is greater than one iovec for then full msg.
+		 * because there is greater than one iovec for then full msg.
 		 */
 		h_index = 0;
 		for (i = 0; i < 2; i++) {
@@ -505,7 +551,7 @@ static void totempg_deliver_fn (
 	 */
 	msg_count = mcast->fragmented ? mcast->msg_count - 1 : mcast->msg_count;
 	continuation = mcast->continuation;
-	iov_delv.iov_base = &assembly->data[0];
+	iov_delv.iov_base = (char *)&assembly->data[0];
 	iov_delv.iov_len = assembly->index + msg_lens[0];
 
 	/*
@@ -542,7 +588,7 @@ static void totempg_deliver_fn (
 		 */
 		if (!continuation) {
 			assembly->index += msg_lens[0];
-			iov_delv.iov_base = &assembly->data[assembly->index];
+			iov_delv.iov_base = (char *)&assembly->data[assembly->index];
 			iov_delv.iov_len = msg_lens[1];
 			start = 1;
 		}
@@ -553,7 +599,7 @@ static void totempg_deliver_fn (
 		app_deliver_fn(nodeid, &iov_delv, 1,
 			endian_conversion_required);
 		assembly->index += msg_lens[i];
-		iov_delv.iov_base = &assembly->data[assembly->index];
+		iov_delv.iov_base = (char *)&assembly->data[assembly->index];
 		if (i < (msg_count - 1)) {
 			iov_delv.iov_len = msg_lens[i + 1];
 		}
@@ -616,9 +662,9 @@ int callback_token_received_fn (enum totem_callback_token_type type,
 
 	mcast.msg_count = mcast_packed_msg_count;
 
-	iovecs[0].iov_base = &mcast;
+	iovecs[0].iov_base = (char *)&mcast;
 	iovecs[0].iov_len = sizeof (struct totempg_mcast);
-	iovecs[1].iov_base = mcast_packed_msg_lens;
+	iovecs[1].iov_base = (char *)mcast_packed_msg_lens;
 	iovecs[1].iov_len = mcast_packed_msg_count * sizeof (unsigned short);
 	iovecs[2].iov_base = &fragmentation_data[0];
 	iovecs[2].iov_len = fragment_size;
@@ -744,7 +790,7 @@ static int mcast_msg (
 		 * If it just fits or is too big, then send out what fits.
 		 */
 		} else {
-			unsigned char *data_ptr;
+			char *data_ptr;
 
 			copy_len = min(copy_len, max_packet_size - fragment_size);
 			if( copy_len == max_packet_size )
@@ -781,9 +827,9 @@ static int mcast_msg (
 			 * assemble the message and send it
 			 */
 			mcast.msg_count = ++mcast_packed_msg_count;
-			iovecs[0].iov_base = &mcast;
+			iovecs[0].iov_base = (char *)&mcast;
 			iovecs[0].iov_len = sizeof(struct totempg_mcast);
-			iovecs[1].iov_base = mcast_packed_msg_lens;
+			iovecs[1].iov_base = (char *)mcast_packed_msg_lens;
 			iovecs[1].iov_len = mcast_packed_msg_count * 
 				sizeof(unsigned short);
 			iovecs[2].iov_base = data_ptr;
@@ -1020,7 +1066,7 @@ int totempg_groups_mcast_joined (
 		iovec_mcast[i + 1].iov_base = instance->groups[i].group;
 	}
 	iovec_mcast[0].iov_len = (instance->groups_cnt + 1) * sizeof (unsigned short);
-	iovec_mcast[0].iov_base = group_len;
+	iovec_mcast[0].iov_base = (char *)group_len;
 	for (i = 0; i < iov_len; i++) {
 		iovec_mcast[i + instance->groups_cnt + 1].iov_len = iovec[i].iov_len;
 		iovec_mcast[i + instance->groups_cnt + 1].iov_base = iovec[i].iov_base;
@@ -1100,7 +1146,7 @@ int totempg_groups_mcast_groups (
 		iovec_mcast[i + 1].iov_base = groups[i].group;
 	}
 	iovec_mcast[0].iov_len = (groups_cnt + 1) * sizeof (unsigned short);
-	iovec_mcast[0].iov_base = group_len;
+	iovec_mcast[0].iov_base = (char *)group_len;
 	for (i = 0; i < iov_len; i++) {
 		iovec_mcast[i + groups_cnt + 1].iov_len = iovec[i].iov_len;
 		iovec_mcast[i + groups_cnt + 1].iov_base = iovec[i].iov_base;

+ 69 - 47
exec/totemsrp.c

@@ -48,6 +48,7 @@
  *   usage on 1.6ghz xeon from 35% to less then .1 % as measured by top
  */
 
+#include <alloca.h>
 #include <assert.h>
 #include <sys/mman.h>
 #include <sys/types.h>
@@ -88,6 +89,7 @@
 #define RECEIVED_MESSAGE_QUEUE_SIZE_MAX		500 /* allow 500 messages to be queued */
 #define MAXIOVS					5	
 #define RETRANSMIT_ENTRIES_MAX			30
+#define TOKEN_SIZE_MAX				64000 /* bytes */
 
 /*
  * Rollover handling:
@@ -542,7 +544,7 @@ static int message_handler_token_hold_cancel (
 static void memb_ring_id_create_or_load (struct totemsrp_instance *, struct memb_ring_id *);
 
 static void token_callbacks_execute (struct totemsrp_instance *instance, enum totem_callback_token_type type);
-static void memb_state_gather_enter (struct totemsrp_instance *instance);
+static void memb_state_gather_enter (struct totemsrp_instance *instance, unsigned int gather_from);
 static void messages_deliver_to_app (struct totemsrp_instance *instance, int skip, unsigned int end_point);
 static int orf_token_mcast (struct totemsrp_instance *instance, struct orf_token *oken,
 	int fcc_mcasts_allowed);
@@ -615,7 +617,7 @@ void totemsrp_instance_initialize (struct totemsrp_instance *instance)
 
 	instance->my_commit_token_seq = SEQNO_START_TOKEN - 1;
 
-	instance->orf_token_retransmit = malloc (15000);
+	instance->orf_token_retransmit = malloc (TOKEN_SIZE_MAX);
 
 	instance->memb_state = MEMB_STATE_OPERATIONAL;
 
@@ -1335,7 +1337,7 @@ static void memb_state_consensus_timeout_expired (
 
 		memb_set_merge (no_consensus_list, no_consensus_list_entries,
 			instance->my_failed_list, &instance->my_failed_list_entries);
-		memb_state_gather_enter (instance);
+		memb_state_gather_enter (instance, 0);
 	}
 }
 
@@ -1350,26 +1352,32 @@ static void timer_function_orf_token_timeout (void *data)
 {
 	struct totemsrp_instance *instance = (struct totemsrp_instance *)data;
 
-	log_printf (instance->totemsrp_log_level_notice,
-		"The token was lost in state %d from timer %p\n", instance->memb_state, data);
 	switch (instance->memb_state) {
 		case MEMB_STATE_OPERATIONAL:
+			log_printf (instance->totemsrp_log_level_notice,
+				"The token was lost in the OPERATIONAL state.\n");
 			totemrrp_iface_check (instance->totemrrp_handle);
-			memb_state_gather_enter (instance);
+			memb_state_gather_enter (instance, 1);
 			break;
 
 		case MEMB_STATE_GATHER:
+			log_printf (instance->totemsrp_log_level_notice,
+				"The consensus timeout expired.\n");
 			memb_state_consensus_timeout_expired (instance);
-			memb_state_gather_enter (instance);
+			memb_state_gather_enter (instance, 2);
 			break;
 
 		case MEMB_STATE_COMMIT:
-			memb_state_gather_enter (instance);
+			log_printf (instance->totemsrp_log_level_notice,
+				"The token was lost in the COMMIT state.\n");
+			memb_state_gather_enter (instance, 3);
 			break;
 		
 		case MEMB_STATE_RECOVERY:
+			log_printf (instance->totemsrp_log_level_notice,
+				"The token was lost in the RECOVERY state.\n");
 			ring_state_restore (instance);
-			memb_state_gather_enter (instance);
+			memb_state_gather_enter (instance, 4);
 			break;
 	}
 }
@@ -1445,12 +1453,12 @@ static void deliver_messages_from_recovery_to_regular (struct totemsrp_instance
 		 * Convert recovery message into regular message
 		 */
 		if (recovery_message_item->iov_len > 1) {
-			mcast = recovery_message_item->iovec[1].iov_base;
+			mcast = (struct mcast *)recovery_message_item->iovec[1].iov_base;
 			memcpy (&regular_message_item.iovec[0],
 				&recovery_message_item->iovec[1],
 				sizeof (struct iovec) * recovery_message_item->iov_len);
 		} else {
-			mcast = recovery_message_item->iovec[0].iov_base;
+			mcast = (struct mcast *)recovery_message_item->iovec[0].iov_base;
 			if (mcast->header.encapsulated == 1) {
 				/*
 				 * Message is a recovery message encapsulated
@@ -1461,7 +1469,7 @@ static void deliver_messages_from_recovery_to_regular (struct totemsrp_instance
 				regular_message_item.iovec[0].iov_len =
 				recovery_message_item->iovec[0].iov_len - sizeof (struct mcast);
 				regular_message_item.iov_len = 1;
-				mcast = regular_message_item.iovec[0].iov_base;
+				mcast = (struct mcast *)regular_message_item.iovec[0].iov_base;
 			} else {
 				continue; /* TODO this case shouldn't happen */
 				/*
@@ -1606,7 +1614,9 @@ static void memb_state_operational_enter (struct totemsrp_instance *instance)
 	return;
 }
 
-static void memb_state_gather_enter (struct totemsrp_instance *instance)
+static void memb_state_gather_enter (
+	struct totemsrp_instance *instance,
+	unsigned int gather_from)
 {
 	instance->my_commit_token_seq = SEQNO_START_TOKEN - 1;
 
@@ -1653,7 +1663,7 @@ static void memb_state_gather_enter (struct totemsrp_instance *instance)
 	memb_consensus_set (instance, &instance->my_id);
 
 	log_printf (instance->totemsrp_log_level_notice,
-		"entering GATHER state.\n");
+		"entering GATHER state %d.\n", gather_from);
 
 	instance->memb_state = MEMB_STATE_GATHER;
 
@@ -2199,10 +2209,10 @@ static int orf_token_mcast (
 		 * Build IO vector
 		 */
 		memset (&sort_queue_item, 0, sizeof (struct sort_queue_item));
-		sort_queue_item.iovec[0].iov_base = message_item->mcast;
+		sort_queue_item.iovec[0].iov_base = (char *)message_item->mcast;
 		sort_queue_item.iovec[0].iov_len = sizeof (struct mcast);
 	
-		mcast = sort_queue_item.iovec[0].iov_base;
+		mcast = (struct mcast *)sort_queue_item.iovec[0].iov_base;
 	
 		memcpy (&sort_queue_item.iovec[1], message_item->iovec,
 			message_item->iov_len * sizeof (struct iovec));
@@ -2394,7 +2404,6 @@ static void timer_function_token_retransmit_timeout (void *data)
 	case MEMB_STATE_GATHER:
 		break;
 	case MEMB_STATE_COMMIT:
-		break;
 	case MEMB_STATE_OPERATIONAL:
 	case MEMB_STATE_RECOVERY:
 		token_retransmit (instance);
@@ -2460,7 +2469,7 @@ static int token_send (
 		return (0);
 	}
 
-	iovec.iov_base = orf_token;
+	iovec.iov_base = (char *)orf_token;
 	iovec.iov_len = iov_len;
 
 	totemrrp_token_send (instance->totemrrp_handle,
@@ -2491,10 +2500,10 @@ static int token_hold_cancel_send (struct totemsrp_instance *instance)
 	token_hold_cancel.header.nodeid = instance->my_id.addr[0].nodeid;
 	assert (token_hold_cancel.header.nodeid);
 
-	iovec[0].iov_base = &token_hold_cancel;
+	iovec[0].iov_base = (char *)&token_hold_cancel;
 	iovec[0].iov_len = sizeof (struct token_hold_cancel) -
 		sizeof (struct memb_ring_id);
-	iovec[1].iov_base = &instance->my_ring_id;
+	iovec[1].iov_base = (char *)&instance->my_ring_id;
 	iovec[1].iov_len = sizeof (struct memb_ring_id);
 
 	totemrrp_mcast_flush_send (instance->totemrrp_handle, iovec, 2);
@@ -2589,10 +2598,15 @@ static int memb_state_commit_token_send (struct totemsrp_instance *instance,
 	commit_token->memb_index = memb_index_this;
 
 
-	iovec.iov_base = commit_token;
+	iovec.iov_base = (char *)commit_token;
 	iovec.iov_len = sizeof (struct memb_commit_token) +
 		((sizeof (struct srp_addr) +
 			sizeof (struct memb_commit_token_memb_entry)) * commit_token->addr_entries);
+	/*
+	 * Make a copy for retransmission if necessary
+	 */
+	memcpy (instance->orf_token_retransmit, commit_token, iovec.iov_len);
+	instance->orf_token_retransmit_size = iovec.iov_len;
 
 	for (i = 0; i < instance->totem_config->interface_count; i++) {
 		totemrrp_token_target_set (
@@ -2605,6 +2619,10 @@ static int memb_state_commit_token_send (struct totemsrp_instance *instance,
 		&iovec,
 		1);
 
+	/*
+	 * Request retransmission of the commit token in case it is lost
+	 */
+	reset_token_retransmit_timeout (instance);
 	return (0);
 }
 
@@ -2704,12 +2722,12 @@ static void memb_join_message_send (struct totemsrp_instance *instance)
 	memb_join.failed_list_entries = instance->my_failed_list_entries;
 	srp_addr_copy (&memb_join.system_from, &instance->my_id);
 		
-	iovec[0].iov_base = &memb_join;
+	iovec[0].iov_base = (char *)&memb_join;
 	iovec[0].iov_len = sizeof (struct memb_join);
-	iovec[1].iov_base = &instance->my_proc_list;
+	iovec[1].iov_base = (char *)&instance->my_proc_list;
 	iovec[1].iov_len = instance->my_proc_list_entries *
 		sizeof (struct srp_addr);
-	iovec[2].iov_base = &instance->my_failed_list;
+	iovec[2].iov_base = (char *)&instance->my_failed_list;
 	iovec[2].iov_len = instance->my_failed_list_entries *
 		sizeof (struct srp_addr);
 
@@ -2731,10 +2749,10 @@ static void memb_merge_detect_transmit (struct totemsrp_instance *instance)
 	srp_addr_copy (&memb_merge_detect.system_from, &instance->my_id);
 	assert (memb_merge_detect.header.nodeid);
 
-	iovec[0].iov_base = &memb_merge_detect;
+	iovec[0].iov_base = (char *)&memb_merge_detect;
 	iovec[0].iov_len = sizeof (struct memb_merge_detect) -
 		sizeof (struct memb_ring_id);
-	iovec[1].iov_base = &instance->my_ring_id;
+	iovec[1].iov_base = (char *)&instance->my_ring_id;
 	iovec[1].iov_len = sizeof (struct memb_ring_id);
 
 	totemrrp_mcast_flush_send (instance->totemrrp_handle, iovec, 2);
@@ -3001,6 +3019,7 @@ static void fcc_token_update (
  * Message Handlers
  */
 
+struct timeval tv_old;
 /*
  * message handler called when TOKEN message type received
  */
@@ -3028,9 +3047,10 @@ static int message_handler_orf_token (
 	timersub (&tv_current, &tv_old, &tv_diff);
 	memcpy (&tv_old, &tv_current, sizeof (struct timeval));
 
-	if ((((float)tv_diff.tv_usec) / 100.0) > 5.0) {
-		printf ("OTHERS %0.4f ms\n", ((float)tv_diff.tv_usec) / 100.0);
-	}
+	log_printf (instance->totemsrp_log_level_notice,
+	"Time since last token %0.4f ms\n",
+		(((float)tv_diff.tv_sec) * 1000) + ((float)tv_diff.tv_usec)
+			/ 1000.0);
 #endif
 
 #ifdef TEST_DROP_ORF_TOKEN_PERCENTAGE
@@ -3201,7 +3221,7 @@ static int message_handler_orf_token (
 			ring_state_restore (instance);
 
 printf ("gather 1");
-			memb_state_gather_enter (instance);
+			memb_state_gather_enter (instance, 5);
 		} else {
 			instance->my_token_seq = token->token_seq;
 			token->token_seq += 1;
@@ -3274,9 +3294,9 @@ printf ("gather 1");
 			gettimeofday (&tv_current, NULL);
 			timersub (&tv_current, &tv_old, &tv_diff);
 			memcpy (&tv_old, &tv_current, sizeof (struct timeval));
-			if ((((float)tv_diff.tv_usec) / 100.0) > 5.0) {
-				printf ("I held %0.4f ms\n", ((float)tv_diff.tv_usec) / 100.0);
-			}
+			log_printf (instance->totemsrp_log_level_notice,
+				"I held %0.4f ms\n",
+				((float)tv_diff.tv_usec) / 1000.0);
 #endif
 			if (instance->memb_state == MEMB_STATE_OPERATIONAL) {
 				messages_deliver_to_app (instance, 0,
@@ -3367,7 +3387,7 @@ static void messages_deliver_to_app (
 
 		sort_queue_item_p = ptr;
 
-		mcast = sort_queue_item_p->iovec[0].iov_base;
+		mcast = (struct mcast *)sort_queue_item_p->iovec[0].iov_base;
 		assert (mcast != (struct mcast *)0xdeadbeef);
 
 		/*
@@ -3378,7 +3398,8 @@ static void messages_deliver_to_app (
 				1,
 				instance->my_deliver_memb_list,
 				instance->my_deliver_memb_entries) == 0) {
-		instance->my_high_delivered = my_high_delivered_stored + i;
+
+				instance->my_high_delivered = my_high_delivered_stored + i;
 
 			continue;
 		}
@@ -3481,7 +3502,7 @@ static int message_handler_mcast (
 				&mcast_header.system_from, 1,
 				instance->my_proc_list, &instance->my_proc_list_entries);
 printf ("gather 2");
-			memb_state_gather_enter (instance);
+			memb_state_gather_enter (instance, 6);
 			break;
 
 		case MEMB_STATE_GATHER:
@@ -3493,7 +3514,7 @@ printf ("gather 2");
 
 				memb_set_merge (&mcast_header.system_from, 1,
 					instance->my_proc_list, &instance->my_proc_list_entries);
-				memb_state_gather_enter (instance);
+				memb_state_gather_enter (instance, 7);
 				return (0);
 			}
 			break;
@@ -3582,8 +3603,7 @@ static int message_handler_memb_merge_detect (
 	case MEMB_STATE_OPERATIONAL:
 		memb_set_merge (&memb_merge_detect->system_from, 1,
 			instance->my_proc_list, &instance->my_proc_list_entries);
-printf ("gather 3");
-		memb_state_gather_enter (instance);
+		memb_state_gather_enter (instance, 8);
 		break;
 
 	case MEMB_STATE_GATHER:
@@ -3595,8 +3615,7 @@ printf ("gather 3");
 
 			memb_set_merge (&memb_merge_detect->system_from, 1,
 				instance->my_proc_list, &instance->my_proc_list_entries);
-printf ("gather 4");
-			memb_state_gather_enter (instance);
+			memb_state_gather_enter (instance, 9);
 			return (0);
 		}
 		break;
@@ -3616,7 +3635,7 @@ static int memb_join_process (
 	struct totemsrp_instance *instance,
 	struct memb_join *memb_join)
 {
-	unsigned char *commit_token_storage[32000];
+	unsigned char *commit_token_storage[TOKEN_SIZE_MAX];
 	struct memb_commit_token *my_commit_token =
 		(struct memb_commit_token *)commit_token_storage;
 	struct srp_addr *proc_list;
@@ -3680,7 +3699,7 @@ static int memb_join_process (
 				memb_join->failed_list_entries,
 				instance->my_failed_list, &instance->my_failed_list_entries);
 		}
-		memb_state_gather_enter (instance);
+		memb_state_gather_enter (instance, 10);
 		return (1); /* gather entered */
 	}
 	return (0); /* gather not entered */
@@ -3824,7 +3843,7 @@ static int message_handler_memb_join (
 			gather_entered = memb_join_process (instance,
 				memb_join);
 			if (gather_entered == 0) {
-				memb_state_gather_enter (instance);
+				memb_state_gather_enter (instance, 11);
 			}
 			break;
 
@@ -3841,7 +3860,7 @@ static int message_handler_memb_join (
 				memb_join->ring_seq >= instance->my_ring_id.seq) {
 
 				memb_join_process (instance, memb_join);
-				memb_state_gather_enter (instance);
+				memb_state_gather_enter (instance, 12);
 			}
 			break;
 
@@ -3856,7 +3875,7 @@ static int message_handler_memb_join (
 				ring_state_restore (instance);
 
 				memb_join_process (instance, memb_join);
-				memb_state_gather_enter (instance);
+				memb_state_gather_enter (instance, 13);
 			}
 			break;
 	}
@@ -3877,6 +3896,9 @@ static int message_handler_memb_commit_token (
 	struct srp_addr *addr;
 	struct memb_commit_token_memb_entry *memb_list;
 
+	log_printf (instance->totemsrp_log_level_debug,
+		"got commit token\n");
+
 	if (endian_conversion_needed) {
 		memb_commit_token = memb_commit_token_convert;
 		memb_commit_token_endian_convert (msg, memb_commit_token);
@@ -4007,7 +4029,7 @@ void main_iface_change_fn (
 
 	}
 	if (instance->iface_changes >= instance->totem_config->interface_count) {
-		memb_state_gather_enter (instance);
+		memb_state_gather_enter (instance, 14);
 	}
 }
 

+ 5 - 5
exec/vsf_ykd.c

@@ -1,12 +1,12 @@
 /*
  * Copyright (c) 2005 MontaVista Software, Inc.
  * Copyright (c) 2006 Red Hat, Inc.
- * Author: Steven Dake (sdake@mvista.com)
- *
  * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
+ * Author: Steven Dake (sdake@mvista.com)
+ *
  * This software licensed under BSD license, the text of which follows:
  * 
  * Redistribution and use in source and binary forms, with or without
@@ -161,9 +161,9 @@ static int ykd_state_send_msg (enum totem_callback_token_type type, void *contex
 
 	header.id = YKD_HEADER_SENDSTATE;
 	
-	iovec[0].iov_base = &header;
+	iovec[0].iov_base = (char *)&header;
 	iovec[0].iov_len = sizeof (struct ykd_header);
-	iovec[1].iov_base = &ykd_state;
+	iovec[1].iov_base = (char *)&ykd_state;
 	iovec[1].iov_len = sizeof (struct ykd_state);
 
 	res = totempg_groups_mcast_joined (ykd_group_handle, iovec, 2,
@@ -190,7 +190,7 @@ static int ykd_attempt_send_msg (enum totem_callback_token_type type, void *cont
 
 	header.id = YKD_HEADER_SENDSTATE;
 	
-	iovec.iov_base = &header;
+	iovec.iov_base = (char *)&header;
 	iovec.iov_len = sizeof (struct ykd_header);
 
 	res = totempg_groups_mcast_joined (ykd_group_handle, &iovec, 1,

+ 2 - 1
include/evs.h

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2004 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -46,7 +47,7 @@
  * @{
  */
 
-typedef u_int64_t evs_handle_t;
+typedef uint64_t evs_handle_t;
 
 typedef enum {
 	EVS_DISPATCH_ONE,

+ 5 - 0
include/mar_gen.h

@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2006 Red Hat, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -35,7 +36,11 @@
 #ifndef AIS_MAR_GEN_H_DEFINED
 #define AIS_MAR_GEN_H_DEFINED
 
+#ifndef OPENAIS_SOLARIS
 #include <stdint.h>
+#else
+#include <sys/types.h>
+#endif
 #include <string.h>
 
 #include "saAis.h"

+ 6 - 0
include/queue.h

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2002-2004 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -38,7 +39,12 @@
 #include <pthread.h>
 #include "assert.h"
 
+#ifndef OPENAIS_SOLARIS
 struct queue {
+#else
+struct _queue {
+#define	queue _queue
+#endif
 	int head;
 	int tail;
 	int used;

+ 5 - 0
include/saAis.h

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2002-2003 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -44,7 +45,11 @@ typedef enum {
 	SA_TRUE = 1
 } SaBoolT;
 
+#ifndef OPENAIS_SOLARIS
 #include <stdint.h>
+#else
+#include <sys/types.h>
+#endif
 
 typedef int8_t SaInt8T;
 typedef int16_t SaInt16T;

+ 4 - 0
lcr/Makefile

@@ -33,6 +33,10 @@ ifeq (${OPENAIS_COMPAT}, LINUX)
 	LDFLAGS += -ldl
 endif
 
+ifeq (${OPENAIS_COMPAT}, SOLARIS)
+	override LDFLAGS += -lnsl -lsocket
+endif
+
 all:liblcr.a test test_static uic libtest_a.lcrso libtest_b.lcrso
 
 liblcr.a: lcr_ifact.o

+ 100 - 3
lcr/lcr_ifact.c

@@ -36,6 +36,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <fnmatch.h>
+#ifdef OPENAIS_SOLARIS
+#include <iso/limits_iso.h>
+#endif
 #include "lcr_comp.h"
 #include "lcr_ifact.h"
 #include "../include/hdb.h"
@@ -68,7 +71,7 @@ static struct hdb_handle_database lcr_iface_instance_database = {
 
 static unsigned int g_component_handle;
 
-#ifdef OPENAIS_LINUX
+#if defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)
 static int lcr_select_so (const struct dirent *dirent)
 #else
 static int lcr_select_so (struct dirent *dirent)
@@ -86,6 +89,7 @@ static int lcr_select_so (struct dirent *dirent)
 	return (0);
 }
 
+#ifndef OPENAIS_SOLARIS
 #ifdef OPENAIS_LINUX
 static int pathlist_select (const struct dirent *dirent)
 #else
@@ -98,6 +102,7 @@ static int pathlist_select (struct dirent *dirent)
 
 	return (0);
 }
+#endif
 
 static inline struct lcr_component_instance *lcr_comp_find (
 	char *iface_name,
@@ -201,6 +206,7 @@ static void ld_library_path_build (void)
 
 static int ldso_path_build (char *path, char *filename)
 {
+#ifndef OPENAIS_SOLARIS
 	FILE *fp;
 	char string[1024];
 	char filename_cat[1024];
@@ -254,9 +260,84 @@ static int ldso_path_build (char *path, char *filename)
 		path_list[path_list_entries++] = strdup (string);
 	}
 	fclose(fp);
+#endif
 	return (0);
 }
 
+#ifdef OPENAIS_SOLARIS
+static int scandir (
+	const char *dir, struct dirent ***namelist,
+	int (*filter)(const struct dirent *),
+	int (*compar)(const struct dirent **, const struct dirent **))
+{
+	DIR *d;
+	struct dirent *entry, **names = NULL;
+	int namelist_items = 0, namelist_size = 0;
+
+	d = opendir(dir);
+	if (d == NULL)
+		return -1;
+
+	names = NULL;
+	while ((entry = readdir (d)) != NULL) {
+		struct dirent *tmpentry;
+		if ((filter != NULL) && ((*filter)(entry) == 0)) {
+			continue;
+		}
+		if (namelist_items >= namelist_size) {
+			struct dirent **tmp;
+			namelist_size += 512;
+			if ((unsigned long)namelist_size > INT_MAX) {
+				errno = EOVERFLOW;
+				goto fail;
+			}
+			tmp = realloc (names,
+				namelist_size * sizeof(struct dirent *));
+			if (tmp == NULL) {
+				goto fail;
+			}
+			names = tmp;
+		}
+		tmpentry = malloc (entry->d_reclen);
+		if (tmpentry == NULL) {
+			goto fail;
+		}
+		(void) memcpy (tmpentry, entry, entry->d_reclen);
+		names[namelist_items++] = tmpentry;
+	}
+	(void) closedir (d);
+	if ((namelist_items > 1) && (compar != NULL)) {
+		qsort (names, namelist_items, sizeof (struct dirent *),
+			(int (*)(const void *, const void *))compar);
+	}
+
+	*namelist = names;
+
+	return namelist_items;
+
+fail:
+	{
+	int err = errno;
+	(void) closedir (d);
+	while (namelist_items != 0) {
+		namelist_items--;
+		free (*namelist[namelist_items]);
+	}
+	if (names != NULL) {
+		free (names);
+	}
+	*namelist = NULL;
+	errno = err;
+	return -1;
+	}
+}
+
+static int alphasort (const struct dirent **a, const struct dirent **b)
+{
+	return strcmp ((*a)->d_name, (*b)->d_name);
+}
+#endif
+
 static int interface_find_and_load (
 	char *path,
 	char *iface_name,
@@ -308,11 +389,27 @@ static int interface_find_and_load (
 		}
 		dlclose (dl_handle);
 	} /* scanning for lcrso loop */
-	return (-1);
+
+
+	if (scandir_entries > 0) {
+		int i;
+		for (i = 0; i < scandir_entries; i++) {
+			free (scandir_list[i]);
+		}
+		free (scandir_list);
+	}
+	return -1;
 
 found:
 	*instance_ret = instance;
-	return (0);
+	if (scandir_entries > 0) {
+		int i;
+		for (i = 0; i < scandir_entries; i++) {
+			free (scandir_list[i]);
+		}
+		free (scandir_list);
+	}
+	return 0;
 }
 
 static unsigned int lcr_initialized = 0;

+ 12 - 4
lcr/uic.c

@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2006 Steven Dake (sdake@mvista.com)
+ * Copyright (c) 2006 Steven Dake (sdake@mvista.com)
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * This software licensed under BSD license, the text of which follows:
  * 
@@ -48,15 +49,17 @@
 #include <sys/poll.h>
 #include <string.h>
 
-#if defined(OPENAIS_LINUX)
+#if defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)
 /* SUN_LEN is broken for abstract namespace 
  */
 #define AIS_SUN_LEN(a) sizeof(*(a))
-
-static char *socketname = "lcr.socket";
 #else
 #define AIS_SUN_LEN(a) SUN_LEN(a)
+#endif
 
+#ifdef OPENAIS_LINUX
+static char *socketname = "lcr.socket";
+#else
 static char *socketname = "/var/run/lcr.socket";
 #endif
 
@@ -108,9 +111,14 @@ int uic_msg_send (int fd, char *msg)
 	msg_send.msg_iovlen = 2;
 	msg_send.msg_name = 0;
 	msg_send.msg_namelen = 0;
+#ifndef OPENAIS_SOLARIS
 	msg_send.msg_control = 0;
 	msg_send.msg_controllen = 0;
 	msg_send.msg_flags = 0;
+#else
+	msg_send.msg_accrights = NULL;
+	msg_send.msg_accrightslen = 0;
+#endif
 
 	retry_send:
 	res = sendmsg (fd, &msg_send, 0);

+ 7 - 4
lcr/uis.c

@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2006 Steven Dake (sdake@mvista.com)
+ * Copyright (c) 2006 Steven Dake (sdake@mvista.com)
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * This software licensed under BSD license, the text of which follows:
  * 
@@ -50,15 +51,17 @@
 
 #define SERVER_BACKLOG 5
 
-#if defined(OPENAIS_LINUX)
+#if defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)
 /* SUN_LEN is broken for abstract namespace 
  */
 #define AIS_SUN_LEN(a) sizeof(*(a))
-
-static char *socketname = "lcr.socket";
 #else
 #define AIS_SUN_LEN(a) SUN_LEN(a)
+#endif
 
+#ifdef OPENAIS_LINUX
+static char *socketname = "lcr.socket";
+#else
 static char *socketname = "/var/run/lcr.socket";
 #endif
 

+ 2 - 2
lib/ckpt.c

@@ -1530,7 +1530,7 @@ saCkptCheckpointWrite (
 		iov_idx++;
 
 		if (ioVector[i].sectionId.idLen) {
-			iov[iov_idx].iov_base = ioVector[i].sectionId.id;
+			iov[iov_idx].iov_base = (char *)ioVector[i].sectionId.id;
 			iov[iov_idx].iov_len = ioVector[i].sectionId.idLen;
 			iov_idx++;
 		}
@@ -1697,7 +1697,7 @@ saCkptCheckpointRead (
 
 		iov[0].iov_base = (char *)&req_lib_ckpt_sectionread;
 		iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionread);
-		iov[1].iov_base = ioVector[i].sectionId.id;
+		iov[1].iov_base = (char *)ioVector[i].sectionId.id;
 		iov[1].iov_len = ioVector[i].sectionId.idLen;
 
 		error = saSendMsgRetry (ckptCheckpointInstance->response_fd,

+ 6 - 5
lib/cpg.c

@@ -2,6 +2,7 @@
  * vi: set autoindent tabstop=4 shiftwidth=4 :
  *
  * Copyright (c) 2006 Red Hat, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -411,7 +412,7 @@ cpg_error_t cpg_join (
 	marshall_to_mar_cpg_name_t (&req_lib_cpg_trackstart.group_name,
 		group);
 
-	iov[0].iov_base = &req_lib_cpg_trackstart;
+	iov[0].iov_base = (char *)&req_lib_cpg_trackstart;
 	iov[0].iov_len = sizeof (struct req_lib_cpg_trackstart);
 
 	error = saSendMsgReceiveReply (cpg_inst->dispatch_fd, iov, 1,
@@ -429,7 +430,7 @@ cpg_error_t cpg_join (
 	marshall_to_mar_cpg_name_t (&req_lib_cpg_join.group_name,
 		group);
 
-	iov[0].iov_base = &req_lib_cpg_join;
+	iov[0].iov_base = (char *)&req_lib_cpg_join;
 	iov[0].iov_len = sizeof (struct req_lib_cpg_join);
 
 	error = saSendMsgReceiveReply (cpg_inst->response_fd, iov, 1,
@@ -470,7 +471,7 @@ cpg_error_t cpg_leave (
 	marshall_to_mar_cpg_name_t (&req_lib_cpg_leave.group_name,
 		group);
 
-	iov[0].iov_base = &req_lib_cpg_leave;
+	iov[0].iov_base = (char *)&req_lib_cpg_leave;
 	iov[0].iov_len = sizeof (struct req_lib_cpg_leave);
 
 	pthread_mutex_lock (&cpg_inst->response_mutex);
@@ -521,7 +522,7 @@ cpg_error_t cpg_mcast_joined (
 	req_lib_cpg_mcast.guarantee = guarantee;
 	req_lib_cpg_mcast.msglen = msg_len;
 
-	iov[0].iov_base = &req_lib_cpg_mcast;
+	iov[0].iov_base = (char *)&req_lib_cpg_mcast;
 	iov[0].iov_len = sizeof (struct req_lib_cpg_mcast);
 	memcpy (&iov[1], iovec, iov_len * sizeof (struct iovec));
 
@@ -567,7 +568,7 @@ cpg_error_t cpg_membership_get (
 	marshall_to_mar_cpg_name_t (&req_lib_cpg_membership_get.group_name,
 		group_name);
 
-	iov.iov_base = &req_lib_cpg_membership_get;
+	iov.iov_base = (char *)&req_lib_cpg_membership_get;
 	iov.iov_len = sizeof (mar_req_header_t);
 
 	pthread_mutex_lock (&cpg_inst->response_mutex);

+ 9 - 8
lib/evs.c

@@ -2,6 +2,7 @@
  * vi: set autoindent tabstop=4 shiftwidth=4 :
 
  * Copyright (c) 2004-2005 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -374,9 +375,9 @@ evs_error_t evs_join (
 	req_lib_evs_join.header.id = MESSAGE_REQ_EVS_JOIN;
 	req_lib_evs_join.group_entries = group_entries;
 
-	iov[0].iov_base = &req_lib_evs_join;
+	iov[0].iov_base = (char *)&req_lib_evs_join;
 	iov[0].iov_len = sizeof (struct req_lib_evs_join);
-	iov[1].iov_base = groups;
+	iov[1].iov_base = (char *)groups;
 	iov[1].iov_len = (group_entries * sizeof (struct evs_group));
 	
 	pthread_mutex_lock (&evs_inst->response_mutex);
@@ -419,9 +420,9 @@ evs_error_t evs_leave (
 	req_lib_evs_leave.header.id = MESSAGE_REQ_EVS_LEAVE;
 	req_lib_evs_leave.group_entries = group_entries;
 
-	iov[0].iov_base = &req_lib_evs_leave;
+	iov[0].iov_base = (char *)&req_lib_evs_leave;
 	iov[0].iov_len = sizeof (struct req_lib_evs_leave);
-	iov[1].iov_base = groups;
+	iov[1].iov_base = (char *)groups;
 	iov[1].iov_len = (group_entries * sizeof (struct evs_group));
 	
 	pthread_mutex_lock (&evs_inst->response_mutex);
@@ -473,7 +474,7 @@ evs_error_t evs_mcast_joined (
 	req_lib_evs_mcast_joined.guarantee = guarantee;
 	req_lib_evs_mcast_joined.msg_len = msg_len;
 
-	iov[0].iov_base = &req_lib_evs_mcast_joined;
+	iov[0].iov_base = (char *)&req_lib_evs_mcast_joined;
 	iov[0].iov_len = sizeof (struct req_lib_evs_mcast_joined);
 	memcpy (&iov[1], iovec, iov_len * sizeof (struct iovec));
 	
@@ -526,9 +527,9 @@ evs_error_t evs_mcast_groups (
 	req_lib_evs_mcast_groups.msg_len = msg_len;
 	req_lib_evs_mcast_groups.group_entries = group_entries;
 
-	iov[0].iov_base = &req_lib_evs_mcast_groups;
+	iov[0].iov_base = (char *)&req_lib_evs_mcast_groups;
 	iov[0].iov_len = sizeof (struct req_lib_evs_mcast_groups);
-	iov[1].iov_base = groups;
+	iov[1].iov_base = (char *)groups;
 	iov[1].iov_len = (group_entries * sizeof (struct evs_group));
 	memcpy (&iov[2], iovec, iov_len * sizeof (struct iovec));
 	
@@ -570,7 +571,7 @@ evs_error_t evs_membership_get (
 	req_lib_evs_membership_get.header.size = sizeof (struct req_lib_evs_membership_get);
 	req_lib_evs_membership_get.header.id = MESSAGE_REQ_EVS_MEMBERSHIP_GET;
 
-	iov.iov_base = &req_lib_evs_membership_get;
+	iov.iov_base = (char *)&req_lib_evs_membership_get;
 	iov.iov_len = sizeof (struct req_lib_evs_membership_get);
 
 	pthread_mutex_lock (&evs_inst->response_mutex);

+ 8 - 8
lib/evt.c

@@ -987,7 +987,7 @@ saEvtChannelOpen(
 	req.ico_open_flag = channelOpenFlags;
 	marshall_to_mar_name_t (&req.ico_channel_name, (SaNameT *)channelName);
 
-	iov.iov_base = &req;
+	iov.iov_base = (char *)&req;
 	iov.iov_len = sizeof(req);
 
 	pthread_mutex_lock(&evti->ei_response_mutex);
@@ -1091,7 +1091,7 @@ saEvtChannelClose(SaEvtChannelHandleT channelHandle)
 	req.icc_head.id = MESSAGE_REQ_EVT_CLOSE_CHANNEL;
 	req.icc_channel_handle = eci->eci_svr_channel_handle;
 
-	iov.iov_base = &req;
+	iov.iov_base = (char *)&req;
 	iov.iov_len = sizeof (req);
 
 	pthread_mutex_lock(&evti->ei_response_mutex);
@@ -1212,7 +1212,7 @@ saEvtChannelOpenAsync(SaEvtHandleT evtHandle,
 	req.ico_invocation = invocation;
 	req.ico_open_flag = channelOpenFlags;
 	marshall_to_mar_name_t (&req.ico_channel_name, (SaNameT *)channelName);
-	iov.iov_base = &req;
+	iov.iov_base = (char *)&req;
 	iov.iov_len = sizeof(req);
 
 
@@ -1313,7 +1313,7 @@ saEvtChannelUnlink(
 	req.iuc_head.size = sizeof(req);
 	req.iuc_head.id = MESSAGE_REQ_EVT_UNLINK_CHANNEL;
 	marshall_to_mar_name_t (&req.iuc_channel_name, (SaNameT *)channelName);
-	iov.iov_base = &req;
+	iov.iov_base = (char *)&req;
 	iov.iov_len = sizeof(req);
 
 
@@ -1989,7 +1989,7 @@ saEvtEventPublish(
 	req->led_priority = edi->edi_priority;
 	marshall_to_mar_name_t (&req->led_publisher_name, &edi->edi_pub_name);
 
-	iov.iov_base = req;
+	iov.iov_base = (char *)req;
 	iov.iov_len = req->led_head.size;
 
 	pthread_mutex_lock(&evti->ei_response_mutex);
@@ -2107,7 +2107,7 @@ saEvtEventSubscribe(
 	req->ics_channel_handle = eci->eci_svr_channel_handle;
 	req->ics_sub_id = subscriptionId;
 	req->ics_filter_size = sz;
-	iov.iov_base = req;
+	iov.iov_base = (char *)req;
 	iov.iov_len = req->ics_head.size;
 
 	pthread_mutex_lock(&evti->ei_response_mutex);
@@ -2170,7 +2170,7 @@ saEvtEventUnsubscribe(
 
 	req.icu_channel_handle = eci->eci_svr_channel_handle;
 	req.icu_sub_id = subscriptionId;
-	iov.iov_base = &req;
+	iov.iov_base = (char *)&req;
 	iov.iov_len = sizeof(req);
 
 	pthread_mutex_lock(&evti->ei_response_mutex);
@@ -2241,7 +2241,7 @@ saEvtEventRetentionTimeClear(
 	req.iec_channel_handle = eci->eci_svr_channel_handle;
 	req.iec_event_id = eventId;
 
-	iov.iov_base = &req;
+	iov.iov_base = (char *)&req;
 	iov.iov_len = sizeof(req);
 
 	pthread_mutex_lock(&evti->ei_response_mutex);

+ 35 - 4
lib/util.c

@@ -70,15 +70,21 @@ struct saHandle {
 	uint32_t check;
 };
 
-#if defined(OPENAIS_LINUX)
+#ifdef OPENAIS_SOLARIS
+#define MSG_NOSIGNAL 0
+#endif
+
+#if defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)
 /* SUN_LEN is broken for abstract namespace 
  */
 #define AIS_SUN_LEN(a) sizeof(*(a))
-
-static char *socketname = "libais.socket";
 #else
 #define AIS_SUN_LEN(a) SUN_LEN(a)
+#endif
 
+#ifdef OPENAIS_LINUX
+static char *socketname = "libais.socket";
+#else
 static char *socketname = "/var/run/libais.socket";
 #endif
 
@@ -228,9 +234,14 @@ saRecvRetry (
 	msg_recv.msg_iovlen = 1;
 	msg_recv.msg_name = 0;
 	msg_recv.msg_namelen = 0;
+#ifndef OPENAIS_SOLARIS
 	msg_recv.msg_control = 0;
 	msg_recv.msg_controllen = 0;
 	msg_recv.msg_flags = 0;
+#else
+	msg_recv.msg_accrights = NULL;
+	msg_recv.msg_accrightslen = 0;
+#endif
 
 retry_recv:
 	iov_recv.iov_base = (void *)&rbuf[processed];
@@ -243,6 +254,16 @@ retry_recv:
 	if (result == -1 && errno == EAGAIN) {
 		goto retry_recv;
 	}
+#ifdef OPENAIS_SOLARIS
+	if (result == 0) {
+		/*
+		 * In case of disconnection, recvmsg() returns 0 and next calls to
+		 * poll() always return POLLIN
+		 */
+		error = SA_AIS_ERR_BAD_HANDLE;
+		goto error_exit;
+	}
+#endif
 	if (result == -1 || result == 0) {
 		error = SA_AIS_ERR_LIBRARY;
 		goto error_exit;
@@ -273,9 +294,14 @@ saSendRetry (
 	msg_send.msg_iovlen = 1;
 	msg_send.msg_name = 0;
 	msg_send.msg_namelen = 0;
+#ifndef OPENAIS_SOLARIS
 	msg_send.msg_control = 0;
 	msg_send.msg_controllen = 0;
 	msg_send.msg_flags = 0;
+#else
+	msg_send.msg_accrights = NULL;
+	msg_send.msg_accrightslen = 0;
+#endif
 
 retry_send:
 	iov_send.iov_base = (void *)&rbuf[processed];
@@ -362,9 +388,14 @@ SaAisErrorT saSendMsgRetry (
 	msg_send.msg_iovlen = iov_len_sendmsg;
 	msg_send.msg_name = 0;
 	msg_send.msg_namelen = 0;
+#ifndef OPENAIS_SOLARIS
 	msg_send.msg_control = 0;
 	msg_send.msg_controllen = 0;
 	msg_send.msg_flags = 0;
+#else
+	msg_send.msg_accrights = NULL;
+	msg_send.msg_accrightslen = 0;
+#endif
 
 retry_sendmsg:
 	result = sendmsg (s, &msg_send, MSG_NOSIGNAL);
@@ -426,7 +457,7 @@ retry_sendmsg:
 		}
 		memcpy (&iovec_save, &iov[i], sizeof (struct iovec));
 		iovec_saved_position = i;
-		iov[i].iov_base = ((unsigned char *)(iov[i].iov_base)) +
+		iov[i].iov_base = ((char *)(iov[i].iov_base)) +
 			(total_sent - csize_cntr);
 		iov[i].iov_len = total_size - total_sent;
 		msg_send.msg_iov = &iov[i];

+ 5 - 0
test/Makefile

@@ -1,4 +1,5 @@
 # Copyright (c) 2002-2004 MontaVista Software, Inc.
+# Copyright (c) 2006 Sun Microsystems, Inc.
 # 
 # All rights reserved.
 # 
@@ -32,6 +33,10 @@
 #
 include ../Makefile.inc
 
+ifeq (${OPENAIS_COMPAT}, SOLARIS)
+	override LDFLAGS += -lnsl -lsocket -lrt
+endif
+
 LIBRARIES= ../lib/libSaClm.a ../lib/libSaAmf.a ../lib/libSaCkpt.a ../lib/libSaEvt.a ../lib/libSaLck.a ../lib/libSaMsg.a ../lib/libevs.a ../lib/libcpg.a ../lib/libcfg.a
 LIBS = $(LIBRARIES) 
 

+ 13 - 0
test/ckptbench.c

@@ -1,6 +1,7 @@
 #define _BSD_SOURCE
 /*
  * Copyright (c) 2002-2004 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -53,6 +54,18 @@
 #include "saAis.h"
 #include "saCkpt.h"
 
+#ifdef OPENAIS_SOLARIS
+#define timersub(a, b, result)						\
+    do {								\
+	(result)->tv_sec = (a)->tv_sec - (b)->tv_sec;			\
+	(result)->tv_usec = (a)->tv_usec - (b)->tv_usec;		\
+	if ((result)->tv_usec < 0) {					\
+	    --(result)->tv_sec;						\
+	    (result)->tv_usec += 1000000;				\
+	}								\
+    } while (0)
+#endif
+
 int alarm_notice;
 
 void printSaNameT (SaNameT *name)

+ 15 - 1
test/ckptbenchth.c

@@ -1,6 +1,7 @@
 #define _BSD_SOURCE
 /*
  * Copyright (c) 2002-2004 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -51,6 +52,18 @@
 #include "saAis.h"
 #include "saCkpt.h"
 
+#ifdef OPENAIS_SOLARIS
+#define timersub(a, b, result)						\
+    do {								\
+	(result)->tv_sec = (a)->tv_sec - (b)->tv_sec;			\
+	(result)->tv_usec = (a)->tv_usec - (b)->tv_usec;		\
+	if ((result)->tv_usec < 0) {					\
+	    --(result)->tv_sec;						\
+	    (result)->tv_usec += 1000000;				\
+	}								\
+    } while (0)
+#endif
+
 int alarm_notice = 0;
 
 void printSaNameT (SaNameT *name)
@@ -165,6 +178,7 @@ struct threaddata {
 	int written;
 };
 
+extern void pthread_exit(void *) __attribute__((noreturn));
 
 void *benchmark_thread (void *arg) 
 {
@@ -276,7 +290,7 @@ int main (void) {
 	 */
 	for (i  = 0; i < CHECKPOINT_THREADS_MAX; i++) {
 		sprintf ((char *)checkpointName.value, "checkpoint (%d)", i);
-		checkpointName.length = strlen (checkpointName.value);
+		checkpointName.length = strlen ((char *)checkpointName.value);
 		do {
 			error = saCkptInitialize (&ckpt_handles[i], &callbacks, &version);
 		} while (error == SA_AIS_ERR_TRY_AGAIN);

+ 12 - 0
test/evsbench.c

@@ -52,6 +52,18 @@
 #include "saAis.h"
 #include "evs.h"
 
+#ifdef OPENAIS_SOLARIS
+#define timersub(a, b, result)						\
+    do {								\
+	(result)->tv_sec = (a)->tv_sec - (b)->tv_sec;			\
+	(result)->tv_usec = (a)->tv_usec - (b)->tv_usec;		\
+	if ((result)->tv_usec < 0) {					\
+	    --(result)->tv_sec;						\
+	    (result)->tv_usec += 1000000;				\
+	}								\
+    } while (0)
+#endif
+
 volatile static int alarm_notice = 0;
 
 int outstanding = 0;

+ 17 - 1
test/evtbench.c

@@ -7,15 +7,31 @@
 #include <sys/poll.h>
 #include <unistd.h>
 #include <fcntl.h>
+#ifndef OPENAIS_SOLARIS
 #include <stdint.h>
-#include <stdlib.h>
 #include <getopt.h>
+#else
+#include <sys/types.h>
+#endif
+#include <stdlib.h>
 #include <sys/time.h>
 #include "saAis.h"
 #include "saEvt.h"
 
 // #define EVENT_SUBSCRIBE
 
+#ifdef OPENAIS_SOLARIS
+#define timersub(a, b, result)						\
+    do {								\
+	(result)->tv_sec = (a)->tv_sec - (b)->tv_sec;			\
+	(result)->tv_usec = (a)->tv_usec - (b)->tv_usec;		\
+	if ((result)->tv_usec < 0) {					\
+	    --(result)->tv_sec;						\
+	    (result)->tv_usec += 1000000;				\
+	}								\
+    } while (0)
+#endif
+
 SaVersionT version = { 'B', 0x01, 0x01 };
 
 void event_callback( SaEvtSubscriptionIdT subscriptionId,

+ 5 - 1
test/publish.c

@@ -7,9 +7,13 @@
 #include <sys/poll.h>
 #include <unistd.h>
 #include <fcntl.h>
+#ifndef OPENAIS_SOLARIS
 #include <stdint.h>
-#include <stdlib.h>
 #include <getopt.h>
+#else
+#include <sys/types.h>
+#endif
+#include <stdlib.h>
 #include <sys/time.h>
 #include "saAis.h"
 #include "saEvt.h"

+ 35 - 5
test/subscription.c

@@ -4,17 +4,46 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <stdint.h>
 #include <unistd.h>
 #include <time.h>
 #include <fcntl.h>
 #include <sys/poll.h>
-#include <stdlib.h>
+#ifndef OPENAIS_SOLARIS
+#include <stdint.h>
 #include <getopt.h>
+#else
+#include <sys/types.h>
+#endif
+#include <stdlib.h>
 #include <sched.h>
 #include "saAis.h"
 #include "saEvt.h"
 
+#ifdef OPENAIS_SOLARIS
+char * strsep(char** str, const char* delims)
+{
+	char* token;
+
+	if (*str == NULL) {
+		/* No more tokens */
+		return NULL;
+	}
+
+	token = *str;
+	while (**str != '\0') {
+		if (strchr(delims,**str)!=NULL) {
+			**str = '\0';
+			(*str)++;
+			return token;
+		}
+		(*str)++;
+	}
+	/* There is no other token */
+	*str = NULL;
+	return token;
+}
+#endif
+
 #define  TEST_EVENT_ORDER 1
 #define  EVT_FREQ 1000
 #define  TRY_WAIT 2
@@ -171,7 +200,8 @@ test_subscription()
 		}
 
 		if (pfd.revents & (POLLERR|POLLHUP)) {
-			printf("Error recieved on poll fd %llu\n", (unsigned long long)fd);
+			printf("Error received on poll fd %llu\n",
+				(unsigned long long)fd);
 			result =  SA_AIS_ERR_BAD_OPERATION;
 			goto sub_fin;
 		}
@@ -373,7 +403,7 @@ evt_free:
 
 static int err_wait_time = -1;
 
-#if defined(OPENAIS_BSD) || defined(OPENAIS_LINUX)
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 static struct sched_param sched_param = {
 	sched_priority: 1
 };
@@ -386,7 +416,7 @@ int main (int argc, char **argv)
 	int option;
 	char *p;
 
-#if defined(OPENAIS_BSD) || defined(OPENAIS_LINUX)
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 	sched_setscheduler (0, SCHED_RR, &sched_param);
 #endif
 

+ 15 - 15
test/testamf1.c

@@ -1,12 +1,12 @@
 /*
  * Copyright (c) 2002-2003 MontaVista Software, Inc.
+ * Copyright (c) 2006 Ericsson AB.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
- * Author: Steven Dake (sdake@mvista.com)
- *
- * Copyright (c) 2006 Ericsson AB.
- *  Author: Hans Feldt
+ * Author:  Steven Dake (sdake@mvista.com)
+ *	    Hans Feldt
  *
  * This software licensed under BSD license, the text of which follows:
  * 
@@ -120,7 +120,7 @@ void ComponentTerminateCallback (
 	gettimeofday(&t,NULL);                                   \
 	printf("%s:%d: %s : %d : %u: %u :%s : " format "\n",\
 		__FILE__,__LINE__,__FUNCTION__,             \
-		getpid(),(int)t.tv_sec, (int)t.tv_usec,#x,x);          \
+		(int)getpid(),(int)t.tv_sec, (int)t.tv_usec,#x,x);          \
     }while(0)
 #else
     #define TRU "%d"
@@ -140,10 +140,10 @@ void CSISetCallback (
 	case SA_AMF_HA_ACTIVE:
 		printf ("%d: Component '%s' requested to enter hastate SA_AMF_ACTIVE"
 				" for \n\tCSI '%s'\n",
-			getpid(), compName->value, csiDescriptor->csiName.value);
+			(int)getpid(), compName->value, csiDescriptor->csiName.value);
 		res = saAmfResponse (handle, invocation, SA_AIS_OK);
 		if (res != SA_AIS_OK) {
-			fprintf (stderr, "%d: saAmfResponse failed: %d\n", getpid(), res);
+			fprintf (stderr, "%d: saAmfResponse failed: %d\n", (int)getpid(), res);
 			exit (-1);
 		}
 
@@ -179,7 +179,7 @@ void CSISetCallback (
 	case SA_AMF_HA_STANDBY:
 		printf ("%d: Component '%s' requested to enter hastate SA_AMF_STANDBY "
 				"for \n\tCSI '%s'\n",
-			getpid(), compName->value, csiDescriptor->csiName.value);
+			(int)getpid(), compName->value, csiDescriptor->csiName.value);
 		res = saAmfResponse (handle, invocation, SA_AIS_OK);
 		
 		TR(TRU,csiDescriptor->csiAttr.number);
@@ -200,7 +200,7 @@ void CSISetCallback (
 	case SA_AMF_HA_QUIESCED:
 		printf ("%d: Component '%s' requested to enter hastate SA_AMF_HA_QUIESCED "
 				"for \n\tCSI '%s'\n",
-			getpid(), compName->value, csiDescriptor->csiName.value);
+			(int)getpid(), compName->value, csiDescriptor->csiName.value);
 		res = saAmfResponse (handle, invocation, SA_AIS_OK);
 		break;
 	case SA_AMF_HA_QUIESCING:
@@ -260,7 +260,7 @@ SaAmfCallbacksT amfCallbacks;
 
 SaVersionT version = { 'B', 1, 1 };
 
-#if defined(OPENAIS_BSD) || defined(OPENAIS_LINUX)
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 static struct sched_param sched_param = {
     sched_priority: 99
 };
@@ -279,11 +279,11 @@ void write_pid (void) {
 	sprintf (filename,  "/var/run/openais_cleanup_%s", compNameGlobal.value);
 	fd = open (filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
 	if (fd == -1) {
-		printf("%d: Failed using /var/run for pid file, using /tmp\n", getpid());
+		printf("%d: Failed using /var/run for pid file, using /tmp\n", (int)getpid());
 		sprintf (filename,  "/tmp/openais_cleanup_%s", compNameGlobal.value);
 		fd = open (filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
 	}
-	sprintf (pid, "%d", getpid());
+	sprintf (pid, "%d", (int)getpid());
 	res = write (fd, pid, strlen (pid));
 	close (fd);
 }
@@ -310,13 +310,13 @@ int main (int argc, char **argv) {
 	}
 #endif
 
-	printf("%d: Hello world from %s\n", getpid(), name);
+	printf("%d: Hello world from %s\n", (int)getpid(), name);
 
 	signal (SIGINT, sigintr_handler);
-#if defined(OPENAIS_BSD) || defined(OPENAIS_LINUX)
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 	result = sched_setscheduler (0, SCHED_RR, &sched_param);
 	if (result == -1) {
-		printf ("%d: couldn't set sched priority\n", getpid());
+		printf ("%d: couldn't set sched priority\n", (int)getpid());
  	}
 #endif
 

+ 5 - 0
test/testamf2.c

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2002-2003 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -187,9 +188,11 @@ SaAmfCallbacksT amfCallbacks;
 
 SaVersionT version = { 'B', 1, 1 };
 
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 static struct sched_param sched_param = {
     sched_priority: 99
 };
+#endif
 
 void sigintr_handler (int signum) {
 	exit (0);
@@ -206,10 +209,12 @@ int main (int argc, char **argv) {
 printf ("testamf2 pid %d\n", getpid());
 	memset (&compNameGlobal, 0, sizeof (SaNameT));
 	signal (SIGINT, sigintr_handler);
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 	result = sched_setscheduler (0, SCHED_RR, &sched_param);
 	if (result == -1) {
 		printf ("couldn't set sched priority\n");
  	}
+#endif
 
 	for (;;){
 		c = getopt(argc,argv,"h:n:");

+ 5 - 0
test/testamf3.c

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2002-2003 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -214,9 +215,11 @@ SaAmfCallbacksT amfCallbacks;
 
 SaVersionT version = { 'B', 1, 1 };
 
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 static struct sched_param sched_param = {
     sched_priority: 99
 };
+#endif
 
 void sigintr_handler (int signum) {
 	exit (0);
@@ -232,10 +235,12 @@ int main (int argc, char **argv) {
 
 	memset (&compNameGlobal, 0, sizeof (SaNameT));
 	signal (SIGINT, sigintr_handler);
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 	result = sched_setscheduler (0, SCHED_RR, &sched_param);
 	if (result == -1) {
 		printf ("couldn't set sched priority\n");
  	}
+#endif
 
 	for (;;){
 		c = getopt(argc,argv,"h:n:");

+ 4 - 0
test/testamf4.c

@@ -214,9 +214,11 @@ SaAmfCallbacksT amfCallbacks;
 
 SaVersionT version = { 'B', 1, 1 };
 
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 static struct sched_param sched_param = {
     sched_priority: 99
 };
+#endif
 
 void sigintr_handler (int signum) {
 	exit (0);
@@ -232,10 +234,12 @@ int main (int argc, char **argv) {
 
 	memset (&compNameGlobal, 0, sizeof (SaNameT));
 	signal (SIGINT, sigintr_handler);
+#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
 	result = sched_setscheduler (0, SCHED_RR, &sched_param);
 	if (result == -1) {
 		printf ("couldn't set sched priority\n");
  	}
+#endif
 
 	for (;;){
 		c = getopt(argc,argv,"h:n:");

+ 1 - 0
test/testamf6.c

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2002-2003 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *

+ 17 - 2
test/testckpt.c

@@ -1,6 +1,7 @@
 #define _BSD_SOURCE
 /*
  * Copyright (c) 2002-2004 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -48,6 +49,18 @@
 #include "saCkpt.h"
 #include "sa_error.h"
 
+#ifdef OPENAIS_SOLARIS
+#define timersub(a, b, result)						\
+    do {								\
+	(result)->tv_sec = (a)->tv_sec - (b)->tv_sec;			\
+	(result)->tv_usec = (a)->tv_usec - (b)->tv_usec;		\
+	if ((result)->tv_usec < 0) {					\
+	    --(result)->tv_sec;						\
+	    (result)->tv_usec += 1000000;				\
+	}								\
+    } while (0)
+#endif
+
 #define SECONDS_TO_EXPIRE 4
 
 int ckptinv;
@@ -207,14 +220,16 @@ int main (void) {
 	int i;
 	
 	error = saCkptInitialize (&ckptHandle, &callbacks, &version);
+	printf ("%s: checkpoint initialize\n",
+		get_test_output (error, SA_AIS_OK));
 
 	error = saCkptCheckpointOpenAsync (ckptHandle,
 		open_invocation,
 		&checkpointName,
 		&checkpointCreationAttributes,
 		SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE);
-    printf ("%s: initial asynchronous open of checkpoint\n",
-        get_test_output (error, SA_AIS_OK));
+	printf ("%s: initial asynchronous open of checkpoint\n",
+		get_test_output (error, SA_AIS_OK));
 
 	error = saCkptSelectionObjectGet (ckptHandle, &sel_fd);
 

+ 2 - 0
test/testclm.c

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2002-2003 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -32,6 +33,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>

+ 2 - 1
test/testevs.c

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2004 MontaVista Software, Inc.
+ * Copyright (c) 2006 Sun Microsystems, Inc.
  *
  * All rights reserved.
  *
@@ -103,7 +104,7 @@ int main (void)
 	int fd;
 	unsigned int member_list[32];
 	unsigned int local_nodeid;
-	int member_list_entries = 32;
+	unsigned int member_list_entries = 32;
 
 	result = evs_initialize (&handle, &callbacks);
 	if (result != EVS_OK) {

+ 5 - 1
test/unlink.c

@@ -7,9 +7,13 @@
 #include <sys/poll.h>
 #include <unistd.h>
 #include <fcntl.h>
+#ifndef OPENAIS_SOLARIS
 #include <stdint.h>
-#include <stdlib.h>
 #include <getopt.h>
+#else
+#include <sys/types.h>
+#endif
+#include <stdlib.h>
 #include <sys/time.h>
 #include "saAis.h"
 #include "saEvt.h"