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

added a ctdb_get_config call

added a ctdb ping control

(This used to be ctdb commit 7d17378b6e6076a922cffe98239e20dfbbae3bf7)
This commit is contained in:
Andrew Tridgell 2007-04-26 19:27:07 +02:00
parent fc43701cbb
commit afa0876335
7 changed files with 107 additions and 1 deletions

View File

@ -153,5 +153,13 @@ struct ctdb_context *ctdb_cmdline_client(struct event_context *ev)
return NULL;
}
/* get our config */
ret = ctdb_get_config(ctdb);
if (ret != 0) {
DEBUG(0,(__location__ " Failed to get ctdb config\n"));
talloc_free(ctdb);
return NULL;
}
return ctdb;
}

View File

@ -479,6 +479,9 @@ void ctdb_connect_wait(struct ctdb_context *ctdb)
/* now we can go into the normal wait routine, as the reply packet
will update the ctdb->num_connected variable */
ctdb_daemon_connect_wait(ctdb);
/* get other config variables */
ctdb_get_config(ctdb);
}
/*
@ -859,3 +862,51 @@ int ctdb_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status
return 0;
}
/*
ping a node
*/
int ctdb_ping(struct ctdb_context *ctdb, uint32_t destnode)
{
int ret;
int32_t res;
TDB_DATA data;
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_PING, data, NULL, NULL, &res);
if (ret != 0 || res != 0) {
return -1;
}
return 0;
}
/*
get ctdb config
*/
int ctdb_get_config(struct ctdb_context *ctdb)
{
int ret;
int32_t res;
TDB_DATA data;
struct ctdb_context c;
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_CONFIG, data,
ctdb, &data, &res);
if (ret != 0 || res != 0) {
return -1;
}
if (data.dsize != sizeof(c)) {
DEBUG(0,("Bad config size %u - expected %u\n", data.dsize, sizeof(c)));
return -1;
}
c = *(struct ctdb_context *)data.dptr;
ctdb->num_nodes = c.num_nodes;
ctdb->num_connected = c.num_connected;
ctdb->vnn = c.vnn;
ctdb->max_lacount = c.max_lacount;
return 0;
}

View File

@ -50,11 +50,22 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
pid = *(pid_t *)indata.dptr;
return kill(pid, 0);
}
case CTDB_CONTROL_STATUS: {
outdata->dptr = (uint8_t *)&ctdb->status;
outdata->dsize = sizeof(ctdb->status);
return 0;
}
case CTDB_CONTROL_CONFIG: {
outdata->dptr = (uint8_t *)ctdb;
outdata->dsize = sizeof(*ctdb);
return 0;
}
case CTDB_CONTROL_PING:
return 0;
default:
DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode));
return -1;

View File

@ -758,6 +758,7 @@ void ctdb_request_finished(struct ctdb_context *ctdb, struct ctdb_req_header *hd
struct daemon_control_state {
struct ctdb_client *client;
struct ctdb_req_control *c;
uint32_t reqid;
};
/*
@ -784,6 +785,7 @@ static void daemon_control_callback(struct ctdb_context *ctdb,
r->hdr.ctdb_magic = CTDB_MAGIC;
r->hdr.ctdb_version = CTDB_VERSION;
r->hdr.operation = CTDB_REPLY_CONTROL;
r->hdr.reqid = state->reqid;
r->status = status;
r->datalen = data.dsize;
memcpy(&r->data[0], data.dptr, data.dsize);
@ -804,11 +806,16 @@ static void daemon_request_control_from_client(struct ctdb_client *client,
int res;
struct daemon_control_state *state;
if (c->hdr.destnode == CTDB_CURRENT_NODE) {
c->hdr.destnode = client->ctdb->vnn;
}
state = talloc(client, struct daemon_control_state);
CTDB_NO_MEMORY_VOID(client->ctdb, state);
state->client = client;
state->c = talloc_steal(state, c);
state->reqid = c->hdr.reqid;
data.dptr = &c->data[0];
data.dsize = c->datalen;

View File

@ -219,4 +219,8 @@ int ctdb_getdbpath(struct ctdb_db_context *ctdb_db, TDB_DATA *path);
int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
int ctdb_ping(struct ctdb_context *ctdb, uint32_t destnode);
int ctdb_get_config(struct ctdb_context *ctdb);
#endif

View File

@ -31,6 +31,7 @@
#define CTDB_NULL_FUNC 0xf0000001
#define CTDB_CURRENT_NODE 0xF0000001
/*
an installed ctdb remote call
@ -228,7 +229,10 @@ struct ctdb_ltdb_header {
uint32_t lacount;
};
enum {CTDB_CONTROL_PROCESS_EXISTS, CTDB_CONTROL_STATUS};
enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS,
CTDB_CONTROL_STATUS,
CTDB_CONTROL_CONFIG,
CTDB_CONTROL_PING};
enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};

View File

@ -33,6 +33,7 @@ static void usage(void)
{
printf("Usage: ctdb_control [options] <control>\n");
printf("\nControls:\n");
printf(" ping\n");
printf(" process-exists <vnn:pid>\n");
printf(" status <vnn>\n");
exit(1);
@ -115,6 +116,24 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv
return 0;
}
static int control_ping(struct ctdb_context *ctdb, int argc, const char **argv)
{
int ret, i;
for (i=0;i<ctdb->num_nodes;i++) {
struct timeval tv = timeval_current();
ret = ctdb_ping(ctdb, i);
if (ret != 0) {
printf("Unable to get ping response from node %u\n", i);
} else {
printf("response from %u time=%.6f sec\n",
i, timeval_elapsed(&tv));
}
}
return 0;
}
/*
main program
*/
@ -171,6 +190,8 @@ int main(int argc, const char *argv[])
ret = control_process_exists(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "status") == 0) {
ret = control_status(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "ping") == 0) {
ret = control_ping(ctdb, extra_argc-1, extra_argv+1);
} else {
printf("Unknown control '%s'\n", control);
exit(1);