summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonnie Sahlberg <sahlberg@ronnie>2007-04-27 23:41:45 +1000
committerRonnie Sahlberg <sahlberg@ronnie>2007-04-27 23:41:45 +1000
commit7d1b82fd09b9a3f698f56f69c6d7c78ba05c1324 (patch)
tree7c0c44b6200392fbe4207ef14da8936ba64a6180
parentf616f2de10769af0c6d2a394f9c9b615ab891922 (diff)
parent3dc6331aee4d2d37c03fdcd52e62762463c1a00f (diff)
downloadsamba-7d1b82fd09b9a3f698f56f69c6d7c78ba05c1324.tar.gz
samba-7d1b82fd09b9a3f698f56f69c6d7c78ba05c1324.tar.xz
samba-7d1b82fd09b9a3f698f56f69c6d7c78ba05c1324.zip
merge from tridge
(This used to be ctdb commit 0d6fb241faa15cb2183d2faa4c5ffa607b9d5f46)
-rw-r--r--ctdb/common/ctdb_client.c58
-rw-r--r--ctdb/common/ctdb_control.c36
-rw-r--r--ctdb/common/ctdb_message.c2
-rw-r--r--ctdb/include/ctdb.h3
-rw-r--r--ctdb/include/ctdb_private.h4
-rw-r--r--ctdb/tools/ctdb_control.c69
6 files changed, 151 insertions, 21 deletions
diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c
index 56e10322997..f2b719f67b3 100644
--- a/ctdb/common/ctdb_client.c
+++ b/ctdb/common/ctdb_client.c
@@ -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;
}
diff --git a/ctdb/common/ctdb_control.c b/ctdb/common/ctdb_control.c
index 9d6a0469dc1..7a9327ec574 100644
--- a/ctdb/common/ctdb_control.c
+++ b/ctdb/common/ctdb_control.c
@@ -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;
diff --git a/ctdb/common/ctdb_message.c b/ctdb/common/ctdb_message.c
index 95df3c2c8de..cb85d21a605 100644
--- a/ctdb/common/ctdb_message.c
+++ b/ctdb/common/ctdb_message.c
@@ -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);
diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h
index 9b7484b037b..af4198887e2 100644
--- a/ctdb/include/ctdb.h
+++ b/ctdb/include/ctdb.h
@@ -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
diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h
index 612290805c7..848941f84bf 100644
--- a/ctdb/include/ctdb_private.h
+++ b/ctdb/include/ctdb_private.h
@@ -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};
diff --git a/ctdb/tools/ctdb_control.c b/ctdb/tools/ctdb_control.c
index c1616878a15..c3ad212f97b 100644
--- a/ctdb/tools/ctdb_control.c
+++ b/ctdb/tools/ctdb_control.c
@@ -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);