Make resync/monitoring functionality optional
This commit is contained in:
committed by
Martin Willi
parent
f24ca1dd55
commit
3e8caf6af6
@@ -105,7 +105,7 @@ plugin_t *plugin_create()
|
||||
private_ha_plugin_t *this;
|
||||
char *local, *remote, *secret;
|
||||
u_int count;
|
||||
bool fifo;
|
||||
bool fifo, monitor, resync;
|
||||
|
||||
local = lib->settings->get_str(lib->settings,
|
||||
"charon.plugins.ha.local", NULL);
|
||||
@@ -114,7 +114,11 @@ plugin_t *plugin_create()
|
||||
secret = lib->settings->get_str(lib->settings,
|
||||
"charon.plugins.ha.secret", NULL);
|
||||
fifo = lib->settings->get_bool(lib->settings,
|
||||
"charon.plugins.ha.fifo_interface", FALSE);
|
||||
"charon.plugins.ha.fifo_interface", TRUE);
|
||||
monitor = lib->settings->get_bool(lib->settings,
|
||||
"charon.plugins.ha.monitor", TRUE);
|
||||
resync = lib->settings->get_bool(lib->settings,
|
||||
"charon.plugins.ha.resync", TRUE);
|
||||
count = min(SEGMENTS_MAX, lib->settings->get_int(lib->settings,
|
||||
"charon.plugins.ha.segment_count", 1));
|
||||
if (!local || !remote)
|
||||
@@ -129,26 +133,20 @@ plugin_t *plugin_create()
|
||||
this->tunnel = NULL;
|
||||
this->ctl = NULL;
|
||||
|
||||
this->socket = ha_socket_create(local, remote);
|
||||
if (!this->socket)
|
||||
{
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
this->kernel = ha_kernel_create(count);
|
||||
if (!this->kernel)
|
||||
{
|
||||
this->socket->destroy(this->socket);
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (secret)
|
||||
{
|
||||
this->tunnel = ha_tunnel_create(local, remote, secret);
|
||||
}
|
||||
this->segments = ha_segments_create(this->socket, this->kernel,
|
||||
this->tunnel, local, remote, count);
|
||||
this->socket = ha_socket_create(local, remote);
|
||||
if (!this->socket)
|
||||
{
|
||||
DESTROY_IF(this->tunnel);
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
this->kernel = ha_kernel_create(count);
|
||||
this->segments = ha_segments_create(this->socket, this->kernel, this->tunnel,
|
||||
count, strcmp(local, remote) > 0, monitor, resync);
|
||||
if (fifo)
|
||||
{
|
||||
this->ctl = ha_ctl_create(this->segments);
|
||||
|
||||
@@ -77,9 +77,9 @@ struct private_ha_segments_t {
|
||||
segment_mask_t active;
|
||||
|
||||
/**
|
||||
* Are we the master node handling segment assignement?
|
||||
* Node number
|
||||
*/
|
||||
bool master;
|
||||
u_int node;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -388,7 +388,7 @@ static void handle_status(private_ha_segments_t *this, segment_mask_t mask)
|
||||
{
|
||||
if (missing & SEGMENTS_BIT(i))
|
||||
{
|
||||
if (this->master != i % 2)
|
||||
if (this->node == i % 2)
|
||||
{
|
||||
DBG1(DBG_CFG, "HA segment %d was not handled, taking", i);
|
||||
enable_disable(this, i, TRUE, TRUE);
|
||||
@@ -458,7 +458,8 @@ static void destroy(private_ha_segments_t *this)
|
||||
* See header
|
||||
*/
|
||||
ha_segments_t *ha_segments_create(ha_socket_t *socket, ha_kernel_t *kernel,
|
||||
ha_tunnel_t *tunnel, char *local, char *remote, u_int count)
|
||||
ha_tunnel_t *tunnel, u_int count, u_int node,
|
||||
bool monitor, bool sync)
|
||||
{
|
||||
private_ha_segments_t *this = malloc_thing(private_ha_segments_t);
|
||||
|
||||
@@ -476,20 +477,25 @@ ha_segments_t *ha_segments_create(ha_socket_t *socket, ha_kernel_t *kernel,
|
||||
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
|
||||
this->condvar = condvar_create(CONDVAR_TYPE_DEFAULT);
|
||||
this->count = count;
|
||||
this->master = strcmp(local, remote) > 0;
|
||||
this->node = node;
|
||||
this->job = NULL;
|
||||
|
||||
/* initially all segments are deactivated */
|
||||
this->active = 0;
|
||||
|
||||
send_status(this);
|
||||
if (monitor)
|
||||
{
|
||||
send_status(this);
|
||||
start_watchdog(this);
|
||||
}
|
||||
|
||||
start_watchdog(this);
|
||||
|
||||
/* request a resync as soon as we are up */
|
||||
charon->processor->queue_job(charon->processor, (job_t*)
|
||||
if (sync)
|
||||
{
|
||||
/* request a resync as soon as we are up */
|
||||
charon->processor->queue_job(charon->processor, (job_t*)
|
||||
callback_job_create((callback_job_cb_t)request_resync,
|
||||
this, NULL, NULL));
|
||||
}
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -97,11 +97,15 @@ struct ha_segments_t {
|
||||
*
|
||||
* @param socket socket to communicate segment (de-)activation
|
||||
* @param kernel interface to control segments at kernel level
|
||||
* @param tunnel HA tunnel
|
||||
* @param count number of segments the cluster uses
|
||||
* @param active bit mask of initially active segments
|
||||
* @param node node, currently 1 or 0
|
||||
* @param monitor should we use monitoring functionality
|
||||
* @param resync request a complete resync on startup
|
||||
* @return segment object
|
||||
*/
|
||||
ha_segments_t *ha_segments_create(ha_socket_t *socket, ha_kernel_t *kernel,
|
||||
ha_tunnel_t *tunnel, char *local, char *remote, u_int count);
|
||||
ha_tunnel_t *tunnel, u_int count, u_int node,
|
||||
bool monitor, bool resync);
|
||||
|
||||
#endif /* HA_SEGMENTS_ @}*/
|
||||
|
||||
Reference in New Issue
Block a user