1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-20 22:50:26 +03:00

merge from tridge

(This used to be ctdb commit 0d6fb241faa15cb2183d2faa4c5ffa607b9d5f46)
This commit is contained in:
Ronnie Sahlberg 2007-04-27 23:41:45 +10:00
commit 7d1b82fd09
6 changed files with 151 additions and 21 deletions

View File

@ -758,25 +758,26 @@ int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid)
int ctdb_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status *status)
{
int ret;
TDB_DATA data, outdata;
TDB_DATA data;
int32_t res;
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_STATUS, data,
ctdb, &outdata, &res);
ctdb, &data, &res);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for status failed\n"));
return -1;
}
if (outdata.dsize != sizeof(struct ctdb_status)) {
if (data.dsize != sizeof(struct ctdb_status)) {
DEBUG(0,(__location__ " Wrong status size %u - expected %u\n",
outdata.dsize, sizeof(struct ctdb_status)));
data.dsize, sizeof(struct ctdb_status)));
return -1;
}
*status = *(struct ctdb_status *)outdata.dptr;
*status = *(struct ctdb_status *)data.dptr;
talloc_free(data.dptr);
return 0;
}
@ -884,6 +885,7 @@ int ctdb_get_config(struct ctdb_context *ctdb)
}
c = *(struct ctdb_context *)data.dptr;
talloc_free(data.dptr);
ctdb->num_nodes = c.num_nodes;
ctdb->num_connected = c.num_connected;
@ -921,5 +923,49 @@ int ctdb_getdbpath(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx,
talloc_free(data.dptr);
return 0;
}
/*
get debug level on a node
*/
int ctdb_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level)
{
int ret;
int32_t res;
TDB_DATA data;
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_DEBUG, data,
ctdb, &data, &res);
if (ret != 0 || res != 0) {
return -1;
}
if (data.dsize != sizeof(uint32_t)) {
DEBUG(0,("Bad control reply size in ctdb_get_debuglevel (got %u)\n",
data.dsize));
return -1;
}
*level = *(uint32_t *)data.dptr;
talloc_free(data.dptr);
return 0;
}
/*
set debug level on a node
*/
int ctdb_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level)
{
int ret;
int32_t res;
TDB_DATA data;
data.dptr = (uint8_t *)&level;
data.dsize = sizeof(level);
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_SET_DEBUG, data,
NULL, NULL, &res);
if (ret != 0 || res != 0) {
return -1;
}
return 0;
}

View File

@ -33,6 +33,14 @@ struct ctdb_control_state {
void *private_data;
};
#define CHECK_CONTROL_DATA_SIZE(size) do { \
if (indata.dsize != size) { \
DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
opcode, indata.dsize, size)); \
return -1; \
} \
} while (0)
/*
process a control request
*/
@ -43,15 +51,26 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
switch (opcode) {
case CTDB_CONTROL_PROCESS_EXISTS: {
pid_t pid;
if (indata.dsize != sizeof(pid_t)) {
DEBUG(0,(__location__ " Invalid data in CTDB_CONTROL_PROCESS_EXISTS\n"));
return -1;
}
CHECK_CONTROL_DATA_SIZE(sizeof(pid));
pid = *(pid_t *)indata.dptr;
return kill(pid, 0);
}
case CTDB_CONTROL_SET_DEBUG: {
CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
LogLevel = *(uint32_t *)indata.dptr;
return 0;
}
case CTDB_CONTROL_GET_DEBUG: {
CHECK_CONTROL_DATA_SIZE(0);
outdata->dptr = (uint8_t *)&LogLevel;
outdata->dsize = sizeof(LogLevel);
return 0;
}
case CTDB_CONTROL_STATUS: {
CHECK_CONTROL_DATA_SIZE(0);
outdata->dptr = (uint8_t *)&ctdb->status;
outdata->dsize = sizeof(ctdb->status);
return 0;
@ -59,7 +78,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
case CTDB_CONTROL_GETVNNMAP: {
uint32_t i, len;
CHECK_CONTROL_DATA_SIZE(0);
len = 2+ctdb->vnn_map->size;
outdata->dsize = 4*len;
outdata->dptr = (unsigned char *)talloc_array(outdata, uint32_t, len);
@ -95,22 +114,21 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
}
case CTDB_CONTROL_CONFIG: {
CHECK_CONTROL_DATA_SIZE(0);
outdata->dptr = (uint8_t *)ctdb;
outdata->dsize = sizeof(*ctdb);
return 0;
}
case CTDB_CONTROL_PING:
CHECK_CONTROL_DATA_SIZE(0);
return 0;
case CTDB_CONTROL_GETDBPATH: {
uint32_t db_id;
struct ctdb_db_context *ctdb_db;
if (indata.dsize != sizeof(uint32_t)) {
DEBUG(0,(__location__ " Invalid data in CTDB_CONTROL_GETDBPATH\n"));
return -1;
}
CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
db_id = *(uint32_t *)indata.dptr;
ctdb_db = find_ctdb_db(ctdb, db_id);
if (ctdb_db == NULL) return -1;

View File

@ -36,8 +36,6 @@ static int ctdb_dispatch_message(struct ctdb_context *ctdb, uint32_t srvid, TDB_
{
struct ctdb_message_list *ml;
/* XXX we need a must faster way of finding the matching srvid
- maybe a tree? */
for (ml=ctdb->message_list;ml;ml=ml->next) {
if (ml->srvid == srvid || ml->srvid == CTDB_SRVID_ALL) {
ml->message_handler(ctdb, srvid, data, ml->message_private);

View File

@ -227,4 +227,7 @@ int ctdb_ping(struct ctdb_context *ctdb, uint32_t destnode);
int ctdb_get_config(struct ctdb_context *ctdb);
int ctdb_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level);
int ctdb_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level);
#endif

View File

@ -246,7 +246,9 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS,
CTDB_CONTROL_PING,
CTDB_CONTROL_GETDBPATH,
CTDB_CONTROL_GETVNNMAP,
CTDB_CONTROL_SETVNNMAP};
CTDB_CONTROL_SETVNNMAP,
CTDB_CONTROL_GET_DEBUG,
CTDB_CONTROL_SET_DEBUG};
enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};

View File

@ -34,13 +34,18 @@ 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");
printf(" getvnnmap <vnn>\n");
printf(" process-exists <vnn:pid> see if a process exists\n");
printf(" status <vnn> show ctdb status on a node\n");
printf(" debug <vnn> <level> set ctdb debug level on a node\n");
printf(" debuglevel display ctdb debug levels\n");
printf(" getvnnmap <vnn> display ctdb vnnmap\n");
printf(" setvnnmap <vnn> <generation> <numslots> <lmaster>*\n");
exit(1);
}
/*
see if a process exists
*/
static int control_process_exists(struct ctdb_context *ctdb, int argc, const char **argv)
{
uint32_t vnn, pid;
@ -98,6 +103,9 @@ static void show_status(struct ctdb_status *s)
printf(" max_lockwait_latency %.6f sec\n", s->max_lockwait_latency);
}
/*
display remote ctdb status
*/
static int control_status(struct ctdb_context *ctdb, int argc, const char **argv)
{
uint32_t vnn;
@ -118,6 +126,9 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv
return 0;
}
/*
display remote ctdb vnn map
*/
static int control_getvnnmap(struct ctdb_context *ctdb, int argc, const char **argv)
{
uint32_t vnn;
@ -143,6 +154,9 @@ static int control_getvnnmap(struct ctdb_context *ctdb, int argc, const char **a
return 0;
}
/*
set remote ctdb vnn map
*/
static int control_setvnnmap(struct ctdb_context *ctdb, int argc, const char **argv)
{
uint32_t vnn;
@ -170,6 +184,9 @@ static int control_setvnnmap(struct ctdb_context *ctdb, int argc, const char **a
return 0;
}
/*
ping all node
*/
static int control_ping(struct ctdb_context *ctdb, int argc, const char **argv)
{
int ret, i;
@ -187,6 +204,48 @@ static int control_ping(struct ctdb_context *ctdb, int argc, const char **argv)
return 0;
}
/*
display debug level on all node
*/
static int control_debuglevel(struct ctdb_context *ctdb, int argc, const char **argv)
{
int ret, i;
for (i=0;i<ctdb->num_nodes;i++) {
uint32_t level;
ret = ctdb_get_debuglevel(ctdb, i, &level);
if (ret != 0) {
printf("Unable to get debuglevel response from node %u\n", i);
} else {
printf("Node %u is at debug level %u\n", i, level);
}
}
return 0;
}
/*
set debug level on a node
*/
static int control_debug(struct ctdb_context *ctdb, int argc, const char **argv)
{
int ret;
uint32_t vnn, level;
if (argc < 2) {
usage();
}
vnn = strtoul(argv[0], NULL, 0);
level = strtoul(argv[1], NULL, 0);
ret = ctdb_set_debuglevel(ctdb, vnn, level);
if (ret != 0) {
printf("Unable to set debug level on node %u\n", vnn);
}
return 0;
}
/*
main program
*/
@ -249,6 +308,10 @@ int main(int argc, const char *argv[])
ret = control_setvnnmap(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "ping") == 0) {
ret = control_ping(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "debug") == 0) {
ret = control_debug(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "debuglevel") == 0) {
ret = control_debuglevel(ctdb, extra_argc-1, extra_argv+1);
} else {
printf("Unknown control '%s'\n", control);
exit(1);