1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

ctdb-client: Add a disconnect callback for ctdb client

This allows the client code to optionally clean up and/or re-connect to
CTDB daemon when it the daemon goes away.  If no disconnect callback is
registered and CTDB daemon goes away, then the client will terminate.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2015-10-14 15:36:55 +11:00 committed by Martin Schwenke
parent 555237f2a8
commit 8ca76adaea
3 changed files with 25 additions and 1 deletions

View File

@ -30,11 +30,17 @@ struct ctdb_client_context;
struct ctdb_db_context;
struct ctdb_record_handle;
typedef void (*ctdb_client_callback_func_t)(void *private_data);
/* from client/client_connect.c */
int ctdb_client_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
const char *sockpath, struct ctdb_client_context **ret);
void ctdb_client_set_disconnect_callback(struct ctdb_client_context *client,
ctdb_client_callback_func_t func,
void *private_data);
uint32_t ctdb_client_pnn(struct ctdb_client_context *client);
void ctdb_client_wait(struct tevent_context *ev, bool *done);

View File

@ -206,12 +206,27 @@ static void client_dead_handler(void *private_data)
{
struct ctdb_client_context *client = talloc_get_type_abort(
private_data, struct ctdb_client_context);
ctdb_client_callback_func_t callback = client->callback;
void *callback_data = client->private_data;
talloc_free(client);
if (callback != NULL) {
callback(callback_data);
return;
}
DEBUG(DEBUG_NOTICE, ("connection to daemon closed, exiting\n"));
talloc_free(client);
exit(1);
}
void ctdb_client_set_disconnect_callback(struct ctdb_client_context *client,
ctdb_client_callback_func_t callback,
void *private_data)
{
client->callback = callback;
client->private_data = private_data;
}
uint32_t ctdb_client_pnn(struct ctdb_client_context *client)
{
return client->pnn;

View File

@ -21,6 +21,7 @@
#define __CTDB_CLIENT_PRIVATE_H__
#include "protocol/protocol.h"
#include "client/client.h"
struct ctdb_db_context {
struct ctdb_db_context *prev, *next;
@ -35,6 +36,8 @@ struct ctdb_client_context {
struct reqid_context *idr;
struct srvid_context *srv;
struct comm_context *comm;
ctdb_client_callback_func_t callback;
void *private_data;
int fd;
uint32_t pnn;
struct ctdb_db_context *db;