mirror of
https://git.proxmox.com/git/mirror_corosync
synced 2025-07-27 05:17:35 +00:00
Add missing cts files.
git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2751 fd59a12c-fef9-0310-b244-a6a79926bd2f
This commit is contained in:
parent
cf4e2069b6
commit
efccdcf140
417
cts/agents/sam_test_agent.c
Normal file
417
cts/agents/sam_test_agent.c
Normal file
@ -0,0 +1,417 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Red Hat, Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Jan Friesse (jfriesse@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 Red Hat, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Provides test of SAM API
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <corosync/corotypes.h>
|
||||
#include <corosync/sam.h>
|
||||
#include "common_test_agent.h"
|
||||
|
||||
|
||||
static int test2_sig_delivered = 0;
|
||||
static int test4_hc_cb_count = 0;
|
||||
|
||||
/*
|
||||
* First test will just register SAM, with policy restart. First instance will
|
||||
* sleep one second, send hc and sleep another 3 seconds. This should force restart.
|
||||
* Second instance will sleep one second, send hc, stop hc and sleep 3 seconds.
|
||||
* Then start hc again and sleep 3 seconds. This should force restart again.
|
||||
* Last instance just calls initialize again. This should end with error.
|
||||
* Then call start, followed by stop and start again. Finally, we will call finalize
|
||||
* twice. One should succeed, second should fail. After this, we will call every function
|
||||
* (none should succeed).
|
||||
*/
|
||||
static int test1 (void)
|
||||
{
|
||||
cs_error_t error;
|
||||
unsigned int instance_id;
|
||||
int i;
|
||||
|
||||
syslog (LOG_INFO,"%s: initialize\n", __FUNCTION__);
|
||||
error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART);
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't initialize SAM API. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
syslog (LOG_INFO,"%s: register\n", __FUNCTION__);
|
||||
error = sam_register (&instance_id);
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't register. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (instance_id == 1 || instance_id == 2) {
|
||||
syslog (LOG_INFO,"%s iid %d: start\n", __FUNCTION__, instance_id);
|
||||
error = sam_start ();
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't start hc. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
syslog (LOG_INFO,"%s iid %d: sleep 1\n", __FUNCTION__, instance_id);
|
||||
sleep (1);
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: hc send\n", __FUNCTION__, instance_id);
|
||||
error = sam_hc_send ();
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't send hc. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (instance_id == 2) {
|
||||
syslog (LOG_INFO,"%s iid %d: stop\n", __FUNCTION__, instance_id);
|
||||
error = sam_stop ();
|
||||
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't send hc. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: sleep 3\n", __FUNCTION__, instance_id);
|
||||
sleep (3);
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: start\n", __FUNCTION__, instance_id);
|
||||
error = sam_start ();
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't start hc. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: sleep 3\n", __FUNCTION__, instance_id);
|
||||
sleep (3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (instance_id == 3) {
|
||||
error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART);
|
||||
if (error == CS_OK) {
|
||||
syslog (LOG_ERR, "Can initialize SAM API after initialization");
|
||||
return 1;
|
||||
}
|
||||
|
||||
error = sam_start ();
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't start hc. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
error = sam_stop ();
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't stop hc. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
error = sam_finalize ();
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't finalize sam. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
error = sam_finalize ();
|
||||
if (error == CS_OK) {
|
||||
syslog (LOG_ERR, "Can finalize sam after finalization!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sam_initialize (2, SAM_RECOVERY_POLICY_RESTART) == CS_OK ||
|
||||
sam_start () == CS_OK || sam_stop () == CS_OK ||
|
||||
sam_register (NULL) == CS_OK || sam_hc_send () == CS_OK ||
|
||||
sam_hc_callback_register (NULL) == CS_OK) {
|
||||
|
||||
syslog (LOG_ERR, "Can call one of function after finalization!\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void test2_signal (int sig) {
|
||||
syslog (LOG_INFO,"%s\n", __FUNCTION__);
|
||||
|
||||
test2_sig_delivered = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This tests recovery policy quit and callback.
|
||||
*/
|
||||
static int test2 (void) {
|
||||
cs_error_t error;
|
||||
unsigned int instance_id;
|
||||
|
||||
syslog (LOG_INFO,"%s: initialize\n", __FUNCTION__);
|
||||
error = sam_initialize (2000, SAM_RECOVERY_POLICY_QUIT);
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't initialize SAM API. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
syslog (LOG_INFO,"%s: register\n", __FUNCTION__);
|
||||
error = sam_register (&instance_id);
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't register. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (instance_id == 1) {
|
||||
signal (SIGTERM, test2_signal);
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: start\n", __FUNCTION__, instance_id);
|
||||
error = sam_start ();
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't start hc. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: sleep 1\n", __FUNCTION__, instance_id);
|
||||
sleep (1);
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: hc send\n", __FUNCTION__, instance_id);
|
||||
error = sam_hc_send ();
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't send hc. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: wait for delivery of signal\n", __FUNCTION__, instance_id);
|
||||
while (!test2_sig_delivered) {
|
||||
sleep (1);
|
||||
}
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: wait for real kill\n", __FUNCTION__, instance_id);
|
||||
|
||||
sleep (3);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Smoke test. Better to turn off coredump ;) This has no time limit, just restart process
|
||||
* when it dies.
|
||||
*/
|
||||
static int test3 (void) {
|
||||
cs_error_t error;
|
||||
unsigned int instance_id;
|
||||
int tmp1, tmp2, tmp3;
|
||||
|
||||
syslog (LOG_INFO,"%s: initialize\n", __FUNCTION__);
|
||||
error = sam_initialize (0, SAM_RECOVERY_POLICY_RESTART);
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't initialize SAM API. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
syslog (LOG_INFO,"%s: register\n", __FUNCTION__);
|
||||
error = sam_register (&instance_id);
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't register. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (instance_id < 100) {
|
||||
syslog (LOG_INFO,"%s iid %d: start\n", __FUNCTION__, instance_id);
|
||||
error = sam_start ();
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't start hc. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: divide by zero\n", __FUNCTION__, instance_id);
|
||||
tmp2 = rand ();
|
||||
tmp3 = 0;
|
||||
tmp1 = tmp2 / tmp3;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int test4_hc_cb (void)
|
||||
{
|
||||
syslog (LOG_INFO,"%s %d\n", __FUNCTION__, ++test4_hc_cb_count);
|
||||
|
||||
if (test4_hc_cb_count > 10)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* Test event driven healtchecking.
|
||||
*/
|
||||
static int test4 (void)
|
||||
{
|
||||
cs_error_t error;
|
||||
unsigned int instance_id;
|
||||
|
||||
syslog (LOG_INFO,"%s: initialize\n", __FUNCTION__);
|
||||
error = sam_initialize (100, SAM_RECOVERY_POLICY_RESTART);
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't initialize SAM API. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
syslog (LOG_INFO,"%s: register\n", __FUNCTION__);
|
||||
error = sam_register (&instance_id);
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't register. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (instance_id == 1) {
|
||||
syslog (LOG_INFO,"%s iid %d: hc callback register\n", __FUNCTION__, instance_id);
|
||||
error = sam_hc_callback_register (test4_hc_cb);
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't register hc cb. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: start\n", __FUNCTION__, instance_id);
|
||||
error = sam_start ();
|
||||
if (error != CS_OK) {
|
||||
syslog (LOG_ERR, "Can't start hc. Error %d\n", error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
sleep (2);
|
||||
|
||||
syslog (LOG_INFO,"%s iid %d: Failed. Wasn't killed.\n", __FUNCTION__, instance_id);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (instance_id == 2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void do_command (int sock, char* func, char*args[], int num_args)
|
||||
{
|
||||
char response[100];
|
||||
pid_t pid;
|
||||
int err;
|
||||
int stat;
|
||||
int please_wait = 1;
|
||||
|
||||
snprintf (response, 100, "%s", FAIL_STR);
|
||||
|
||||
if (parse_debug)
|
||||
syslog (LOG_INFO,"RPC:%s() called.", func);
|
||||
|
||||
pid = fork ();
|
||||
|
||||
if (pid == -1) {
|
||||
syslog (LOG_ERR, "Can't fork\n");
|
||||
send (sock, response, strlen (response) + 1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
if (strcmp ("test1", func) == 0) {
|
||||
err = test1 ();
|
||||
} else if (strcmp ("test2", func) == 0) {
|
||||
err = test2 ();
|
||||
} else if (strcmp ("test3", func) == 0) {
|
||||
err = test3 ();
|
||||
} else if (strcmp ("test4", func) == 0) {
|
||||
err = test4 ();
|
||||
} else {
|
||||
err = -1;
|
||||
please_wait = 0;
|
||||
syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
|
||||
snprintf (response, 100, "%s", NOT_SUPPORTED_STR);
|
||||
}
|
||||
}
|
||||
|
||||
if (please_wait) {
|
||||
waitpid (pid, &stat, 0);
|
||||
|
||||
if (WEXITSTATUS (stat) == 0) {
|
||||
snprintf (response, 100, "%s", OK_STR);
|
||||
} else {
|
||||
snprintf (response, 100, "%s", FAIL_STR);
|
||||
}
|
||||
}
|
||||
send (sock, response, strlen (response) + 1, 0);
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
|
||||
openlog (NULL, LOG_CONS|LOG_PID, LOG_DAEMON);
|
||||
syslog (LOG_ERR, "sam_test_agent STARTING");
|
||||
|
||||
parse_debug = 1;
|
||||
ret = test_agent_run (9036, do_command);
|
||||
syslog (LOG_ERR, "sam_test_agent EXITING");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
309
cts/agents/syncv2.c
Normal file
309
cts/agents/syncv2.c
Normal file
@ -0,0 +1,309 @@
|
||||
/*
|
||||
* Copyright (c) 2010 Red Hat, Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Angus Salkeld <asalkeld@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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <corosync/swab.h>
|
||||
#include <corosync/corotypes.h>
|
||||
#include <corosync/coroipc_types.h>
|
||||
#include <corosync/corodefs.h>
|
||||
#include <corosync/lcr/lcr_comp.h>
|
||||
#include <corosync/mar_gen.h>
|
||||
#include <corosync/engine/coroapi.h>
|
||||
#include <corosync/list.h>
|
||||
#include <corosync/engine/logsys.h>
|
||||
|
||||
#include "../exec/tlist.h"
|
||||
|
||||
LOGSYS_DECLARE_SUBSYS ("TST2");
|
||||
|
||||
/*
|
||||
* Service Interfaces required by service_message_handler struct
|
||||
*/
|
||||
static int tst_sv2_exec_init_fn (
|
||||
struct corosync_api_v1 *corosync_api);
|
||||
|
||||
static void tst_sv2_confchg_fn (
|
||||
enum totem_configuration_type configuration_type,
|
||||
const unsigned int *member_list, size_t member_list_entries,
|
||||
const unsigned int *left_list, size_t left_list_entries,
|
||||
const unsigned int *joined_list, size_t joined_list_entries,
|
||||
const struct memb_ring_id *ring_id);
|
||||
|
||||
static int tst_sv2_lib_init_fn (void *conn);
|
||||
static int tst_sv2_lib_exit_fn (void *conn);
|
||||
static struct corosync_api_v1 *api;
|
||||
|
||||
static void tst_sv2_sync_init_v2 (
|
||||
const unsigned int *member_list,
|
||||
size_t member_list_entries,
|
||||
const struct memb_ring_id *ring_id);
|
||||
|
||||
static int tst_sv2_sync_process (void);
|
||||
|
||||
static void tst_sv2_sync_activate (void);
|
||||
|
||||
static void tst_sv2_sync_abort (void);
|
||||
|
||||
struct corosync_service_engine tst_sv2_service_engine = {
|
||||
.name = "corosync test synv2 service",
|
||||
.id = TST_SV2_SERVICE,
|
||||
.priority = 1,
|
||||
.private_data_size = 0,
|
||||
.flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
|
||||
.lib_init_fn = tst_sv2_lib_init_fn,
|
||||
.lib_exit_fn = tst_sv2_lib_exit_fn,
|
||||
.lib_engine = NULL,
|
||||
.lib_engine_count = 0,
|
||||
.exec_engine = NULL,
|
||||
.exec_engine_count = 0,
|
||||
.confchg_fn = tst_sv2_confchg_fn,
|
||||
.exec_init_fn = tst_sv2_exec_init_fn,
|
||||
.exec_dump_fn = NULL,
|
||||
.sync_mode = CS_SYNC_V2,
|
||||
.sync_init = tst_sv2_sync_init_v2,
|
||||
.sync_process = tst_sv2_sync_process,
|
||||
.sync_activate = tst_sv2_sync_activate,
|
||||
.sync_abort = tst_sv2_sync_abort
|
||||
};
|
||||
|
||||
static unsigned int my_member_list[PROCESSOR_COUNT_MAX];
|
||||
|
||||
static unsigned int my_member_list_entries;
|
||||
|
||||
static unsigned int my_old_member_list[PROCESSOR_COUNT_MAX];
|
||||
|
||||
static unsigned int my_old_member_list_entries = 0;
|
||||
static int num_sync_processes = 0;
|
||||
|
||||
static DECLARE_LIST_INIT (confchg_notify);
|
||||
|
||||
/*
|
||||
* Dynamic loading descriptor
|
||||
*/
|
||||
|
||||
static struct corosync_service_engine *tst_sv2_get_service_engine_ver0 (void);
|
||||
|
||||
static struct corosync_service_engine_iface_ver0 tst_sv2_service_engine_iface = {
|
||||
.corosync_get_service_engine_ver0 = tst_sv2_get_service_engine_ver0
|
||||
};
|
||||
|
||||
static struct lcr_iface corosync_tst_sv2_ver0[1] = {
|
||||
{
|
||||
.name = "corosync_tst_sv2",
|
||||
.version = 0,
|
||||
.versions_replace = 0,
|
||||
.versions_replace_count = 0,
|
||||
.dependencies = 0,
|
||||
.dependency_count = 0,
|
||||
.constructor = NULL,
|
||||
.destructor = NULL,
|
||||
.interfaces = NULL,
|
||||
}
|
||||
};
|
||||
|
||||
static struct lcr_comp tst_sv2_comp_ver0 = {
|
||||
.iface_count = 1,
|
||||
.ifaces = corosync_tst_sv2_ver0
|
||||
};
|
||||
|
||||
static struct corosync_service_engine *tst_sv2_get_service_engine_ver0 (void)
|
||||
{
|
||||
return (&tst_sv2_service_engine);
|
||||
}
|
||||
|
||||
#ifdef COROSYNC_SOLARIS
|
||||
void corosync_lcr_component_register (void);
|
||||
|
||||
void corosync_lcr_component_register (void) {
|
||||
#else
|
||||
__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
|
||||
#endif
|
||||
lcr_interfaces_set (&corosync_tst_sv2_ver0[0], &tst_sv2_service_engine_iface);
|
||||
|
||||
lcr_component_register (&tst_sv2_comp_ver0);
|
||||
}
|
||||
|
||||
static int tst_sv2_exec_init_fn (
|
||||
struct corosync_api_v1 *corosync_api)
|
||||
{
|
||||
#ifdef COROSYNC_SOLARIS
|
||||
logsys_subsys_init();
|
||||
#endif
|
||||
api = corosync_api;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void tst_sv2_confchg_fn (
|
||||
enum totem_configuration_type configuration_type,
|
||||
const unsigned int *member_list, size_t member_list_entries,
|
||||
const unsigned int *left_list, size_t left_list_entries,
|
||||
const unsigned int *joined_list, size_t joined_list_entries,
|
||||
const struct memb_ring_id *ring_id)
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < left_list_entries; j++) {
|
||||
log_printf (LOGSYS_LEVEL_INFO,
|
||||
"Member left: %s", api->totem_ifaces_print (left_list[j]));
|
||||
}
|
||||
for (j = 0; j < joined_list_entries; j++) {
|
||||
log_printf (LOGSYS_LEVEL_INFO,
|
||||
"Member joined: %s", api->totem_ifaces_print (joined_list[j]));
|
||||
}
|
||||
}
|
||||
|
||||
static int tst_sv2_lib_init_fn (void *conn)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int tst_sv2_lib_exit_fn (void *conn)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
static void tst_sv2_sync_init_v2 (
|
||||
const unsigned int *member_list,
|
||||
size_t member_list_entries,
|
||||
const struct memb_ring_id *ring_id)
|
||||
{
|
||||
unsigned int lowest_nodeid = 0xffffffff;
|
||||
int i, j;
|
||||
int found;
|
||||
|
||||
num_sync_processes = 0;
|
||||
|
||||
memcpy (my_member_list, member_list, member_list_entries *
|
||||
sizeof (unsigned int));
|
||||
my_member_list_entries = member_list_entries;
|
||||
|
||||
for (i = 0; i < my_member_list_entries; i++) {
|
||||
if (my_member_list[i] < lowest_nodeid) {
|
||||
lowest_nodeid = my_member_list[i];
|
||||
}
|
||||
}
|
||||
|
||||
log_printf (LOGSYS_LEVEL_INFO,
|
||||
"tst_sv2_sync_init_v2 %s",
|
||||
api->totem_ifaces_print (lowest_nodeid));
|
||||
|
||||
/* look for new (joined) nodes */
|
||||
for (j = 0; j < member_list_entries; j++) {
|
||||
found = 0;
|
||||
for (i = 0; i < my_old_member_list_entries; i++) {
|
||||
if (my_old_member_list[i] == member_list[j]) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == 0) {
|
||||
log_printf (LOGSYS_LEVEL_INFO,
|
||||
"sync: node joined %s",
|
||||
api->totem_ifaces_print (member_list[j]));
|
||||
}
|
||||
}
|
||||
/* look for old (left) nodes */
|
||||
for (i = 0; i < my_old_member_list_entries; i++) {
|
||||
found = 0;
|
||||
for (j = 0; j < member_list_entries; j++) {
|
||||
if (my_old_member_list[i] == member_list[j]) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == 0) {
|
||||
log_printf (LOGSYS_LEVEL_INFO,
|
||||
"sync: node left %s",
|
||||
api->totem_ifaces_print (my_old_member_list[i]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int tst_sv2_sync_process (void)
|
||||
{
|
||||
num_sync_processes++;
|
||||
|
||||
log_printf (LOGSYS_LEVEL_INFO, "sync: process %d", num_sync_processes);
|
||||
|
||||
if (num_sync_processes > 3) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void tst_sv2_sync_activate (void)
|
||||
{
|
||||
memcpy (my_old_member_list, my_member_list,
|
||||
my_member_list_entries * sizeof (unsigned int));
|
||||
my_old_member_list_entries = my_member_list_entries;
|
||||
|
||||
if (num_sync_processes <= 3) {
|
||||
log_printf (LOGSYS_LEVEL_ERROR,
|
||||
"sync: activate called before process is done %d",
|
||||
num_sync_processes);
|
||||
} else {
|
||||
log_printf (LOGSYS_LEVEL_INFO,
|
||||
"sync: activate correctly %d",
|
||||
num_sync_processes);
|
||||
}
|
||||
|
||||
num_sync_processes = 0;
|
||||
}
|
||||
|
||||
static void tst_sv2_sync_abort (void)
|
||||
{
|
||||
log_printf (LOGSYS_LEVEL_INFO, "sync: abort");
|
||||
}
|
||||
|
222
cts/agents/votequorum_test_agent.c
Normal file
222
cts/agents/votequorum_test_agent.c
Normal file
@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright (c) 2010 Red Hat Inc
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Angus Salkeld <asalkeld@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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <corosync/corotypes.h>
|
||||
#include <corosync/votequorum.h>
|
||||
#include <corosync/quorum.h>
|
||||
#include "common_test_agent.h"
|
||||
|
||||
|
||||
static void getinfo (int sock)
|
||||
{
|
||||
votequorum_callbacks_t callbacks;
|
||||
int ret;
|
||||
struct votequorum_info info;
|
||||
char response[100];
|
||||
votequorum_handle_t g_handle;
|
||||
|
||||
callbacks.votequorum_notify_fn = NULL;
|
||||
callbacks.votequorum_expectedvotes_notify_fn = NULL;
|
||||
|
||||
ret = votequorum_initialize(&g_handle, &callbacks);
|
||||
if (ret != CS_OK) {
|
||||
snprintf (response, 100, "%s", FAIL_STR);
|
||||
syslog (LOG_ERR, "votequorum_initialize FAILED: %d\n", ret);
|
||||
goto send_response;
|
||||
}
|
||||
|
||||
ret = votequorum_getinfo(g_handle, 0, &info);
|
||||
if (ret != CS_OK) {
|
||||
snprintf (response, 100, "%s", FAIL_STR);
|
||||
syslog (LOG_ERR, "votequorum_getinfo FAILED: %d\n", ret);
|
||||
goto send_response;
|
||||
}
|
||||
|
||||
snprintf (response, 100, "%d:%d:%d:%d:%d",
|
||||
info.node_votes,
|
||||
info.node_expected_votes,
|
||||
info.highest_expected,
|
||||
info.total_votes,
|
||||
info.quorum);
|
||||
|
||||
send_response:
|
||||
votequorum_finalize (g_handle);
|
||||
send (sock, response, strlen (response), 0);
|
||||
}
|
||||
|
||||
|
||||
static void setexpected (int sock, char *arg)
|
||||
{
|
||||
votequorum_callbacks_t callbacks;
|
||||
int ret;
|
||||
char response[100];
|
||||
votequorum_handle_t g_handle;
|
||||
|
||||
callbacks.votequorum_notify_fn = NULL;
|
||||
callbacks.votequorum_expectedvotes_notify_fn = NULL;
|
||||
|
||||
ret = votequorum_initialize(&g_handle, &callbacks);
|
||||
if (ret != CS_OK) {
|
||||
snprintf (response, 100, "%s", FAIL_STR);
|
||||
syslog (LOG_ERR, "votequorum_initialize FAILED: %d\n", ret);
|
||||
goto send_response;
|
||||
}
|
||||
|
||||
ret = votequorum_setexpected (g_handle, atoi(arg));
|
||||
if (ret != CS_OK) {
|
||||
snprintf (response, 100, "%s", FAIL_STR);
|
||||
syslog (LOG_ERR, "set expected votes FAILED: %d\n", ret);
|
||||
goto send_response;
|
||||
}
|
||||
|
||||
snprintf (response, 100, "%s", OK_STR);
|
||||
|
||||
send_response:
|
||||
votequorum_finalize (g_handle);
|
||||
send (sock, response, strlen (response) + 1, 0);
|
||||
}
|
||||
|
||||
static void setvotes (int sock, char *arg)
|
||||
{
|
||||
votequorum_callbacks_t callbacks;
|
||||
int ret;
|
||||
char response[100];
|
||||
votequorum_handle_t g_handle;
|
||||
|
||||
callbacks.votequorum_notify_fn = NULL;
|
||||
callbacks.votequorum_expectedvotes_notify_fn = NULL;
|
||||
|
||||
ret = votequorum_initialize(&g_handle, &callbacks);
|
||||
if (ret != CS_OK) {
|
||||
snprintf (response, 100, "%s", FAIL_STR);
|
||||
syslog (LOG_ERR, "votequorum_initialize FAILED: %d\n", ret);
|
||||
goto send_response;
|
||||
}
|
||||
|
||||
ret = votequorum_setvotes (g_handle, 0, atoi(arg));
|
||||
if (ret != CS_OK) {
|
||||
snprintf (response, 100, "%s", FAIL_STR);
|
||||
syslog (LOG_ERR, "set votes FAILED: %d\n", ret);
|
||||
goto send_response;
|
||||
}
|
||||
|
||||
snprintf (response, 100, "%s", OK_STR);
|
||||
|
||||
send_response:
|
||||
votequorum_finalize (g_handle);
|
||||
send (sock, response, strlen (response), 0);
|
||||
}
|
||||
|
||||
|
||||
static void getquorate (int sock)
|
||||
{
|
||||
int ret;
|
||||
int quorate;
|
||||
char response[100];
|
||||
quorum_handle_t handle;
|
||||
|
||||
ret = quorum_initialize (&handle, NULL);
|
||||
if (ret != CS_OK) {
|
||||
snprintf (response, 100, "%s", FAIL_STR);
|
||||
syslog (LOG_ERR, "quorum_initialize FAILED: %d\n", ret);
|
||||
goto send_response;
|
||||
}
|
||||
|
||||
ret = quorum_getquorate (handle, &quorate);
|
||||
if (ret != CS_OK) {
|
||||
snprintf (response, 100, "%s", FAIL_STR);
|
||||
syslog (LOG_ERR, "getquorate FAILED: %d\n", ret);
|
||||
goto send_response;
|
||||
}
|
||||
|
||||
snprintf (response, 100, "%d", quorate);
|
||||
|
||||
send_response:
|
||||
quorum_finalize (handle);
|
||||
send (sock, response, strlen (response), 0);
|
||||
}
|
||||
|
||||
static void do_command (int sock, char* func, char*args[], int num_args)
|
||||
{
|
||||
char response[100];
|
||||
|
||||
if (parse_debug)
|
||||
syslog (LOG_DEBUG,"RPC:%s() called.", func);
|
||||
|
||||
if (strcmp ("votequorum_getinfo", func) == 0) {
|
||||
getinfo (sock);
|
||||
} else if (strcmp ("votequorum_setvotes", func) == 0) {
|
||||
setvotes (sock, args[0]);
|
||||
} else if (strcmp ("votequorum_setexpected", func) == 0) {
|
||||
setexpected (sock, args[0]);
|
||||
} else if (strcmp ("quorum_getquorate", func) == 0) {
|
||||
getquorate (sock);
|
||||
} else {
|
||||
syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
|
||||
snprintf (response, 100, "%s", NOT_SUPPORTED_STR);
|
||||
send (sock, response, strlen (response), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
|
||||
openlog (NULL, LOG_CONS|LOG_PID, LOG_DAEMON);
|
||||
syslog (LOG_ERR, "votequorum_test_agent STARTING");
|
||||
|
||||
parse_debug = 1;
|
||||
ret = test_agent_run (9037, do_command);
|
||||
syslog (LOG_ERR, "votequorum_test_agent EXITING");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user