1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

ctdb-tests: Reimplement message handlers using srvid abstraction

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13042

This is required for CHECK_PID_SRVID control implementation.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-08-30 16:59:16 +10:00 committed by Martin Schwenke
parent 1c472dffd4
commit c480cc0152

View File

@ -40,6 +40,7 @@
#include "common/system.h"
#include "common/logging.h"
#include "common/tunable.h"
#include "common/srvid.h"
#include "ipalloc_read_known_ips.h"
@ -95,12 +96,6 @@ struct database_map {
struct database *db;
};
struct srvid_register_state {
struct srvid_register_state *prev, *next;
struct ctdbd_context *ctdb;
uint64_t srvid;
};
struct fake_control_failure {
struct fake_control_failure *prev, *next;
enum ctdb_controls opcode;
@ -121,7 +116,7 @@ struct ctdbd_context {
struct interface_map *iface_map;
struct vnn_map *vnn_map;
struct database_map *db_map;
struct srvid_register_state *rstate;
struct srvid_context *srv;
int num_clients;
struct timeval start_time;
struct timeval recovery_start_time;
@ -898,6 +893,7 @@ static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx)
struct ctdbd_context *ctdb;
char line[1024];
bool status;
int ret;
ctdb = talloc_zero(mem_ctx, struct ctdbd_context);
if (ctdb == NULL) {
@ -924,6 +920,11 @@ static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx)
goto fail;
}
ret = srvid_init(ctdb, &ctdb->srv);
if (ret != 0) {
goto fail;
}
while (fgets(line, sizeof(line), stdin) != NULL) {
char *t;
@ -1590,10 +1591,9 @@ fail:
}
static int srvid_register_state_destructor(struct srvid_register_state *rstate)
static void srvid_handler(uint64_t srvid, TDB_DATA data, void *private_data)
{
DLIST_REMOVE(rstate->ctdb->rstate, rstate);
return 0;
printf("Received a message for SRVID 0x%"PRIx64"\n", srvid);
}
static void control_register_srvid(TALLOC_CTX *mem_ctx,
@ -1605,24 +1605,19 @@ static void control_register_srvid(TALLOC_CTX *mem_ctx,
req, struct client_state);
struct ctdbd_context *ctdb = state->ctdb;
struct ctdb_reply_control reply;
struct srvid_register_state *rstate;
int ret;
reply.rdata.opcode = request->opcode;
rstate = talloc_zero(ctdb, struct srvid_register_state);
if (rstate == NULL) {
ret = srvid_register(ctdb->srv, state, request->srvid,
srvid_handler, state);
if (ret != 0) {
reply.status = -1;
reply.errmsg = "Memory error";
goto fail;
}
rstate->ctdb = ctdb;
rstate->srvid = request->srvid;
talloc_set_destructor(rstate, srvid_register_state_destructor);
DLIST_ADD_END(ctdb->rstate, rstate);
DEBUG(DEBUG_INFO, ("Register srvid 0x%"PRIx64"\n", rstate->srvid));
DEBUG(DEBUG_INFO, ("Register srvid 0x%"PRIx64"\n", request->srvid));
reply.status = 0;
reply.errmsg = NULL;
@ -1640,24 +1635,18 @@ static void control_deregister_srvid(TALLOC_CTX *mem_ctx,
req, struct client_state);
struct ctdbd_context *ctdb = state->ctdb;
struct ctdb_reply_control reply;
struct srvid_register_state *rstate = NULL;
int ret;
reply.rdata.opcode = request->opcode;
for (rstate = ctdb->rstate; rstate != NULL; rstate = rstate->next) {
if (rstate->srvid == request->srvid) {
break;
}
}
if (rstate == NULL) {
ret = srvid_deregister(ctdb->srv, request->srvid, state);
if (ret != 0) {
reply.status = -1;
reply.errmsg = "srvid not registered";
goto fail;
}
DEBUG(DEBUG_INFO, ("Deregister srvid 0x%"PRIx64"\n", rstate->srvid));
talloc_free(rstate);
DEBUG(DEBUG_INFO, ("Deregister srvid 0x%"PRIx64"\n", request->srvid));
reply.status = 0;
reply.errmsg = NULL;
@ -1666,7 +1655,6 @@ static void control_deregister_srvid(TALLOC_CTX *mem_ctx,
return;
fail:
TALLOC_FREE(rstate);
client_send_control(req, header, &reply);
}